mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
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. -->
This commit is contained in:
commit
f200e21064
10 changed files with 398 additions and 219 deletions
|
@ -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)
|
||||
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.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),
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue