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>
26 //#include <cutils/log.h>
32 #define DEBUG_NANO 0
34 #ifdef __ANDROID__
35 #include <android/log.h>
36 #define LOG __android_log_print
38 #define LOGI( ... ) __android_log_print( ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__ )
39 #define LOGD( ... ) \
40 if ( DEBUG_NANO ) \
41 __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
46 #define LOGI( ... ) \
49 #define LOGD( ... ) \
50 if ( DEBUG_NANO ) \
51 { \
54 }
55 #define LOGE( ... ) \
58 #define LOGW( ... ) \
61 #else
62 #define LOGI printf
63 #define LOGD printf
64 #define LOGE printf
65 #define LOGW printf
67 #endif
68 #endif
70 #ifdef _WIN32
71 #include <windows.h>
72 #define loadDriver( x ) LoadLibraryA( x )
73 #define procAddress( x, y ) (( void * ) GetProcAddress( (HINSTANCE)x, y ))
74 #define freeDriver( x ) FreeLibrary( (HINSTANCE)x )
78 #else
79 #include <dlfcn.h>
80 #define loadDriver( x ) dlopen( x, RTLD_NOW | RTLD_LOCAL )
81 #define procAddress( x, y ) dlsym( x, y )
82 #define freeDriver( x ) dlclose() x )
86 #endif
88 //#define GL_ENTRY(_r, _api, ...) #_api,
92 NULL};
94 //const char * driver;
101 #ifdef WIN32
103 {
104 #ifndef USE_CORE_PROFILE
106 #endif
107 }
110 {
111 #ifndef USE_CORE_PROFILE
113 #endif
115 }
116 #endif
117 #ifdef XASH_SDL
118 #define NANOGL_SDL
119 #endif
120 #ifdef __ANDROID__
121 #define NANOGL_EGL
122 #endif
123 #ifdef NANOGL_SDL
125 #endif
127 #ifdef NANOGL_EGL
129 #endif
132 {
134 #ifdef NANOGL_SDL
137 #endif
139 #ifdef NANOGL_EGL
144 #endif
146 }
148 #if 1
150 {
151 // load GL API calls
156 // alloc space
161 #ifdef NANOGL_EGL
163 #endif
164 #ifdef USE_CORE_PROFILE
166 #else
168 #endif
170 // nanoGL interface pointer
174 {
179 #ifdef USE_CORE_PROFILE
180 // Hack: try ARB and EXT suffix
182 {
186 }
188 {
192 }
193 #endif
195 {
198 }
199 else
200 {
202 count++;
203 }
206 api++;
207 }
211 // it has loaded something, maybe it will work
214 else
216 }
217 #else
220 {
221 // alloc space
226 {
228 }
230 // load GL API calls
234 // nanoGL interface pointer
238 {
243 #ifdef USE_CORE_PROFILE
244 // Hack: try ARB and EXT suffix
246 {
250 }
252 {
256 }
257 #endif
259 {
262 // try lib1
264 {
268 {
270 if ( glEsImpl->eglGetProcAddress && ( (void *)glEsImpl->eglGetProcAddress != (void *)gl_unimplemented ) )
274 }
275 else
276 {
278 }
279 }
280 else
281 {
283 if ( glEsImpl->eglGetProcAddress && ( (void *)glEsImpl->eglGetProcAddress != (void *)gl_unimplemented ) )
287 }
288 }
289 else
290 {
292 }
295 api++;
296 }
299 }
301 // Load using the dynamic loader
303 {
307 }
309 /**
310 * Init
311 */
312 #ifdef _WIN32
314 {
320 // load lib
322 //LOG (ANDROID_LOG_DEBUG, LOG_TAG, "nanoGL: Init loading driver %s\n", lib1);
325 {
329 {
332 }
333 else
335 }
336 else
341 //if ( strcmp(driver, lib2) == 0 ) {
347 {
349 }
350 //}
352 // Load API gl* for 1.5+ else egl* gl*
353 //if (CreateGlEsInterface(driver, glesLib, eglLib, NULL) == -1)
355 {
356 // release lib
361 }
363 // Init nanoGL
366 }
367 #else
369 {
375 // load lib
377 //LOG (ANDROID_LOG_DEBUG, LOG_TAG, "nanoGL: Init loading driver %s\n", lib1);
380 {
384 {
387 }
388 else
390 }
391 else
396 //if ( strcmp(driver, lib2) == 0 ) {
402 {
404 }
405 //}
407 // Load API gl* for 1.5+ else egl* gl*
408 //if (CreateGlEsInterface(driver, glesLib, eglLib, NULL) == -1)
410 {
411 // release lib
416 }
418 #ifdef __ANDROID__
419 // somewhy it does not initialize correctly
420 *( (void **)&glEsImpl->glGenFramebuffers ) = (void *)glEsImpl->eglGetProcAddress( "glGenFramebuffersOES" );
421 *( (void **)&glEsImpl->glGenRenderbuffers ) = (void *)glEsImpl->eglGetProcAddress( "glGenRenderbuffersOES" );
422 *( (void **)&glEsImpl->glRenderbufferStorage ) = (void *)glEsImpl->eglGetProcAddress( "glRenderbufferStorageOES" );
423 *( (void **)&glEsImpl->glBindFramebuffer ) = (void *)glEsImpl->eglGetProcAddress( "glBindFramebufferOES" );
424 *( (void **)&glEsImpl->glBindRenderbuffer ) = (void *)glEsImpl->eglGetProcAddress( "glBindRenderbufferOES" );
425 *( (void **)&glEsImpl->glFramebufferTexture2D ) = (void *)glEsImpl->eglGetProcAddress( "glFramebufferTexture2DOES" );
426 *( (void **)&glEsImpl->glDeleteRenderbuffers ) = (void *)glEsImpl->eglGetProcAddress( "glDeleteRenderbuffersOES" );
427 *( (void **)&glEsImpl->glDeleteFramebuffers ) = (void *)glEsImpl->eglGetProcAddress( "glDeleteFramebuffersOES" );
428 *( (void **)&glEsImpl->glFramebufferRenderbuffer ) = (void *)glEsImpl->eglGetProcAddress( "glFramebufferRenderbufferOES" );
433 #endif
435 // Init nanoGL
438 }
439 #endif
441 #endif
443 {
447 {
450 }
452 // release lib
454 }