Bug 1285676 - Don't call into GL for GetFramebufferAttachmentParameter. - r=ethlin

MozReview-Commit-ID: G7ub5GG7bJ
This commit is contained in:
Jeff Gilbert 2016-07-08 15:48:36 -07:00
Родитель c98755a4a2
Коммит b1e4820ae3
1 изменённых файлов: 84 добавлений и 32 удалений

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

@ -469,35 +469,8 @@ WebGLFBAttachPoint::GetParameter(const char* funcName, WebGLContext* webgl, JSCo
*out_error)
: webgl->WebGLObjectAsJSValue(cx, mRenderbufferPtr.get(),
*out_error));
////////////////
case LOCAL_GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE:
case LOCAL_GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE:
case LOCAL_GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE:
case LOCAL_GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE:
case LOCAL_GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE:
case LOCAL_GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE:
isPNameValid = true;
break;
case LOCAL_GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE:
MOZ_ASSERT(attachment != LOCAL_GL_DEPTH_STENCIL_ATTACHMENT);
isPNameValid = true;
break;
case LOCAL_GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING:
if (webgl->IsWebGL2() ||
webgl->IsExtensionEnabled(WebGLExtensionID::EXT_sRGB))
{
const auto format = Format();
if (!format)
return JS::NullValue();
return JS::Int32Value(format->format->isSRGB ? LOCAL_GL_SRGB
: LOCAL_GL_LINEAR);
}
break;
////////////////
//////
case LOCAL_GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL:
if (mTexturePtr)
@ -514,8 +487,10 @@ WebGLFBAttachPoint::GetParameter(const char* funcName, WebGLContext* webgl, JSCo
}
break;
//////
case LOCAL_GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER:
if (mTexturePtr) {
if (webgl->IsWebGL2() && mTexturePtr) {
int32_t layer = 0;
if (ImageTarget() == LOCAL_GL_TEXTURE_2D_ARRAY ||
ImageTarget() == LOCAL_GL_TEXTURE_3D)
@ -525,6 +500,23 @@ WebGLFBAttachPoint::GetParameter(const char* funcName, WebGLContext* webgl, JSCo
return JS::Int32Value(layer);
}
break;
//////
case LOCAL_GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE:
case LOCAL_GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE:
case LOCAL_GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE:
case LOCAL_GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE:
case LOCAL_GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE:
case LOCAL_GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE:
case LOCAL_GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE:
isPNameValid = webgl->IsWebGL2();
break;
case LOCAL_GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING:
isPNameValid = (webgl->IsWebGL2() ||
webgl->IsExtensionEnabled(WebGLExtensionID::EXT_sRGB));
break;
}
if (!isPNameValid) {
@ -532,11 +524,71 @@ WebGLFBAttachPoint::GetParameter(const char* funcName, WebGLContext* webgl, JSCo
return JS::NullValue();
}
gl::GLContext* gl = webgl->GL();
gl->MakeCurrent();
const auto usage = Format();
if (!usage)
return JS::NullValue();
const auto format = usage->format;
GLint ret = 0;
gl->fGetFramebufferAttachmentParameteriv(target, attachment, pname, &ret);
switch (pname) {
case LOCAL_GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE:
ret = format->r;
break;
case LOCAL_GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE:
ret = format->g;
break;
case LOCAL_GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE:
ret = format->b;
break;
case LOCAL_GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE:
ret = format->a;
break;
case LOCAL_GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE:
ret = format->d;
break;
case LOCAL_GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE:
ret = format->s;
break;
case LOCAL_GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING:
ret = (format->isSRGB ? LOCAL_GL_SRGB
: LOCAL_GL_LINEAR);
break;
case LOCAL_GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE:
MOZ_ASSERT(attachment != LOCAL_GL_DEPTH_STENCIL_ATTACHMENT);
switch (format->componentType) {
case webgl::ComponentType::Special:
MOZ_ASSERT(false, "Should never happen.");
MOZ_FALLTHROUGH;
case webgl::ComponentType::None:
ret = LOCAL_GL_NONE;
break;
case webgl::ComponentType::Int:
ret = LOCAL_GL_INT;
break;
case webgl::ComponentType::UInt:
ret = LOCAL_GL_UNSIGNED_INT;
break;
case webgl::ComponentType::NormInt:
ret = LOCAL_GL_SIGNED_NORMALIZED;
break;
case webgl::ComponentType::NormUInt:
ret = LOCAL_GL_UNSIGNED_NORMALIZED;
break;
case webgl::ComponentType::Float:
ret = LOCAL_GL_FLOAT;
break;
}
break;
default:
MOZ_ASSERT(false, "Missing case.");
break;
}
return JS::Int32Value(ret);
}