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

Unified Diff: third_party/WebKit/Source/modules/webgl/WebGL2RenderingContextBase.cpp

Issue 1435183002: WebGL 2: fix the bug in invalidate-framebuffer.html (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: addressed Ken's feedback Created 5 years, 1 month 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
« no previous file with comments | « third_party/WebKit/Source/modules/webgl/WebGL2RenderingContextBase.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/modules/webgl/WebGL2RenderingContextBase.cpp
diff --git a/third_party/WebKit/Source/modules/webgl/WebGL2RenderingContextBase.cpp b/third_party/WebKit/Source/modules/webgl/WebGL2RenderingContextBase.cpp
index 3d04ecf6f55805db757caba6b23430516db667ad..1e3c61c612bce2f92e0665af52fe3b08166d6737 100644
--- a/third_party/WebKit/Source/modules/webgl/WebGL2RenderingContextBase.cpp
+++ b/third_party/WebKit/Source/modules/webgl/WebGL2RenderingContextBase.cpp
@@ -371,20 +371,93 @@ ScriptValue WebGL2RenderingContextBase::getInternalformatParameter(ScriptState*
}
}
-void WebGL2RenderingContextBase::invalidateFramebuffer(GLenum target, Vector<GLenum>& attachments)
+bool WebGL2RenderingContextBase::checkAndTranslateAttachments(const char* functionName, GLenum target, const Vector<GLenum>& attachments, Vector<GLenum>& translatedAttachments)
+{
+ GLsizei size = attachments.size();
+ translatedAttachments.resize(size);
+
+ WebGLFramebuffer* framebufferBinding = getFramebufferBinding(target);
+ ASSERT(framebufferBinding || drawingBuffer());
+ if (!framebufferBinding) {
+ // For the default framebuffer
+ // Translate GL_BACK/GL_DEPTH/GL_STENCIL, because the default framebuffer of WebGL is not fb 0, it is an internal fbo
Ken Russell (switch to Gerrit) 2015/11/19 02:24:05 GL_BACK -> GL_COLOR
+ for (GLsizei i = 0; i < size; ++i) {
+ switch (attachments[i]) {
+ case GL_COLOR:
+ translatedAttachments[i] = GL_COLOR_ATTACHMENT0;
+ break;
+ case GL_DEPTH:
+ translatedAttachments[i] = GL_DEPTH_ATTACHMENT;
+ break;
+ case GL_STENCIL:
+ translatedAttachments[i] = GL_STENCIL_ATTACHMENT;
+ break;
+ default:
+ synthesizeGLError(GL_INVALID_ENUM, functionName, "invalid attachment");
+ return false;
+ }
+ }
+ } else {
+ // For the FBO
+ for (GLsizei i = 0; i < size; ++i) {
+ switch (attachments[i]) {
+ case GL_COLOR_ATTACHMENT0:
+ case GL_DEPTH_ATTACHMENT:
+ case GL_STENCIL_ATTACHMENT:
+ case GL_DEPTH_STENCIL_ATTACHMENT:
+ translatedAttachments[i] = attachments[i];
+ break;
+ default:
+ if (attachments[i] > GL_COLOR_ATTACHMENT0
+ && attachments[i] < static_cast<GLenum>(GL_COLOR_ATTACHMENT0 + maxColorAttachments())) {
+ translatedAttachments[i] = attachments[i];
+ break;
+ }
+ synthesizeGLError(GL_INVALID_OPERATION, functionName, "invalid attachment");
+ return false;
+ }
+ }
+ }
+ return true;
+}
+
+void WebGL2RenderingContextBase::invalidateFramebuffer(GLenum target, const Vector<GLenum>& attachments)
{
if (isContextLost())
return;
- webContext()->invalidateFramebuffer(target, attachments.size(), attachments.data());
+ if (!validateFramebufferTarget(target)) {
+ synthesizeGLError(GL_INVALID_ENUM, "invalidateFramebuffer", "invalid target");
+ return;
+ }
+
+ Vector<GLenum> translatedAttachments;
+ if (!checkAndTranslateAttachments("invalidateFramebuffer", target, attachments, translatedAttachments))
+ return;
+
+ webContext()->invalidateFramebuffer(target, translatedAttachments.size(), translatedAttachments.data());
}
-void WebGL2RenderingContextBase::invalidateSubFramebuffer(GLenum target, Vector<GLenum>& attachments, GLint x, GLint y, GLsizei width, GLsizei height)
+void WebGL2RenderingContextBase::invalidateSubFramebuffer(GLenum target, const Vector<GLenum>& attachments, GLint x, GLint y, GLsizei width, GLsizei height)
{
if (isContextLost())
return;
- webContext()->invalidateSubFramebuffer(target, attachments.size(), attachments.data(), x, y, width, height);
+ if (!validateFramebufferTarget(target)) {
+ synthesizeGLError(GL_INVALID_ENUM, "invalidateFramebuffer", "invalid target");
+ return;
+ }
+
+ if (width < 0 || height < 0) {
+ synthesizeGLError(GL_INVALID_VALUE, "invalidateSubFramebuffer", "invalid width or height");
+ return;
+ }
+
+ Vector<GLenum> translatedAttachments;
+ if (!checkAndTranslateAttachments("invalidateSubFramebuffer", target, attachments, translatedAttachments))
+ return;
+
+ webContext()->invalidateSubFramebuffer(target, translatedAttachments.size(), translatedAttachments.data(), x, y, width, height);
}
void WebGL2RenderingContextBase::readBuffer(GLenum mode)
« no previous file with comments | « third_party/WebKit/Source/modules/webgl/WebGL2RenderingContextBase.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698