openglsupport.cpp File Reference
#include <main.h>
#include <iostream>
#include <string>
#include <GL/glew.h>
#include <Eigen/OpenGLSupport>
#include <GL/freeglut.h>

Macros

#define VERIFY_MATRIX(CODE, REF)
 
#define VERIFY_UNIFORM(SUFFIX, NAME, TYPE)
 
#define VERIFY_UNIFORMi(NAME, TYPE)
 

Functions

void printProgramInfoLog (GLuint objectID)
 
void printShaderInfoLog (GLuint objectID)
 
GLint createProgram (const char *vtx, const char *frg, bool print_errors=true)
 
GLint createProgram (const std::string &vtx, const std::string &frg, bool print_errors=true)
 
std::string getGlslVersionString (int gl_major_version, int gl_minor_version)
 
void find_and_replace (std::string &str, const std::string &find, const std::string &replace)
 
std::string format (const std::string &str, const std::vector< std::string > &find, const std::vector< std::string > &replace)
 
void openglsupport_test_loop ()
 
 EIGEN_DECLARE_TEST (openglsupport)
 

Macro Definition Documentation

◆ VERIFY_MATRIX

#define VERIFY_MATRIX (   CODE,
  REF 
)
Value:
{ \
glMatrixMode(GL_MODELVIEW); \
glLoadIdentity(); \
CODE; \
Matrix<float, 4, 4, ColMajor> m; \
m.setZero(); \
glGet(GL_MODELVIEW_MATRIX, m); \
if (!(REF).cast<float>().isApprox(m)) { \
std::cerr << "Expected:\n" \
<< ((REF).cast<float>()) << "\n" \
<< "got\n" \
<< m << "\n\n"; \
} \
VERIFY_IS_APPROX((REF).cast<float>(), m); \
}
int * m
Definition: level2_cplx_impl.h:294
EIGEN_DEVICE_FUNC bool isApprox(const Scalar &x, const Scalar &y, const typename NumTraits< Scalar >::Real &precision=NumTraits< Scalar >::dummy_precision())
Definition: MathFunctions.h:1923

◆ VERIFY_UNIFORM

