Ion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
resourcemanager.cc
Go to the documentation of this file.
1 
19 
20 #include <algorithm>
21 #include <memory>
22 
23 #include "base/integral_types.h"
25 #include "ion/base/stringutils.h"
26 #include "ion/gfx/attributearray.h"
27 #include "ion/gfx/bufferobject.h"
30 #include "ion/gfx/sampler.h"
31 #include "ion/gfx/shader.h"
32 #include "ion/gfx/shaderprogram.h"
33 #include "ion/gfx/texture.h"
34 #include "ion/math/matrixutils.h"
35 
36 namespace ion {
37 namespace gfx {
38 
39 namespace {
40 
42 
47 
48 static void FillArrayInfo(const GraphicsManagerPtr& gm,
51  GLint attrib_count;
52  gm->GetIntegerv(GL_MAX_VERTEX_ATTRIBS, &attrib_count);
54  info->attributes.resize(attrib_count);
55  GLint boolean_value = GL_FALSE;
56  for (GLint i = 0; i < attrib_count; ++i) {
57  gm->GetVertexAttribiv(
58  static_cast<GLuint>(i), GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING,
59  reinterpret_cast<GLint*>(&info->attributes[i].buffer));
60  gm->GetVertexAttribiv(
61  static_cast<GLuint>(i), GL_VERTEX_ATTRIB_ARRAY_ENABLED, &boolean_value);
62  info->attributes[i].enabled = static_cast<GLboolean>(boolean_value);
63  gm->GetVertexAttribiv(
64  static_cast<GLuint>(i), GL_VERTEX_ATTRIB_ARRAY_SIZE,
65  reinterpret_cast<GLint*>(&info->attributes[i].size));
66  gm->GetVertexAttribiv(
67  static_cast<GLuint>(i), GL_VERTEX_ATTRIB_ARRAY_STRIDE,
68  reinterpret_cast<GLint*>(&info->attributes[i].stride));
69  gm->GetVertexAttribiv(
70  static_cast<GLuint>(i), GL_VERTEX_ATTRIB_ARRAY_TYPE,
71  reinterpret_cast<GLint*>(&info->attributes[i].type));
72  gm->GetVertexAttribiv(
73  static_cast<GLuint>(i), GL_VERTEX_ATTRIB_ARRAY_NORMALIZED,
74  &boolean_value);
75  info->attributes[i].normalized = static_cast<GLboolean>(boolean_value);
76  gm->GetVertexAttribfv(
77  static_cast<GLuint>(i), GL_CURRENT_VERTEX_ATTRIB,
78  &info->attributes[i].value[0]);
79  gm->GetVertexAttribPointerv(
80  static_cast<GLuint>(i), GL_VERTEX_ATTRIB_ARRAY_POINTER,
81  &info->attributes[i].pointer);
82  if (gm->IsFunctionGroupAvailable(GraphicsManager::kInstancedDrawing)) {
83  gm->GetVertexAttribiv(
84  static_cast<GLuint>(i), GL_VERTEX_ATTRIB_ARRAY_DIVISOR,
85  reinterpret_cast<GLint*>(&info->attributes[i].divisor));
86  }
87  }
88 }
89 
91 
96 
97 static void FillBufferInfo(const GraphicsManagerPtr& gm,
101  GLint size = 0;
102  gm->GetBufferParameteriv(info->target, GL_BUFFER_SIZE, &size);
103  info->size = size;
104  gm->GetBufferParameteriv(
105  info->target, GL_BUFFER_USAGE, reinterpret_cast<GLint*>(&info->usage));
106  if (gm->IsFunctionGroupAvailable(GraphicsManager::kMapBufferBase)) {
107  void* data = NULL;
108  gm->GetBufferPointerv(info->target, GL_BUFFER_MAP_POINTER, &data);
109  info->mapped_data = data;
110  }
111 }
112 
114 
119 
120 static void FillFramebufferAttachmentInfo(
121  const GraphicsManagerPtr& gm,
122  ResourceManager::FramebufferInfo::Attachment* info,
124  GLenum attachment) {
125  gm->GetFramebufferAttachmentParameteriv(
126  GL_FRAMEBUFFER, attachment, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE,
127  reinterpret_cast<GLint*>(&info->type));
128 
132  if ((info->type == GL_RENDERBUFFER) && (rb_info->id == 0U)) {
133  info->type = GL_NONE;
134  }
135 
136  if (info->type != GL_NONE)
137  gm->GetFramebufferAttachmentParameteriv(
138  GL_FRAMEBUFFER, attachment, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME,
139  reinterpret_cast<GLint*>(&info->value));
140  if (info->type == GL_TEXTURE) {
141  gm->GetFramebufferAttachmentParameteriv(
142  GL_FRAMEBUFFER, attachment, GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL,
143  reinterpret_cast<GLint*>(&info->level));
144  gm->GetFramebufferAttachmentParameteriv(
145  GL_FRAMEBUFFER, attachment,
146  GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE,
147  reinterpret_cast<GLint*>(&info->cube_face));
148  }
149 
151  if (info->type == GL_RENDERBUFFER) {
152  gm->BindRenderbuffer(GL_RENDERBUFFER, rb_info->id);
153  gm->GetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_WIDTH,
154  reinterpret_cast<GLint*>(&rb_info->width));
155  gm->GetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_HEIGHT,
156  reinterpret_cast<GLint*>(&rb_info->height));
157  gm->GetRenderbufferParameteriv(
158  GL_RENDERBUFFER, GL_RENDERBUFFER_INTERNAL_FORMAT,
159  reinterpret_cast<GLint*>(&rb_info->internal_format));
160  gm->GetRenderbufferParameteriv(
161  GL_RENDERBUFFER, GL_RENDERBUFFER_RED_SIZE,
162  reinterpret_cast<GLint*>(&rb_info->red_size));
163  gm->GetRenderbufferParameteriv(
164  GL_RENDERBUFFER, GL_RENDERBUFFER_GREEN_SIZE,
165  reinterpret_cast<GLint*>(&rb_info->green_size));
166  gm->GetRenderbufferParameteriv(
167  GL_RENDERBUFFER, GL_RENDERBUFFER_BLUE_SIZE,
168  reinterpret_cast<GLint*>(&rb_info->blue_size));
169  gm->GetRenderbufferParameteriv(
170  GL_RENDERBUFFER, GL_RENDERBUFFER_ALPHA_SIZE,
171  reinterpret_cast<GLint*>(&rb_info->alpha_size));
172  gm->GetRenderbufferParameteriv(
173  GL_RENDERBUFFER, GL_RENDERBUFFER_DEPTH_SIZE,
174  reinterpret_cast<GLint*>(&rb_info->depth_size));
175  gm->GetRenderbufferParameteriv(
176  GL_RENDERBUFFER, GL_RENDERBUFFER_STENCIL_SIZE,
177  reinterpret_cast<GLint*>(&rb_info->stencil_size));
178  }
179 }
180 
181 static void FillFramebufferInfo(const GraphicsManagerPtr& gm,
184  FillFramebufferAttachmentInfo(
185  gm, &info->color0, &info->color0_renderbuffer, GL_COLOR_ATTACHMENT0);
186  FillFramebufferAttachmentInfo(
187  gm, &info->depth, &info->depth_renderbuffer, GL_DEPTH_ATTACHMENT);
188  FillFramebufferAttachmentInfo(
189  gm, &info->stencil, &info->stencil_renderbuffer, GL_STENCIL_ATTACHMENT);
190 }
191 
193 
198 
199 static void FillSamplerInfo(const GraphicsManagerPtr& gm,
201  if (gm->IsFunctionGroupAvailable(GraphicsManager::kSamplerObjects)) {
202  gm->GetSamplerParameteriv(info->id, GL_TEXTURE_COMPARE_FUNC,
203  reinterpret_cast<GLint*>(&info->compare_func));
204  gm->GetSamplerParameteriv(info->id, GL_TEXTURE_COMPARE_MODE,
205  reinterpret_cast<GLint*>(&info->compare_mode));
206  gm->GetSamplerParameterfv(
207  info->id, GL_TEXTURE_MAX_ANISOTROPY_EXT,
208  reinterpret_cast<GLfloat*>(&info->max_anisotropy));
209  gm->GetSamplerParameteriv(info->id, GL_TEXTURE_MAG_FILTER,
210  reinterpret_cast<GLint*>(&info->mag_filter));
211  gm->GetSamplerParameterfv(info->id, GL_TEXTURE_MAX_LOD,
212  reinterpret_cast<GLfloat*>(&info->max_lod));
213  gm->GetSamplerParameteriv(info->id, GL_TEXTURE_MIN_FILTER,
214  reinterpret_cast<GLint*>(&info->min_filter));
215  gm->GetSamplerParameterfv(info->id, GL_TEXTURE_MIN_LOD,
216  reinterpret_cast<GLfloat*>(&info->min_lod));
217  gm->GetSamplerParameteriv(
218  info->id, GL_TEXTURE_WRAP_R, reinterpret_cast<GLint*>(&info->wrap_r));
219  gm->GetSamplerParameteriv(
220  info->id, GL_TEXTURE_WRAP_S, reinterpret_cast<GLint*>(&info->wrap_s));
221  gm->GetSamplerParameteriv(
222  info->id, GL_TEXTURE_WRAP_T, reinterpret_cast<GLint*>(&info->wrap_t));
223  }
224 }
225 
227 
232 
233 static void FillShaderInfo(const GraphicsManagerPtr& gm,
235  GLint boolean_value = GL_FALSE;
236  gm->GetShaderiv(
237  info->id, GL_SHADER_TYPE, reinterpret_cast<GLint*>(&info->type));
238  gm->GetShaderiv(info->id, GL_DELETE_STATUS, &boolean_value);
239  info->delete_status = static_cast<GLboolean>(boolean_value);
240  gm->GetShaderiv(info->id, GL_COMPILE_STATUS, &boolean_value);
241  info->compile_status = static_cast<GLboolean>(boolean_value);
242 
244  GLint length = 0;
245  gm->GetShaderiv(info->id, GL_SHADER_SOURCE_LENGTH, &length);
246  length = std::max(1, length);
247  {
248  base::ScopedAllocation<char> buffer(base::kShortTerm, length);
249  buffer.Get()[0] = 0;
250  gm->GetShaderSource(info->id, length, &length, buffer.Get());
251  info->source = buffer.Get();
252  }
253 
255  length = 0;
256  gm->GetShaderiv(info->id, GL_INFO_LOG_LENGTH, &length);
257  length = std::max(1, length);
258  {
259  base::ScopedAllocation<char> buffer(base::kShortTerm, length);
260  buffer.Get()[0] = 0;
261  gm->GetShaderInfoLog(info->id, length, &length, buffer.Get());
262  info->info_log = buffer.Get();
263  }
264 }
265 
267 
272 
273 template <typename T>
274 void FillShaderInputs(
275  const GraphicsManagerPtr& gm, GLuint id, GLenum active_enum,
276  GLenum length_enum,
277  const std::function<void(GLuint, GLuint, GLsizei, GLsizei*, GLint*, GLenum*,
278  GLchar*)>& GetInput,
279  const std::function<GLint(GLuint, const GLchar*)>& GetLocation,
280  std::vector<T>* infos) {
281  GLint count = 0;
282  gm->GetProgramiv(id, active_enum, &count);
283  infos->resize(count);
284  if (count) {
285  char name[2048];
287  for (GLint i = 0; i < count; ++i) {
289  GLsizei length = 0;
290  name[0] = 0;
291  GetInput(id, static_cast<GLuint>(i), 2047, &length, &(*infos)[i].size,
292  &(*infos)[i].type, name);
293  (*infos)[i].name = name;
294  (*infos)[i].index = GetLocation(id, name);
295  if ((*infos)[i].size > 1) {
296  for (GLint j = 0; j < (*infos)[i].size; ++j) {
297  std::ostringstream str;
298  str << name << "[" << j << "]";
299  const std::string array_name = str.str();
300  (*infos)[i].array_indices.push_back(
301  GetLocation(id, array_name.c_str()));
302  }
303  }
304  }
305  }
306 }
307 
308 template <typename T>
309 static void FillUniformValue(T* values,
310  ResourceManager::ProgramInfo::Uniform* uniform,
311  const base::AllocatorPtr& allocator) {
312  if (uniform->size > 1) {
313  uniform->value.InitArray<T>(allocator, uniform->size);
314  for (GLint i = 0; i < uniform->size; i++)
315  uniform->value.SetValueAt(i, values[i]);
316  } else {
317  uniform->value.Set(values[0]);
318  }
319 }
320 
321 template <int Dimension, typename T>
322 static void FillUniformValue(math::Matrix<Dimension, T>* values,
323  ResourceManager::ProgramInfo::Uniform* uniform,
324  const base::AllocatorPtr& allocator) {
325  if (uniform->size > 1) {
326  uniform->value.InitArray<math::Matrix<Dimension, T>>(allocator,
327  uniform->size);
328  for (GLint i = 0; i < uniform->size; i++)
329  uniform->value.SetValueAt(i, math::Transpose(values[i]));
330  } else {
331  uniform->value.Set(math::Transpose(values[0]));
332  }
333 }
334 
338 template <typename T>
339 static void GetGlUniformValue(const GraphicsManagerPtr& gm, GLuint id,
340  GLuint stride,
341  ResourceManager::ProgramInfo::Uniform* uniform,
342  void (GraphicsManager::*Getv)(GLuint, GLint, T*),
343  T* gl_values) {
345  if (uniform->size == 1) {
346  ((*gm).*Getv)(id, uniform->index, gl_values);
347  } else {
348  uint8* ptr = reinterpret_cast<uint8*>(gl_values);
349  for (GLint i = 0; i < uniform->size; ++i) {
350  T* values = reinterpret_cast<T*>(&ptr[i * stride]);
351  ((*gm).*Getv)(id, uniform->array_indices[i], values);
352  }
353  }
354 }
355 
356 template <typename T>
357 static void FillFloatUniformValue(
358  const GraphicsManagerPtr& gm, GLuint id,
359  ResourceManager::ProgramInfo::Uniform* uniform, T* values,
360  GLfloat* gl_values, const base::AllocatorPtr& allocator) {
362  GetGlUniformValue(gm, id, sizeof(T), uniform, &GraphicsManager::GetUniformfv,
363  gl_values);
364  FillUniformValue(values, uniform, allocator);
365 }
366 
367 template <typename T>
368 static void FillIntUniformValue(const GraphicsManagerPtr& gm, GLuint id,
369  ResourceManager::ProgramInfo::Uniform* uniform,
370  T* values, GLint* gl_values,
371  const base::AllocatorPtr& allocator) {
372  GetGlUniformValue(gm, id, sizeof(T), uniform, &GraphicsManager::GetUniformiv,
373  gl_values);
374  FillUniformValue(values, uniform, allocator);
375 }
376 
377 template <typename T>
378 static void FillUintUniformValue(const GraphicsManagerPtr& gm, GLuint id,
379  ResourceManager::ProgramInfo::Uniform* uniform,
380  T* values, GLuint* gl_values,
381  const base::AllocatorPtr& allocator) {
382  GetGlUniformValue(gm, id, sizeof(T), uniform, &GraphicsManager::GetUniformuiv,
383  gl_values);
384  FillUniformValue(values, uniform, allocator);
385 }
386 
387 static void FillUniformValues(
388  const GraphicsManagerPtr& gm, GLuint id,
389  std::vector<ResourceManager::ProgramInfo::Uniform>* uniforms) {
390  base::AllocatorPtr allocator =
393  const size_t count = uniforms->size();
394  for (size_t i = 0; i < count; ++i) {
395  ResourceManager::ProgramInfo::Uniform& u = (*uniforms)[i];
396  switch (u.type) {
397  case GL_FLOAT: {
398  base::ScopedAllocation<float> value(allocator, u.size);
399  FillFloatUniformValue<float>(gm, id, &u, value.Get(), value.Get(),
400  allocator);
401  break;
402  }
403  case GL_FLOAT_VEC2: {
404  base::ScopedAllocation<math::Vector2f> value(allocator, u.size);
405  FillFloatUniformValue<math::Vector2f>(gm, id, &u, value.Get(),
406  &(*value.Get())[0], allocator);
407  break;
408  }
409  case GL_FLOAT_VEC3: {
410  base::ScopedAllocation<math::Vector3f> value(allocator, u.size);
411  FillFloatUniformValue<math::Vector3f>(gm, id, &u, value.Get(),
412  &(*value.Get())[0], allocator);
413  break;
414  }
415  case GL_FLOAT_VEC4: {
416  base::ScopedAllocation<math::Vector4f> value(allocator, u.size);
417  FillFloatUniformValue<math::Vector4f>(gm, id, &u, value.Get(),
418  &(*value.Get())[0], allocator);
419  break;
420  }
422  case GL_INT:
423  case GL_INT_SAMPLER_1D:
424  case GL_INT_SAMPLER_1D_ARRAY:
425  case GL_INT_SAMPLER_2D:
426  case GL_INT_SAMPLER_2D_ARRAY:
427  case GL_INT_SAMPLER_3D:
428  case GL_INT_SAMPLER_CUBE:
429  case GL_INT_SAMPLER_CUBE_MAP_ARRAY:
430  case GL_SAMPLER_1D:
431  case GL_SAMPLER_1D_ARRAY:
432  case GL_SAMPLER_1D_ARRAY_SHADOW:
433  case GL_SAMPLER_1D_SHADOW:
434  case GL_SAMPLER_2D:
435  case GL_SAMPLER_2D_ARRAY:
436  case GL_SAMPLER_2D_ARRAY_SHADOW:
437  case GL_SAMPLER_2D_MULTISAMPLE:
438  case GL_SAMPLER_2D_MULTISAMPLE_ARRAY:
439  case GL_SAMPLER_2D_SHADOW:
440  case GL_SAMPLER_3D:
441  case GL_SAMPLER_CUBE:
442  case GL_SAMPLER_CUBE_MAP_ARRAY:
443  case GL_SAMPLER_CUBE_MAP_ARRAY_SHADOW:
444  case GL_SAMPLER_CUBE_SHADOW:
446  case GL_UNSIGNED_INT_SAMPLER_1D:
447  case GL_UNSIGNED_INT_SAMPLER_1D_ARRAY:
448  case GL_UNSIGNED_INT_SAMPLER_2D:
449  case GL_UNSIGNED_INT_SAMPLER_2D_ARRAY:
450  case GL_UNSIGNED_INT_SAMPLER_3D:
451  case GL_UNSIGNED_INT_SAMPLER_CUBE:
452  case GL_UNSIGNED_INT_SAMPLER_CUBE_MAP_ARRAY: {
453  base::ScopedAllocation<int> value(allocator, u.size);
454  FillIntUniformValue<int>(gm, id, &u, value.Get(), value.Get(),
455  allocator);
456  break;
457  }
458  case GL_INT_VEC2: {
459  base::ScopedAllocation<math::Vector2i> value(allocator, u.size);
460  FillIntUniformValue<math::Vector2i>(gm, id, &u, value.Get(),
461  &(*value.Get())[0], allocator);
462  break;
463  }
464  case GL_INT_VEC3: {
465  base::ScopedAllocation<math::Vector3i> value(allocator, u.size);
466  FillIntUniformValue<math::Vector3i>(gm, id, &u, value.Get(),
467  &(*value.Get())[0], allocator);
468  break;
469  }
470  case GL_INT_VEC4: {
471  base::ScopedAllocation<math::Vector4i> value(allocator, u.size);
472  FillIntUniformValue<math::Vector4i>(gm, id, &u, value.Get(),
473  &(*value.Get())[0], allocator);
474  break;
475  }
476  case GL_UNSIGNED_INT: {
477  base::ScopedAllocation<uint32> value(allocator, u.size);
478  FillUintUniformValue<uint32>(gm, id, &u, value.Get(), value.Get(),
479  allocator);
480  break;
481  }
482  case GL_UNSIGNED_INT_VEC2: {
483  base::ScopedAllocation<math::Vector2ui> value(allocator, u.size);
484  FillUintUniformValue<math::Vector2ui>(gm, id, &u, value.Get(),
485  &(*value.Get())[0], allocator);
486  break;
487  }
488  case GL_UNSIGNED_INT_VEC3: {
489  base::ScopedAllocation<math::Vector3ui> value(allocator, u.size);
490  FillUintUniformValue<math::Vector3ui>(gm, id, &u, value.Get(),
491  &(*value.Get())[0], allocator);
492  break;
493  }
494  case GL_UNSIGNED_INT_VEC4: {
495  base::ScopedAllocation<math::Vector4ui> value(allocator, u.size);
496  FillUintUniformValue<math::Vector4ui>(gm, id, &u, value.Get(),
497  &(*value.Get())[0], allocator);
498  break;
499  }
500  case GL_FLOAT_MAT2: {
501  base::ScopedAllocation<math::Matrix2f> value(allocator, u.size);
502  FillFloatUniformValue<math::Matrix2f>(gm, id, &u, value.Get(),
503  &(*value.Get())[0][0], allocator);
504  break;
505  }
506  case GL_FLOAT_MAT3: {
507  base::ScopedAllocation<math::Matrix3f> value(allocator, u.size);
508  FillFloatUniformValue<math::Matrix3f>(gm, id, &u, value.Get(),
509  &(*value.Get())[0][0], allocator);
510  break;
511  }
512  case GL_FLOAT_MAT4: {
513  base::ScopedAllocation<math::Matrix4f> value(allocator, u.size);
514  FillFloatUniformValue<math::Matrix4f>(gm, id, &u, value.Get(),
515  &(*value.Get())[0][0], allocator);
516  break;
517  }
518 #if !defined(ION_COVERAGE) // COV_NF_START
519  default:
520  break;
521 #endif // COV_NF_END
522  }
523  }
524 }
525 
526 static void FillProgramInfo(const GraphicsManagerPtr& gm,
528  using std::bind;
529  using std::placeholders::_1;
530  using std::placeholders::_2;
531  using std::placeholders::_3;
532  using std::placeholders::_4;
533  using std::placeholders::_5;
534  using std::placeholders::_6;
535  using std::placeholders::_7;
536 
538  GLint boolean_value = GL_FALSE;
539  gm->GetProgramiv(info->id, GL_DELETE_STATUS, &boolean_value);
540  info->delete_status = static_cast<GLboolean>(boolean_value);
541  gm->GetProgramiv(info->id, GL_LINK_STATUS, &boolean_value);
542  info->link_status = static_cast<GLboolean>(boolean_value);
543  gm->GetProgramiv(info->id, GL_VALIDATE_STATUS, &boolean_value);
544  info->validate_status = static_cast<GLboolean>(boolean_value);
545 
547  GLint info_log_length = 0;
548  gm->GetProgramiv(info->id, GL_INFO_LOG_LENGTH, &info_log_length);
549  info_log_length = std::max(1, info_log_length);
550  {
551  base::ScopedAllocation<char> buffer(base::kShortTerm, info_log_length);
552  buffer.Get()[0] = 0;
553  gm->GetProgramInfoLog(
554  info->id, info_log_length, &info_log_length, buffer.Get());
555  info->info_log = buffer.Get();
556  }
557  info->info_log.resize(info_log_length);
558 
560  FillShaderInputs(
561  gm, info->id, GL_ACTIVE_ATTRIBUTES, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH,
562  bind(&GraphicsManager::GetActiveAttrib, gm.Get(),
563  _1, _2, _3, _4, _5, _6, _7),
564  bind(&GraphicsManager::GetAttribLocation, gm.Get(), _1, _2),
565  &info->attributes);
567  FillShaderInputs(
568  gm, info->id, GL_ACTIVE_UNIFORMS, GL_ACTIVE_UNIFORM_MAX_LENGTH,
569  bind(&GraphicsManager::GetActiveUniform, gm.Get(),
570  _1, _2, _3, _4, _5, _6, _7),
571  bind(&GraphicsManager::GetUniformLocation, gm.Get(), _1, _2),
572  &info->uniforms);
574  FillUniformValues(gm, info->id, &info->uniforms);
575 }
576 
578 
583 
584 static void FillStringsAndVersions(const GraphicsManagerPtr& gm,
585  ResourceManager::PlatformInfo* info) {
586  info->renderer = reinterpret_cast<const char*>(gm->GetString(GL_RENDERER));
587  info->vendor = reinterpret_cast<const char*>(gm->GetString(GL_VENDOR));
588  info->version_string =
589  reinterpret_cast<const char*>(gm->GetString(GL_VERSION));
590 
591  const size_t dot_pos = info->version_string.find('.');
592  info->major_version = 0;
593  info->minor_version = 0;
594  info->glsl_version = 0;
595  if (dot_pos != std::string::npos && dot_pos > 0 &&
596  dot_pos < info->version_string.length() - 1) {
597  info->major_version = info->version_string[dot_pos - 1] - '0';
598  info->minor_version = info->version_string[dot_pos + 1] - '0';
599  }
600  const char* glsl_version_string =
601  reinterpret_cast<const char*>(gm->GetString(GL_SHADING_LANGUAGE_VERSION));
602  const std::vector<std::string> strings = base::SplitString(
603  glsl_version_string, " ");
604  const size_t count = strings.size();
605  for (size_t i = 0; i < count; ++i) {
606  size_t pos = strings[i].find(".");
607  if (pos != std::string::npos) {
608  const std::vector<std::string> numbers = base::SplitString(strings[i],
609  ".");
610  if (numbers.size() == 2)
611  info->glsl_version = 100 * base::StringToInt32(numbers[0]) +
612  base::StringToInt32(numbers[1]);
613  }
614  }
615 
616  if (const char* extensions =
617  reinterpret_cast<const char*>(gm->GetString(GL_EXTENSIONS))) {
618  info->extensions = extensions;
619  }
620 }
621 
622 static void FillPlatformInfo(const GraphicsManagerPtr& gm,
623  ResourceManager::PlatformInfo* info) {
625  gm->GetFloatv(GL_ALIASED_LINE_WIDTH_RANGE, info->aliased_line_width_range);
626  if (gm->GetGlApiStandard() == GraphicsManager::kDesktop &&
627  gm->GetGlVersion() >= 30)
628  gm->GetFloatv(GL_POINT_SIZE_RANGE, info->aliased_point_size_range);
629  else
630  gm->GetFloatv(GL_ALIASED_POINT_SIZE_RANGE, info->aliased_point_size_range);
631 
633  info->max_color_attachments = -1;
634  gm->GetIntegerv(GL_MAX_COLOR_ATTACHMENTS,
635  &info->max_color_attachments);
636  info->max_combined_texture_image_units = -1;
637  gm->GetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS,
638  &info->max_combined_texture_image_units);
639  info->max_combined_texture_image_units = -1;
640  gm->GetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS,
641  &info->max_combined_texture_image_units);
642  info->max_cube_map_texture_size = -1;
643  gm->GetIntegerv(GL_MAX_CUBE_MAP_TEXTURE_SIZE,
644  &info->max_cube_map_texture_size);
645  info->max_draw_buffers = -1;
646  gm->GetIntegerv(GL_MAX_DRAW_BUFFERS,
647  &info->max_draw_buffers);
648  info->max_fragment_uniform_vectors = -1;
649  gm->GetIntegerv(GL_MAX_FRAGMENT_UNIFORM_VECTORS,
650  &info->max_fragment_uniform_vectors);
651  info->max_renderbuffer_size = -1;
652  gm->GetIntegerv(GL_MAX_RENDERBUFFER_SIZE, &info->max_renderbuffer_size);
653  info->max_texture_image_units = -1;
654  gm->GetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &info->max_texture_image_units);
655  info->max_texture_size = -1;
656  gm->GetIntegerv(GL_MAX_TEXTURE_SIZE, &info->max_texture_size);
657  info->max_varying_vectors = -1;
658  gm->GetIntegerv(GL_MAX_VARYING_VECTORS, &info->max_varying_vectors);
659  info->max_vertex_attribs = -1;
660  gm->GetIntegerv(GL_MAX_VERTEX_ATTRIBS, &info->max_vertex_attribs);
661  info->max_vertex_texture_image_units = -1;
662  gm->GetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS,
663  &info->max_vertex_texture_image_units);
664  info->max_vertex_uniform_vectors = -1;
665  gm->GetIntegerv(GL_MAX_VERTEX_UNIFORM_VECTORS,
666  &info->max_vertex_uniform_vectors);
667  info->max_viewport_dims[0] = -1;
668  info->max_viewport_dims[1] = -1;
669  gm->GetIntegerv(GL_MAX_VIEWPORT_DIMS, info->max_viewport_dims);
670 
673  info->max_transform_feedback_buffers = -1;
674  info->max_transform_feedback_interleaved_components = -1;
675  info->max_transform_feedback_separate_attribs = -1;
676  info->max_transform_feedback_separate_components = -1;
677  info->transform_feedback_varying_max_length = -1;
678  if (gm->IsFunctionGroupAvailable(GraphicsManager::kTransformFeedback)) {
679  gm->GetIntegerv(GL_MAX_TRANSFORM_FEEDBACK_BUFFERS,
680  &info->max_transform_feedback_buffers);
681  gm->GetIntegerv(GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS,
682  &info->max_transform_feedback_interleaved_components);
683  gm->GetIntegerv(GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS,
684  &info->max_transform_feedback_separate_attribs);
685  gm->GetIntegerv(GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS,
686  &info->max_transform_feedback_separate_components);
687  gm->GetIntegerv(GL_TRANSFORM_FEEDBACK_VARYING_MAX_LENGTH,
688  &info->transform_feedback_varying_max_length);
689  }
690 
692  GLint count = 0;
693  gm->GetIntegerv(GL_NUM_COMPRESSED_TEXTURE_FORMATS, &count);
694  info->compressed_texture_formats.resize(count);
695  if (count)
696  gm->GetIntegerv(
697  GL_COMPRESSED_TEXTURE_FORMATS,
698  reinterpret_cast<GLint*>(&info->compressed_texture_formats[0]));
699 
700  count = 0;
701  gm->GetIntegerv(GL_NUM_SHADER_BINARY_FORMATS, &count);
702  info->shader_binary_formats.resize(count);
703  if (count)
704  gm->GetIntegerv(
705  GL_SHADER_BINARY_FORMATS,
706  reinterpret_cast<GLint*>(&info->shader_binary_formats[0]));
707 
708  FillStringsAndVersions(gm, info);
709 }
710 
712 
717 
718 static void FillTextureInfo(const GraphicsManagerPtr& gm,
721  gm->ActiveTexture(info->unit);
722  gm->GetTexParameterfv(info->target, GL_TEXTURE_MAX_ANISOTROPY_EXT,
723  reinterpret_cast<GLfloat*>(&info->max_anisotropy));
724  gm->GetTexParameteriv(info->target, GL_TEXTURE_MAG_FILTER,
725  reinterpret_cast<GLint*>(&info->mag_filter));
726  gm->GetTexParameteriv(info->target, GL_TEXTURE_MIN_FILTER,
727  reinterpret_cast<GLint*>(&info->min_filter));
728  gm->GetTexParameteriv(info->target, GL_TEXTURE_WRAP_S,
729  reinterpret_cast<GLint*>(&info->wrap_s));
730  gm->GetTexParameteriv(info->target, GL_TEXTURE_WRAP_T,
731  reinterpret_cast<GLint*>(&info->wrap_t));
732  if (gm->GetGlVersion() > 20) {
733  gm->GetIntegerv(GL_SAMPLER_BINDING,
734  reinterpret_cast<GLint*>(&info->sampler));
735  gm->GetTexParameteriv(info->target, GL_TEXTURE_BASE_LEVEL,
736  reinterpret_cast<GLint*>(&info->base_level));
737  gm->GetTexParameteriv(info->target, GL_TEXTURE_COMPARE_FUNC,
738  reinterpret_cast<GLint*>(&info->compare_func));
739  gm->GetTexParameteriv(info->target, GL_TEXTURE_COMPARE_MODE,
740  reinterpret_cast<GLint*>(&info->compare_mode));
741  gm->GetTexParameteriv(info->target, GL_TEXTURE_MAX_LEVEL,
742  reinterpret_cast<GLint*>(&info->max_level));
743  gm->GetTexParameterfv(info->target, GL_TEXTURE_MAX_LOD,
744  reinterpret_cast<GLfloat*>(&info->max_lod));
745  gm->GetTexParameterfv(info->target, GL_TEXTURE_MIN_LOD,
746  reinterpret_cast<GLfloat*>(&info->min_lod));
747  gm->GetTexParameteriv(info->target, GL_TEXTURE_SWIZZLE_R,
748  reinterpret_cast<GLint*>(&info->swizzle_r));
749  gm->GetTexParameteriv(info->target, GL_TEXTURE_SWIZZLE_G,
750  reinterpret_cast<GLint*>(&info->swizzle_g));
751  gm->GetTexParameteriv(info->target, GL_TEXTURE_SWIZZLE_B,
752  reinterpret_cast<GLint*>(&info->swizzle_b));
753  gm->GetTexParameteriv(info->target, GL_TEXTURE_SWIZZLE_A,
754  reinterpret_cast<GLint*>(&info->swizzle_a));
755  gm->GetTexParameteriv(info->target, GL_TEXTURE_WRAP_R,
756  reinterpret_cast<GLint*>(&info->wrap_r));
757  }
758  if (gm->IsFunctionGroupAvailable(GraphicsManager::kTextureMultisample)) {
759  gm->GetTexParameteriv(info->target, GL_TEXTURE_SAMPLES,
760  reinterpret_cast<GLint*>(&info->samples));
761  gm->GetTexParameteriv(info->target, GL_TEXTURE_FIXED_SAMPLE_LOCATIONS,
762  reinterpret_cast<GLint*>(
763  &info->fixed_sample_locations));
764  }
765 }
766 
767 } // anonymous namespace
768 
770  : graphics_manager_(gm) {
771 }
772 
774 }
775 
776 template <> ION_API
781  return &array_requests_;
782 }
783 
784 template <> ION_API
785 std::vector<ResourceManager::ResourceRequest<BufferObject,
789  return &buffer_requests_;
790 }
791 
792 template <> ION_API std::vector<
793  ResourceManager::ResourceRequest<FramebufferObject,
797  return &framebuffer_requests_;
798 }
799 
800 template <> ION_API
801 std::vector<ResourceManager::DataRequest<ResourceManager::PlatformInfo> >*
802 ResourceManager::GetDataRequestVector<ResourceManager::PlatformInfo>() {
803  return &platform_requests_;
804 }
805 
806 template <> ION_API
807 std::vector<ResourceManager::ResourceRequest<ShaderProgram,
811  return &program_requests_;
812 }
813 
814 template <> ION_API std::vector<
815  ResourceManager::ResourceRequest<Sampler, ResourceManager::SamplerInfo> >*
818  return &sampler_requests_;
819 }
820 
821 template <> ION_API std::vector<
822  ResourceManager::ResourceRequest<Shader, ResourceManager::ShaderInfo> >*
825  return &shader_requests_;
826 }
827 
828 template <> ION_API
829 std::vector<ResourceManager::ResourceRequest<TextureBase,
833  return &texture_requests_;
834 }
835 
836 template <> ION_API
837 std::vector<ResourceManager::DataRequest<ResourceManager::TextureImageInfo> >*
838 ResourceManager::GetDataRequestVector<ResourceManager::TextureImageInfo>() {
839  return &texture_image_requests_;
840 }
841 
843  const InfoCallback<PlatformInfo>::Type& callback) {
844  base::LockGuard lock_guard(&this->request_mutex_);
845  GetDataRequestVector<PlatformInfo>()->push_back(
846  DataRequest<PlatformInfo>(0, callback));
847 }
848 
850  GLuint id, const InfoCallback<TextureImageInfo>::Type& callback) {
851  GetDataRequestVector<TextureImageInfo>()->push_back(
852  DataRequest<TextureImageInfo>(id, callback));
853 }
854 
855 template <>
857  FillArrayInfo(graphics_manager_, info);
858 }
859 
860 template <>
862  FillBufferInfo(graphics_manager_, info);
863 }
864 
865 template <>
868  FillFramebufferInfo(graphics_manager_, info);
869 }
870 
871 template <>
873  FillProgramInfo(graphics_manager_, info);
874 }
875 
876 template <>
878  FillSamplerInfo(graphics_manager_, info);
879 }
880 
881 template <>
883  FillShaderInfo(graphics_manager_, info);
884 }
885 
886 template <>
888  FillPlatformInfo(graphics_manager_, info);
889 }
890 
891 template <>
893  FillTextureInfo(graphics_manager_, info);
894 }
895 
899 
900 } // namespace gfx
901 } // namespace ion
std::string buffer
kShortTerm is used for objects that are very transient in nature, such as scratch memory used to comp...
Definition: allocator.h:36
A ShaderInfo corresponds to an OpenGL Shader Object.
A SamplerInfo corresponds to an OpenGL Sampler Object.
const std::string & str
gfx::BufferInfo< BufferTargetInfo > BufferInfo
ResourceManager(const GraphicsManagerPtr &gm)
A valid GraphicsManagerPtr must be passed to the constructor.
std::string type
Definition: printer.cc:353
gfx::FramebufferInfo< FramebufferResourceInfo > FramebufferInfo
double value
#define GL_SAMPLER_EXTERNAL_OES
Definition: glheaders.h:912
std::function< void(const std::vector< T > &infos)> Type
void RequestTextureImage(GLuint id, const InfoCallback< TextureImageInfo >::Type &callback)
Executes the callback passing a TextureImageInfo that contains a pointer to the texture that has the ...
std::vector< std::string > ION_API SplitString(const std::string &str, const std::string &delimiters)
Splits a string into a vector of substrings, given a set of delimiter characters (expressed as a stri...
Definition: stringutils.cc:187
uint32 length
SharedPtr< Allocator > AllocatorPtr
Definition: allocator.h:51
uint32 id
Struct for getting information about the local OpenGL platform.
#define GL_ALIASED_POINT_SIZE_RANGE
These constants are not always defined in OpenGL header files.
Definition: glheaders.h:138
A LockGuard locks a mutex when created, and unlocks it when destroyed.
Definition: lockguards.h:90
gfx::TextureInfo< TextureResourceInfo > TextureInfo
void FillInfoFromOpenGL(InfoType *info)
Performs OpenGL calls to fill in info details, specialized for each type derived from ResourceInfo...
Wrapper struct for resource info requests.
Struct containing information about a texture and its image(s).
gfx::ProgramInfo< ResourceInfo > ProgramInfo
std::string name
Definition: printer.cc:324
port::Mutex request_mutex_
For locking access to request vectors.
int32 ION_API StringToInt32(const std::string &str)
Extracts and returns an integral value from str.
Definition: stringutils.cc:328
An AttributeArray represents a collection of Attributes used to describe the vertices of a Shape...
void RequestPlatformInfo(const InfoCallback< PlatformInfo >::Type &callback)
Requests information about the local OpenGL platform.
gfx::SamplerInfo< ResourceInfo > SamplerInfo
std::vector< ResourceRequest< HolderType, InfoType > > * GetResourceRequestVector()
Returns a pointer to the vector of requests for the templated holder and info types.
A ProgramInfo corresponds to an OpenGL Program Object.
Wrapper struct for data requests.
A BufferInfo corresponds to an OpenGL Framebuffer Object.
base::ReferentPtr< GraphicsManager >::Type GraphicsManagerPtr
Convenience typedef for shared pointer to a GraphicsManager.
gfx::RenderbufferInfo< ResourceInfo > RenderbufferInfo
A BufferInfo corresponds to an OpenGL Buffer Object.
Definition: openglobjects.h:85
gfx::ArrayInfo< ArrayResourceInfo > ArrayInfo
The actual info types.
framebuffer alpha dfactor const GLvoid usage alpha const GLvoid data border const GLuint buffers const GLuint renderbuffers count renderbuffer GLuint framebuffers GLsizei GLint GLenum GLchar name GLsizei GLuint shaders GLint data GLsizei GLchar info_log GLint params GLint GLint precision GLint params GLint params GetUniformiv
The below structs correspond to OpenGL "objects." For example, a BufferObject corresponds to an OpenG...
Definition: openglobjects.h:42
A TextureInfo corresponds to an OpenGL Texture Object.
A SharedPtr is a smart shared pointer to an instance of some class that implements reference counting...
Definition: sharedptr.h:60
kMediumTerm is used for objects that don't fall into the kShortTerm or kLongTerm categories.
Definition: allocator.h:40
framebuffer alpha dfactor const GLvoid usage alpha const GLvoid data border const GLuint buffers const GLuint renderbuffers count renderbuffer GLuint framebuffers GetActiveAttrib
Matrix< Dimension, T > Transpose(const Matrix< Dimension, T > &m)
Public functions.
Definition: matrixutils.h:65
static const AllocatorPtr & GetDefaultAllocatorForLifetime(AllocationLifetime lifetime)
gfx::ShaderInfo< ResourceInfo > ShaderInfo