diff --git a/CMakeLists.txt b/CMakeLists.txt index 1837a34d..7acc1a91 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -306,6 +306,7 @@ option(NO_METAL "Disable Metal support" OFF) option(NO_DX "Disable DirectX support") option(NO_TESTS "Disable all tests") option(NO_GLTESTS "Disable GL tests") +option(NO_GLEW "Disable use of GLEW" OFF) option(NO_GLFW "Disable components depending on GLFW" OFF) option(NO_GLFW_X11 "Disable GLFW components depending on X11" OFF) @@ -351,13 +352,17 @@ if (OPENGL_FOUND AND NOT IOS) add_definitions( -DOPENSUBDIV_HAS_OPENGL ) - if (APPLE) - find_package(GLEW) - else() - find_package(GLEW REQUIRED) + if (NOT NO_GLEW) + if (APPLE) + find_package(GLEW) + else() + find_package(GLEW REQUIRED) + endif() endif() if(GLEW_FOUND) add_definitions( -DOSD_USES_GLEW ) + else() + add_definitions( -DOSD_USES_INTERNAL_GLAPILOADER ) endif() endif() @@ -457,9 +462,9 @@ if(GLEW_FOUND AND GLEW_INCLUDE_DIR) ${GLEW_LIBRARY} ${OPENGL_gl_LIBRARY}) -elseif(OPENGL_FOUND AND OPENGL_INCLUDE_DIR) +elseif(OPENGL_FOUND) - osd_detect_gl_version(${OPENGL_INCLUDE_DIR}/GL/glext.h) + osd_detect_gl_version(${PROJECT_SOURCE_DIR}/glLoader/glApi.h) set(OPENGL_LOADER_INCLUDE_DIRS ${OPENGL_INCLUDE_DIR} ${PROJECT_SOURCE_DIR}/glLoader) diff --git a/glLoader/CMakeLists.txt b/glLoader/CMakeLists.txt index a05aa671..99bab5a6 100644 --- a/glLoader/CMakeLists.txt +++ b/glLoader/CMakeLists.txt @@ -28,10 +28,13 @@ endif() list(APPEND GLLOADER_SOURCE_FILES glLoader.cpp + glApi.cpp ) list(APPEND GLLOADER_HEADER_FILES glLoader.h + glApi.h + khrplatform.h ) include_directories( diff --git a/glLoader/glLoader.cpp b/glLoader/glLoader.cpp index 58cdd5bb..d0ce9a9a 100644 --- a/glLoader/glLoader.cpp +++ b/glLoader/glLoader.cpp @@ -36,7 +36,12 @@ namespace GLLoader { bool applicationInitializeGL() { -#if defined(OSD_USES_GLEW) +#if defined(OSD_USES_INTERNAL_GLAPILOADER) + // -- GLAPILOADER + return OpenSubdiv::internal::GLApi::glApiLoad(); + +#elif defined(OSD_USES_GLEW) + // -- GLEW #define CORE_PROFILE #ifdef CORE_PROFILE // this is the only way to initialize GLEW (before GLEW 1.13) @@ -60,8 +65,12 @@ applicationInitializeGL() bool libraryInitializeGL() { - // do nothing +#if defined(OSD_USES_INTERNAL_GLAPILOADER) + return OpenSubdiv::internal::GLApi::glApiLoad(); +#else + // otherwise do nothing return true; +#endif } diff --git a/glLoader/glLoader.h b/glLoader/glLoader.h index 95a9e71e..3a431725 100644 --- a/glLoader/glLoader.h +++ b/glLoader/glLoader.h @@ -31,6 +31,11 @@ /// function entry points at run-time and to define types, enum values, /// and function prototypes needed at compile-time. /// +/// There are three components to this library: +/// glLoader.h -- interface (this header file) +/// glApi.h -- low-level generated OpenGL API loader +/// khrplatform.h -- khronos.org abstraction for low-level platform types +/// /// To use: /// - Include "glloader.h" /// @@ -132,36 +137,18 @@ /// The boolean variables described here are defined in an internal namespace. /// -#if defined(OSD_USES_GLEW) +#if defined(OSD_USES_INTERNAL_GLAPILOADER) + // -- GLAPILOADER + #include "glApi.h" + + #define OSD_OPENGL_HAS(token) (GLAPILOADER_GL_##token) + +#elif defined(OSD_USES_GLEW) // -- GLEW #include #define OSD_OPENGL_HAS(token) (GLEW_##token) -#else - - // -- PLATFORM - #if defined(__APPLE__) - #include "TargetConditionals.h" - #if TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR - #include - #else - #include - #endif - #elif defined(ANDROID) - #include - #elif defined(_WIN32) - #define WIN32_LEAN_AND_MEAN - #include - #include - #else - #define GL_GLEXT_PROTOTYPES - #include - #include - #endif - - #define OSD_OPENGL_HAS(token) (GL_##token) - #endif namespace OpenSubdiv { @@ -184,4 +171,9 @@ extern bool libraryInitializeGL(); } // namespace OpenSubdiv +#if defined(OSD_USES_INTERNAL_GLAPILOADER) +using namespace OpenSubdiv::internal::GLApi; +#endif + + #endif // OPENSUBDIV3_GLLOADER_H diff --git a/opensubdiv/osd/clGLVertexBuffer.cpp b/opensubdiv/osd/clGLVertexBuffer.cpp index 56d786ec..a0567327 100644 --- a/opensubdiv/osd/clGLVertexBuffer.cpp +++ b/opensubdiv/osd/clGLVertexBuffer.cpp @@ -38,6 +38,9 @@ CLGLVertexBuffer::CLGLVertexBuffer(int numElements, cl_context /* clContext */) : _numElements(numElements), _numVertices(numVertices), _vbo(0), _clQueue(0), _clMemory(0), _clMapped(false) { + + // Initialize internal OpenGL loader library if necessary + OpenSubdiv::internal::GLLoader::libraryInitializeGL(); } CLGLVertexBuffer::~CLGLVertexBuffer() { diff --git a/opensubdiv/osd/cpuGLVertexBuffer.cpp b/opensubdiv/osd/cpuGLVertexBuffer.cpp index b9ca8532..8b4afab5 100644 --- a/opensubdiv/osd/cpuGLVertexBuffer.cpp +++ b/opensubdiv/osd/cpuGLVertexBuffer.cpp @@ -37,6 +37,9 @@ namespace Osd { CpuGLVertexBuffer::CpuGLVertexBuffer(int numElements, int numVertices) : _numElements(numElements), _numVertices(numVertices), _vbo(0), _cpuBuffer(0), _dataDirty(true) { + + // Initialize internal OpenGL loader library if necessary + OpenSubdiv::internal::GLLoader::libraryInitializeGL(); } CpuGLVertexBuffer::~CpuGLVertexBuffer() { diff --git a/opensubdiv/osd/cudaGLVertexBuffer.cpp b/opensubdiv/osd/cudaGLVertexBuffer.cpp index 194b4df6..edf5875e 100644 --- a/opensubdiv/osd/cudaGLVertexBuffer.cpp +++ b/opensubdiv/osd/cudaGLVertexBuffer.cpp @@ -40,6 +40,9 @@ namespace Osd { CudaGLVertexBuffer::CudaGLVertexBuffer(int numElements, int numVertices) : _numElements(numElements), _numVertices(numVertices), _vbo(0), _devicePtr(0), _cudaResource(0) { + + // Initialize internal OpenGL loader library if necessary + OpenSubdiv::internal::GLLoader::libraryInitializeGL(); } CudaGLVertexBuffer::~CudaGLVertexBuffer() { diff --git a/opensubdiv/osd/glComputeEvaluator.cpp b/opensubdiv/osd/glComputeEvaluator.cpp index bebd9c19..ec5cd537 100644 --- a/opensubdiv/osd/glComputeEvaluator.cpp +++ b/opensubdiv/osd/glComputeEvaluator.cpp @@ -130,6 +130,9 @@ GLComputeEvaluator::GLComputeEvaluator() _patchArraysSSBO(0) { memset (&_stencilKernel, 0, sizeof(_stencilKernel)); memset (&_patchKernel, 0, sizeof(_patchKernel)); + + // Initialize internal OpenGL loader library if necessary + OpenSubdiv::internal::GLLoader::libraryInitializeGL(); } GLComputeEvaluator::~GLComputeEvaluator() { diff --git a/opensubdiv/osd/glLegacyGregoryPatchTable.cpp b/opensubdiv/osd/glLegacyGregoryPatchTable.cpp index e7abb3f5..ad48b7fb 100644 --- a/opensubdiv/osd/glLegacyGregoryPatchTable.cpp +++ b/opensubdiv/osd/glLegacyGregoryPatchTable.cpp @@ -35,6 +35,9 @@ GLLegacyGregoryPatchTable::GLLegacyGregoryPatchTable() : _vertexTextureBuffer(0), _vertexValenceTextureBuffer(0), _quadOffsetsTextureBuffer(0) { _quadOffsetsBase[0] = _quadOffsetsBase[1] = 0; + + // Initialize internal OpenGL loader library if necessary + OpenSubdiv::internal::GLLoader::libraryInitializeGL(); } GLLegacyGregoryPatchTable::~GLLegacyGregoryPatchTable() { diff --git a/opensubdiv/osd/glPatchTable.cpp b/opensubdiv/osd/glPatchTable.cpp index b7779c6d..856e726f 100644 --- a/opensubdiv/osd/glPatchTable.cpp +++ b/opensubdiv/osd/glPatchTable.cpp @@ -37,6 +37,9 @@ namespace Osd { GLPatchTable::GLPatchTable() : _patchIndexBuffer(0), _patchParamBuffer(0), _patchIndexTexture(0), _patchParamTexture(0) { + + // Initialize internal OpenGL loader library if necessary + OpenSubdiv::internal::GLLoader::libraryInitializeGL(); } GLPatchTable::~GLPatchTable() { diff --git a/opensubdiv/osd/glVertexBuffer.cpp b/opensubdiv/osd/glVertexBuffer.cpp index ad868a67..bc79788d 100644 --- a/opensubdiv/osd/glVertexBuffer.cpp +++ b/opensubdiv/osd/glVertexBuffer.cpp @@ -35,6 +35,9 @@ GLVertexBuffer::GLVertexBuffer(int numElements, int numVertices) : _numElements(numElements), _numVertices(numVertices), _vbo(0) { + + // Initialize internal OpenGL loader library if necessary + OpenSubdiv::internal::GLLoader::libraryInitializeGL(); } GLVertexBuffer::~GLVertexBuffer() { diff --git a/opensubdiv/osd/glXFBEvaluator.cpp b/opensubdiv/osd/glXFBEvaluator.cpp index eb0d5092..36a0cc23 100644 --- a/opensubdiv/osd/glXFBEvaluator.cpp +++ b/opensubdiv/osd/glXFBEvaluator.cpp @@ -157,6 +157,9 @@ GLXFBEvaluator::GLXFBEvaluator(bool interleavedDerivativeBuffers) : _srcBufferTexture(0), _patchArraysUBO(0), _interleavedDerivativeBuffers(interleavedDerivativeBuffers) { + + // Initialize internal OpenGL loader library if necessary + OpenSubdiv::internal::GLLoader::libraryInitializeGL(); } GLXFBEvaluator::~GLXFBEvaluator() {