aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/webglrenderingcontext.rs
diff options
context:
space:
mode:
authorAnthony Ramine <n.oxyde@gmail.com>2018-04-03 12:22:32 +0200
committerAnthony Ramine <n.oxyde@gmail.com>2018-04-03 12:22:32 +0200
commit866a523914029089f3a4ce17ec70b88f1307ecd4 (patch)
treec828b73fbc335c16ed7da54a0899758458efc93e /components/script/dom/webglrenderingcontext.rs
parent088ebcb095cef24d85a4f5d1d7c525b198333fbf (diff)
downloadservo-866a523914029089f3a4ce17ec70b88f1307ecd4.tar.gz
servo-866a523914029089f3a4ce17ec70b88f1307ecd4.zip
Properly use Float32List and Int32List for WebGL uniform methods
Diffstat (limited to 'components/script/dom/webglrenderingcontext.rs')
-rw-r--r--components/script/dom/webglrenderingcontext.rs228
1 files changed, 90 insertions, 138 deletions
diff --git a/components/script/dom/webglrenderingcontext.rs b/components/script/dom/webglrenderingcontext.rs
index 245a4c81991..4fc569ca331 100644
--- a/components/script/dom/webglrenderingcontext.rs
+++ b/components/script/dom/webglrenderingcontext.rs
@@ -15,7 +15,9 @@ use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::{self, WebGL
use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLRenderingContextConstants as constants;
use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLRenderingContextMethods;
use dom::bindings::codegen::UnionTypes::ArrayBufferViewOrArrayBuffer;
+use dom::bindings::codegen::UnionTypes::Float32ArrayOrUnrestrictedFloatSequence;
use dom::bindings::codegen::UnionTypes::ImageDataOrHTMLImageElementOrHTMLCanvasElementOrHTMLVideoElement;
+use dom::bindings::codegen::UnionTypes::Int32ArrayOrLongSequence;
use dom::bindings::conversions::ToJSValConvertible;
use dom::bindings::error::{Error, ErrorResult};
use dom::bindings::inheritance::Castable;
@@ -50,7 +52,7 @@ use half::f16;
use js::jsapi::{JSContext, JSObject, Type};
use js::jsval::{BooleanValue, DoubleValue, Int32Value, JSVal, NullValue, UndefinedValue};
use js::rust::CustomAutoRooterGuard;
-use js::typedarray::{ArrayBufferView, Float32Array, Int32Array};
+use js::typedarray::ArrayBufferView;
use net_traits::image::base::PixelFormat;
use net_traits::image_cache::ImageResponse;
use offscreen_gl_context::{GLContextAttributes, GLLimits};
@@ -2873,13 +2875,12 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
fn Uniform1iv(
&self,
location: Option<&WebGLUniformLocation>,
- v: CustomAutoRooterGuard<Int32Array>,
+ v: Int32ArrayOrLongSequence,
) {
- self.Uniform1iv_(location, v.to_vec());
- }
-
- // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10
- fn Uniform1iv_(&self, location: Option<&WebGLUniformLocation>, v: Vec<i32>) {
+ let v = match v {
+ Int32ArrayOrLongSequence::Int32Array(v) => v.to_vec(),
+ Int32ArrayOrLongSequence::LongSequence(v) => v,
+ };
if self.validate_uniform_parameters(location, UniformSetterType::Int, &v) {
self.send_command(WebGLCommand::Uniform1iv(location.unwrap().id(), v))
}
@@ -2889,13 +2890,12 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
fn Uniform1fv(
&self,
location: Option<&WebGLUniformLocation>,
- v: CustomAutoRooterGuard<Float32Array>,
+ v: Float32ArrayOrUnrestrictedFloatSequence,
) {
- self.Uniform1fv_(location, v.to_vec());
- }
-
- // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10
- fn Uniform1fv_(&self, location: Option<&WebGLUniformLocation>, v: Vec<f32>) {
+ let v = match v {
+ Float32ArrayOrUnrestrictedFloatSequence::Float32Array(v) => v.to_vec(),
+ Float32ArrayOrUnrestrictedFloatSequence::UnrestrictedFloatSequence(v) => v,
+ };
if self.validate_uniform_parameters(location, UniformSetterType::Float, &v) {
self.send_command(WebGLCommand::Uniform1fv(location.unwrap().id(), v));
}
@@ -2914,16 +2914,13 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
fn Uniform2fv(
&self,
location: Option<&WebGLUniformLocation>,
- v: CustomAutoRooterGuard<Float32Array>,
+ v: Float32ArrayOrUnrestrictedFloatSequence,
) {
- self.Uniform2fv_(location, v.to_vec());
- }
-
- // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10
- fn Uniform2fv_(&self, location: Option<&WebGLUniformLocation>, v: Vec<f32>) {
- if self.validate_uniform_parameters(location,
- UniformSetterType::FloatVec2,
- &v) {
+ let v = match v {
+ Float32ArrayOrUnrestrictedFloatSequence::Float32Array(v) => v.to_vec(),
+ Float32ArrayOrUnrestrictedFloatSequence::UnrestrictedFloatSequence(v) => v,
+ };
+ if self.validate_uniform_parameters(location, UniformSetterType::FloatVec2, &v) {
self.send_command(WebGLCommand::Uniform2fv(location.unwrap().id(), v));
}
}
@@ -2946,16 +2943,13 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
fn Uniform2iv(
&self,
location: Option<&WebGLUniformLocation>,
- v: CustomAutoRooterGuard<Int32Array>,
+ v: Int32ArrayOrLongSequence,
) {
- self.Uniform2iv_(location, v.to_vec());
- }
-
- // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10
- fn Uniform2iv_(&self, location: Option<&WebGLUniformLocation>, v: Vec<i32>) {
- if self.validate_uniform_parameters(location,
- UniformSetterType::IntVec2,
- &v) {
+ let v = match v {
+ Int32ArrayOrLongSequence::Int32Array(v) => v.to_vec(),
+ Int32ArrayOrLongSequence::LongSequence(v) => v,
+ };
+ if self.validate_uniform_parameters(location, UniformSetterType::IntVec2, &v) {
self.send_command(WebGLCommand::Uniform2iv(location.unwrap().id(), v));
}
}
@@ -2979,16 +2973,13 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
fn Uniform3fv(
&self,
location: Option<&WebGLUniformLocation>,
- v: CustomAutoRooterGuard<Float32Array>,
+ v: Float32ArrayOrUnrestrictedFloatSequence,
) {
- self.Uniform3fv_(location, v.to_vec());
- }
-
- // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10
- fn Uniform3fv_(&self, location: Option<&WebGLUniformLocation>, v: Vec<f32>) {
- if self.validate_uniform_parameters(location,
- UniformSetterType::FloatVec3,
- &v) {
+ let v = match v {
+ Float32ArrayOrUnrestrictedFloatSequence::Float32Array(v) => v.to_vec(),
+ Float32ArrayOrUnrestrictedFloatSequence::UnrestrictedFloatSequence(v) => v,
+ };
+ if self.validate_uniform_parameters(location, UniformSetterType::FloatVec3, &v) {
self.send_command(WebGLCommand::Uniform3fv(location.unwrap().id(), v))
}
}
@@ -3008,16 +2999,13 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
fn Uniform3iv(
&self,
location: Option<&WebGLUniformLocation>,
- v: CustomAutoRooterGuard<Int32Array>,
+ v: Int32ArrayOrLongSequence,
) {
- self.Uniform3iv_(location, v.to_vec());
- }
-
- // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10
- fn Uniform3iv_(&self, location: Option<&WebGLUniformLocation>, v: Vec<i32>) {
- if self.validate_uniform_parameters(location,
- UniformSetterType::IntVec3,
- &v) {
+ let v = match v {
+ Int32ArrayOrLongSequence::Int32Array(v) => v.to_vec(),
+ Int32ArrayOrLongSequence::LongSequence(v) => v,
+ };
+ if self.validate_uniform_parameters(location, UniformSetterType::IntVec3, &v) {
self.send_command(WebGLCommand::Uniform3iv(location.unwrap().id(), v))
}
}
@@ -3043,16 +3031,13 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
fn Uniform4iv(
&self,
location: Option<&WebGLUniformLocation>,
- v: CustomAutoRooterGuard<Int32Array>,
+ v: Int32ArrayOrLongSequence,
) {
- self.Uniform4iv_(location, v.to_vec());
- }
-
- // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10
- fn Uniform4iv_(&self, location: Option<&WebGLUniformLocation>, v: Vec<i32>) {
- if self.validate_uniform_parameters(location,
- UniformSetterType::IntVec4,
- &v) {
+ let v = match v {
+ Int32ArrayOrLongSequence::Int32Array(v) => v.to_vec(),
+ Int32ArrayOrLongSequence::LongSequence(v) => v,
+ };
+ if self.validate_uniform_parameters(location, UniformSetterType::IntVec4, &v) {
self.send_command(WebGLCommand::Uniform4iv(location.unwrap().id(), v))
}
}
@@ -3077,16 +3062,13 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
fn Uniform4fv(
&self,
location: Option<&WebGLUniformLocation>,
- v: CustomAutoRooterGuard<Float32Array>,
+ v: Float32ArrayOrUnrestrictedFloatSequence,
) {
- self.Uniform4fv_(location, v.to_vec());
- }
-
- // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10
- fn Uniform4fv_(&self, location: Option<&WebGLUniformLocation>, v: Vec<f32>) {
- if self.validate_uniform_parameters(location,
- UniformSetterType::FloatVec4,
- &v) {
+ let v = match v {
+ Float32ArrayOrUnrestrictedFloatSequence::Float32Array(v) => v.to_vec(),
+ Float32ArrayOrUnrestrictedFloatSequence::UnrestrictedFloatSequence(v) => v,
+ };
+ if self.validate_uniform_parameters(location, UniformSetterType::FloatVec4, &v) {
self.send_command(WebGLCommand::Uniform4fv(location.unwrap().id(), v))
}
}
@@ -3096,20 +3078,14 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
&self,
location: Option<&WebGLUniformLocation>,
transpose: bool,
- v: CustomAutoRooterGuard<Float32Array>,
+ v: Float32ArrayOrUnrestrictedFloatSequence,
) {
- self.UniformMatrix2fv_(location, transpose, v.to_vec());
- }
-
- // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10
- fn UniformMatrix2fv_(&self,
- location: Option<&WebGLUniformLocation>,
- transpose: bool,
- value: Vec<f32>) {
- if self.validate_uniform_parameters(location,
- UniformSetterType::FloatMat2,
- &value) {
- self.send_command(WebGLCommand::UniformMatrix2fv(location.unwrap().id(), transpose, value));
+ let v = match v {
+ Float32ArrayOrUnrestrictedFloatSequence::Float32Array(v) => v.to_vec(),
+ Float32ArrayOrUnrestrictedFloatSequence::UnrestrictedFloatSequence(v) => v,
+ };
+ if self.validate_uniform_parameters(location, UniformSetterType::FloatMat2, &v) {
+ self.send_command(WebGLCommand::UniformMatrix2fv(location.unwrap().id(), transpose, v));
}
}
@@ -3118,22 +3094,14 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
&self,
location: Option<&WebGLUniformLocation>,
transpose: bool,
- v: CustomAutoRooterGuard<Float32Array>,
- ) {
- self.UniformMatrix3fv_(location, transpose, v.to_vec());
- }
-
- // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10
- fn UniformMatrix3fv_(
- &self,
- location: Option<&WebGLUniformLocation>,
- transpose: bool,
- value: Vec<f32>,
+ v: Float32ArrayOrUnrestrictedFloatSequence,
) {
- if self.validate_uniform_parameters(location,
- UniformSetterType::FloatMat3,
- &value) {
- self.send_command(WebGLCommand::UniformMatrix3fv(location.unwrap().id(), transpose, value));
+ let v = match v {
+ Float32ArrayOrUnrestrictedFloatSequence::Float32Array(v) => v.to_vec(),
+ Float32ArrayOrUnrestrictedFloatSequence::UnrestrictedFloatSequence(v) => v,
+ };
+ if self.validate_uniform_parameters(location, UniformSetterType::FloatMat3, &v) {
+ self.send_command(WebGLCommand::UniformMatrix3fv(location.unwrap().id(), transpose, v));
}
}
@@ -3142,22 +3110,14 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
&self,
location: Option<&WebGLUniformLocation>,
transpose: bool,
- v: CustomAutoRooterGuard<Float32Array>,
+ v: Float32ArrayOrUnrestrictedFloatSequence,
) {
- self.UniformMatrix4fv_(location, transpose, v.to_vec());
- }
-
- // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10
- fn UniformMatrix4fv_(
- &self,
- location: Option<&WebGLUniformLocation>,
- transpose: bool,
- value: Vec<f32>,
- ) {
- if self.validate_uniform_parameters(location,
- UniformSetterType::FloatMat4,
- &value) {
- self.send_command(WebGLCommand::UniformMatrix4fv(location.unwrap().id(), transpose, value));
+ let v = match v {
+ Float32ArrayOrUnrestrictedFloatSequence::Float32Array(v) => v.to_vec(),
+ Float32ArrayOrUnrestrictedFloatSequence::UnrestrictedFloatSequence(v) => v,
+ };
+ if self.validate_uniform_parameters(location, UniformSetterType::FloatMat4, &v) {
+ self.send_command(WebGLCommand::UniformMatrix4fv(location.unwrap().id(), transpose, v));
}
}
@@ -3184,16 +3144,14 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
}
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10
- fn VertexAttrib1fv(&self, indx: u32, v: CustomAutoRooterGuard<Float32Array>) {
- self.VertexAttrib1fv_(indx, v.to_vec());
- }
-
- // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10
- fn VertexAttrib1fv_(&self, indx: u32, values: Vec<f32>) {
+ fn VertexAttrib1fv(&self, indx: u32, v: Float32ArrayOrUnrestrictedFloatSequence) {
+ let values = match v {
+ Float32ArrayOrUnrestrictedFloatSequence::Float32Array(v) => v.to_vec(),
+ Float32ArrayOrUnrestrictedFloatSequence::UnrestrictedFloatSequence(v) => v,
+ };
if values.len() < 1 {
return self.webgl_error(InvalidOperation);
}
-
self.vertex_attrib(indx, values[0], 0f32, 0f32, 1f32);
}
@@ -3203,16 +3161,14 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
}
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10
- fn VertexAttrib2fv(&self, indx: u32, v: CustomAutoRooterGuard<Float32Array>) {
- self.VertexAttrib2fv_(indx, v.to_vec());
- }
-
- // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10
- fn VertexAttrib2fv_(&self, indx: u32, values: Vec<f32>) {
+ fn VertexAttrib2fv(&self, indx: u32, v: Float32ArrayOrUnrestrictedFloatSequence) {
+ let values = match v {
+ Float32ArrayOrUnrestrictedFloatSequence::Float32Array(v) => v.to_vec(),
+ Float32ArrayOrUnrestrictedFloatSequence::UnrestrictedFloatSequence(v) => v,
+ };
if values.len() < 2 {
return self.webgl_error(InvalidOperation);
}
-
self.vertex_attrib(indx, values[0], values[1], 0f32, 1f32);
}
@@ -3222,16 +3178,14 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
}
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10
- fn VertexAttrib3fv(&self, indx: u32, v: CustomAutoRooterGuard<Float32Array>) {
- self.VertexAttrib3fv_(indx, v.to_vec());
- }
-
- // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10
- fn VertexAttrib3fv_(&self, indx: u32, values: Vec<f32>) {
+ fn VertexAttrib3fv(&self, indx: u32, v: Float32ArrayOrUnrestrictedFloatSequence) {
+ let values = match v {
+ Float32ArrayOrUnrestrictedFloatSequence::Float32Array(v) => v.to_vec(),
+ Float32ArrayOrUnrestrictedFloatSequence::UnrestrictedFloatSequence(v) => v,
+ };
if values.len() < 3 {
return self.webgl_error(InvalidOperation);
}
-
self.vertex_attrib(indx, values[0], values[1], values[2], 1f32);
}
@@ -3241,16 +3195,14 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
}
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10
- fn VertexAttrib4fv(&self, indx: u32, v: CustomAutoRooterGuard<Float32Array>) {
- self.VertexAttrib4fv_(indx, v.to_vec());
- }
-
- // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10
- fn VertexAttrib4fv_(&self, indx: u32, values: Vec<f32>) {
+ fn VertexAttrib4fv(&self, indx: u32, v: Float32ArrayOrUnrestrictedFloatSequence) {
+ let values = match v {
+ Float32ArrayOrUnrestrictedFloatSequence::Float32Array(v) => v.to_vec(),
+ Float32ArrayOrUnrestrictedFloatSequence::UnrestrictedFloatSequence(v) => v,
+ };
if values.len() < 4 {
return self.webgl_error(InvalidOperation);
}
-
self.vertex_attrib(indx, values[0], values[1], values[2], values[3]);
}