webgl: Implement uniformMatrix*fv.

These new functions are derived from the existing uniform*fv
functions.  They get used in a lot of demo code, so it should greatly
improve our compatibility.

This regresses uniformMatrixBadArgs.html, which gets at an existing
problem in our uniform matrix support (failure to validate that the
uniform is a matrix before calling down) but previously just failed
because it only called the 'fv' variants and never the existing 'f'
variants.
This commit is contained in:
Eric Anholt 2016-09-17 19:40:42 +01:00
parent 804317c885
commit 61debe5c01
13 changed files with 262 additions and 94 deletions

View file

@ -2108,6 +2108,66 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
Ok(())
}
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10
#[allow(unsafe_code)]
fn UniformMatrix2fv(&self,
cx: *mut JSContext,
uniform: Option<&WebGLUniformLocation>,
transpose: bool,
data: *mut JSObject) -> Fallible<()> {
assert!(!data.is_null());
let data_vec = try!(unsafe { typed_array_or_sequence_to_vec::<f32>(cx, data, ()) });
if self.validate_uniform_parameters(uniform,
UniformSetterType::FloatMat2,
&data_vec) {
self.ipc_renderer
.send(CanvasMsg::WebGL(WebGLCommand::UniformMatrix2fv(uniform.unwrap().id(), transpose, data_vec)))
.unwrap()
}
Ok(())
}
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10
#[allow(unsafe_code)]
fn UniformMatrix3fv(&self,
cx: *mut JSContext,
uniform: Option<&WebGLUniformLocation>,
transpose: bool,
data: *mut JSObject) -> Fallible<()> {
assert!(!data.is_null());
let data_vec = try!(unsafe { typed_array_or_sequence_to_vec::<f32>(cx, data, ()) });
if self.validate_uniform_parameters(uniform,
UniformSetterType::FloatMat3,
&data_vec) {
self.ipc_renderer
.send(CanvasMsg::WebGL(WebGLCommand::UniformMatrix3fv(uniform.unwrap().id(), transpose, data_vec)))
.unwrap()
}
Ok(())
}
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10
#[allow(unsafe_code)]
fn UniformMatrix4fv(&self,
cx: *mut JSContext,
uniform: Option<&WebGLUniformLocation>,
transpose: bool,
data: *mut JSObject) -> Fallible<()> {
assert!(!data.is_null());
let data_vec = try!(unsafe { typed_array_or_sequence_to_vec::<f32>(cx, data, ()) });
if self.validate_uniform_parameters(uniform,
UniformSetterType::FloatMat4,
&data_vec) {
self.ipc_renderer
.send(CanvasMsg::WebGL(WebGLCommand::UniformMatrix4fv(uniform.unwrap().id(), transpose, data_vec)))
.unwrap()
}
Ok(())
}
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.9
fn UseProgram(&self, program: Option<&WebGLProgram>) {
if let Some(program) = program {
@ -2480,6 +2540,9 @@ pub enum UniformSetterType {
FloatVec2,
FloatVec3,
FloatVec4,
FloatMat2,
FloatMat3,
FloatMat4,
}
impl UniformSetterType {
@ -2493,6 +2556,9 @@ impl UniformSetterType {
UniformSetterType::FloatVec2 => 2,
UniformSetterType::FloatVec3 => 3,
UniformSetterType::FloatVec4 => 4,
UniformSetterType::FloatMat2 => 4,
UniformSetterType::FloatMat3 => 9,
UniformSetterType::FloatMat4 => 16,
}
}
@ -2525,6 +2591,9 @@ impl UniformSetterType {
UniformSetterType::FloatVec2 => constants::FLOAT_VEC2,
UniformSetterType::FloatVec3 => constants::FLOAT_VEC3,
UniformSetterType::FloatVec4 => constants::FLOAT_VEC4,
UniformSetterType::FloatMat2 => constants::FLOAT_MAT2,
UniformSetterType::FloatMat3 => constants::FLOAT_MAT3,
UniformSetterType::FloatMat4 => constants::FLOAT_MAT4,
}
}
}

View file

@ -713,14 +713,23 @@ interface WebGLRenderingContextBase
// Float32Array value);
//void uniformMatrix2fv(WebGLUniformLocation? location, GLboolean transpose,
// sequence<GLfloat> value);
[Throws]
void uniformMatrix2fv(WebGLUniformLocation? location, GLboolean transpose,
object v);
//void uniformMatrix3fv(WebGLUniformLocation? location, GLboolean transpose,
// Float32Array value);
//void uniformMatrix3fv(WebGLUniformLocation? location, GLboolean transpose,
// sequence<GLfloat> value);
[Throws]
void uniformMatrix3fv(WebGLUniformLocation? location, GLboolean transpose,
object v);
//void uniformMatrix4fv(WebGLUniformLocation? location, GLboolean transpose,
// Float32Array value);
//void uniformMatrix4fv(WebGLUniformLocation? location, GLboolean transpose,
// sequence<GLfloat> value);
[Throws]
void uniformMatrix4fv(WebGLUniformLocation? location, GLboolean transpose,
object v);
void useProgram(WebGLProgram? program);
void validateProgram(WebGLProgram? program);

