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

Add support for WebGL2 FramebufferTextureLayer #25814

Merged
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Add support for WebGL2 FramebufferTextureLayer

Adds support for `FramebufferTextureLayer` WebGL2 call.

See: https://www.khronos.org/registry/webgl/specs/latest/2.0/#3.7.4
  • Loading branch information
mmatyas committed Mar 4, 2020
commit 8389189d943dfd5b404401ae41e73da71ec774be

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

@@ -35,7 +35,7 @@ raqote = {git = "https://github.com/jrmuizel/raqote"}
time = { version = "0.1.0", optional = true }
pixels = {path = "../pixels"}
servo_config = {path = "../config"}
sparkle = "0.1.19"
sparkle = "0.1.20"
webrender = {git = "https://github.com/servo/webrender"}
webrender_api = {git = "https://github.com/servo/webrender"}
webrender_traits = {path = "../webrender_traits"}
@@ -79,6 +79,8 @@ impl GLLimitsDetect for GLLimits {
max_vertex_uniform_components,
max_fragment_uniform_blocks,
max_fragment_uniform_components,
max_3d_texture_size,
max_array_texture_layers,
uniform_buffer_offset_alignment,
);
if webgl_version == WebGLVersion::WebGL2 {
@@ -102,6 +104,8 @@ impl GLLimitsDetect for GLLimits {
max_fragment_uniform_blocks = gl.get_integer(gl::MAX_FRAGMENT_UNIFORM_BLOCKS);
max_fragment_uniform_components = gl.get_integer(gl::MAX_FRAGMENT_UNIFORM_COMPONENTS);
uniform_buffer_offset_alignment = gl.get_integer(gl::UNIFORM_BUFFER_OFFSET_ALIGNMENT);
max_3d_texture_size = gl.get_integer(gl::MAX_3D_TEXTURE_SIZE);
max_array_texture_layers = gl.get_integer(gl::MAX_ARRAY_TEXTURE_LAYERS)
} else {
max_uniform_block_size = 0;
max_uniform_buffer_bindings = 0;
@@ -118,6 +122,8 @@ impl GLLimitsDetect for GLLimits {
max_fragment_uniform_blocks = 0;
max_fragment_uniform_components = 0;
uniform_buffer_offset_alignment = 0;
max_3d_texture_size = 0;
max_array_texture_layers = 0;
}

GLLimits {
@@ -148,6 +154,8 @@ impl GLLimitsDetect for GLLimits {
max_vertex_uniform_components,
max_fragment_uniform_blocks,
max_fragment_uniform_components,
max_3d_texture_size,
max_array_texture_layers,
uniform_buffer_offset_alignment,
}
}
@@ -1974,6 +1974,19 @@ impl WebGLImpl {
WebGLCommand::InvalidateSubFramebuffer(target, ref attachments, x, y, w, h) => {
gl.invalidate_sub_framebuffer(target, attachments, x, y, w, h)
},
WebGLCommand::FramebufferTextureLayer(target, attachment, tex_id, level, layer) => {
let tex_id = tex_id.map_or(0, WebGLTextureId::get);
let attach = |attachment| {
gl.framebuffer_texture_layer(target, attachment, tex_id, level, layer)
};

if attachment == gl::DEPTH_STENCIL_ATTACHMENT {
attach(gl::DEPTH_ATTACHMENT);
attach(gl::STENCIL_ATTACHMENT);
} else {
attach(attachment)
}
},
}

// If debug asertions are enabled, then check the error state.
@@ -535,6 +535,7 @@ pub enum WebGLCommand {
ClearBufferfi(u32, i32, f32, i32),
InvalidateFramebuffer(u32, Vec<u32>),
InvalidateSubFramebuffer(u32, Vec<u32>, i32, i32, i32, i32),
FramebufferTextureLayer(u32, u32, Option<WebGLTextureId>, i32, i32),
}

macro_rules! nonzero_type {
@@ -1074,5 +1075,7 @@ pub struct GLLimits {
pub max_vertex_uniform_components: u32,
pub max_fragment_uniform_blocks: u32,
pub max_fragment_uniform_components: u32,
pub max_3d_texture_size: u32,
pub max_array_texture_layers: u32,
pub uniform_buffer_offset_alignment: u32,
}
@@ -3581,6 +3581,36 @@ impl WebGL2RenderingContextMethods for WebGL2RenderingContext {
height,
))
}

/// https://www.khronos.org/registry/webgl/specs/latest/2.0/#3.7.4
fn FramebufferTextureLayer(
&self,
target: u32,
attachment: u32,
texture: Option<&WebGLTexture>,
level: i32,
layer: i32,
) {
if let Some(tex) = texture {
handle_potential_webgl_error!(self.base, self.base.validate_ownership(tex), return);
}

let fb_slot = match target {
constants::FRAMEBUFFER | constants::DRAW_FRAMEBUFFER => {
self.base.get_draw_framebuffer_slot()
},
constants::READ_FRAMEBUFFER => self.base.get_read_framebuffer_slot(),
_ => return self.base.webgl_error(InvalidEnum),
};

match fb_slot.get() {
Some(fb) => handle_potential_webgl_error!(
self.base,
fb.texture_layer(attachment, texture, level, layer)
),
None => self.base.webgl_error(InvalidOperation),
}
}
}

