Chromium Code Reviews| Index: Source/core/html/canvas/WebGL2RenderingContextBase.cpp |
| diff --git a/Source/core/html/canvas/WebGL2RenderingContextBase.cpp b/Source/core/html/canvas/WebGL2RenderingContextBase.cpp |
| index c0a3f6496f59dd8fd526ac58cda3521fc025dfdc..89f4978964ddb935e4e4debf5d308c4593d5f433 100644 |
| --- a/Source/core/html/canvas/WebGL2RenderingContextBase.cpp |
| +++ b/Source/core/html/canvas/WebGL2RenderingContextBase.cpp |
| @@ -1526,6 +1526,111 @@ bool WebGL2RenderingContextBase::validateAndUpdateBufferBindTarget(const char* f |
| return true; |
| } |
| +bool WebGL2RenderingContextBase::validateGetFramebufferAttachmentParameterFunc(const char* functionName, GLenum target, GLenum attachment) |
| +{ |
| + if (!validateFramebufferTarget(target) { |
| + synthesizeGLError(GL_INVALID_ENUM, functionName, "invalid target"); |
| + return false; |
| + } |
| + |
| + WebGLFramebuffer* framebufferBinding = getFramebufferBinding(target); |
| + ASSERT(framebufferBinding || drawingBuffer()); |
| + if (!framebufferBinding) { |
| + // for the default framebuffer |
| + switch (attachment) { |
| + case GL_BACK: |
| + case GL_DEPTH: |
| + case GL_STENCIL: |
| + break; |
| + default: |
| + synthesizeGLError(GL_INVALID_ENUM, functionName, "invalid attachment"); |
| + return false; |
| + } |
| + } else { |
| + // for the FBO |
| + switch (attachment) { |
| + case GL_COLOR_ATTACHMENT0: |
| + case GL_DEPTH_ATTACHMENT: |
| + case GL_STENCIL_ATTACHMENT: |
| + break; |
| + case GL_DEPTH_STENCIL_ATTACHMENT: |
| + if (framebufferBinding->getAttachmentObject(GL_DEPTH_STENCIL_ATTACHMENT) || (framebufferBinding->getAttachmentObject(GL_DEPTH_ATTACHMENT) == framebufferBinding->getAttachmentObject(GL_STENCIL_ATTACHMENT))) |
| + break; |
|
Ken Russell (switch to Gerrit)
2015/04/30 02:28:26
The scenario where different objects are bound to
|
| + default: |
| + if (attachment > GL_COLOR_ATTACHMENT0 |
| + && attachment < static_cast<GLenum>(GL_COLOR_ATTACHMENT0 + maxColorAttachments())) |
| + break; |
| + synthesizeGLError(GL_INVALID_ENUM, functionName, "invalid attachment"); |
| + return false; |
| + } |
| + } |
| + return true; |
| +} |
| + |
| +ScriptValue WebGL2RenderingContextBase::getFramebufferAttachmentParameter(ScriptState* scriptState, GLenum target, GLenum attachment, GLenum pname) |
| +{ |
| + if (isContextLost() || !validateGetFramebufferAttachmentParameterFunc("getFramebufferAttachmentParameter", target, attachment)) |
| + return ScriptValue::createNull(scriptState); |
| + |
| + WebGLFramebuffer* framebufferBinding = getFramebufferBinding(target); |
| + ASSERT(!framebufferBinding || framebufferBinding->object()); |
| + |
| + WebGLSharedObject* attachmentObject = framebufferBinding ? framebufferBinding->getAttachmentObject(attachment) : 0; |
| + if (framebufferBinding && !attachmentObject) { |
| + if (pname == GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE) |
| + return WebGLAny(scriptState, GL_NONE); |
| + if (pname == GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME) |
| + return WebGLAny(scriptState, 0); |
| + synthesizeGLError(GL_INVALID_OPERATION, "getFramebufferAttachmentParameter", "invalid parameter name"); |
| + return ScriptValue::createNull(scriptState); |
| + } |
| + |
| + switch (pname) { |
| + case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE: |
| + if (!attachmentObject) { |
| + ASSERT(!framebufferBinding); |
| + return WebGLAny(scriptState, GL_FRAMEBUFFER_DEFAULT); |
| + } |
| + ASSERT(attachmentObject->isTexture() || attachmentObject->isRenderbuffer()); |
| + if (attachmentObject->isTexture()) |
| + return WebGLAny(scriptState, GL_TEXTURE); |
| + if (attachmentObject->isRenderbuffer()) |
| + return WebGLAny(scriptState, GL_RENDERBUFFER); |
| + break; |
| + case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME: |
| + if (!attachmentObject) |
| + break; |
| + return WebGLAny(scriptState, PassRefPtrWillBeRawPtr<WebGLObject>(attachmentObject)); |
| + case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE: |
| + case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER: |
| + case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL: |
| + if (!attachmentObject || !attachmentObject->isTexture()) |
| + break; |
| + case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE: |
| + case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE: |
| + case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE: |
| + case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE: |
| + case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE: |
| + case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE: |
| + { |
| + GLint value = 0; |
| + webContext()->getFramebufferAttachmentParameteriv(target, attachment, pname, &value); |
| + return WebGLAny(scriptState, value); |
| + } |
| + case GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE: |
| + case GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING: |
| + { |
| + GLint value = 0; |
| + webContext()->getFramebufferAttachmentParameteriv(target, attachment, pname, &value); |
| + return WebGLAny(scriptState, static_cast<unsigned>(value)); |
| + } |
| + default: |
| + break; |
| + } |
| + synthesizeGLError(GL_INVALID_ENUM, "getFramebufferAttachmentParameter", "invalid parameter name"); |
| + return ScriptValue::createNull(scriptState); |
| +} |
| + |
| DEFINE_TRACE(WebGL2RenderingContextBase) |
| { |
| visitor->trace(m_readFramebufferBinding); |