Browse Source

Create depth-stencil texture instead of renderbuffer on OpenGL 3 / Intel / Windows to work around a driver bug.

Lasse Öörni 10 years ago
parent
commit
d99fefa68b

+ 8 - 4
Source/Urho3D/Graphics/OpenGL/OGLGraphics.cpp

@@ -205,6 +205,7 @@ static void GetGLPrimitiveType(unsigned elementCount, PrimitiveType type, unsign
 
 
 const Vector2 Graphics::pixelUVOffset(0.0f, 0.0f);
 const Vector2 Graphics::pixelUVOffset(0.0f, 0.0f);
 bool Graphics::gl3Support = false;
 bool Graphics::gl3Support = false;
+bool Graphics::intelGPU = false;
 
 
 Graphics::Graphics(Context* context_) :
 Graphics::Graphics(Context* context_) :
     Object(context_),
     Object(context_),
@@ -2762,12 +2763,15 @@ void Graphics::CheckFeatureSupport(String& extensions)
     if (numSupportedRTs >= 4)
     if (numSupportedRTs >= 4)
         deferredSupport_ = true;
         deferredSupport_ = true;
     
     
-    #if defined(__APPLE__) && !defined(IOS)
-    // On OS X check for an Intel driver and use shadow map RGBA dummy color textures, because mixing
-    // depth-only FBO rendering and backbuffer rendering will bug, resulting in a black screen in full
-    // screen mode, and incomplete shadow maps in windowed mode
     String renderer((const char*)glGetString(GL_RENDERER));
     String renderer((const char*)glGetString(GL_RENDERER));
     if (renderer.Contains("Intel", false))
     if (renderer.Contains("Intel", false))
+        intelGPU = true;
+
+    #if defined(__APPLE__) && !defined(IOS)
+    // On OS X Intel drivers need to use shadow map RGBA dummy color textures, because mixing depth-
+    // only FBO rendering and backbuffer rendering will bug, resulting in a black screen in full screen
+    // mode, and incomplete shadow maps in windowed mode
+    if (intelGPU)
         dummyColorFormat_ = GetRGBAFormat();
         dummyColorFormat_ = GetRGBAFormat();
     #endif
     #endif
     
     

+ 4 - 0
Source/Urho3D/Graphics/OpenGL/OGLGraphics.h

@@ -443,6 +443,8 @@ public:
     static unsigned GetMaxBones();
     static unsigned GetMaxBones();
     /// Return whether is using an OpenGL 3 context.
     /// Return whether is using an OpenGL 3 context.
     static bool GetGL3Support() { return gl3Support; }
     static bool GetGL3Support() { return gl3Support; }
+    /// Return whether is using an Intel GPU. These need some specific workarounds.
+    static bool IsIntelGPU() { return intelGPU; }
 
 
 private:
 private:
     /// Create the application window icon.
     /// Create the application window icon.
@@ -637,6 +639,8 @@ private:
     static const Vector2 pixelUVOffset;
     static const Vector2 pixelUVOffset;
     /// Flag for OpenGL 3 support.
     /// Flag for OpenGL 3 support.
     static bool gl3Support;
     static bool gl3Support;
+    /// Flag for Intel GPU.
+    static bool intelGPU;
 };
 };
 
 
 /// Register Graphics library objects.
 /// Register Graphics library objects.

+ 8 - 2
Source/Urho3D/Graphics/OpenGL/OGLTexture2D.cpp

@@ -440,9 +440,15 @@ bool Texture2D::Create()
     unsigned dataType = GetDataType(format_);
     unsigned dataType = GetDataType(format_);
     
     
     // Create a renderbuffer instead of a texture if depth texture is not properly supported, or if this will be a packed
     // Create a renderbuffer instead of a texture if depth texture is not properly supported, or if this will be a packed
-    // depth stencil texture
+    // depth stencil surface. Exception on Intel GPU's on Windows: always create depth textures on OpenGL 3 to work
+    // around a driver bug
     #ifndef GL_ES_VERSION_2_0
     #ifndef GL_ES_VERSION_2_0
-    if (format == Graphics::GetDepthStencilFormat())
+    #ifdef WIN32
+    bool depthStencilWorkaround = Graphics::GetGL3Support() && Graphics::IsIntelGPU();
+    #else
+    bool depthStencilWorkaround = false;
+    #endif
+    if (!depthStencilWorkaround && format == Graphics::GetDepthStencilFormat())
     #else
     #else
     if (format == GL_DEPTH_COMPONENT16 || format == GL_DEPTH_COMPONENT24_OES || format == GL_DEPTH24_STENCIL8_OES ||
     if (format == GL_DEPTH_COMPONENT16 || format == GL_DEPTH_COMPONENT24_OES || format == GL_DEPTH24_STENCIL8_OES ||
         (format == GL_DEPTH_COMPONENT && !graphics_->GetShadowMapFormat()))
         (format == GL_DEPTH_COMPONENT && !graphics_->GetShadowMapFormat()))