aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/webglshader.rs
diff options
context:
space:
mode:
Diffstat (limited to 'components/script/dom/webglshader.rs')
-rw-r--r--components/script/dom/webglshader.rs43
1 files changed, 32 insertions, 11 deletions
diff --git a/components/script/dom/webglshader.rs b/components/script/dom/webglshader.rs
index 3ce6b93ad77..4a50a6d97f3 100644
--- a/components/script/dom/webglshader.rs
+++ b/components/script/dom/webglshader.rs
@@ -4,8 +4,8 @@
// 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 canvas_traits::webgl::WebGLVersion;
use dom::bindings::cell::DomRefCell;
use dom::bindings::codegen::Bindings::WebGLShaderBinding;
use dom::bindings::reflector::reflect_dom_object;
@@ -40,12 +40,6 @@ pub struct WebGLShader {
renderer: WebGLMsgSender,
}
-#[cfg(not(target_os = "android"))]
-const SHADER_OUTPUT_FORMAT: Output = Output::Glsl;
-
-#[cfg(target_os = "android")]
-const SHADER_OUTPUT_FORMAT: Output = Output::Essl;
-
static GLSLANG_INITIALIZATION: Once = ONCE_INIT;
impl WebGLShader {
@@ -100,7 +94,12 @@ impl WebGLShader {
}
/// glCompileShader
- pub fn compile(&self, version: WebGLVersion, ext: &WebGLExtensions) {
+ pub fn compile(
+ &self,
+ webgl_version: WebGLVersion,
+ glsl_version: WebGLSLVersion,
+ ext: &WebGLExtensions
+ ) {
if self.compilation_status.get() != ShaderCompilationStatus::NotCompiled {
debug!("Compiling already compiled shader {}", self.id);
}
@@ -109,15 +108,37 @@ impl WebGLShader {
let mut params = BuiltInResources::default();
params.FragmentPrecisionHigh = 1;
params.OES_standard_derivatives = ext.is_enabled::<OESStandardDerivatives>() as i32;
- let validator = match version {
+ let validator = match webgl_version {
WebGLVersion::WebGL1 => {
+ let output_format = if cfg!(any(target_os = "android", target_os = "ios")) {
+ Output::Essl
+ } else {
+ Output::Glsl
+ };
ShaderValidator::for_webgl(self.gl_type,
- SHADER_OUTPUT_FORMAT,
+ output_format,
&params).unwrap()
},
WebGLVersion::WebGL2 => {
+ let output_format = if cfg!(any(target_os = "android", target_os = "ios")) {
+ Output::Essl
+ } else {
+ match (glsl_version.major, glsl_version.minor) {
+ (1, 30) => Output::Glsl130,
+ (1, 40) => Output::Glsl140,
+ (1, 50) => Output::Glsl150Core,
+ (3, 30) => Output::Glsl330Core,
+ (4, 0) => Output::Glsl400Core,
+ (4, 10) => Output::Glsl410Core,
+ (4, 20) => Output::Glsl420Core,
+ (4, 30) => Output::Glsl430Core,
+ (4, 40) => Output::Glsl440Core,
+ (4, _) => Output::Glsl450Core,
+ _ => Output::Glsl140
+ }
+ };
ShaderValidator::for_webgl2(self.gl_type,
- SHADER_OUTPUT_FORMAT,
+ output_format,
&params).unwrap()
},
};