From 5e56691dcfcdb00bbbe59caad93b79ced8b2b93d Mon Sep 17 00:00:00 2001 From: Sergey Lipskiy Date: Wed, 10 Jun 2015 23:23:53 +0600 Subject: [PATCH] Fix compilation of depth_compare_shader_float for GL ES 3.1 Note: the shader does not work properly yet on Android --- src/DepthBuffer.cpp | 10 +++++----- src/OGL3X/Shaders_ogl3x.h | 14 ++++++++------ src/OpenGL.cpp | 10 ++++++++++ src/OpenGL.h | 5 +++++ 4 files changed, 28 insertions(+), 11 deletions(-) diff --git a/src/DepthBuffer.cpp b/src/DepthBuffer.cpp index 57727408..fec8c79e 100644 --- a/src/DepthBuffer.cpp +++ b/src/DepthBuffer.cpp @@ -74,11 +74,11 @@ void DepthBuffer::initDepthImageTexture(FrameBuffer * _pBuffer) m_pDepthImageTexture->mirrorT = 0; m_pDepthImageTexture->realWidth = m_pDepthImageTexture->width; m_pDepthImageTexture->realHeight = m_pDepthImageTexture->height; - m_pDepthImageTexture->textureBytes = m_pDepthImageTexture->realWidth * m_pDepthImageTexture->realHeight * 2 * sizeof(float); // Width*Height*RG*sizeof(GL_RGBA32F) + m_pDepthImageTexture->textureBytes = m_pDepthImageTexture->realWidth * m_pDepthImageTexture->realHeight * fboFormats.depthImageFormatBytes; textureCache().addFrameBufferTextureSize(m_pDepthImageTexture->textureBytes); glBindTexture(GL_TEXTURE_2D, m_pDepthImageTexture->glName); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RG32F, m_pDepthImageTexture->realWidth, m_pDepthImageTexture->realHeight, 0, GL_RG, GL_FLOAT, NULL); + glTexImage2D(GL_TEXTURE_2D, 0, fboFormats.depthImageInternalFormat, m_pDepthImageTexture->realWidth, m_pDepthImageTexture->realHeight, 0, fboFormats.depthImageFormat, fboFormats.depthImageType, NULL); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glBindTexture(GL_TEXTURE_2D, 0); @@ -218,7 +218,7 @@ void DepthBuffer::activateDepthBufferTexture(FrameBuffer * _pBuffer) void DepthBuffer::bindDepthImageTexture() { #ifdef GL_IMAGE_TEXTURES_SUPPORT - glBindImageTexture(depthImageUnit, m_pDepthImageTexture->glName, 0, GL_FALSE, 0, GL_READ_WRITE, GL_RG32F); + glBindImageTexture(depthImageUnit, m_pDepthImageTexture->glName, 0, GL_FALSE, 0, GL_READ_WRITE, fboFormats.depthImageInternalFormat); #endif } @@ -335,13 +335,13 @@ void DepthBufferList::clearBuffer(u32 _uly, u32 _lry) if (m_pCurrent->m_FBO == 0 || !video().getRender().isImageTexturesSupported() || config.frameBufferEmulation.N64DepthCompare == 0) return; float color[4] = {1.0f, 1.0f, 0.0f, 1.0f}; - glBindImageTexture(depthImageUnit, 0, 0, GL_FALSE, 0, GL_READ_WRITE, GL_RG32F); + glBindImageTexture(depthImageUnit, 0, 0, GL_FALSE, 0, GL_READ_WRITE, fboFormats.depthImageInternalFormat); glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_pCurrent->m_FBO); const u32 cycleType = gDP.otherMode.cycleType; gDP.otherMode.cycleType = G_CYC_FILL; video().getRender().drawRect(0,0,VI.width, VI.height, color); gDP.otherMode.cycleType = cycleType; - glBindImageTexture(depthImageUnit, m_pCurrent->m_pDepthImageTexture->glName, 0, GL_FALSE, 0, GL_READ_WRITE, GL_RG32F); + glBindImageTexture(depthImageUnit, m_pCurrent->m_pDepthImageTexture->glName, 0, GL_FALSE, 0, GL_READ_WRITE, fboFormats.depthImageInternalFormat); glBindFramebuffer(GL_DRAW_FRAMEBUFFER, frameBufferList().getCurrent()->m_FBO); #endif // GL_IMAGE_TEXTURES_SUPPORT } diff --git a/src/OGL3X/Shaders_ogl3x.h b/src/OGL3X/Shaders_ogl3x.h index c1a98534..65e9543e 100644 --- a/src/OGL3X/Shaders_ogl3x.h +++ b/src/OGL3X/Shaders_ogl3x.h @@ -499,6 +499,9 @@ static const char* fragment_shader_dummy_noise = static const char* depth_compare_shader_float = #ifndef GLESX "#version 430 \n" +"layout(binding = 2, rg32f) uniform coherent image2D uDepthImage;\n" +#else +"layout(binding = 2, rgba32f) highp uniform coherent image2D uDepthImage;\n" #endif //"uniform int uEnableDepth; \n" "uniform lowp int uDepthMode; \n" @@ -506,7 +509,6 @@ static const char* depth_compare_shader_float = "uniform lowp int uEnableDepthCompare; \n" "uniform lowp int uEnableDepthUpdate; \n" "uniform mediump float uDeltaZ; \n" -"layout(binding = 2, rg32f) uniform coherent image2D uDepthImage;\n" "bool depth_compare() \n" "{ \n" //" if (uEnableDepth == 0) return true; \n" @@ -521,10 +523,10 @@ static const char* depth_compare_shader_float = " dz = 4.0*fwidth(gl_FragDepth); \n" " dzMin = min(dz, depth.g); \n" " } \n" -" const bool bInfront = curZ < bufZ; \n" -" const bool bFarther = (curZ + dzMin) >= bufZ; \n" -" const bool bNearer = (curZ - dzMin) <= bufZ; \n" -" const bool bMax = bufZ == 1.0; \n" +" bool bInfront = curZ < bufZ; \n" +" bool bFarther = (curZ + dzMin) >= bufZ; \n" +" bool bNearer = (curZ - dzMin) <= bufZ; \n" +" bool bMax = bufZ == 1.0; \n" " bool bRes; \n" " switch (uDepthMode) { \n" " case 1: \n" @@ -576,7 +578,7 @@ MAIN_SHADER_VERSION " highp float n64z = clamp(float(iN64z)/65532.0, 0.0, 1.0);\n" " highp int index = min(255, int(n64z*255.0)); \n" " highp uint iAlpha = imageLoad(uTlutImage,ivec2(index,0)).r;\n" -" return float(iAlpha/uint(256))/255.0; \n" +" return float(iAlpha>>8)/255.0; \n" "} \n" "void main() \n" "{ \n" diff --git a/src/OpenGL.cpp b/src/OpenGL.cpp index 2c24b0d4..30239db2 100644 --- a/src/OpenGL.cpp +++ b/src/OpenGL.cpp @@ -1186,6 +1186,11 @@ void FBOTextureFormats::init() depthType = GL_FLOAT; depthFormatBytes = 4; + depthImageInternalFormat = GL_RGBA32F; + depthImageFormat = GL_RGBA; + depthImageType = GL_FLOAT; + depthImageFormatBytes = 16; + lutInternalFormat = GL_R32UI; lutFormat = GL_RED; lutType = GL_UNSIGNED_INT; @@ -1206,6 +1211,11 @@ void FBOTextureFormats::init() depthType = GL_FLOAT; depthFormatBytes = 4; + depthImageInternalFormat = GL_RG32F; + depthImageFormat = GL_RG; + depthImageType = GL_FLOAT; + depthImageFormatBytes = 8; + lutInternalFormat = GL_R16; lutFormat = GL_RED; lutType = GL_UNSIGNED_SHORT; diff --git a/src/OpenGL.h b/src/OpenGL.h index 0d433911..eb8153a9 100644 --- a/src/OpenGL.h +++ b/src/OpenGL.h @@ -236,6 +236,11 @@ struct FBOTextureFormats GLenum depthType; u32 depthFormatBytes; + GLint depthImageInternalFormat; + GLenum depthImageFormat; + GLenum depthImageType; + u32 depthImageFormatBytes; + GLint lutInternalFormat; GLenum lutFormat; GLenum lutType;