diff options
author | ecoal95 <ecoal95@gmail.com> | 2015-07-25 21:01:44 +0200 |
---|---|---|
committer | ecoal95 <ecoal95@gmail.com> | 2015-08-25 17:16:46 +0200 |
commit | 6341c77700fa5f914c32c6153e9c532bc69474fd (patch) | |
tree | 3509f4dc996823641e384972baf7a22aa5ad1ad9 /components/script/dom/webglbuffer.rs | |
parent | af3310f1490e93b2b1a77c1c1e9aab13cc46c9d5 (diff) | |
download | servo-6341c77700fa5f914c32c6153e9c532bc69474fd.tar.gz servo-6341c77700fa5f914c32c6153e9c532bc69474fd.zip |
webgl: Implement multiple calls and improve error detection
This commit implements WebGL's:
* cullFace
* frontFace
* enable
* disable
* depthMask
* colorMask
* clearDepth
* clearStencil
* depthFunc
* depthRange
* hint
* lineWidth
* pixelStorei
* polygonOffset
* texParameteri
* texParameterf
* texImage2D (partially)
It inlines a lot of OpenGL calls to keep the file
`components/canvas/webgl_paint_task.rs` as small as possible while
keeping readability.
It also improves error detection on previous calls, and sets node damage
on the canvas in the drawing calls.
It adds a `TexImage2D` reftest, even though it's not enabled because:
* WebGL paints the image when it loads (asynchronously), so the reftest doesn't wait for it and it finishes early
* If we change the source for the base64 src of the image it works as expected in non-headless mode, but the test harness locks
Diffstat (limited to 'components/script/dom/webglbuffer.rs')
-rw-r--r-- | components/script/dom/webglbuffer.rs | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/components/script/dom/webglbuffer.rs b/components/script/dom/webglbuffer.rs index 5ad078a38e5..6f958d62597 100644 --- a/components/script/dom/webglbuffer.rs +++ b/components/script/dom/webglbuffer.rs @@ -9,7 +9,7 @@ use dom::bindings::js::Root; use dom::bindings::utils::reflect_dom_object; use dom::webglobject::WebGLObject; -use canvas_traits::{CanvasMsg, CanvasWebGLMsg}; +use canvas_traits::{CanvasMsg, CanvasWebGLMsg, WebGLError, WebGLResult}; use ipc_channel::ipc::{self, IpcSender}; use std::cell::Cell; @@ -18,6 +18,8 @@ use std::cell::Cell; pub struct WebGLBuffer { webgl_object: WebGLObject, id: u32, + /// The target to which this buffer was bound the first time + target: Cell<Option<u32>>, is_deleted: Cell<bool>, #[ignore_heap_size_of = "Defined in ipc-channel"] renderer: IpcSender<CanvasMsg>, @@ -28,6 +30,7 @@ impl WebGLBuffer { WebGLBuffer { webgl_object: WebGLObject::new_inherited(), id: id, + target: Cell::new(None), is_deleted: Cell::new(false), renderer: renderer, } @@ -49,7 +52,7 @@ impl WebGLBuffer { pub trait WebGLBufferHelpers { fn id(self) -> u32; - fn bind(self, target: u32); + fn bind(self, target: u32) -> WebGLResult<()>; fn delete(self); } @@ -58,8 +61,18 @@ impl<'a> WebGLBufferHelpers for &'a WebGLBuffer { self.id } - fn bind(self, target: u32) { + // NB: Only valid buffer targets come here + fn bind(self, target: u32) -> WebGLResult<()> { + if let Some(previous_target) = self.target.get() { + if target != previous_target { + return Err(WebGLError::InvalidOperation); + } + } else { + self.target.set(Some(target)); + } self.renderer.send(CanvasMsg::WebGL(CanvasWebGLMsg::BindBuffer(target, self.id))).unwrap(); + + Ok(()) } fn delete(self) { |