const GLubyte * __glGetStringi_override(GLenum name, GLuint index) { switch (name) { case GL_EXTENSIONS: { const ExtensionsDesc *desc = getExtraExtensions(); GLint numExtensions = 0; __glGetIntegerv(GL_NUM_EXTENSIONS, &numExtensions); if ((GLuint)numExtensions <= index && index < (GLuint)numExtensions + desc->numStrings) { return (const GLubyte *)desc->strings[index - (GLuint)numExtensions]; } } break; default: break; } return __glGetStringi(name, index); }
BIT_API Bool BindOpenGLExtensions( const Uint32 p_Major, const Uint32 p_Minor ) { // Get all the available extensions std::list< std::string > availableExtensions; GLint availableExtensionCount = 0; // Get the available extension count glGetIntegerv( GL_NUM_EXTENSIONS, &availableExtensionCount ); // Get the proc address for glGetStringi __glGetStringi = (PFNGLGETSTRINGIPROC)glGetProcAddress( "glGetStringi" ); // Get all the available extensions for( SizeType i = 0; i < (SizeType)availableExtensionCount; i++ ) { availableExtensions.push_back( ( char * )( __glGetStringi( GL_EXTENSIONS, i ) ) ); } // Go through some of the extensions to confirm some of them. for( std::list< std::string >::iterator it = availableExtensions.begin( ); it != availableExtensions.end( ); it++ ) { if( *it == "GL_ARB_vertex_buffer_object" ) { BIT_ARB_vertex_buffer_object = true; } else if( *it == "GL_ARB_vertex_array_object" ) { BIT_ARB_vertex_array_object = true; } else if( *it == "GL_ARB_framebuffer_object" ) { BIT_ARB_framebuffer_object = true; } // Checking for shader extensions else if( *it == "GL_ARB_shading_language_100" ) { BIT_ARB_shading_language_100 = true; } else if( *it == "GL_ARB_shader_objects" ) { BIT_ARB_shader_objects = true; } else if( *it == "GL_ARB_vertex_shader" ) { BIT_ARB_vertex_shader = true; } else if( *it == "GL_ARB_fragment_shader" ) { BIT_ARB_fragment_shader = true; } // Check for texture extensions else if( *it == "GL_EXT_texture_filter_anisotropic" ) { BIT_EXT_texture_filter_anisotropic = true; // Get the max level GLfloat levels; glGetFloatv( GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &levels ); g_AnisotropicMaxLevel = static_cast<Uint32>( levels + 0.5f ); } } // Use a boolean to check if any attempt in getting // any OpenGL function failed Bool Ret = 0; // Get the texture functions if( BIT_ARB_framebuffer_object ) { Ret |= (__glClearBufferfv = (PFNGLCLEARBUFFERFVPROC) glGetProcAddress("glClearBufferfv")) == NULL; Ret |= (__glDrawBuffers = (PFNGLDRAWBUFFERSPROC) glGetProcAddress("glDrawBuffers")) == NULL; Ret |= (__glBlitFramebuffer = (PFNGLBLITFRAMEBUFFERPROC) glGetProcAddress("glBlitFramebuffer")) == NULL; Ret |= ( __glGenerateMipmap = ( PFNGLGENERATEMIPMAPPROC ) glGetProcAddress( "glGenerateMipmap" ) ) == NULL; Ret |= ( __glBindFramebuffer = ( PFNGLBINDFRAMEBUFFERPROC ) glGetProcAddress( "glBindFramebuffer" ) ) == NULL; Ret |= ( __glBindRenderbuffer = ( PFNGLBINDRENDERBUFFERPROC ) glGetProcAddress( "glBindRenderbuffer" ) ) == NULL; Ret |= ( __glCheckFramebufferStatus = ( PFNGLCHECKFRAMEBUFFERSTATUSPROC ) glGetProcAddress( "glCheckFramebufferStatus" ) ) == NULL; Ret |= ( __glDeleteFramebuffers = ( PFNGLDELETEFRAMEBUFFERSPROC ) glGetProcAddress( "glDeleteFramebuffers" ) ) == NULL; Ret |= ( __glDeleteRenderbuffers = ( PFNGLDELETERENDERBUFFERSPROC ) glGetProcAddress( "glDeleteRenderbuffers" ) ) == NULL; Ret |= ( __glFramebufferRenderbuffer = ( PFNGLFRAMEBUFFERRENDERBUFFERPROC ) glGetProcAddress( "glFramebufferRenderbuffer" ) ) == NULL; Ret |= ( __glFramebufferTexture2D = ( PFNGLFRAMEBUFFERTEXTURE2DPROC ) glGetProcAddress( "glFramebufferTexture2D" ) ) == NULL; Ret |= ( __glGenFramebuffers = ( PFNGLGENFRAMEBUFFERSPROC ) glGetProcAddress( "glGenFramebuffers" ) ) == NULL; Ret |= ( __glGenRenderbuffers = ( PFNGLGENRENDERBUFFERSPROC ) glGetProcAddress( "glGenRenderbuffers" ) ) == NULL; Ret |= ( __glRenderbufferStorage = ( PFNGLRENDERBUFFERSTORAGEPROC ) glGetProcAddress( "glRenderbufferStorage" ) ) == NULL; Ret |= ( __glRenderbufferStorageMultisample = ( PFNGLRENDERBUFFERSTORAGEMULTISAMPLEPROC ) glGetProcAddress( "glRenderbufferStorageMultisample" ) ) == NULL; Ret |= ( __glTexImage2DMultisample = ( PFNGLTEXIMAGE2DMULTISAMPLEPROC ) glGetProcAddress( "glTexImage2DMultisample" ) ) == NULL; if( Ret ) { BIT_ARB_framebuffer_object = false; } } // Reset the return flag Ret = 0; if( p_Major > 1 || ( p_Major == 1 && p_Minor >= 3 ) ) { Ret |= ( __glActiveTexture = ( PFNGLACTIVETEXTUREPROC ) glGetProcAddress( "glActiveTexture" ) ) == NULL; if( !Ret ) { s_GeneralTextureFunctions = true; } } // Reset the return flag Ret = 0; // Get the buffer functions if( p_Major > 1 || ( p_Major == 1 && p_Minor >= 5 ) ) { Ret |= ( __glBindBuffer = ( PFNGLBINDBUFFERPROC ) glGetProcAddress( "glBindBuffer" ) ) == NULL; Ret |= ( __glBufferData = ( PFNGLBUFFERDATAPROC ) glGetProcAddress( "glBufferData" ) ) == NULL; Ret |= ( __glBufferSubData = ( PFNGLBUFFERSUBDATAPROC ) glGetProcAddress( "glBufferSubData" ) ) == NULL; Ret |= ( __glDeleteBuffers = ( PFNGLDELETEBUFFERSPROC ) glGetProcAddress( "glDeleteBuffers" ) ) == NULL; Ret |= ( __glGenBuffers = ( PFNGLGENBUFFERSPROC ) glGetProcAddress( "glGenBuffers" ) ) == NULL; if( !Ret ) { s_GeneralBuffersFunctions = true; } } // Reset the return flag Ret = 0; // Get the vertex array object functions if they are available if( BIT_ARB_vertex_array_object ) { Ret |= ( __glBindVertexArray = ( PFNGLBINDVERTEXARRAYPROC ) glGetProcAddress( "glBindVertexArray" ) ) == NULL; Ret |= ( __glDeleteVertexArrays = ( PFNGLDELETEVERTEXARRAYSPROC ) glGetProcAddress( "glDeleteVertexArrays" ) ) == NULL; Ret |= ( __glGenVertexArrays = ( PFNGLGENVERTEXARRAYSPROC ) glGetProcAddress( "glGenVertexArrays" ) ) == NULL; Ret |= ( __glIsVertexArray = ( PFNGLISVERTEXARRAYPROC ) glGetProcAddress( "glIsVertexArray" ) ) == NULL; if( Ret ) { BIT_ARB_vertex_array_object = false; } } // Reset the return flag Ret = 0; // Load the shader functions if the shader extenstions are available // and we are using the right verison of OpenGL // WARNING: comparison of unsigned expression >= 0 is always true [-Wtype-limits]| if( p_Major >= 2 ) { // Needed for the vertex objects. Ret |= ( __glEnableVertexAttribArray = ( PFNGLENABLEVERTEXATTRIBARRAYPROC ) glGetProcAddress( "glEnableVertexAttribArray" ) ) == NULL; Ret |= ( __glVertexAttribPointer = ( PFNGLVERTEXATTRIBPOINTERPROC ) glGetProcAddress( "glVertexAttribPointer" ) ) == NULL; Ret |= ( __glAttachShader = ( PFNGLATTACHSHADERPROC ) glGetProcAddress( "glAttachShader" ) ) == NULL; Ret |= ( __glCompileShader = ( PFNGLCOMPILESHADERPROC ) glGetProcAddress( "glCompileShader" ) ) == NULL; Ret |= ( __glCreateProgram = ( PFNGLCREATEPROGRAMPROC ) glGetProcAddress( "glCreateProgram" ) ) == NULL; Ret |= ( __glCreateShader = ( PFNGLCREATESHADERPROC ) glGetProcAddress( "glCreateShader" ) ) == NULL; Ret |= ( __glDeleteProgram = ( PFNGLDELETEPROGRAMPROC ) glGetProcAddress( "glDeleteProgram" ) ) == NULL; Ret |= ( __glDeleteShader = ( PFNGLDELETESHADERPROC ) glGetProcAddress( "glDeleteShader" ) ) == NULL; Ret |= ( __glGetProgramInfoLog = ( PFNGLGETPROGRAMINFOLOGPROC ) glGetProcAddress( "glGetProgramInfoLog" ) ) == NULL; Ret |= ( __glGetProgramiv = ( PFNGLGETPROGRAMIVPROC ) glGetProcAddress( "glGetProgramiv" ) ) == NULL; Ret |= ( __glGetShaderInfoLog = ( PFNGLGETSHADERINFOLOGPROC ) glGetProcAddress( "glGetShaderInfoLog" ) ) == NULL; Ret |= ( __glGetShaderiv = ( PFNGLGETSHADERIVPROC ) glGetProcAddress( "glGetShaderiv" ) ) == NULL; Ret |= ( __glGetUniformLocation = ( PFNGLGETUNIFORMLOCATIONPROC ) glGetProcAddress( "glGetUniformLocation" ) ) == NULL; Ret |= ( __glLinkProgram = ( PFNGLLINKPROGRAMPROC ) glGetProcAddress( "glLinkProgram" ) ) == NULL; Ret |= ( __glShaderSource = ( PFNGLSHADERSOURCEPROC ) glGetProcAddress( "glShaderSource" ) ) == NULL; Ret |= ( __glValidateProgram = ( PFNGLVALIDATEPROGRAMPROC ) glGetProcAddress( "glValidateProgram" ) ) == NULL; Ret |= ( __glBindAttribLocation = ( PFNGLBINDATTRIBLOCATIONPROC ) glGetProcAddress( "glBindAttribLocation" ) ) == NULL; Ret |= ( __glGetAttribLocation = ( PFNGLGETATTRIBLOCATIONPROC ) glGetProcAddress( "glGetAttribLocation" ) ) == NULL; Ret |= ( __glUseProgram = ( PFNGLUSEPROGRAMPROC ) glGetProcAddress( "glUseProgram" ) ) == NULL; // Uniforms Ret |= ( __glUniform1f = ( PFNGLUNIFORM1FPROC ) glGetProcAddress( "glUniform1f" ) ) == NULL; Ret |= ( __glUniform1fv = ( PFNGLUNIFORM1FVPROC ) glGetProcAddress( "glUniform1fv" ) ) == NULL; Ret |= ( __glUniform1i = ( PFNGLUNIFORM1IPROC ) glGetProcAddress( "glUniform1i" ) ) == NULL; Ret |= ( __glUniform1iv = ( PFNGLUNIFORM1IVPROC ) glGetProcAddress( "glUniform1iv" ) ) == NULL; Ret |= ( __glUniform2f = ( PFNGLUNIFORM2FPROC ) glGetProcAddress( "glUniform2f" ) ) == NULL; Ret |= ( __glUniform2fv = ( PFNGLUNIFORM2FVPROC ) glGetProcAddress( "glUniform2fv" ) ) == NULL; Ret |= ( __glUniform2i = ( PFNGLUNIFORM2IPROC ) glGetProcAddress( "glUniform2i" ) ) == NULL; Ret |= ( __glUniform2iv = ( PFNGLUNIFORM2IVPROC ) glGetProcAddress( "glUniform2iv" ) ) == NULL; Ret |= ( __glUniform3f = ( PFNGLUNIFORM3FPROC ) glGetProcAddress( "glUniform3f" ) ) == NULL; Ret |= ( __glUniform3fv = ( PFNGLUNIFORM3FVPROC ) glGetProcAddress( "glUniform3fv" ) ) == NULL; Ret |= ( __glUniform3i = ( PFNGLUNIFORM3IPROC ) glGetProcAddress( "glUniform3i" ) ) == NULL; Ret |= ( __glUniform3iv = ( PFNGLUNIFORM3IVPROC ) glGetProcAddress( "glUniform3iv" ) ) == NULL; Ret |= ( __glUniform4f = ( PFNGLUNIFORM4FPROC ) glGetProcAddress( "glUniform4f" ) ) == NULL; Ret |= ( __glUniform4fv = ( PFNGLUNIFORM4FVPROC ) glGetProcAddress( "glUniform4fv" ) ) == NULL; Ret |= ( __glUniform4i = ( PFNGLUNIFORM4IPROC ) glGetProcAddress( "glUniform4i" ) ) == NULL; Ret |= ( __glUniform4iv = ( PFNGLUNIFORM4IVPROC ) glGetProcAddress( "glUniform4iv" ) ) == NULL; Ret |= ( __glUniformMatrix2fv = ( PFNGLUNIFORMMATRIX2FVPROC ) glGetProcAddress( "glUniformMatrix2fv" ) ) == NULL; Ret |= ( __glUniformMatrix3fv = ( PFNGLUNIFORMMATRIX3FVPROC ) glGetProcAddress( "glUniformMatrix3fv" ) ) == NULL; Ret |= ( __glUniformMatrix4fv = ( PFNGLUNIFORMMATRIX4FVPROC ) glGetProcAddress( "glUniformMatrix4fv" ) ) == NULL; // Error check the OpenGL shader functions if( Ret == 0 ) { s_AllShaderFunctions = true; } } return true; }