Enabled internal GL API loader as GLEW alternative

At build time, the preprocessor symbols: OSD_USES_GLEW or
OSD_USES_INTERNAL_GLAPILOADER determine the GL API loader
that will be used by the OSD library.
This commit is contained in:
David G Yu 2020-03-04 09:47:36 -08:00
parent 720462a315
commit f3f28995a5
12 changed files with 66 additions and 33 deletions

View File

@ -306,6 +306,7 @@ option(NO_METAL "Disable Metal support" OFF)
option(NO_DX "Disable DirectX support") option(NO_DX "Disable DirectX support")
option(NO_TESTS "Disable all tests") option(NO_TESTS "Disable all tests")
option(NO_GLTESTS "Disable GL 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 "Disable components depending on GLFW" OFF)
option(NO_GLFW_X11 "Disable GLFW components depending on X11" OFF) option(NO_GLFW_X11 "Disable GLFW components depending on X11" OFF)
@ -351,13 +352,17 @@ if (OPENGL_FOUND AND NOT IOS)
add_definitions( add_definitions(
-DOPENSUBDIV_HAS_OPENGL -DOPENSUBDIV_HAS_OPENGL
) )
if (APPLE) if (NOT NO_GLEW)
find_package(GLEW) if (APPLE)
else() find_package(GLEW)
find_package(GLEW REQUIRED) else()
find_package(GLEW REQUIRED)
endif()
endif() endif()
if(GLEW_FOUND) if(GLEW_FOUND)
add_definitions( -DOSD_USES_GLEW ) add_definitions( -DOSD_USES_GLEW )
else()
add_definitions( -DOSD_USES_INTERNAL_GLAPILOADER )
endif() endif()
endif() endif()
@ -457,9 +462,9 @@ if(GLEW_FOUND AND GLEW_INCLUDE_DIR)
${GLEW_LIBRARY} ${GLEW_LIBRARY}
${OPENGL_gl_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 set(OPENGL_LOADER_INCLUDE_DIRS
${OPENGL_INCLUDE_DIR} ${OPENGL_INCLUDE_DIR}
${PROJECT_SOURCE_DIR}/glLoader) ${PROJECT_SOURCE_DIR}/glLoader)

View File

@ -28,10 +28,13 @@ endif()
list(APPEND GLLOADER_SOURCE_FILES list(APPEND GLLOADER_SOURCE_FILES
glLoader.cpp glLoader.cpp
glApi.cpp
) )
list(APPEND GLLOADER_HEADER_FILES list(APPEND GLLOADER_HEADER_FILES
glLoader.h glLoader.h
glApi.h
khrplatform.h
) )
include_directories( include_directories(

View File

@ -36,7 +36,12 @@ namespace GLLoader {
bool bool
applicationInitializeGL() 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 #define CORE_PROFILE
#ifdef CORE_PROFILE #ifdef CORE_PROFILE
// this is the only way to initialize GLEW (before GLEW 1.13) // this is the only way to initialize GLEW (before GLEW 1.13)
@ -60,8 +65,12 @@ applicationInitializeGL()
bool bool
libraryInitializeGL() libraryInitializeGL()
{ {
// do nothing #if defined(OSD_USES_INTERNAL_GLAPILOADER)
return OpenSubdiv::internal::GLApi::glApiLoad();
#else
// otherwise do nothing
return true; return true;
#endif
} }

View File

@ -31,6 +31,11 @@
/// function entry points at run-time and to define types, enum values, /// function entry points at run-time and to define types, enum values,
/// and function prototypes needed at compile-time. /// 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: /// To use:
/// - Include "glloader.h" /// - Include "glloader.h"
/// ///
@ -132,36 +137,18 @@
/// The boolean variables described here are defined in an internal namespace. /// 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 // -- GLEW
#include <GL/glew.h> #include <GL/glew.h>
#define OSD_OPENGL_HAS(token) (GLEW_##token) #define OSD_OPENGL_HAS(token) (GLEW_##token)
#else
// -- PLATFORM
#if defined(__APPLE__)
#include "TargetConditionals.h"
#if TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR
#include <OpenGLES/ES2/gl.h>
#else
#include <OpenGL/gl3.h>
#endif
#elif defined(ANDROID)
#include <GLES2/gl2.h>
#elif defined(_WIN32)
#define WIN32_LEAN_AND_MEAN
#include <GL/gl.h>
#include <windows.h>
#else
#define GL_GLEXT_PROTOTYPES
#include <GL/gl.h>
#include <GL/glext.h>
#endif
#define OSD_OPENGL_HAS(token) (GL_##token)
#endif #endif
namespace OpenSubdiv { namespace OpenSubdiv {
@ -184,4 +171,9 @@ extern bool libraryInitializeGL();
} // namespace OpenSubdiv } // namespace OpenSubdiv
#if defined(OSD_USES_INTERNAL_GLAPILOADER)
using namespace OpenSubdiv::internal::GLApi;
#endif
#endif // OPENSUBDIV3_GLLOADER_H #endif // OPENSUBDIV3_GLLOADER_H

View File

@ -38,6 +38,9 @@ CLGLVertexBuffer::CLGLVertexBuffer(int numElements,
cl_context /* clContext */) cl_context /* clContext */)
: _numElements(numElements), _numVertices(numVertices), : _numElements(numElements), _numVertices(numVertices),
_vbo(0), _clQueue(0), _clMemory(0), _clMapped(false) { _vbo(0), _clQueue(0), _clMemory(0), _clMapped(false) {
// Initialize internal OpenGL loader library if necessary
OpenSubdiv::internal::GLLoader::libraryInitializeGL();
} }
CLGLVertexBuffer::~CLGLVertexBuffer() { CLGLVertexBuffer::~CLGLVertexBuffer() {

View File

@ -37,6 +37,9 @@ namespace Osd {
CpuGLVertexBuffer::CpuGLVertexBuffer(int numElements, int numVertices) CpuGLVertexBuffer::CpuGLVertexBuffer(int numElements, int numVertices)
: _numElements(numElements), _numVertices(numVertices), : _numElements(numElements), _numVertices(numVertices),
_vbo(0), _cpuBuffer(0), _dataDirty(true) { _vbo(0), _cpuBuffer(0), _dataDirty(true) {
// Initialize internal OpenGL loader library if necessary
OpenSubdiv::internal::GLLoader::libraryInitializeGL();
} }
CpuGLVertexBuffer::~CpuGLVertexBuffer() { CpuGLVertexBuffer::~CpuGLVertexBuffer() {

View File

@ -40,6 +40,9 @@ namespace Osd {
CudaGLVertexBuffer::CudaGLVertexBuffer(int numElements, int numVertices) CudaGLVertexBuffer::CudaGLVertexBuffer(int numElements, int numVertices)
: _numElements(numElements), _numVertices(numVertices), : _numElements(numElements), _numVertices(numVertices),
_vbo(0), _devicePtr(0), _cudaResource(0) { _vbo(0), _devicePtr(0), _cudaResource(0) {
// Initialize internal OpenGL loader library if necessary
OpenSubdiv::internal::GLLoader::libraryInitializeGL();
} }
CudaGLVertexBuffer::~CudaGLVertexBuffer() { CudaGLVertexBuffer::~CudaGLVertexBuffer() {

View File

@ -130,6 +130,9 @@ GLComputeEvaluator::GLComputeEvaluator()
_patchArraysSSBO(0) { _patchArraysSSBO(0) {
memset (&_stencilKernel, 0, sizeof(_stencilKernel)); memset (&_stencilKernel, 0, sizeof(_stencilKernel));
memset (&_patchKernel, 0, sizeof(_patchKernel)); memset (&_patchKernel, 0, sizeof(_patchKernel));
// Initialize internal OpenGL loader library if necessary
OpenSubdiv::internal::GLLoader::libraryInitializeGL();
} }
GLComputeEvaluator::~GLComputeEvaluator() { GLComputeEvaluator::~GLComputeEvaluator() {

View File

@ -35,6 +35,9 @@ GLLegacyGregoryPatchTable::GLLegacyGregoryPatchTable() :
_vertexTextureBuffer(0), _vertexValenceTextureBuffer(0), _vertexTextureBuffer(0), _vertexValenceTextureBuffer(0),
_quadOffsetsTextureBuffer(0) { _quadOffsetsTextureBuffer(0) {
_quadOffsetsBase[0] = _quadOffsetsBase[1] = 0; _quadOffsetsBase[0] = _quadOffsetsBase[1] = 0;
// Initialize internal OpenGL loader library if necessary
OpenSubdiv::internal::GLLoader::libraryInitializeGL();
} }
GLLegacyGregoryPatchTable::~GLLegacyGregoryPatchTable() { GLLegacyGregoryPatchTable::~GLLegacyGregoryPatchTable() {

View File

@ -37,6 +37,9 @@ namespace Osd {
GLPatchTable::GLPatchTable() : GLPatchTable::GLPatchTable() :
_patchIndexBuffer(0), _patchParamBuffer(0), _patchIndexBuffer(0), _patchParamBuffer(0),
_patchIndexTexture(0), _patchParamTexture(0) { _patchIndexTexture(0), _patchParamTexture(0) {
// Initialize internal OpenGL loader library if necessary
OpenSubdiv::internal::GLLoader::libraryInitializeGL();
} }
GLPatchTable::~GLPatchTable() { GLPatchTable::~GLPatchTable() {

View File

@ -35,6 +35,9 @@ GLVertexBuffer::GLVertexBuffer(int numElements, int numVertices)
: _numElements(numElements), : _numElements(numElements),
_numVertices(numVertices), _numVertices(numVertices),
_vbo(0) { _vbo(0) {
// Initialize internal OpenGL loader library if necessary
OpenSubdiv::internal::GLLoader::libraryInitializeGL();
} }
GLVertexBuffer::~GLVertexBuffer() { GLVertexBuffer::~GLVertexBuffer() {

View File

@ -157,6 +157,9 @@ GLXFBEvaluator::GLXFBEvaluator(bool interleavedDerivativeBuffers)
: _srcBufferTexture(0), : _srcBufferTexture(0),
_patchArraysUBO(0), _patchArraysUBO(0),
_interleavedDerivativeBuffers(interleavedDerivativeBuffers) { _interleavedDerivativeBuffers(interleavedDerivativeBuffers) {
// Initialize internal OpenGL loader library if necessary
OpenSubdiv::internal::GLLoader::libraryInitializeGL();
} }
GLXFBEvaluator::~GLXFBEvaluator() { GLXFBEvaluator::~GLXFBEvaluator() {