00001 #include "MercuryOGL_Ext.h" 00002 00003 #if !defined(WIN32) 00004 #include "MercuryWindowSDL.h" 00005 #endif 00006 00007 PWSWAPINTERVALEXTPROC wglSwapIntervalEXT; 00008 00009 PFNGLMULTITEXCOORD1FARBPROC glMultiTexCoord1fARBm; 00010 PFNGLMULTITEXCOORD2FARBPROC glMultiTexCoord2fARBm; 00011 PFNGLMULTITEXCOORD3FARBPROC glMultiTexCoord3fARBm; 00012 PFNGLMULTITEXCOORD4FARBPROC glMultiTexCoord4fARBm; 00013 PFNGLACTIVETEXTUREARBPROC glActiveTextureARBm; 00014 PFNGLCLIENTACTIVETEXTUREARBPROC glClientActiveTextureARBm; 00015 00016 PFNGLPOINTPARAMETERFARBPROC glPointParameterfARB; 00017 PFNGLPOINTPARAMETERFVARBPROC glPointParameterfvARB; 00018 00019 //glslang 00020 PFNGLCREATEPROGRAMOBJECTARBPROC glCreateProgramObjectARB; 00021 PFNGLDELETEOBJECTARBPROC glDeleteObjectARB; 00022 PFNGLDETACHOBJECTARBPROC glDetachObjectARB; 00023 PFNGLGETATTACHEDOBJECTSARBPROC glGetAttachedObjectsARB; 00024 PFNGLUSEPROGRAMOBJECTARBPROC glUseProgramObjectARB; 00025 PFNGLCREATESHADEROBJECTARBPROC glCreateShaderObjectARB ; 00026 PFNGLSHADERSOURCEARBPROC glShaderSourceARB; 00027 PFNGLCOMPILESHADERARBPROC glCompileShaderARB; 00028 PFNGLGETOBJECTPARAMETERIVARBPROC glGetObjectParameterivARB; 00029 PFNGLATTACHOBJECTARBPROC glAttachObjectARB; 00030 PFNGLGETINFOLOGARBPROC glGetInfoLogARB; 00031 PFNGLLINKPROGRAMARBPROC glLinkProgramARB; 00032 PFNGLGETUNIFORMLOCATIONARBPROC glGetUniformLocationARB; 00033 PFNGLUNIFORM1FARBPROC glUniform1fARB; 00034 PFNGLUNIFORM2FARBPROC glUniform2fARB; 00035 PFNGLUNIFORM3FARBPROC glUniform3fARB; 00036 PFNGLUNIFORM4FARBPROC glUniform4fARB; 00037 PFNGLUNIFORM1IARBPROC glUniform1iARB; 00038 PFNGLUNIFORM2IARBPROC glUniform2iARB; 00039 PFNGLUNIFORM3IARBPROC glUniform3iARB; 00040 PFNGLUNIFORM4IARBPROC glUniform4iARB; 00041 PFNGLGETATTRIBLOCATIONARBPROC glGetAttribLocationARB; 00042 PFNGLVERTEXATTRIB3FARBPROC glVertexAttrib3fARB; 00043 00044 PFNGLENABLEVERTEXATTRIBARRAYARBPROC glEnableVertexAttribArrayARB; 00045 PFNGLENABLEVERTEXATTRIBARRAYARBPROC glDisableVertexAttribArrayARB; 00046 PFNGLVERTEXATTRIBPOINTERARBPROC glVertexAttribPointerARB; 00047 00048 bool mercuryIsSupportFrameBufferObjectEXT = false; 00049 bool supportAnisotrophy = false; 00050 00051 // EXT_framebuffer_object - http://oss.sgi.com/projects/ogl-sample/registry/EXT/framebuffer_object.txt 00052 PFNGLISRENDERBUFFEREXTPROC glIsRenderbufferEXT; 00053 PFNGLBINDRENDERBUFFEREXTPROC glBindRenderbufferEXT; 00054 PFNGLDELETERENDERBUFFERSEXTPROC glDeleteRenderbuffersEXT; 00055 PFNGLGENRENDERBUFFERSEXTPROC glGenRenderbuffersEXT; 00056 PFNGLRENDERBUFFERSTORAGEEXTPROC glRenderbufferStorageEXT; 00057 PFNGLGETRENDERBUFFERPARAMETERIVEXTPROC glGetRenderbufferParameterivEXT; 00058 PFNGLISFRAMEBUFFEREXTPROC glIsFramebufferEXT; 00059 PFNGLBINDFRAMEBUFFEREXTPROC glBindFramebufferEXT; 00060 PFNGLDELETEFRAMEBUFFERSEXTPROC glDeleteFramebuffersEXT; 00061 PFNGLGENFRAMEBUFFERSEXTPROC glGenFramebuffersEXT; 00062 PFNGLCHECKFRAMEBUFFERSTATUSEXTPROC glCheckFramebufferStatusEXT; 00063 PFNGLFRAMEBUFFERTEXTURE1DEXTPROC glFramebufferTexture1DEXT; 00064 PFNGLFRAMEBUFFERTEXTURE2DEXTPROC glFramebufferTexture2DEXT; 00065 PFNGLFRAMEBUFFERTEXTURE3DEXTPROC glFramebufferTexture3DEXT; 00066 PFNGLFRAMEBUFFERRENDERBUFFEREXTPROC glFramebufferRenderbufferEXT; 00067 PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVEXTPROC glGetFramebufferAttachmentParameterivEXT; 00068 PFNGLGENERATEMIPMAPEXTPROC glGenerateMipmapEXT; 00069 00070 //VBO 00071 PFNGLBINDBUFFERARBPROC glBindBufferARB; 00072 PFNGLDELETEBUFFERSARBPROC glDeleteBuffersARB; 00073 PFNGLGENBUFFERSARBPROC glGenBuffersARB; 00074 PFNGLBUFFERDATAARBPROC glBufferDataARB; 00075 00076 PFNGLLOCKARRAYSEXTPROC glLockArraysEXT; 00077 PFNGLUNLOCKARRAYSEXTPROC glUnlockArraysEXT; 00078 00079 void ClearOpenglApiExtensions() 00080 { 00081 wglSwapIntervalEXT = NULL; 00082 00083 glMultiTexCoord1fARBm = NULL; 00084 glMultiTexCoord2fARBm = NULL; 00085 glMultiTexCoord3fARBm = NULL; 00086 glMultiTexCoord4fARBm = NULL; 00087 glActiveTextureARBm = NULL; 00088 glClientActiveTextureARBm = NULL; 00089 00090 glPointParameterfARB = NULL; 00091 glPointParameterfvARB = NULL; 00092 00093 glBindBufferARB = NULL; 00094 glGenBuffersARB = NULL; 00095 glBufferDataARB = NULL; 00096 00097 //(glSlang) GL_ARB_shader_objects 00098 glCreateProgramObjectARB = NULL; 00099 glDeleteObjectARB = NULL; 00100 glDetachObjectARB = NULL; 00101 glGetAttachedObjectsARB = NULL; 00102 glUseProgramObjectARB = NULL; 00103 glGetAttribLocationARB = NULL; 00104 glVertexAttrib3fARB = NULL; 00105 00106 glCreateShaderObjectARB = NULL; 00107 glShaderSourceARB = NULL; 00108 glCompileShaderARB = NULL; 00109 glGetObjectParameterivARB = NULL; 00110 glAttachObjectARB = NULL; 00111 glGetInfoLogARB = NULL; 00112 glLinkProgramARB = NULL; 00113 glGetUniformLocationARB = NULL; 00114 glUniform1fARB = NULL; 00115 glUniform2fARB = NULL; 00116 glUniform3fARB = NULL; 00117 glUniform4fARB = NULL; 00118 glUniform1iARB = NULL; 00119 glUniform2iARB = NULL; 00120 glUniform3iARB = NULL; 00121 glUniform4iARB = NULL; 00122 00123 glEnableVertexAttribArrayARB = NULL; 00124 glDisableVertexAttribArrayARB = NULL; 00125 glVertexAttribPointerARB = NULL; 00126 00127 glGenBuffersARB = NULL; 00128 glBindBufferARB = NULL; 00129 glBufferDataARB = NULL; 00130 glDeleteBuffersARB = NULL; 00131 00132 glLockArraysEXT = NULL; 00133 glUnlockArraysEXT = NULL; 00134 } 00135 00136 void InitOpenglApiExtensions() 00137 { 00138 GLExtensions ext; 00139 00140 ClearOpenglApiExtensions(); 00141 PopulateExtensions(ext); 00142 00143 if (ext.IsExtension("WGL_EXT_swap_control")) 00144 { 00145 wglSwapIntervalEXT = (PWSWAPINTERVALEXTPROC) GetProcAddress("wglSwapIntervalEXT"); 00146 } 00147 00148 if (ext.IsExtension("GL_ARB_multitexture")) 00149 { 00150 // glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB,&maxTexelUnits); 00151 glMultiTexCoord1fARBm = (PFNGLMULTITEXCOORD1FARBPROC) GetProcAddress("glMultiTexCoord1fARB"); 00152 glMultiTexCoord2fARBm = (PFNGLMULTITEXCOORD2FARBPROC) GetProcAddress("glMultiTexCoord2fARB"); 00153 glMultiTexCoord3fARBm = (PFNGLMULTITEXCOORD3FARBPROC) GetProcAddress("glMultiTexCoord3fARB"); 00154 glMultiTexCoord4fARBm = (PFNGLMULTITEXCOORD4FARBPROC) GetProcAddress("glMultiTexCoord4fARB"); 00155 glActiveTextureARBm = (PFNGLACTIVETEXTUREARBPROC) GetProcAddress("glActiveTextureARB"); 00156 glClientActiveTextureARBm = (PFNGLCLIENTACTIVETEXTUREARBPROC) GetProcAddress("glClientActiveTextureARB"); 00157 } 00158 00159 if ( ext.IsExtension("GL_ARB_point_sprite") ) 00160 { 00161 glPointParameterfARB = (PFNGLPOINTPARAMETERFEXTPROC)GetProcAddress("glPointParameterfARB"); 00162 glPointParameterfvARB = (PFNGLPOINTPARAMETERFVEXTPROC)GetProcAddress("glPointParameterfvARB"); 00163 } 00164 00165 if ( ext.IsExtension("GL_ARB_vertex_buffer_object") ) 00166 { 00167 glBindBufferARB = (PFNGLBINDBUFFERARBPROC) GetProcAddress("glBindBufferARB"); 00168 glGenBuffersARB = (PFNGLGENBUFFERSARBPROC) GetProcAddress("glGenBuffersARB"); 00169 glBufferDataARB = (PFNGLBUFFERDATAARBPROC) GetProcAddress("glBufferDataARB"); 00170 } 00171 00172 if ( ext.IsExtension("GL_ARB_shading_language_100") && ext.IsExtension ("GL_ARB_shader_objects")) 00173 { 00174 glCreateProgramObjectARB = (PFNGLCREATEPROGRAMOBJECTARBPROC)GetProcAddress("glCreateProgramObjectARB"); 00175 glDeleteObjectARB = (PFNGLDELETEOBJECTARBPROC)GetProcAddress("glDeleteObjectARB"); 00176 glDetachObjectARB = (PFNGLDETACHOBJECTARBPROC)GetProcAddress("glDetachObjectARB"); 00177 glGetAttachedObjectsARB = (PFNGLGETATTACHEDOBJECTSARBPROC)GetProcAddress("glGetAttachedObjectsARB"); 00178 glUseProgramObjectARB = (PFNGLUSEPROGRAMOBJECTARBPROC)GetProcAddress("glUseProgramObjectARB"); 00179 glGetAttribLocationARB = (PFNGLGETATTRIBLOCATIONARBPROC)GetProcAddress("glGetAttribLocationARB"); 00180 glVertexAttrib3fARB = (PFNGLVERTEXATTRIB3FARBPROC)GetProcAddress("glVertexAttrib3fARB"); 00181 00182 glCreateShaderObjectARB = (PFNGLCREATESHADEROBJECTARBPROC)GetProcAddress("glCreateShaderObjectARB"); 00183 glShaderSourceARB = (PFNGLSHADERSOURCEARBPROC)GetProcAddress("glShaderSourceARB"); 00184 glCompileShaderARB = (PFNGLCOMPILESHADERARBPROC)GetProcAddress("glCompileShaderARB"); 00185 glGetObjectParameterivARB = (PFNGLGETOBJECTPARAMETERIVARBPROC)GetProcAddress("glGetObjectParameterivARB"); 00186 glAttachObjectARB = (PFNGLATTACHOBJECTARBPROC)GetProcAddress("glAttachObjectARB"); 00187 glGetInfoLogARB = (PFNGLGETINFOLOGARBPROC)GetProcAddress("glGetInfoLogARB"); 00188 glLinkProgramARB = (PFNGLLINKPROGRAMARBPROC)GetProcAddress("glLinkProgramARB"); 00189 glGetUniformLocationARB = (PFNGLGETUNIFORMLOCATIONARBPROC)GetProcAddress("glGetUniformLocationARB"); 00190 glUniform4fARB = (PFNGLUNIFORM4FARBPROC)GetProcAddress("glUniform4fARB"); 00191 glUniform3fARB = (PFNGLUNIFORM3FARBPROC)GetProcAddress("glUniform3fARB"); 00192 glUniform2fARB = (PFNGLUNIFORM2FARBPROC)GetProcAddress("glUniform2fARB"); 00193 glUniform1fARB = (PFNGLUNIFORM1FARBPROC)GetProcAddress("glUniform1fARB"); 00194 glUniform1iARB = (PFNGLUNIFORM1IARBPROC)GetProcAddress("glUniform1iARB"); 00195 glUniform2iARB = (PFNGLUNIFORM2IARBPROC)GetProcAddress("glUniform2iARB"); 00196 glUniform3iARB = (PFNGLUNIFORM3IARBPROC)GetProcAddress("glUniform3iARB"); 00197 glUniform4iARB = (PFNGLUNIFORM4IARBPROC)GetProcAddress("glUniform4iARB"); 00198 00199 glEnableVertexAttribArrayARB = (PFNGLENABLEVERTEXATTRIBARRAYARBPROC)GetProcAddress("glEnableVertexAttribArrayARB"); 00200 glDisableVertexAttribArrayARB = (PFNGLENABLEVERTEXATTRIBARRAYARBPROC)GetProcAddress("glDisableVertexAttribArrayARB"); 00201 glVertexAttribPointerARB = (PFNGLVERTEXATTRIBPOINTERARBPROC)GetProcAddress("glVertexAttribPointerARB"); 00202 } 00203 00204 00205 //this stuff was cut and paste from codesampler.com 00206 if ( ext.IsExtension("GL_EXT_framebuffer_object") ) 00207 { 00208 glIsRenderbufferEXT = (PFNGLISRENDERBUFFEREXTPROC)GetProcAddress("glIsRenderbufferEXT"); 00209 glBindRenderbufferEXT = (PFNGLBINDRENDERBUFFEREXTPROC)GetProcAddress("glBindRenderbufferEXT"); 00210 glDeleteRenderbuffersEXT = (PFNGLDELETERENDERBUFFERSEXTPROC)GetProcAddress("glDeleteRenderbuffersEXT"); 00211 glGenRenderbuffersEXT = (PFNGLGENRENDERBUFFERSEXTPROC)GetProcAddress("glGenRenderbuffersEXT"); 00212 glRenderbufferStorageEXT = (PFNGLRENDERBUFFERSTORAGEEXTPROC)GetProcAddress("glRenderbufferStorageEXT"); 00213 glGetRenderbufferParameterivEXT = (PFNGLGETRENDERBUFFERPARAMETERIVEXTPROC)GetProcAddress("glGetRenderbufferParameterivEXT"); 00214 glIsFramebufferEXT = (PFNGLISFRAMEBUFFEREXTPROC)GetProcAddress("glIsFramebufferEXT"); 00215 glBindFramebufferEXT = (PFNGLBINDFRAMEBUFFEREXTPROC)GetProcAddress("glBindFramebufferEXT"); 00216 glDeleteFramebuffersEXT = (PFNGLDELETEFRAMEBUFFERSEXTPROC)GetProcAddress("glDeleteFramebuffersEXT"); 00217 glGenFramebuffersEXT = (PFNGLGENFRAMEBUFFERSEXTPROC)GetProcAddress("glGenFramebuffersEXT"); 00218 glCheckFramebufferStatusEXT = (PFNGLCHECKFRAMEBUFFERSTATUSEXTPROC)GetProcAddress("glCheckFramebufferStatusEXT"); 00219 glFramebufferTexture1DEXT = (PFNGLFRAMEBUFFERTEXTURE1DEXTPROC)GetProcAddress("glFramebufferTexture1DEXT"); 00220 glFramebufferTexture2DEXT = (PFNGLFRAMEBUFFERTEXTURE2DEXTPROC)GetProcAddress("glFramebufferTexture2DEXT"); 00221 glFramebufferTexture3DEXT = (PFNGLFRAMEBUFFERTEXTURE3DEXTPROC)GetProcAddress("glFramebufferTexture3DEXT"); 00222 glFramebufferRenderbufferEXT = (PFNGLFRAMEBUFFERRENDERBUFFEREXTPROC)GetProcAddress("glFramebufferRenderbufferEXT"); 00223 glGetFramebufferAttachmentParameterivEXT = (PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVEXTPROC)GetProcAddress("glGetFramebufferAttachmentParameterivEXT"); 00224 glGenerateMipmapEXT = (PFNGLGENERATEMIPMAPEXTPROC)GetProcAddress("glGenerateMipmapEXT"); 00225 00226 mercuryIsSupportFrameBufferObjectEXT = true; 00227 } 00228 else 00229 mercuryIsSupportFrameBufferObjectEXT = false; 00230 00231 if (ext.IsExtension("GL_ARB_vertex_buffer_object")) 00232 { 00233 glGenBuffersARB = (PFNGLGENBUFFERSARBPROC)GetProcAddress("glGenBuffersARB"); 00234 glBindBufferARB = (PFNGLBINDBUFFERARBPROC)GetProcAddress("glBindBufferARB"); 00235 glBufferDataARB = (PFNGLBUFFERDATAARBPROC)GetProcAddress("glBufferDataARB"); 00236 glDeleteBuffersARB = (PFNGLDELETEBUFFERSARBPROC)GetProcAddress("glDeleteBuffersARB"); 00237 } 00238 00239 if (ext.IsExtension("GL_EXT_texture_filter_anisotropic")) 00240 supportAnisotrophy = true; 00241 00242 if (ext.IsExtension("GL_EXT_compiled_vertex_array")) 00243 { 00244 glLockArraysEXT = (PFNGLLOCKARRAYSEXTPROC)GetProcAddress("glLockArraysEXT"); 00245 glUnlockArraysEXT = (PFNGLUNLOCKARRAYSEXTPROC)GetProcAddress("glUnlockArraysEXT"); 00246 } 00247 } 00248 00249 void PopulateExtensions(GLExtensions& extc) 00250 { 00251 MString ext = (char*)glGetString(GL_EXTENSIONS); 00252 while (ext.length() > 0) 00253 { 00254 int p = ext.find(" ", 0); 00255 00256 MString extension; 00257 if ( p > -1 ) 00258 { 00259 extension = ext.substr(0, p); 00260 ext = ext.substr(p+1); 00261 } 00262 else 00263 { 00264 extension = ext; 00265 ext.assign(""); 00266 } 00267 00268 //Map Insert 00269 extc.m_extensions[extension] = true; 00270 } 00271 }; 00272 00273 bool GLExtensions::IsExtension(const MString& ext) const 00274 { 00275 if (m_extensions.find(ext) == m_extensions.end()) 00276 return false; 00277 00278 return true; 00279 } 00280 00281 00282 #if defined(WIN32) 00283 void* GetProcAddress( MString s ) 00284 { 00285 void *pRet = (void *)wglGetProcAddress( s ); 00286 if( pRet != NULL ) 00287 return pRet; 00288 00289 return NULL; 00290 } 00291 #else 00292 void* GetProcAddress( MString s ) 00293 { 00294 return SDL_GL_GetProcAddress(s); 00295 } 00296 #endif 00297 00298 00299 /* 00300 * Copyright (c) 2006, Joshua Allen 00301 * All rights reserved. 00302 * 00303 * Redistribution and use in source and binary forms, with or 00304 * without modification, are permitted provided that the following 00305 * conditions are met: 00306 * - Redistributions of source code must retain the above 00307 * copyright notice, this list of conditions and the following disclaimer. 00308 * - Redistributions in binary form must reproduce the above copyright 00309 * notice, this list of conditions and the following disclaimer in 00310 * the documentation and/or other materials provided with the distribution. 00311 * - Neither the name of the Mercury Engine nor the names of its 00312 * contributors may be used to endorse or promote products derived from 00313 * this software without specific prior written permission. 00314 * 00315 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00316 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00317 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00318 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 00319 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00320 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 00321 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00322 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00323 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 00324 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00325 */