X-Git-Url: https://deadsoftware.ru/gitweb?p=nanogl.git;a=blobdiff_plain;f=nanogl.cpp;h=fdc2a9a8543a7d17b4d909c7fa40a09cd5d9efd0;hp=9af6d1d36a6fdc9f898f4c19809a6052b881024e;hb=HEAD;hpb=09d6668385eaa4a132f4efb14da2e4882ff3c82f diff --git a/nanogl.cpp b/nanogl.cpp index 9af6d1d..fdc2a9a 100644 --- a/nanogl.cpp +++ b/nanogl.cpp @@ -44,19 +44,19 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #else #ifndef _MSC_VER #define LOGI( ... ) \ - printf( "I: "__VA_ARGS__ ); \ + printf( "I: " __VA_ARGS__ ); \ printf( "\n" ) #define LOGD( ... ) \ if ( DEBUG_NANO ) \ { \ - printf( "D: "__VA_ARGS__ ); \ + printf( "D: " __VA_ARGS__ ); \ printf( "\n" ); \ } #define LOGE( ... ) \ - printf( "E: "__VA_ARGS__ ); \ + printf( "E: " __VA_ARGS__ ); \ printf( "\n" ) #define LOGW( ... ) \ - printf( "W: "__VA_ARGS__ ); \ + printf( "W: " __VA_ARGS__ ); \ printf( "\n" ) #else #define LOGI printf @@ -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 ); + addr = procAddress( glesLib, name ); +#ifdef NANOGL_EGL + if( !addr ) + addr = procAddress( eglLib, name ); + if( !addr && glEsImpl->eglGetProcAddress ) + addr = (void *)glEsImpl->eglGetProcAddress( name ); +#endif 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 ) ); + memset( glEsImpl, 0, 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 @@ -322,12 +426,18 @@ int nanoGL_Init( ) *( (void **)&glEsImpl->glDeleteRenderbuffers ) = (void *)glEsImpl->eglGetProcAddress( "glDeleteRenderbuffersOES" ); *( (void **)&glEsImpl->glDeleteFramebuffers ) = (void *)glEsImpl->eglGetProcAddress( "glDeleteFramebuffersOES" ); *( (void **)&glEsImpl->glFramebufferRenderbuffer ) = (void *)glEsImpl->eglGetProcAddress( "glFramebufferRenderbufferOES" ); + *( (void **)&glEsImpl->glTexGeniOES ) = (void *)glEsImpl->eglGetProcAddress( "glTexGeniOES" ); + *( (void **)&glEsImpl->glTexGenfvOES ) = (void *)glEsImpl->eglGetProcAddress( "glTexGenfv" ); + + #endif // Init nanoGL InitGLStructs( ); return 1; } +#endif + #endif void nanoGL_Destroy( ) {