diff options
author | bohu <bohu@google.com> | 2014-10-29 09:14:35 -0700 |
---|---|---|
committer | bohu <bohu@google.com> | 2014-11-25 12:31:48 -0800 |
commit | a3a65b66357a72fb347fdb6ff155ca0aba47536b (patch) | |
tree | 148174850bbffaed7f2fe04fc3e71d2e81714099 /emulator | |
parent | 92a73be1a361353e0c3577002e477db68fa00d45 (diff) | |
download | sdk-a3a65b66357a72fb347fdb6ff155ca0aba47536b.zip sdk-a3a65b66357a72fb347fdb6ff155ca0aba47536b.tar.gz sdk-a3a65b66357a72fb347fdb6ff155ca0aba47536b.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 833a4ce..71b29c2 100644 --- a/emulator/opengl/host/libs/Translator/GLES_V2/GLESv2Imp.cpp +++ b/emulator/opengl/host/libs/Translator/GLES_V2/GLESv2Imp.cpp @@ -474,6 +474,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); @@ -482,6 +503,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]); } } } @@ -505,6 +527,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]); } } } @@ -1108,12 +1131,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() || |