--- a/dom/canvas/WebGLTextureUpload.cpp
+++ b/dom/canvas/WebGLTextureUpload.cpp
@@ -1722,22 +1722,25 @@ ValidateCopyTexImageFormats(WebGLContext
////////////////////////////////////////////////////////////////////////////////
class ScopedCopyTexImageSource
{
WebGLContext* const mWebGL;
GLuint mRB;
GLuint mFB;
+ GLenum mSrcSizedFormat;
public:
ScopedCopyTexImageSource(WebGLContext* webgl, const char* funcName, uint32_t srcWidth,
uint32_t srcHeight, const webgl::FormatInfo* srcFormat,
const webgl::FormatUsageInfo* dstUsage);
~ScopedCopyTexImageSource();
+ bool IsValidFB() { return mFB != 0;}
+ GLenum GetSourceSizedFormat() {return mSrcSizedFormat;}
};
ScopedCopyTexImageSource::ScopedCopyTexImageSource(WebGLContext* webgl,
const char* funcName,
uint32_t srcWidth, uint32_t srcHeight,
const webgl::FormatInfo* srcFormat,
const webgl::FormatUsageInfo* dstUsage)
: mWebGL(webgl)
@@ -1759,31 +1762,29 @@ ScopedCopyTexImageSource::ScopedCopyTexI
return;
}
if (!dstUsage->textureSwizzleRGBA)
return;
gl::GLContext* gl = webgl->gl;
- GLenum sizedFormat;
-
switch (srcFormat->componentType) {
case webgl::ComponentType::NormUInt:
- sizedFormat = LOCAL_GL_RGBA8;
+ mSrcSizedFormat = LOCAL_GL_RGBA8;
break;
case webgl::ComponentType::Float:
if (webgl->IsExtensionEnabled(WebGLExtensionID::WEBGL_color_buffer_float)) {
- sizedFormat = LOCAL_GL_RGBA32F;
+ mSrcSizedFormat = LOCAL_GL_RGBA32F;
break;
}
if (webgl->IsExtensionEnabled(WebGLExtensionID::EXT_color_buffer_half_float)) {
- sizedFormat = LOCAL_GL_RGBA16F;
+ mSrcSizedFormat = LOCAL_GL_RGBA16F;
break;
}
MOZ_CRASH("GFX: Should be able to request CopyTexImage from Float.");
default:
MOZ_CRASH("GFX: Should be able to request CopyTexImage from this type.");
}
@@ -1812,25 +1813,25 @@ ScopedCopyTexImageSource::ScopedCopyTexI
MOZ_CRASH("GFX: Unhandled unsizedFormat.");
}
gl->fTexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_SWIZZLE_R, blitSwizzle[0]);
gl->fTexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_SWIZZLE_G, blitSwizzle[1]);
gl->fTexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_SWIZZLE_B, blitSwizzle[2]);
gl->fTexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_SWIZZLE_A, blitSwizzle[3]);
- gl->fCopyTexImage2D(LOCAL_GL_TEXTURE_2D, 0, sizedFormat, 0, 0, srcWidth,
+ gl->fCopyTexImage2D(LOCAL_GL_TEXTURE_2D, 0, mSrcSizedFormat, 0, 0, srcWidth,
srcHeight, 0);
// Now create the swizzled FB we'll be exposing.
GLuint rgbaRB = 0;
gl->fGenRenderbuffers(1, &rgbaRB);
gl::ScopedBindRenderbuffer scopedRB(gl, rgbaRB);
- gl->fRenderbufferStorage(LOCAL_GL_RENDERBUFFER, sizedFormat, srcWidth, srcHeight);
+ gl->fRenderbufferStorage(LOCAL_GL_RENDERBUFFER, mSrcSizedFormat, srcWidth, srcHeight);
GLuint rgbaFB = 0;
gl->fGenFramebuffers(1, &rgbaFB);
gl->fBindFramebuffer(LOCAL_GL_FRAMEBUFFER, rgbaFB);
gl->fFramebufferRenderbuffer(LOCAL_GL_FRAMEBUFFER, LOCAL_GL_COLOR_ATTACHMENT0,
LOCAL_GL_RENDERBUFFER, rgbaRB);
const GLenum status = gl->fCheckFramebufferStatus(LOCAL_GL_FRAMEBUFFER);
@@ -2068,17 +2069,19 @@ WebGLTexture::CopyTexImage2D(TexImageTar
uint32_t readX, readY;
uint32_t writeX, writeY;
uint32_t rwWidth, rwHeight;
Intersect(srcWidth, x, width, &readX, &writeX, &rwWidth);
Intersect(srcHeight, y, height, &readY, &writeY, &rwHeight);
GLenum error;
if (rwWidth == uint32_t(width) && rwHeight == uint32_t(height)) {
- error = DoCopyTexImage2D(gl, target, level, internalFormat, x, y, width, height);
+ GLenum validFormat = maybeSwizzle.IsValidFB() ?
+ maybeSwizzle.GetSourceSizedFormat() : internalFormat;
+ error = DoCopyTexImage2D(gl, target, level, validFormat, x, y, width, height);
} else {
// 1. Zero the texture data.
// 2. CopyTexSubImage the subrect.
const bool respecifyTexture = true;
const uint8_t zOffset = 0;
if (!ZeroTextureData(mContext, funcName, respecifyTexture, mGLName, target, level,
dstUsage, 0, 0, zOffset, width, height, depth))