Implement WebGL getFramebufferAttachmentParameter API

This commit is contained in:
Igor Gutorov 2018-03-14 20:41:36 +02:00
parent f92f0809f8
commit ee5bdbbd8b
10 changed files with 338 additions and 110 deletions

View file

@ -25,6 +25,12 @@ enum WebGLFramebufferAttachment {
Texture { texture: Dom<WebGLTexture>, level: i32 },
}
#[derive(Clone, JSTraceable, MallocSizeOf)]
pub enum WebGLFramebufferAttachmentRoot {
Renderbuffer(DomRoot<WebGLRenderbuffer>),
Texture(DomRoot<WebGLTexture>),
}
#[dom_struct]
pub struct WebGLFramebuffer {
webgl_object: WebGLObject,
@ -213,6 +219,25 @@ impl WebGLFramebuffer {
Ok(())
}
pub fn attachment(&self, attachment: u32) -> Option<WebGLFramebufferAttachmentRoot> {
let binding = match attachment {
constants::COLOR_ATTACHMENT0 => &self.color,
constants::DEPTH_ATTACHMENT => &self.depth,
constants::STENCIL_ATTACHMENT => &self.stencil,
constants::DEPTH_STENCIL_ATTACHMENT => &self.depthstencil,
_ => return None,
};
binding.borrow().as_ref().map(|bin| {
match bin {
&WebGLFramebufferAttachment::Renderbuffer(ref rb) =>
WebGLFramebufferAttachmentRoot::Renderbuffer(DomRoot::from_ref(&rb)),
&WebGLFramebufferAttachment::Texture { ref texture, .. } =>
WebGLFramebufferAttachmentRoot::Texture(DomRoot::from_ref(&texture)),
}
})
}
pub fn texture2d(&self, attachment: u32, textarget: u32, texture: Option<&WebGLTexture>,
level: i32) -> WebGLResult<()> {
let binding = match attachment {