Implement IsShader fn and IsTexture fn for WebGLRenderingContext

This commit is contained in:
Daniel 2016-05-07 12:06:17 -04:00
parent a09b2374f9
commit 8a5b0b8972
5 changed files with 51 additions and 2 deletions

View file

@ -32,6 +32,7 @@ pub struct WebGLShader {
source: DOMRefCell<Option<DOMString>>,
info_log: DOMRefCell<Option<String>>,
is_deleted: Cell<bool>,
attached_counter: Cell<u32>,
compilation_status: Cell<ShaderCompilationStatus>,
#[ignore_heap_size_of = "Defined in ipc-channel"]
renderer: IpcSender<CanvasMsg>,
@ -55,6 +56,7 @@ impl WebGLShader {
source: DOMRefCell::new(None),
info_log: DOMRefCell::new(None),
is_deleted: Cell::new(false),
attached_counter: Cell::new(0),
compilation_status: Cell::new(ShaderCompilationStatus::NotCompiled),
renderer: renderer,
}
@ -126,6 +128,7 @@ impl WebGLShader {
/// Mark this shader as deleted (if it wasn't previously)
/// and delete it as if calling glDeleteShader.
/// Currently does not check if shader is attached
pub fn delete(&self) {
if !self.is_deleted.get() {
self.is_deleted.set(true);
@ -133,6 +136,23 @@ impl WebGLShader {
}
}
pub fn is_deleted(&self) -> bool {
self.is_deleted.get()
}
pub fn is_attached(&self) -> bool {
self.attached_counter.get() > 0
}
pub fn increment_attached_counter(&self) {
self.attached_counter.set(self.attached_counter.get() + 1);
}
pub fn decrement_attached_counter(&self) {
assert!(self.attached_counter.get() > 0);
self.attached_counter.set(self.attached_counter.get() - 1);
}
/// glGetShaderInfoLog
pub fn info_log(&self) -> Option<String> {
self.info_log.borrow().clone()
@ -162,6 +182,7 @@ impl WebGLShader {
impl Drop for WebGLShader {
fn drop(&mut self) {
assert!(self.attached_counter.get() == 0);
self.delete();
}
}