mirror of
https://github.com/servo/servo.git
synced 2025-08-01 19:50:30 +01:00
Auto merge of #13665 - anholt:webgl-uniform-matrix-v, r=emilio
webgl: Implement uniformMatrix*fv. <!-- Please describe your changes on the following line: --> --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [ ] These changes fix #__ (github issue number if applicable). <!-- Either: --> - [X] There are tests for these changes OR - [ ] These changes do not require tests because _____ <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> 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. <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/13665) <!-- Reviewable:end -->
This commit is contained in:
commit
aab9d61025
13 changed files with 262 additions and 94 deletions
|
@ -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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue