x86UNIXGL.client.cpp
Engine/source/platformX86UNIX/x86UNIXGL.client.cpp
Detailed Description
1 2//----------------------------------------------------------------------------- 3// Copyright (c) 2012 GarageGames, LLC 4// 5// Permission is hereby granted, free of charge, to any person obtaining a copy 6// of this software and associated documentation files (the "Software"), to 7// deal in the Software without restriction, including without limitation the 8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 9// sell copies of the Software, and to permit persons to whom the Software is 10// furnished to do so, subject to the following conditions: 11// 12// The above copyright notice and this permission notice shall be included in 13// all copies or substantial portions of the Software. 14// 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21// IN THE SOFTWARE. 22//----------------------------------------------------------------------------- 23#if 0 24#include "platformX86UNIX/platformGL.h" 25#include "platformX86UNIX/platformX86UNIX.h" 26#include "console/console.h" 27 28#include <dlfcn.h> 29#include <SDL/SDL.h> 30 31// declare stub functions 32#define GL_FUNCTION(fn_return, fn_name, fn_args, fn_value) fn_return stub_##fn_name fn_args{ fn_value } 33#include "platform/GLCoreFunc.h" 34#include "platform/GLExtFunc.h" 35#undef GL_FUNCTION 36 37// point gl function pointers at stub functions 38#define GL_FUNCTION(fn_return,fn_name,fn_args, fn_value) fn_return (*fn_name)fn_args = stub_##fn_name; 39#include "platform/GLCoreFunc.h" 40#include "platform/GLExtFunc.h" 41#undef GL_FUNCTION 42 43static void* dlHandle = NULL; 44 45//------------------------------------------------------------------ 46//bind functions for each function prototype 47//------------------------------------------------------------------ 48 49//GL_EXT/ARB 50enum { 51 ARB_multitexture = BIT(0), 52 ARB_texture_compression = BIT(1), 53 EXT_compiled_vertex_array = BIT(2), 54 EXT_fog_coord = BIT(3), 55 EXT_paletted_texture = BIT(4), 56 NV_vertex_array_range = BIT(5), 57 EXT_blend_color = BIT(6), 58 EXT_blend_minmax = BIT(7) 59}; 60 61//WGL_ARB 62enum { 63 WGL_ARB_extensions_string = BIT(0), 64 WGL_EXT_swap_control = BIT(1), 65 WGL_3DFX_gamma_control = BIT(2) 66}; 67 68 69static bool isFnOk( const char *name) 70{ 71 bool ok = false; 72 73 // JMQ: these are specific to torque's d3d->gl wrapper. They are not used under linux. 74 if (dStrcmp(name, "glAvailableVertexBufferEXT")==0) 75 ok = true; 76 else if (dStrcmp(name, "glAllocateVertexBufferEXT")==0) 77 ok = true; 78 else if (dStrcmp(name, "glLockVertexBufferEXT")==0) 79 ok = true; 80 else if (dStrcmp(name, "glUnlockVertexBufferEXT")==0) 81 ok = true; 82 else if (dStrcmp(name, "glSetVertexBufferEXT")==0) 83 ok = true; 84 else if (dStrcmp(name, "glOffsetVertexBufferEXT")==0) 85 ok = true; 86 else if (dStrcmp(name, "glFillVertexBufferEXT")==0) 87 ok = true; 88 else if (dStrcmp(name, "glFreeVertexBufferEXT")==0) 89 ok = true; 90 91 return ok; 92} 93 94//------------------------------------------------------------------ 95//bind functions for each function prototype 96//------------------------------------------------------------------ 97static bool bindGLFunction( void *&fnAddress, const char *name ) 98{ 99 void* addr = (void*)SDL_GL_GetProcAddress(name); 100 bool ok = (bool)addr; 101 if( !ok ) 102 { 103 if (!isFnOk(name)) 104 ConsoleLogEntry::General, " Missing OpenGL function '%s'", name); 105 else 106 ok = true; 107 } 108 else 109 fnAddress = addr; 110 return ok; 111} 112 113static bool bindEXTFunction( void *&fnAddress, const char *name ) 114{ 115 void* addr = (void*)SDL_GL_GetProcAddress(name); 116 if( !addr ) 117 ConsoleLogEntry::General, " Missing OpenGL extension '%s'", name); 118 else 119 fnAddress = addr; 120 return (addr != NULL); 121} 122 123//------------------------------------------------------------------ 124//binds for each function group 125//------------------------------------------------------------------ 126static bool bindGLFunctions() 127{ 128 bool result = true; 129 #define GL_FUNCTION(fn_return, fn_name, fn_args, fn_value) \ 130 result &= bindGLFunction( *(void**)&fn_name, #fn_name); 131 #include "platform/GLCoreFunc.h" 132 #undef GL_FUNCTION 133 return result; 134} 135 136static bool bindEXTFunctions(U32 extMask) 137{ 138 bool result = true; 139 140 #define GL_GROUP_BEGIN( flag ) \ 141 if( extMask & flag ) { 142 #define GL_GROUP_END() } 143 144 #define GL_FUNCTION(fn_return, fn_name, fn_args, fn_value) \ 145 result &= bindEXTFunction( *(void**)&fn_name, #fn_name); 146 #include "platform/GLExtFunc.h" 147 #undef GL_FUNCTION 148 149 #undef GL_GROUP_BEGIN 150 #undef GL_GROUP_END 151 152 return result; 153} 154 155static void unbindGLFunctions() 156{ 157 // point gl function pointers at stub functions 158#define GL_FUNCTION(fn_return, fn_name, fn_args, fn_value) fn_name = stub_##fn_name; 159#include "platform/GLCoreFunc.h" 160#include "platform/GLExtFunc.h" 161#undef GL_FUNCTION 162} 163 164namespace GLLoader 165{ 166 167 bool OpenGLInit() 168 { 169 return OpenGLDLLInit(); 170 } 171 172 void OpenGLShutdown() 173 { 174 OpenGLDLLShutdown(); 175 } 176 177 bool OpenGLDLLInit() 178 { 179 OpenGLDLLShutdown(); 180 181 // load libGL.so 182 if (SDL_GL_LoadLibrary("libGL.so") == -1 && 183 SDL_GL_LoadLibrary("libGL.so.1") == -1) 184 { 185 Con::errorf("Error loading GL library: %s", SDL_GetError()); 186 return false; 187 } 188 189 // bind functions 190 if (!bindGLFunctions()) 191 { 192 Con::errorf("Error binding GL functions"); 193 OpenGLDLLShutdown(); 194 return false; 195 } 196 197 return true; 198 } 199 200 void OpenGLDLLShutdown() 201 { 202 // there is no way to tell SDL to unload the library 203 if (dlHandle != NULL) 204 { 205 dlclose(dlHandle); 206 dlHandle = NULL; 207 } 208 209 unbindGLFunctions(); 210 } 211 212} 213 214GLState gGLState; 215 216bool gOpenGLDisablePT = false; 217bool gOpenGLDisableCVA = false; 218bool gOpenGLDisableTEC = false; 219bool gOpenGLDisableARBMT = false; 220bool gOpenGLDisableFC = false; 221bool gOpenGLDisableTCompress = false; 222bool gOpenGLNoEnvColor = false; 223float gOpenGLGammaCorrection = 0.5; 224bool gOpenGLNoDrawArraysAlpha = false; 225 226// JMQTODO: really need a platform-shared version of this nastiness 227bool GL_EXT_Init( ) 228{ 229 // Load extensions... 230 // 231 const char* pExtString = reinterpret_cast<const char*>(glGetString(GL_EXTENSIONS)); 232 gGLState.primMode = 0; 233 U32 extBitMask = 0; 234 235 // GL_EXT_paletted_texture 236 if (pExtString && NULL) 237 { 238 extBitMask |= EXT_paletted_texture; 239 gGLState.suppPalettedTexture = true; 240 } 241 else 242 gGLState.suppPalettedTexture = false; 243 244 // EXT_compiled_vertex_array 245 if (pExtString && NULL) 246 { 247 extBitMask |= EXT_compiled_vertex_array; 248 gGLState.suppLockedArrays = true; 249 } 250 else 251 { 252 gGLState.suppLockedArrays = false; 253 } 254 255 // ARB_multitexture 256 if (pExtString && NULL) 257 { 258 extBitMask |= ARB_multitexture; 259 gGLState.suppARBMultitexture = true; 260 } else { 261 gGLState.suppARBMultitexture = false; 262 } 263 264 // EXT_blend_color 265 if(pExtString && NULL) 266 { 267 extBitMask |= EXT_blend_color; 268 gGLState.suppEXTblendcolor = true; 269 } else { 270 gGLState.suppEXTblendcolor = false; 271 } 272 273 // EXT_blend_minmax 274 if(pExtString && NULL) 275 { 276 extBitMask |= EXT_blend_color; 277 gGLState.suppEXTblendminmax = true; 278 } else { 279 gGLState.suppEXTblendminmax = false; 280 } 281 282 // EXT_fog_coord 283 if (pExtString && NULL) 284 { 285 extBitMask |= EXT_fog_coord; 286 gGLState.suppFogCoord = true; 287 } else { 288 gGLState.suppFogCoord = false; 289 } 290 291 // EXT_texture_compression_s3tc 292 if (pExtString && NULL) 293 gGLState.suppS3TC = true; 294 else 295 gGLState.suppS3TC = false; 296 297 // ARB_texture_compression 298 NULL) 299 { 300 extBitMask |= ARB_texture_compression; 301 gGLState.suppTextureCompression = true; 302 } else { 303 gGLState.suppTextureCompression = false; 304 } 305 306 // NV_vertex_array_range (not on *nix) 307 gGLState.suppVertexArrayRange = false; 308 309 // 3DFX_texture_compression_FXT1 310 if (pExtString && NULL) 311 gGLState.suppFXT1 = true; 312 else 313 gGLState.suppFXT1 = false; 314 315 if (!bindEXTFunctions(extBitMask)) 316 Con::warnf("You are missing some OpenGL Extensions. You may experience rendering problems."); 317 318 // Binary states, i.e., no supporting functions 319 // EXT_packed_pixels 320 // EXT_texture_env_combine 321 // 322 // dhc note: a number of these can have multiple matching 'versions', private, ext, and arb. 323 gGLState.suppPackedPixels = pExtString? (NULL) : false; 324 gGLState.suppTextureEnvCombine = pExtString? (NULL) : false; 325 gGLState.suppEdgeClamp = pExtString? (NULL) : false; 326 gGLState.suppEdgeClamp |= pExtString? (NULL) : false; 327 gGLState.suppTexEnvAdd = pExtString? (NULL) : false; 328 gGLState.suppTexEnvAdd |= pExtString? (NULL) : false; 329 330 // Anisotropic filtering 331 gGLState.suppTexAnisotropic = pExtString? (NULL) : false; 332 if (gGLState.suppTexAnisotropic) 333 glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &gGLState.maxAnisotropy); 334 if (gGLState.suppARBMultitexture) 335 glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &gGLState.maxTextureUnits); 336 else 337 gGLState.maxTextureUnits = 1; 338 339 // JMQ: vsync/swap interval skipped 340 gGLState.suppSwapInterval = false; 341 342 Con::printf("OpenGL Init: Enabled Extensions"); 343 if (gGLState.suppARBMultitexture) Con::printf(" ARB_multitexture (Max Texture Units: %d)", gGLState.maxTextureUnits); 344 if (gGLState.suppEXTblendcolor) Con::printf(" EXT_blend_color"); 345 if (gGLState.suppEXTblendminmax) Con::printf(" EXT_blend_minmax"); 346 if (gGLState.suppPalettedTexture) Con::printf(" EXT_paletted_texture"); 347 if (gGLState.suppLockedArrays) Con::printf(" EXT_compiled_vertex_array"); 348 if (gGLState.suppVertexArrayRange) Con::printf(" NV_vertex_array_range"); 349 if (gGLState.suppTextureEnvCombine) Con::printf(" EXT_texture_env_combine"); 350 if (gGLState.suppPackedPixels) Con::printf(" EXT_packed_pixels"); 351 if (gGLState.suppFogCoord) Con::printf(" EXT_fog_coord"); 352 if (gGLState.suppTextureCompression) Con::printf(" ARB_texture_compression"); 353 if (gGLState.suppS3TC) Con::printf(" EXT_texture_compression_s3tc"); 354 if (gGLState.suppFXT1) Con::printf(" 3DFX_texture_compression_FXT1"); 355 if (gGLState.suppTexEnvAdd) Con::printf(" (ARB|EXT)_texture_env_add"); 356 if (gGLState.suppTexAnisotropic) Con::printf(" EXT_texture_filter_anisotropic (Max anisotropy: %f)", gGLState.maxAnisotropy); 357 if (gGLState.suppSwapInterval) Con::printf(" WGL_EXT_swap_control"); 358 359 Con::warnf("OpenGL Init: Disabled Extensions"); 360 if (!gGLState.suppARBMultitexture) Con::warnf(" ARB_multitexture"); 361 if (!gGLState.suppEXTblendcolor) Con::warnf(" EXT_blend_color"); 362 if (!gGLState.suppEXTblendminmax) Con::warnf(" EXT_blend_minmax"); 363 if (!gGLState.suppPalettedTexture) Con::warnf(" EXT_paletted_texture"); 364 if (!gGLState.suppLockedArrays) Con::warnf(" EXT_compiled_vertex_array"); 365 if (!gGLState.suppVertexArrayRange) Con::warnf(" NV_vertex_array_range"); 366 if (!gGLState.suppTextureEnvCombine) Con::warnf(" EXT_texture_env_combine"); 367 if (!gGLState.suppPackedPixels) Con::warnf(" EXT_packed_pixels"); 368 if (!gGLState.suppFogCoord) Con::warnf(" EXT_fog_coord"); 369 if (!gGLState.suppTextureCompression) Con::warnf(" ARB_texture_compression"); 370 if (!gGLState.suppS3TC) Con::warnf(" EXT_texture_compression_s3tc"); 371 if (!gGLState.suppFXT1) Con::warnf(" 3DFX_texture_compression_FXT1"); 372 if (!gGLState.suppTexEnvAdd) Con::warnf(" (ARB|EXT)_texture_env_add"); 373 if (!gGLState.suppTexAnisotropic) Con::warnf(" EXT_texture_filter_anisotropic"); 374 if (!gGLState.suppSwapInterval) Con::warnf(" WGL_EXT_swap_control"); 375 Con::printf(" "); 376 377 // Set some console variables: 378 Con::setBoolVariable( "$FogCoordSupported", gGLState.suppFogCoord ); 379 Con::setBoolVariable( "$TextureCompressionSupported", gGLState.suppTextureCompression ); 380 Con::setBoolVariable( "$AnisotropySupported", gGLState.suppTexAnisotropic ); 381 Con::setBoolVariable( "$PalettedTextureSupported", gGLState.suppPalettedTexture ); 382 Con::setBoolVariable( "$SwapIntervalSupported", gGLState.suppSwapInterval ); 383 384 if (!gGLState.suppPalettedTexture && Con::getBoolVariable("$pref::OpenGL::forcePalettedTexture",false)) 385 { 386 Con::setBoolVariable("$pref::OpenGL::forcePalettedTexture", false); 387 Con::setBoolVariable("$pref::OpenGL::force16BitTexture", true); 388 } 389 390 return true; 391} 392 393#endif // 0 394