diff options
author | Anthony Ramine <n.oxyde@gmail.com> | 2018-07-11 11:55:25 +0200 |
---|---|---|
committer | Anthony Ramine <n.oxyde@gmail.com> | 2018-07-16 10:16:29 +0200 |
commit | cbac5d05be13888fa78fcb4678f1620860b80228 (patch) | |
tree | b91817877382fef7e8052e232d0c50ae4c120e7e /components/script/dom/webglprogram.rs | |
parent | a5b800970a91139ca9790cd6417576e7cc4ff6e9 (diff) | |
download | servo-cbac5d05be13888fa78fcb4678f1620860b80228.tar.gz servo-cbac5d05be13888fa78fcb4678f1620860b80228.zip |
Store active uniforms on the DOM side
Diffstat (limited to 'components/script/dom/webglprogram.rs')
-rw-r--r-- | components/script/dom/webglprogram.rs | 65 |
1 files changed, 40 insertions, 25 deletions
diff --git a/components/script/dom/webglprogram.rs b/components/script/dom/webglprogram.rs index d5902e1afff..e2a6f8fcf8d 100644 --- a/components/script/dom/webglprogram.rs +++ b/components/script/dom/webglprogram.rs @@ -3,9 +3,8 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ // https://www.khronos.org/registry/webgl/specs/latest/1.0/webgl.idl -use canvas_traits::webgl::{ActiveAttribInfo, WebGLCommand, WebGLError, WebGLMsgSender}; -use canvas_traits::webgl::{WebGLProgramId, WebGLResult, from_name_in_compiled_shader}; -use canvas_traits::webgl::{to_name_in_compiled_shader, webgl_channel}; +use canvas_traits::webgl::{ActiveAttribInfo, ActiveUniformInfo, WebGLCommand, WebGLError, WebGLMsgSender}; +use canvas_traits::webgl::{WebGLProgramId, WebGLResult, to_name_in_compiled_shader, webgl_channel}; use dom::bindings::cell::DomRefCell; use dom::bindings::codegen::Bindings::WebGLProgramBinding; use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLRenderingContextConstants as constants; @@ -33,6 +32,7 @@ pub struct WebGLProgram { #[ignore_malloc_size_of = "Defined in ipc-channel"] renderer: WebGLMsgSender, active_attribs: DomRefCell<Box<[ActiveAttribInfo]>>, + active_uniforms: DomRefCell<Box<[ActiveUniformInfo]>>, } impl WebGLProgram { @@ -49,6 +49,7 @@ impl WebGLProgram { vertex_shader: Default::default(), renderer: renderer, active_attribs: DomRefCell::new(vec![].into()), + active_uniforms: DomRefCell::new(vec![].into()), } } @@ -123,20 +124,30 @@ impl WebGLProgram { self.renderer.send(WebGLCommand::LinkProgram(self.id, sender)).unwrap(); let link_info = receiver.recv().unwrap(); - // https://www.khronos.org/registry/webgl/specs/latest/1.0/#6.31 - let mut used_locs = FnvHashSet::default(); - for active_attrib in &*link_info.active_attribs { - if active_attrib.location == -1 { - continue; + { + let mut used_locs = FnvHashSet::default(); + let mut used_names = FnvHashSet::default(); + for active_attrib in &*link_info.active_attribs { + if active_attrib.location == -1 { + continue; + } + let columns = match active_attrib.type_ { + constants::FLOAT_MAT2 => 2, + constants::FLOAT_MAT3 => 3, + constants::FLOAT_MAT4 => 4, + _ => 1, + }; + assert!(used_names.insert(&*active_attrib.name)); + for column in 0..columns { + // https://www.khronos.org/registry/webgl/specs/latest/1.0/#6.31 + if !used_locs.insert(active_attrib.location as u32 + column) { + return Ok(()); + } + } } - let columns = match active_attrib.type_ { - constants::FLOAT_MAT2 => 2, - constants::FLOAT_MAT3 => 3, - constants::FLOAT_MAT4 => 4, - _ => 1, - }; - for column in 0..columns { - if !used_locs.insert(active_attrib.location as u32 + column) { + for active_uniform in &*link_info.active_uniforms { + // https://www.khronos.org/registry/webgl/specs/latest/1.0/#6.41 + if !used_names.insert(&*active_uniform.name) { return Ok(()); } } @@ -144,6 +155,7 @@ impl WebGLProgram { self.linked.set(link_info.linked); *self.active_attribs.borrow_mut() = link_info.active_attribs; + *self.active_uniforms.borrow_mut() = link_info.active_uniforms; Ok(()) } @@ -151,6 +163,10 @@ impl WebGLProgram { Ref::map(self.active_attribs.borrow(), |attribs| &**attribs) } + pub fn active_uniforms(&self) -> Ref<[ActiveUniformInfo]> { + Ref::map(self.active_uniforms.borrow(), |uniforms| &**uniforms) + } + /// glValidateProgram pub fn validate(&self) -> WebGLResult<()> { if self.is_deleted() { @@ -244,15 +260,14 @@ impl WebGLProgram { if self.is_deleted() { return Err(WebGLError::InvalidValue); } - let (sender, receiver) = webgl_channel().unwrap(); - self.renderer - .send(WebGLCommand::GetActiveUniform(self.id, index, sender)) - .unwrap(); - - receiver.recv().unwrap().map(|(size, ty, name)| { - let name = DOMString::from(from_name_in_compiled_shader(&name)); - WebGLActiveInfo::new(self.global().as_window(), size, ty, name) - }) + let uniforms = self.active_uniforms.borrow(); + let data = uniforms.get(index as usize).ok_or(WebGLError::InvalidValue)?; + Ok(WebGLActiveInfo::new( + self.global().as_window(), + data.size, + data.type_, + data.name.clone().into(), + )) } /// glGetActiveAttrib |