webgl: Add support for renderbufferStorage().

This is not a complete implementation yet: It doesn't clear the
contents of the renderbuffer on creation.  However, Gecko's plan to
only clear renderbuffers when the first FBO using them is the
simplest.
This commit is contained in:
Eric Anholt 2016-09-10 17:29:50 -07:00
parent 8a0ca2efba
commit 989c936e67
8 changed files with 69 additions and 30 deletions

View file

@ -5,13 +5,14 @@
// https://www.khronos.org/registry/webgl/specs/latest/1.0/webgl.idl
use canvas_traits::CanvasMsg;
use dom::bindings::codegen::Bindings::WebGLRenderbufferBinding;
use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLRenderingContextConstants as constants;
use dom::bindings::js::Root;
use dom::bindings::reflector::reflect_dom_object;
use dom::globalscope::GlobalScope;
use dom::webglobject::WebGLObject;
use ipc_channel::ipc::{self, IpcSender};
use std::cell::Cell;
use webrender_traits::{WebGLCommand, WebGLRenderbufferId};
use webrender_traits::{WebGLCommand, WebGLRenderbufferId, WebGLResult, WebGLError};
#[dom_struct]
pub struct WebGLRenderbuffer {
@ -19,6 +20,7 @@ pub struct WebGLRenderbuffer {
id: WebGLRenderbufferId,
ever_bound: Cell<bool>,
is_deleted: Cell<bool>,
internal_format: Cell<Option<u32>>,
#[ignore_heap_size_of = "Defined in ipc-channel"]
renderer: IpcSender<CanvasMsg>,
}
@ -33,6 +35,7 @@ impl WebGLRenderbuffer {
ever_bound: Cell::new(false),
is_deleted: Cell::new(false),
renderer: renderer,
internal_format: Cell::new(None),
}
}
@ -81,4 +84,28 @@ impl WebGLRenderbuffer {
pub fn ever_bound(&self) -> bool {
self.ever_bound.get()
}
pub fn storage(&self, internal_format: u32, width: i32, height: i32) -> WebGLResult<()> {
// Validate the internal_format, and save it for completeness
// validation.
match internal_format {
constants::RGBA4 |
constants::DEPTH_STENCIL |
constants::DEPTH_COMPONENT16 |
constants::STENCIL_INDEX8 =>
self.internal_format.set(Some(internal_format)),
_ => return Err(WebGLError::InvalidEnum),
};
// FIXME: Check that w/h are < MAX_RENDERBUFFER_SIZE
// FIXME: Invalidate completeness after the call
let msg = CanvasMsg::WebGL(WebGLCommand::RenderbufferStorage(constants::RENDERBUFFER,
internal_format, width, height));
self.renderer.send(msg).unwrap();
Ok(())
}
}