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__
36 #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 LOGE( ... ) __android_log_print( ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__ )
42 #define LOGW( ... ) __android_log_print( ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__ )
43 #define LOGD( ... ) if ( DEBUG_NANO ) __android_log_print( ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__ )
45 #elif defined( TIZEN )
46 #include <dlog.h>
48 #define LOGI( ... ) dlog_print( DLOG_INFO, LOG_TAG, __VA_ARGS__ )
49 #define LOGE( ... ) dlog_print( DLOG_ERROR, LOG_TAG, __VA_ARGS__ )
50 #define LOGW( ... ) dlog_print( DLOG_WARN, LOG_TAG, __VA_ARGS__ )
51 #define LOGD( ... ) if( DEBUG_NANO ) dlog_print( DLOG_DEBUG, LOG_TAG, __VA_ARGS__ )
54 #elif !defined(_MSC_VER)
56 #define LOGI( ... ) \
59 #define LOGD( ... ) \
60 if ( DEBUG_NANO ) \
61 { \
64 }
65 #define LOGE( ... ) \
68 #define LOGW( ... ) \
71 #else
73 #define LOGI printf
74 #define LOGD printf
75 #define LOGE printf
76 #define LOGW printf
78 #endif
80 #ifdef _WIN32
81 #include <windows.h>
82 #define dlopen( x, y ) LoadLibraryA( x )
83 #define dlsym( x, y ) ( void * ) GetProcAddress( (HINSTANCE)x, y )
84 #define dlclose( x ) FreeLibrary( (HINSTANCE)x )
88 #else
89 #include <dlfcn.h>
93 #endif
95 //#define GL_ENTRY(_r, _api, ...) #_api,
98 {
100 NULL
101 };
103 //const char * driver;
110 {
111 #ifndef USE_CORE_PROFILE
113 #endif
114 }
116 #ifdef XASH_SDL
118 #endif
121 {
123 #ifdef XASH_SDL
126 #endif
129 }
132 {
133 // alloc space
138 {
140 }
142 // load GL API calls
146 // nanoGL interface pointer
150 {
155 #ifdef USE_CORE_PROFILE
156 // Hack: try ARB and EXT suffix
158 {
162 }
164 {
168 }
169 #endif
171 {
174 // try lib1
176 {
180 {
182 if ( glEsImpl->eglGetProcAddress && ( (void *)glEsImpl->eglGetProcAddress != (void *)gl_unimplemented ) )
186 }
187 else
188 {
190 }
191 }
192 else
193 {
195 if ( glEsImpl->eglGetProcAddress && ( (void *)glEsImpl->eglGetProcAddress != (void *)gl_unimplemented ) )
199 }
200 }
201 else
202 {
204 }
207 api++;
208 }
211 }
213 // Load using the dynamic loader
215 {
219 }
221 /**
222 * Init
223 */
225 {
231 // load lib
233 //LOG (ANDROID_LOG_DEBUG, LOG_TAG, "nanoGL: Init loading driver %s\n", lib1);
236 {
240 {
243 }
244 else
246 }
247 else
252 //if ( strcmp(driver, lib2) == 0 ) {
258 {
260 }
261 //}
263 // Load API gl* for 1.5+ else egl* gl*
265 {
266 // release lib
271 }
273 #ifdef __ANDROID__
274 // somewhy it does not initialize correctly
275 *( (void **)&glEsImpl->glGenFramebuffers ) = (void *)glEsImpl->eglGetProcAddress( "glGenFramebuffersOES" );
276 *( (void **)&glEsImpl->glGenRenderbuffers ) = (void *)glEsImpl->eglGetProcAddress( "glGenRenderbuffersOES" );
277 *( (void **)&glEsImpl->glRenderbufferStorage ) = (void *)glEsImpl->eglGetProcAddress( "glRenderbufferStorageOES" );
278 *( (void **)&glEsImpl->glBindFramebuffer ) = (void *)glEsImpl->eglGetProcAddress( "glBindFramebufferOES" );
279 *( (void **)&glEsImpl->glBindRenderbuffer ) = (void *)glEsImpl->eglGetProcAddress( "glBindRenderbufferOES" );
280 *( (void **)&glEsImpl->glFramebufferTexture2D ) = (void *)glEsImpl->eglGetProcAddress( "glFramebufferTexture2DOES" );
281 *( (void **)&glEsImpl->glDeleteRenderbuffers ) = (void *)glEsImpl->eglGetProcAddress( "glDeleteRenderbuffersOES" );
282 *( (void **)&glEsImpl->glDeleteFramebuffers ) = (void *)glEsImpl->eglGetProcAddress( "glDeleteFramebuffersOES" );
283 *( (void **)&glEsImpl->glFramebufferRenderbuffer ) = (void *)glEsImpl->eglGetProcAddress( "glFramebufferRenderbufferOES" );
284 #endif
286 // Init nanoGL
289 }
292 {
296 {
299 }
301 // release lib
303 }