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 b6f57f87ac8c23137bcad0062f63a038e1dc62b6..f55920d09937c2a03af126a7cca05e2b6f392150 100644 |
| --- a/Source/core/html/canvas/WebGL2RenderingContextBase.cpp |
| +++ b/Source/core/html/canvas/WebGL2RenderingContextBase.cpp |
| @@ -1196,6 +1196,108 @@ bool WebGL2RenderingContextBase::validateAndUpdateBufferBindTarget(const char* f |
| return true; |
| } |
| +bool WebGL2RenderingContextBase::validateGetFramebufferAttachmentParameters(const char* functionName, GLenum target, GLenum attachment) |
|
Zhenyao Mo
2015/03/06 18:35:37
I think you should fold this function into getFram
yunchao
2015/03/09 07:16:57
Agree. Considering that this validation is standal
|
| +{ |
| + if (target != GL_FRAMEBUFFER && target != GL_READ_FRAMEBUFFER) { |
|
Zhenyao Mo
2015/03/06 18:35:37
Add a comment GL_DRAW_FRAMEBUFFER == GL_FRAMEBUFFE
yunchao
2015/03/09 07:16:57
A little tricky here. GL_DRAW_FRAMEBUFFER is not e
yunchao
2015/03/09 10:00:34
GLenum GL_DRAW_FRAMEBUFFER(0x8CA9) is not equal to
|
| + synthesizeGLError(GL_INVALID_ENUM, functionName, "invalid target"); |
| + return false; |
| + } |
| + ASSERT(!m_framebufferBinding && !drawingBuffer()); |
|
Zhenyao Mo
2015/03/06 18:35:37
This ASSERTION is incorrect. It should be ||, not
yunchao
2015/03/09 07:16:57
If binding to default FB, m_framebufferBinding wil
|
| + if (!m_framebufferBinding) { |
|
Zhenyao Mo
2015/03/06 18:35:37
You also need to check || !m_framebufferBinding->
yunchao
2015/03/09 07:16:57
Personally, I think it is not necessary to check m
|
| + // for the default framebuffer |
| + switch (attachment) { |
| + case GL_BACK: |
| + case GL_DEPTH: |
| + case GL_STENCIL: |
| + break; |
| + default: |
| + synthesizeGLError(GL_INVALID_OPERATION, 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 (m_framebufferBinding->getAttachmentObject(GL_DEPTH_STENCIL_ATTACHMENT) || (m_framebufferBinding->getAttachmentObject(GL_DEPTH_ATTACHMENT) == m_framebufferBinding->getAttachmentObject(GL_STENCIL_ATTACHMENT))) |
| + break; |
| + default: |
| + if (attachment > GL_COLOR_ATTACHMENT0 |
| + && attachment < static_cast<GLenum>(GL_COLOR_ATTACHMENT0 + maxColorAttachments())) |
| + break; |
| + synthesizeGLError(GL_INVALID_OPERATION, functionName, "invalid attachment"); |
| + return false; |
| + } |
| + } |
| + return true; |
| +} |
| + |
| +ScriptValue WebGL2RenderingContextBase::getFramebufferAttachmentParameter(ScriptState* scriptState, GLenum target, GLenum attachment, GLenum pname) |
| +{ |
| + if (isContextLost() || !validateGetFramebufferAttachmentParameters("getFramebufferAttachmentParameter", target, attachment)) |
| + return ScriptValue::createNull(scriptState); |
| + |
| + if (m_framebufferBinding && !m_framebufferBinding->object()) { |
|
Zhenyao Mo
2015/03/06 18:35:37
This is incorrect, in ES3 we allow querying the ba
yunchao
2015/03/09 07:16:57
Agree, but this is different from the original cod
|
| + synthesizeGLError(GL_INVALID_OPERATION, "getFramebufferAttachmentParameter", "no framebuffer bound"); |
| + return ScriptValue::createNull(scriptState); |
| + } |
| + |
| + WebGLSharedObject* object = m_framebufferBinding ? m_framebufferBinding->getAttachmentObject(attachment) : 0; |
| + if (m_framebufferBinding && !object) { |
| + 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 (!object) |
| + return WebGLAny(scriptState, GL_FRAMEBUFFER_DEFAULT); |
| + if (object->isTexture()) |
| + return WebGLAny(scriptState, GL_TEXTURE); |
| + if (object->isRenderbuffer()) |
| + return WebGLAny(scriptState, GL_RENDERBUFFER); |
| + break; |
| + case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME: |
| + if (!object) |
| + break; |
| + return WebGLAny(scriptState, PassRefPtrWillBeRawPtr<WebGLObject>(object)); |
| + case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE: |
| + case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER: |
| + case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL: |
| + if (!object || !object->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) |
| { |
| WebGLRenderingContextBase::trace(visitor); |