diff --git a/renderdoc/driver/gl/gl_manager.cpp b/renderdoc/driver/gl/gl_manager.cpp index 777d5de55..8d55303ad 100644 --- a/renderdoc/driver/gl/gl_manager.cpp +++ b/renderdoc/driver/gl/gl_manager.cpp @@ -304,12 +304,12 @@ bool GLResourceManager::Prepare_InitialState(GLResource res, byte *blob) for(int i = 0; i < (int)ARRAY_COUNT(data->Attachments); i++) { FramebufferAttachmentData &a = data->Attachments[i]; + GLenum attachment = FramebufferInitialData::attachmentNames[i]; - gl.glGetNamedFramebufferAttachmentParameterivEXT(res.name, data->attachmentNames[i], - eGL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME, - (GLint *)&object); gl.glGetNamedFramebufferAttachmentParameterivEXT( - res.name, data->attachmentNames[i], eGL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE, (GLint *)&type); + res.name, attachment, eGL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME, (GLint *)&object); + gl.glGetNamedFramebufferAttachmentParameterivEXT( + res.name, attachment, eGL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE, (GLint *)&type); a.renderbuffer = (type == eGL_RENDERBUFFER); @@ -320,13 +320,13 @@ bool GLResourceManager::Prepare_InitialState(GLResource res, byte *blob) if(object && !a.renderbuffer) { gl.glGetNamedFramebufferAttachmentParameterivEXT( - res.name, data->attachmentNames[i], eGL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL, &a.level); + res.name, attachment, eGL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL, &a.level); gl.glGetNamedFramebufferAttachmentParameterivEXT( - res.name, data->attachmentNames[i], eGL_FRAMEBUFFER_ATTACHMENT_LAYERED, &layered); + res.name, attachment, eGL_FRAMEBUFFER_ATTACHMENT_LAYERED, &layered); if(layered == 0) gl.glGetNamedFramebufferAttachmentParameterivEXT( - res.name, data->attachmentNames[i], eGL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER, &a.layer); + res.name, attachment, eGL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER, &a.layer); } a.layered = (layered != 0); @@ -341,8 +341,7 @@ bool GLResourceManager::Prepare_InitialState(GLResource res, byte *blob) { GLenum face; gl.glGetNamedFramebufferAttachmentParameterivEXT( - res.name, data->attachmentNames[i], eGL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE, - (GLint *)&face); + res.name, attachment, eGL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE, (GLint *)&face); a.layer = CubeTargetIndex(face); } @@ -1951,16 +1950,28 @@ void GLResourceManager::Apply_InitialState(GLResource live, InitialContentData i gl.glBindFramebuffer(eGL_DRAW_FRAMEBUFFER, live.name); gl.glBindFramebuffer(eGL_READ_FRAMEBUFFER, live.name); + GLint numCols = 8; + gl.glGetIntegerv(eGL_MAX_COLOR_ATTACHMENTS, &numCols); + for(int i = 0; i < (int)ARRAY_COUNT(data->Attachments); i++) { FramebufferAttachmentData &a = data->Attachments[i]; + GLenum attachment = FramebufferInitialData::attachmentNames[i]; + + if(attachment != eGL_DEPTH_ATTACHMENT && attachment != eGL_STENCIL_ATTACHMENT && + attachment != eGL_DEPTH_STENCIL_ATTACHMENT) + { + // color attachment + int attachNum = attachment - eGL_COLOR_ATTACHMENT0; + if(attachNum >= numCols) // attachment is invalid on this device + continue; + } GLuint obj = a.obj == ResourceId() ? 0 : GetLiveResource(a.obj).name; if(a.renderbuffer && obj) { - gl.glNamedFramebufferRenderbufferEXT(live.name, data->attachmentNames[i], - eGL_RENDERBUFFER, obj); + gl.glNamedFramebufferRenderbufferEXT(live.name, attachment, eGL_RENDERBUFFER, obj); } else { @@ -1982,32 +1993,30 @@ void GLResourceManager::Apply_InitialState(GLResource live, InitialContentData i if(a.layer < 6) { - gl.glFramebufferTexture2D(eGL_DRAW_FRAMEBUFFER, data->attachmentNames[i], - faces[a.layer], obj, a.level); + gl.glFramebufferTexture2D(eGL_DRAW_FRAMEBUFFER, attachment, faces[a.layer], obj, + a.level); } else { RDCWARN("Invalid layer %u used to bind cubemap to framebuffer. Binding POSITIVE_X"); - gl.glFramebufferTexture2D(eGL_DRAW_FRAMEBUFFER, data->attachmentNames[i], faces[0], - obj, a.level); + gl.glFramebufferTexture2D(eGL_DRAW_FRAMEBUFFER, attachment, faces[0], obj, a.level); } } else if(details.curType == eGL_TEXTURE_CUBE_MAP_ARRAY || details.curType == eGL_TEXTURE_1D_ARRAY || details.curType == eGL_TEXTURE_2D_ARRAY) { - gl.glFramebufferTextureLayer(eGL_DRAW_FRAMEBUFFER, data->attachmentNames[i], obj, - a.level, a.layer); + gl.glFramebufferTextureLayer(eGL_DRAW_FRAMEBUFFER, attachment, obj, a.level, a.layer); } else { RDCASSERT(a.layer == 0); - gl.glNamedFramebufferTextureEXT(live.name, data->attachmentNames[i], obj, a.level); + gl.glNamedFramebufferTextureEXT(live.name, attachment, obj, a.level); } } else { - gl.glNamedFramebufferTextureEXT(live.name, data->attachmentNames[i], obj, a.level); + gl.glNamedFramebufferTextureEXT(live.name, attachment, obj, a.level); } } } diff --git a/renderdoc/driver/gl/gl_renderstate.cpp b/renderdoc/driver/gl/gl_renderstate.cpp index 54707bd73..f387ec59c 100644 --- a/renderdoc/driver/gl/gl_renderstate.cpp +++ b/renderdoc/driver/gl/gl_renderstate.cpp @@ -1211,7 +1211,7 @@ void GLRenderState::ApplyState(void *ctx, WrappedOpenGL *gl) { // use sanitised parameters when no image is bound if(Images[i].name == 0) - m_Real->glBindImageTexture(i, 0, 0, GL_FALSE, 0, eGL_READ_ONLY, eGL_R8); + m_Real->glBindImageTexture(i, 0, 0, GL_FALSE, 0, eGL_READ_ONLY, eGL_RGBA8); else m_Real->glBindImageTexture(i, Images[i].name, (GLint)Images[i].level, Images[i].layered, (GLint)Images[i].layer, Images[i].access, Images[i].format); @@ -1344,6 +1344,10 @@ void GLRenderState::ApplyState(void *ctx, WrappedOpenGL *gl) { for(GLuint i = 0; i < RDCMIN(maxDraws, (GLuint)ARRAY_COUNT(Blends)); i++) { + if(Blends[i].EquationRGB == + eGL_NONE) // not set, possibly there were lesser draw buffers during capture + continue; + m_Real->glBlendFuncSeparatei(i, Blends[i].SourceRGB, Blends[i].DestinationRGB, Blends[i].SourceAlpha, Blends[i].DestinationAlpha); m_Real->glBlendEquationSeparatei(i, Blends[i].EquationRGB, Blends[i].EquationAlpha); @@ -1540,7 +1544,7 @@ void GLRenderState::Clear() for(GLuint i = 0; i < (GLuint)ARRAY_COUNT(Images); i++) { Images[i].access = eGL_READ_ONLY; - Images[i].format = eGL_R8; + Images[i].format = eGL_RGBA8; } RDCEraseEl(Program);