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

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 zmo@'s feedback: translate GL_COLOR_ATTACHMENT0 to GL_BACK in getter for default fb 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 66aca1a524d6d8ab7eacc656b8705ac81aeffb47..b396f26d32fd0f7bcab2bf761a0c084f63607b6c 100644
--- a/Source/core/html/canvas/WebGLRenderingContextBase.cpp
+++ b/Source/core/html/canvas/WebGLRenderingContextBase.cpp
@@ -727,6 +727,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 {
@@ -1543,6 +1546,18 @@ bool WebGLRenderingContextBase::validateSettableTexFormat(const char* functionNa
return true;
}
+bool WebGLRenderingContextBase::validateReadBufferAttachment(const char* functionName, const WebGLFramebuffer* readFramebufferBinding)
+{
+ if (readFramebufferBinding) {
+ WebGLSharedObject* attachmentObject = readFramebufferBinding->getAttachmentObject(m_readbufferOfFBO);
+ if (!attachmentObject) {
+ synthesizeGLError(GL_INVALID_OPERATION, functionName, "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())
@@ -1573,6 +1588,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(), readFramebufferBinding);
webContext()->copyTexImage2D(target, level, internalformat, x, y, width, height, border);
@@ -1618,6 +1635,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(), readFramebufferBinding);
webContext()->copyTexSubImage2D(target, level, xoffset, yoffset, x, y, width, height);
@@ -3359,6 +3378,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