From 23c0eb2d61efd66753e97fdce8d4221d0fbf72bd Mon Sep 17 00:00:00 2001 From: baldurk Date: Fri, 14 Apr 2023 14:03:52 +0100 Subject: [PATCH] Ensure pixel pack state doesn't affect GL pixel history --- renderdoc/driver/gl/gl_pixelhistory.cpp | 38 +++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/renderdoc/driver/gl/gl_pixelhistory.cpp b/renderdoc/driver/gl/gl_pixelhistory.cpp index a5364e7cb..d9c3e1076 100644 --- a/renderdoc/driver/gl/gl_pixelhistory.cpp +++ b/renderdoc/driver/gl/gl_pixelhistory.cpp @@ -858,10 +858,42 @@ void readPixelValuesMS(WrappedOpenGL *driver, const GLPixelHistoryResources &res } } +struct ScopedReadPixelsSanitiser +{ + PixelUnpackState unpack; + PixelPackState pack; + GLuint pixelPackBuffer = 0; + GLuint pixelUnpackBuffer = 0; + + ScopedReadPixelsSanitiser() + { + unpack.Fetch(false); + pack.Fetch(false); + + GL.glGetIntegerv(eGL_PIXEL_PACK_BUFFER_BINDING, (GLint *)&pixelPackBuffer); + GL.glGetIntegerv(eGL_PIXEL_UNPACK_BUFFER_BINDING, (GLint *)&pixelUnpackBuffer); + + ResetPixelPackState(false, 1); + ResetPixelUnpackState(false, 1); + GL.glBindBuffer(eGL_PIXEL_PACK_BUFFER, 0); + GL.glBindBuffer(eGL_PIXEL_UNPACK_BUFFER, 0); + } + + ~ScopedReadPixelsSanitiser() + { + unpack.Apply(false); + pack.Apply(false); + GL.glBindBuffer(eGL_PIXEL_PACK_BUFFER, pixelPackBuffer); + GL.glBindBuffer(eGL_PIXEL_UNPACK_BUFFER, pixelUnpackBuffer); + } +}; + void readPixelValues(WrappedOpenGL *driver, const GLPixelHistoryResources &resources, const CopyFramebuffer ©Framebuffer, rdcarray &history, int historyIndex, bool readStencil, uint32_t numPixels, bool isIntegerColour) { + ScopedReadPixelsSanitiser scope; + driver->glBindFramebuffer(eGL_READ_FRAMEBUFFER, copyFramebuffer.framebufferId); rdcarray intColourValues; intColourValues.resize(4 * numPixels); @@ -1180,6 +1212,8 @@ std::map QueryNumFragmentsByEvent( uint32_t numFragments = 0; if(numSamples == 1) { + ScopedReadPixelsSanitiser scope; + ModificationValue modValue; if(colourFormatType == eGL_UNSIGNED_INT || colourFormatType == eGL_INT) { @@ -1465,6 +1499,8 @@ void QueryShaderOutPerFragment(WrappedOpenGL *driver, GLReplay *replay, if(numSamples == 1) { + ScopedReadPixelsSanitiser scope; + ModificationValue modValue; if(colourFormatType == eGL_UNSIGNED_INT || colourFormatType == eGL_INT) @@ -1849,6 +1885,8 @@ void QueryPrimitiveIdPerFragment(WrappedOpenGL *driver, GLReplay *replay, float primitiveIds[8]; if(numSamples == 1) { + ScopedReadPixelsSanitiser scope; + driver->glReadPixels(x, y, 1, 1, eGL_RGBA, eGL_FLOAT, (void *)primitiveIds); } else