impl LayoutCanvasWebGLRenderingContextHelpers for LayoutDom<WebGL2RenderingContext> {
@@ -727,6 +727,61 @@ impl WebGLFramebuffer {
Ok(())
}

pub fn texture_layer(
&self,
attachment: u32,
texture: Option<&WebGLTexture>,
level: i32,
layer: i32,
) -> WebGLResult<()> {
let binding = self
.attachment_binding(attachment)
.ok_or(WebGLError::InvalidEnum)?;

let context = self.upcast::<WebGLObject>().context();

let tex_id = match texture {
Some(texture) => {
let (max_level, max_layer) = match texture.target() {
Some(constants::TEXTURE_3D) => (
log2(context.limits().max_3d_texture_size),
context.limits().max_3d_texture_size - 1,
),
Some(constants::TEXTURE_2D) => (
log2(context.limits().max_tex_size),
context.limits().max_array_texture_layers - 1,
),
_ => return Err(WebGLError::InvalidOperation),
};

if level < 0 || level as u32 >= max_level {
return Err(WebGLError::InvalidValue);
}
if layer < 0 || layer as u32 >= max_layer {
return Err(WebGLError::InvalidValue);
}

*binding.borrow_mut() = Some(WebGLFramebufferAttachment::Texture {
texture: Dom::from_ref(texture),
level: level,
});
texture.attach_to_framebuffer(self);

Some(texture.id())
},
_ => None,
};

context.send_command(WebGLCommand::FramebufferTextureLayer(
self.target.get().unwrap(),
attachment,
tex_id,
level,
layer,
));
Ok(())
}

fn with_matching_renderbuffers<F>(&self, rb: &WebGLRenderbuffer, mut closure: F)
where
F: FnMut(&DomRefCell<Option<WebGLFramebufferAttachment>>, u32),
@@ -312,8 +312,8 @@ interface mixin WebGL2RenderingContextBase
/* Framebuffer objects */
// void blitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0,
// GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter);
// void framebufferTextureLayer(GLenum target, GLenum attachment, WebGLTexture? texture, GLint level,
// GLint layer);
void framebufferTextureLayer(GLenum target, GLenum attachment, WebGLTexture? texture, GLint level,
GLint layer);
void invalidateFramebuffer(GLenum target, sequence<GLenum> attachments);
void invalidateSubFramebuffer(GLenum target, sequence<GLenum> attachments,
GLint x, GLint y, GLsizei width, GLsizei height);
@@ -1,79 +1,76 @@
[methods-2.html]
[WebGL test #20: Property either does not exist or is not a function: drawBuffers]
[WebGL test #11: Property either does not exist or is not a function: compressedTexSubImage3D]
expected: FAIL

[WebGL test #9: Property either does not exist or is not a function: texSubImage3D]
[WebGL test #8: Property either does not exist or is not a function: texSubImage3D]
expected: FAIL

[WebGL test #2: Property either does not exist or is not a function: framebufferTextureLayer]
[WebGL test #14: Property either does not exist or is not a function: vertexAttribI4iv]
expected: FAIL

[WebGL test #7: Property either does not exist or is not a function: texStorage2D]
[WebGL test #15: Property either does not exist or is not a function: vertexAttribI4ui]
expected: FAIL

[WebGL test #8: Property either does not exist or is not a function: texStorage3D]
[WebGL test #22: Property either does not exist or is not a function: deleteVertexArray]
expected: FAIL

[WebGL test #15: Property either does not exist or is not a function: vertexAttribI4iv]
[WebGL test #6: Property either does not exist or is not a function: texStorage2D]
expected: FAIL

[WebGL test #5: Property either does not exist or is not a function: renderbufferStorageMultisample]
expected: FAIL

[WebGL test #16: Property either does not exist or is not a function: vertexAttribI4ui]
[WebGL test #1: Property either does not exist or is not a function: blitFramebuffer]
expected: FAIL

[WebGL test #22: Property either does not exist or is not a function: createVertexArray]
[WebGL test #13: Property either does not exist or is not a function: vertexAttribI4i]
expected: FAIL

[WebGL test #4: Property either does not exist or is not a function: readBuffer]
[WebGL test #5: Property either does not exist or is not a function: texImage3D]
expected: FAIL

[WebGL test #11: Property either does not exist or is not a function: compressedTexImage3D]
[WebGL test #4: Property either does not exist or is not a function: renderbufferStorageMultisample]
expected: FAIL

[WebGL test #1: Property either does not exist or is not a function: blitFramebuffer]
[WebGL test #20: Property either does not exist or is not a function: getIndexedParameter]
expected: FAIL

[WebGL test #24: Property either does not exist or is not a function: isVertexArray]
[WebGL test #19: Property either does not exist or is not a function: drawBuffers]
expected: FAIL

[WebGL test #12: Property either does not exist or is not a function: compressedTexSubImage3D]
[WebGL test #10: Property either does not exist or is not a function: compressedTexImage3D]
expected: FAIL

[WebGL test #18: Property either does not exist or is not a function: vertexAttribIPointer]
[WebGL test #7: Property either does not exist or is not a function: texStorage3D]
expected: FAIL

[WebGL test #6: Property either does not exist or is not a function: texImage3D]
[WebGL test #16: Property either does not exist or is not a function: vertexAttribI4uiv]
expected: FAIL

[WebGL test #3: Property either does not exist or is not a function: getInternalformatParameter]
[WebGL test #18: Property either does not exist or is not a function: drawRangeElements]
expected: FAIL

[WebGL test #21: Property either does not exist or is not a function: getIndexedParameter]
[WebGL test #9: Property either does not exist or is not a function: copyTexSubImage3D]
expected: FAIL

[WebGL test #13: Property either does not exist or is not a function: getFragDataLocation]
[WebGL test #0: Property either does not exist or is not a function: isContextLost]
expected: FAIL

[WebGL test #0: Property either does not exist or is not a function: isContextLost]
[WebGL test #17: Property either does not exist or is not a function: vertexAttribIPointer]
expected: FAIL

[WebGL test #10: Property either does not exist or is not a function: copyTexSubImage3D]
[WebGL test #2: Property either does not exist or is not a function: getInternalformatParameter]
expected: FAIL

[WebGL test #25: Property either does not exist or is not a function: bindVertexArray]
[WebGL test #3: Property either does not exist or is not a function: readBuffer]
expected: FAIL

[WebGL test #17: Property either does not exist or is not a function: vertexAttribI4uiv]
[WebGL test #21: Property either does not exist or is not a function: createVertexArray]
expected: FAIL

[WebGL test #19: Property either does not exist or is not a function: drawRangeElements]
[WebGL test #12: Property either does not exist or is not a function: getFragDataLocation]
expected: FAIL

[WebGL test #14: Property either does not exist or is not a function: vertexAttribI4i]
[WebGL test #24: Property either does not exist or is not a function: bindVertexArray]
expected: FAIL

[WebGL test #23: Property either does not exist or is not a function: deleteVertexArray]
[WebGL test #23: Property either does not exist or is not a function: isVertexArray]
expected: FAIL

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.