mirror of
https://github.com/servo/servo.git
synced 2025-07-22 23:03:42 +01:00
Auto merge of #19040 - MortimerGoro:webgl2_extensions, r=emilio
Add support for filtering WebGL extensions based on WebGL version <!-- Please describe your changes on the following line: --> Add support for filtering WebGL extensions based on WebGL version --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [ ] These changes fix #__ (github issue number if applicable). <!-- Either: --> - [x] There are tests for these changes OR - [ ] These changes do not require tests because _____ <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- 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/19040) <!-- Reviewable:end -->
This commit is contained in:
commit
63af764fc5
13 changed files with 87 additions and 25 deletions
|
@ -74,7 +74,7 @@ pub enum WebGLContextShareMode {
|
|||
}
|
||||
|
||||
/// Defines the WebGL version
|
||||
#[derive(Clone, Copy, Deserialize, MallocSizeOf, Serialize)]
|
||||
#[derive(Clone, Copy, Deserialize, Eq, MallocSizeOf, PartialEq, Serialize)]
|
||||
pub enum WebGLVersion {
|
||||
/// https://www.khronos.org/registry/webgl/specs/1.0.2/
|
||||
/// Conforms closely to the OpenGL ES 2.0 API
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLRenderingContextConstants as constants;
|
||||
use super::{ext_constants, WebGLExtension, WebGLExtensions};
|
||||
use super::{ext_constants, WebGLExtension, WebGLExtensions, WebGLExtensionSpec};
|
||||
|
||||
pub mod oesstandardderivatives;
|
||||
pub mod oestexturefloat;
|
||||
|
|
|
@ -2,13 +2,14 @@
|
|||
* 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 canvas_traits::webgl::WebGLVersion;
|
||||
use dom::bindings::codegen::Bindings::OESStandardDerivativesBinding;
|
||||
use dom::bindings::codegen::Bindings::OESStandardDerivativesBinding::OESStandardDerivativesConstants;
|
||||
use dom::bindings::reflector::{DomObject, Reflector, reflect_dom_object};
|
||||
use dom::bindings::root::DomRoot;
|
||||
use dom::webglrenderingcontext::WebGLRenderingContext;
|
||||
use dom_struct::dom_struct;
|
||||
use super::{WebGLExtension, WebGLExtensions};
|
||||
use super::{WebGLExtension, WebGLExtensions, WebGLExtensionSpec};
|
||||
|
||||
#[dom_struct]
|
||||
pub struct OESStandardDerivatives {
|
||||
|
@ -31,6 +32,10 @@ impl WebGLExtension for OESStandardDerivatives {
|
|||
OESStandardDerivativesBinding::Wrap)
|
||||
}
|
||||
|
||||
fn spec() -> WebGLExtensionSpec {
|
||||
WebGLExtensionSpec::Specific(WebGLVersion::WebGL1)
|
||||
}
|
||||
|
||||
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"]);
|
||||
|
|
|
@ -2,12 +2,13 @@
|
|||
* 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 canvas_traits::webgl::WebGLVersion;
|
||||
use dom::bindings::codegen::Bindings::OESTextureFloatBinding;
|
||||
use dom::bindings::reflector::{DomObject, Reflector, reflect_dom_object};
|
||||
use dom::bindings::root::DomRoot;
|
||||
use dom::webglrenderingcontext::WebGLRenderingContext;
|
||||
use dom_struct::dom_struct;
|
||||
use super::{constants as webgl, ext_constants as gl, WebGLExtension, WebGLExtensions};
|
||||
use super::{constants as webgl, ext_constants as gl, WebGLExtension, WebGLExtensions, WebGLExtensionSpec};
|
||||
|
||||
#[dom_struct]
|
||||
pub struct OESTextureFloat {
|
||||
|
@ -30,6 +31,10 @@ impl WebGLExtension for OESTextureFloat {
|
|||
OESTextureFloatBinding::Wrap)
|
||||
}
|
||||
|
||||
fn spec() -> WebGLExtensionSpec {
|
||||
WebGLExtensionSpec::Specific(WebGLVersion::WebGL1)
|
||||
}
|
||||
|
||||
fn is_supported(ext: &WebGLExtensions) -> bool {
|
||||
ext.supports_any_gl_extension(&["GL_OES_texture_float",
|
||||
"GL_ARB_texture_float",
|
||||
|
|
|
@ -7,7 +7,7 @@ use dom::bindings::reflector::{DomObject, Reflector, reflect_dom_object};
|
|||
use dom::bindings::root::DomRoot;
|
||||
use dom::webglrenderingcontext::WebGLRenderingContext;
|
||||
use dom_struct::dom_struct;
|
||||
use super::{constants as webgl, WebGLExtension, WebGLExtensions};
|
||||
use super::{constants as webgl, WebGLExtension, WebGLExtensions, WebGLExtensionSpec};
|
||||
|
||||
#[dom_struct]
|
||||
pub struct OESTextureFloatLinear {
|
||||
|
@ -30,6 +30,10 @@ impl WebGLExtension for OESTextureFloatLinear {
|
|||
OESTextureFloatLinearBinding::Wrap)
|
||||
}
|
||||
|
||||
fn spec() -> WebGLExtensionSpec {
|
||||
WebGLExtensionSpec::All
|
||||
}
|
||||
|
||||
fn is_supported(ext: &WebGLExtensions) -> bool {
|
||||
ext.supports_any_gl_extension(&["GL_OES_texture_float_linear",
|
||||
"GL_ARB_texture_float"])
|
||||
|
|
|
@ -2,12 +2,13 @@
|
|||
* 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 canvas_traits::webgl::WebGLVersion;
|
||||
use dom::bindings::codegen::Bindings::OESTextureHalfFloatBinding::{self, OESTextureHalfFloatConstants};
|
||||
use dom::bindings::reflector::{DomObject, Reflector, reflect_dom_object};
|
||||
use dom::bindings::root::DomRoot;
|
||||
use dom::webglrenderingcontext::WebGLRenderingContext;
|
||||
use dom_struct::dom_struct;
|
||||
use super::{constants as webgl, ext_constants as gl, WebGLExtension, WebGLExtensions};
|
||||
use super::{constants as webgl, ext_constants as gl, WebGLExtension, WebGLExtensions, WebGLExtensionSpec};
|
||||
|
||||
#[dom_struct]
|
||||
pub struct OESTextureHalfFloat {
|
||||
|
@ -30,6 +31,10 @@ impl WebGLExtension for OESTextureHalfFloat {
|
|||
OESTextureHalfFloatBinding::Wrap)
|
||||
}
|
||||
|
||||
fn spec() -> WebGLExtensionSpec {
|
||||
WebGLExtensionSpec::Specific(WebGLVersion::WebGL1)
|
||||
}
|
||||
|
||||
fn is_supported(ext: &WebGLExtensions) -> bool {
|
||||
ext.supports_any_gl_extension(&["GL_OES_texture_half_float",
|
||||
"GL_ARB_half_float_pixel",
|
||||
|
|
|
@ -8,7 +8,7 @@ use dom::bindings::reflector::{DomObject, Reflector, reflect_dom_object};
|
|||
use dom::bindings::root::DomRoot;
|
||||
use dom::webglrenderingcontext::WebGLRenderingContext;
|
||||
use dom_struct::dom_struct;
|
||||
use super::{WebGLExtension, WebGLExtensions};
|
||||
use super::{WebGLExtension, WebGLExtensions, WebGLExtensionSpec};
|
||||
|
||||
#[dom_struct]
|
||||
pub struct OESTextureHalfFloatLinear {
|
||||
|
@ -31,6 +31,10 @@ impl WebGLExtension for OESTextureHalfFloatLinear {
|
|||
OESTextureHalfFloatLinearBinding::Wrap)
|
||||
}
|
||||
|
||||
fn spec() -> WebGLExtensionSpec {
|
||||
WebGLExtensionSpec::All
|
||||
}
|
||||
|
||||
fn is_supported(ext: &WebGLExtensions) -> bool {
|
||||
ext.supports_any_gl_extension(&["GL_OES_texture_float_linear",
|
||||
"GL_ARB_half_float_pixel",
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* 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 canvas_traits::webgl::{webgl_channel, WebGLCommand, WebGLError};
|
||||
use canvas_traits::webgl::{webgl_channel, WebGLCommand, WebGLError, WebGLVersion};
|
||||
use dom::bindings::codegen::Bindings::OESVertexArrayObjectBinding::{self, OESVertexArrayObjectMethods};
|
||||
use dom::bindings::codegen::Bindings::OESVertexArrayObjectBinding::OESVertexArrayObjectConstants;
|
||||
use dom::bindings::reflector::{DomObject, Reflector, reflect_dom_object};
|
||||
|
@ -14,7 +14,7 @@ use js::conversions::ToJSValConvertible;
|
|||
use js::jsapi::JSContext;
|
||||
use js::jsval::{JSVal, NullValue};
|
||||
use std::iter;
|
||||
use super::{WebGLExtension, WebGLExtensions};
|
||||
use super::{WebGLExtension, WebGLExtensions, WebGLExtensionSpec};
|
||||
|
||||
#[dom_struct]
|
||||
pub struct OESVertexArrayObject {
|
||||
|
@ -138,6 +138,10 @@ impl WebGLExtension for OESVertexArrayObject {
|
|||
OESVertexArrayObjectBinding::Wrap)
|
||||
}
|
||||
|
||||
fn spec() -> WebGLExtensionSpec {
|
||||
WebGLExtensionSpec::Specific(WebGLVersion::WebGL1)
|
||||
}
|
||||
|
||||
fn is_supported(ext: &WebGLExtensions) -> bool {
|
||||
ext.supports_any_gl_extension(&["GL_OES_vertex_array_object",
|
||||
"GL_ARB_vertex_array_object",
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
* 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 canvas_traits::webgl::WebGLVersion;
|
||||
use dom::bindings::reflector::DomObject;
|
||||
use dom::bindings::root::DomRoot;
|
||||
use dom::bindings::trace::JSTraceable;
|
||||
|
@ -15,6 +16,9 @@ pub trait WebGLExtension: Sized where Self::Extension: DomObject + JSTraceable {
|
|||
/// Creates the DOM object of the WebGL extension.
|
||||
fn new(ctx: &WebGLRenderingContext) -> DomRoot<Self::Extension>;
|
||||
|
||||
/// Returns which WebGL spec is this extension written against.
|
||||
fn spec() -> WebGLExtensionSpec;
|
||||
|
||||
/// Checks if the extension is supported.
|
||||
fn is_supported(ext: &WebGLExtensions) -> bool;
|
||||
|
||||
|
@ -24,3 +28,10 @@ pub trait WebGLExtension: Sized where Self::Extension: DomObject + JSTraceable {
|
|||
/// Name of the WebGL Extension.
|
||||
fn name() -> &'static str;
|
||||
}
|
||||
|
||||
pub enum WebGLExtensionSpec {
|
||||
/// Extensions written against both WebGL and WebGL2 specs.
|
||||
All,
|
||||
/// Extensions writen against a specific WebGL version spec.
|
||||
Specific(WebGLVersion)
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* 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 canvas_traits::webgl::WebGLError;
|
||||
use canvas_traits::webgl::{WebGLError, WebGLVersion};
|
||||
use dom::bindings::cell::DomRefCell;
|
||||
use dom::bindings::codegen::Bindings::OESStandardDerivativesBinding::OESStandardDerivativesConstants;
|
||||
use dom::bindings::codegen::Bindings::OESTextureHalfFloatBinding::OESTextureHalfFloatConstants;
|
||||
|
@ -20,13 +20,13 @@ use ref_filter_map::ref_filter_map;
|
|||
use std::cell::Ref;
|
||||
use std::collections::HashMap;
|
||||
use std::iter::FromIterator;
|
||||
use super::{ext, WebGLExtension};
|
||||
use super::{ext, WebGLExtension, WebGLExtensionSpec};
|
||||
use super::wrapper::{WebGLExtensionWrapper, TypedWebGLExtensionWrapper};
|
||||
|
||||
// Data types that are implemented for texImage2D and texSubImage2D in WebGLRenderingContext
|
||||
// Data types that are implemented for texImage2D and texSubImage2D in a WebGL 1.0 context
|
||||
// but must trigger a InvalidValue error until the related WebGL Extensions are enabled.
|
||||
// Example: https://www.khronos.org/registry/webgl/extensions/OES_texture_float/
|
||||
const DEFAULT_DISABLED_TEX_TYPES: [GLenum; 2] = [
|
||||
const DEFAULT_DISABLED_TEX_TYPES_WEBGL1: [GLenum; 2] = [
|
||||
constants::FLOAT, OESTextureHalfFloatConstants::HALF_FLOAT_OES
|
||||
];
|
||||
|
||||
|
@ -37,10 +37,10 @@ const DEFAULT_NOT_FILTERABLE_TEX_TYPES: [GLenum; 2] = [
|
|||
constants::FLOAT, OESTextureHalfFloatConstants::HALF_FLOAT_OES
|
||||
];
|
||||
|
||||
// Param names that are implemented for getParameter WebGL function
|
||||
// Param names that are implemented for glGetParameter in a WebGL 1.0 context
|
||||
// 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] = [
|
||||
const DEFAULT_DISABLED_GET_PARAMETER_NAMES_WEBGL1: [GLenum; 1] = [
|
||||
OESStandardDerivativesConstants::FRAGMENT_SHADER_DERIVATIVE_HINT_OES
|
||||
];
|
||||
|
||||
|
@ -58,16 +58,25 @@ struct WebGLExtensionFeatures {
|
|||
disabled_get_parameter_names: FnvHashSet<GLenum>,
|
||||
}
|
||||
|
||||
impl Default for WebGLExtensionFeatures {
|
||||
fn default() -> WebGLExtensionFeatures {
|
||||
WebGLExtensionFeatures {
|
||||
impl WebGLExtensionFeatures {
|
||||
fn new(webgl_version: WebGLVersion) -> Self {
|
||||
let (disabled_tex_types, disabled_get_parameter_names) = match webgl_version {
|
||||
WebGLVersion::WebGL1 => {
|
||||
(DEFAULT_DISABLED_TEX_TYPES_WEBGL1.iter().cloned().collect(),
|
||||
DEFAULT_DISABLED_GET_PARAMETER_NAMES_WEBGL1.iter().cloned().collect())
|
||||
},
|
||||
WebGLVersion::WebGL2 => {
|
||||
(Default::default(), Default::default())
|
||||
}
|
||||
};
|
||||
Self {
|
||||
gl_extensions: Default::default(),
|
||||
disabled_tex_types: DEFAULT_DISABLED_TEX_TYPES.iter().cloned().collect(),
|
||||
disabled_tex_types,
|
||||
not_filterable_tex_types: DEFAULT_NOT_FILTERABLE_TEX_TYPES.iter().cloned().collect(),
|
||||
effective_tex_internal_formats: Default::default(),
|
||||
query_parameter_handlers: Default::default(),
|
||||
hint_targets: Default::default(),
|
||||
disabled_get_parameter_names: DEFAULT_DISABLED_GET_PARAMETER_NAMES.iter().cloned().collect(),
|
||||
disabled_get_parameter_names,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -78,13 +87,15 @@ impl Default for WebGLExtensionFeatures {
|
|||
pub struct WebGLExtensions {
|
||||
extensions: DomRefCell<HashMap<String, Box<WebGLExtensionWrapper>>>,
|
||||
features: DomRefCell<WebGLExtensionFeatures>,
|
||||
webgl_version: WebGLVersion,
|
||||
}
|
||||
|
||||
impl WebGLExtensions {
|
||||
pub fn new() -> WebGLExtensions {
|
||||
pub fn new(webgl_version: WebGLVersion) -> WebGLExtensions {
|
||||
Self {
|
||||
extensions: DomRefCell::new(HashMap::new()),
|
||||
features: DomRefCell::new(Default::default())
|
||||
features: DomRefCell::new(WebGLExtensionFeatures::new(webgl_version)),
|
||||
webgl_version
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -104,7 +115,14 @@ impl WebGLExtensions {
|
|||
|
||||
pub fn get_suported_extensions(&self) -> Vec<&'static str> {
|
||||
self.extensions.borrow().iter()
|
||||
.filter(|ref v| v.1.is_supported(&self))
|
||||
.filter(|ref v| {
|
||||
if let WebGLExtensionSpec::Specific(version) = v.1.spec() {
|
||||
if self.webgl_version != version {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
v.1.is_supported(&self)
|
||||
})
|
||||
.map(|ref v| v.1.name())
|
||||
.collect()
|
||||
}
|
||||
|
|
|
@ -22,4 +22,5 @@ pub mod ext_constants {
|
|||
}
|
||||
|
||||
pub use self::extension::WebGLExtension;
|
||||
pub use self::extension::WebGLExtensionSpec;
|
||||
pub use self::extensions::WebGLExtensions;
|
||||
|
|
|
@ -9,7 +9,7 @@ use dom::bindings::trace::JSTraceable;
|
|||
use dom::webglrenderingcontext::WebGLRenderingContext;
|
||||
use malloc_size_of::MallocSizeOf;
|
||||
use std::any::Any;
|
||||
use super::{WebGLExtension, WebGLExtensions};
|
||||
use super::{WebGLExtension, WebGLExtensions, WebGLExtensionSpec};
|
||||
|
||||
/// Trait used internally by WebGLExtensions to store and
|
||||
/// handle the different WebGL extensions in a common list.
|
||||
|
@ -18,6 +18,7 @@ pub trait WebGLExtensionWrapper: JSTraceable + MallocSizeOf {
|
|||
ctx: &WebGLRenderingContext,
|
||||
ext: &WebGLExtensions)
|
||||
-> NonNullJSObjectPtr;
|
||||
fn spec(&self) -> WebGLExtensionSpec;
|
||||
fn is_supported(&self, &WebGLExtensions) -> bool;
|
||||
fn is_enabled(&self) -> bool;
|
||||
fn enable(&self, ext: &WebGLExtensions);
|
||||
|
@ -61,6 +62,10 @@ impl<T> WebGLExtensionWrapper for TypedWebGLExtensionWrapper<T>
|
|||
}
|
||||
}
|
||||
|
||||
fn spec(&self) -> WebGLExtensionSpec {
|
||||
T::spec()
|
||||
}
|
||||
|
||||
fn is_supported(&self, ext: &WebGLExtensions) -> bool {
|
||||
self.is_enabled() || T::is_supported(ext)
|
||||
}
|
||||
|
|
|
@ -252,7 +252,7 @@ impl WebGLRenderingContext {
|
|||
current_vertex_attrib_0: Cell::new((0f32, 0f32, 0f32, 1f32)),
|
||||
current_scissor: Cell::new((0, 0, size.width, size.height)),
|
||||
current_clear_color: Cell::new((0.0, 0.0, 0.0, 0.0)),
|
||||
extension_manager: WebGLExtensions::new()
|
||||
extension_manager: WebGLExtensions::new(webgl_version)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue