aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/webglrenderingcontext.rs
diff options
context:
space:
mode:
authorEmilio Cobos Álvarez <ecoal95@gmail.com>2015-12-23 09:22:01 +0100
committerEmilio Cobos Álvarez <ecoal95@gmail.com>2016-01-13 13:41:30 +0100
commit532b53ddc94cd99d737411b635f2fb6a6d50af51 (patch)
treed156993f3a83b170e910fe96b8a48ae383281755 /components/script/dom/webglrenderingcontext.rs
parentee5aead60bba3c6a482960021677aac3d559289b (diff)
downloadservo-532b53ddc94cd99d737411b635f2fb6a6d50af51.tar.gz
servo-532b53ddc94cd99d737411b635f2fb6a6d50af51.zip
webgl: Implement Uniform1f, Uniform1fv, and Uniform4f
I was going to implement Uniform4fv with sequences, (since it practically implemented), but we can't until we support Float32Array args because codegen doesn't know how tu differenciate between both.
Diffstat (limited to 'components/script/dom/webglrenderingcontext.rs')
-rw-r--r--components/script/dom/webglrenderingcontext.rs51
1 files changed, 41 insertions, 10 deletions
diff --git a/components/script/dom/webglrenderingcontext.rs b/components/script/dom/webglrenderingcontext.rs
index 7481b161a77..701ae737ba8 100644
--- a/components/script/dom/webglrenderingcontext.rs
+++ b/components/script/dom/webglrenderingcontext.rs
@@ -930,30 +930,61 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
}
}
- #[allow(unsafe_code)]
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10
- fn Uniform4fv(&self,
- _cx: *mut JSContext,
+ fn Uniform1f(&self,
uniform: Option<&WebGLUniformLocation>,
- data: Option<*mut JSObject>) {
+ val: f32) {
let uniform_id = match uniform {
Some(uniform) => uniform.id(),
None => return,
};
+ self.ipc_renderer
+ .send(CanvasMsg::WebGL(CanvasWebGLMsg::Uniform1f(uniform_id, val)))
+ .unwrap()
+ }
+
+ // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10
+ fn Uniform1fv(&self,
+ uniform: Option<&WebGLUniformLocation>,
+ data: Vec<f32>) {
+ if data.is_empty() {
+ return self.webgl_error(InvalidValue);
+ }
+
+ self.Uniform1f(uniform, data[0]);
+ }
+
+ // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10
+ fn Uniform4f(&self,
+ uniform: Option<&WebGLUniformLocation>,
+ x: f32, y: f32, z: f32, w: f32) {
+ let uniform_id = match uniform {
+ Some(uniform) => uniform.id(),
+ None => return,
+ };
+
+ self.ipc_renderer
+ .send(CanvasMsg::WebGL(CanvasWebGLMsg::Uniform4f(uniform_id, x, y, z, w)))
+ .unwrap()
+ }
+
+ // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10
+ fn Uniform4fv(&self,
+ _cx: *mut JSContext,
+ uniform: Option<&WebGLUniformLocation>,
+ data: Option<*mut JSObject>) {
let data = match data {
Some(data) => data,
- None => return,
+ None => return self.webgl_error(InvalidValue),
};
- if let Some(data_vec) = array_buffer_view_to_vec_checked::<f32>(data) {
- if data_vec.len() < 4 {
+ if let Some(data) = array_buffer_view_to_vec_checked::<f32>(data) {
+ if data.len() < 4 {
return self.webgl_error(InvalidOperation);
}
- self.ipc_renderer
- .send(CanvasMsg::WebGL(CanvasWebGLMsg::Uniform4fv(uniform_id, data_vec)))
- .unwrap()
+ self.Uniform4f(uniform, data[0], data[1], data[2], data[3]);
} else {
self.webgl_error(InvalidValue);
}