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

[WIP] Implement WebGL depth texture #26052

Closed
wants to merge 1 commit into from
Closed
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 depth texture

  • Loading branch information
ivanshen committed Feb 24, 2020
commit b93af11270ee8204b01ce4e5a545763a77c4bab4
@@ -35,4 +35,10 @@ linker = "lld-link.exe"
linker = "lld-link.exe"

[target.aarch64-uwp-windows-msvc]
linker = "lld-link.exe"
linker = "lld-link.exe"

[target.x86_64-apple-darwin]
rustflags = [
"-C", "link-arg=-undefined",
"-C", "link-arg=dynamic_lookup",
]
@@ -915,6 +915,7 @@ mod gl_ext_constants {
pub const COMPRESSED_RGBA_S3TC_DXT3_EXT: GLenum = 0x83F2;
pub const COMPRESSED_RGBA_S3TC_DXT5_EXT: GLenum = 0x83F3;
pub const COMPRESSED_RGB_ETC1_WEBGL: GLenum = 0x8D64;
pub const UNSIGNED_INT_24_8_WEBGL: GLenum = 0x84FA;

pub static COMPRESSIONS: &'static [GLenum] = &[
COMPRESSED_RGB_S3TC_DXT1_EXT,
@@ -938,6 +939,7 @@ gl_enums! {
CompressedRgbaS3tcDxt3 = gl_ext_constants::COMPRESSED_RGBA_S3TC_DXT3_EXT,
CompressedRgbaS3tcDxt5 = gl_ext_constants::COMPRESSED_RGBA_S3TC_DXT5_EXT,
CompressedRgbEtc1 = gl_ext_constants::COMPRESSED_RGB_ETC1_WEBGL,
UnsignedInt24_8 = gl_ext_constants::UNSIGNED_INT_24_8_WEBGL,
}

pub enum TexDataType {
@@ -947,6 +949,7 @@ gl_enums! {
UnsignedShort565 = gl::UNSIGNED_SHORT_5_6_5,
Float = gl::FLOAT,
HalfFloat = gl::HALF_FLOAT_OES,
UnsignedInt24_8 = gl::UNSIGNED_INT_24_8,
}
}

@@ -982,6 +985,7 @@ impl TexDataType {
TexDataType::UnsignedShort565 => 2,
TexDataType::Float => 4,
TexDataType::HalfFloat => 2,
TexDataType::UnsignedInt24_8 => 4,
}
}

@@ -995,6 +999,7 @@ impl TexDataType {
TexDataType::UnsignedShort4444 => 4,
TexDataType::Float => 1,
TexDataType::HalfFloat => 1,
TexDataType::UnsignedInt24_8 => 3,
}
}
}
@@ -20,3 +20,4 @@ pub mod oesvertexarrayobject;
pub mod webglcolorbufferfloat;
pub mod webglcompressedtextureetc1;
pub mod webglcompressedtextures3tc;
pub mod webgldepthtexture;
@@ -0,0 +1,60 @@
use super::{
constants as webgl, ext_constants as ext, WebGLExtension, WebGLExtensionSpec, WebGLExtensions,
};
use crate::dom::bindings::codegen::Bindings::WebGLDepthTextureBinding;
use crate::dom::webglrenderingcontext::WebGLRenderingContext;
use crate::dom::bindings::reflector::{reflect_dom_object, DomObject, Reflector};
use crate::dom::bindings::root::DomRoot;
use canvas_traits::webgl::WebGLVersion;
use sparkle::gl;
use dom_struct::dom_struct;

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

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

impl WebGLExtension for WebGLDepthTexture {
type Extension = WebGLDepthTexture;
fn new(ctx: &WebGLRenderingContext) -> DomRoot<WebGLDepthTexture> {
reflect_dom_object(
Box::new(WebGLDepthTexture::new_inherited()),
&*ctx.global(),
WebGLDepthTextureBinding::Wrap,
)
}

fn spec() -> WebGLExtensionSpec {
WebGLExtensionSpec::Specific(WebGLVersion::WebGL1)
}

fn is_supported(ext: &WebGLExtensions) -> bool {
ext.supports_gl_extension("ANGLE_depth_texture")
}

fn enable(ext: &WebGLExtensions) {
let uint248 = gl::UNSIGNED_INT_24_8;
ext.enable_tex_type(uint248);
ext.add_effective_tex_internal_format(webgl::RGBA, uint248, ext::RGBA32F);
ext.add_effective_tex_internal_format(webgl::RGB, uint248, ext::RGB32F);
ext.add_effective_tex_internal_format(webgl::LUMINANCE, uint248, ext::LUMINANCE32F_ARB);
ext.add_effective_tex_internal_format(webgl::ALPHA, uint248, ext::ALPHA32F_ARB);
ext.add_effective_tex_internal_format(
webgl::LUMINANCE_ALPHA,
uint248,
ext::LUMINANCE_ALPHA32F_ARB,
);
}

fn name() -> &'static str {
"ANGLE_depth_texture"
}
}
@@ -30,8 +30,9 @@ use std::ptr::NonNull;
// 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_WEBGL1: [GLenum; 2] = [
const DEFAULT_DISABLED_TEX_TYPES_WEBGL1: [GLenum; 3] = [
constants::FLOAT,
gl::UNSIGNED_INT_24_8,
OESTextureHalfFloatConstants::HALF_FLOAT_OES,
];

