mirror of
https://github.com/servo/servo.git
synced 2025-08-05 21:50:18 +01:00
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:
parent
8a0ca2efba
commit
989c936e67
8 changed files with 69 additions and 30 deletions
|
@ -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(())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2569,6 +2569,39 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
|
|||
None => return constants::FRAMEBUFFER_COMPLETE,
|
||||
}
|
||||
}
|
||||
|
||||
fn RenderbufferStorage(&self, target: u32, internal_format: u32,
|
||||
width: i32, height: i32) {
|
||||
// From the GLES 2.0.25 spec:
|
||||
//
|
||||
// "target must be RENDERBUFFER."
|
||||
if target != constants::RENDERBUFFER {
|
||||
return self.webgl_error(InvalidOperation)
|
||||
}
|
||||
|
||||
// From the GLES 2.0.25 spec:
|
||||
//
|
||||
// "If either width or height is greater than the value of
|
||||
// MAX_RENDERBUFFER_SIZE , the error INVALID_VALUE is
|
||||
// generated."
|
||||
//
|
||||
// and we have to throw out negative-size values as well just
|
||||
// like for TexImage.
|
||||
//
|
||||
// FIXME: Handle max_renderbuffer_size, which doesn't seem to
|
||||
// be in limits.
|
||||
if width < 0 || height < 0 {
|
||||
return self.webgl_error(InvalidValue);
|
||||
}
|
||||
|
||||
match self.bound_renderbuffer.get() {
|
||||
Some(rb) => handle_potential_webgl_error!(self, rb.storage(internal_format, width, height)),
|
||||
None => self.webgl_error(InvalidOperation),
|
||||
};
|
||||
|
||||
// FIXME: We need to clear the renderbuffer before it can be
|
||||
// accessed. See https://github.com/servo/servo/issues/13710
|
||||
}
|
||||
}
|
||||
|
||||
pub trait LayoutCanvasWebGLRenderingContextHelpers {
|
||||
|
|
|
@ -626,8 +626,8 @@ interface WebGLRenderingContextBase
|
|||
void readPixels(GLint x, GLint y, GLsizei width, GLsizei height,
|
||||
GLenum format, GLenum type, object? pixels);
|
||||
|
||||
//void renderbufferStorage(GLenum target, GLenum internalformat,
|
||||
// GLsizei width, GLsizei height);
|
||||
void renderbufferStorage(GLenum target, GLenum internalformat,
|
||||
GLsizei width, GLsizei height);
|
||||
void sampleCoverage(GLclampf value, GLboolean invert);
|
||||
void scissor(GLint x, GLint y, GLsizei width, GLsizei height);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue