From f160c28d166b356b423faff52336609cc1dc9e0d Mon Sep 17 00:00:00 2001 From: baldurk Date: Thu, 26 Feb 2015 15:41:47 +0000 Subject: [PATCH] Fix GL PickPixel to be able to read back depth & stencil in two passes * GL doesn't seem to support reading both depth and stencil channels from a single texture, so we need to do a second pass to read back the stencil component --- renderdoc/driver/gl/gl_debug.cpp | 55 +++++++++++++++++++++----------- 1 file changed, 36 insertions(+), 19 deletions(-) diff --git a/renderdoc/driver/gl/gl_debug.cpp b/renderdoc/driver/gl/gl_debug.cpp index ad47470c1..25efac2c4 100644 --- a/renderdoc/driver/gl/gl_debug.cpp +++ b/renderdoc/driver/gl/gl_debug.cpp @@ -950,29 +950,46 @@ void GLReplay::PickPixel(ResourceId texture, uint32_t x, uint32_t y, uint32_t sl DebugData.outWidth = DebugData.outHeight = 1.0f; gl.glViewport(0, 0, 1, 1); - { - TextureDisplay texDisplay; + TextureDisplay texDisplay; - texDisplay.Red = texDisplay.Green = texDisplay.Blue = texDisplay.Alpha = true; - texDisplay.FlipY = false; - texDisplay.HDRMul = -1.0f; - texDisplay.linearDisplayAsGamma = true; - texDisplay.mip = mip; - texDisplay.sampleIdx = sample; - texDisplay.CustomShader = ResourceId(); - texDisplay.sliceFace = sliceFace; - texDisplay.rangemin = 0.0f; - texDisplay.rangemax = 1.0f; - texDisplay.scale = 1.0f; - texDisplay.texid = texture; - texDisplay.rawoutput = true; - texDisplay.offx = -float(x); - texDisplay.offy = -float(y); + texDisplay.Red = texDisplay.Green = texDisplay.Blue = texDisplay.Alpha = true; + texDisplay.FlipY = false; + texDisplay.HDRMul = -1.0f; + texDisplay.linearDisplayAsGamma = true; + texDisplay.mip = mip; + texDisplay.sampleIdx = sample; + texDisplay.CustomShader = ResourceId(); + texDisplay.sliceFace = sliceFace; + texDisplay.rangemin = 0.0f; + texDisplay.rangemax = 1.0f; + texDisplay.scale = 1.0f; + texDisplay.texid = texture; + texDisplay.rawoutput = true; + texDisplay.offx = -float(x); + texDisplay.offy = -float(y); - RenderTextureInternal(texDisplay, false); - } + RenderTextureInternal(texDisplay, false); gl.glReadPixels(0, 0, 1, 1, eGL_RGBA, eGL_FLOAT, (void *)pixel); + + { + auto &texDetails = m_pDriver->m_Textures[texture]; + + // need to read stencil separately as GL can't read both depth and stencil + // at the same time. + if(texDetails.internalFormat == eGL_DEPTH24_STENCIL8 || + texDetails.internalFormat == eGL_DEPTH32F_STENCIL8) + { + texDisplay.Red = texDisplay.Blue = texDisplay.Alpha = false; + + RenderTextureInternal(texDisplay, false); + + uint32_t stencilpixel[4]; + gl.glReadPixels(0, 0, 1, 1, eGL_RGBA, eGL_FLOAT, (void *)stencilpixel); + + pixel[1] = float(stencilpixel[1])/255.0f; + } + } } void GLReplay::CopyTex2DMSToArray(GLuint destArray, GLuint srcMS, GLint width, GLint height, GLint arraySize, GLint samples, GLenum intFormat)