aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/webgl2renderingcontext.rs
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2020-01-17 12:55:14 -0500
committerGitHub <noreply@github.com>2020-01-17 12:55:14 -0500
commitf200e2106499d412890fdc750485d7e9c1d4dcf8 (patch)
tree251f8bc402e117367a89e75c6f4b2ad2ffa040c3 /components/script/dom/webgl2renderingcontext.rs
parent1de92906e8205e5e46ae947378dd916905fbbf7f (diff)
parent7d5048f8852df0de2a0a86cb16e2a54f493b6e7c (diff)
downloadservo-f200e2106499d412890fdc750485d7e9c1d4dcf8.tar.gz
servo-f200e2106499d412890fdc750485d7e9c1d4dcf8.zip
Auto merge of #25543 - szeged:mmatyas__webgl_fns_uniforms_p3, r=jdm
Add support for WebGL2 uniform matrix operations Adds support for the `uniformMatrix[234]x[234]fv` WebGL2 functions. See: https://www.khronos.org/registry/webgl/specs/latest/2.0/#3.7.8 <!-- Please describe your changes on the following line: --> Note: Similarly to #25538, some of the functions here also overlap with their WebGL 1 variant. cc @jdm @zakorgy @imiklos --- <!-- 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 - [x] There are tests for these changes <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
Diffstat (limited to 'components/script/dom/webgl2renderingcontext.rs')
-rw-r--r--components/script/dom/webgl2renderingcontext.rs221
1 files changed, 217 insertions, 4 deletions
diff --git a/components/script/dom/webgl2renderingcontext.rs b/components/script/dom/webgl2renderingcontext.rs
index 2f847cebd3f..3b666f515e2 100644
--- a/components/script/dom/webgl2renderingcontext.rs
+++ b/components/script/dom/webgl2renderingcontext.rs
@@ -50,7 +50,7 @@ use js::jsapi::{JSObject, Type};
use js::jsval::{BooleanValue, DoubleValue, Int32Value, UInt32Value};
use js::jsval::{JSVal, NullValue, ObjectValue, UndefinedValue};
use js::rust::CustomAutoRooterGuard;
-use js::typedarray::{ArrayBufferView, CreateWith, Uint32, Uint32Array};
+use js::typedarray::{ArrayBufferView, CreateWith, Float32, Uint32, Uint32Array};
use script_layout_interface::HTMLCanvasDataSource;
use std::cell::Cell;
use std::cmp;
@@ -1761,8 +1761,11 @@ impl WebGL2RenderingContextMethods for WebGL2RenderingContext {
location: Option<&WebGLUniformLocation>,
transpose: bool,
v: Float32ArrayOrUnrestrictedFloatSequence,
+ src_offset: u32,
+ src_length: u32,
) {
- self.base.UniformMatrix2fv(location, transpose, v)
+ self.base
+ .UniformMatrix2fv(location, transpose, v, src_offset, src_length)
}
/// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10
@@ -1771,8 +1774,11 @@ impl WebGL2RenderingContextMethods for WebGL2RenderingContext {
location: Option<&WebGLUniformLocation>,
transpose: bool,
v: Float32ArrayOrUnrestrictedFloatSequence,
+ src_offset: u32,
+ src_length: u32,
) {
- self.base.UniformMatrix3fv(location, transpose, v)
+ self.base
+ .UniformMatrix3fv(location, transpose, v, src_offset, src_length)
}
/// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10
@@ -1781,8 +1787,179 @@ impl WebGL2RenderingContextMethods for WebGL2RenderingContext {
location: Option<&WebGLUniformLocation>,
transpose: bool,
v: Float32ArrayOrUnrestrictedFloatSequence,
+ src_offset: u32,
+ src_length: u32,
+ ) {
+ self.base
+ .UniformMatrix4fv(location, transpose, v, src_offset, src_length)
+ }
+
+ /// https://www.khronos.org/registry/webgl/specs/latest/2.0/#3.7.8
+ fn UniformMatrix3x2fv(
+ &self,
+ location: Option<&WebGLUniformLocation>,
+ transpose: bool,
+ val: Float32ArrayOrUnrestrictedFloatSequence,
+ src_offset: u32,
+ src_length: u32,
) {
- self.base.UniformMatrix4fv(location, transpose, v)
+ self.base.with_location(location, |location| {
+ match location.type_() {
+ constants::FLOAT_MAT3x2 => {},
+ _ => return Err(InvalidOperation),
+ }
+ let val = self.base.uniform_matrix_section(
+ val,
+ src_offset,
+ src_length,
+ transpose,
+ 3 * 2,
+ location,
+ )?;
+ self.base
+ .send_command(WebGLCommand::UniformMatrix3x2fv(location.id(), val));
+ Ok(())
+ });
+ }
+
+ /// https://www.khronos.org/registry/webgl/specs/latest/2.0/#3.7.8
+ fn UniformMatrix4x2fv(
+ &self,
+ location: Option<&WebGLUniformLocation>,
+ transpose: bool,
+ val: Float32ArrayOrUnrestrictedFloatSequence,
+ src_offset: u32,
+ src_length: u32,
+ ) {
+ self.base.with_location(location, |location| {
+ match location.type_() {
+ constants::FLOAT_MAT4x2 => {},
+ _ => return Err(InvalidOperation),
+ }
+ let val = self.base.uniform_matrix_section(
+ val,
+ src_offset,
+ src_length,
+ transpose,
+ 4 * 2,
+ location,
+ )?;
+ self.base
+ .send_command(WebGLCommand::UniformMatrix4x2fv(location.id(), val));
+ Ok(())
+ });
+ }
+
+ /// https://www.khronos.org/registry/webgl/specs/latest/2.0/#3.7.8
+ fn UniformMatrix2x3fv(
+ &self,
+ location: Option<&WebGLUniformLocation>,
+ transpose: bool,
+ val: Float32ArrayOrUnrestrictedFloatSequence,
+ src_offset: u32,
+ src_length: u32,
+ ) {
+ self.base.with_location(location, |location| {
+ match location.type_() {
+ constants::FLOAT_MAT2x3 => {},
+ _ => return Err(InvalidOperation),
+ }
+ let val = self.base.uniform_matrix_section(
+ val,
+ src_offset,
+ src_length,
+ transpose,
+ 2 * 3,
+ location,
+ )?;
+ self.base
+ .send_command(WebGLCommand::UniformMatrix2x3fv(location.id(), val));
+ Ok(())
+ });
+ }
+
+ /// https://www.khronos.org/registry/webgl/specs/latest/2.0/#3.7.8
+ fn UniformMatrix4x3fv(
+ &self,
+ location: Option<&WebGLUniformLocation>,
+ transpose: bool,
+ val: Float32ArrayOrUnrestrictedFloatSequence,
+ src_offset: u32,
+ src_length: u32,
+ ) {
+ self.base.with_location(location, |location| {
+ match location.type_() {
+ constants::FLOAT_MAT4x3 => {},
+ _ => return Err(InvalidOperation),
+ }
+ let val = self.base.uniform_matrix_section(
+ val,
+ src_offset,
+ src_length,
+ transpose,
+ 4 * 3,
+ location,
+ )?;
+ self.base
+ .send_command(WebGLCommand::UniformMatrix4x3fv(location.id(), val));
+ Ok(())
+ });
+ }
+
+ /// https://www.khronos.org/registry/webgl/specs/latest/2.0/#3.7.8
+ fn UniformMatrix2x4fv(
+ &self,
+ location: Option<&WebGLUniformLocation>,
+ transpose: bool,
+ val: Float32ArrayOrUnrestrictedFloatSequence,
+ src_offset: u32,
+ src_length: u32,
+ ) {
+ self.base.with_location(location, |location| {
+ match location.type_() {
+ constants::FLOAT_MAT2x4 => {},
+ _ => return Err(InvalidOperation),
+ }
+ let val = self.base.uniform_matrix_section(
+ val,
+ src_offset,
+ src_length,
+ transpose,
+ 2 * 4,
+ location,
+ )?;
+ self.base
+ .send_command(WebGLCommand::UniformMatrix2x4fv(location.id(), val));
+ Ok(())
+ });
+ }
+
+ /// https://www.khronos.org/registry/webgl/specs/latest/2.0/#3.7.8
+ fn UniformMatrix3x4fv(
+ &self,
+ location: Option<&WebGLUniformLocation>,
+ transpose: bool,
+ val: Float32ArrayOrUnrestrictedFloatSequence,
+ src_offset: u32,
+ src_length: u32,
+ ) {
+ self.base.with_location(location, |location| {
+ match location.type_() {
+ constants::FLOAT_MAT3x4 => {},
+ _ => return Err(InvalidOperation),
+ }
+ let val = self.base.uniform_matrix_section(
+ val,
+ src_offset,
+ src_length,
+ transpose,
+ 3 * 4,
+ location,
+ )?;
+ self.base
+ .send_command(WebGLCommand::UniformMatrix3x4fv(location.id(), val));
+ Ok(())
+ });
}
/// https://www.khronos.org/registry/webgl/specs/latest/2.0/#3.7.8
@@ -1814,6 +1991,42 @@ impl WebGL2RenderingContextMethods for WebGL2RenderingContext {
constants::UNSIGNED_INT_VEC4 => unsafe {
uniform_typed::<Uint32>(*cx, &uniform_get(triple, WebGLCommand::GetUniformUint4))
},
+ constants::FLOAT_MAT2x3 => unsafe {
+ uniform_typed::<Float32>(
+ *cx,
+ &uniform_get(triple, WebGLCommand::GetUniformFloat2x3),
+ )
+ },
+ constants::FLOAT_MAT2x4 => unsafe {
+ uniform_typed::<Float32>(
+ *cx,
+ &uniform_get(triple, WebGLCommand::GetUniformFloat2x4),
+ )
+ },
+ constants::FLOAT_MAT3x2 => unsafe {
+ uniform_typed::<Float32>(
+ *cx,
+ &uniform_get(triple, WebGLCommand::GetUniformFloat3x2),
+ )
+ },
+ constants::FLOAT_MAT3x4 => unsafe {
+ uniform_typed::<Float32>(
+ *cx,
+ &uniform_get(triple, WebGLCommand::GetUniformFloat3x4),
+ )
+ },
+ constants::FLOAT_MAT4x2 => unsafe {
+ uniform_typed::<Float32>(
+ *cx,
+ &uniform_get(triple, WebGLCommand::GetUniformFloat4x2),
+ )
+ },
+ constants::FLOAT_MAT4x3 => unsafe {
+ uniform_typed::<Float32>(
+ *cx,
+ &uniform_get(triple, WebGLCommand::GetUniformFloat4x3),
+ )
+ },
_ => self.base.GetUniform(cx, program, location),
}
}