From d903681b752c3062923c8445b35fea009faece9e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jos=C3=A9=20Fonseca?= Date: Thu, 26 Sep 2013 17:54:52 +0100 Subject: [PATCH] glretrace: Always pass a format appropriate for the internalFormat when reading pixels. Fixes dumping of GL_RGBA8I framebuffers. --- retrace/glstate_images.cpp | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/retrace/glstate_images.cpp b/retrace/glstate_images.cpp index 37c0ae1..549dec7 100644 --- a/retrace/glstate_images.cpp +++ b/retrace/glstate_images.cpp @@ -506,6 +506,10 @@ internalFormatDescs[] = { }; +/** + * Choose the glReadPixels/glGetTexImage format appropriate for the given + * internalFormat. + */ static GLenum getFormat(GLenum internalFormat) { @@ -534,11 +538,11 @@ dumpActiveTextureLevel(JSONWriter &json, Context &context, GLenum target, GLint json.beginMember(label); - GLenum format = getFormat(desc.internalFormat);; + GLenum format = getFormat(desc.internalFormat); if (context.ES && format == GL_DEPTH_COMPONENT) { format = GL_RED; } - GLuint channels = _gl_format_channels(format);; + GLuint channels = _gl_format_channels(format); image::Image *image = new image::Image(desc.width, desc.height*desc.depth, channels, true); @@ -997,6 +1001,7 @@ dumpReadBufferImage(JSONWriter &json, GLint width, GLint height, GLenum format, Context context; GLenum type = GL_UNSIGNED_BYTE; + getFormat(internalFormat); image::ChannelType channelType = image::TYPE_UNORM8; if (format == GL_DEPTH_COMPONENT) { @@ -1189,7 +1194,7 @@ dumpDrawableImages(JSONWriter &json, Context &context) * In the case of a color attachment, it assumes it is already bound for read. */ static void -dumpFramebufferAttachment(JSONWriter &json, Context &context, GLenum target, GLenum attachment, GLenum format) +dumpFramebufferAttachment(JSONWriter &json, Context &context, GLenum target, GLenum attachment, GLenum format = GL_NONE) { ImageDesc desc; if (!getFramebufferAttachmentDesc(context, target, attachment, desc)) { @@ -1198,6 +1203,11 @@ dumpFramebufferAttachment(JSONWriter &json, Context &context, GLenum target, GLe assert(desc.samples == 0); + if (format == GL_NONE) { + assert(desc.internalFormat != GL_NONE); + format = getFormat(desc.internalFormat); + } + json.beginMember(enumToString(attachment)); dumpReadBufferImage(json, desc.width, desc.height, format, desc.internalFormat); json.endMember(); @@ -1230,12 +1240,7 @@ dumpFramebufferAttachments(JSONWriter &json, Context &context, GLenum target) std::cerr << "warning: unexpected GL_DRAW_BUFFER" << i << " = " << draw_buffer << "\n"; attachment = GL_COLOR_ATTACHMENT0; } - GLint alpha_size = 0; - glGetFramebufferAttachmentParameteriv(target, attachment, - GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE, - &alpha_size); - GLenum format = alpha_size ? GL_RGBA : GL_RGB; - dumpFramebufferAttachment(json, context, target, attachment, format); + dumpFramebufferAttachment(json, context, target, attachment); } } -- 2.43.0