Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement WebGL extensions #16893

Merged
merged 1 commit into from May 19, 2017
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Implement WebGL extensions.

  • Loading branch information
MortimerGoro committed May 18, 2017
commit 32e23c4db4a80f8ebe01bead141c5ca04bc6b215

Some generated files are not rendered by default. Learn more.

@@ -43,7 +43,9 @@ domobject_derive = {path = "../domobject_derive"}
encoding = "0.2"
euclid = "0.11"
fnv = "1.0"
gleam = "0.4"
gfx_traits = {path = "../gfx_traits"}
half = "1.0"
heapsize = "0.3.6"
heapsize_derive = "0.1"
html5ever = {version = "0.16", features = ["heap_size", "unstable"]}
@@ -107,7 +107,7 @@ use style::viewport::ViewportRule;
use time::Duration;
use uuid::Uuid;
use webrender_traits::{WebGLBufferId, WebGLError, WebGLFramebufferId, WebGLProgramId};
use webrender_traits::{WebGLRenderbufferId, WebGLShaderId, WebGLTextureId};
use webrender_traits::{WebGLRenderbufferId, WebGLShaderId, WebGLTextureId, WebGLVertexArrayId};
use webvr_traits::WebVRGamepadHand;

/// A trait to allow tracing (only) DOM objects.
@@ -388,6 +388,7 @@ unsafe_no_jsmanaged_fields!(WebGLProgramId);
unsafe_no_jsmanaged_fields!(WebGLRenderbufferId);
unsafe_no_jsmanaged_fields!(WebGLShaderId);
unsafe_no_jsmanaged_fields!(WebGLTextureId);
unsafe_no_jsmanaged_fields!(WebGLVertexArrayId);
unsafe_no_jsmanaged_fields!(MediaList);
unsafe_no_jsmanaged_fields!(WebVRGamepadHand);

@@ -451,6 +451,8 @@ pub mod vrfieldofview;
pub mod vrframedata;
pub mod vrpose;
pub mod vrstageparameters;
pub mod webgl_extensions;
pub use self::webgl_extensions::ext::*;
pub mod webgl_validations;
pub mod webglactiveinfo;
pub mod webglbuffer;
@@ -0,0 +1,13 @@
/* 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::WebGLRenderingContextBinding::WebGLRenderingContextConstants as constants;
use super::{ext_constants, WebGLExtension, WebGLExtensions};

pub mod oestexturefloat;
pub mod oestexturefloatlinear;
pub mod oestexturehalffloat;
pub mod oestexturehalffloatlinear;
pub mod oesvertexarrayobject;
pub mod webglvertexarrayobjectoes;
@@ -0,0 +1,56 @@
/* 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::OESTextureFloatBinding;
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::{constants as webgl, ext_constants as gl, WebGLExtension, WebGLExtensions};

#[dom_struct]
pub struct OESTextureFloat {
reflector_: Reflector,
}

impl OESTextureFloat {
fn new_inherited() -> OESTextureFloat {
Self {
reflector_: Reflector::new(),
}
}
}

impl WebGLExtension for OESTextureFloat {
type Extension = OESTextureFloat;
fn new(ctx: &WebGLRenderingContext) -> Root<OESTextureFloat> {
reflect_dom_object(box OESTextureFloat::new_inherited(),
&*ctx.global(),
OESTextureFloatBinding::Wrap)
}

fn is_supported(ext: &WebGLExtensions) -> bool {
ext.supports_any_gl_extension(&["GL_OES_texture_float",
"GL_ARB_texture_float"])
}

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
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::ALPHA, webgl::FLOAT, gl::ALPHA32F_ARB);
ext.add_effective_tex_internal_format(webgl::LUMINANCE_ALPHA, webgl::FLOAT,
gl::LUMINANCE_ALPHA32F_ARB);
}
}

fn name() -> &'static str {
"OES_texture_float"
}
}
@@ -0,0 +1,45 @@
/* 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::OESTextureFloatLinearBinding;
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::{constants as webgl, WebGLExtension, WebGLExtensions};

#[dom_struct]
pub struct OESTextureFloatLinear {
reflector_: Reflector,
}

impl OESTextureFloatLinear {
fn new_inherited() -> OESTextureFloatLinear {
Self {
reflector_: Reflector::new(),
}
}
}

impl WebGLExtension for OESTextureFloatLinear {
type Extension = OESTextureFloatLinear;
fn new(ctx: &WebGLRenderingContext) -> Root<OESTextureFloatLinear> {
reflect_dom_object(box OESTextureFloatLinear::new_inherited(),
&*ctx.global(),
OESTextureFloatLinearBinding::Wrap)
}

fn is_supported(ext: &WebGLExtensions) -> bool {
ext.supports_any_gl_extension(&["GL_OES_texture_float_linear",
"GL_ARB_texture_float"])
}

fn enable(ext: &WebGLExtensions) {
ext.enable_filterable_tex_type(webgl::FLOAT);
}

fn name() -> &'static str {
"OES_texture_float_linear"
}
}
@@ -0,0 +1,57 @@
/* 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::OESTextureHalfFloatBinding::{self, OESTextureHalfFloatConstants};
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::{constants as webgl, ext_constants as gl, WebGLExtension, WebGLExtensions};

#[dom_struct]
pub struct OESTextureHalfFloat {
reflector_: Reflector,
}

impl OESTextureHalfFloat {
fn new_inherited() -> OESTextureHalfFloat {
Self {
reflector_: Reflector::new(),
}
}
}

impl WebGLExtension for OESTextureHalfFloat {
type Extension = OESTextureHalfFloat;
fn new(ctx: &WebGLRenderingContext) -> Root<OESTextureHalfFloat> {
reflect_dom_object(box OESTextureHalfFloat::new_inherited(),
&*ctx.global(),
OESTextureHalfFloatBinding::Wrap)
}

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"])
}

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
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);
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);
}
}

fn name() -> &'static str {
"OES_texture_half_float"
}
}
@@ -0,0 +1,47 @@
/* 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::OESTextureHalfFloatBinding::OESTextureHalfFloatConstants;
use dom::bindings::codegen::Bindings::OESTextureHalfFloatLinearBinding;
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 OESTextureHalfFloatLinear {
reflector_: Reflector,
}

impl OESTextureHalfFloatLinear {
fn new_inherited() -> OESTextureHalfFloatLinear {
Self {
reflector_: Reflector::new(),
}
}
}

impl WebGLExtension for OESTextureHalfFloatLinear {
type Extension = OESTextureHalfFloatLinear;
fn new(ctx: &WebGLRenderingContext) -> Root<OESTextureHalfFloatLinear> {
reflect_dom_object(box OESTextureHalfFloatLinear::new_inherited(),
&*ctx.global(),
OESTextureHalfFloatLinearBinding::Wrap)
}

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"])
}

fn enable(ext: &WebGLExtensions) {
ext.enable_filterable_tex_type(OESTextureHalfFloatConstants::HALF_FLOAT_OES);
}

fn name() -> &'static str {
"OES_texture_half_float_linear"
}
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.