mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
Implement WebGL OES_standard_derivatives extension.
This commit is contained in:
parent
d4e43d9d76
commit
1dd3899c37
9 changed files with 127 additions and 20 deletions
|
@ -892,7 +892,8 @@ impl WebGLImpl {
|
|||
gl::STENCIL_VALUE_MASK |
|
||||
gl::STENCIL_WRITEMASK |
|
||||
gl::SUBPIXEL_BITS |
|
||||
gl::UNPACK_ALIGNMENT =>
|
||||
gl::UNPACK_ALIGNMENT |
|
||||
gl::FRAGMENT_SHADER_DERIVATIVE_HINT =>
|
||||
//gl::UNPACK_COLORSPACE_CONVERSION_WEBGL =>
|
||||
Ok(WebGLParameter::Int(gl.get_integer_v(param_id))),
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLRenderingContextConstants as constants;
|
||||
use super::{ext_constants, WebGLExtension, WebGLExtensions};
|
||||
|
||||
pub mod oesstandardderivatives;
|
||||
pub mod oestexturefloat;
|
||||
pub mod oestexturefloatlinear;
|
||||
pub mod oestexturehalffloat;
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use dom::bindings::codegen::Bindings::OESStandardDerivativesBinding;
|
||||
use dom::bindings::codegen::Bindings::OESStandardDerivativesBinding::OESStandardDerivativesConstants;
|
||||
use dom::bindings::js::Root;
|
||||
use dom::bindings::reflector::{DomObject, Reflector, reflect_dom_object};
|
||||
use dom::webglrenderingcontext::WebGLRenderingContext;
|
||||
use dom_struct::dom_struct;
|
||||
use super::{WebGLExtension, WebGLExtensions};
|
||||
|
||||
#[dom_struct]
|
||||
pub struct OESStandardDerivatives {
|
||||
reflector_: Reflector,
|
||||
}
|
||||
|
||||
impl OESStandardDerivatives {
|
||||
fn new_inherited() -> OESStandardDerivatives {
|
||||
Self {
|
||||
reflector_: Reflector::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl WebGLExtension for OESStandardDerivatives {
|
||||
type Extension = OESStandardDerivatives;
|
||||
fn new(ctx: &WebGLRenderingContext) -> Root<OESStandardDerivatives> {
|
||||
reflect_dom_object(box OESStandardDerivatives::new_inherited(),
|
||||
&*ctx.global(),
|
||||
OESStandardDerivativesBinding::Wrap)
|
||||
}
|
||||
|
||||
fn is_supported(ext: &WebGLExtensions) -> bool {
|
||||
if cfg!(any(target_os = "android", target_os = "ios")) {
|
||||
return ext.supports_any_gl_extension(&["GL_OES_standard_derivatives"]);
|
||||
}
|
||||
// The standard derivatives are always available in desktop OpenGL.
|
||||
true
|
||||
}
|
||||
|
||||
fn enable(ext: &WebGLExtensions) {
|
||||
ext.enable_hint_target(OESStandardDerivativesConstants::FRAGMENT_SHADER_DERIVATIVE_HINT_OES);
|
||||
ext.enable_get_parameter_name(OESStandardDerivativesConstants::FRAGMENT_SHADER_DERIVATIVE_HINT_OES);
|
||||
}
|
||||
|
||||
fn name() -> &'static str {
|
||||
"OES_standard_derivatives"
|
||||
}
|
||||
}
|
|
@ -6,6 +6,7 @@ use canvas_traits::webgl::WebGLError;
|
|||
use core::iter::FromIterator;
|
||||
use core::nonzero::NonZero;
|
||||
use dom::bindings::cell::DOMRefCell;
|
||||
use dom::bindings::codegen::Bindings::OESStandardDerivativesBinding::OESStandardDerivativesConstants;
|
||||
use dom::bindings::codegen::Bindings::OESTextureHalfFloatBinding::OESTextureHalfFloatConstants;
|
||||
use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLRenderingContextConstants as constants;
|
||||
use dom::bindings::js::Root;
|
||||
|
@ -35,6 +36,13 @@ const DEFAULT_NOT_FILTERABLE_TEX_TYPES: [GLenum; 2] = [
|
|||
constants::FLOAT, OESTextureHalfFloatConstants::HALF_FLOAT_OES
|
||||
];
|
||||
|
||||
// Param names that are implemented for getParameter WebGL function
|
||||
// but must trigger a InvalidEnum error until the related WebGL Extensions are enabled.
|
||||
// Example: https://www.khronos.org/registry/webgl/extensions/OES_standard_derivatives/
|
||||
const DEFAULT_DISABLED_GET_PARAMETER_NAMES: [GLenum; 1] = [
|
||||
OESStandardDerivativesConstants::FRAGMENT_SHADER_DERIVATIVE_HINT_OES
|
||||
];
|
||||
|
||||
/// WebGL features that are enabled/disabled by WebGL Extensions.
|
||||
#[derive(JSTraceable, HeapSizeOf)]
|
||||
struct WebGLExtensionFeatures {
|
||||
|
@ -42,7 +50,11 @@ struct WebGLExtensionFeatures {
|
|||
disabled_tex_types: HashSet<GLenum>,
|
||||
not_filterable_tex_types: HashSet<GLenum>,
|
||||
effective_tex_internal_formats: HashMap<TexFormatType, u32>,
|
||||
query_parameter_handlers: HashMap<GLenum, WebGLQueryParameterHandler>
|
||||
query_parameter_handlers: HashMap<GLenum, WebGLQueryParameterHandler>,
|
||||
/// WebGL Hint() targets enabled by extensions.
|
||||
hint_targets: HashSet<GLenum>,
|
||||
/// WebGL GetParameter() names enabled by extensions.
|
||||
disabled_get_parameter_names: HashSet<GLenum>,
|
||||
}
|
||||
|
||||
impl Default for WebGLExtensionFeatures {
|
||||
|
@ -52,7 +64,9 @@ impl Default for WebGLExtensionFeatures {
|
|||
disabled_tex_types: DEFAULT_DISABLED_TEX_TYPES.iter().cloned().collect(),
|
||||
not_filterable_tex_types: DEFAULT_NOT_FILTERABLE_TEX_TYPES.iter().cloned().collect(),
|
||||
effective_tex_internal_formats: HashMap::new(),
|
||||
query_parameter_handlers: HashMap::new()
|
||||
query_parameter_handlers: HashMap::new(),
|
||||
hint_targets: HashSet::new(),
|
||||
disabled_get_parameter_names: DEFAULT_DISABLED_GET_PARAMETER_NAMES.iter().cloned().collect(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -105,8 +119,18 @@ impl WebGLExtensions {
|
|||
})
|
||||
}
|
||||
|
||||
pub fn is_enabled<T>(&self) -> bool
|
||||
where
|
||||
T: 'static + WebGLExtension + JSTraceable + HeapSizeOf
|
||||
{
|
||||
let name = T::name().to_uppercase();
|
||||
self.extensions.borrow().get(&name).map_or(false, |ext| { ext.is_enabled() })
|
||||
}
|
||||
|
||||
pub fn get_dom_object<T>(&self) -> Option<Root<T::Extension>>
|
||||
where T: 'static + WebGLExtension + JSTraceable + HeapSizeOf {
|
||||
where
|
||||
T: 'static + WebGLExtension + JSTraceable + HeapSizeOf
|
||||
{
|
||||
let name = T::name().to_uppercase();
|
||||
self.extensions.borrow().get(&name).and_then(|extension| {
|
||||
extension.as_any().downcast_ref::<TypedWebGLExtensionWrapper<T>>().and_then(|extension| {
|
||||
|
@ -172,7 +196,24 @@ impl WebGLExtensions {
|
|||
})
|
||||
}
|
||||
|
||||
pub fn enable_hint_target(&self, name: GLenum) {
|
||||
self.features.borrow_mut().hint_targets.insert(name);
|
||||
}
|
||||
|
||||
pub fn is_hint_target_enabled(&self, name: GLenum) -> bool {
|
||||
self.features.borrow().hint_targets.contains(&name)
|
||||
}
|
||||
|
||||
pub fn enable_get_parameter_name(&self, name: GLenum) {
|
||||
self.features.borrow_mut().disabled_get_parameter_names.remove(&name);
|
||||
}
|
||||
|
||||
pub fn is_get_parameter_name_enabled(&self, name: GLenum) -> bool {
|
||||
!self.features.borrow().disabled_get_parameter_names.contains(&name)
|
||||
}
|
||||
|
||||
fn register_all_extensions(&self) {
|
||||
self.register::<ext::oesstandardderivatives::OESStandardDerivatives>();
|
||||
self.register::<ext::oestexturefloat::OESTextureFloat>();
|
||||
self.register::<ext::oestexturefloatlinear::OESTextureFloatLinear>();
|
||||
self.register::<ext::oestexturehalffloat::OESTextureHalfFloat>();
|
||||
|
|
|
@ -20,6 +20,7 @@ pub trait WebGLExtensionWrapper: JSTraceable + HeapSizeOf {
|
|||
ext: &WebGLExtensions)
|
||||
-> NonZero<*mut JSObject>;
|
||||
fn is_supported(&self, &WebGLExtensions) -> bool;
|
||||
fn is_enabled(&self) -> bool;
|
||||
fn enable(&self, ext: &WebGLExtensions);
|
||||
fn name(&self) -> &'static str;
|
||||
fn as_any(&self) -> &Any;
|
||||
|
@ -62,7 +63,11 @@ impl<T> WebGLExtensionWrapper for TypedWebGLExtensionWrapper<T>
|
|||
}
|
||||
|
||||
fn is_supported(&self, ext: &WebGLExtensions) -> bool {
|
||||
self.extension.get().is_some() || T::is_supported(ext)
|
||||
self.is_enabled() || T::is_supported(ext)
|
||||
}
|
||||
|
||||
fn is_enabled(&self) -> bool {
|
||||
self.extension.get().is_some()
|
||||
}
|
||||
|
||||
fn enable(&self, ext: &WebGLExtensions) {
|
||||
|
|
|
@ -1222,7 +1222,12 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
|
|||
return Int32Value(constants::UNSIGNED_BYTE as i32);
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
_ => {
|
||||
if !self.extension_manager.is_get_parameter_name_enabled(parameter) {
|
||||
self.webgl_error(WebGLError::InvalidEnum);
|
||||
return NullValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Handle GetParameter getters injected via WebGL extensions
|
||||
|
@ -1832,7 +1837,7 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
|
|||
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.9
|
||||
fn CompileShader(&self, shader: Option<&WebGLShader>) {
|
||||
if let Some(shader) = shader {
|
||||
shader.compile()
|
||||
shader.compile(&self.extension_manager)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2284,7 +2289,7 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
|
|||
|
||||
// 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 {
|
||||
if target != constants::GENERATE_MIPMAP_HINT && !self.extension_manager.is_hint_target_enabled(target) {
|
||||
return self.webgl_error(InvalidEnum);
|
||||
}
|
||||
|
||||
|
|
|
@ -10,6 +10,8 @@ use dom::bindings::codegen::Bindings::WebGLShaderBinding;
|
|||
use dom::bindings::js::Root;
|
||||
use dom::bindings::reflector::reflect_dom_object;
|
||||
use dom::bindings::str::DOMString;
|
||||
use dom::webgl_extensions::WebGLExtensions;
|
||||
use dom::webgl_extensions::ext::oesstandardderivatives::OESStandardDerivatives;
|
||||
use dom::webglobject::WebGLObject;
|
||||
use dom::window::Window;
|
||||
use dom_struct::dom_struct;
|
||||
|
@ -97,7 +99,7 @@ impl WebGLShader {
|
|||
}
|
||||
|
||||
/// glCompileShader
|
||||
pub fn compile(&self) {
|
||||
pub fn compile(&self, ext: &WebGLExtensions) {
|
||||
if self.compilation_status.get() != ShaderCompilationStatus::NotCompiled {
|
||||
debug!("Compiling already compiled shader {}", self.id);
|
||||
}
|
||||
|
@ -105,6 +107,7 @@ impl WebGLShader {
|
|||
if let Some(ref source) = *self.source.borrow() {
|
||||
let mut params = BuiltInResources::default();
|
||||
params.FragmentPrecisionHigh = 1;
|
||||
params.OES_standard_derivatives = ext.is_enabled::<OESStandardDerivatives>() as i32;
|
||||
let validator = ShaderValidator::for_webgl(self.gl_type,
|
||||
SHADER_OUTPUT_FORMAT,
|
||||
¶ms).unwrap();
|
||||
|
|
12
components/script/dom/webidls/OESStandardDerivatives.webidl
Normal file
12
components/script/dom/webidls/OESStandardDerivatives.webidl
Normal file
|
@ -0,0 +1,12 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
/*
|
||||
* WebGL IDL definitions from the Khronos specification:
|
||||
* https://www.khronos.org/registry/webgl/extensions/OES_standard_derivatives/
|
||||
*/
|
||||
|
||||
[NoInterfaceObject]
|
||||
interface OESStandardDerivatives {
|
||||
const GLenum FRAGMENT_SHADER_DERIVATIVE_HINT_OES = 0x8B8B;
|
||||
};
|
|
@ -1,11 +0,0 @@
|
|||
[oes-standard-derivatives.html]
|
||||
type: testharness
|
||||
[WebGL test #3: successfullyParsed should be true (of type boolean). Was undefined (of type undefined).]
|
||||
expected: FAIL
|
||||
|
||||
[WebGL test #0: Unable to fetch WebGL rendering context for Canvas]
|
||||
expected: FAIL
|
||||
|
||||
[WebGL test #1: WebGL context does not exist]
|
||||
expected: FAIL
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue