1 /*
2 Copyright (C) 2007-2009 Olli Hinkka
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 See the GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 */
23 #include <stdio.h>
24 #include <stdlib.h>
27 //#include <cutils/log.h>
34 #define DEBUG_NANO 0
36 #ifdef __ANDROID__
37 #include <android/log.h>
38 #define LOG __android_log_print
40 #define LOGI(...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)
41 #define LOGD(...) if (DEBUG_NANO) __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__)
42 #define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG,__VA_ARGS__)
43 #define LOGW(...) __android_log_print(ANDROID_LOG_WARN, LOG_TAG,__VA_ARGS__)
44 #else
45 #ifndef _MSC_VER
50 #else
51 #define LOGI printf
52 #define LOGD printf
53 #define LOGE printf
54 #define LOGW printf
56 #endif
57 #endif
59 #ifdef _WIN32
60 #include <windows.h>
61 #define dlopen(x,y) LoadLibraryA(x)
62 #define dlsym(x,y) (void*)GetProcAddress((HINSTANCE)x,y)
63 #define dlclose(x) FreeLibrary((HINSTANCE)x)
64 #else
65 #include <dlfcn.h>
66 #endif
69 //#define GL_ENTRY(_r, _api, ...) #_api,
73 NULL
74 };
76 //const char * driver;
85 #ifndef USE_CORE_PROFILE
87 #endif
88 }
90 #ifdef XASH_SDL
92 #endif
95 {
97 #ifdef XASH_SDL
100 #endif
103 }
105 static int CreateGlEsInterface( const char * name, void * lib, void * lib1, void * default_func )
106 {
107 // alloc space
113 }
115 // load GL API calls
119 // nanoGL interface pointer
123 {
128 #ifdef USE_CORE_PROFILE
129 // Hack: try ARB and EXT suffix
134 }
139 }
140 #endif
144 // try lib1
150 if( glEsImpl->eglGetProcAddress && ( (void*)glEsImpl->eglGetProcAddress != (void*)gl_unimplemented ) )
155 }
158 }
159 }
160 else
161 {
163 if( glEsImpl->eglGetProcAddress && ( (void*)glEsImpl->eglGetProcAddress != (void*)gl_unimplemented ) )
167 }
168 }
171 }
174 api++;
175 }
178 }
180 // Load using the dynamic loader
185 }
187 /**
188 * Init
189 */
190 #ifdef _WIN32
192 {
198 // load lib
200 //LOG (ANDROID_LOG_DEBUG, LOG_TAG, "nanoGL: Init loading driver %s\n", lib1);
203 {
209 }
210 else
212 }
213 else
218 //if ( strcmp(driver, lib2) == 0 ) {
225 }
226 //}
228 // Load API gl* for 1.5+ else egl* gl*
229 //if (CreateGlEsInterface(driver, glesLib, eglLib, NULL) == -1)
231 {
232 // release lib
237 }
239 // Init nanoGL
242 }
243 #else
245 {
251 // load lib
253 //LOG (ANDROID_LOG_DEBUG, LOG_TAG, "nanoGL: Init loading driver %s\n", lib1);
256 {
262 }
263 else
265 }
266 else
271 //if ( strcmp(driver, lib2) == 0 ) {
278 }
279 //}
281 // Load API gl* for 1.5+ else egl* gl*
282 //if (CreateGlEsInterface(driver, glesLib, eglLib, NULL) == -1)
284 {
285 // release lib
290 }
292 #ifdef __ANDROID__
293 // somewhy it does not initialize correctly
294 *((void**)&glEsImpl->glGenFramebuffers) = (void*)glEsImpl->eglGetProcAddress( "glGenFramebuffersOES" );
295 *((void**)&glEsImpl->glGenRenderbuffers) = (void*)glEsImpl->eglGetProcAddress( "glGenRenderbuffersOES" );
296 *((void**)&glEsImpl->glRenderbufferStorage) = (void*)glEsImpl->eglGetProcAddress( "glRenderbufferStorageOES" );
297 *((void**)&glEsImpl->glBindFramebuffer) = (void*)glEsImpl->eglGetProcAddress( "glBindFramebufferOES" );
298 *((void**)&glEsImpl->glBindRenderbuffer) = (void*)glEsImpl->eglGetProcAddress( "glBindRenderbufferOES" );
299 *((void**)&glEsImpl->glFramebufferTexture2D) = (void*)glEsImpl->eglGetProcAddress( "glFramebufferTexture2DOES" );
300 *((void**)&glEsImpl->glDeleteRenderbuffers) = (void*)glEsImpl->eglGetProcAddress( "glDeleteRenderbuffersOES" );
301 *((void**)&glEsImpl->glDeleteFramebuffers) = (void*)glEsImpl->eglGetProcAddress( "glDeleteFramebuffersOES" );
302 *((void**)&glEsImpl->glFramebufferRenderbuffer) = (void*)glEsImpl->eglGetProcAddress( "glFramebufferRenderbufferOES" );
303 #endif
305 // Init nanoGL
308 }
309 #endif
311 {
317 }
319 // release lib
321 }