View file

@ -1,5 +0,0 @@
[uniformMatrix.html]
type: testharness
[WebGL test #0: testUniformf]
expected: FAIL

View file

@ -1,5 +1,3 @@
[uniformMatrixBadArgs.html]
type: testharness
[WebGL test #0: testUniformf]
expected: FAIL
expected: CRASH

View file

@ -1,6 +1,5 @@
[many-draw-calls.html]
type: testharness
expected: ERROR
[WebGL test #0: failed to create test program]
expected: FAIL

View file

@ -1,6 +1,5 @@
[texparameter-test.html]
type: testharness
expected: ERROR
[WebGL test #0: successfullyParsed should be true (of type boolean). Was undefined (of type undefined).]
expected: FAIL

View file

@ -1,6 +1,5 @@
[texture-active-bind-2.html]
type: testharness
expected: ERROR
[WebGL test #0: successfullyParsed should be true (of type boolean). Was undefined (of type undefined).]
expected: FAIL

View file

@ -1,6 +1,5 @@
[texture-active-bind.html]
type: testharness
expected: ERROR
[WebGL test #4: successfullyParsed should be true (of type boolean). Was undefined (of type undefined).]
expected: FAIL

View file

@ -1,3 +1,74 @@
[texture-size-cube-maps.html]
type: testharness
expected: ERROR
[WebGL test #7: at (0, 1) expected: 0,255,255,255 was 255,255,0,255]
expected: FAIL
[WebGL test #8: at (0, 0) expected: 0,255,255,255 was 0,0,255,255]
expected: FAIL
[WebGL test #10: at (0, 0) expected: 255,0,255,255 was 255,255,0,255]
expected: FAIL
[WebGL test #13: at (0, 1) expected: 255,0,255,255 was 0,0,255,255]
expected: FAIL
[WebGL test #14: at (0, 0) expected: 255,255,0,255 was 255,0,0,255]
expected: FAIL
[WebGL test #17: at (0, 1) expected: 0,0,255,255 was 255,0,0,255]
expected: FAIL
[WebGL test #25: at (0, 1) expected: 255,0,255,255 was 0,255,255,255]
expected: FAIL
[WebGL test #26: at (0, 0) expected: 255,0,255,255 was 255,255,0,255]
expected: FAIL
[WebGL test #28: at (0, 0) expected: 255,0,0,255 was 0,255,255,255]
expected: FAIL
[WebGL test #31: at (0, 1) expected: 255,0,0,255 was 255,255,0,255]
expected: FAIL
[WebGL test #32: at (0, 0) expected: 0,255,255,255 was 0,255,0,255]
expected: FAIL
[WebGL test #35: at (0, 1) expected: 255,255,0,255 was 0,255,0,255]
expected: FAIL
[WebGL test #44: at (0, 1) expected: 255,0,0,255 was 255,0,255,255]
expected: FAIL
[WebGL test #45: at (0, 0) expected: 255,0,0,255 was 0,255,255,255]
expected: FAIL
[WebGL test #47: at (0, 0) expected: 0,255,0,255 was 255,0,255,255]
expected: FAIL
[WebGL test #50: at (0, 1) expected: 0,255,0,255 was 0,255,255,255]
expected: FAIL
[WebGL test #51: at (0, 0) expected: 255,0,255,255 was 0,0,255,255]
expected: FAIL
[WebGL test #54: at (0, 1) expected: 0,255,255,255 was 0,0,255,255]
expected: FAIL
[WebGL test #62: at (0, 1) expected: 0,255,0,255 was 255,0,0,255]
expected: FAIL
[WebGL test #63: at (0, 0) expected: 0,255,0,255 was 255,0,255,255]
expected: FAIL
[WebGL test #65: at (0, 0) expected: 0,0,255,255 was 255,0,0,255]
expected: FAIL
[WebGL test #68: at (0, 1) expected: 0,0,255,255 was 255,0,255,255]
expected: FAIL
[WebGL test #69: at (0, 0) expected: 255,0,0,255 was 255,255,0,255]
expected: FAIL
[WebGL test #72: at (0, 1) expected: 255,0,255,255 was 255,255,0,255]
expected: FAIL

View file

@ -1,6 +1,5 @@
[texture-sub-image-cube-maps.html]
type: testharness
expected: ERROR
[WebGL test #0: successfullyParsed should be true (of type boolean). Was undefined (of type undefined).]
expected: FAIL
@ -10,3 +9,114 @@
[WebGL test #1: successfullyParsed should be true (of type boolean). Was undefined (of type undefined).]
expected: FAIL
[WebGL test #1: at (0, 0) expected: 255,0,0,255 was 0,0,0,0]
expected: FAIL
[WebGL test #2: at (0, 0) expected: 0,255,0,255 was 0,0,0,0]
expected: FAIL
[WebGL test #3: at (0, 0) expected: 0,0,255,255 was 0,0,0,0]
expected: FAIL
[WebGL test #4: at (0, 0) expected: 255,255,0,255 was 0,0,0,0]
expected: FAIL
[WebGL test #5: at (0, 0) expected: 0,255,255,255 was 0,0,0,0]
expected: FAIL
[WebGL test #6: at (0, 0) expected: 255,0,255,255 was 0,0,0,0]
expected: FAIL
[WebGL test #7: at (0, 0) expected: 255,255,0,255 was 0,0,0,0]
expected: FAIL
[WebGL test #8: at (0, 2) expected: 0,255,255,255 was 0,0,0,0]
expected: FAIL
[WebGL test #9: at (0, 0) expected: 0,255,255,255 was 0,0,0,0]
expected: FAIL
[WebGL test #10: at (0, 2) expected: 0,0,255,255 was 0,0,0,0]
expected: FAIL
[WebGL test #11: at (0, 0) expected: 255,0,255,255 was 0,0,0,0]
expected: FAIL
[WebGL test #12: at (0, 2) expected: 255,255,0,255 was 0,0,0,0]
expected: FAIL
[WebGL test #13: at (0, 0) expected: 0,0,255,255 was 0,0,0,0]
expected: FAIL
[WebGL test #14: at (0, 2) expected: 255,0,255,255 was 0,0,0,0]
expected: FAIL
[WebGL test #15: at (0, 0) expected: 255,255,0,255 was 0,0,0,0]
expected: FAIL
[WebGL test #16: at (0, 2) expected: 255,0,0,255 was 0,0,0,0]
expected: FAIL
[WebGL test #17: at (0, 0) expected: 255,0,0,255 was 0,0,0,0]
expected: FAIL
[WebGL test #18: at (0, 2) expected: 0,0,255,255 was 0,0,0,0]
expected: FAIL
[WebGL test #19: unexpected gl error: INVALID_VALUE]
expected: FAIL
[WebGL test #20: at (0, 0) expected: 0,255,0,255 was 0,0,0,0]
expected: FAIL
[WebGL test #21: at (0, 0) expected: 0,0,255,255 was 0,0,0,0]
expected: FAIL
[WebGL test #22: at (0, 0) expected: 255,255,0,255 was 0,0,0,0]
expected: FAIL
[WebGL test #23: at (0, 0) expected: 0,255,255,255 was 0,0,0,0]
expected: FAIL
[WebGL test #24: at (0, 0) expected: 255,0,255,255 was 0,0,0,0]
expected: FAIL
[WebGL test #25: at (0, 0) expected: 255,0,0,255 was 0,0,0,0]
expected: FAIL
[WebGL test #26: at (0, 0) expected: 0,255,255,255 was 0,0,0,0]
expected: FAIL
[WebGL test #27: at (0, 2) expected: 255,0,255,255 was 0,0,0,0]
expected: FAIL
[WebGL test #28: at (0, 0) expected: 255,0,255,255 was 0,0,0,0]
expected: FAIL
[WebGL test #29: at (0, 2) expected: 255,255,0,255 was 0,0,0,0]
expected: FAIL
[WebGL test #30: at (0, 0) expected: 255,0,0,255 was 0,0,0,0]
expected: FAIL
[WebGL test #31: at (0, 2) expected: 0,255,255,255 was 0,0,0,0]
expected: FAIL
[WebGL test #32: at (0, 0) expected: 255,255,0,255 was 0,0,0,0]
expected: FAIL
[WebGL test #33: at (0, 2) expected: 255,0,0,255 was 0,0,0,0]
expected: FAIL
[WebGL test #34: at (0, 0) expected: 0,255,255,255 was 0,0,0,0]
expected: FAIL
[WebGL test #35: at (0, 2) expected: 0,255,0,255 was 0,0,0,0]
expected: FAIL
[WebGL test #36: at (0, 0) expected: 0,255,0,255 was 0,0,0,0]
expected: FAIL
[WebGL test #37: at (0, 2) expected: 255,255,0,255 was 0,0,0,0]
expected: FAIL

View file

@ -4,9 +4,3 @@
[WebGL test #0: successfullyParsed should be true (of type boolean). Was undefined (of type undefined).]
expected: FAIL
[WebGL test #0: Unable to fetch WebGL rendering context for Canvas]
expected: FAIL
[WebGL test #1: successfullyParsed should be true (of type boolean). Was undefined (of type undefined).]
expected: FAIL

View file

@ -1,47 +0,0 @@
[null-uniform-location.html]
type: testharness
[WebGL test #6: callUniformFunction('uniform1i') should be undefined. Threw exception TypeError: func is undefined]
expected: FAIL
[WebGL test #8: callUniformFunction('uniform1iv') should be undefined. Threw exception TypeError: func is undefined]
expected: FAIL
[WebGL test #10: callUniformFunction('uniform2f') should be undefined. Threw exception TypeError: func is undefined]
expected: FAIL
[WebGL test #12: callUniformFunction('uniform2fv') should be undefined. Threw exception TypeError: func is undefined]
expected: FAIL
[WebGL test #14: callUniformFunction('uniform2i') should be undefined. Threw exception TypeError: func is undefined]
expected: FAIL
[WebGL test #16: callUniformFunction('uniform2iv') should be undefined. Threw exception TypeError: func is undefined]
expected: FAIL
[WebGL test #18: callUniformFunction('uniform3f') should be undefined. Threw exception TypeError: func is undefined]
expected: FAIL
[WebGL test #20: callUniformFunction('uniform3fv') should be undefined. Threw exception TypeError: func is undefined]
expected: FAIL
[WebGL test #22: callUniformFunction('uniform3i') should be undefined. Threw exception TypeError: func is undefined]
expected: FAIL
[WebGL test #24: callUniformFunction('uniform3iv') should be undefined. Threw exception TypeError: func is undefined]
expected: FAIL
[WebGL test #30: callUniformFunction('uniform4i') should be undefined. Threw exception TypeError: func is undefined]
expected: FAIL
[WebGL test #32: callUniformFunction('uniform4iv') should be undefined. Threw exception TypeError: func is undefined]
expected: FAIL
[WebGL test #34: callUniformFunction('uniformMatrix2fv') should be undefined. Threw exception TypeError: func is undefined]
expected: FAIL
[WebGL test #36: callUniformFunction('uniformMatrix3fv') should be undefined. Threw exception TypeError: func is undefined]
expected: FAIL
[WebGL test #38: callUniformFunction('uniformMatrix4fv') should be undefined. Threw exception TypeError: func is undefined]
expected: FAIL

View file

@ -1,14 +1,5 @@
[uniform-location.html]
type: testharness
[WebGL test #1: contextA.uniformMatrix4fv(locationA, false, mat) threw exception TypeError: contextA.uniformMatrix4fv is not a function]
expected: FAIL
[WebGL test #3: contextA.uniformMatrix4fv(locationA, false, mat) threw exception TypeError: contextA.uniformMatrix4fv is not a function]
expected: FAIL
[WebGL test #4: contextA.uniformMatrix4fv(null, false, mat) threw exception TypeError: contextA.uniformMatrix4fv is not a function]
expected: FAIL
[WebGL test #9: contextA.getUniform(programS, locationSx) should be 333. Threw exception TypeError: contextA.getUniform is not a function]
expected: FAIL
@ -18,27 +9,9 @@
[WebGL test #11: contextA.getUniform(programS, locationArray1) should be 5. Threw exception TypeError: contextA.getUniform is not a function]
expected: FAIL
[WebGL test #13: getError expected: NO_ERROR. Was INVALID_VALUE : after evaluating: contextA.uniform4fv(locationVec4, vec)]
expected: FAIL
[WebGL test #14: contextA.getUniform(programV, locationVec4) should be 1,2,3,4. Threw exception TypeError: contextA.getUniform is not a function]
expected: FAIL
[WebGL test #17: contextA.uniformMatrix4fv(locationA, false, mat) threw exception TypeError: contextA.uniformMatrix4fv is not a function]
expected: FAIL
[WebGL test #19: successfullyParsed should be true (of type boolean). Was undefined (of type undefined).]
expected: FAIL
[WebGL test #7: getError expected: NO_ERROR. Was INVALID_OPERATION : after evaluating: contextA.uniform1f(locationArray0, 4.0)]
expected: FAIL
[WebGL test #8: getError expected: NO_ERROR. Was INVALID_OPERATION : after evaluating: contextA.uniform1f(locationArray1, 5.0)]
expected: FAIL
[WebGL test #13: getError expected: NO_ERROR. Was INVALID_OPERATION : after evaluating: contextA.uniform4fv(locationVec4, vec)]
expected: FAIL
[WebGL test #20: getError expected: INVALID_OPERATION. Was NO_ERROR : after evaluating: contextA.uniform1i(locationSx, 3)]
expected: FAIL