Make GL/GLES decisions based on the API in use.

This commit is contained in:
Josh Matthews 2019-07-10 17:34:16 -04:00
parent 812bf8d816
commit dbaed5ed92
13 changed files with 83 additions and 52 deletions

View file

@ -7,7 +7,7 @@ use crate::dom::bindings::codegen::Bindings::EXTShaderTextureLodBinding;
use crate::dom::bindings::reflector::{reflect_dom_object, DomObject, Reflector};
use crate::dom::bindings::root::DomRoot;
use crate::dom::webglrenderingcontext::WebGLRenderingContext;
use canvas_traits::webgl::{is_gles, WebGLVersion};
use canvas_traits::webgl::WebGLVersion;
use dom_struct::dom_struct;
#[dom_struct]
@ -40,7 +40,7 @@ impl WebGLExtension for EXTShaderTextureLod {
fn is_supported(ext: &WebGLExtensions) -> bool {
// This extension is always available on desktop GL.
!is_gles() || ext.supports_gl_extension("GL_EXT_shader_texture_lod")
!ext.is_gles() || ext.supports_gl_extension("GL_EXT_shader_texture_lod")
}
fn enable(_ext: &WebGLExtensions) {}

View file

@ -7,7 +7,7 @@ use crate::dom::bindings::codegen::Bindings::OESElementIndexUintBinding;
use crate::dom::bindings::reflector::{reflect_dom_object, DomObject, Reflector};
use crate::dom::bindings::root::DomRoot;
use crate::dom::webglrenderingcontext::WebGLRenderingContext;
use canvas_traits::webgl::{is_gles, WebGLVersion};
use canvas_traits::webgl::WebGLVersion;
use dom_struct::dom_struct;
#[dom_struct]
@ -40,7 +40,7 @@ impl WebGLExtension for OESElementIndexUint {
fn is_supported(ext: &WebGLExtensions) -> bool {
// This extension is always available in desktop OpenGL.
!is_gles() || ext.supports_gl_extension("GL_OES_element_index_uint")
!ext.is_gles() || ext.supports_gl_extension("GL_OES_element_index_uint")
}
fn enable(ext: &WebGLExtensions) {

View file

@ -8,7 +8,7 @@ use crate::dom::bindings::codegen::Bindings::OESStandardDerivativesBinding::OESS
use crate::dom::bindings::reflector::{reflect_dom_object, DomObject, Reflector};
use crate::dom::bindings::root::DomRoot;
use crate::dom::webglrenderingcontext::WebGLRenderingContext;
use canvas_traits::webgl::{is_gles, WebGLVersion};
use canvas_traits::webgl::WebGLVersion;
use dom_struct::dom_struct;
#[dom_struct]
@ -40,7 +40,7 @@ impl WebGLExtension for OESStandardDerivatives {
fn is_supported(ext: &WebGLExtensions) -> bool {
// The standard derivatives are always available in desktop OpenGL.
!is_gles() || ext.supports_any_gl_extension(&["GL_OES_standard_derivatives"])
!ext.is_gles() || ext.supports_any_gl_extension(&["GL_OES_standard_derivatives"])
}
fn enable(ext: &WebGLExtensions) {

View file

@ -18,7 +18,7 @@ use crate::dom::oestexturehalffloat::OESTextureHalfFloat;
use crate::dom::webglcolorbufferfloat::WEBGLColorBufferFloat;
use crate::dom::webglrenderingcontext::WebGLRenderingContext;
use crate::dom::webgltexture::TexCompression;
use canvas_traits::webgl::WebGLVersion;
use canvas_traits::webgl::{GlType, WebGLVersion};
use fnv::{FnvHashMap, FnvHashSet};
use gleam::gl::{self, GLenum};
use js::jsapi::JSObject;
@ -146,14 +146,16 @@ pub struct WebGLExtensions {
extensions: DomRefCell<HashMap<String, Box<dyn WebGLExtensionWrapper>>>,
features: DomRefCell<WebGLExtensionFeatures>,
webgl_version: WebGLVersion,
api_type: GlType,
}
impl WebGLExtensions {
pub fn new(webgl_version: WebGLVersion) -> WebGLExtensions {
pub fn new(webgl_version: WebGLVersion, api_type: GlType) -> WebGLExtensions {
Self {
extensions: DomRefCell::new(HashMap::new()),
features: DomRefCell::new(WebGLExtensionFeatures::new(webgl_version)),
webgl_version,
api_type,
}
}
@ -425,6 +427,10 @@ impl WebGLExtensions {
}
type_
}
pub fn is_gles(&self) -> bool {
self.api_type == GlType::Gles
}
}
// Helper structs