Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(622)

Unified Diff: Source/core/html/canvas/WebGLRenderingContextBase.cpp

Issue 1205573003: WebGL 2: validate read buffer attachment when reading from FBO (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: addressed kbr@'s feedback: translate GL_BACK to GL_COLOR_ATTACHMENT0 on default fb of WebGL Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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)
Zhenyao Mo 2015/06/25 22:42:22 This should not even compile. You missed the func
yunchao 2015/06/30 05:44:56 Sorry. My local Chromium src code has some issues
+{
+ if (readFramebufferBinding) {
+ WebGLSharedObject* attachmentObject = readFramebufferBinding->getAttachmentObject(m_readbufferOfFBO);
+ if (!attachmentObject) {
+ synthesizeGLError(GL_INVALID_OPERATION, "copyTexImage2D", "no image attached to read buffer");
Zhenyao Mo 2015/06/25 22:42:22 Should be functionName instead of "copyTexImage2D"
yunchao 2015/06/30 05:44:56 Done.
+ 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))
+ 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();

Powered by Google App Engine
This is Rietveld 408576698