From: mittorn Date: Sun, 18 Jun 2017 20:11:15 +0000 (+0000) Subject: Rewrite nanoGL initialization X-Git-Url: http://deadsoftware.ru/gitweb?a=commitdiff_plain;h=472a91567501b466be9161d26025060306f869d2;p=nanogl.git Rewrite nanoGL initialization --- diff --git a/funcnames.h b/funcnames.h index cf26c55..c394c45 100644 --- a/funcnames.h +++ b/funcnames.h @@ -187,3 +187,14 @@ // Rikku2000: Light "glColorMaterial", + +// fbo + "glGenFramebuffersOES", + "glGenRenderbuffersOES", + "glRenderbufferStorageOES", + "glBindFramebufferOES", + "glBindRenderbufferOES", + "glFramebufferTexture2DOES", + "glDeleteRenderbuffersOES", + "glDeleteFramebuffersOES", + "glFramebufferRenderbufferOES", diff --git a/nanoWrap.cpp b/nanoWrap.cpp index 41eb4dd..3e88b0f 100644 --- a/nanoWrap.cpp +++ b/nanoWrap.cpp @@ -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 +} diff --git a/nanogl.cpp b/nanogl.cpp index b0a525f..25ab85d 100644 --- a/nanogl.cpp +++ b/nanogl.cpp @@ -69,11 +69,20 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #ifdef _WIN32 #include -#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 +#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( ) {