mirror of
https://github.com/servo/servo.git
synced 2025-07-23 07:13:52 +01:00
Format script component
This commit is contained in:
parent
2ca7a13473
commit
c37a345dc9
357 changed files with 25485 additions and 18076 deletions
|
@ -64,16 +64,11 @@ impl WebGLExtension for ANGLEInstancedArrays {
|
|||
|
||||
impl ANGLEInstancedArraysMethods for ANGLEInstancedArrays {
|
||||
// https://www.khronos.org/registry/webgl/extensions/ANGLE_instanced_arrays/
|
||||
fn DrawArraysInstancedANGLE(
|
||||
&self,
|
||||
mode: u32,
|
||||
first: i32,
|
||||
count: i32,
|
||||
primcount: i32,
|
||||
) {
|
||||
fn DrawArraysInstancedANGLE(&self, mode: u32, first: i32, count: i32, primcount: i32) {
|
||||
handle_potential_webgl_error!(
|
||||
self.ctx,
|
||||
self.ctx.draw_arrays_instanced(mode, first, count, primcount)
|
||||
self.ctx
|
||||
.draw_arrays_instanced(mode, first, count, primcount)
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -88,7 +83,8 @@ impl ANGLEInstancedArraysMethods for ANGLEInstancedArrays {
|
|||
) {
|
||||
handle_potential_webgl_error!(
|
||||
self.ctx,
|
||||
self.ctx.draw_elements_instanced(mode, count, type_, offset, primcount)
|
||||
self.ctx
|
||||
.draw_elements_instanced(mode, count, type_, offset, primcount)
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -17,7 +17,9 @@ pub struct EXTBlendMinmax {
|
|||
|
||||
impl EXTBlendMinmax {
|
||||
fn new_inherited() -> Self {
|
||||
Self { reflector_: Reflector::new() }
|
||||
Self {
|
||||
reflector_: Reflector::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -17,7 +17,9 @@ pub struct EXTShaderTextureLod {
|
|||
|
||||
impl EXTShaderTextureLod {
|
||||
fn new_inherited() -> Self {
|
||||
Self { reflector_: Reflector::new() }
|
||||
Self {
|
||||
reflector_: Reflector::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -44,8 +44,12 @@ impl WebGLExtension for EXTTextureFilterAnisotropic {
|
|||
}
|
||||
|
||||
fn enable(ext: &WebGLExtensions) {
|
||||
ext.enable_get_tex_parameter_name(EXTTextureFilterAnisotropicConstants::TEXTURE_MAX_ANISOTROPY_EXT);
|
||||
ext.enable_get_parameter_name(EXTTextureFilterAnisotropicConstants::MAX_TEXTURE_MAX_ANISOTROPY_EXT);
|
||||
ext.enable_get_tex_parameter_name(
|
||||
EXTTextureFilterAnisotropicConstants::TEXTURE_MAX_ANISOTROPY_EXT,
|
||||
);
|
||||
ext.enable_get_parameter_name(
|
||||
EXTTextureFilterAnisotropicConstants::MAX_TEXTURE_MAX_ANISOTROPY_EXT,
|
||||
);
|
||||
}
|
||||
|
||||
fn name() -> &'static str {
|
||||
|
|
|
@ -17,7 +17,9 @@ pub struct OESElementIndexUint {
|
|||
|
||||
impl OESElementIndexUint {
|
||||
fn new_inherited() -> Self {
|
||||
Self { reflector_: Reflector::new() }
|
||||
Self {
|
||||
reflector_: Reflector::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -27,9 +27,11 @@ impl OESStandardDerivatives {
|
|||
impl WebGLExtension for OESStandardDerivatives {
|
||||
type Extension = OESStandardDerivatives;
|
||||
fn new(ctx: &WebGLRenderingContext) -> DomRoot<OESStandardDerivatives> {
|
||||
reflect_dom_object(Box::new(OESStandardDerivatives::new_inherited()),
|
||||
&*ctx.global(),
|
||||
OESStandardDerivativesBinding::Wrap)
|
||||
reflect_dom_object(
|
||||
Box::new(OESStandardDerivatives::new_inherited()),
|
||||
&*ctx.global(),
|
||||
OESStandardDerivativesBinding::Wrap,
|
||||
)
|
||||
}
|
||||
|
||||
fn spec() -> WebGLExtensionSpec {
|
||||
|
@ -42,8 +44,12 @@ impl WebGLExtension for OESStandardDerivatives {
|
|||
}
|
||||
|
||||
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);
|
||||
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 {
|
||||
|
|
|
@ -26,9 +26,11 @@ impl OESTextureFloat {
|
|||
impl WebGLExtension for OESTextureFloat {
|
||||
type Extension = OESTextureFloat;
|
||||
fn new(ctx: &WebGLRenderingContext) -> DomRoot<OESTextureFloat> {
|
||||
reflect_dom_object(Box::new(OESTextureFloat::new_inherited()),
|
||||
&*ctx.global(),
|
||||
OESTextureFloatBinding::Wrap)
|
||||
reflect_dom_object(
|
||||
Box::new(OESTextureFloat::new_inherited()),
|
||||
&*ctx.global(),
|
||||
OESTextureFloatBinding::Wrap,
|
||||
)
|
||||
}
|
||||
|
||||
fn spec() -> WebGLExtensionSpec {
|
||||
|
@ -36,9 +38,11 @@ impl WebGLExtension for OESTextureFloat {
|
|||
}
|
||||
|
||||
fn is_supported(ext: &WebGLExtensions) -> bool {
|
||||
ext.supports_any_gl_extension(&["GL_OES_texture_float",
|
||||
"GL_ARB_texture_float",
|
||||
"GL_EXT_color_buffer_float"])
|
||||
ext.supports_any_gl_extension(&[
|
||||
"GL_OES_texture_float",
|
||||
"GL_ARB_texture_float",
|
||||
"GL_EXT_color_buffer_float",
|
||||
])
|
||||
}
|
||||
|
||||
fn enable(ext: &WebGLExtensions) {
|
||||
|
@ -49,10 +53,17 @@ impl WebGLExtension for OESTextureFloat {
|
|||
// Special internal formats must be used to avoid clamped float values
|
||||
ext.add_effective_tex_internal_format(webgl::RGBA, webgl::FLOAT, gl::RGBA32F);
|
||||
ext.add_effective_tex_internal_format(webgl::RGB, webgl::FLOAT, gl::RGB32F);
|
||||
ext.add_effective_tex_internal_format(webgl::LUMINANCE, webgl::FLOAT, gl::LUMINANCE32F_ARB);
|
||||
ext.add_effective_tex_internal_format(
|
||||
webgl::LUMINANCE,
|
||||
webgl::FLOAT,
|
||||
gl::LUMINANCE32F_ARB,
|
||||
);
|
||||
ext.add_effective_tex_internal_format(webgl::ALPHA, webgl::FLOAT, gl::ALPHA32F_ARB);
|
||||
ext.add_effective_tex_internal_format(webgl::LUMINANCE_ALPHA, webgl::FLOAT,
|
||||
gl::LUMINANCE_ALPHA32F_ARB);
|
||||
ext.add_effective_tex_internal_format(
|
||||
webgl::LUMINANCE_ALPHA,
|
||||
webgl::FLOAT,
|
||||
gl::LUMINANCE_ALPHA32F_ARB,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -25,9 +25,11 @@ impl OESTextureFloatLinear {
|
|||
impl WebGLExtension for OESTextureFloatLinear {
|
||||
type Extension = OESTextureFloatLinear;
|
||||
fn new(ctx: &WebGLRenderingContext) -> DomRoot<OESTextureFloatLinear> {
|
||||
reflect_dom_object(Box::new(OESTextureFloatLinear::new_inherited()),
|
||||
&*ctx.global(),
|
||||
OESTextureFloatLinearBinding::Wrap)
|
||||
reflect_dom_object(
|
||||
Box::new(OESTextureFloatLinear::new_inherited()),
|
||||
&*ctx.global(),
|
||||
OESTextureFloatLinearBinding::Wrap,
|
||||
)
|
||||
}
|
||||
|
||||
fn spec() -> WebGLExtensionSpec {
|
||||
|
@ -35,8 +37,7 @@ impl WebGLExtension for OESTextureFloatLinear {
|
|||
}
|
||||
|
||||
fn is_supported(ext: &WebGLExtensions) -> bool {
|
||||
ext.supports_any_gl_extension(&["GL_OES_texture_float_linear",
|
||||
"GL_ARB_texture_float"])
|
||||
ext.supports_any_gl_extension(&["GL_OES_texture_float_linear", "GL_ARB_texture_float"])
|
||||
}
|
||||
|
||||
fn enable(ext: &WebGLExtensions) {
|
||||
|
|
|
@ -26,9 +26,11 @@ impl OESTextureHalfFloat {
|
|||
impl WebGLExtension for OESTextureHalfFloat {
|
||||
type Extension = OESTextureHalfFloat;
|
||||
fn new(ctx: &WebGLRenderingContext) -> DomRoot<OESTextureHalfFloat> {
|
||||
reflect_dom_object(Box::new(OESTextureHalfFloat::new_inherited()),
|
||||
&*ctx.global(),
|
||||
OESTextureHalfFloatBinding::Wrap)
|
||||
reflect_dom_object(
|
||||
Box::new(OESTextureHalfFloat::new_inherited()),
|
||||
&*ctx.global(),
|
||||
OESTextureHalfFloatBinding::Wrap,
|
||||
)
|
||||
}
|
||||
|
||||
fn spec() -> WebGLExtensionSpec {
|
||||
|
@ -36,10 +38,12 @@ impl WebGLExtension for OESTextureHalfFloat {
|
|||
}
|
||||
|
||||
fn is_supported(ext: &WebGLExtensions) -> bool {
|
||||
ext.supports_any_gl_extension(&["GL_OES_texture_half_float",
|
||||
"GL_ARB_half_float_pixel",
|
||||
"GL_NV_half_float",
|
||||
"GL_EXT_color_buffer_half_float"])
|
||||
ext.supports_any_gl_extension(&[
|
||||
"GL_OES_texture_half_float",
|
||||
"GL_ARB_half_float_pixel",
|
||||
"GL_NV_half_float",
|
||||
"GL_EXT_color_buffer_half_float",
|
||||
])
|
||||
}
|
||||
|
||||
fn enable(ext: &WebGLExtensions) {
|
||||
|
@ -53,7 +57,11 @@ impl WebGLExtension for OESTextureHalfFloat {
|
|||
ext.add_effective_tex_internal_format(webgl::RGB, hf, gl::RGB16F);
|
||||
ext.add_effective_tex_internal_format(webgl::LUMINANCE, hf, gl::LUMINANCE16F_ARB);
|
||||
ext.add_effective_tex_internal_format(webgl::ALPHA, hf, gl::ALPHA16F_ARB);
|
||||
ext.add_effective_tex_internal_format(webgl::LUMINANCE_ALPHA, hf, gl::LUMINANCE_ALPHA16F_ARB);
|
||||
ext.add_effective_tex_internal_format(
|
||||
webgl::LUMINANCE_ALPHA,
|
||||
hf,
|
||||
gl::LUMINANCE_ALPHA16F_ARB,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -26,9 +26,11 @@ impl OESTextureHalfFloatLinear {
|
|||
impl WebGLExtension for OESTextureHalfFloatLinear {
|
||||
type Extension = OESTextureHalfFloatLinear;
|
||||
fn new(ctx: &WebGLRenderingContext) -> DomRoot<OESTextureHalfFloatLinear> {
|
||||
reflect_dom_object(Box::new(OESTextureHalfFloatLinear::new_inherited()),
|
||||
&*ctx.global(),
|
||||
OESTextureHalfFloatLinearBinding::Wrap)
|
||||
reflect_dom_object(
|
||||
Box::new(OESTextureHalfFloatLinear::new_inherited()),
|
||||
&*ctx.global(),
|
||||
OESTextureHalfFloatLinearBinding::Wrap,
|
||||
)
|
||||
}
|
||||
|
||||
fn spec() -> WebGLExtensionSpec {
|
||||
|
@ -36,9 +38,11 @@ impl WebGLExtension for OESTextureHalfFloatLinear {
|
|||
}
|
||||
|
||||
fn is_supported(ext: &WebGLExtensions) -> bool {
|
||||
ext.supports_any_gl_extension(&["GL_OES_texture_float_linear",
|
||||
"GL_ARB_half_float_pixel",
|
||||
"GL_NV_half_float"])
|
||||
ext.supports_any_gl_extension(&[
|
||||
"GL_OES_texture_float_linear",
|
||||
"GL_ARB_half_float_pixel",
|
||||
"GL_NV_half_float",
|
||||
])
|
||||
}
|
||||
|
||||
fn enable(ext: &WebGLExtensions) {
|
||||
|
|
|
@ -52,9 +52,11 @@ impl OESVertexArrayObjectMethods for OESVertexArrayObject {
|
|||
impl WebGLExtension for OESVertexArrayObject {
|
||||
type Extension = OESVertexArrayObject;
|
||||
fn new(ctx: &WebGLRenderingContext) -> DomRoot<OESVertexArrayObject> {
|
||||
reflect_dom_object(Box::new(OESVertexArrayObject::new_inherited(ctx)),
|
||||
&*ctx.global(),
|
||||
OESVertexArrayObjectBinding::Wrap)
|
||||
reflect_dom_object(
|
||||
Box::new(OESVertexArrayObject::new_inherited(ctx)),
|
||||
&*ctx.global(),
|
||||
OESVertexArrayObjectBinding::Wrap,
|
||||
)
|
||||
}
|
||||
|
||||
fn spec() -> WebGLExtensionSpec {
|
||||
|
@ -62,9 +64,11 @@ impl WebGLExtension for OESVertexArrayObject {
|
|||
}
|
||||
|
||||
fn is_supported(ext: &WebGLExtensions) -> bool {
|
||||
ext.supports_any_gl_extension(&["GL_OES_vertex_array_object",
|
||||
"GL_ARB_vertex_array_object",
|
||||
"GL_APPLE_vertex_array_object"])
|
||||
ext.supports_any_gl_extension(&[
|
||||
"GL_OES_vertex_array_object",
|
||||
"GL_ARB_vertex_array_object",
|
||||
"GL_APPLE_vertex_array_object",
|
||||
])
|
||||
}
|
||||
|
||||
fn enable(ext: &WebGLExtensions) {
|
||||
|
|
|
@ -10,7 +10,10 @@ use dom::webglrenderingcontext::WebGLRenderingContext;
|
|||
use super::WebGLExtensions;
|
||||
|
||||
/// Trait implemented by WebGL extensions.
|
||||
pub trait WebGLExtension: Sized where Self::Extension: DomObject + JSTraceable {
|
||||
pub trait WebGLExtension: Sized
|
||||
where
|
||||
Self::Extension: DomObject + JSTraceable,
|
||||
{
|
||||
type Extension;
|
||||
|
||||
/// Creates the DOM object of the WebGL extension.
|
||||
|
@ -33,5 +36,5 @@ pub enum WebGLExtensionSpec {
|
|||
/// Extensions written against both WebGL and WebGL2 specs.
|
||||
All,
|
||||
/// Extensions writen against a specific WebGL version spec.
|
||||
Specific(WebGLVersion)
|
||||
Specific(WebGLVersion),
|
||||
}
|
||||
|
|
|
@ -26,14 +26,16 @@ use super::wrapper::{WebGLExtensionWrapper, TypedWebGLExtensionWrapper};
|
|||
// 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_WEBGL1: [GLenum; 2] = [
|
||||
constants::FLOAT, OESTextureHalfFloatConstants::HALF_FLOAT_OES
|
||||
constants::FLOAT,
|
||||
OESTextureHalfFloatConstants::HALF_FLOAT_OES,
|
||||
];
|
||||
|
||||
// Data types that are implemented for textures in WebGLRenderingContext
|
||||
// but not allowed to use with linear filtering until the related WebGL Extensions are enabled.
|
||||
// Example: https://www.khronos.org/registry/webgl/extensions/OES_texture_float_linear/
|
||||
const DEFAULT_NOT_FILTERABLE_TEX_TYPES: [GLenum; 2] = [
|
||||
constants::FLOAT, OESTextureHalfFloatConstants::HALF_FLOAT_OES
|
||||
constants::FLOAT,
|
||||
OESTextureHalfFloatConstants::HALF_FLOAT_OES,
|
||||
];
|
||||
|
||||
// Param names that are implemented for glGetParameter in a WebGL 1.0 context
|
||||
|
@ -48,16 +50,14 @@ const DEFAULT_DISABLED_GET_PARAMETER_NAMES_WEBGL1: [GLenum; 3] = [
|
|||
// Param names that are implemented for glGetTexParameter 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_TEX_PARAMETER_NAMES_WEBGL1: [GLenum; 1] = [
|
||||
EXTTextureFilterAnisotropicConstants::TEXTURE_MAX_ANISOTROPY_EXT,
|
||||
];
|
||||
const DEFAULT_DISABLED_GET_TEX_PARAMETER_NAMES_WEBGL1: [GLenum; 1] =
|
||||
[EXTTextureFilterAnisotropicConstants::TEXTURE_MAX_ANISOTROPY_EXT];
|
||||
|
||||
// Param names that are implemented for glGetVertexAttrib 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/ANGLE_instanced_arrays/
|
||||
const DEFAULT_DISABLED_GET_VERTEX_ATTRIB_NAMES_WEBGL1: [GLenum; 1] = [
|
||||
ANGLEInstancedArraysConstants::VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE,
|
||||
];
|
||||
const DEFAULT_DISABLED_GET_VERTEX_ATTRIB_NAMES_WEBGL1: [GLenum; 1] =
|
||||
[ANGLEInstancedArraysConstants::VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE];
|
||||
|
||||
/// WebGL features that are enabled/disabled by WebGL Extensions.
|
||||
#[derive(JSTraceable, MallocSizeOf)]
|
||||
|
@ -90,26 +90,31 @@ impl WebGLExtensionFeatures {
|
|||
element_index_uint_enabled,
|
||||
blend_minmax_enabled,
|
||||
) = match webgl_version {
|
||||
WebGLVersion::WebGL1 => {
|
||||
(
|
||||
DEFAULT_DISABLED_TEX_TYPES_WEBGL1.iter().cloned().collect(),
|
||||
DEFAULT_DISABLED_GET_PARAMETER_NAMES_WEBGL1.iter().cloned().collect(),
|
||||
DEFAULT_DISABLED_GET_TEX_PARAMETER_NAMES_WEBGL1.iter().cloned().collect(),
|
||||
DEFAULT_DISABLED_GET_VERTEX_ATTRIB_NAMES_WEBGL1.iter().cloned().collect(),
|
||||
false,
|
||||
false,
|
||||
)
|
||||
},
|
||||
WebGLVersion::WebGL2 => {
|
||||
(
|
||||
Default::default(),
|
||||
Default::default(),
|
||||
Default::default(),
|
||||
Default::default(),
|
||||
true,
|
||||
true,
|
||||
)
|
||||
}
|
||||
WebGLVersion::WebGL1 => (
|
||||
DEFAULT_DISABLED_TEX_TYPES_WEBGL1.iter().cloned().collect(),
|
||||
DEFAULT_DISABLED_GET_PARAMETER_NAMES_WEBGL1
|
||||
.iter()
|
||||
.cloned()
|
||||
.collect(),
|
||||
DEFAULT_DISABLED_GET_TEX_PARAMETER_NAMES_WEBGL1
|
||||
.iter()
|
||||
.cloned()
|
||||
.collect(),
|
||||
DEFAULT_DISABLED_GET_VERTEX_ATTRIB_NAMES_WEBGL1
|
||||
.iter()
|
||||
.cloned()
|
||||
.collect(),
|
||||
false,
|
||||
false,
|
||||
),
|
||||
WebGLVersion::WebGL2 => (
|
||||
Default::default(),
|
||||
Default::default(),
|
||||
Default::default(),
|
||||
Default::default(),
|
||||
true,
|
||||
true,
|
||||
),
|
||||
};
|
||||
Self {
|
||||
gl_extensions: Default::default(),
|
||||
|
@ -144,35 +149,45 @@ impl WebGLExtensions {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn init_once<F>(&self, cb: F) where F: FnOnce() -> String {
|
||||
pub fn init_once<F>(&self, cb: F)
|
||||
where
|
||||
F: FnOnce() -> String,
|
||||
{
|
||||
if self.extensions.borrow().len() == 0 {
|
||||
let gl_str = cb();
|
||||
self.features.borrow_mut().gl_extensions = FnvHashSet::from_iter(gl_str.split(&[',', ' '][..])
|
||||
.map(|s| s.into()));
|
||||
self.features.borrow_mut().gl_extensions =
|
||||
FnvHashSet::from_iter(gl_str.split(&[',', ' '][..]).map(|s| s.into()));
|
||||
self.register_all_extensions();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn register<T:'static + WebGLExtension + JSTraceable + MallocSizeOf>(&self) {
|
||||
pub fn register<T: 'static + WebGLExtension + JSTraceable + MallocSizeOf>(&self) {
|
||||
let name = T::name().to_uppercase();
|
||||
self.extensions.borrow_mut().insert(name, Box::new(TypedWebGLExtensionWrapper::<T>::new()));
|
||||
self.extensions
|
||||
.borrow_mut()
|
||||
.insert(name, Box::new(TypedWebGLExtensionWrapper::<T>::new()));
|
||||
}
|
||||
|
||||
pub fn get_suported_extensions(&self) -> Vec<&'static str> {
|
||||
self.extensions.borrow().iter()
|
||||
.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()
|
||||
self.extensions
|
||||
.borrow()
|
||||
.iter()
|
||||
.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()
|
||||
}
|
||||
|
||||
pub fn get_or_init_extension(&self, name: &str, ctx: &WebGLRenderingContext) -> Option<NonNull<JSObject>> {
|
||||
pub fn get_or_init_extension(
|
||||
&self,
|
||||
name: &str,
|
||||
ctx: &WebGLRenderingContext,
|
||||
) -> Option<NonNull<JSObject>> {
|
||||
let name = name.to_uppercase();
|
||||
self.extensions.borrow().get(&name).and_then(|extension| {
|
||||
if extension.is_supported(self) {
|
||||
|
@ -185,10 +200,13 @@ impl WebGLExtensions {
|
|||
|
||||
pub fn is_enabled<T>(&self) -> bool
|
||||
where
|
||||
T: 'static + WebGLExtension + JSTraceable + MallocSizeOf
|
||||
T: 'static + WebGLExtension + JSTraceable + MallocSizeOf,
|
||||
{
|
||||
let name = T::name().to_uppercase();
|
||||
self.extensions.borrow().get(&name).map_or(false, |ext| { ext.is_enabled() })
|
||||
self.extensions
|
||||
.borrow()
|
||||
.get(&name)
|
||||
.map_or(false, |ext| ext.is_enabled())
|
||||
}
|
||||
|
||||
pub fn supports_gl_extension(&self, name: &str) -> bool {
|
||||
|
@ -197,42 +215,66 @@ impl WebGLExtensions {
|
|||
|
||||
pub fn supports_any_gl_extension(&self, names: &[&str]) -> bool {
|
||||
let features = self.features.borrow();
|
||||
names.iter().any(|name| features.gl_extensions.contains(*name))
|
||||
names
|
||||
.iter()
|
||||
.any(|name| features.gl_extensions.contains(*name))
|
||||
}
|
||||
|
||||
pub fn enable_tex_type(&self, data_type: GLenum) {
|
||||
self.features.borrow_mut().disabled_tex_types.remove(&data_type);
|
||||
self.features
|
||||
.borrow_mut()
|
||||
.disabled_tex_types
|
||||
.remove(&data_type);
|
||||
}
|
||||
|
||||
pub fn is_tex_type_enabled(&self, data_type: GLenum) -> bool {
|
||||
self.features.borrow().disabled_tex_types.get(&data_type).is_none()
|
||||
self.features
|
||||
.borrow()
|
||||
.disabled_tex_types
|
||||
.get(&data_type)
|
||||
.is_none()
|
||||
}
|
||||
|
||||
pub fn add_effective_tex_internal_format(&self,
|
||||
source_internal_format: u32,
|
||||
source_data_type: u32,
|
||||
effective_internal_format: u32)
|
||||
{
|
||||
pub fn add_effective_tex_internal_format(
|
||||
&self,
|
||||
source_internal_format: u32,
|
||||
source_data_type: u32,
|
||||
effective_internal_format: u32,
|
||||
) {
|
||||
let format = TexFormatType(source_internal_format, source_data_type);
|
||||
self.features.borrow_mut().effective_tex_internal_formats.insert(format,
|
||||
effective_internal_format);
|
||||
|
||||
self.features
|
||||
.borrow_mut()
|
||||
.effective_tex_internal_formats
|
||||
.insert(format, effective_internal_format);
|
||||
}
|
||||
|
||||
pub fn get_effective_tex_internal_format(&self,
|
||||
source_internal_format: u32,
|
||||
source_data_type: u32) -> u32 {
|
||||
pub fn get_effective_tex_internal_format(
|
||||
&self,
|
||||
source_internal_format: u32,
|
||||
source_data_type: u32,
|
||||
) -> u32 {
|
||||
let format = TexFormatType(source_internal_format, source_data_type);
|
||||
*(self.features.borrow().effective_tex_internal_formats.get(&format)
|
||||
.unwrap_or(&source_internal_format))
|
||||
*(self
|
||||
.features
|
||||
.borrow()
|
||||
.effective_tex_internal_formats
|
||||
.get(&format)
|
||||
.unwrap_or(&source_internal_format))
|
||||
}
|
||||
|
||||
pub fn enable_filterable_tex_type(&self, text_data_type: GLenum) {
|
||||
self.features.borrow_mut().not_filterable_tex_types.remove(&text_data_type);
|
||||
self.features
|
||||
.borrow_mut()
|
||||
.not_filterable_tex_types
|
||||
.remove(&text_data_type);
|
||||
}
|
||||
|
||||
pub fn is_filterable(&self, text_data_type: u32) -> bool {
|
||||
self.features.borrow().not_filterable_tex_types.get(&text_data_type).is_none()
|
||||
self.features
|
||||
.borrow()
|
||||
.not_filterable_tex_types
|
||||
.get(&text_data_type)
|
||||
.is_none()
|
||||
}
|
||||
|
||||
pub fn enable_hint_target(&self, name: GLenum) {
|
||||
|
@ -244,27 +286,48 @@ impl WebGLExtensions {
|
|||
}
|
||||
|
||||
pub fn enable_get_parameter_name(&self, name: GLenum) {
|
||||
self.features.borrow_mut().disabled_get_parameter_names.remove(&name);
|
||||
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)
|
||||
!self
|
||||
.features
|
||||
.borrow()
|
||||
.disabled_get_parameter_names
|
||||
.contains(&name)
|
||||
}
|
||||
|
||||
pub fn enable_get_tex_parameter_name(&self, name: GLenum) {
|
||||
self.features.borrow_mut().disabled_get_tex_parameter_names.remove(&name);
|
||||
self.features
|
||||
.borrow_mut()
|
||||
.disabled_get_tex_parameter_names
|
||||
.remove(&name);
|
||||
}
|
||||
|
||||
pub fn is_get_tex_parameter_name_enabled(&self, name: GLenum) -> bool {
|
||||
!self.features.borrow().disabled_get_tex_parameter_names.contains(&name)
|
||||
!self
|
||||
.features
|
||||
.borrow()
|
||||
.disabled_get_tex_parameter_names
|
||||
.contains(&name)
|
||||
}
|
||||
|
||||
pub fn enable_get_vertex_attrib_name(&self, name: GLenum) {
|
||||
self.features.borrow_mut().disabled_get_vertex_attrib_names.remove(&name);
|
||||
self.features
|
||||
.borrow_mut()
|
||||
.disabled_get_vertex_attrib_names
|
||||
.remove(&name);
|
||||
}
|
||||
|
||||
pub fn is_get_vertex_attrib_name_enabled(&self, name: GLenum) -> bool {
|
||||
!self.features.borrow().disabled_get_vertex_attrib_names.contains(&name)
|
||||
!self
|
||||
.features
|
||||
.borrow()
|
||||
.disabled_get_vertex_attrib_names
|
||||
.contains(&name)
|
||||
}
|
||||
|
||||
fn register_all_extensions(&self) {
|
||||
|
|
|
@ -9,16 +9,16 @@ mod wrapper;
|
|||
|
||||
// Some extra constants not exposed in WebGLRenderingContext constants
|
||||
pub mod ext_constants {
|
||||
pub const ALPHA16F_ARB: u32 = 0x881C;
|
||||
pub const ALPHA32F_ARB: u32 = 0x8816;
|
||||
pub const LUMINANCE16F_ARB: u32 = 0x881E;
|
||||
pub const LUMINANCE32F_ARB: u32 = 0x8818;
|
||||
pub const LUMINANCE_ALPHA16F_ARB: u32 = 0x881F;
|
||||
pub const LUMINANCE_ALPHA32F_ARB: u32 = 0x8819;
|
||||
pub const RGBA16F: u32 = 0x881A;
|
||||
pub const RGB16F: u32 = 0x881B;
|
||||
pub const RGBA32F: u32 = 0x8814;
|
||||
pub const RGB32F: u32 = 0x8815;
|
||||
pub const ALPHA16F_ARB: u32 = 0x881C;
|
||||
pub const ALPHA32F_ARB: u32 = 0x8816;
|
||||
pub const LUMINANCE16F_ARB: u32 = 0x881E;
|
||||
pub const LUMINANCE32F_ARB: u32 = 0x8818;
|
||||
pub const LUMINANCE_ALPHA16F_ARB: u32 = 0x881F;
|
||||
pub const LUMINANCE_ALPHA32F_ARB: u32 = 0x8819;
|
||||
pub const RGBA16F: u32 = 0x881A;
|
||||
pub const RGB16F: u32 = 0x881B;
|
||||
pub const RGBA32F: u32 = 0x8814;
|
||||
pub const RGB32F: u32 = 0x8815;
|
||||
}
|
||||
|
||||
pub use self::extension::WebGLExtension;
|
||||
|
|
|
@ -15,10 +15,11 @@ use super::{WebGLExtension, WebGLExtensions, WebGLExtensionSpec};
|
|||
/// Trait used internally by WebGLExtensions to store and
|
||||
/// handle the different WebGL extensions in a common list.
|
||||
pub trait WebGLExtensionWrapper: JSTraceable + MallocSizeOf {
|
||||
fn instance_or_init(&self,
|
||||
ctx: &WebGLRenderingContext,
|
||||
ext: &WebGLExtensions)
|
||||
-> NonNull<JSObject>;
|
||||
fn instance_or_init(
|
||||
&self,
|
||||
ctx: &WebGLRenderingContext,
|
||||
ext: &WebGLExtensions,
|
||||
) -> NonNull<JSObject>;
|
||||
fn spec(&self) -> WebGLExtensionSpec;
|
||||
fn is_supported(&self, &WebGLExtensions) -> bool;
|
||||
fn is_enabled(&self) -> bool;
|
||||
|
@ -30,7 +31,7 @@ pub trait WebGLExtensionWrapper: JSTraceable + MallocSizeOf {
|
|||
#[must_root]
|
||||
#[derive(JSTraceable, MallocSizeOf)]
|
||||
pub struct TypedWebGLExtensionWrapper<T: WebGLExtension> {
|
||||
extension: MutNullableDom<T::Extension>
|
||||
extension: MutNullableDom<T::Extension>,
|
||||
}
|
||||
|
||||
/// Typed WebGL Extension implementation.
|
||||
|
@ -38,18 +39,21 @@ pub struct TypedWebGLExtensionWrapper<T: WebGLExtension> {
|
|||
impl<T: WebGLExtension> TypedWebGLExtensionWrapper<T> {
|
||||
pub fn new() -> TypedWebGLExtensionWrapper<T> {
|
||||
TypedWebGLExtensionWrapper {
|
||||
extension: MutNullableDom::new(None)
|
||||
extension: MutNullableDom::new(None),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> WebGLExtensionWrapper for TypedWebGLExtensionWrapper<T>
|
||||
where T: WebGLExtension + JSTraceable + MallocSizeOf + 'static {
|
||||
where
|
||||
T: WebGLExtension + JSTraceable + MallocSizeOf + 'static,
|
||||
{
|
||||
#[allow(unsafe_code)]
|
||||
fn instance_or_init(&self,
|
||||
ctx: &WebGLRenderingContext,
|
||||
ext: &WebGLExtensions)
|
||||
-> NonNull<JSObject> {
|
||||
fn instance_or_init(
|
||||
&self,
|
||||
ctx: &WebGLRenderingContext,
|
||||
ext: &WebGLExtensions,
|
||||
) -> NonNull<JSObject> {
|
||||
let mut enabled = true;
|
||||
let extension = self.extension.or_init(|| {
|
||||
enabled = false;
|
||||
|
@ -58,13 +62,11 @@ impl<T> WebGLExtensionWrapper for TypedWebGLExtensionWrapper<T>
|
|||
if !enabled {
|
||||
self.enable(ext);
|
||||
}
|
||||
unsafe {
|
||||
NonNull::new_unchecked(extension.reflector().get_jsobject().get())
|
||||
}
|
||||
unsafe { NonNull::new_unchecked(extension.reflector().get_jsobject().get()) }
|
||||
}
|
||||
|
||||
fn spec(&self) -> WebGLExtensionSpec {
|
||||
T::spec()
|
||||
T::spec()
|
||||
}
|
||||
|
||||
fn is_supported(&self, ext: &WebGLExtensions) -> bool {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue