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 dlopen( x, y ) LoadLibraryA( x )
73 #define dlsym( x, y ) ( void * ) GetProcAddress( (HINSTANCE)x, y )
74 #define dlclose( x ) FreeLibrary( (HINSTANCE)x )
75 #else
76 #include <dlfcn.h>
77 #endif
79 //#define GL_ENTRY(_r, _api, ...) #_api,
83 NULL};
85 //const char * driver;
95 {
96 #ifndef USE_CORE_PROFILE
98 #endif
99 }
101 #ifdef XASH_SDL
103 #endif
106 {
108 #ifdef XASH_SDL
111 #endif
114 }
117 {
118 // alloc space
123 {
125 }
127 // load GL API calls
131 // nanoGL interface pointer
135 {
140 #ifdef USE_CORE_PROFILE
141 // Hack: try ARB and EXT suffix
143 {
147 }
149 {
153 }
154 #endif
155 /*if ( f == NULL )
156 {
157 LOGW( "<%s> not found in %s. Trying libEGL.so.", *api, name ); //driver);
159 // try lib1
160 if ( lib1 )
161 {
162 f = dlsym( lib1, *api ); // libEGL.so
164 if ( f == NULL )
165 {
166 LOGE( "<%s> not found in libEGL.so", *api );
167 if ( glEsImpl->eglGetProcAddress && ( (void *)glEsImpl->eglGetProcAddress != (void *)gl_unimplemented ) )
168 f = (void *)glEsImpl->eglGetProcAddress( *api );
169 if ( f == NULL )
170 f = (void *)default_func; //(void*)gl_unimplemented;
171 }
172 else
173 {
174 LOGD( "<%s> @ 0x%p\n", *api, f );
175 }
176 }
177 else
178 {
179 LOGE( "libEGL.so not loaded!" );
180 if ( glEsImpl->eglGetProcAddress && ( (void *)glEsImpl->eglGetProcAddress != (void *)gl_unimplemented ) )
181 f = (void *)glEsImpl->eglGetProcAddress( *api );
182 if ( !f )
183 f = (void *)default_func;
184 }
185 }
186 else*/
187 {
189 }
192 api++;
193 }
196 }
198 // Load using the dynamic loader
200 {
204 }
206 /**
207 * Init
208 */
209 #ifdef _WIN32
211 {
217 // load lib
219 //LOG (ANDROID_LOG_DEBUG, LOG_TAG, "nanoGL: Init loading driver %s\n", lib1);
222 {
226 {
229 }
230 else
232 }
233 else
238 //if ( strcmp(driver, lib2) == 0 ) {
244 {
246 }
247 //}
249 // Load API gl* for 1.5+ else egl* gl*
250 //if (CreateGlEsInterface(driver, glesLib, eglLib, NULL) == -1)
252 {
253 // release lib
258 }
260 // Init nanoGL
263 }
264 #else
266 {
272 // load lib
274 //LOG (ANDROID_LOG_DEBUG, LOG_TAG, "nanoGL: Init loading driver %s\n", lib1);
276 /*if ( !loadDriver( lib1 ) )
277 {
278 LOGE( "Failed to load driver %s. Trying %s\n", lib1, lib2 );
280 if ( !loadDriver( lib2 ) )
281 {
282 LOGE( "Failed to load %s.\n", lib2 );
283 return 0;
284 }
285 else
286 driver = lib2;
287 }
288 else
289 driver = lib1;*/
293 //if ( strcmp(driver, lib2) == 0 ) {
299 {
301 }
302 //}
304 // Load API gl* for 1.5+ else egl* gl*
305 //if (CreateGlEsInterface(driver, glesLib, eglLib, NULL) == -1)
307 {
308 // release lib
313 }
315 #ifdef __ANDROID__
316 // somewhy it does not initialize correctly
317 *( (void **)&glEsImpl->glGenFramebuffers ) = (void *)glEsImpl->eglGetProcAddress( "glGenFramebuffersOES" );
318 *( (void **)&glEsImpl->glGenRenderbuffers ) = (void *)glEsImpl->eglGetProcAddress( "glGenRenderbuffersOES" );
319 *( (void **)&glEsImpl->glRenderbufferStorage ) = (void *)glEsImpl->eglGetProcAddress( "glRenderbufferStorageOES" );
320 *( (void **)&glEsImpl->glBindFramebuffer ) = (void *)glEsImpl->eglGetProcAddress( "glBindFramebufferOES" );
321 *( (void **)&glEsImpl->glBindRenderbuffer ) = (void *)glEsImpl->eglGetProcAddress( "glBindRenderbufferOES" );
322 *( (void **)&glEsImpl->glFramebufferTexture2D ) = (void *)glEsImpl->eglGetProcAddress( "glFramebufferTexture2DOES" );
323 *( (void **)&glEsImpl->glDeleteRenderbuffers ) = (void *)glEsImpl->eglGetProcAddress( "glDeleteRenderbuffersOES" );
324 *( (void **)&glEsImpl->glDeleteFramebuffers ) = (void *)glEsImpl->eglGetProcAddress( "glDeleteFramebuffersOES" );
325 *( (void **)&glEsImpl->glFramebufferRenderbuffer ) = (void *)glEsImpl->eglGetProcAddress( "glFramebufferRenderbufferOES" );
326 #endif
328 // Init nanoGL
331 }
332 #endif
334 {
338 {
341 }
343 // release lib
345 }