- Timestamp:
- 08/14/14 21:21:39 (11 years ago)
- Location:
- trunk/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/gl/gl_context.cc
r303 r311 612 612 } 613 613 614 load_gl_library( NV_GL_PATH, true ); 615 load_wgl_library( NV_GL_PATH, true ); 614 616 m_handle = (void*)handle; 615 617 #else -
trunk/src/lib/gl.cc
r245 r311 6 6 7 7 #include "nv/common.hh" 8 #include "nv/range.hh" 8 9 #include "nv/lib/gl.hh" 9 10 … … 33 34 #include <nv/lib/detail/wgl_functions.inc> 34 35 #endif 36 #include <nv/lib/detail/gl_ext/gl_ext_all_functions.inc> 35 37 #undef NV_GL_FUN_REN 36 38 #undef NV_GL_FUN_EXT … … 38 40 39 41 static nv::library gl_library; 42 static nv::gl_extensions gl_loaded_extensions = nv::gl_extensions(0); 43 extern "C" void* (NV_GL_APIENTRY *gl_ext_loader) ( const char* ) = nullptr; 40 44 static bool gl_library_loaded = false; 41 45 static bool wgl_library_loaded = false; 42 46 43 bool nv::load_gl_library( const char* path ) 44 { 45 if ( gl_library_loaded ) return true; 47 static const char *gl_extension_names[] = { 48 "UNKNOWN", 49 #define NV_GL_EXTENSION( count, id, name ) "GL_EXT_"#id, 50 #include <nv/lib/detail/gl_ext/gl_ext_info.inc> 51 #undef NV_GL_EXTENSION 52 }; 53 54 static const char *gl_extension_ids[] = { 55 "UNKNOWN", 56 #define NV_GL_EXTENSION( count, id, name ) #id, 57 #include <nv/lib/detail/gl_ext/gl_ext_info.inc> 58 #undef NV_GL_EXTENSION 59 }; 60 61 62 static void* load_gl_ext_symbol_impl( const char* name, nv::log_level fail_level = nv::LOG_DEBUG ) 63 { 64 void* result = gl_ext_loader( name ); 65 NV_LOG( ( result ? nv::LOG_DEBUG : fail_level ), "load_gl_ext_symbol : " << name << ( result ? " succeded." : "failed." ) ); 66 return result; 67 } 68 69 static void* load_gl_ext_symbol( const char* name, bool iterate, const char* ext ) 70 { 71 void * result = nullptr; 72 result = load_gl_ext_symbol_impl( ext ? ( std::string(name) + ext ).c_str() : name ); 73 if ( result ) return result; 74 if ( iterate ) 75 { 76 result = gl_ext_loader( (std::string(name) + "ARB").c_str() ); 77 if ( result ) return result; 78 result = gl_ext_loader( (std::string(name) + "EXT").c_str() ); 79 if ( result ) return result; 80 } 81 return result; 82 } 83 84 bool nv::load_gl_library( const char* path, bool force_reload ) 85 { 86 if ( gl_library_loaded && !force_reload ) return true; 46 87 #if defined( NV_SDL_GL ) 47 88 # define NV_GL_LOAD( symbol ) *(void **) (&symbol) = SDL_GL_GetProcAddress(#symbol); 48 89 # define NV_GL_LOAD_EXT( symbol ) *(void **) (&symbol) = SDL_GL_GetProcAddress(#symbol); 90 *(void **) (&gl_ext_loader) = SDL_GL_GetProcAddress; 49 91 #else 50 92 if ( !gl_library.is_open() ) gl_library.open( path ); 51 93 52 void * (NV_GL_APIENTRY *ext_loader) (const char* proc) = nullptr;53 94 # if NV_PLATFORM == NV_WINDOWS 54 95 # define NV_GL_LOAD( symbol ) *(void **) (&symbol) = gl_library.get(#symbol); 55 *(void **) (& ext_loader) = gl_library.get("wglGetProcAddress");56 # define NV_GL_LOAD_EXT( symbol ) *(void **) (&symbol) = ext_loader(#symbol);96 *(void **) (&gl_ext_loader) = gl_library.get("wglGetProcAddress"); 97 # define NV_GL_LOAD_EXT( symbol ) *(void **) (&symbol) = gl_ext_loader(#symbol); 57 98 # elif (NV_PLATFORM == NV_LINUX || NV_PLATFORM == NV_APPLE) 58 99 # define NV_GL_LOAD( symbol ) *(void **) (&symbol) = gl_library.get(#symbol); 59 *(void **) (& ext_loader) = gl_library.get("glXGetProcAddress");60 # define NV_GL_LOAD_EXT( symbol ) *(void **) (&symbol) = ext_loader(#symbol);100 *(void **) (&gl_ext_loader) = gl_library.get("glXGetProcAddress"); 101 # define NV_GL_LOAD_EXT( symbol ) *(void **) (&symbol) = gl_ext_loader(#symbol); 61 102 # else 62 103 # define NV_GL_LOAD( symbol ) *(void **) (&symbol) = gl_library.get(#symbol); … … 77 118 } 78 119 79 bool nv::load_wgl_library( const char* path /*= NV_GL_PATH */ )80 { 81 if ( wgl_library_loaded ) return true;120 bool nv::load_wgl_library( const char* path /*= NV_GL_PATH */, bool force_reload ) 121 { 122 if ( wgl_library_loaded && !force_reload ) return true; 82 123 #if NV_PLATFORM == NV_WINDOWS 83 124 #if defined( NV_SDL_GL ) … … 85 126 # define NV_GL_LOAD_EXT( symbol ) *(void **) (&symbol) = SDL_GL_GetProcAddress(#symbol); 86 127 # define NV_GL_LOAD_REN( fname, rname ) *(void **) (&rname) = SDL_GL_GetProcAddress(#fname); 128 (void **) (&gl_ext_loader) = SDL_GL_GetProcAddress; 87 129 #else // 88 130 if ( !gl_library.is_open() ) gl_library.open( path ); 89 131 90 void * (NV_GL_APIENTRY *ext_loader) (const char* proc) = nullptr; 91 *(void **) (&ext_loader) = gl_library.get("wglGetProcAddress"); 132 *(void **) (&gl_ext_loader) = gl_library.get("wglGetProcAddress"); 92 133 #define NV_GL_LOAD( symbol ) *(void **) (&symbol) = gl_library.get(#symbol); 93 #define NV_GL_LOAD_EXT( symbol ) *(void **) (&symbol) = ext_loader(#symbol);134 #define NV_GL_LOAD_EXT( symbol ) *(void **) (&symbol) = gl_ext_loader(#symbol); 94 135 #define NV_GL_LOAD_REN( fname, rname ) *(void **) (&rname) = gl_library.get(#fname); 95 136 #endif … … 186 227 } 187 228 229 const char* nv::get_gl_extension_name( gl_extensions extension ) 230 { 231 uint32 value = uint32( extension ); 232 uint32 index = 0; 233 while ( value >>= 1 ) index++; 234 return NV_SAFE_ARRAY(gl_extension_names, index+1, gl_extension_names[0] ); 235 } 236 237 238 bool nv::load_gl_extension( gl_extensions extension ) 239 { 240 const char* name = get_gl_extension_name( extension ); 241 // TODO: first check for support using gl mechanisms 242 // see SDL 2.0 SDL_video.c 243 if ( !gl_library.is_open() ) 244 { 245 NV_LOG( nv::LOG_ERROR, "load_gl_extension used, while gl_library was closed!" ); 246 return false; 247 } 248 249 if ( gl_ext_loader == nullptr ) 250 { 251 NV_LOG( nv::LOG_ERROR, "load_gl_extension used, while gl_ext_loader was undefined!" ); 252 return false; 253 } 254 NV_LOG( nv::LOG_DEBUG, "load_gl_extension - loading extension - \"" << name << "\"..." ); 255 256 uint32 count = 0; 257 uint32 fail_count = 0; 258 259 # define NV_GL_FUN_EXT( rtype, symbol, fparams ) \ 260 *(void **) (&symbol) = load_gl_ext_symbol(#symbol, true, nullptr); \ 261 count++; if ( !symbol ) fail_count++; 262 263 switch ( extension ) 264 { 265 case GL_EXT_FRAMEBUFFER_BLIT : { 266 #include <nv/lib/detail/gl_ext/gl_ext_framebuffer_blit_functions.inc> 267 } break; 268 case GL_EXT_FRAMEBUFFER_OBJECT : { 269 #include <nv/lib/detail/gl_ext/gl_ext_framebuffer_object_functions.inc> 270 } break; 271 default : { 272 NV_LOG( nv::LOG_ERROR, "load_gl_extension - unknown extension \"" << name << "\"!" ); 273 return nullptr; 274 } 275 } 276 # undef NV_GL_FUN_EXT 277 278 if ( fail_count == 0 ) 279 { 280 NV_LOG( nv::LOG_NOTICE, "load_gl_extension - extension \"" << name << "\" loaded (" << count << " symbols)" ); 281 return false; 282 } 283 NV_LOG( nv::LOG_NOTICE, "load_gl_extension - failed to load extension \"" << name << "\" (" << count << "/" << fail_count << " symbols loaded)" ); 284 return true; 285 } 286 287 nv::gl_extensions nv::load_gl_extensions( uint32 extensions ) 288 { 289 gl_extensions result = gl_extensions(0); 290 for ( auto ext : nv::bits( gl_extensions(extensions) ) ) 291 { 292 if ( load_gl_extension(ext) ) result = gl_extensions( result | ext ); 293 } 294 return result; 295 } 296 297 bool nv::is_gl_extension_loaded( gl_extensions extensions ) 298 { 299 return ( gl_loaded_extensions & extensions ) != 0; 300 } 301 302 bool nv::are_gl_extensions_loaded( uint32 extensions ) 303 { 304 for ( auto ext : nv::bits( gl_extensions(extensions) ) ) 305 { 306 if ( !is_gl_extension_loaded(ext) ) return false; 307 } 308 return true; 309 } 310
Note: See TracChangeset
for help on using the changeset viewer.