diff --git a/renderdoc/driver/gl/gl_renderstate.cpp b/renderdoc/driver/gl/gl_renderstate.cpp index e046d8acd..c655047ec 100644 --- a/renderdoc/driver/gl/gl_renderstate.cpp +++ b/renderdoc/driver/gl/gl_renderstate.cpp @@ -83,7 +83,43 @@ bool PixelUnpackState::FastPath(GLsizei width, GLsizei height, GLsizei depth, GL if(height > 0 && imageheight > 0 && height < imageheight) return false; - if(dataformat != eGL_NONE && alignment > (int32_t)GetByteSize(1, 1, 1, dataformat, basetype)) + if(alignment > (int32_t)GetByteSize(1, 1, 1, dataformat, basetype)) + return false; + + return true; +} + +bool PixelUnpackState::FastPathCompressed(GLsizei width, GLsizei height, GLsizei depth) +{ + // compressedBlockSize and compressedBlockWidth must be set for any of the unpack params to be used + // if they are 0, all of the unpack params are ignored, so we go through the fast path (no unpacking) + if(compressedBlockSize == 0 || compressedBlockWidth == 0) + return true; + + if(skipPixels) + return false; + + if(width > 0 && rowlength > 0 && width < rowlength) + return false; + + // the below two unpack params require compressedBlockHeight to be set so if we haven't "failed" to + // hit the fast path, none of the other params make a difference as they're ignored and we go through + // the fast path (no unpacking) + if(compressedBlockHeight == 0) + return true; + + if(height > 0 && skipRows) + return false; + + if(height > 0 && imageheight > 0 && height < imageheight) + return false; + + // the final unpack param requires compressedBlockDepth to be set, as above if it's 0 then we can + // just go straight through the fast path (no unpacking) + if(compressedBlockDepth == 0) + return true; + + if(depth > 0 && skipImages) return false; return true; diff --git a/renderdoc/driver/gl/gl_renderstate.h b/renderdoc/driver/gl/gl_renderstate.h index abc473885..d8448bd9d 100644 --- a/renderdoc/driver/gl/gl_renderstate.h +++ b/renderdoc/driver/gl/gl_renderstate.h @@ -44,7 +44,9 @@ struct PixelUnpackState void Fetch(const GLHookSet *funcs, bool compressed); void Apply(const GLHookSet *funcs, bool compressed); - bool FastPath(GLsizei width, GLsizei height, GLsizei depth, GLenum dataformat=eGL_NONE, GLenum basetype=eGL_NONE); + bool FastPath(GLsizei width, GLsizei height, GLsizei depth, GLenum dataformat, GLenum basetype); + bool FastPathCompressed(GLsizei width, GLsizei height, GLsizei depth); + byte *Unpack(byte *pixels, GLsizei width, GLsizei height, GLsizei depth, GLenum dataformat, GLenum basetype); byte *UnpackCompressed(byte *pixels, GLsizei width, GLsizei height, GLsizei depth, GLsizei &imageSize); }; diff --git a/renderdoc/driver/gl/wrappers/gl_texture_funcs.cpp b/renderdoc/driver/gl/wrappers/gl_texture_funcs.cpp index 77f13042a..5009297d0 100644 --- a/renderdoc/driver/gl/wrappers/gl_texture_funcs.cpp +++ b/renderdoc/driver/gl/wrappers/gl_texture_funcs.cpp @@ -2039,7 +2039,7 @@ bool WrappedOpenGL::Serialise_glCompressedTextureImage1DEXT(GLuint texture, GLen { PixelUnpackState unpack; unpack.Fetch(&m_Real, true); - if(unpack.FastPath(Width, 0, 0)) + if(unpack.FastPathCompressed(Width, 0, 0)) srcPixels = (byte *)pixels; else srcPixels = unpackedPixels = unpack.UnpackCompressed((byte *)pixels, Width, 0, 0, imageSize); @@ -2199,7 +2199,7 @@ bool WrappedOpenGL::Serialise_glCompressedTextureImage2DEXT(GLuint texture, GLen { PixelUnpackState unpack; unpack.Fetch(&m_Real, true); - if(unpack.FastPath(Width, Height, 0)) + if(unpack.FastPathCompressed(Width, Height, 0)) srcPixels = (byte *)pixels; else srcPixels = unpackedPixels = unpack.UnpackCompressed((byte *)pixels, Width, Height, 0, imageSize); @@ -2383,7 +2383,7 @@ bool WrappedOpenGL::Serialise_glCompressedTextureImage3DEXT(GLuint texture, GLen { PixelUnpackState unpack; unpack.Fetch(&m_Real, true); - if(unpack.FastPath(Width, Height, Depth)) + if(unpack.FastPathCompressed(Width, Height, Depth)) srcPixels = (byte *)pixels; else srcPixels = unpackedPixels = unpack.UnpackCompressed((byte *)pixels, Width, Height, Depth, imageSize); @@ -3689,7 +3689,7 @@ bool WrappedOpenGL::Serialise_glCompressedTextureSubImage1DEXT(GLuint texture, G { PixelUnpackState unpack; unpack.Fetch(&m_Real, true); - if(unpack.FastPath(Width, 0, 0)) + if(unpack.FastPathCompressed(Width, 0, 0)) srcPixels = (byte *)pixels; else srcPixels = unpackedPixels = unpack.UnpackCompressed((byte *)pixels, Width, 0, 0, imageSize); @@ -3817,7 +3817,7 @@ bool WrappedOpenGL::Serialise_glCompressedTextureSubImage2DEXT(GLuint texture, G { PixelUnpackState unpack; unpack.Fetch(&m_Real, true); - if(unpack.FastPath(Width, Height, 0)) + if(unpack.FastPathCompressed(Width, Height, 0)) srcPixels = (byte *)pixels; else srcPixels = unpackedPixels = unpack.UnpackCompressed((byte *)pixels, Width, Height, 0, imageSize); @@ -3947,7 +3947,7 @@ bool WrappedOpenGL::Serialise_glCompressedTextureSubImage3DEXT(GLuint texture, G { PixelUnpackState unpack; unpack.Fetch(&m_Real, true); - if(unpack.FastPath(Width, Height, Depth)) + if(unpack.FastPathCompressed(Width, Height, Depth)) srcPixels = (byte *)pixels; else srcPixels = unpackedPixels = unpack.UnpackCompressed((byte *)pixels, Width, Height, Depth, imageSize);