diff --git a/cocos/2d/CCRenderTexture.cpp b/cocos/2d/CCRenderTexture.cpp index d5eb3d87f5..3ba783cc51 100644 --- a/cocos/2d/CCRenderTexture.cpp +++ b/cocos/2d/CCRenderTexture.cpp @@ -260,13 +260,9 @@ bool RenderTexture::initWithWidthAndHeight(int w, int h, Texture2D::PixelFormat if (depthStencilFormat != 0) { - - const char* extString = (const char*)glGetString(GL_EXTENSIONS); - bool hasGL_OES_packed_depth_stencil = (strstr(extString, "GL_OES_packed_depth_stencil") != 0); - bool hasGL_OES_depth24 = (strstr(extString, "GL_OES_depth24") != 0); - - - if(hasGL_OES_packed_depth_stencil==true) + +#if(CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) + if(Configuration::getInstance()->supportsOESPackedDepthStencil()) { //create and attach depth buffer glGenRenderbuffers(1, &_depthRenderBufffer); @@ -282,11 +278,12 @@ bool RenderTexture::initWithWidthAndHeight(int w, int h, Texture2D::PixelFormat } else { + glGenRenderbuffers(1, &_depthRenderBufffer); glGenRenderbuffers(1, &_stencilRenderBufffer); glBindRenderbuffer(GL_RENDERBUFFER, _depthRenderBufffer); - if(hasGL_OES_depth24) + if(Configuration::getInstance()->supportsOESPackedDepthStencil()) { glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24_OES, (GLsizei)powW, (GLsizei)powH); } @@ -301,8 +298,23 @@ bool RenderTexture::initWithWidthAndHeight(int w, int h, Texture2D::PixelFormat glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, _depthRenderBufffer); glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, _stencilRenderBufffer); - } +#else + + //create and attach depth buffer + glGenRenderbuffers(1, &_depthRenderBufffer); + glBindRenderbuffer(GL_RENDERBUFFER, _depthRenderBufffer); + glRenderbufferStorage(GL_RENDERBUFFER, depthStencilFormat, (GLsizei)powW, (GLsizei)powH); + glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, _depthRenderBufffer); + + // if depth format is the one with stencil part, bind same render buffer as stencil attachment + if (depthStencilFormat == GL_DEPTH24_STENCIL8) + { + glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, _depthRenderBufffer); + } + +#endif + } // check if it worked (probably worth doing :) ) diff --git a/cocos/base/CCConfiguration.cpp b/cocos/base/CCConfiguration.cpp index 654100433b..b56665ed14 100644 --- a/cocos/base/CCConfiguration.cpp +++ b/cocos/base/CCConfiguration.cpp @@ -49,6 +49,8 @@ Configuration::Configuration() , _supportsBGRA8888(false) , _supportsDiscardFramebuffer(false) , _supportsShareableVAO(false) +, _supportsOESDepth24(false) +, _supportsOESPackedDepthStencil(false) , _maxSamplesAllowed(0) , _maxTextureUnits(0) , _glExtensions(nullptr) @@ -149,6 +151,14 @@ void Configuration::gatherGPUInfo() _supportsShareableVAO = checkForGLExtension("vertex_array_object"); _valueDict["gl.supports_vertex_array_object"] = Value(_supportsShareableVAO); + + _supportsOESDepth24 = checkForGLExtension("GL_OES_depth24"); + _valueDict["gl.supports_OES_depth24"] = Value(_supportsOESDepth24); + + + _supportsOESPackedDepthStencil = checkForGLExtension("GL_OES_packed_depth_stencil"); + _valueDict["gl.supports_OES_packed_depth_stencil"] = Value(_supportsOESPackedDepthStencil); + CHECK_GL_ERROR_DEBUG(); } @@ -259,6 +269,19 @@ bool Configuration::supportsShareableVAO() const #endif } + +bool supportsOESDepth24() const +{ + return _supportsOESDepth24; + +} +bool supportsOESPackedDepthStencil() const +{ + return _supportsOESPackedDepthStencil; +} + + + int Configuration::getMaxSupportDirLightInShader() const { return _maxDirLightInShader; diff --git a/cocos/base/CCConfiguration.h b/cocos/base/CCConfiguration.h index 3c49a17807..9bf2348498 100644 --- a/cocos/base/CCConfiguration.h +++ b/cocos/base/CCConfiguration.h @@ -145,6 +145,22 @@ public: * @since v2.0.0 */ bool supportsShareableVAO() const; + + /** Whether or not OES_depth24 is supported. + * + * @return Is true if supports OES_depth24. + * @since v2.0.0 + */ + bool supportsOESDepth24() const; + + /** Whether or not OES_Packed_depth_stencil is supported. + * + * @return Is true if supports OES_Packed_depth_stencil. + * @since v2.0.0 + */ + bool supportsOESPackedDepthStencil() const; + + /** Max support directional light in shader, for Sprite3D. * @@ -232,6 +248,9 @@ protected: bool _supportsBGRA8888; bool _supportsDiscardFramebuffer; bool _supportsShareableVAO; + bool _supportsOESDepth24; + bool _supportsOESPackedDepthStencil; + GLint _maxSamplesAllowed; GLint _maxTextureUnits; char * _glExtensions;