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.
21 #define LOG_TAG "nanoGL"
27 //#include <cutils/log.h>
30 #include "glesinterface.h"
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__)
46 #define LOGI(...) printf("I: "__VA_ARGS__)
47 #define LOGD(...) if(DEBUG_NANO) printf("D: "__VA_ARGS__)
48 #define LOGE(...) printf("E: "__VA_ARGS__)
49 #define LOGW(...) printf("W: "__VA_ARGS__)
54 #define GL_ENTRY(_r, _api, ...) #_api,
56 static char const * const gl_names
[] = {
57 #include "gl_entries.in"
61 //const char * driver;
63 static void* glesLib
= NULL
;
65 GlESInterface
* glEsImpl
= NULL
;
67 extern void InitGLStructs();
69 static void gl_unimplemented() {
70 LOGE ("Called unimplemented OpenGL ES API\n");
74 static int CreateGlEsInterface( const char * name
, void * lib
, void * lib1
, void * default_func
)
78 glEsImpl
= (GlESInterface
*) malloc(sizeof(GlESInterface
));
85 char const * const * api
;
88 // nanoGL interface pointer
89 void ** ptr
= (void **)(glEsImpl
);
95 f
= dlsym(lib
, *api
); // ltry ibGLESxx_CM.so
98 LOGW( "<%s> not found in %s. Trying libEGL.so.", *api
, name
); //driver);
102 f
= dlsym(lib1
, *api
); // libEGL.so
105 LOGE ( "<%s> not found in libEGL.so", *api
);
106 f
= default_func
; //(void*)gl_unimplemented;
109 LOGD ("<%s> @ 0x%p\n", *api
, f
);
116 LOGD ("<%s> @ 0x%p\n", *api
, f
);
126 // Load using the dynamic loader
127 static int loadDriver(const char * name
) {
128 glesLib
= dlopen(name
, RTLD_NOW
| RTLD_LOCAL
);
129 int rc
= (glesLib
) ? 1 : 0;
138 const char * lib1
= "libGLESv1_CM.so"; // Has both gl* & egl* funcs SDK < 1.5
139 const char * lib2
= "libGLESv2.so"; // Only gl* funcs SDK >= 1.5
140 const char * lib3
= "libEGL.so"; // Only egl* funcs SDK >= 1.5
144 LOGI("nanoGL: Init loading driver %s\n", lib1
);
145 //LOG (ANDROID_LOG_DEBUG, LOG_TAG, "nanoGL: Init loading driver %s\n", lib1);
147 if ( ! loadDriver(lib1
) )
149 LOGE("Failed to load driver %s. Trying %s\n", lib1
, lib2
);
151 if ( ! loadDriver(lib2
) ) {
152 LOGE ("Failed to load %s.\n", lib2
);
163 //if ( strcmp(driver, lib2) == 0 ) {
164 LOGD ("**** Will Load EGL subs from %s ****", lib3
);
166 eglLib
= dlopen(lib3
, RTLD_NOW
| RTLD_LOCAL
);
169 LOGE ( "Failed to load %s", lib3
);
173 // Load API gl* for 1.5+ else egl* gl*
174 //if (CreateGlEsInterface(driver, glesLib, eglLib, NULL) == -1)
175 if ( !CreateGlEsInterface(driver
, glesLib
, eglLib
, (void *) gl_unimplemented
) == -1)
178 LOGE ( "CreateGlEsInterface failed.");
189 void nanoGL_Destroy()
191 LOGD ("nanoGL_Destroy");