1 /* 2 * Copyright (C) 2011 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 #include "GLDispatch.h" 17 #include <stdio.h> 18 #include <OpenglOsUtils/osDynLibrary.h> 19 20 #ifdef __linux__ 21 #include <GL/glx.h> 22 #elif defined(WIN32) 23 #include <windows.h> 24 #endif 25 26 typedef void (*GL_FUNC_PTR)(); 27 getGLFuncAddress(const char * funcName)28static GL_FUNC_PTR getGLFuncAddress(const char *funcName) { 29 GL_FUNC_PTR ret = NULL; 30 #ifdef __linux__ 31 static osUtils::dynLibrary* libGL = osUtils::dynLibrary::open("libGL.so"); 32 ret = (GL_FUNC_PTR)glXGetProcAddress((const GLubyte*)funcName); 33 #elif defined(WIN32) 34 static osUtils::dynLibrary* libGL = osUtils::dynLibrary::open("opengl32"); 35 ret = (GL_FUNC_PTR)wglGetProcAddress(funcName); 36 #endif 37 if(!ret && libGL){ 38 ret = libGL->findSymbol(funcName); 39 } 40 return ret; 41 } 42 43 #define LOAD_GL_FUNC(name) { void * funcAddrs = NULL; \ 44 funcAddrs = (void *)getGLFuncAddress(#name); \ 45 if(funcAddrs) \ 46 *(void**)(&name) = funcAddrs; \ 47 else \ 48 fprintf(stderr,"could not load func %s\n",#name); } 49 GLDispatch()50GLDispatch::GLDispatch():m_isLoaded(false){}; 51 52 dispatchFuncs()53void GLDispatch::dispatchFuncs() { 54 emugl::Mutex::AutoLock mutex(m_lock); 55 if(m_isLoaded) 56 return; 57 LOAD_GL_FUNC(glActiveTexture); 58 LOAD_GL_FUNC(glAlphaFunc); 59 LOAD_GL_FUNC(glBegin); 60 LOAD_GL_FUNC(glBindBuffer); 61 LOAD_GL_FUNC(glBindTexture); 62 LOAD_GL_FUNC(glBlendFunc); 63 LOAD_GL_FUNC(glBufferData); 64 LOAD_GL_FUNC(glBufferSubData); 65 LOAD_GL_FUNC(glClear); 66 LOAD_GL_FUNC(glClearColor); 67 LOAD_GL_FUNC(glClearDepth); 68 LOAD_GL_FUNC(glClearStencil); 69 LOAD_GL_FUNC(glClientActiveTexture); 70 LOAD_GL_FUNC(glClipPlane); 71 LOAD_GL_FUNC(glColor4d); 72 LOAD_GL_FUNC(glColor4f); 73 LOAD_GL_FUNC(glColor4fv); 74 LOAD_GL_FUNC(glColor4ub); 75 LOAD_GL_FUNC(glColor4ubv); 76 LOAD_GL_FUNC(glColorMask); 77 LOAD_GL_FUNC(glColorPointer); 78 LOAD_GL_FUNC(glCompressedTexImage2D); 79 LOAD_GL_FUNC(glCompressedTexSubImage2D); 80 LOAD_GL_FUNC(glCopyTexImage2D); 81 LOAD_GL_FUNC(glCopyTexSubImage2D); 82 LOAD_GL_FUNC(glCullFace); 83 LOAD_GL_FUNC(glDeleteBuffers); 84 LOAD_GL_FUNC(glDeleteTextures); 85 LOAD_GL_FUNC(glDepthFunc); 86 LOAD_GL_FUNC(glDepthMask); 87 LOAD_GL_FUNC(glDepthRange); 88 LOAD_GL_FUNC(glDisable); 89 LOAD_GL_FUNC(glDisableClientState); 90 LOAD_GL_FUNC(glDrawArrays); 91 LOAD_GL_FUNC(glDrawElements); 92 LOAD_GL_FUNC(glEnable); 93 LOAD_GL_FUNC(glEnableClientState); 94 LOAD_GL_FUNC(glEnd); 95 LOAD_GL_FUNC(glFinish); 96 LOAD_GL_FUNC(glFlush); 97 LOAD_GL_FUNC(glFogf); 98 LOAD_GL_FUNC(glFogfv); 99 LOAD_GL_FUNC(glFrontFace); 100 LOAD_GL_FUNC(glFrustum); 101 LOAD_GL_FUNC(glGenBuffers); 102 LOAD_GL_FUNC(glGenTextures); 103 LOAD_GL_FUNC(glGetBooleanv); 104 LOAD_GL_FUNC(glGetBufferParameteriv); 105 LOAD_GL_FUNC(glGetClipPlane); 106 LOAD_GL_FUNC(glGetDoublev); 107 LOAD_GL_FUNC(glGetError); 108 LOAD_GL_FUNC(glGetFloatv); 109 LOAD_GL_FUNC(glGetIntegerv); 110 LOAD_GL_FUNC(glGetLightfv); 111 LOAD_GL_FUNC(glGetMaterialfv); 112 LOAD_GL_FUNC(glGetPointerv); 113 LOAD_GL_FUNC(glGetString); 114 LOAD_GL_FUNC(glGetTexEnvfv); 115 LOAD_GL_FUNC(glGetTexEnviv); 116 LOAD_GL_FUNC(glGetTexParameterfv); 117 LOAD_GL_FUNC(glGetTexParameteriv); 118 LOAD_GL_FUNC(glHint); 119 LOAD_GL_FUNC(glIsBuffer); 120 LOAD_GL_FUNC(glIsEnabled); 121 LOAD_GL_FUNC(glIsTexture); 122 LOAD_GL_FUNC(glLightf); 123 LOAD_GL_FUNC(glLightfv); 124 LOAD_GL_FUNC(glLightModelf); 125 LOAD_GL_FUNC(glLightModelfv); 126 LOAD_GL_FUNC(glLineWidth); 127 LOAD_GL_FUNC(glLoadIdentity); 128 LOAD_GL_FUNC(glLoadMatrixf); 129 LOAD_GL_FUNC(glLogicOp); 130 LOAD_GL_FUNC(glMaterialf); 131 LOAD_GL_FUNC(glMaterialfv); 132 LOAD_GL_FUNC(glMultiTexCoord2fv); 133 LOAD_GL_FUNC(glMultiTexCoord2sv); 134 LOAD_GL_FUNC(glMultiTexCoord3fv); 135 LOAD_GL_FUNC(glMultiTexCoord3sv); 136 LOAD_GL_FUNC(glMultiTexCoord4fv); 137 LOAD_GL_FUNC(glMultiTexCoord4sv); 138 LOAD_GL_FUNC(glMultiTexCoord4f); 139 LOAD_GL_FUNC(glMultMatrixf); 140 LOAD_GL_FUNC(glNormal3f); 141 LOAD_GL_FUNC(glNormal3fv); 142 LOAD_GL_FUNC(glNormal3sv); 143 LOAD_GL_FUNC(glOrtho); 144 LOAD_GL_FUNC(glPointParameterf); 145 LOAD_GL_FUNC(glPointParameterfv); 146 LOAD_GL_FUNC(glPointSize); 147 LOAD_GL_FUNC(glPolygonOffset); 148 LOAD_GL_FUNC(glRotatef); 149 LOAD_GL_FUNC(glScalef); 150 LOAD_GL_FUNC(glTexEnvf); 151 LOAD_GL_FUNC(glTexEnvfv); 152 LOAD_GL_FUNC(glTexParameterf); 153 LOAD_GL_FUNC(glTexParameterfv); 154 LOAD_GL_FUNC(glMatrixMode); 155 LOAD_GL_FUNC(glNormalPointer); 156 LOAD_GL_FUNC(glPixelStorei); 157 LOAD_GL_FUNC(glPopMatrix); 158 LOAD_GL_FUNC(glPushMatrix); 159 LOAD_GL_FUNC(glReadPixels); 160 LOAD_GL_FUNC(glSampleCoverage); 161 LOAD_GL_FUNC(glScissor); 162 LOAD_GL_FUNC(glShadeModel); 163 LOAD_GL_FUNC(glStencilFunc); 164 LOAD_GL_FUNC(glStencilMask); 165 LOAD_GL_FUNC(glStencilOp); 166 LOAD_GL_FUNC(glTexCoordPointer); 167 LOAD_GL_FUNC(glTexEnvi); 168 LOAD_GL_FUNC(glTexEnviv); 169 LOAD_GL_FUNC(glTexImage2D); 170 LOAD_GL_FUNC(glTexParameteri); 171 LOAD_GL_FUNC(glTexParameteriv); 172 LOAD_GL_FUNC(glTexSubImage2D); 173 LOAD_GL_FUNC(glTranslatef); 174 LOAD_GL_FUNC(glVertexPointer); 175 LOAD_GL_FUNC(glViewport); 176 177 m_isLoaded = true; 178 } 179