diff --git a/examples/common/glUtils.cpp b/examples/common/glUtils.cpp index e8ea17d3..9cdbb24a 100644 --- a/examples/common/glUtils.cpp +++ b/examples/common/glUtils.cpp @@ -26,6 +26,8 @@ #include #include "glUtils.h" +#include + namespace GLUtils { // Note that glewIsSupported is required here for Core profile, glewGetExtension @@ -35,6 +37,41 @@ namespace GLUtils { (glewIsSupported(x) == GL_TRUE) #endif +void +SetMinimumGLVersion() { + // Here 3.2 is the minimum GL version supported, GLFW will allocate + // a higher version if possible. + int major = 3, + minor = 2; + + #define glfwOpenWindowHint glfwWindowHint + #define GLFW_OPENGL_VERSION_MAJOR GLFW_CONTEXT_VERSION_MAJOR + #define GLFW_OPENGL_VERSION_MINOR GLFW_CONTEXT_VERSION_MINOR + + #ifdef CORE_PROFILE + glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); + #endif + + glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, major); + glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, minor); + + glfwOpenWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); +} + +void +PrintGLVersion() { + std::cout << glGetString(GL_VENDOR) << "\n"; + std::cout << glGetString(GL_RENDERER) << "\n"; + std::cout << glGetString(GL_VERSION) << "\n"; + + int i; + std::cout << "Init OpenGL "; + glGetIntegerv(GL_MAJOR_VERSION, &i); + std::cout << i << "."; + glGetIntegerv(GL_MINOR_VERSION, &i); + std::cout << i << "\n"; +} + void CheckGLErrors(std::string const & where) { GLuint err; @@ -76,8 +113,6 @@ SupportsAdaptiveTessellation() { #endif } -///Helper function that parses the open gl version string, retrieving the major -///and minor version from it. void GetMajorMinorVersion(int *major, int *minor){ const GLubyte *ver = glGetString(GL_SHADING_LANGUAGE_VERSION); if (!ver){ @@ -92,9 +127,6 @@ void GetMajorMinorVersion(int *major, int *minor){ } } -/** Gets the shader version based on the current opengl version and returns - * it in a string form */ - std::string GetShaderVersion(){ std::string shader_version; diff --git a/examples/common/glUtils.h b/examples/common/glUtils.h index cf8fc1ba..bec96b2a 100644 --- a/examples/common/glUtils.h +++ b/examples/common/glUtils.h @@ -25,28 +25,54 @@ #ifndef OPENSUBDIV_EXAMPLES_GL_UTILS_H #define OPENSUBDIV_EXAMPLES_GL_UTILS_H +#if defined(__APPLE__) + #if defined(OSD_USES_GLEW) + #include + #else + #include + #endif + #define GLFW_INCLUDE_GL3 + #define GLFW_NO_GLU +#else + #include + #include + #if defined(WIN32) + #include + #endif +#endif + #include #include #include #include +#define CORE_PROFILE + namespace GLUtils { +void SetMinimumGLVersion(); + +void PrintGLVersion(); + void CheckGLErrors(std::string const & where = ""); GLuint CompileShader(GLenum shaderType, const char *source); bool SupportsAdaptiveTessellation(); +// Helper function that parses the open gl version string, retrieving the +// major and minor version from it. void GetMajorMinorVersion(int *major, int *minor); - +// Gets the shader version based on the current opengl version and returns +// it in a string form. std::string GetShaderVersion(); std::string GetShaderVersionInclude(); bool GL_ARBSeparateShaderObjectsOrGL_VERSION_4_1(); + bool GL_ARBComputeShaderOrGL_VERSION_4_3(); }; diff --git a/examples/farViewer/farViewer.cpp b/examples/farViewer/farViewer.cpp index 542e2a8e..8938738f 100644 --- a/examples/farViewer/farViewer.cpp +++ b/examples/farViewer/farViewer.cpp @@ -1294,13 +1294,15 @@ setGLCoreProfile() { #define GLFW_OPENGL_VERSION_MINOR GLFW_CONTEXT_VERSION_MINOR glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); + #if not defined(__APPLE__) glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 4); -#ifdef OPENSUBDIV_HAS_GLSL_COMPUTE - glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 3); -#else - glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 2); -#endif + + #ifdef OPENSUBDIV_HAS_GLSL_COMPUTE + glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 3); + #else + glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 2); + #endif #else glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3); diff --git a/examples/glEvalLimit/glEvalLimit.cpp b/examples/glEvalLimit/glEvalLimit.cpp index 5ab76c0c..ceef8a9c 100644 --- a/examples/glEvalLimit/glEvalLimit.cpp +++ b/examples/glEvalLimit/glEvalLimit.cpp @@ -22,21 +22,7 @@ // language governing permissions and limitations under the Apache License. // -#if defined(__APPLE__) - #if defined(OSD_USES_GLEW) - #include - #else - #include - #endif - #define GLFW_INCLUDE_GL3 - #define GLFW_NO_GLU -#else - #include - #include - #if defined(WIN32) - #include - #endif -#endif +#include "../common/glUtils.h" #include GLFWwindow* g_window=0; @@ -97,7 +83,6 @@ GLFWmonitor* g_primary=0; #include "../common/stopwatch.h" #include "../common/simple_math.h" #include "../common/glHud.h" -#include "../common/glUtils.h" #include "init_shapes.h" #include "particles.h" @@ -691,18 +676,6 @@ createOsdMesh(ShapeDesc const & shapeDesc, int level) { delete topologyRefiner; } -//------------------------------------------------------------------------------ -static void -checkGLErrors(std::string const & where = "") { - GLuint err; - while ((err = glGetError()) != GL_NO_ERROR) { - - std::cerr << "GL error: " - << (where.empty() ? "" : where + " ") - << err << "\n"; - } -} - //------------------------------------------------------------------------------ static bool linkDefaultProgram() { @@ -1036,7 +1009,7 @@ display() { glFinish(); - checkGLErrors("display leave"); + GLUtils::CheckGLErrors("display leave"); } //------------------------------------------------------------------------------ @@ -1355,25 +1328,6 @@ callbackErrorGLFW(int error, const char* description) { fprintf(stderr, "GLFW Error (%d) : %s\n", error, description); } -//------------------------------------------------------------------------------ -static void -setGLCoreProfile() { - - #define glfwOpenWindowHint glfwWindowHint - #define GLFW_OPENGL_VERSION_MAJOR GLFW_CONTEXT_VERSION_MAJOR - #define GLFW_OPENGL_VERSION_MINOR GLFW_CONTEXT_VERSION_MINOR - - glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); -#if not defined(__APPLE__) - glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 4); - glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 2); -#else - glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3); - glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 2); -#endif - glfwOpenWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); -} - //------------------------------------------------------------------------------ int main(int argc, char **argv) { @@ -1407,10 +1361,7 @@ int main(int argc, char **argv) { static const char windowTitle[] = "OpenSubdiv glEvalLimit " OPENSUBDIV_VERSION_STRING; -#define CORE_PROFILE -#ifdef CORE_PROFILE - setGLCoreProfile(); -#endif + GLUtils::SetMinimumGLVersion(); if (fullscreen) { @@ -1435,11 +1386,13 @@ int main(int argc, char **argv) { if (not (g_window=glfwCreateWindow(g_width, g_height, windowTitle, fullscreen and g_primary ? g_primary : NULL, NULL))) { - printf("Failed to open window.\n"); + std::cerr << "Failed to create OpenGL context.\n"; glfwTerminate(); return 1; } + glfwMakeContextCurrent(g_window); + GLUtils::PrintGLVersion(); // accommodate high DPI displays (e.g. mac retina displays) glfwGetFramebufferSize(g_window, &g_width, &g_height); diff --git a/examples/glFVarViewer/glFVarViewer.cpp b/examples/glFVarViewer/glFVarViewer.cpp index a185bffd..5ba083b9 100644 --- a/examples/glFVarViewer/glFVarViewer.cpp +++ b/examples/glFVarViewer/glFVarViewer.cpp @@ -22,21 +22,7 @@ // language governing permissions and limitations under the Apache License. // -#if defined(__APPLE__) - #if defined(OSD_USES_GLEW) - #include - #else - #include - #endif - #define GLFW_INCLUDE_GL3 - #define GLFW_NO_GLU -#else - #include - #include - #if defined(WIN32) - #include - #endif -#endif +#include "../common/glUtils.h" #include GLFWwindow* g_window = 0; @@ -52,7 +38,6 @@ OpenSubdiv::Osd::GLMeshInterface *g_mesh = NULL; #include "../common/stopwatch.h" #include "../common/simple_math.h" #include "../common/glHud.h" -#include "../common/glUtils.h" #include "../common/glShaderCache.h" #include @@ -1205,24 +1190,6 @@ static void callbackErrorGLFW(int error, const char* description) { fprintf(stderr, "GLFW Error (%d) : %s\n", error, description); } -//------------------------------------------------------------------------------ -static void -setGLCoreProfile() { - - #define glfwOpenWindowHint glfwWindowHint - #define GLFW_OPENGL_VERSION_MAJOR GLFW_CONTEXT_VERSION_MAJOR - #define GLFW_OPENGL_VERSION_MINOR GLFW_CONTEXT_VERSION_MINOR - - glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); -#if not defined(__APPLE__) - glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 4); - glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 2); -#else - glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3); - glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 2); -#endif - glfwOpenWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); -} //------------------------------------------------------------------------------ int main(int argc, char ** argv) { @@ -1260,10 +1227,7 @@ int main(int argc, char ** argv) { static const char windowTitle[] = "OpenSubdiv glFVarViewer " OPENSUBDIV_VERSION_STRING; -#define CORE_PROFILE -#ifdef CORE_PROFILE - setGLCoreProfile(); -#endif + GLUtils::SetMinimumGLVersion(); if (fullscreen) { g_primary = glfwGetPrimaryMonitor(); @@ -1287,11 +1251,13 @@ int main(int argc, char ** argv) { if (not (g_window=glfwCreateWindow(g_width, g_height, windowTitle, fullscreen and g_primary ? g_primary : NULL, NULL))) { - printf("Failed to open window.\n"); + std::cerr << "Failed to create OpenGL context.\n"; glfwTerminate(); return 1; } + glfwMakeContextCurrent(g_window); + GLUtils::PrintGLVersion(); // accommodate high DPI displays (e.g. mac retina displays) glfwGetFramebufferSize(g_window, &g_width, &g_height); diff --git a/examples/glFVarViewer/shader.glsl b/examples/glFVarViewer/shader.glsl index 4802fb51..98fb2793 100644 --- a/examples/glFVarViewer/shader.glsl +++ b/examples/glFVarViewer/shader.glsl @@ -112,6 +112,21 @@ out block { void main() { outpt.v.position = ModelViewMatrix * position; + + // We don't actually want to write all these, but some + // compilers complain during about failing to fully write + // outpt.v if they are excluded. + outpt.v.normal = vec3(0); + outpt.v.tangent = vec3(0); + outpt.v.bitangent = vec3(0); + outpt.v.patchCoord = vec4(0); + outpt.v.tessCoord = vec2(0); +#if defined OSD_COMPUTE_NORMAL_DERIVATIVES + outpt.v.Nu = vec3(0); + outpt.v.Nv = vec3(0); +#endif + // -- + OSD_USER_VARYING_PER_VERTEX(); } diff --git a/examples/glImaging/glImaging.cpp b/examples/glImaging/glImaging.cpp index 3d6cb560..2318733c 100644 --- a/examples/glImaging/glImaging.cpp +++ b/examples/glImaging/glImaging.cpp @@ -22,23 +22,7 @@ // language governing permissions and limitations under the Apache License. // -#if defined(__APPLE__) - #if defined(OSD_USES_GLEW) - #include - #else - #include - #endif - #define GLFW_INCLUDE_GL3 - #define GLFW_NO_GLU -#else - #include - #include - #if defined(_WIN32) - // XXX Must include windows.h here or GLFW pollutes the global namespace - #define WIN32_LEAN_AND_MEAN - #include - #endif -#endif +#include "../common/glUtils.h" #include #include @@ -97,28 +81,6 @@ static const char *shaderSource = #include "shader.gen.h" ; -static void -setGLCoreProfile() { - #define glfwOpenWindowHint glfwWindowHint - #define GLFW_OPENGL_VERSION_MAJOR GLFW_CONTEXT_VERSION_MAJOR - #define GLFW_OPENGL_VERSION_MINOR GLFW_CONTEXT_VERSION_MINOR - - glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); -#if not defined(__APPLE__) - glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 4); -#ifdef OPENSUBDIV_HAS_GLSL_COMPUTE - glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 3); -#else - glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 2); -#endif - -#else - glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 4); - glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 1); -#endif - glfwOpenWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); -} - class ShaderCache : public GLShaderCache { public: ShaderCache(std::string const &displayMode) : _displayMode(displayMode) { } @@ -565,14 +527,16 @@ int main(int argc, char ** argv) { static const char windowTitle[] = "OpenSubdiv imaging test " OPENSUBDIV_VERSION_STRING; - setGLCoreProfile(); + GLUtils::SetMinimumGLVersion(); GLFWwindow *window = glfwCreateWindow(width, height, windowTitle, NULL, NULL); if (not window) { - std::cout << "Failed to open window.\n"; + std::cerr << "Failed to create OpenGL context.\n"; glfwTerminate(); } + glfwMakeContextCurrent(window); + GLUtils::PrintGLVersion(); #if defined(OSD_USES_GLEW) // this is the only way to initialize glew correctly under core profile context. diff --git a/examples/glPaintTest/glPaintTest.cpp b/examples/glPaintTest/glPaintTest.cpp index 1ed081c6..c0730279 100644 --- a/examples/glPaintTest/glPaintTest.cpp +++ b/examples/glPaintTest/glPaintTest.cpp @@ -22,21 +22,8 @@ // language governing permissions and limitations under the Apache License. // -#if defined(__APPLE__) - #if defined(OSD_USES_GLEW) - #include - #else - #include - #endif - #define GLFW_INCLUDE_GL3 - #define GLFW_NO_GLU -#else - #include - #include - #if defined(WIN32) - #include - #endif -#endif + +#include "../common/glUtils.h" #include GLFWwindow* g_window=0; diff --git a/examples/glPtexViewer/glPtexViewer.cpp b/examples/glPtexViewer/glPtexViewer.cpp index 7aefb1d8..c6e239d0 100644 --- a/examples/glPtexViewer/glPtexViewer.cpp +++ b/examples/glPtexViewer/glPtexViewer.cpp @@ -305,16 +305,6 @@ const char * g_ptexColorFilename; size_t g_ptexMemoryUsage = 0; -static void -checkGLErrors(std::string const & where = "") { - GLuint err; - while ((err = glGetError()) != GL_NO_ERROR) { - std::cerr << "GL error: " - << (where.empty() ? "" : where + " ") - << err << "\n"; - } -} - //------------------------------------------------------------------------------ static void calcNormals(OpenSubdiv::Far::TopologyRefiner * refiner, @@ -509,7 +499,7 @@ reshape(GLFWwindow *, int width, int height) { glBindTexture(GL_TEXTURE_2D, 0); glBindFramebuffer(GL_FRAMEBUFFER, 0); - checkGLErrors("Reshape"); + GLUtils::CheckGLErrors("Reshape"); } void reshape() { @@ -879,7 +869,7 @@ createPtex(const char *filename, int memLimit) { void createOsdMesh(int level, int kernel) { - checkGLErrors("createOsdMesh"); + GLUtils::CheckGLErrors("createOsdMesh"); Ptex::String ptexError; PtexTexture *ptexColor = PtexTexture::open(g_ptexColorFilename, ptexError, true); @@ -1367,7 +1357,7 @@ drawSky() { glEnable(GL_DEPTH_TEST); glDepthMask(GL_TRUE); - checkGLErrors("draw model"); + GLUtils::CheckGLErrors("draw model"); } //------------------------------------------------------------------------------ @@ -1395,7 +1385,7 @@ drawCageEdges() { glBindVertexArray(0); glUseProgram(0); - checkGLErrors("draw cage edges"); + GLUtils::CheckGLErrors("draw cage edges"); } //------------------------------------------------------------------------------ @@ -1503,7 +1493,7 @@ display() { glFinish(); - checkGLErrors("draw end"); + GLUtils::CheckGLErrors("draw end"); } //------------------------------------------------------------------------------ @@ -1782,29 +1772,6 @@ static void callbackErrorGLFW(int error, const char* description) { fprintf(stderr, "GLFW Error (%d) : %s\n", error, description); } -//------------------------------------------------------------------------------ -static void -setGLCoreProfile() { - - #define glfwOpenWindowHint glfwWindowHint - #define GLFW_OPENGL_VERSION_MAJOR GLFW_CONTEXT_VERSION_MAJOR - #define GLFW_OPENGL_VERSION_MINOR GLFW_CONTEXT_VERSION_MINOR - - glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); -#if not defined(__APPLE__) - glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 4); -#ifdef OPENSUBDIV_HAS_GLSL_COMPUTE - glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 3); -#else - glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 2); -#endif - -#else - glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3); - glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 2); -#endif - glfwOpenWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); -} //------------------------------------------------------------------------------ int main(int argc, char ** argv) { @@ -1878,10 +1845,7 @@ int main(int argc, char ** argv) { static const char windowTitle[] = "OpenSubdiv glPtexViewer" OPENSUBDIV_VERSION_STRING; -#define CORE_PROFILE -#ifdef CORE_PROFILE - setGLCoreProfile(); -#endif + GLUtils::SetMinimumGLVersion(); if (fullscreen) { g_primary = glfwGetPrimaryMonitor(); @@ -1904,12 +1868,15 @@ int main(int argc, char ** argv) { } if (not (g_window=glfwCreateWindow(g_width, g_height, windowTitle, - fullscreen and g_primary ? g_primary : NULL, NULL))) { - printf("Failed to open window.\n"); + fullscreen and g_primary ? g_primary : NULL, NULL))) { + std::cerr << "Failed to create OpenGL context.\n"; glfwTerminate(); return 1; } + glfwMakeContextCurrent(g_window); + GLUtils::PrintGLVersion(); + glfwSetKeyCallback(g_window, keyboard); glfwSetCursorPosCallback(g_window, motion); glfwSetMouseButtonCallback(g_window, mouse); diff --git a/examples/glShareTopology/glShareTopology.cpp b/examples/glShareTopology/glShareTopology.cpp index 944ee4e2..5834a4c2 100644 --- a/examples/glShareTopology/glShareTopology.cpp +++ b/examples/glShareTopology/glShareTopology.cpp @@ -22,21 +22,7 @@ // language governing permissions and limitations under the Apache License. // -#if defined(__APPLE__) - #if defined(OSD_USES_GLEW) - #include - #else - #include - #endif - #define GLFW_INCLUDE_GL3 - #define GLFW_NO_GLU -#else - #include - #include - #if defined(WIN32) - #include - #endif -#endif +#include "../common/glUtils.h" #include GLFWwindow* g_window=0; @@ -1176,30 +1162,7 @@ callbackErrorGLFW(int error, const char* description) { fprintf(stderr, "GLFW Error (%d) : %s\n", error, description); } //------------------------------------------------------------------------------ -static void -setGLCoreProfile() { - #define glfwOpenWindowHint glfwWindowHint - #define GLFW_OPENGL_VERSION_MAJOR GLFW_CONTEXT_VERSION_MAJOR - #define GLFW_OPENGL_VERSION_MINOR GLFW_CONTEXT_VERSION_MINOR - - glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); -#if not defined(__APPLE__) - glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 4); -#ifdef OPENSUBDIV_HAS_GLSL_COMPUTE - glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 3); -#else - glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 2); -#endif - -#else - glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3); - glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 2); -#endif - glfwOpenWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); -} - -//------------------------------------------------------------------------------ int main(int argc, char ** argv) { std::string str; @@ -1218,17 +1181,16 @@ int main(int argc, char ** argv) { static const char windowTitle[] = "OpenSubdiv batching example " OPENSUBDIV_VERSION_STRING; -#define CORE_PROFILE -#ifdef CORE_PROFILE - setGLCoreProfile(); -#endif + GLUtils::SetMinimumGLVersion(); if (not (g_window=glfwCreateWindow(g_width, g_height, windowTitle, NULL, NULL))) { - printf("Failed to open window.\n"); + std::cerr << "Failed to create OpenGL context.\n"; glfwTerminate(); return 1; } + glfwMakeContextCurrent(g_window); + GLUtils::PrintGLVersion(); // accommocate high DPI displays (e.g. mac retina displays) glfwGetFramebufferSize(g_window, &g_width, &g_height); diff --git a/examples/glStencilViewer/glStencilViewer.cpp b/examples/glStencilViewer/glStencilViewer.cpp index 3a132609..414be3f2 100644 --- a/examples/glStencilViewer/glStencilViewer.cpp +++ b/examples/glStencilViewer/glStencilViewer.cpp @@ -22,21 +22,7 @@ // language governing permissions and limitations under the Apache License. // -#if defined(__APPLE__) - #if defined(OSD_USES_GLEW) - #include - #else - #include - #endif - #define GLFW_INCLUDE_GL3 - #define GLFW_NO_GLU -#else - #include - #include - #if defined(WIN32) - #include - #endif -#endif +#include "../common/glUtils.h" #include GLFWwindow* g_window=0; @@ -45,7 +31,6 @@ GLFWmonitor* g_primary=0; #include "../../regression/common/vtr_utils.h" #include "../common/stopwatch.h" #include "../common/simple_math.h" -#include "../common/glUtils.h" #include "../common/glHud.h" #include @@ -1185,25 +1170,6 @@ static void callbackErrorGLFW(int error, const char* description) { fprintf(stderr, "GLFW Error (%d) : %s\n", error, description); } -//------------------------------------------------------------------------------ -static void -setGLCoreProfile() { - - #define glfwOpenWindowHint glfwWindowHint - #define GLFW_OPENGL_VERSION_MAJOR GLFW_CONTEXT_VERSION_MAJOR - #define GLFW_OPENGL_VERSION_MINOR GLFW_CONTEXT_VERSION_MINOR - - glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); -#if not defined(__APPLE__) - glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 4); - glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 2); -#else - glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3); - glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 2); -#endif - glfwOpenWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); -} - //------------------------------------------------------------------------------ int main(int argc, char **argv) { @@ -1237,10 +1203,7 @@ int main(int argc, char **argv) { static const char windowTitle[] = "OpenSubdiv glStencilViewer " OPENSUBDIV_VERSION_STRING; -#define CORE_PROFILE -#ifdef CORE_PROFILE - setGLCoreProfile(); -#endif + GLUtils::SetMinimumGLVersion(); if (fullscreen) { @@ -1264,12 +1227,13 @@ int main(int argc, char **argv) { } if (not (g_window=glfwCreateWindow(g_width, g_height, windowTitle, - fullscreen and g_primary ? g_primary : NULL, NULL))) { - printf("Failed to open window.\n"); + fullscreen and g_primary ? g_primary : NULL, NULL))) { + std::cerr << "Failed to create OpenGL context.\n"; glfwTerminate(); return 1; } glfwMakeContextCurrent(g_window); + GLUtils::PrintGLVersion(); // accommodate high DPI displays (e.g. mac retina displays) glfwGetFramebufferSize(g_window, &g_width, &g_height); diff --git a/examples/glViewer/glViewer.cpp b/examples/glViewer/glViewer.cpp index c41b0ede..c32ccd85 100644 --- a/examples/glViewer/glViewer.cpp +++ b/examples/glViewer/glViewer.cpp @@ -22,21 +22,7 @@ // language governing permissions and limitations under the Apache License. // -#if defined(__APPLE__) - #if defined(OSD_USES_GLEW) - #include - #else - #include - #endif - #define GLFW_INCLUDE_GL3 - #define GLFW_NO_GLU -#else - #include - #include - #if defined(WIN32) - #include - #endif -#endif +#include "../common/glUtils.h" #include GLFWwindow* g_window=0; @@ -90,7 +76,6 @@ OpenSubdiv::Osd::GLLegacyGregoryPatchTable *g_legacyGregoryPatchTable = NULL; #include "../common/stopwatch.h" #include "../common/simple_math.h" #include "../common/glHud.h" -#include "../common/glUtils.h" #include "../common/objAnim.h" #include "../common/patchColors.h" #include "../common/glShaderCache.h" @@ -315,20 +300,6 @@ struct FVarData GLuint textureBuffer; } g_fvarData; -static void -checkGLErrors(std::string const & where = "") -{ - GLuint err; - while ((err = glGetError()) != GL_NO_ERROR) { - std::cerr << "GL error: " - << (where.empty() ? "" : where + " ") - << err << "\n"; - } -} - - - - static bool linkDefaultProgram() { @@ -1802,20 +1773,6 @@ callbackErrorGLFW(int error, const char* description) { fprintf(stderr, "GLFW Error (%d) : %s\n", error, description); } //------------------------------------------------------------------------------ -static void -setGLCoreProfile(int major, int minor) { - #define glfwOpenWindowHint glfwWindowHint - #define GLFW_OPENGL_VERSION_MAJOR GLFW_CONTEXT_VERSION_MAJOR - #define GLFW_OPENGL_VERSION_MINOR GLFW_CONTEXT_VERSION_MINOR - - glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); - - glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, major); - glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, minor); - - glfwOpenWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); -} - //------------------------------------------------------------------------------ int main(int argc, char ** argv) { @@ -1872,10 +1829,7 @@ int main(int argc, char ** argv) { static const char windowTitle[] = "OpenSubdiv glViewer " OPENSUBDIV_VERSION_STRING; -#define CORE_PROFILE -#ifdef CORE_PROFILE - setGLCoreProfile(4, 4); -#endif + GLUtils::SetMinimumGLVersion(); if (fullscreen) { @@ -1901,26 +1855,14 @@ int main(int argc, char ** argv) { g_window = glfwCreateWindow(g_width, g_height, windowTitle, fullscreen and g_primary ? g_primary : NULL, NULL); -#ifdef CORE_PROFILE - if (not g_window){ - setGLCoreProfile(4, 2); - g_window = glfwCreateWindow(g_width, g_height, windowTitle, - fullscreen and g_primary ? g_primary : NULL, NULL); - } - if (not g_window){ - setGLCoreProfile(3, 3); - g_window = glfwCreateWindow(g_width, g_height, windowTitle, - fullscreen and g_primary ? g_primary : NULL, NULL); - } - -#endif - if (not g_window){ + if (not g_window) { + std::cerr << "Failed to create OpenGL context.\n"; glfwTerminate(); return 1; } - glfwMakeContextCurrent(g_window); + GLUtils::PrintGLVersion(); // accommocate high DPI displays (e.g. mac retina displays) glfwGetFramebufferSize(g_window, &g_width, &g_height);