From 7d61fe130134455d298fbadad676bef854b2dabe Mon Sep 17 00:00:00 2001 From: Jeff Gilbert Date: Thu, 13 Feb 2014 15:08:08 -0800 Subject: [PATCH] Bug 970775 - Fix error gen'd by CopyTex(Sub)Image2D for incomplete FBs. - r=bjacob --- content/canvas/src/WebGLContextGL.cpp | 44 +++++++++++++-------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/content/canvas/src/WebGLContextGL.cpp b/content/canvas/src/WebGLContextGL.cpp index f1e416d2450..62cfae0db84 100644 --- a/content/canvas/src/WebGLContextGL.cpp +++ b/content/canvas/src/WebGLContextGL.cpp @@ -530,6 +530,18 @@ WebGLContext::CopyTexImage2D(GLenum target, return ErrorInvalidValue("copyTexImage2D: with level > 0, width and height must be powers of two"); } + if (internalformat == LOCAL_GL_DEPTH_COMPONENT || + internalformat == LOCAL_GL_DEPTH_STENCIL) + return ErrorInvalidOperation("copyTexImage2D: a base internal format of DEPTH_COMPONENT or DEPTH_STENCIL isn't supported"); + + WebGLTexture *tex = activeBoundTextureForTarget(target); + if (!tex) + return ErrorInvalidOperation("copyTexImage2D: no texture bound to this target"); + + if (mBoundFramebuffer) + if (!mBoundFramebuffer->CheckAndInitializeAttachments()) + return ErrorInvalidFramebufferOperation("copyTexImage2D: incomplete framebuffer"); + bool texFormatRequiresAlpha = internalformat == LOCAL_GL_RGBA || internalformat == LOCAL_GL_ALPHA || internalformat == LOCAL_GL_LUMINANCE_ALPHA; @@ -539,18 +551,6 @@ WebGLContext::CopyTexImage2D(GLenum target, return ErrorInvalidOperation("copyTexImage2D: texture format requires an alpha channel " "but the framebuffer doesn't have one"); - if (internalformat == LOCAL_GL_DEPTH_COMPONENT || - internalformat == LOCAL_GL_DEPTH_STENCIL) - return ErrorInvalidOperation("copyTexImage2D: a base internal format of DEPTH_COMPONENT or DEPTH_STENCIL isn't supported"); - - if (mBoundFramebuffer) - if (!mBoundFramebuffer->CheckAndInitializeAttachments()) - return ErrorInvalidFramebufferOperation("copyTexImage2D: incomplete framebuffer"); - - WebGLTexture *tex = activeBoundTextureForTarget(target); - if (!tex) - return ErrorInvalidOperation("copyTexImage2D: no texture bound to this target"); - // copyTexImage2D only generates textures with type = UNSIGNED_BYTE GLenum type = LOCAL_GL_UNSIGNED_BYTE; @@ -639,16 +639,6 @@ WebGLContext::CopyTexSubImage2D(GLenum target, return ErrorInvalidValue("copyTexSubImage2D: yoffset+height is too large"); GLenum internalFormat = imageInfo.InternalFormat(); - bool texFormatRequiresAlpha = (internalFormat == LOCAL_GL_RGBA || - internalFormat == LOCAL_GL_ALPHA || - internalFormat == LOCAL_GL_LUMINANCE_ALPHA); - bool fboFormatHasAlpha = mBoundFramebuffer ? mBoundFramebuffer->ColorAttachment(0).HasAlpha() - : bool(gl->GetPixelFormat().alpha > 0); - - if (texFormatRequiresAlpha && !fboFormatHasAlpha) - return ErrorInvalidOperation("copyTexSubImage2D: texture format requires an alpha channel " - "but the framebuffer doesn't have one"); - if (IsGLDepthFormat(internalFormat) || IsGLDepthStencilFormat(internalFormat)) { @@ -659,6 +649,16 @@ WebGLContext::CopyTexSubImage2D(GLenum target, if (!mBoundFramebuffer->CheckAndInitializeAttachments()) return ErrorInvalidFramebufferOperation("copyTexSubImage2D: incomplete framebuffer"); + bool texFormatRequiresAlpha = (internalFormat == LOCAL_GL_RGBA || + internalFormat == LOCAL_GL_ALPHA || + internalFormat == LOCAL_GL_LUMINANCE_ALPHA); + bool fboFormatHasAlpha = mBoundFramebuffer ? mBoundFramebuffer->ColorAttachment(0).HasAlpha() + : bool(gl->GetPixelFormat().alpha > 0); + + if (texFormatRequiresAlpha && !fboFormatHasAlpha) + return ErrorInvalidOperation("copyTexSubImage2D: texture format requires an alpha channel " + "but the framebuffer doesn't have one"); + if (imageInfo.HasUninitializedImageData()) { tex->DoDeferredImageInitialization(target, level); }