diff options
author | bohu <bohu@google.com> | 2014-10-29 09:14:35 -0700 |
---|---|---|
committer | bohu <bohu@google.com> | 2014-10-29 09:14:35 -0700 |
commit | 7748c5f71a17c51ede5ed77a17bdad14445e20d2 (patch) | |
tree | d7b66cebd8c3af74f964d9923d92c719c7ac1e3e /emulator | |
parent | cf7e8c7948b3b811a6693ac871d2578a2bdf0a46 (diff) | |
download | sdk-7748c5f71a17c51ede5ed77a17bdad14445e20d2.zip sdk-7748c5f71a17c51ede5ed77a17bdad14445e20d2.tar.gz sdk-7748c5f71a17c51ede5ed77a17bdad14445e20d2.tar.bz2 |
Detach texture or renderbuffer when deleting them
When a texture or renderbuffer is still attached to framebuffer but
is getting deleted, it should also be detached from framebuffer.
Change-Id: Ide2c2a0e36ca8bf58f9351a17b78b76ebd507c12
Diffstat (limited to 'emulator')
-rw-r--r-- | emulator/opengl/host/libs/Translator/GLES_V2/GLESv2Imp.cpp | 25 | ||||
-rw-r--r-- | emulator/opengl/host/libs/Translator/GLcommon/FramebufferData.cpp | 5 |
2 files changed, 29 insertions, 1 deletions
diff --git a/emulator/opengl/host/libs/Translator/GLES_V2/GLESv2Imp.cpp b/emulator/opengl/host/libs/Translator/GLES_V2/GLESv2Imp.cpp index fe64f6f..e245390 100644 --- a/emulator/opengl/host/libs/Translator/GLES_V2/GLESv2Imp.cpp +++ b/emulator/opengl/host/libs/Translator/GLES_V2/GLESv2Imp.cpp @@ -452,6 +452,27 @@ GL_APICALL void GL_APIENTRY glDeleteFramebuffers(GLsizei n, const GLuint* frame } } +static void s_detachFromFramebuffer(GLuint bufferType, GLuint texture) { + GET_CTX(); + GLuint fbName = ctx->getFramebufferBinding(); + if (!fbName) return; + ObjectDataPtr fbObj = ctx->shareGroup()->getObjectData(FRAMEBUFFER,fbName); + if (fbObj.Ptr() == NULL) return; + FramebufferData *fbData = (FramebufferData *)fbObj.Ptr(); + GLenum target; + const GLenum kAttachments[] = {GL_COLOR_ATTACHMENT0, GL_DEPTH_ATTACHMENT, GL_STENCIL_ATTACHMENT}; + const size_t sizen = sizeof(kAttachments)/sizeof(GLenum); + for (size_t i = 0; i < sizen; ++i ) { + GLuint name = fbData->getAttachment(kAttachments[i], &target, NULL); + if (name != texture) continue; + if (TEXTURE == bufferType && GLESv2Validate::textureTargetEx(target)) { + glFramebufferTexture2D(GL_FRAMEBUFFER, kAttachments[i], target, 0, 0); + } else if (RENDERBUFFER == bufferType && GLESv2Validate::renderbufferTarget(target)) { + glFramebufferRenderbuffer(GL_FRAMEBUFFER, kAttachments[i], target, 0); + } + } +} + GL_APICALL void GL_APIENTRY glDeleteRenderbuffers(GLsizei n, const GLuint* renderbuffers){ GET_CTX(); SET_ERROR_IF(n<0,GL_INVALID_VALUE); @@ -460,6 +481,7 @@ GL_APICALL void GL_APIENTRY glDeleteRenderbuffers(GLsizei n, const GLuint* rend const GLuint globalRenderBufferName = ctx->shareGroup()->getGlobalName(RENDERBUFFER,renderbuffers[i]); ctx->shareGroup()->deleteName(RENDERBUFFER,renderbuffers[i]); ctx->dispatcher().glDeleteRenderbuffersEXT(1,&globalRenderBufferName); + s_detachFromFramebuffer(RENDERBUFFER, renderbuffers[i]); } } } @@ -483,6 +505,7 @@ GL_APICALL void GL_APIENTRY glDeleteTextures(GLsizei n, const GLuint* textures) ctx->setBindedTexture(GL_TEXTURE_2D,0); if (ctx->getBindedTexture(GL_TEXTURE_CUBE_MAP) == textures[i]) ctx->setBindedTexture(GL_TEXTURE_CUBE_MAP,0); + s_detachFromFramebuffer(TEXTURE, textures[i]); } } } @@ -1052,12 +1075,14 @@ GL_APICALL void GL_APIENTRY glGetFramebufferAttachmentParameteriv(GLenum target // Take the attachment attribute from our state - if available // GLuint fbName = ctx->getFramebufferBinding(); + SET_ERROR_IF (!fbName, GL_INVALID_OPERATION); if (fbName) { ObjectDataPtr fbObj = ctx->shareGroup()->getObjectData(FRAMEBUFFER,fbName); if (fbObj.Ptr() != NULL) { FramebufferData *fbData = (FramebufferData *)fbObj.Ptr(); GLenum target; GLuint name = fbData->getAttachment(attachment, &target, NULL); + SET_ERROR_IF(!name && pname != GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE, GL_INVALID_ENUM); if (pname == GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE) { if (target == GL_TEXTURE_2D) { *params = GL_TEXTURE; diff --git a/emulator/opengl/host/libs/Translator/GLcommon/FramebufferData.cpp b/emulator/opengl/host/libs/Translator/GLcommon/FramebufferData.cpp index c923bfc..2e35c8d 100644 --- a/emulator/opengl/host/libs/Translator/GLcommon/FramebufferData.cpp +++ b/emulator/opengl/host/libs/Translator/GLcommon/FramebufferData.cpp @@ -52,7 +52,10 @@ void FramebufferData::setAttachment(GLenum attachment, ObjectDataPtr obj, bool takeOwnership) { int idx = attachmentPointIndex(attachment); - + if (!name) { + detachObject(idx); + return; + } if (m_attachPoints[idx].target != target || m_attachPoints[idx].name != name || m_attachPoints[idx].obj.Ptr() != obj.Ptr() || |