mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Auto merge of #20216 - servo:mozangle, r=emilio
Switch from servo/angle to the mozangle crate https://github.com/servo/mozangle <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/20216) <!-- Reviewable:end -->
This commit is contained in:
commit
345c373192
5 changed files with 81 additions and 28 deletions
|
@ -31,6 +31,46 @@ pub struct WebGLProgram {
|
|||
renderer: WebGLMsgSender,
|
||||
}
|
||||
|
||||
/// ANGLE adds a `_u` prefix to variable names:
|
||||
///
|
||||
/// https://chromium.googlesource.com/angle/angle/+/855d964bd0d05f6b2cb303f625506cf53d37e94f
|
||||
///
|
||||
/// To avoid hard-coding this we would need to use the `sh::GetAttributes` and `sh::GetUniforms`
|
||||
/// API to look up the `x.name` and `x.mappedName` members,
|
||||
/// then build a data structure for bi-directional lookup (so either linear scan or two hashmaps).
|
||||
/// Even then, this would probably only support plain variable names like "foo".
|
||||
/// Strings passed to e.g. `GetUniformLocation` can be expressions like "foo[0].bar",
|
||||
/// with the mapping for that "bar" name in yet another part of ANGLE’s API.
|
||||
const ANGLE_NAME_PREFIX: &'static str = "_u";
|
||||
|
||||
fn to_name_in_compiled_shader(s: &str) -> String {
|
||||
map_dot_separated(s, |s, mapped| {
|
||||
mapped.push_str(ANGLE_NAME_PREFIX);
|
||||
mapped.push_str(s);
|
||||
})
|
||||
}
|
||||
|
||||
fn from_name_in_compiled_shader(s: &str) -> String {
|
||||
map_dot_separated(s, |s, mapped| {
|
||||
mapped.push_str(if s.starts_with(ANGLE_NAME_PREFIX) {
|
||||
&s[ANGLE_NAME_PREFIX.len()..]
|
||||
} else {
|
||||
s
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
fn map_dot_separated<F: Fn(&str, &mut String)>(s: &str, f: F) -> String {
|
||||
let mut iter = s.split('.');
|
||||
let mut mapped = String::new();
|
||||
f(iter.next().unwrap(), &mut mapped);
|
||||
for s in iter {
|
||||
mapped.push('.');
|
||||
f(s, &mut mapped);
|
||||
}
|
||||
mapped
|
||||
}
|
||||
|
||||
impl WebGLProgram {
|
||||
fn new_inherited(renderer: WebGLMsgSender,
|
||||
id: WebGLProgramId)
|
||||
|
@ -213,8 +253,10 @@ impl WebGLProgram {
|
|||
return Err(WebGLError::InvalidOperation);
|
||||
}
|
||||
|
||||
let name = to_name_in_compiled_shader(&name);
|
||||
|
||||
self.renderer
|
||||
.send(WebGLCommand::BindAttribLocation(self.id, index, String::from(name)))
|
||||
.send(WebGLCommand::BindAttribLocation(self.id, index, name))
|
||||
.unwrap();
|
||||
Ok(())
|
||||
}
|
||||
|
@ -228,8 +270,10 @@ impl WebGLProgram {
|
|||
.send(WebGLCommand::GetActiveUniform(self.id, index, sender))
|
||||
.unwrap();
|
||||
|
||||
receiver.recv().unwrap().map(|(size, ty, name)|
|
||||
WebGLActiveInfo::new(self.global().as_window(), size, ty, DOMString::from(name)))
|
||||
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)
|
||||
})
|
||||
}
|
||||
|
||||
/// glGetActiveAttrib
|
||||
|
@ -242,8 +286,10 @@ impl WebGLProgram {
|
|||
.send(WebGLCommand::GetActiveAttrib(self.id, index, sender))
|
||||
.unwrap();
|
||||
|
||||
receiver.recv().unwrap().map(|(size, ty, name)|
|
||||
WebGLActiveInfo::new(self.global().as_window(), size, ty, DOMString::from(name)))
|
||||
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)
|
||||
})
|
||||
}
|
||||
|
||||
/// glGetAttribLocation
|
||||
|
@ -264,9 +310,11 @@ impl WebGLProgram {
|
|||
return Ok(None);
|
||||
}
|
||||
|
||||
let name = to_name_in_compiled_shader(&name);
|
||||
|
||||
let (sender, receiver) = webgl_channel().unwrap();
|
||||
self.renderer
|
||||
.send(WebGLCommand::GetAttribLocation(self.id, String::from(name), sender))
|
||||
.send(WebGLCommand::GetAttribLocation(self.id, name, sender))
|
||||
.unwrap();
|
||||
Ok(receiver.recv().unwrap())
|
||||
}
|
||||
|
@ -285,9 +333,11 @@ impl WebGLProgram {
|
|||
return Ok(None);
|
||||
}
|
||||
|
||||
let name = to_name_in_compiled_shader(&name);
|
||||
|
||||
let (sender, receiver) = webgl_channel().unwrap();
|
||||
self.renderer
|
||||
.send(WebGLCommand::GetUniformLocation(self.id, String::from(name), sender))
|
||||
.send(WebGLCommand::GetUniformLocation(self.id, name, sender))
|
||||
.unwrap();
|
||||
Ok(receiver.recv().unwrap())
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
* 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 angle::hl::{BuiltInResources, Output, ShaderValidator};
|
||||
use canvas_traits::webgl::{WebGLSLVersion, WebGLVersion};
|
||||
use canvas_traits::webgl::{webgl_channel, WebGLCommand, WebGLMsgSender, WebGLParameter, WebGLResult, WebGLShaderId};
|
||||
use dom::bindings::cell::DomRefCell;
|
||||
|
@ -16,6 +15,7 @@ use dom::webgl_extensions::ext::oesstandardderivatives::OESStandardDerivatives;
|
|||
use dom::webglobject::WebGLObject;
|
||||
use dom::window::Window;
|
||||
use dom_struct::dom_struct;
|
||||
use mozangle::shaders::{BuiltInResources, Output, ShaderValidator};
|
||||
use std::cell::Cell;
|
||||
use std::sync::{ONCE_INIT, Once};
|
||||
|
||||
|
@ -47,7 +47,7 @@ impl WebGLShader {
|
|||
id: WebGLShaderId,
|
||||
shader_type: u32)
|
||||
-> WebGLShader {
|
||||
GLSLANG_INITIALIZATION.call_once(|| ::angle::hl::initialize().unwrap());
|
||||
GLSLANG_INITIALIZATION.call_once(|| ::mozangle::shaders::initialize().unwrap());
|
||||
WebGLShader {
|
||||
webgl_object: WebGLObject::new_inherited(),
|
||||
id: id,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue