Bug 616655 - Pass the tex-input-validation.html test - r=vlad

This commit is contained in:
Benoit Jacob 2010-12-06 06:34:35 -05:00
parent 2689520e00
commit 1de3f28ff0
2 changed files with 49 additions and 26 deletions

View File

@ -804,6 +804,8 @@ protected:
PRBool mIsDefined;
};
public:
ImageInfo& ImageInfoAt(size_t level, size_t face) {
#ifdef DEBUG
if (face >= mFacesCount)
@ -817,6 +819,8 @@ protected:
return const_cast<WebGLTexture*>(this)->ImageInfoAt(level, face);
}
protected:
WebGLenum mTarget;
WebGLenum mMinFilter, mMagFilter, mWrapS, mWrapT;
@ -1372,6 +1376,19 @@ public:
return !mTexturePtr && !mRenderbufferPtr;
}
PRBool HasAlpha() const {
WebGLenum format = 0;
if (mTexturePtr)
format = mTexturePtr->ImageInfoAt(0,0).mFormat;
if (mRenderbufferPtr)
format = mRenderbufferPtr->InternalFormat();
return format == LOCAL_GL_RGBA ||
format == LOCAL_GL_LUMINANCE_ALPHA ||
format == LOCAL_GL_ALPHA ||
format == LOCAL_GL_RGBA4 ||
format == LOCAL_GL_RGB5_A1;
}
void SetTexture(WebGLTexture *tex) {
mTexturePtr = tex;
mRenderbufferPtr = nsnull;
@ -1431,7 +1448,6 @@ public:
WebGLFramebuffer(WebGLContext *context, WebGLuint name) :
WebGLContextBoundObject(context),
mName(name), mDeleted(PR_FALSE),
mColorAttachmentHasAlpha(PR_FALSE),
mColorAttachment(LOCAL_GL_COLOR_ATTACHMENT0),
mDepthAttachment(LOCAL_GL_DEPTH_ATTACHMENT),
mStencilAttachment(LOCAL_GL_STENCIL_ATTACHMENT),
@ -1447,8 +1463,6 @@ public:
PRBool Deleted() { return mDeleted; }
WebGLuint GLName() { return mName; }
PRBool ColorAttachmentHasAlpha() { return mColorAttachmentHasAlpha; }
nsresult FramebufferRenderbuffer(WebGLenum target,
WebGLenum attachment,
WebGLenum rbtarget,
@ -1488,7 +1502,6 @@ public:
// ReadPixels needs alpha and size information, but only
// for COLOR_ATTACHMENT0
setDimensions(wrb);
mColorAttachmentHasAlpha = InternalFormatHasAlpha(wrb->mInternalFormat);
}
mColorAttachment.SetRenderbuffer(wrb);
break;
@ -1544,16 +1557,6 @@ public:
// keep data for readPixels, function only uses COLOR_ATTACHMENT0
setDimensions(wtex);
if (wtex) {
const WebGLTexture::ImageInfo& ia = wtex->ImageInfoAt
(level, textarget == LOCAL_GL_TEXTURE_2D
? 0
: textarget - LOCAL_GL_TEXTURE_CUBE_MAP_POSITIVE_X);
mColorAttachmentHasAlpha = InternalFormatHasAlpha(ia.mFormat);
} else {
mColorAttachmentHasAlpha = PR_FALSE;
}
mColorAttachment.SetTexture(wtex);
break;
}
@ -1601,13 +1604,8 @@ public:
else return PR_FALSE;
}
static PRBool InternalFormatHasAlpha(WebGLenum aInternalFormat) {
return
aInternalFormat == LOCAL_GL_RGBA ||
aInternalFormat == LOCAL_GL_LUMINANCE_ALPHA ||
aInternalFormat == LOCAL_GL_ALPHA ||
aInternalFormat == LOCAL_GL_RGBA4 ||
aInternalFormat == LOCAL_GL_RGB5_A1;
const WebGLFramebufferAttachment ColorAttachment() const {
return mColorAttachment;
}
NS_DECL_ISUPPORTS
@ -1717,8 +1715,6 @@ protected:
WebGLuint mName;
PRPackedBool mDeleted;
PRBool mColorAttachmentHasAlpha;
// we only store pointers to attached renderbuffers, not to attached textures, because
// we will only need to initialize renderbuffers. Textures are already initialized.
WebGLFramebufferAttachment mColorAttachment,

View File

@ -603,11 +603,12 @@ WebGLContext::CopyTexImage2D(WebGLenum target,
return ErrorInvalidEnumInfo("copyTexImage2D: target", target);
}
switch (internalformat) {
case LOCAL_GL_RGB:
case LOCAL_GL_LUMINANCE:
case LOCAL_GL_RGBA:
case LOCAL_GL_ALPHA:
case LOCAL_GL_LUMINANCE:
case LOCAL_GL_LUMINANCE_ALPHA:
break;
default:
@ -626,6 +627,15 @@ WebGLContext::CopyTexImage2D(WebGLenum target,
return ErrorInvalidValue("copyTexImage2D: with level > 0, width and height must be powers of two");
}
PRBool texFormatRequiresAlpha = internalformat == LOCAL_GL_RGBA ||
internalformat == LOCAL_GL_ALPHA ||
internalformat == LOCAL_GL_LUMINANCE_ALPHA;
PRBool fboFormatHasAlpha = mBoundFramebuffer ? mBoundFramebuffer->ColorAttachment().HasAlpha()
: PRBool(gl->ActualFormat().alpha > 0);
if (texFormatRequiresAlpha && !fboFormatHasAlpha)
return ErrorInvalidOperation("copyTexImage2D: texture format requires an alpha channel "
"but the framebuffer doesn't have one");
if (!CanvasUtils::CheckSaneSubrectSize(x,y,width, height, mWidth, mHeight))
return ErrorInvalidOperation("CopyTexImage2D: copied rectangle out of bounds");
@ -669,6 +679,21 @@ WebGLContext::CopyTexSubImage2D(WebGLenum target,
return ErrorInvalidEnumInfo("CopyTexSubImage2D: target", target);
}
WebGLTexture *tex = activeBoundTextureForTarget(target);
if (!tex)
return ErrorInvalidOperation("copyTexSubImage2D: no texture bound to this target");
WebGLenum format = tex->ImageInfoAt(0,0).mFormat;
PRBool texFormatRequiresAlpha = format == LOCAL_GL_RGBA ||
format == LOCAL_GL_ALPHA ||
format == LOCAL_GL_LUMINANCE_ALPHA;
PRBool fboFormatHasAlpha = mBoundFramebuffer ? mBoundFramebuffer->ColorAttachment().HasAlpha()
: PRBool(gl->ActualFormat().alpha > 0);
if (texFormatRequiresAlpha && !fboFormatHasAlpha)
return ErrorInvalidOperation("copyTexSubImage2D: texture format requires an alpha channel "
"but the framebuffer doesn't have one");
if (!CanvasUtils::CheckSaneSubrectSize(x,y,width, height, mWidth, mHeight))
return ErrorInvalidOperation("CopyTexSubImage2D: copied rectangle out of bounds");
@ -2073,11 +2098,13 @@ nsresult WebGLContext::TexParameter_base(WebGLenum target, WebGLenum pname,
}
if (pnameAndParamAreIncompatible) {
// note that currently all params are enums, and the tex-input-validation test wants INVALID_ENUM errors
// even for texParameterf. why not.
if (intParamPtr)
return ErrorInvalidEnum("texParameteri: pname %x and param %x (decimal %d) are mutually incompatible",
pname, intParam, intParam);
else
return ErrorInvalidValue("texParameterf: pname %x and floating-point param %e are mutually incompatible",
return ErrorInvalidEnum("texParameterf: pname %x and floating-point param %e are mutually incompatible",
pname, floatParam);
}
@ -2647,7 +2674,7 @@ WebGLContext::ReadPixels_base(WebGLint x, WebGLint y, WebGLsizei width, WebGLsiz
{
PRBool needAlphaFixup;
if (mBoundFramebuffer) {
needAlphaFixup = !mBoundFramebuffer->ColorAttachmentHasAlpha();
needAlphaFixup = !mBoundFramebuffer->ColorAttachment().HasAlpha();
} else {
needAlphaFixup = gl->ActualFormat().alpha == 0;
}