DEADSOFTWARE

Rewrite nanoGL initialization
authormittorn <mittorn@sibmail.com>
Sun, 18 Jun 2017 20:11:15 +0000 (20:11 +0000)
committermittorn <mittorn@sibmail.com>
Sun, 18 Jun 2017 20:11:15 +0000 (20:11 +0000)
funcnames.h
nanoWrap.cpp
nanogl.cpp

index cf26c5560729efee533139f1b74394ed3febb51c..c394c45600edba48a660ef0a4e98414818946fd6 100644 (file)
 \r
 // Rikku2000: Light\r
        "glColorMaterial",\r
+\r
+// fbo\r
+       "glGenFramebuffersOES",\r
+       "glGenRenderbuffersOES",\r
+       "glRenderbufferStorageOES",\r
+       "glBindFramebufferOES",\r
+       "glBindRenderbufferOES",\r
+       "glFramebufferTexture2DOES",\r
+       "glDeleteRenderbuffersOES",\r
+       "glDeleteFramebuffersOES",\r
+       "glFramebufferRenderbufferOES",\r
index 41eb4dda9ebacbbba3d3194bbb89ac8f3c115311..3e88b0f8150d9c6a2b16dc5388ec49c16c0e525f 100644 (file)
@@ -180,7 +180,7 @@ static struct nanotmuState tmuInitState =
 
 static struct nanotmuState *activetmuState = &tmuState0;
 
-extern "C++" GlESInterface *glEsImpl;
+extern GlESInterface *glEsImpl;
 
 static GLenum wrapperPrimitiveMode = GL_QUADS;
 GLboolean useTexCoordArray         = GL_FALSE;
@@ -2527,4 +2527,4 @@ void glBufferDataARB( GLuint target, GLuint size, void *buffer, GLuint type )
 void glBufferSubDataARB( GLuint target, GLsizei offset, GLsizei size, void *buffer )
 {
        glEsImpl->glBufferSubData( target, offset, size, buffer );
-}
\ No newline at end of file
+}
index b0a525f5819d84f4526bf12afc0207024ea7809b..25ab85dbd57311a8ea460a57e8c317ccd171918e 100644 (file)
@@ -69,11 +69,20 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
 #ifdef _WIN32
 #include <windows.h>
-#define dlopen( x, y ) LoadLibraryA( x )
-#define dlsym( x, y ) ( void * ) GetProcAddress( (HINSTANCE)x, y )
-#define dlclose( x ) FreeLibrary( (HINSTANCE)x )
+#define loadDriver( x ) LoadLibraryA( x )
+#define procAddress( x, y ) (( void * ) GetProcAddress( (HINSTANCE)x, y ))
+#define freeDriver( x ) FreeLibrary( (HINSTANCE)x )
+#define GL_LIB "opengl32.dll"
+#define GLES_LIB "GLESv1_CM.dll"
+#define EGL_LIB "EGL.dll"
 #else
 #include <dlfcn.h>
+#define loadDriver( x ) dlopen( x, RTLD_NOW | RTLD_LOCAL )
+#define procAddress( x, y ) dlsym( x, y )
+#define freeDriver( x ) dlclose() x )
+#define GL_LIB "libGL.so.1"
+#define GLES_LIB "libGLESv1_CM.so"
+#define EGL_LIB "libEGL.so"
 #endif
 
 //#define GL_ENTRY(_r, _api, ...) #_api,
@@ -89,29 +98,124 @@ static void *glesLib = NULL;
 GlESInterface *glEsImpl = NULL;
 
 extern void InitGLStructs( );
-
+#ifdef WIN32
 void APIENTRY gl_unimplemented( GLenum none )
 {
 #ifndef USE_CORE_PROFILE
        LOGE( "Called unimplemented OpenGL ES API\n" );
 #endif
 }
-
+#else // make glGetString not crash
+const char * APIENTRY gl_unimplemented( GLenum none )
+{
+#ifndef USE_CORE_PROFILE
+       LOGE( "Called unimplemented OpenGL ES API\n" );
+#endif
+       return "";
+}
+#endif
 #ifdef XASH_SDL
+#define NANOGL_SDL
+#endif
+#ifdef __ANDROID__
+#define NANOGL_EGL
+#endif
+#ifdef NANOGL_SDL
 #include "SDL.h"
 #endif
 
+#ifdef NANOGL_EGL
+void *eglLib;
+#endif
+
 void *nanoGL_GetProcAddress( const char *name )
 {
        void *addr = NULL;
-#ifdef XASH_SDL
+#ifdef NANOGL_SDL
        addr = SDL_GL_GetProcAddress( name );
        if ( !addr )
 #endif
-               addr = dlsym( glesLib, name );
+#ifdef NANOGL_EGL
+       if( glEsImpl->eglGetProcAddress )
+               addr = (void *)glEsImpl->eglGetProcAddress( name );
+       if( !addr )
+               addr = procAddress( eglLib, name );
+       if( !addr )
+#endif
+               addr = procAddress( glesLib, name );
        return addr;
 }
 
+#if 1
+int nanoGL_Init( void)
+{
+       // load GL API calls
+       char const *const *api;
+       api = gl_names;
+       int count = 0;
+
+       // alloc space
+       if ( !glEsImpl )
+               glEsImpl = (GlESInterface *)malloc( sizeof( GlESInterface ) );
+
+#ifdef NANOGL_EGL
+       eglLib = loadDriver( EGL_LIB );
+#endif
+#ifdef USE_CORE_PROFILE
+       glesLib = loadDriver( GL_LIB );
+#else
+       glesLib = loadDriver( GLES_LIB );
+#endif
+
+       // nanoGL interface pointer
+       void **ptr = (void **)( glEsImpl );
+
+       while ( *api )
+       {
+               void *f;
+
+               f = nanoGL_GetProcAddress( *api);
+
+       #ifdef USE_CORE_PROFILE
+               // Hack: try ARB and EXT suffix
+               if ( f == NULL )
+               {
+                       char namearb[256];
+                       snprintf( namearb, 256, "%sARB", *api );
+                       f = nanoGL_GetProcAddress( namearb );
+               }
+               if ( f == NULL )
+               {
+                       char namearb[256];
+                       snprintf( namearb, 256, "%sEXT", *api );
+                       f = nanoGL_GetProcAddress( namearb );
+               }
+       #endif
+               if ( f == NULL )
+               {
+                       LOGW( "<%s> not found.", *api);
+                       f = (void*)gl_unimplemented;
+               }
+               else
+               {
+                       LOGD( "<%s> @ 0x%p\n", *api, f );
+                       count++;
+               }
+
+               *ptr++ = f;
+               api++;
+       }
+
+       InitGLStructs();
+
+       // it has loaded something, maybe it will work
+       if( count > 10 )
+               return 1;
+       else
+               return 0;
+}
+#else
+
 static int CreateGlEsInterface( const char *name, void *lib, void *lib1, void *default_func )
 {
        // alloc space
@@ -332,6 +436,8 @@ int nanoGL_Init( )
        InitGLStructs( );
        return 1;
 }
+#endif
+
 #endif
 void nanoGL_Destroy( )
 {