From a0eb7de06034dba4ee934516e1155ba70d248da0 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Fri, 14 May 2010 19:47:50 +0000 Subject: [PATCH] From Alok Priyadarshi, support for statically linking to GLES2.lib --- src/osg/CMakeLists.txt | 2 + src/osg/GLExtensions.cpp | 10 +- src/osg/GLStaticLibrary.cpp | 208 ++++++++++++++++++++++++++++++++++++ src/osg/GLStaticLibrary.h | 33 ++++++ src/osg/Notify.cpp | 4 +- 5 files changed, 249 insertions(+), 8 deletions(-) create mode 100644 src/osg/GLStaticLibrary.cpp create mode 100644 src/osg/GLStaticLibrary.h diff --git a/src/osg/CMakeLists.txt b/src/osg/CMakeLists.txt index 915385907..a99dfb5c2 100644 --- a/src/osg/CMakeLists.txt +++ b/src/osg/CMakeLists.txt @@ -245,6 +245,8 @@ ADD_LIBRARY(${LIB_NAME} GLExtensions.cpp GLBeginEndAdapter.cpp GLObjects.cpp + GLStaticLibrary.h + GLStaticLibrary.cpp GraphicsContext.cpp GraphicsThread.cpp Group.cpp diff --git a/src/osg/GLExtensions.cpp b/src/osg/GLExtensions.cpp index 72ea24c62..183198619 100644 --- a/src/osg/GLExtensions.cpp +++ b/src/osg/GLExtensions.cpp @@ -26,11 +26,6 @@ #include #include -#if defined(WIN32) -#include -#endif - - typedef std::set ExtensionSet; static osg::buffered_object s_glExtensionSetList; static osg::buffered_object s_glRendererList; @@ -344,10 +339,11 @@ std::string& osg::getGLExtensionDisableString() #ifdef OSG_GL_LIBRARY_STATIC + #include "GLStaticLibrary.h" + void* osg::getGLExtensionFuncPtr(const char *funcName) { - OSG_NOTICE<<"osg::getGLExtensionFuncPtr("< + +#include +#include + +// This file is intended for GL static linking only. +#if defined(OSG_GL_LIBRARY_STATIC) + +using namespace osg; + +namespace { +typedef void (*GLProc)(void); +typedef std::map GLProcAddressMap; +static bool sProcAddressInitialized = false; +static GLProcAddressMap sProcAddressMap; + +void initGLES2ProcAddress() +{ + sProcAddressMap["glActiveTexture"] = reinterpret_cast(&glActiveTexture); + sProcAddressMap["glAttachShader"] = reinterpret_cast(&glAttachShader); + sProcAddressMap["glBindAttribLocation"] = reinterpret_cast(&glBindAttribLocation); + sProcAddressMap["glBindBuffer"] = reinterpret_cast(&glBindBuffer); + sProcAddressMap["glBindFramebuffer"] = reinterpret_cast(&glBindFramebuffer); + sProcAddressMap["glBindRenderbuffer"] = reinterpret_cast(&glBindRenderbuffer); + sProcAddressMap["glBindTexture"] = reinterpret_cast(&glBindTexture); + sProcAddressMap["glBlendColor"] = reinterpret_cast(&glBlendColor); + sProcAddressMap["glBlendEquation"] = reinterpret_cast(&glBlendEquation); + sProcAddressMap["glBlendEquationSeparate"] = reinterpret_cast(&glBlendEquationSeparate); + sProcAddressMap["glBlendFunc"] = reinterpret_cast(&glBlendFunc); + sProcAddressMap["glBlendFuncSeparate"] = reinterpret_cast(&glBlendFuncSeparate); + sProcAddressMap["glBufferData"] = reinterpret_cast(&glBufferData); + sProcAddressMap["glBufferSubData"] = reinterpret_cast(&glBufferSubData); + sProcAddressMap["glCheckFramebufferStatus"] = reinterpret_cast(&glCheckFramebufferStatus); + sProcAddressMap["glClear"] = reinterpret_cast(&glClear); + sProcAddressMap["glClearColor"] = reinterpret_cast(&glClearColor); + sProcAddressMap["glClearDepthf"] = reinterpret_cast(&glClearDepthf); + sProcAddressMap["glClearStencil"] = reinterpret_cast(&glClearStencil); + sProcAddressMap["glColorMask"] = reinterpret_cast(&glColorMask); + sProcAddressMap["glCompileShader"] = reinterpret_cast(&glCompileShader); + sProcAddressMap["glCompressedTexImage2D"] = reinterpret_cast(&glCompressedTexImage2D); + sProcAddressMap["glCompressedTexSubImage2D"] = reinterpret_cast(&glCompressedTexSubImage2D); + sProcAddressMap["glCopyTexImage2D"] = reinterpret_cast(&glCopyTexImage2D); + sProcAddressMap["glCopyTexSubImage2D"] = reinterpret_cast(&glCopyTexSubImage2D); + sProcAddressMap["glCreateProgram"] = reinterpret_cast(&glCreateProgram); + sProcAddressMap["glCreateShader"] = reinterpret_cast(&glCreateShader); + sProcAddressMap["glCullFace"] = reinterpret_cast(&glCullFace); + sProcAddressMap["glDeleteBuffers"] = reinterpret_cast(&glDeleteBuffers); + sProcAddressMap["glDeleteFramebuffers"] = reinterpret_cast(&glDeleteFramebuffers); + sProcAddressMap["glDeleteProgram"] = reinterpret_cast(&glDeleteProgram); + sProcAddressMap["glDeleteRenderbuffers"] = reinterpret_cast(&glDeleteRenderbuffers); + sProcAddressMap["glDeleteShader"] = reinterpret_cast(&glDeleteShader); + sProcAddressMap["glDeleteTextures"] = reinterpret_cast(&glDeleteTextures); + sProcAddressMap["glDepthFunc"] = reinterpret_cast(&glDepthFunc); + sProcAddressMap["glDepthMask"] = reinterpret_cast(&glDepthMask); + sProcAddressMap["glDepthRangef"] = reinterpret_cast(&glDepthRangef); + sProcAddressMap["glDetachShader"] = reinterpret_cast(&glDetachShader); + sProcAddressMap["glDisable"] = reinterpret_cast(&glDisable); + sProcAddressMap["glDisableVertexAttribArray"] = reinterpret_cast(&glDisableVertexAttribArray); + sProcAddressMap["glDrawArrays"] = reinterpret_cast(&glDrawArrays); + sProcAddressMap["glDrawElements"] = reinterpret_cast(&glDrawElements); + sProcAddressMap["glEnable"] = reinterpret_cast(&glEnable); + sProcAddressMap["glEnableVertexAttribArray"] = reinterpret_cast(&glEnableVertexAttribArray); + sProcAddressMap["glFinish"] = reinterpret_cast(&glFinish); + sProcAddressMap["glFlush"] = reinterpret_cast(&glFlush); + sProcAddressMap["glFramebufferRenderbuffer"] = reinterpret_cast(&glFramebufferRenderbuffer); + sProcAddressMap["glFramebufferTexture2D"] = reinterpret_cast(&glFramebufferTexture2D); + sProcAddressMap["glFrontFace"] = reinterpret_cast(&glFrontFace); + sProcAddressMap["glGenBuffers"] = reinterpret_cast(&glGenBuffers); + sProcAddressMap["glGenerateMipmap"] = reinterpret_cast(&glGenerateMipmap); + sProcAddressMap["glGenFramebuffers"] = reinterpret_cast(&glGenFramebuffers); + sProcAddressMap["glGenRenderbuffers"] = reinterpret_cast(&glGenRenderbuffers); + sProcAddressMap["glGenTextures"] = reinterpret_cast(&glGenTextures); + sProcAddressMap["glGetActiveAttrib"] = reinterpret_cast(&glGetActiveAttrib); + sProcAddressMap["glGetActiveUniform"] = reinterpret_cast(&glGetActiveUniform); + sProcAddressMap["glGetAttachedShaders"] = reinterpret_cast(&glGetAttachedShaders); + sProcAddressMap["glGetAttribLocation"] = reinterpret_cast(&glGetAttribLocation); + sProcAddressMap["glGetBooleanv"] = reinterpret_cast(&glGetBooleanv); + sProcAddressMap["glGetBufferParameteriv"] = reinterpret_cast(&glGetBufferParameteriv); + sProcAddressMap["glGetError"] = reinterpret_cast(&glGetError); + sProcAddressMap["glGetFloatv"] = reinterpret_cast(&glGetFloatv); + sProcAddressMap["glGetFramebufferAttachmentParameteriv"] = reinterpret_cast(&glGetFramebufferAttachmentParameteriv); + sProcAddressMap["glGetIntegerv"] = reinterpret_cast(&glGetIntegerv); + sProcAddressMap["glGetProgramiv"] = reinterpret_cast(&glGetProgramiv); + sProcAddressMap["glGetProgramInfoLog"] = reinterpret_cast(&glGetProgramInfoLog); + sProcAddressMap["glGetRenderbufferParameteriv"] = reinterpret_cast(&glGetRenderbufferParameteriv); + sProcAddressMap["glGetShaderiv"] = reinterpret_cast(&glGetShaderiv); + sProcAddressMap["glGetShaderInfoLog"] = reinterpret_cast(&glGetShaderInfoLog); + sProcAddressMap["glGetShaderPrecisionFormat"] = reinterpret_cast(&glGetShaderPrecisionFormat); + sProcAddressMap["glGetShaderSource"] = reinterpret_cast(&glGetShaderSource); + sProcAddressMap["glGetString"] = reinterpret_cast(&glGetString); + sProcAddressMap["glGetTexParameterfv"] = reinterpret_cast(&glGetTexParameterfv); + sProcAddressMap["glGetTexParameteriv"] = reinterpret_cast(&glGetTexParameteriv); + sProcAddressMap["glGetUniformfv"] = reinterpret_cast(&glGetUniformfv); + sProcAddressMap["glGetUniformiv"] = reinterpret_cast(&glGetUniformiv); + sProcAddressMap["glGetUniformLocation"] = reinterpret_cast(&glGetUniformLocation); + sProcAddressMap["glGetVertexAttribfv"] = reinterpret_cast(&glGetVertexAttribfv); + sProcAddressMap["glGetVertexAttribiv"] = reinterpret_cast(&glGetVertexAttribiv); + sProcAddressMap["glGetVertexAttribPointerv"] = reinterpret_cast(&glGetVertexAttribPointerv); + sProcAddressMap["glHint"] = reinterpret_cast(&glHint); + sProcAddressMap["glIsBuffer"] = reinterpret_cast(&glIsBuffer); + sProcAddressMap["glIsEnabled"] = reinterpret_cast(&glIsEnabled); + sProcAddressMap["glIsFramebuffer"] = reinterpret_cast(&glIsFramebuffer); + sProcAddressMap["glIsProgram"] = reinterpret_cast(&glIsProgram); + sProcAddressMap["glIsRenderbuffer"] = reinterpret_cast(&glIsRenderbuffer); + sProcAddressMap["glIsShader"] = reinterpret_cast(&glIsShader); + sProcAddressMap["glIsTexture"] = reinterpret_cast(&glIsTexture); + sProcAddressMap["glLineWidth"] = reinterpret_cast(&glLineWidth); + sProcAddressMap["glLinkProgram"] = reinterpret_cast(&glLinkProgram); + sProcAddressMap["glPixelStorei"] = reinterpret_cast(&glPixelStorei); + sProcAddressMap["glPolygonOffset"] = reinterpret_cast(&glPolygonOffset); + sProcAddressMap["glReadPixels"] = reinterpret_cast(&glReadPixels); + sProcAddressMap["glReleaseShaderCompiler"] = reinterpret_cast(&glReleaseShaderCompiler); + sProcAddressMap["glRenderbufferStorage"] = reinterpret_cast(&glRenderbufferStorage); + sProcAddressMap["glSampleCoverage"] = reinterpret_cast(&glSampleCoverage); + sProcAddressMap["glScissor"] = reinterpret_cast(&glScissor); + sProcAddressMap["glShaderBinary"] = reinterpret_cast(&glShaderBinary); + sProcAddressMap["glShaderSource"] = reinterpret_cast(&glShaderSource); + sProcAddressMap["glStencilFunc"] = reinterpret_cast(&glStencilFunc); + sProcAddressMap["glStencilFuncSeparate"] = reinterpret_cast(&glStencilFuncSeparate); + sProcAddressMap["glStencilMask"] = reinterpret_cast(&glStencilMask); + sProcAddressMap["glStencilMaskSeparate"] = reinterpret_cast(&glStencilMaskSeparate); + sProcAddressMap["glStencilOp"] = reinterpret_cast(&glStencilOp); + sProcAddressMap["glStencilOpSeparate"] = reinterpret_cast(&glStencilOpSeparate); + sProcAddressMap["glTexImage2D"] = reinterpret_cast(&glTexImage2D); + sProcAddressMap["glTexParameterf"] = reinterpret_cast(&glTexParameterf); + sProcAddressMap["glTexParameterfv"] = reinterpret_cast(&glTexParameterfv); + sProcAddressMap["glTexParameteri"] = reinterpret_cast(&glTexParameteri); + sProcAddressMap["glTexParameteriv"] = reinterpret_cast(&glTexParameteriv); + sProcAddressMap["glTexSubImage2D"] = reinterpret_cast(&glTexSubImage2D); + sProcAddressMap["glUniform1f"] = reinterpret_cast(&glUniform1f); + sProcAddressMap["glUniform1fv"] = reinterpret_cast(&glUniform1fv); + sProcAddressMap["glUniform1i"] = reinterpret_cast(&glUniform1i); + sProcAddressMap["glUniform1iv"] = reinterpret_cast(&glUniform1iv); + sProcAddressMap["glUniform2f"] = reinterpret_cast(&glUniform2f); + sProcAddressMap["glUniform2fv"] = reinterpret_cast(&glUniform2fv); + sProcAddressMap["glUniform2i"] = reinterpret_cast(&glUniform2i); + sProcAddressMap["glUniform2iv"] = reinterpret_cast(&glUniform2iv); + sProcAddressMap["glUniform3f"] = reinterpret_cast(&glUniform3f); + sProcAddressMap["glUniform3fv"] = reinterpret_cast(&glUniform3fv); + sProcAddressMap["glUniform3i"] = reinterpret_cast(&glUniform3i); + sProcAddressMap["glUniform3iv"] = reinterpret_cast(&glUniform3iv); + sProcAddressMap["glUniform4f"] = reinterpret_cast(&glUniform4f); + sProcAddressMap["glUniform4fv"] = reinterpret_cast(&glUniform4fv); + sProcAddressMap["glUniform4i"] = reinterpret_cast(&glUniform4i); + sProcAddressMap["glUniform4iv"] = reinterpret_cast(&glUniform4iv); + sProcAddressMap["glUniformMatrix2fv"] = reinterpret_cast(&glUniformMatrix2fv); + sProcAddressMap["glUniformMatrix3fv"] = reinterpret_cast(&glUniformMatrix3fv); + sProcAddressMap["glUniformMatrix4fv"] = reinterpret_cast(&glUniformMatrix4fv); + sProcAddressMap["glUseProgram"] = reinterpret_cast(&glUseProgram); + sProcAddressMap["glValidateProgram"] = reinterpret_cast(&glValidateProgram); + sProcAddressMap["glVertexAttrib1f"] = reinterpret_cast(&glVertexAttrib1f); + sProcAddressMap["glVertexAttrib1fv"] = reinterpret_cast(&glVertexAttrib1fv); + sProcAddressMap["glVertexAttrib2f"] = reinterpret_cast(&glVertexAttrib2f); + sProcAddressMap["glVertexAttrib2fv"] = reinterpret_cast(&glVertexAttrib2fv); + sProcAddressMap["glVertexAttrib3f"] = reinterpret_cast(&glVertexAttrib3f); + sProcAddressMap["glVertexAttrib3fv"] = reinterpret_cast(&glVertexAttrib3fv); + sProcAddressMap["glVertexAttrib4f"] = reinterpret_cast(&glVertexAttrib4f); + sProcAddressMap["glVertexAttrib4fv"] = reinterpret_cast(&glVertexAttrib4fv); + sProcAddressMap["glVertexAttribPointer"] = reinterpret_cast(&glVertexAttribPointer); + sProcAddressMap["glViewport"] = reinterpret_cast(&glViewport); +} + +void initProcAddress() +{ +#if defined(OSG_GLES2_AVAILABLE) + initGLES2ProcAddress(); +#else + OSG_NOTICE << "initProcAddress() not implemented for static GL lib yet." << std::endl; +#endif +} + +} // namespace + +void* GLStaticLibrary::getProcAddress(const char* procName) +{ + // TODO(alokp): Add a mutex around sProcAddressInitialized. + if (!sProcAddressInitialized) + { + initProcAddress(); + sProcAddressInitialized = true; + } + + GLProcAddressMap::const_iterator iter = sProcAddressMap.find(procName); + return iter != sProcAddressMap.end() ? iter->second : 0; +} + +#endif // OSG_GLES2_LIBRARY_STATIC + diff --git a/src/osg/GLStaticLibrary.h b/src/osg/GLStaticLibrary.h new file mode 100644 index 000000000..4440a266c --- /dev/null +++ b/src/osg/GLStaticLibrary.h @@ -0,0 +1,33 @@ +/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield + * Copyright (C) 2003-2005 3Dlabs Inc. Ltd. + * Copyright (C) 2004-2005 Nathan Cournia + * Copyright (C) 2007 Art Tevs + * Copyright (C) 2008 Zebra Imaging + * + * This application is open source and may be redistributed and/or modified + * freely and without restriction, both in commericial and non commericial + * applications, as long as this copyright notice is maintained. + * + * This application is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +*/ + +/* file: src/osg/GLStaticLibrary.h + * author: Alok Priyadarshi 2010-04-27 +*/ + +#ifndef OSG_GLSTATICLIBRARY +#define OSG_GLSTATICLIBRARY 1 + +namespace osg { + +class GLStaticLibrary +{ +public: + static void* getProcAddress(const char* procName); +}; + +} + +#endif diff --git a/src/osg/Notify.cpp b/src/osg/Notify.cpp index 18d2b82a5..fda36c4ee 100644 --- a/src/osg/Notify.cpp +++ b/src/osg/Notify.cpp @@ -231,7 +231,9 @@ void osg::StandardNotifyHandler::notify(osg::NotifySeverity severity, const char #if defined(WIN32) && !defined(__CYGWIN__) -#define WIN32_LEAN_AND_MEAN +#ifndef WIN32_LEAN_AND_MEAN + #define WIN32_LEAN_AND_MEAN +#endif #include void osg::WinDebugNotifyHandler::notify(osg::NotifySeverity severity, const char *message)