Bug 684882 - back out b4fd4fd0dc3f

This commit is contained in:
Benoit Jacob 2011-09-29 10:13:49 -04:00
Родитель 4259bb9e4b
Коммит 428af685fc
2 изменённых файлов: 30 добавлений и 65 удалений

Просмотреть файл

@ -588,17 +588,6 @@ protected:
return target == LOCAL_GL_TEXTURE_2D ? mGLMaxTextureSize : mGLMaxCubeMapTextureSize;
}
// bug 684882 comment 37. On Mac OS (confirmed on 10.7.1), Intel driver, rendering to a face of a cube map
// copies random video memory into it.
// In particular, since glGenerateMipmap does that, it must be avoided.
bool WorkAroundCubeMapBug684882() const {
#ifdef XP_MACOSX
return gl->Vendor() == gl::GLContext::VendorIntel;
#else
return false;
#endif
}
/** like glBufferData but if the call may change the buffer size, checks any GL error generated
* by this glBufferData call and returns it */
GLenum CheckedBufferData(GLenum target,

Просмотреть файл

@ -1696,17 +1696,10 @@ WebGLContext::FramebufferTexture2D(WebGLenum target,
nsIWebGLTexture *tobj,
WebGLint level)
{
if (!mBoundFramebuffer)
if (mBoundFramebuffer)
return mBoundFramebuffer->FramebufferTexture2D(target, attachment, textarget, tobj, level);
else
return ErrorInvalidOperation("framebufferTexture2D: cannot modify framebuffer 0");
if (textarget != LOCAL_GL_TEXTURE_2D && WorkAroundCubeMapBug684882()) {
return ErrorInvalidOperation("framebufferTexture2D: Attaching a face of a cube map to a framebuffer is disabled "
"on Mac OS X on Intel GPUs to protect you from a bug causing random "
"video memory to be copied into cube maps attached to framebuffers "
"(Mozilla bug 684882, Apple bug 9129398)");
}
return mBoundFramebuffer->FramebufferTexture2D(target, attachment, textarget, tobj, level);
}
GL_SAME_METHOD_0(Flush, Flush)
@ -1785,17 +1778,27 @@ WebGLContext::GenerateMipmap(WebGLenum target)
MakeContextCurrent();
if (WorkAroundCubeMapBug684882()) {
if (target == LOCAL_GL_TEXTURE_2D) {
gl->fGenerateMipmap(target);
} else {
// do nothing! Accordingly we must make sure to never actually set texture parameters to something that requires mipmaps,
// or else we'll fail to render.
}
} else {
#ifdef XP_MACOSX
// On Mac, glGenerateMipmap on a texture whose minification filter does NOT require a mipmap at the time of the call,
// will happily grab random video memory into certain mipmap levels. See bug 684882. Also, this is Apple bug 9129398.
// Thanks to Kenneth Russell / Google for figuring this out.
// So we temporarily spoof the minification filter, call glGenerateMipmap,
// and restore it. If that turned out to not be enough, we would have to avoid calling glGenerateMipmap altogether and
// emulate it.
if (tex->DoesMinFilterRequireMipmap()) {
gl->fGenerateMipmap(target);
} else {
// spoof the min filter as something that requires a mipmap. The particular choice of a filter doesn't matter as
// we're not rendering anything here. Since LINEAR_MIPMAP_LINEAR is by far the most common use case, and we're trying
// to work around a bug triggered by "unexpected" min filters, it seems to be the safest choice.
gl->fTexParameteri(target, LOCAL_GL_TEXTURE_MIN_FILTER, LOCAL_GL_LINEAR_MIPMAP_LINEAR);
gl->fGenerateMipmap(target);
gl->fTexParameteri(target, LOCAL_GL_TEXTURE_MIN_FILTER, tex->MinFilter());
}
#else
gl->fGenerateMipmap(target);
#endif
return NS_OK;
}
@ -2527,33 +2530,12 @@ nsresult WebGLContext::TexParameter_base(WebGLenum target, WebGLenum pname,
return ErrorInvalidEnum("texParameterf: pname %x and floating-point param %e are mutually incompatible",
pname, floatParam);
}
WebGLint intParamForGL = intParam;
WebGLfloat floatParamForGL = floatParam;
if (WorkAroundCubeMapBug684882()) {
// bug 684882 - we skip mipmap generation in this case to work around a Mac GL bug, so we have
// to tweak the minification filter to avoid requiring a mipmap
if (pname == LOCAL_GL_TEXTURE_MIN_FILTER) {
if (intParam == LOCAL_GL_NEAREST_MIPMAP_NEAREST ||
intParam == LOCAL_GL_NEAREST_MIPMAP_LINEAR)
{
intParamForGL = LOCAL_GL_NEAREST;
floatParamForGL = WebGLfloat(intParamForGL);
} else if (intParam == LOCAL_GL_LINEAR_MIPMAP_NEAREST ||
intParam == LOCAL_GL_LINEAR_MIPMAP_LINEAR)
{
intParamForGL = LOCAL_GL_LINEAR;
floatParamForGL = WebGLfloat(intParamForGL);
}
}
}
MakeContextCurrent();
if (intParamPtr)
gl->fTexParameteri(target, pname, intParamForGL);
gl->fTexParameteri(target, pname, intParam);
else
gl->fTexParameterf(target, pname, floatParamForGL);
gl->fTexParameterf(target, pname, floatParam);
return NS_OK;
}
@ -2579,29 +2561,23 @@ WebGLContext::GetTexParameter(WebGLenum target, WebGLenum pname, nsIVariant **re
if (!ValidateTextureTargetEnum(target, "getTexParameter: target"))
return NS_OK;
WebGLTexture *tex = activeBoundTextureForTarget(target);
if (!tex)
if (!activeBoundTextureForTarget(target))
return ErrorInvalidOperation("getTexParameter: no texture bound");
nsCOMPtr<nsIWritableVariant> wrval = do_CreateInstance("@mozilla.org/variant;1");
NS_ENSURE_TRUE(wrval, NS_ERROR_FAILURE);
switch (pname) {
// note that because of bug 684882, the minification filter for OpenGL is sometimes spoofed.
// here we want to return our own value, not OpenGL's value
case LOCAL_GL_TEXTURE_MIN_FILTER:
wrval->SetAsInt32(tex->mMinFilter);
break;
case LOCAL_GL_TEXTURE_MAG_FILTER:
wrval->SetAsInt32(tex->mMagFilter);
break;
case LOCAL_GL_TEXTURE_WRAP_S:
wrval->SetAsInt32(tex->mWrapS);
break;
case LOCAL_GL_TEXTURE_WRAP_T:
wrval->SetAsInt32(tex->mWrapT);
{
GLint i = 0;
gl->fGetTexParameteriv(target, pname, &i);
wrval->SetAsInt32(i);
}
break;
default: