/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield * Copyright (C) 2003-2005 3Dlabs Inc. Ltd. * Copyright (C) 2004-2005 Nathan Cournia * 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.cpp * author: Alok Priyadarshi 2010-04-27 */ #include "GLStaticLibrary.h" #include #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