diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2018-03-22 12:28:30 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-03-22 12:28:30 -0400 |
commit | 4aaac61a87f4e45e46d0591be73ce108e562c33f (patch) | |
tree | e8786e5026db056b14393adeb61e63011f619bf4 /components/script | |
parent | 2de89377db63ec03ae3b1256486c4c32b33f5fce (diff) | |
parent | ee5bdbbd8b99b58eda19c117b1a06e4a90a61bb1 (diff) | |
download | servo-4aaac61a87f4e45e46d0591be73ce108e562c33f.tar.gz servo-4aaac61a87f4e45e46d0591be73ce108e562c33f.zip |
Auto merge of #20317 - gootorov:webgl-getFramebufferAttachmentParameter, r=jdm
Implement WebGL getFrameBufferAttachmentParameter API
<!-- Please describe your changes on the following line: -->
Implementation of `getFramebufferAttachmentParameter` as in WebGL1 specification.
Part of https://github.com/servo/servo/issues/10209.
r? emilio or jdm.
---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [ ] These changes fix #__ (github issue number if applicable).
<!-- Either: -->
- [x] There are tests for these changes
<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->
<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/20317)
<!-- Reviewable:end -->
Diffstat (limited to 'components/script')
-rw-r--r-- | components/script/dom/webgl2renderingcontext.rs | 12 | ||||
-rw-r--r-- | components/script/dom/webglframebuffer.rs | 25 | ||||
-rw-r--r-- | components/script/dom/webglrenderingcontext.rs | 94 | ||||
-rw-r--r-- | components/script/dom/webidls/WebGLRenderingContext.webidl | 4 |
4 files changed, 132 insertions, 3 deletions
diff --git a/components/script/dom/webgl2renderingcontext.rs b/components/script/dom/webgl2renderingcontext.rs index 2a25c450b08..2d1186c0dcc 100644 --- a/components/script/dom/webgl2renderingcontext.rs +++ b/components/script/dom/webgl2renderingcontext.rs @@ -142,6 +142,18 @@ impl WebGL2RenderingContextMethods for WebGL2RenderingContext { self.base.GetExtension(cx, name) } + #[allow(unsafe_code)] + /// https://www.khronos.org/registry/webgl/specs/latest/2.0/#3.7.4 + unsafe fn GetFramebufferAttachmentParameter( + &self, + cx: *mut JSContext, + target: u32, + attachment: u32, + pname: u32 + ) -> JSVal { + self.base.GetFramebufferAttachmentParameter(cx, target, attachment, pname) + } + /// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.3 fn ActiveTexture(&self, texture: u32) { self.base.ActiveTexture(texture) diff --git a/components/script/dom/webglframebuffer.rs b/components/script/dom/webglframebuffer.rs index c9165609cdb..ccea1efec7b 100644 --- a/components/script/dom/webglframebuffer.rs +++ b/components/script/dom/webglframebuffer.rs @@ -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 { diff --git a/components/script/dom/webglrenderingcontext.rs b/components/script/dom/webglrenderingcontext.rs index 64990da1504..ad572751607 100644 --- a/components/script/dom/webglrenderingcontext.rs +++ b/components/script/dom/webglrenderingcontext.rs @@ -10,6 +10,7 @@ use canvas_traits::webgl::DOMToTextureCommand; use canvas_traits::webgl::WebGLError::*; use canvas_traits::webgl::webgl_channel; use dom::bindings::cell::DomRefCell; +use dom::bindings::codegen::Bindings::WebGL2RenderingContextBinding::WebGL2RenderingContextConstants as WebGL2Constants; use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::{self, WebGLContextAttributes}; use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLRenderingContextConstants as constants; use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLRenderingContextMethods; @@ -33,7 +34,7 @@ use dom::webgl_validations::types::{TexDataType, TexFormat, TexImageTarget}; use dom::webglactiveinfo::WebGLActiveInfo; use dom::webglbuffer::WebGLBuffer; use dom::webglcontextevent::WebGLContextEvent; -use dom::webglframebuffer::WebGLFramebuffer; +use dom::webglframebuffer::{WebGLFramebuffer, WebGLFramebufferAttachmentRoot}; use dom::webglprogram::WebGLProgram; use dom::webglrenderbuffer::WebGLRenderbuffer; use dom::webglshader::WebGLShader; @@ -1554,6 +1555,10 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext { // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.6 fn BindFramebuffer(&self, target: u32, framebuffer: Option<&WebGLFramebuffer>) { + if target == WebGL2Constants::READ_FRAMEBUFFER { + return self.webgl_error(InvalidEnum); + } + if target != constants::FRAMEBUFFER { return self.webgl_error(InvalidOperation); } @@ -2297,6 +2302,93 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext { } } + #[allow(unsafe_code)] + // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.6 + unsafe fn GetFramebufferAttachmentParameter( + &self, + cx: *mut JSContext, + target: u32, + attachment: u32, + pname: u32 + ) -> JSVal { + // Check if currently bound framebuffer is non-zero as per spec. + if self.bound_framebuffer.get().is_none() { + self.webgl_error(InvalidOperation); + return NullValue(); + } + + // Note: commented out stuff is for the WebGL2 standard. + let target_matches = match target { + // constants::READ_FRAMEBUFFER | + // constants::DRAW_FRAMEBUFFER => true, + constants::FRAMEBUFFER => true, + _ => false + }; + let attachment_matches = match attachment { + // constants::MAX_COLOR_ATTACHMENTS ... gl::COLOR_ATTACHMENT0 | + // constants::BACK | + constants::COLOR_ATTACHMENT0 | + constants::DEPTH_STENCIL_ATTACHMENT | + constants::DEPTH_ATTACHMENT | + constants::STENCIL_ATTACHMENT => true, + _ => false, + }; + let pname_matches = match pname { + // constants::FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE | + // constants::FRAMEBUFFER_ATTACHMENT_BLUE_SIZE | + // constants::FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING | + // constants::FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE | + // constants::FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE | + // constants::FRAMEBUFFER_ATTACHMENT_GREEN_SIZE | + // constants::FRAMEBUFFER_ATTACHMENT_RED_SIZE | + // constants::FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE | + // constants::FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER | + constants::FRAMEBUFFER_ATTACHMENT_OBJECT_NAME | + constants::FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE | + constants::FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE | + constants::FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL => true, + _ => false + }; + + if !target_matches || !attachment_matches || !pname_matches { + self.webgl_error(InvalidEnum); + return NullValue(); + } + + // From the GLES2 spec: + // + // If the value of FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE is NONE, + // then querying any other pname will generate INVALID_ENUM. + // + // otherwise, return `WebGLRenderbuffer` or `WebGLTexture` dom object + if pname == constants::FRAMEBUFFER_ATTACHMENT_OBJECT_NAME { + // if fb is None, an INVALID_OPERATION is returned + // at the beggining of the function, so `.unwrap()` will never panic + let fb = self.bound_framebuffer.get().unwrap(); + if let Some(webgl_attachment) = fb.attachment(attachment) { + match webgl_attachment { + WebGLFramebufferAttachmentRoot::Renderbuffer(rb) => { + rooted!(in(cx) let mut rval = NullValue()); + rb.to_jsval(cx, rval.handle_mut()); + return rval.get(); + }, + WebGLFramebufferAttachmentRoot::Texture(texture) => { + rooted!(in(cx) let mut rval = NullValue()); + texture.to_jsval(cx, rval.handle_mut()); + return rval.get(); + }, + } + } + self.webgl_error(InvalidEnum); + return NullValue(); + } + + let (sender, receiver) = webgl_channel().unwrap(); + self.send_command(WebGLCommand::GetFramebufferAttachmentParameter(target, attachment, pname, sender)); + + Int32Value(receiver.recv().unwrap()) + } + // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.9 fn GetProgramInfoLog(&self, program: Option<&WebGLProgram>) -> Option<DOMString> { if let Some(program) = program { diff --git a/components/script/dom/webidls/WebGLRenderingContext.webidl b/components/script/dom/webidls/WebGLRenderingContext.webidl index 3f845126701..05e9212d974 100644 --- a/components/script/dom/webidls/WebGLRenderingContext.webidl +++ b/components/script/dom/webidls/WebGLRenderingContext.webidl @@ -589,8 +589,8 @@ interface WebGLRenderingContextBase [WebGLHandlesContextLoss] GLenum getError(); - //any getFramebufferAttachmentParameter(GLenum target, GLenum attachment, - // GLenum pname); + any getFramebufferAttachmentParameter(GLenum target, GLenum attachment, + GLenum pname); any getProgramParameter(WebGLProgram? program, GLenum pname); DOMString? getProgramInfoLog(WebGLProgram? program); //any getRenderbufferParameter(GLenum target, GLenum pname); |