#define VERIFY_UNIFORM (   SUFFIX,
  NAME,
  TYPE 
)
Value:
{ \
TYPE value; \
value.setRandom(); \
TYPE data; \
int loc = glGetUniformLocation(prg_id, #NAME); \
VERIFY((loc != -1) && "uniform not found"); \
glUniform(loc, value); \
EIGEN_CAT(glGetUniform, SUFFIX)(prg_id, loc, data.data()); \
if (!value.isApprox(data)) { \
std::cerr << "Expected:\n" \
<< value << "\n" \
<< "got\n" \
<< data << "\n\n"; \
} \
VERIFY_IS_APPROX(value, data); \
}
int data[]
Definition: Map_placement_new.cpp:1
squared absolute value
Definition: GlobalFunctions.h:87

◆ VERIFY_UNIFORMi

#define VERIFY_UNIFORMi (   NAME,
  TYPE 
)
Value:
{ \
TYPE value = TYPE::Random().eval().cast<float>().cast<TYPE::Scalar>(); \
TYPE data; \
int loc = glGetUniformLocation(prg_id, #NAME); \
VERIFY((loc != -1) && "uniform not found"); \
glUniform(loc, value); \
glGetUniformiv(prg_id, loc, (GLint*)data.data()); \
if (!value.isApprox(data)) { \
std::cerr << "Expected:\n" \
<< value << "\n" \
<< "got\n" \
<< data << "\n\n"; \
} \
VERIFY_IS_APPROX(value, data); \
}

Function Documentation

◆ createProgram() [1/2]

GLint createProgram ( const char vtx,
const char frg,
bool  print_errors = true 
)
104  {
105  GLint prg_id = glCreateProgram();
106  GLint vtx_id = glCreateShader(GL_VERTEX_SHADER);
107  GLint frg_id = glCreateShader(GL_FRAGMENT_SHADER);
108  GLint ok;
109 
110  glShaderSource(vtx_id, 1, &vtx, 0);
111  glCompileShader(vtx_id);
112  glGetShaderiv(vtx_id, GL_COMPILE_STATUS, &ok);
113  if (!ok) {
114  if (print_errors) {
115  std::cerr << "vtx compilation failed\n";
116  std::cerr << "Source:\n" << vtx << "\n";
117  printShaderInfoLog(vtx_id);
118  }
119  glDeleteShader(vtx_id);
120  return GL_ZERO;
121  }
122 
123  glShaderSource(frg_id, 1, &frg, 0);
124  glCompileShader(frg_id);
125  glGetShaderiv(frg_id, GL_COMPILE_STATUS, &ok);
126  if (!ok) {
127  if (print_errors) {
128  std::cerr << "frg compilation failed.\n";
129  std::cerr << "Source:\n" << frg << "\n";
130  printShaderInfoLog(frg_id);
131  }
132  glDeleteShader(vtx_id);
133  glDeleteShader(frg_id);
134  return GL_ZERO;
135  }
136 
137  glAttachShader(prg_id, vtx_id);
138  glAttachShader(prg_id, frg_id);
139  glLinkProgram(prg_id);
140 
141  // Delete shaders once linked.
142  glDeleteShader(vtx_id);
143  glDeleteShader(frg_id);
144  glGetProgramiv(prg_id, GL_LINK_STATUS, &ok);
145  if (!ok) {
146  if (print_errors) {
147  std::cerr << "linking failed.\n";
148  printProgramInfoLog(prg_id);
149  }
150  glDeleteProgram(prg_id);
151  return GL_ZERO;
152  }
153 
154  glUseProgram(prg_id);
155  return prg_id;
156 }
void printProgramInfoLog(GLuint objectID)
Definition: openglsupport.cpp:80
void printShaderInfoLog(GLuint objectID)
Definition: openglsupport.cpp:92

References printProgramInfoLog(), and printShaderInfoLog().

Referenced by createProgram(), and openglsupport_test_loop().

◆ createProgram() [2/2]

GLint createProgram ( const std::string &  vtx,
const std::string &  frg,
bool  print_errors = true 
)
158  {
159  return createProgram(vtx.c_str(), frg.c_str(), print_errors);
160 }
GLint createProgram(const char *vtx, const char *frg, bool print_errors=true)
Definition: openglsupport.cpp:104

References createProgram().

◆ EIGEN_DECLARE_TEST()

EIGEN_DECLARE_TEST ( openglsupport  )
556  {
557  int argc = 0;
558  glutInit(&argc, 0);
559 
560  GLint glut_display_mode = GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH;
561 
562 #ifndef EIGEN_LEGACY_OPENGL
563  // Initialize 3.2+ OpenGL context.
564 #if defined(__APPLE_CC__)
565  glut_display_mode |= GLUT_3_2_CORE_PROFILE;
566 #elif defined(FREEGLUT)
567  glutInitContextVersion(3, 2);
568  glutInitContextFlags(GLUT_FORWARD_COMPATIBLE);
569  glutInitContextProfile(GLUT_CORE_PROFILE);
570 #endif
571 #endif
572 
573  glutInitDisplayMode(glut_display_mode);
574  glutInitWindowPosition(0, 0);
575  glutInitWindowSize(10, 10);
576 
577  int window = glutCreateWindow("Eigen");
578  if (window <= 0) {
579  std::cerr << "Error: Unable to create GLUT Window.\n";
580  exit(1);
581  }
582 
583  glewExperimental = GL_TRUE;
584  if (glewInit() != GLEW_OK) {
585  std::cerr << "Warning: Failed to initialize GLEW.\n";
586  exit(1);
587  }
588 
589  // Run test in display, otherwise GLUT fails to clean up and leads to memory
590  // access errors on exit.
591  glutDisplayFunc(openglsupport_test_loop);
592  glutMainLoop();
593  glutDestroyWindow(window);
594 }
void openglsupport_test_loop()
Definition: openglsupport.cpp:228

References openglsupport_test_loop().

◆ find_and_replace()

void find_and_replace ( std::string &  str,
const std::string &  find,
const std::string &  replace 
)
206  {
207  size_t loc = 0;
208  size_t flen = find.length();
209  size_t rlen = replace.length();
210  while ((loc = str.find(find, loc)) != std::string::npos) {
211  str.replace(loc, flen, replace);
212  loc += rlen;
213  }
214 }
str
Definition: compute_granudrum_aor.py:141

References compute_granudrum_aor::str.

Referenced by format().

◆ format()

std::string format ( const std::string &  str,
const std::vector< std::string > &  find,
const std::vector< std::string > &  replace 
)
218  {
219  std::string out = str;
220  for (std::size_t i = 0; i < find.size(); ++i) {
221  find_and_replace(out, find[i], replace[i]);
222  }
223  return out;
224 }
int i
Definition: BiCGSTAB_step_by_step.cpp:9
std::string string(const unsigned &i)
Definition: oomph_definitions.cc:286
void find_and_replace(std::string &str, const std::string &find, const std::string &replace)
Definition: openglsupport.cpp:206
std::ofstream out("Result.txt")

References find_and_replace(), i, out(), compute_granudrum_aor::str, and oomph::Global_string_for_annotation::string().

Referenced by eigenlldb.EigenSparseMatrixChildProvider::_child_name(), Loadstatistics::load_stat_file(), openglsupport_test_loop(), Logger< L, ASSERTS >::operator()(), DPMBase::outputXBallsData(), fix_broken_doxygen_formulae::process_file(), Particles2023AnalysisHung::random_forest(), DPMBase::readDataFile(), DPMBase::readNextDataFile(), fix_broken_doxygen_formulae::run(), helpers::stringFormat(), Particles2023AnalysisHung::write_calibration_script(), inflowFromPeriodic::writeXBallsScript(), and ChuteWithPeriodicInflow::writeXBallsScript().

◆ getGlslVersionString()

std::string getGlslVersionString ( int  gl_major_version,
int  gl_minor_version 
)
162  {
163  switch (gl_major_version) {
164  case 2:
165  switch (gl_minor_version) {
166  case 0:
167  return "#version 110";
168  case 1:
169  return "#version 120";
170  }
171  break;
172  case 3:
173  switch (gl_minor_version) {
174  case 0:
175  return "#version 130";
176  case 1:
177  return "#version 140";
178  case 2:
179  return "#version 150";
180  case 3:
181  return "#version 330";
182  }
183  break;
184  case 4:
185  switch (gl_minor_version) {
186  case 0:
187  return "#version 400";
188  case 1:
189  return "#version 410";
190  case 2:
191  return "#version 420";
192  case 3:
193  return "#version 430";
194  case 4:
195  return "#version 440";
196  case 5:
197  return "#version 450";
198  case 6:
199  return "#version 460";
200  }
201  break;
202  }
203  return "";
204 }

Referenced by openglsupport_test_loop().

◆ openglsupport_test_loop()

void openglsupport_test_loop ( )
228  {
229  // Get context info.
230  const GLubyte* gl_version_string = glGetString(GL_VERSION);
231  std::cerr << "GL version: " << gl_version_string << std::endl;
232  std::cerr << "GLSL version: " << glGetString(GL_SHADING_LANGUAGE_VERSION) << std::endl;
233  // Parse version from string since GL_MAJOR_VERSION is only supported in GL 3.0+.
234  // Version string guaranteed to be <major>.<minor><vendor extension>.
235  GLint gl_major_version = gl_version_string[0] - '0';
236  GLint gl_minor_version = gl_version_string[2] - '0';
237  bool legacy_gl = gl_major_version < 3 || (gl_major_version == 3 && gl_minor_version < 2);
238 
239  // Fixed-function pipeline removed in OpenGL 3.2.
240  if (legacy_gl) {
241  // Draw a basic triangle.
242  Vector3f v3f;
243  Matrix3f rot;
244  glBegin(GL_POINTS);
245  {
246  glVertex(v3f);
247  glVertex(2 * v3f + v3f);
248  glVertex(rot * v3f);
249  }
250  glEnd();
251 
252  // 4x4 matrices
253  Matrix4f mf44;
254  mf44.setRandom();
255  VERIFY_MATRIX(glLoadMatrix(mf44), mf44);
256  VERIFY_MATRIX(glMultMatrix(mf44), mf44);
257  Matrix4d md44;
258  md44.setRandom();
259  VERIFY_MATRIX(glLoadMatrix(md44), md44);
260  VERIFY_MATRIX(glMultMatrix(md44), md44);
261 
262  // Quaternion
263  Quaterniond qd(AngleAxisd(internal::random<double>(), Vector3d::Random()));
264  VERIFY_MATRIX(glRotate(qd), Projective3d(qd).matrix());
265 
266  Quaternionf qf(AngleAxisf(internal::random<double>(), Vector3f::Random()));
267  VERIFY_MATRIX(glRotate(qf), Projective3f(qf).matrix());
268 
269  // 3D Transform
271  acf3.matrix().setRandom();
272  VERIFY_MATRIX(glLoadMatrix(acf3), Projective3f(acf3).matrix());
273  VERIFY_MATRIX(glMultMatrix(acf3), Projective3f(acf3).matrix());
274 
275  Transform<float, 3, Affine> af3(acf3);
276  VERIFY_MATRIX(glLoadMatrix(af3), Projective3f(af3).matrix());
277  VERIFY_MATRIX(glMultMatrix(af3), Projective3f(af3).matrix());
278 
280  pf3.matrix().setRandom();
281  VERIFY_MATRIX(glLoadMatrix(pf3), Projective3f(pf3).matrix());
282  VERIFY_MATRIX(glMultMatrix(pf3), Projective3f(pf3).matrix());
283 
285  acd3.matrix().setRandom();
286  VERIFY_MATRIX(glLoadMatrix(acd3), Projective3d(acd3).matrix());
287  VERIFY_MATRIX(glMultMatrix(acd3), Projective3d(acd3).matrix());
288 
290  VERIFY_MATRIX(glLoadMatrix(ad3), Projective3d(ad3).matrix());
291  VERIFY_MATRIX(glMultMatrix(ad3), Projective3d(ad3).matrix());
292 
294  pd3.matrix().setRandom();
295  VERIFY_MATRIX(glLoadMatrix(pd3), Projective3d(pd3).matrix());
296  VERIFY_MATRIX(glMultMatrix(pd3), Projective3d(pd3).matrix());
297 
298  // translations (2D and 3D)
299  {
300  Vector2f vf2;
301  vf2.setRandom();
302  Vector3f vf23;
303  vf23 << vf2, 0;
304  VERIFY_MATRIX(glTranslate(vf2), Projective3f(Translation3f(vf23)).matrix());
305  Vector2d vd2;
306  vd2.setRandom();
307  Vector3d vd23;
308  vd23 << vd2, 0;
309  VERIFY_MATRIX(glTranslate(vd2), Projective3d(Translation3d(vd23)).matrix());
310 
311  Vector3f vf3;
312  vf3.setRandom();
313  VERIFY_MATRIX(glTranslate(vf3), Projective3f(Translation3f(vf3)).matrix());
314  Vector3d vd3;
315  vd3.setRandom();
316  VERIFY_MATRIX(glTranslate(vd3), Projective3d(Translation3d(vd3)).matrix());
317 
319  tf3.vector().setRandom();
320  VERIFY_MATRIX(glTranslate(tf3), Projective3f(tf3).matrix());
321 
323  td3.vector().setRandom();
324  VERIFY_MATRIX(glTranslate(td3), Projective3d(td3).matrix());
325  }
326 
327  // scaling (2D and 3D)
328  {
329  Vector2f vf2;
330  vf2.setRandom();
331  Vector3f vf23;
332  vf23 << vf2, 1;
333  VERIFY_MATRIX(glScale(vf2), Projective3f(Scaling(vf23)).matrix());
334  Vector2d vd2;
335  vd2.setRandom();
336  Vector3d vd23;
337  vd23 << vd2, 1;
338  VERIFY_MATRIX(glScale(vd2), Projective3d(Scaling(vd23)).matrix());
339 
340  Vector3f vf3;
341  vf3.setRandom();
342  VERIFY_MATRIX(glScale(vf3), Projective3f(Scaling(vf3)).matrix());
343  Vector3d vd3;
344  vd3.setRandom();
345  VERIFY_MATRIX(glScale(vd3), Projective3d(Scaling(vd3)).matrix());
346 
347  UniformScaling<float> usf(internal::random<float>());
348  VERIFY_MATRIX(glScale(usf), Projective3f(usf).matrix());
349 
350  UniformScaling<double> usd(internal::random<double>());
351  VERIFY_MATRIX(glScale(usd), Projective3d(usd).matrix());
352  }
353  } else {
354  std::cerr << "Warning: fixed-function pipeline was not tested.\n";
355  }
356 
357  // Dynamic shader substitution variables.
358  // Modern shaders require a version string, and newer runtimes fail to
359  // compile old GLSL versions. Thus, we dynamically set the GLSL version
360  // string based on runtime. Also, pre OpenGL 3.0, the output gl_FragColor was
361  // built-in. This was deprecated in OpenGL 3.0, requiring us to explicitly
362  // define the output variable.
363  std::vector<std::string> glsl_vars;
364  glsl_vars.push_back("${GLSL_VERSION}");
365  glsl_vars.push_back("${FRAG_OUTPUT_DECLARATION}");
366  glsl_vars.push_back("${FRAG_OUTPUT_VARIABLE}");
367 
368  std::vector<std::string> glsl_vals;
369  glsl_vals.push_back(getGlslVersionString(gl_major_version, gl_minor_version));
370  if (gl_major_version >= 3) {
371  glsl_vals.push_back("out vec4 fragColor;");
372  glsl_vals.push_back("fragColor");
373  } else {
374  glsl_vals.push_back("");
375  glsl_vals.push_back("gl_FragColor");
376  }
377 
378  // uniform
379  {
380  // vertex shader.
381  std::string vtx = format(
382  "${GLSL_VERSION}\n"
383  "void main(void) {\n"
384  " gl_Position = vec4(0,0,0,1);\n"
385  "}\n",
386  glsl_vars, glsl_vals);
387 
388 #ifdef GL_VERSION_2_0
389  if (GLEW_VERSION_2_0 && GL_VERSION_2_0) {
390  std::string frg = format(
391  "${GLSL_VERSION}\n"
392  "uniform vec2 v2f;\n"
393  "uniform vec3 v3f;\n"
394  "uniform vec4 v4f;\n"
395  "uniform ivec2 v2i;\n"
396  "uniform ivec3 v3i;\n"
397  "uniform ivec4 v4i;\n"
398  "uniform mat2 m2f;\n"
399  "uniform mat3 m3f;\n"
400  "uniform mat4 m4f;\n"
401  "${FRAG_OUTPUT_DECLARATION}\n"
402  "void main(void) { \n"
403  " ${FRAG_OUTPUT_VARIABLE} = "
404  "vec4(v2f[0]+v3f[0]+v4f[0])+vec4(v2i[0]+v3i[0]+v4i[0])+vec4(m2f[0][0]+m3f[0][0]+m4f[0][0]);\n"
405  "}\n",
406  glsl_vars, glsl_vals);
407 
408  GLint prg_id = createProgram(vtx, frg);
409  VERIFY(prg_id > 0 && "Failed to create program.");
410  VERIFY_UNIFORM(fv, v2f, Vector2f);
411  VERIFY_UNIFORM(fv, v3f, Vector3f);
412  VERIFY_UNIFORM(fv, v4f, Vector4f);
413  VERIFY_UNIFORMi(v2i, Vector2i);
414  VERIFY_UNIFORMi(v3i, Vector3i);
415  VERIFY_UNIFORMi(v4i, Vector4i);
416  VERIFY_UNIFORM(fv, m2f, Matrix2f);
417  VERIFY_UNIFORM(fv, m3f, Matrix3f);
418  VERIFY_UNIFORM(fv, m4f, Matrix4f);
419  glDeleteProgram(prg_id);
420  } else
421 #endif
422  std::cerr << "Warning: opengl 2.0 was not tested.\n";
423 
424 #ifdef GL_VERSION_2_1
425  if (GLEW_VERSION_2_1 && GL_VERSION_2_1 &&
426  (gl_major_version > 2 || (gl_major_version == 2 && gl_minor_version >= 1))) {
427  std::string frg = format(
428  "${GLSL_VERSION}\n"
429  "uniform mat2x3 m23f;\n"
430  "uniform mat3x2 m32f;\n"
431  "uniform mat2x4 m24f;\n"
432  "uniform mat4x2 m42f;\n"
433  "uniform mat3x4 m34f;\n"
434  "uniform mat4x3 m43f;\n"
435  "${FRAG_OUTPUT_DECLARATION}\n"
436  "void main(void) {\n"
437  " ${FRAG_OUTPUT_VARIABLE} = vec4(m23f[0][0]+m32f[0][0]+m24f[0][0]+m42f[0][0]+m34f[0][0]+m43f[0][0]);\n"
438  "}\n",
439  glsl_vars, glsl_vals);
440 
441  GLint prg_id = createProgram(vtx, frg);
442  VERIFY(prg_id > 0 && "Failed to create program.");
443  typedef Matrix<float, 2, 3> Matrix23f;
444  typedef Matrix<float, 3, 2> Matrix32f;
445  typedef Matrix<float, 2, 4> Matrix24f;
446  typedef Matrix<float, 4, 2> Matrix42f;
447  typedef Matrix<float, 3, 4> Matrix34f;
448  typedef Matrix<float, 4, 3> Matrix43f;
449 
450  VERIFY_UNIFORM(fv, m23f, Matrix23f);
451  VERIFY_UNIFORM(fv, m32f, Matrix32f);
452  VERIFY_UNIFORM(fv, m24f, Matrix24f);
453  VERIFY_UNIFORM(fv, m42f, Matrix42f);
454  VERIFY_UNIFORM(fv, m34f, Matrix34f);
455  VERIFY_UNIFORM(fv, m43f, Matrix43f);
456  glDeleteProgram(prg_id);
457  } else
458 #endif
459  std::cerr << "Warning: opengl 2.1 was not tested.\n";
460 
461 #ifdef GL_VERSION_3_0
462  if (GLEW_VERSION_3_0 && GL_VERSION_3_0 && gl_major_version >= 3) {
463  std::string frg = format(
464  "${GLSL_VERSION}\n"
465  "uniform uvec2 v2ui;\n"
466  "uniform uvec3 v3ui;\n"
467  "uniform uvec4 v4ui;\n"
468  "${FRAG_OUTPUT_DECLARATION}\n"
469  "void main(void) {\n"
470  " ${FRAG_OUTPUT_VARIABLE} = vec4(v2ui[0]+v3ui[0]+v4ui[0]);\n"
471  "}\n",
472  glsl_vars, glsl_vals);
473 
474  GLint prg_id = createProgram(vtx, frg);
475  VERIFY(prg_id > 0 && "Failed to create program.");
476  typedef Matrix<unsigned int, 2, 1> Vector2ui;
477  typedef Matrix<unsigned int, 3, 1> Vector3ui;
478  typedef Matrix<unsigned int, 4, 1> Vector4ui;
479 
480  VERIFY_UNIFORMi(v2ui, Vector2ui);
481  VERIFY_UNIFORMi(v3ui, Vector3ui);
482  VERIFY_UNIFORMi(v4ui, Vector4ui);
483  glDeleteProgram(prg_id);
484  } else
485 #endif
486  std::cerr << "Warning: opengl 3.0 was not tested.\n";
487 
488  // dvecn supported if >= 4.1 or ARB_vertex_attrib_64bit
489  bool has_fp64_native = (gl_major_version == 4 && gl_minor_version >= 1);
490  bool has_fp64_extension = false;
491 #ifdef GLEW_ARB_gpu_shader_fp64
492  if (GLEW_ARB_gpu_shader_fp64) {
493  // Check that extension can actually be compiled.
494  if (has_fp64_extension) {
495  std::string frg = format(
496  "${GLSL_VERSION}\n"
497  "#extension GL_ARB_gpu_shader_fp64 : enable\n"
498  "uniform dvec2 dv2;\n"
499  "${FRAG_OUTPUT_DECLARATION}\n"
500  "void main(void) {\n"
501  " ${FRAG_OUTPUT_VARIABLE} = vec4(dv2.x, dv2.y, dv2.x, dv2.y);\n"
502  "}\n",
503  glsl_vars, glsl_vals);
504  GLint prg_id = createProgram(vtx, frg, /*print_errors=*/false);
505  if (prg_id) {
506  has_fp64_extension = true;
507  glDeleteProgram(prg_id);
508  }
509  }
510  }
511 #endif
512 
513  if (has_fp64_native || has_fp64_extension) {
514  std::vector<std::string> glsl_vars_with_extension = glsl_vars;
515  glsl_vars_with_extension.push_back("${GLSL_EXTENSIONS}");
516  std::vector<std::string> glsl_vals_with_extension = glsl_vals;
517  if (has_fp64_extension) {
518  glsl_vals_with_extension.push_back("#extension GL_ARB_gpu_shader_fp64 : enable");
519  } else {
520  glsl_vals_with_extension.push_back("");
521  }
522 
523  std::string frg = format(
524  "${GLSL_VERSION}\n"
525  "${GLSL_EXTENSIONS}\n"
526  "uniform dvec2 v2d;\n"
527  "uniform dvec3 v3d;\n"
528  "uniform dvec4 v4d;\n"
529  "${FRAG_OUTPUT_DECLARATION}\n"
530  "void main(void) {\n"
531  " ${FRAG_OUTPUT_VARIABLE} = vec4(v2d[0]+v3d[0]+v4d[0]);\n"
532  "}\n",
533  glsl_vars_with_extension, glsl_vals_with_extension);
534 
535  GLint prg_id = createProgram(vtx, frg);
536  VERIFY(prg_id > 0 && "Failed to create program.");
537  VERIFY_UNIFORM(dv, v2d, Vector2d);
538  VERIFY_UNIFORM(dv, v3d, Vector3d);
539  VERIFY_UNIFORM(dv, v4d, Vector4d);
540  glDeleteProgram(prg_id);
541  } else
542  std::cerr << "Warning: dvec (fp64) was not tested.\n";
543  }
544 
545  // Exit loop - Leaving main loop is supported by freeglut, otherwise we
546  // are forced to exit.
547 #ifdef FREEGLUT
548  glutLeaveMainLoop();
549  // Trigger another display loop iteration. Otherwise, it just hangs.
550  glutPostRedisplay();
551 #else
552  exit(0);
553 #endif
554 }
The matrix class, also used for vectors and row-vectors.
Definition: Eigen/Eigen/src/Core/Matrix.h:186
Derived & setRandom(Index size)
Definition: Random.h:147
The quaternion class used to represent 3D orientations and rotations.
Definition: Eigen/Eigen/src/Geometry/Quaternion.h:285
Represents an homogeneous transformation in a N dimensional space.
Definition: Transform.h:192
EIGEN_DEVICE_FUNC const MatrixType & matrix() const
Definition: Transform.h:369
Represents a translation transformation.
Definition: Translation.h:33
EIGEN_DEVICE_FUNC const VectorType & vector() const
Definition: Translation.h:85
Represents a generic uniform scaling transformation.
Definition: Eigen/src/Geometry/Scaling.h:47
Eigen::Map< Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor >, 0, Eigen::OuterStride<> > matrix(T *data, int rows, int cols, int stride)
Definition: common.h:85
Transform< double, 3, Projective > Projective3d
Definition: Transform.h:704
Transform< float, 3, Projective > Projective3f
Definition: Transform.h:700
AngleAxis< float > AngleAxisf
Definition: AngleAxis.h:165
AngleAxis< double > AngleAxisd
Definition: AngleAxis.h:168
EIGEN_BLAS_FUNC() rot(int *n, Scalar *px, int *incx, Scalar *py, int *incy, Scalar *pc, Scalar *ps)
Definition: level1_real_impl.h:88
#define VERIFY(a)
Definition: main.h:362
UniformScaling< float > Scaling(float s)
Definition: Eigen/src/Geometry/Scaling.h:138
Translation< float, 3 > Translation3f
Definition: Translation.h:174
Translation< double, 3 > Translation3d
Definition: Translation.h:175
#define VERIFY_MATRIX(CODE, REF)
Definition: openglsupport.cpp:28
#define VERIFY_UNIFORM(SUFFIX, NAME, TYPE)
Definition: openglsupport.cpp:45
#define VERIFY_UNIFORMi(NAME, TYPE)
Definition: openglsupport.cpp:63
std::string getGlslVersionString(int gl_major_version, int gl_minor_version)
Definition: openglsupport.cpp:162
std::string format(const std::string &str, const std::vector< std::string > &find, const std::vector< std::string > &replace)
Definition: openglsupport.cpp:217

References createProgram(), format(), getGlslVersionString(), Eigen::Transform< Scalar_, Dim_, Mode_, Options_ >::matrix(), matrix(), rot(), Eigen::Scaling(), Eigen::PlainObjectBase< Derived >::setRandom(), oomph::Global_string_for_annotation::string(), Eigen::Translation< Scalar_, Dim_ >::vector(), VERIFY, VERIFY_MATRIX, VERIFY_UNIFORM, and VERIFY_UNIFORMi.

Referenced by EIGEN_DECLARE_TEST().

◆ printProgramInfoLog()

void printProgramInfoLog ( GLuint  objectID)
80  {
81  int infologLength, charsWritten;
82  GLchar* infoLog;
83  glGetProgramiv(objectID, GL_INFO_LOG_LENGTH, &infologLength);
84  if (infologLength > 0) {
85  infoLog = new GLchar[infologLength];
86  glGetProgramInfoLog(objectID, infologLength, &charsWritten, infoLog);
87  if (charsWritten > 0) std::cerr << "Program info : \n" << infoLog << std::endl;
88  delete[] infoLog;
89  }
90 }

Referenced by createProgram().

◆ printShaderInfoLog()

void printShaderInfoLog ( GLuint  objectID)
92  {
93  int infologLength, charsWritten;
94  GLchar* infoLog;
95  glGetShaderiv(objectID, GL_INFO_LOG_LENGTH, &infologLength);
96  if (infologLength > 0) {
97  infoLog = new GLchar[infologLength];
98  glGetShaderInfoLog(objectID, infologLength, &charsWritten, infoLog);
99  if (charsWritten > 0) std::cerr << "Shader info : \n" << infoLog << std::endl;
100  delete[] infoLog;
101  }
102 }

Referenced by createProgram().