From aa90e6848f3200433cabc3fea2c87df0b1f767c5 Mon Sep 17 00:00:00 2001 From: Dries Harnie Date: Mon, 21 Apr 2014 11:45:26 +0200 Subject: [PATCH] GRAPHICS: Only use packed depth-stencil framebuffer if extensions allow it --- graphics/opengles2/framebuffer.cpp | 39 +++++++++++++++++++++++------ graphics/opengles2/framebuffer.h | 2 +- graphics/opengles2/system_headers.h | 2 -- 3 files changed, 32 insertions(+), 11 deletions(-) diff --git a/graphics/opengles2/framebuffer.cpp b/graphics/opengles2/framebuffer.cpp index 3f257bb7fad..561abeb0549 100644 --- a/graphics/opengles2/framebuffer.cpp +++ b/graphics/opengles2/framebuffer.cpp @@ -25,21 +25,44 @@ #if defined(USE_GLES2) || defined(USE_OPENGL_SHADERS) #include "graphics/opengles2/framebuffer.h" +#include "graphics/opengles2/extensions.h" + +#ifdef USE_GLES2 +#define GL_DEPTH24_STENCIL8 GL_DEPTH24_STENCIL8_OES +#endif namespace Graphics { +static bool usePackedBuffer() { +#ifdef USE_GLES2 + return Graphics::isExtensionSupported("GL_OES_packed_depth_stencil"); +#endif + return true; +} + FrameBuffer::FrameBuffer(GLuint texture_name, uint width, uint height, uint texture_width, uint texture_height) : _colorTexture(texture_name), _width(width), _height(height) { glGenFramebuffers(1, &_frameBuffer); - glGenRenderbuffers(1, &_depthRenderBuffer); - - glBindRenderbuffer(GL_RENDERBUFFER, _depthRenderBuffer); - glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, texture_width, texture_height); - glBindRenderbuffer(GL_RENDERBUFFER, 0); + glGenRenderbuffers(2, &_renderBuffers[0]); glBindFramebuffer(GL_FRAMEBUFFER, _frameBuffer); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture_name, 0); - glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, _depthRenderBuffer); - glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, _depthRenderBuffer); + +if (usePackedBuffer()) { + glBindRenderbuffer(GL_RENDERBUFFER, _renderBuffers[0]); + glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, texture_width, texture_height); + glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, _renderBuffers[0]); + glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, _renderBuffers[0]); + glBindRenderbuffer(GL_RENDERBUFFER, 0); +} else { + glBindRenderbuffer(GL_RENDERBUFFER, _renderBuffers[0]); + glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, texture_width, texture_height); + glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, _renderBuffers[0]); + + glBindRenderbuffer(GL_RENDERBUFFER, _renderBuffers[1]); + glRenderbufferStorage(GL_RENDERBUFFER, GL_STENCIL_INDEX8, texture_width, texture_height); + glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, _renderBuffers[1]); + glBindRenderbuffer(GL_RENDERBUFFER, 0); +} glBindFramebuffer(GL_FRAMEBUFFER, _frameBuffer); GLenum status=glCheckFramebufferStatus(GL_FRAMEBUFFER); @@ -51,7 +74,7 @@ FrameBuffer::FrameBuffer(GLuint texture_name, uint width, uint height, uint text } FrameBuffer::~FrameBuffer() { - glDeleteRenderbuffers(1, &_depthRenderBuffer); + glDeleteRenderbuffers(2, &_renderBuffers[0]); glDeleteFramebuffers(1, &_frameBuffer); } diff --git a/graphics/opengles2/framebuffer.h b/graphics/opengles2/framebuffer.h index 45b1d5e406a..965d65da3f5 100644 --- a/graphics/opengles2/framebuffer.h +++ b/graphics/opengles2/framebuffer.h @@ -39,7 +39,7 @@ public: private: GLuint _colorTexture; - GLuint _depthRenderBuffer; + GLuint _renderBuffers[2]; GLuint _frameBuffer; uint _width, _height; }; diff --git a/graphics/opengles2/system_headers.h b/graphics/opengles2/system_headers.h index 45f0da2c76d..95d6a25ff65 100644 --- a/graphics/opengles2/system_headers.h +++ b/graphics/opengles2/system_headers.h @@ -37,8 +37,6 @@ #endif #undef GL_GLEXT_PROTOTYPES -#define GL_DEPTH24_STENCIL8 GL_DEPTH24_STENCIL8_OES - #ifndef GL_BGRA # define GL_BGRA GL_BGRA_EXT #endif