Chromium Code Reviews| Index: Source/core/html/canvas/WebGLRenderingContextBase.cpp |
| diff --git a/Source/core/html/canvas/WebGLRenderingContextBase.cpp b/Source/core/html/canvas/WebGLRenderingContextBase.cpp |
| index 1f1288f7f0fcd95bffbb33106e102646e8991c1f..45f3cef0d9ceead3578ec91c3814a2583e1d1b0e 100644 |
| --- a/Source/core/html/canvas/WebGLRenderingContextBase.cpp |
| +++ b/Source/core/html/canvas/WebGLRenderingContextBase.cpp |
| @@ -724,6 +724,9 @@ void WebGLRenderingContextBase::initializeNewContext() |
| m_backDrawBuffer = GL_BACK; |
| + // set the default read color buffer for FBO |
| + m_readbufferOfFBO = GL_COLOR_ATTACHMENT0; |
| + |
| if (isWebGL2OrHigher()) { |
| m_defaultVertexArrayObject = WebGLVertexArrayObject::create(this, WebGLVertexArrayObjectBase::VaoTypeDefault); |
| } else { |
| @@ -1539,6 +1542,18 @@ bool WebGLRenderingContextBase::validateSettableTexFormat(const char* functionNa |
| return true; |
| } |
| +bool WebGLRenderingContextBase::validateReadBufferAttachment(WebGLFramebuffer* readFramebufferBinding) |
| +{ |
| + if (readFramebufferBinding) { |
| + WebGLSharedObject* attachmentObject = readFramebufferBinding->getAttachmentObject(m_readbufferOfFBO); |
| + if (!attachmentObject) { |
| + synthesizeGLError(GL_INVALID_OPERATION, "copyTexImage2D", "no image attached to read buffer"); |
| + return false; |
| + } |
| + } |
| + return true; |
| +} |
| + |
| void WebGLRenderingContextBase::copyTexImage2D(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border) |
| { |
| if (isContextLost()) |
| @@ -1567,6 +1582,8 @@ void WebGLRenderingContextBase::copyTexImage2D(GLenum target, GLint level, GLenu |
| synthesizeGLError(GL_INVALID_FRAMEBUFFER_OPERATION, "copyTexImage2D", reason); |
| return; |
| } |
| + if (!validateReadBufferAttachment("copyTexImage2D", readFramebufferBinding)) |
|
Ken Russell (switch to Gerrit)
2015/06/24 00:24:38
Has this code path been tested? It looks to me lik
yunchao
2015/06/24 08:50:51
Good catch. I have updated the patch to translate
|
| + return; |
| clearIfComposited(); |
| ScopedDrawingBufferBinder binder(drawingBuffer(), m_framebufferBinding.get()); |
| webContext()->copyTexImage2D(target, level, internalformat, x, y, width, height, border); |
| @@ -1610,6 +1627,8 @@ void WebGLRenderingContextBase::copyTexSubImage2D(GLenum target, GLint level, GL |
| synthesizeGLError(GL_INVALID_FRAMEBUFFER_OPERATION, "copyTexSubImage2D", reason); |
| return; |
| } |
| + if (!validateReadBufferAttachment("copyTexSubImage2D", readFramebufferBinding)) |
| + return; |
| clearIfComposited(); |
| ScopedDrawingBufferBinder binder(drawingBuffer(), m_framebufferBinding.get()); |
| webContext()->copyTexSubImage2D(target, level, xoffset, yoffset, x, y, width, height); |
| @@ -3343,6 +3362,9 @@ void WebGLRenderingContextBase::readPixels(GLint x, GLint y, GLsizei width, GLsi |
| return; |
| } |
| + if (!validateReadBufferAttachment("readPixels", readFramebufferBinding)) |
| + return; |
| + |
| clearIfComposited(); |
| void* data = pixels->baseAddress(); |