aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/webglrenderingcontext.rs
diff options
context:
space:
mode:
authorDavid Zbarsky <dzbarsky@gmail.com>2016-04-21 00:29:53 -0700
committerDavid Zbarsky <dzbarsky@gmail.com>2016-05-12 23:56:10 -0700
commit2bf016ff149da46f8957b959a61d5c5a6afb682a (patch)
tree851e788ae0488d14d42a1298adb86acc4f22839d /components/script/dom/webglrenderingcontext.rs
parent03465ad8c77f03ae2f538d046ae1e1dc86f04723 (diff)
downloadservo-2bf016ff149da46f8957b959a61d5c5a6afb682a.tar.gz
servo-2bf016ff149da46f8957b959a61d5c5a6afb682a.zip
Implement GetVertexAttrib
Diffstat (limited to 'components/script/dom/webglrenderingcontext.rs')
-rw-r--r--components/script/dom/webglrenderingcontext.rs39
1 files changed, 39 insertions, 0 deletions
diff --git a/components/script/dom/webglrenderingcontext.rs b/components/script/dom/webglrenderingcontext.rs
index 70b98ce06cd..4223598a985 100644
--- a/components/script/dom/webglrenderingcontext.rs
+++ b/components/script/dom/webglrenderingcontext.rs
@@ -83,6 +83,8 @@ pub struct WebGLRenderingContext {
bound_buffer_array: MutNullableHeap<JS<WebGLBuffer>>,
bound_buffer_element_array: MutNullableHeap<JS<WebGLBuffer>>,
current_program: MutNullableHeap<JS<WebGLProgram>>,
+ #[ignore_heap_size_of = "Because it's small"]
+ current_vertex_attrib_0: Cell<(f32, f32, f32, f32)>,
}
impl WebGLRenderingContext {
@@ -111,6 +113,7 @@ impl WebGLRenderingContext {
bound_buffer_array: MutNullableHeap::new(None),
bound_buffer_element_array: MutNullableHeap::new(None),
current_program: MutNullableHeap::new(None),
+ current_vertex_attrib_0: Cell::new((0f32, 0f32, 0f32, 1f32)),
}
})
}
@@ -175,6 +178,10 @@ impl WebGLRenderingContext {
return self.webgl_error(InvalidValue);
}
+ if indx == 0 {
+ self.current_vertex_attrib_0.set((x, y, z, w))
+ }
+
self.ipc_renderer
.send(CanvasMsg::WebGL(WebGLCommand::VertexAttrib(indx, x, y, z, w)))
.unwrap();
@@ -1138,6 +1145,38 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
})
}
+ #[allow(unsafe_code)]
+ // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.9
+ fn GetVertexAttrib(&self, cx: *mut JSContext, index: u32, pname: u32) -> JSVal {
+ if index == 0 && pname == constants::CURRENT_VERTEX_ATTRIB {
+ let mut result = RootedValue::new(cx, UndefinedValue());
+ let (x, y, z, w) = self.current_vertex_attrib_0.get();
+ let attrib = vec![x, y, z, w];
+ unsafe {
+ attrib.to_jsval(cx, result.handle_mut());
+ }
+ return result.ptr
+ }
+
+ let (sender, receiver) = ipc::channel().unwrap();
+ self.ipc_renderer.send(CanvasMsg::WebGL(WebGLCommand::GetVertexAttrib(index, pname, sender))).unwrap();
+
+ match handle_potential_webgl_error!(self, receiver.recv().unwrap(), WebGLParameter::Invalid) {
+ WebGLParameter::Int(val) => Int32Value(val),
+ WebGLParameter::Bool(val) => BooleanValue(val),
+ WebGLParameter::String(_) => panic!("Vertex attrib should not be string"),
+ WebGLParameter::Float(_) => panic!("Vertex attrib should not be float"),
+ WebGLParameter::FloatArray(val) => {
+ let mut result = RootedValue::new(cx, UndefinedValue());
+ unsafe {
+ val.to_jsval(cx, result.handle_mut());
+ }
+ result.ptr
+ }
+ WebGLParameter::Invalid => NullValue(),
+ }
+ }
+
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.3
fn Hint(&self, target: u32, mode: u32) {
if target != constants::GENERATE_MIPMAP_HINT {