mirror of
https://github.com/servo/servo.git
synced 2025-07-23 07:13:52 +01:00
Implement WEBGL_color_buffer_float and EXT_color_buffer_half_float (fixes #22113)
This commit is contained in:
parent
176d984b3b
commit
e31462c37c
12 changed files with 240 additions and 32 deletions
|
@ -0,0 +1,49 @@
|
|||
/* 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 canvas_traits::webgl::WebGLVersion;
|
||||
use dom::bindings::codegen::Bindings::EXTColorBufferHalfFloatBinding;
|
||||
use dom::bindings::reflector::{DomObject, Reflector, reflect_dom_object};
|
||||
use dom::bindings::root::DomRoot;
|
||||
use dom::webgl_extensions::ext::oestexturehalffloat::OESTextureHalfFloat;
|
||||
use dom::webglrenderingcontext::WebGLRenderingContext;
|
||||
use dom_struct::dom_struct;
|
||||
use super::{WebGLExtension, WebGLExtensions, WebGLExtensionSpec};
|
||||
|
||||
#[dom_struct]
|
||||
pub struct EXTColorBufferHalfFloat {
|
||||
reflector_: Reflector,
|
||||
}
|
||||
|
||||
impl EXTColorBufferHalfFloat {
|
||||
fn new_inherited() -> EXTColorBufferHalfFloat {
|
||||
Self {
|
||||
reflector_: Reflector::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl WebGLExtension for EXTColorBufferHalfFloat {
|
||||
type Extension = EXTColorBufferHalfFloat;
|
||||
fn new(ctx: &WebGLRenderingContext) -> DomRoot<EXTColorBufferHalfFloat> {
|
||||
reflect_dom_object(Box::new(EXTColorBufferHalfFloat::new_inherited()),
|
||||
&*ctx.global(),
|
||||
EXTColorBufferHalfFloatBinding::Wrap)
|
||||
}
|
||||
|
||||
fn spec() -> WebGLExtensionSpec {
|
||||
WebGLExtensionSpec::Specific(WebGLVersion::WebGL1)
|
||||
}
|
||||
|
||||
fn is_supported(ext: &WebGLExtensions) -> bool {
|
||||
OESTextureHalfFloat::is_supported(ext)
|
||||
}
|
||||
|
||||
fn enable(_ext: &WebGLExtensions) {
|
||||
}
|
||||
|
||||
fn name() -> &'static str {
|
||||
"EXT_color_buffer_half_float"
|
||||
}
|
||||
}
|
|
@ -7,6 +7,7 @@ use super::{ext_constants, WebGLExtension, WebGLExtensions, WebGLExtensionSpec};
|
|||
|
||||
pub mod angleinstancedarrays;
|
||||
pub mod extblendminmax;
|
||||
pub mod extcolorbufferhalffloat;
|
||||
pub mod extshadertexturelod;
|
||||
pub mod exttexturefilteranisotropic;
|
||||
pub mod oeselementindexuint;
|
||||
|
@ -16,3 +17,4 @@ pub mod oestexturefloatlinear;
|
|||
pub mod oestexturehalffloat;
|
||||
pub mod oestexturehalffloatlinear;
|
||||
pub mod oesvertexarrayobject;
|
||||
pub mod webglcolorbufferfloat;
|
||||
|
|
|
@ -46,11 +46,8 @@ impl WebGLExtension for OESTextureFloat {
|
|||
}
|
||||
|
||||
fn enable(ext: &WebGLExtensions) {
|
||||
// Enable FLOAT text data type
|
||||
ext.enable_tex_type(webgl::FLOAT);
|
||||
let needs_replace = !ext.supports_gl_extension("GL_OES_texture_float");
|
||||
if needs_replace {
|
||||
// Special internal formats must be used to avoid clamped float values
|
||||
if !ext.supports_gl_extension("GL_OES_texture_float") {
|
||||
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(
|
||||
|
|
|
@ -47,12 +47,9 @@ impl WebGLExtension for OESTextureHalfFloat {
|
|||
}
|
||||
|
||||
fn enable(ext: &WebGLExtensions) {
|
||||
// Enable FLOAT text data type
|
||||
let hf = OESTextureHalfFloatConstants::HALF_FLOAT_OES;
|
||||
ext.enable_tex_type(hf);
|
||||
let needs_replace = !ext.supports_gl_extension("GL_OES_texture_float");
|
||||
if needs_replace {
|
||||
// Special internal formats must be used to avoid clamped float values
|
||||
if !ext.supports_gl_extension("GL_OES_texture_half_float") {
|
||||
ext.add_effective_tex_internal_format(webgl::RGBA, hf, gl::RGBA16F);
|
||||
ext.add_effective_tex_internal_format(webgl::RGB, hf, gl::RGB16F);
|
||||
ext.add_effective_tex_internal_format(webgl::LUMINANCE, hf, gl::LUMINANCE16F_ARB);
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
/* 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 canvas_traits::webgl::WebGLVersion;
|
||||
use dom::bindings::codegen::Bindings::WEBGLColorBufferFloatBinding;
|
||||
use dom::bindings::reflector::{DomObject, Reflector, reflect_dom_object};
|
||||
use dom::bindings::root::DomRoot;
|
||||
use dom::webgl_extensions::ext::oestexturefloat::OESTextureFloat;
|
||||
use dom::webglrenderingcontext::WebGLRenderingContext;
|
||||
use dom_struct::dom_struct;
|
||||
use super::{WebGLExtension, WebGLExtensions, WebGLExtensionSpec};
|
||||
|
||||
#[dom_struct]
|
||||
pub struct WEBGLColorBufferFloat {
|
||||
reflector_: Reflector,
|
||||
}
|
||||
|
||||
impl WEBGLColorBufferFloat {
|
||||
fn new_inherited() -> WEBGLColorBufferFloat {
|
||||
Self {
|
||||
reflector_: Reflector::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl WebGLExtension for WEBGLColorBufferFloat {
|
||||
type Extension = WEBGLColorBufferFloat;
|
||||
fn new(ctx: &WebGLRenderingContext) -> DomRoot<WEBGLColorBufferFloat> {
|
||||
reflect_dom_object(Box::new(WEBGLColorBufferFloat::new_inherited()),
|
||||
&*ctx.global(),
|
||||
WEBGLColorBufferFloatBinding::Wrap)
|
||||
}
|
||||
|
||||
fn spec() -> WebGLExtensionSpec {
|
||||
WebGLExtensionSpec::Specific(WebGLVersion::WebGL1)
|
||||
}
|
||||
|
||||
fn is_supported(ext: &WebGLExtensions) -> bool {
|
||||
OESTextureFloat::is_supported(ext)
|
||||
}
|
||||
|
||||
fn enable(_ext: &WebGLExtensions) {
|
||||
}
|
||||
|
||||
fn name() -> &'static str {
|
||||
"WEBGL_color_buffer_float"
|
||||
}
|
||||
}
|
|
@ -11,9 +11,13 @@ use dom::bindings::codegen::Bindings::OESTextureHalfFloatBinding::OESTextureHalf
|
|||
use dom::bindings::codegen::Bindings::OESVertexArrayObjectBinding::OESVertexArrayObjectConstants;
|
||||
use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLRenderingContextConstants as constants;
|
||||
use dom::bindings::trace::JSTraceable;
|
||||
use dom::extcolorbufferhalffloat::EXTColorBufferHalfFloat;
|
||||
use dom::oestexturefloat::OESTextureFloat;
|
||||
use dom::oestexturehalffloat::OESTextureHalfFloat;
|
||||
use dom::webglcolorbufferfloat::WEBGLColorBufferFloat;
|
||||
use dom::webglrenderingcontext::WebGLRenderingContext;
|
||||
use fnv::{FnvHashMap, FnvHashSet};
|
||||
use gleam::gl::GLenum;
|
||||
use gleam::gl::{self, GLenum};
|
||||
use js::jsapi::JSObject;
|
||||
use malloc_size_of::MallocSizeOf;
|
||||
use std::collections::HashMap;
|
||||
|
@ -333,6 +337,7 @@ impl WebGLExtensions {
|
|||
fn register_all_extensions(&self) {
|
||||
self.register::<ext::angleinstancedarrays::ANGLEInstancedArrays>();
|
||||
self.register::<ext::extblendminmax::EXTBlendMinmax>();
|
||||
self.register::<ext::extcolorbufferhalffloat::EXTColorBufferHalfFloat>();
|
||||
self.register::<ext::extshadertexturelod::EXTShaderTextureLod>();
|
||||
self.register::<ext::exttexturefilteranisotropic::EXTTextureFilterAnisotropic>();
|
||||
self.register::<ext::oeselementindexuint::OESElementIndexUint>();
|
||||
|
@ -342,6 +347,7 @@ impl WebGLExtensions {
|
|||
self.register::<ext::oestexturehalffloat::OESTextureHalfFloat>();
|
||||
self.register::<ext::oestexturehalffloatlinear::OESTextureHalfFloatLinear>();
|
||||
self.register::<ext::oesvertexarrayobject::OESVertexArrayObject>();
|
||||
self.register::<ext::webglcolorbufferfloat::WEBGLColorBufferFloat>();
|
||||
}
|
||||
|
||||
pub fn enable_element_index_uint(&self) {
|
||||
|
@ -359,6 +365,23 @@ impl WebGLExtensions {
|
|||
pub fn is_blend_minmax_enabled(&self) -> bool {
|
||||
self.features.borrow().blend_minmax_enabled
|
||||
}
|
||||
|
||||
pub fn is_float_buffer_renderable(&self) -> bool {
|
||||
self.is_enabled::<WEBGLColorBufferFloat>() || self.is_enabled::<OESTextureFloat>()
|
||||
}
|
||||
|
||||
pub fn is_half_float_buffer_renderable(&self) -> bool {
|
||||
self.is_enabled::<EXTColorBufferHalfFloat>() || self.is_enabled::<OESTextureHalfFloat>()
|
||||
}
|
||||
|
||||
pub fn effective_type(&self, type_: u32) -> u32 {
|
||||
if type_ == OESTextureHalfFloatConstants::HALF_FLOAT_OES {
|
||||
if !self.supports_gl_extension("GL_OES_texture_half_float") {
|
||||
return gl::HALF_FLOAT;
|
||||
}
|
||||
}
|
||||
type_
|
||||
}
|
||||
}
|
||||
|
||||
// Helper structs
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue