gfxGLCardProfiler.cpp 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #include "gfx/gl/gfxGLCardProfiler.h"
  23. #include "gfx/gl/gfxGLDevice.h"
  24. #include "gfx/gl/gfxGLEnumTranslate.h"
  25. void GFXGLCardProfiler::init()
  26. {
  27. mChipSet = reinterpret_cast<const char*>(glGetString(GL_VENDOR));
  28. // get the major and minor parts of the GL version. These are defined to be
  29. // in the order "[major].[minor] [other]|[major].[minor].[release] [other] in the spec
  30. const char *versionStart = reinterpret_cast<const char*>(glGetString(GL_VERSION));
  31. const char *versionEnd = versionStart;
  32. // get the text for the version "x.x.xxxx "
  33. for( S32 tok = 0; tok < 2; ++tok )
  34. {
  35. char *text = dStrdup( versionEnd );
  36. dStrtok(text, ". ");
  37. versionEnd += dStrlen( text ) + 1;
  38. dFree( text );
  39. }
  40. mRendererString = "GL";
  41. mRendererString += String::SpanToString(versionStart, versionEnd - 1);
  42. mCardDescription = reinterpret_cast<const char*>(glGetString(GL_RENDERER));
  43. mVersionString = reinterpret_cast<const char*>(glGetString(GL_VERSION));
  44. mVideoMemory = static_cast<GFXGLDevice*>(GFX)->getTotalVideoMemory();
  45. Parent::init();
  46. // Set new enums here so if our profile script forces this to be false we keep the GL_ZEROs.
  47. if(queryProfile("GL::suppFloatTexture"))
  48. {
  49. GFXGLTextureInternalFormat[GFXFormatR16G16F] = GL_RGBA_FLOAT16_ATI;
  50. GFXGLTextureFormat[GFXFormatR16G16F] = GL_RGBA;
  51. GFXGLTextureInternalFormat[GFXFormatR16G16B16A16F] = GL_RGBA_FLOAT16_ATI;
  52. GFXGLTextureInternalFormat[GFXFormatR32G32B32A32F] = GL_RGBA_FLOAT32_ATI;
  53. GFXGLTextureInternalFormat[GFXFormatR32F] = GL_RGBA_FLOAT32_ATI;
  54. }
  55. }
  56. void GFXGLCardProfiler::setupCardCapabilities()
  57. {
  58. GLint maxTexSize;
  59. glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTexSize);
  60. const char* versionString = reinterpret_cast<const char*>(glGetString(GL_VERSION));
  61. F32 glVersion = dAtof(versionString);
  62. // OpenGL doesn't have separate maximum width/height.
  63. setCapability("maxTextureWidth", maxTexSize);
  64. setCapability("maxTextureHeight", maxTexSize);
  65. setCapability("maxTextureSize", maxTexSize);
  66. // If extensions haven't been inited, we're in trouble here.
  67. bool suppVBO = (gglHasExtension(ARB_vertex_buffer_object) || glVersion >= 1.499f);
  68. setCapability("GL::suppVertexBufferObject", suppVBO);
  69. // check if render to texture supported is available
  70. bool suppRTT = gglHasExtension(EXT_framebuffer_object);
  71. setCapability("GL::suppRenderTexture", suppRTT);
  72. bool suppBlit = gglHasExtension(EXT_framebuffer_blit);
  73. setCapability("GL::suppRTBlit", suppBlit);
  74. bool suppFloatTex = gglHasExtension(ARB_texture_float);
  75. setCapability("GL::suppFloatTexture", suppFloatTex);
  76. // Check for anisotropic filtering support.
  77. bool suppAnisotropic = gglHasExtension( EXT_texture_filter_anisotropic );
  78. setCapability( "GL::suppAnisotropic", suppAnisotropic );
  79. // check to see if we have the fragment shader extension or the gl version is high enough for glsl to be core
  80. // also check to see if the language version is high enough
  81. F32 glslVersion = dAtof(reinterpret_cast<const char*>(glGetString( GL_SHADING_LANGUAGE_VERSION)));
  82. bool suppSPU = (gglHasExtension(ARB_fragment_shader) || glVersion >= 1.999f) && glslVersion >= 1.0999;
  83. setCapability("GL::suppFragmentShader", suppSPU);
  84. bool suppAppleFence = gglHasExtension(APPLE_fence);
  85. setCapability("GL::APPLE::suppFence", suppAppleFence);
  86. // When enabled, call glGenerateMipmapEXT() to generate mipmaps instead of relying on GL_GENERATE_MIPMAP
  87. setCapability("GL::Workaround::needsExplicitGenerateMipmap", false);
  88. // When enabled, binds and unbinds a texture target before doing the depth buffer copy. Failure to do
  89. // so will cause a hard freeze on Mac OS 10.4 with a Radeon X1600
  90. setCapability("GL::Workaround::X1600DepthBufferCopy", false);
  91. // When enabled, does not copy the last column and row of the depth buffer in a depth buffer copy. Failure
  92. // to do so will cause a kernel panic on Mac OS 10.5(.1) with a Radeon HD 2600 (fixed in 10.5.2)
  93. setCapability("GL::Workaround::HD2600DepthBufferCopy", false);
  94. // Certain Intel drivers have a divide by 0 crash if mipmaps are specified with
  95. // glTexSubImage2D.
  96. setCapability("GL::Workaround::noManualMips", false);
  97. }
  98. bool GFXGLCardProfiler::_queryCardCap(const String& query, U32& foundResult)
  99. {
  100. // Just doing what the D3D9 layer does
  101. return 0;
  102. }
  103. bool GFXGLCardProfiler::_queryFormat(const GFXFormat fmt, const GFXTextureProfile *profile, bool &inOutAutogenMips)
  104. {
  105. // We assume if the format is valid that we can use it for any purpose.
  106. // This may not be the case, but we have no way to check short of in depth
  107. // testing of every format for every purpose. And by testing, I mean sitting
  108. // down and doing it by hand, because there is no OpenGL API to check these
  109. // things.
  110. return GFXGLTextureInternalFormat[fmt] != GL_ZERO;
  111. }