Bug 1237193 - Fix WebGL getActiveUniforms return type. r=jgilbert, r=smaug

This commit is contained in:
Ethan Lin 2016-01-07 21:45:00 +01:00
parent 020e5ddb3f
commit d07db5d65d
3 changed files with 70 additions and 13 deletions

View File

@ -360,9 +360,12 @@ public:
void GetUniformIndices(WebGLProgram* program,
const dom::Sequence<nsString>& uniformNames,
dom::Nullable< nsTArray<GLuint> >& retval);
void GetActiveUniforms(WebGLProgram* program,
const dom::Sequence<GLuint>& uniformIndices, GLenum pname,
dom::Nullable< nsTArray<GLint> >& retval);
void GetActiveUniforms(JSContext* cx,
WebGLProgram* program,
const dom::Sequence<GLuint>& uniformIndices,
GLenum pname,
JS::MutableHandleValue retval);
GLuint GetUniformBlockIndex(WebGLProgram* program, const nsAString& uniformBlockName);
void GetActiveUniformBlockParameter(JSContext*, WebGLProgram* program,
GLuint uniformBlockIndex, GLenum pname,

View File

@ -318,20 +318,38 @@ WebGL2Context::GetUniformIndices(WebGLProgram* program,
program->GetUniformIndices(uniformNames, retval);
}
static bool
ValidateUniformEnum(WebGLContext* webgl, GLenum pname, const char* info)
{
switch (pname) {
case LOCAL_GL_UNIFORM_TYPE:
case LOCAL_GL_UNIFORM_SIZE:
case LOCAL_GL_UNIFORM_BLOCK_INDEX:
case LOCAL_GL_UNIFORM_OFFSET:
case LOCAL_GL_UNIFORM_ARRAY_STRIDE:
case LOCAL_GL_UNIFORM_MATRIX_STRIDE:
case LOCAL_GL_UNIFORM_IS_ROW_MAJOR:
return true;
default:
webgl->ErrorInvalidEnum("%s: invalid pname: %s", info, webgl->EnumName(pname));
return false;
}
}
void
WebGL2Context::GetActiveUniforms(WebGLProgram* program,
WebGL2Context::GetActiveUniforms(JSContext* cx,
WebGLProgram* program,
const dom::Sequence<GLuint>& uniformIndices,
GLenum pname,
dom::Nullable< nsTArray<GLint> >& retval)
JS::MutableHandleValue retval)
{
retval.SetNull();
retval.set(JS::NullValue());
if (IsContextLost())
return;
if (pname == LOCAL_GL_UNIFORM_NAME_LENGTH) {
ErrorInvalidEnumInfo("getActiveUniforms: pname", pname);
if (!ValidateUniformEnum(this, pname, "getActiveUniforms"))
return;
}
if (!ValidateObject("getActiveUniforms: program", program))
return;
@ -341,12 +359,48 @@ WebGL2Context::GetActiveUniforms(WebGLProgram* program,
return;
GLuint progname = program->mGLName;
nsTArray<GLint>& arr = retval.SetValue();
arr.SetLength(count);
Vector<GLint> samples;
samples.resize(count);
MakeContextCurrent();
gl->fGetActiveUniformsiv(progname, count, uniformIndices.Elements(), pname,
arr.Elements());
samples.begin());
JS::Rooted<JSObject*> array(cx, JS_NewArrayObject(cx, count));
if (!array) {
return;
}
switch (pname) {
case LOCAL_GL_UNIFORM_TYPE:
case LOCAL_GL_UNIFORM_SIZE:
case LOCAL_GL_UNIFORM_BLOCK_INDEX:
case LOCAL_GL_UNIFORM_OFFSET:
case LOCAL_GL_UNIFORM_ARRAY_STRIDE:
case LOCAL_GL_UNIFORM_MATRIX_STRIDE:
for (uint32_t i = 0; i < count; ++i) {
JS::RootedValue value(cx);
value = JS::Int32Value(samples[i]);
if (!JS_DefineElement(cx, array, i, value, JSPROP_ENUMERATE)) {
return;
}
}
break;
case LOCAL_GL_UNIFORM_IS_ROW_MAJOR:
for (uint32_t i = 0; i < count; ++i) {
JS::RootedValue value(cx);
value = JS::BooleanValue(samples[i]);
if (!JS_DefineElement(cx, array, i, value, JSPROP_ENUMERATE)) {
return;
}
}
break;
default:
return;
}
retval.setObjectOrNull(array);
}
GLuint

View File

@ -475,7 +475,7 @@ interface WebGL2RenderingContext : WebGLRenderingContext
// GLintptr here, otherwise interface generator returns error.
(WebGLBuffer or GLintptr)? getIndexedParameter(GLenum target, GLuint index);
sequence<GLuint>? getUniformIndices(WebGLProgram? program, sequence<DOMString> uniformNames);
sequence<GLint>? getActiveUniforms(WebGLProgram? program, sequence<GLuint> uniformIndices, GLenum pname);
any getActiveUniforms(WebGLProgram? program, sequence<GLuint> uniformIndices, GLenum pname);
GLuint getUniformBlockIndex(WebGLProgram? program, DOMString uniformBlockName);
[Throws]
(GLuint or Uint32Array or GLboolean)? getActiveUniformBlockParameter(WebGLProgram? program, GLuint uniformBlockIndex, GLenum pname);