diff options
author | Mátyás Mustoha <matyas.mustoha@h-lab.eu> | 2020-02-25 10:47:59 +0100 |
---|---|---|
committer | Mátyás Mustoha <matyas.mustoha@h-lab.eu> | 2020-03-16 12:17:15 +0100 |
commit | 0afe27ef18e1bb458863bd881c79d0fa63d9c4a4 (patch) | |
tree | 20d762f9809d0eee4e8301def5ac513da9f09384 /components/script/dom/webglframebuffer.rs | |
parent | e8e0b702662704572e7c04a78d0ab9e023a0ad5c (diff) | |
download | servo-0afe27ef18e1bb458863bd881c79d0fa63d9c4a4.tar.gz servo-0afe27ef18e1bb458863bd881c79d0fa63d9c4a4.zip |
Add support for WebGL2 read and draw buffer settings
Adds support for the `ReadBuffer` and `DrawBuffers`
WebGL2 calls and the related parameter getters.
See:
- https://www.khronos.org/registry/webgl/specs/latest/2.0/#3.7.2
- https://www.khronos.org/registry/webgl/specs/latest/2.0/#3.7.4
- https://www.khronos.org/registry/webgl/specs/latest/2.0/#3.7.11
Diffstat (limited to 'components/script/dom/webglframebuffer.rs')
-rw-r--r-- | components/script/dom/webglframebuffer.rs | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/components/script/dom/webglframebuffer.rs b/components/script/dom/webglframebuffer.rs index 2d6fcf9122d..f3f6e939f4f 100644 --- a/components/script/dom/webglframebuffer.rs +++ b/components/script/dom/webglframebuffer.rs @@ -101,6 +101,8 @@ pub struct WebGLFramebuffer { depth: DomRefCell<Option<WebGLFramebufferAttachment>>, stencil: DomRefCell<Option<WebGLFramebufferAttachment>>, depthstencil: DomRefCell<Option<WebGLFramebufferAttachment>>, + color_read_buffer: DomRefCell<u32>, + color_draw_buffers: DomRefCell<Vec<u32>>, is_initialized: Cell<bool>, // Framebuffers for XR keep a reference to the XR session. // https://github.com/immersive-web/webxr/issues/856 @@ -121,6 +123,8 @@ impl WebGLFramebuffer { depth: DomRefCell::new(None), stencil: DomRefCell::new(None), depthstencil: DomRefCell::new(None), + color_read_buffer: DomRefCell::new(constants::COLOR_ATTACHMENT0), + color_draw_buffers: DomRefCell::new(vec![constants::COLOR_ATTACHMENT0]), is_initialized: Cell::new(false), xr_session: Default::default(), } @@ -914,6 +918,55 @@ impl WebGLFramebuffer { }); } + pub fn set_read_buffer(&self, buffer: u32) -> WebGLResult<()> { + let context = self.upcast::<WebGLObject>().context(); + + match buffer { + constants::NONE => {}, + _ if context.valid_color_attachment_enum(buffer) => {}, + _ => return Err(WebGLError::InvalidOperation), + }; + + *self.color_read_buffer.borrow_mut() = buffer; + context.send_command(WebGLCommand::ReadBuffer(buffer)); + Ok(()) + } + + pub fn set_draw_buffers(&self, buffers: Vec<u32>) -> WebGLResult<()> { + let context = self.upcast::<WebGLObject>().context(); + + if buffers.len() > context.limits().max_draw_buffers as usize { + return Err(WebGLError::InvalidValue); + } + + let enums_valid = buffers + .iter() + .all(|&val| val == constants::NONE || context.valid_color_attachment_enum(val)); + if !enums_valid { + return Err(WebGLError::InvalidEnum); + } + + let values_valid = buffers.iter().enumerate().all(|(i, &val)| { + val == constants::NONE || val == (constants::COLOR_ATTACHMENT0 + i as u32) + }); + if !values_valid { + return Err(WebGLError::InvalidOperation); + } + + *self.color_draw_buffers.borrow_mut() = buffers.clone(); + context.send_command(WebGLCommand::DrawBuffers(buffers)); + Ok(()) + } + + pub fn read_buffer(&self) -> u32 { + *self.color_read_buffer.borrow() + } + + pub fn draw_buffer_i(&self, index: usize) -> u32 { + let buffers = &*self.color_draw_buffers.borrow(); + *buffers.get(index).unwrap_or(&constants::NONE) + } + pub fn target(&self) -> Option<u32> { self.target.get() } |