Browse Source

On OpenGL ES 2.0, create depth renderbuffers in explicit GL_DEPTH_COMPONENT16 format, as GL_DEPTH_COMPONENT is unsupported on some devices. Possibly a fix for #140.
For better performance, avoid backbuffer resolve to texture on OpenGL ES 2.0 and instead prefer to render into a texture if the viewport contents need to be read.

Lasse Öörni 12 years ago
parent
commit
d723bef62b

+ 1 - 1
Source/Engine/Graphics/OpenGL/OGLGraphics.cpp

@@ -2426,7 +2426,7 @@ unsigned Graphics::GetDepthStencilFormat()
     #ifndef GL_ES_VERSION_2_0
     return GL_DEPTH24_STENCIL8_EXT;
     #else
-    return GL_DEPTH_COMPONENT;
+    return GL_DEPTH_COMPONENT16;
     #endif
 }
 

+ 2 - 2
Source/Engine/Graphics/OpenGL/OGLTexture2D.cpp

@@ -409,7 +409,7 @@ bool Texture2D::Create()
         LOGWARNING("Texture creation while device is lost");
         return true;
     }
-    
+
     unsigned format = GetSRGB() ? GetSRGBFormat(format_) : format_;
     unsigned externalFormat = GetExternalFormat(format_);
     unsigned dataType = GetDataType(format_);
@@ -419,7 +419,7 @@ bool Texture2D::Create()
     #ifndef GL_ES_VERSION_2_0
     if (format == Graphics::GetDepthStencilFormat())
     #else
-    if (!graphics_->GetShadowMapFormat() && externalFormat == GL_DEPTH_COMPONENT)
+    if (format == Graphics::GetDepthStencilFormat() || (!graphics_->GetShadowMapFormat() && externalFormat == GL_DEPTH_COMPONENT))
     #endif
     {
         if (renderSurface_)

+ 9 - 0
Source/Engine/Graphics/View.cpp

@@ -1700,10 +1700,19 @@ void View::AllocateScreenBuffers()
     if (hasViewportRead)
     {
         ++numViewportTextures;
+
+        // If OpenGL ES, use substitute target to avoid resolve from the backbuffer, which may be slow. However if multisampling
+        // is specified, there is no choice
+        #ifdef GL_ES_VERSION_2_0
+        if (!renderTarget_ && graphics_->GetMultiSample() < 2)
+            needSubstitute = true;
+        #endif
+
         // If we have viewport read and target is a cube map, must allocate a substitute target instead as BlitFramebuffer()
         // does not support reading a cube map
         if (renderTarget_ && renderTarget_->GetParentTexture()->GetType() == TextureCube::GetTypeStatic())
             needSubstitute = true;
+
         if (hasPingpong && !needSubstitute)
             ++numViewportTextures;
     }