aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/webglframebuffer.rs
diff options
context:
space:
mode:
authorMátyás Mustoha <matyas.mustoha@h-lab.eu>2020-02-14 13:14:07 +0100
committerMátyás Mustoha <matyas.mustoha@h-lab.eu>2020-03-04 10:07:13 +0100
commit8389189d943dfd5b404401ae41e73da71ec774be (patch)
tree10e60c9ee0869f63b349c3e5b401e572ad697896 /components/script/dom/webglframebuffer.rs
parent61cf25c98ae73f5c1d9c7fac7dd02f83dbfeb703 (diff)
downloadservo-8389189d943dfd5b404401ae41e73da71ec774be.tar.gz
servo-8389189d943dfd5b404401ae41e73da71ec774be.zip
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
Diffstat (limited to 'components/script/dom/webglframebuffer.rs')
-rw-r--r--components/script/dom/webglframebuffer.rs55
1 files changed, 55 insertions, 0 deletions
diff --git a/components/script/dom/webglframebuffer.rs b/components/script/dom/webglframebuffer.rs
index 8f5f499072a..51604d3e415 100644
--- a/components/script/dom/webglframebuffer.rs
+++ b/components/script/dom/webglframebuffer.rs
@@ -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),