DEADSOFTWARE

Fix typo in nanoGL_GetProcAddress, return 1 in nanoGL_Init() if wrapper already initi...
[nanogl.git] / nanogl.cpp
index 823851fcae9117a6fcd0c8b94b2c605400565a10..64c5f4da9eb5f8b90faec6a93af1f35590197867 100644 (file)
@@ -25,19 +25,31 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 #include <dlfcn.h>
 
 //#include <cutils/log.h>
-#include <android/log.h>
 
 #include "nanogl.h"
 #include "glesinterface.h"
 #include "gl.h"
 
-#define LOG __android_log_print
+
 #define DEBUG_NANO 0
 
+#ifdef __ANDROID__
+#include <android/log.h>
+#define LOG __android_log_print
+
 #define LOGI(...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)
 #define LOGD(...) if (DEBUG_NANO) __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__)
 #define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG,__VA_ARGS__)
 #define LOGW(...) __android_log_print(ANDROID_LOG_WARN, LOG_TAG,__VA_ARGS__)
+#else
+
+#define LOGI(...) printf("I: "__VA_ARGS__)
+#define LOGD(...) if(DEBUG_NANO) printf("D: "__VA_ARGS__) 
+#define LOGE(...) printf("E: "__VA_ARGS__)
+#define LOGW(...) printf("W: "__VA_ARGS__)
+
+#endif
+
 
 #define GL_ENTRY(_r, _api, ...) #_api,
 
@@ -52,12 +64,32 @@ static void* glesLib = NULL;
 
 GlESInterface* glEsImpl = NULL;
 
+int initialized = 0;
+
 extern void InitGLStructs();
 
 static void gl_unimplemented() { 
        LOGE ("Called unimplemented OpenGL ES API\n"); 
 }
 
+void *nanoGL_GetProcAddress(const char *procname)
+{
+#if defined(__MULTITEXTURE_SUPPORT__)
+       if (!strcmp(procname, "glMultiTexCoord2fARB"))
+       {
+               return (void*)&glMultiTexCoord2fARB;
+       }
+       else if (!strcmp(procname, "glActiveTextureARB"))
+       {
+               return (void*)&glActiveTexture;
+       }
+       else if (!strcmp(procname, "glClientActiveTextureARB"))
+       {
+               return (void*)&glClientActiveTexture;
+       }
+#endif
+       return dlsym(glesLib, procname);
+}
 
 static int CreateGlEsInterface( const char * name, void * lib, void * lib1, void * default_func )
 {
@@ -80,7 +112,7 @@ static int CreateGlEsInterface( const char * name, void * lib, void * lib1, void
        {
                void * f;
                
-               f = dlsym(lib, *api); // ltry ibGLESxx_CM.so
+               f = dlsym(lib, *api); // try libGLESxx_CM.so
 
                if (f == NULL) {
                        LOGW( "<%s> not found in %s. Trying libEGL.so.", *api, name); //driver);
@@ -123,6 +155,8 @@ static int loadDriver(const char * name) {
  */
 int nanoGL_Init()
 {
+       if( initialized ) return 1;
+
        const char * lib1 = "libGLESv1_CM.so";  // Has both gl* & egl* funcs SDK < 1.5
        const char * lib2 = "libGLESv2.so";     // Only gl* funcs SDK >= 1.5
        const char * lib3 = "libEGL.so";                // Only egl* funcs SDK >= 1.5
@@ -171,6 +205,7 @@ int nanoGL_Init()
 
        // Init nanoGL
        InitGLStructs();
+       initialized = 1;
        return 1;
 }