From 9659f35509ed98cf6888510ea0c3fcf0e3017f56 Mon Sep 17 00:00:00 2001 From: Matt Larsen Date: Tue, 2 Aug 2016 09:56:26 -0700 Subject: [PATCH] my changes --- vtkm/rendering/MapperGL.h | 364 +++++++++++++++++- vtkm/rendering/internal/OpenGLHeaders.h | 3 + vtkm/rendering/testing/CMakeLists.txt | 3 +- vtkm/rendering/testing/UnitTestMapperGLFW.cxx | 4 + 4 files changed, 360 insertions(+), 14 deletions(-) diff --git a/vtkm/rendering/MapperGL.h b/vtkm/rendering/MapperGL.h index bea0c2bf9..e9d6589d0 100644 --- a/vtkm/rendering/MapperGL.h +++ b/vtkm/rendering/MapperGL.h @@ -33,6 +33,8 @@ #include #include +using namespace std; + namespace vtkm { namespace rendering { @@ -92,7 +94,108 @@ public: glFinish(); glFlush(); } - +const char* GL_type_to_string (GLenum type) +{ + switch (type) { + case GL_BOOL: return "bool"; + case GL_INT: return "int"; + case GL_FLOAT: return "float"; + case GL_FLOAT_VEC2: return "vec2"; + case GL_FLOAT_VEC3: return "vec3"; + case GL_FLOAT_VEC4: return "vec4"; + case GL_FLOAT_MAT2: return "mat2"; + case GL_FLOAT_MAT3: return "mat3"; + case GL_FLOAT_MAT4: return "mat4"; + case GL_SAMPLER_2D: return "sampler2D"; + case GL_SAMPLER_3D: return "sampler3D"; + case GL_SAMPLER_CUBE: return "samplerCube"; + case GL_SAMPLER_2D_SHADOW: return "sampler2DShadow"; + default: break; + } + return "other"; +} +void _print_programme_info_log (GLuint programme) { + int max_length = 2048; + int actual_length = 0; + char log[2048]; + glGetProgramInfoLog (programme, max_length, &actual_length, log); + printf ("program info log for GL index %u:\n%s", programme, log); +} +void print_all (GLuint programme) { + printf ("--------------------\nshader programme %i info:\n", programme); + int params = -1; + glGetProgramiv (programme, GL_LINK_STATUS, ¶ms); + printf ("GL_LINK_STATUS = %i\n", params); + + glGetProgramiv (programme, GL_ATTACHED_SHADERS, ¶ms); + printf ("GL_ATTACHED_SHADERS = %i\n", params); + + glGetProgramiv (programme, GL_ACTIVE_ATTRIBUTES, ¶ms); + printf ("GL_ACTIVE_ATTRIBUTES = %i\n", params); + for (int i = 0; i < params; i++) { + char name[64]; + int max_length = 64; + int actual_length = 0; + int size = 0; + GLenum type; + glGetActiveAttrib ( + programme, + i, + max_length, + &actual_length, + &size, + &type, + name + ); + if (size > 1) { + for (int j = 0; j < size; j++) { + char long_name[64]; + sprintf (long_name, "%s[%i]", name, j); + int location = glGetAttribLocation (programme, long_name); + printf (" %i) type:%s name:%s location:%i\n", + i, GL_type_to_string (type), long_name, location); + } + } else { + int location = glGetAttribLocation (programme, name); + printf (" %i) type:%s name:%s location:%i\n", + i, GL_type_to_string (type), name, location); + } + } + + glGetProgramiv (programme, GL_ACTIVE_UNIFORMS, ¶ms); + printf ("GL_ACTIVE_UNIFORMS = %i\n", params); + for (int i = 0; i < params; i++) { + char name[64]; + int max_length = 64; + int actual_length = 0; + int size = 0; + GLenum type; + glGetActiveUniform ( + programme, + i, + max_length, + &actual_length, + &size, + &type, + name + ); + if (size > 1) { + for (int j = 0; j < size; j++) { + char long_name[64]; + sprintf (long_name, "%s[%i]", name, j); + int location = glGetUniformLocation (programme, long_name); + printf (" %i) type:%s name:%s location:%i\n", + i, GL_type_to_string (type), long_name, location); + } + } else { + int location = glGetUniformLocation (programme, name); + printf (" %i) type:%s name:%s location:%i\n", + i, GL_type_to_string (type), name, location); + } + } + + _print_programme_info_log (programme); +} template VTKM_CONT_EXPORT void RenderTriangles(vtkm::Id numTri, const PtType &verts, @@ -101,11 +204,14 @@ public: const vtkm::rendering::ColorTable &ct, const vtkm::Range &scalarRange) { + glewExperimental = GL_TRUE; + glewInit(); vtkm::Float32 sMin = vtkm::Float32(scalarRange.Min); vtkm::Float32 sMax = vtkm::Float32(scalarRange.Max); vtkm::Float32 sDiff = sMax-sMin; - glBegin(GL_TRIANGLES); + vector data, colors; + int method = 2; for (int i = 0; i < numTri; i++) { vtkm::Vec idx = indices.GetPortalConstControl().Get(i); @@ -117,29 +223,261 @@ public: vtkm::Vec p2 = verts.GetPortalConstControl().Get(idx[2]); vtkm::Vec p3 = verts.GetPortalConstControl().Get(idx[3]); - vtkm::Float32 s = scalar.GetPortalConstControl().Get(i1); + vtkm::Float32 s; + Color color; + + s = scalar.GetPortalConstControl().Get(i1); s = (s-sMin)/sDiff; - - Color color = ct.MapRGB(s); - glColor3f(color.Components[0], color.Components[1], color.Components[2]); - glVertex3f(p1[0],p1[1],p1[2]); + color = ct.MapRGB(s); + data.push_back(p1[0]); + data.push_back(p1[1]); + data.push_back(p1[2]); + if (method==0) + { + data.push_back(color.Components[0]); + data.push_back(color.Components[1]); + data.push_back(color.Components[2]); + } + else if (method == 2) + { + colors.push_back(color.Components[0]); + colors.push_back(color.Components[1]); + colors.push_back(color.Components[2]); + } s = scalar.GetPortalConstControl().Get(i2); s = (s-sMin)/sDiff; color = ct.MapRGB(s); - glColor3f(color.Components[0], color.Components[1], color.Components[2]); - glVertex3f(p2[0],p2[1],p2[2]); + data.push_back(p2[0]); + data.push_back(p2[1]); + data.push_back(p2[2]); + if (method==0) + { + data.push_back(color.Components[0]); + data.push_back(color.Components[1]); + data.push_back(color.Components[2]); + } + else if (method == 2) + { + colors.push_back(color.Components[0]); + colors.push_back(color.Components[1]); + colors.push_back(color.Components[2]); + } s = scalar.GetPortalConstControl().Get(i3); s = (s-sMin)/sDiff; color = ct.MapRGB(s); - glColor3f(color.Components[0], color.Components[1], color.Components[2]); - glVertex3f(p3[0],p3[1],p3[2]); + data.push_back(p3[0]); + data.push_back(p3[1]); + data.push_back(p3[2]); + if (method==0) + { + data.push_back(color.Components[0]); + data.push_back(color.Components[1]); + data.push_back(color.Components[2]); + } + else if (method == 2) + { + colors.push_back(color.Components[0]); + colors.push_back(color.Components[1]); + colors.push_back(color.Components[2]); + } } - glEnd(); + cout<<"data.size()= "< # include + #else +#include # include #endif diff --git a/vtkm/rendering/testing/CMakeLists.txt b/vtkm/rendering/testing/CMakeLists.txt index 0cfb7dc06..f84c6e962 100644 --- a/vtkm/rendering/testing/CMakeLists.txt +++ b/vtkm/rendering/testing/CMakeLists.txt @@ -36,7 +36,8 @@ if (OPENGL_FOUND) ) list(APPEND libs ${EGL_LIBRARIES}) endif() - + #apple needs thes linker flags + #-framework Cocoa -framework OpenGL -framework IOKit -framework CoreVideo if (GLFW_FOUND) set(unit_tests ${unit_tests} UnitTestMapperGLFW.cxx diff --git a/vtkm/rendering/testing/UnitTestMapperGLFW.cxx b/vtkm/rendering/testing/UnitTestMapperGLFW.cxx index a82472d8b..acf1066da 100644 --- a/vtkm/rendering/testing/UnitTestMapperGLFW.cxx +++ b/vtkm/rendering/testing/UnitTestMapperGLFW.cxx @@ -58,6 +58,10 @@ void RenderTests() vtkm::rendering::ColorTable colorTable("thermal"); glfwInit(); + glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); + glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); + glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); + glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2); GLFWwindow *window = glfwCreateWindow(WIDTH, HEIGHT, "GLFW Test", NULL, NULL); glfwMakeContextCurrent(window); glfwSetKeyCallback(window, keyCallback);