@@ -393,6 +394,7 @@ impl WebGLExtensions {
self.register::<ext::webglcolorbufferfloat::WEBGLColorBufferFloat>();
self.register::<ext::webglcompressedtextureetc1::WEBGLCompressedTextureETC1>();
self.register::<ext::webglcompressedtextures3tc::WEBGLCompressedTextureS3TC>();
self.register::<ext::webgldepthtexture::WebGLDepthTexture>();
}

pub fn enable_element_index_uint(&self) {
@@ -419,6 +419,22 @@ fn valid_compressed_data_len(
data_len == required_bytes as usize
}

// fn valid_depth_texture_cube_map(format: u32, target: u32) -> bool {
// ((format == constants::DEPTH_COMPONENT || format == constants::DEPTH_STENCIL) &&
// (target == constants::GL_TEXTURE_CUBE_MAP_POSITIVE_X ||
// target == constants::GL_TEXTURE_CUBE_MAP_POSITIVE_Y ||
// target == constants::GL_TEXTURE_CUBE_MAP_POSITIVE_Z ||
// target == constants::GL_TEXTURE_CUBE_MAP_NEGATIVE_X ||
// target == constants::GL_TEXTURE_CUBE_MAP_NEGATIVE_Y ||
// target == constants::GL_TEXTURE_CUBE_MAP_NEGATIVE_Z))

// }

// fn valid_depth_texture_internal_format(format: u32, internalformat: u32, type: u32) -> bool {
// (format == constants::DEPTH_COMPONENT && internalformat == constants::DEPTH_STENCIL && (type != constants::UNSIGNED_SHORT || type != constants::UNSIGNED_INT)) ||
// (format != constants::DEPTH_COMPONENT && internalformat != constants::DEPTH_STENCIL) && (type == constants::UNSIGNED_SHORT || type == constants::UNSIGNED_INT))
// }

fn is_subimage_blockaligned(
xoffset: u32,
yoffset: u32,
@@ -539,6 +555,13 @@ impl<'a> WebGLValidator for CompressedTexImage2DValidator<'a> {
valid_width && valid_height
},
TexCompressionValidation::None => true,
// TexCompressionValidation::DepthTexture => {
// // let valid_format =
// let valid_format = valid_depth_texture_cube_map(compression.format, target, );
// // let valid_internal_format = compression.format == constants::DEPTH_COMPONENT && self.compression_validator.common_validator.internal_format == constants::DEPTH_STENCIL;
// let valid_internal_format = valid_depth_texture_internal_format(compression.format, self.compression_validator.common_validator.internal_format, data_type);
// valid_format && valid_internal_format
// }
};
if !compression_valid {
context.webgl_error(InvalidOperation);
@@ -22,6 +22,7 @@ use euclid::Size2D;
use std::cell::Cell;
use webxr_api::SwapChainId as WebXRSwapChainId;
use webxr_api::Viewport;
use sparkle::gl;

pub enum CompleteForRendering {
Complete,
@@ -571,7 +572,7 @@ impl WebGLFramebuffer {
self.upcast::<WebGLObject>()
.context()
.send_command(WebGLCommand::FramebufferTexture2D(
constants::FRAMEBUFFER,
gl::UNSIGNED_INT_24_8,

This comment has been minimized.

Copy link
@jdm

jdm Apr 27, 2020

Member

This change does not make sense to me. What is the intention here?

attachment,
textarget,
tex_id,
@@ -82,7 +82,7 @@ use std::cmp;
use std::ptr::{self, NonNull};
use std::rc::Rc;
use webxr_api::SwapChainId as WebXRSwapChainId;

use sparkle::gl;
// From the GLES 2.0.25 spec, page 85:
//
// "If a texture that is currently bound to one of the targets
@@ -667,6 +667,7 @@ impl WebGLRenderingContext {
Some(ref buffer) => match buffer.get_array_type() {
Type::Uint8 => 1,
Type::Uint16 => 2,
Type::Uint32 => 4,
Type::Float32 => 4,
_ => {
self.webgl_error(InvalidOperation);
@@ -4227,7 +4228,7 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
handle_potential_webgl_error!(self, self.validate_ownership(texture), return);
}

if target != constants::FRAMEBUFFER {
if target != gl::UNSIGNED_INT_24_8 {

This comment has been minimized.

Copy link
@jdm

jdm Apr 27, 2020

Member

This also doesn't make sense. The spec says The framebufferTexture2D entry point is extended to accept the target parameter DEPTH_ATTACHMENT and DEPTH_STENCIL_ATTACHMENT, which is not what's being checked.

return self.webgl_error(InvalidEnum);
}

@@ -0,0 +1,12 @@
/* 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 https://mozilla.org/MPL/2.0/. */
/*
* WebGL IDL definitions from the Khronos specification:
* https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/
*/

[NoInterfaceObject, Exposed=Window]
interface WebGLDepthTexture {
const GLenum UNSIGNED_INT_24_8_WEBGL = 0x84FA;
};
Binary file not shown.
Binary file not shown.
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.