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

Side by Side Diff: Source/core/html/canvas/WebGL2RenderingContextBase.cpp

Issue 981913002: update getFramebufferAttachmentParameter for WebGL 2 (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: addressed zmo@'s feedback Created 5 years, 9 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "config.h" 5 #include "config.h"
6 #include "core/html/canvas/WebGL2RenderingContextBase.h" 6 #include "core/html/canvas/WebGL2RenderingContextBase.h"
7 7
8 #include "bindings/core/v8/WebGLAny.h" 8 #include "bindings/core/v8/WebGLAny.h"
9 #include "core/html/HTMLCanvasElement.h" 9 #include "core/html/HTMLCanvasElement.h"
10 #include "core/html/HTMLImageElement.h" 10 #include "core/html/HTMLImageElement.h"
(...skipping 1178 matching lines...) Expand 10 before | Expand all | Expand 10 after
1189 // FIXME: Some of these ES3 buffer targets may require additional state tracking. 1189 // FIXME: Some of these ES3 buffer targets may require additional state tracking.
1190 break; 1190 break;
1191 default: 1191 default:
1192 synthesizeGLError(GL_INVALID_ENUM, functionName, "invalid target"); 1192 synthesizeGLError(GL_INVALID_ENUM, functionName, "invalid target");
1193 return false; 1193 return false;
1194 } 1194 }
1195 1195
1196 return true; 1196 return true;
1197 } 1197 }
1198 1198
1199 bool WebGL2RenderingContextBase::validateGetFramebufferAttachmentParameterFunc(c onst char* functionName, GLenum target, GLenum attachment)
1200 {
1201 if (target != GL_FRAMEBUFFER && target != GL_READ_FRAMEBUFFER && target != G L_DRAW_FRAMEBUFFER) {
1202 synthesizeGLError(GL_INVALID_ENUM, functionName, "invalid target");
1203 return false;
1204 }
1205 ASSERT(!m_framebufferBinding && !drawingBuffer());
Zhenyao Mo 2015/03/09 18:39:19 OK, let me explain again. I understand your inten
yunchao 2015/03/10 15:34:54 Yeah. I got it. Thank you, @zmo.
1206 if (!m_framebufferBinding) {
1207 // for the default framebuffer
1208 switch (attachment) {
1209 case GL_BACK:
1210 case GL_DEPTH:
1211 case GL_STENCIL:
1212 break;
1213 default:
1214 synthesizeGLError(GL_INVALID_OPERATION, functionName, "invalid attac hment");
Zhenyao Mo 2015/03/09 18:39:19 Although the man page of this function says INVALI
yunchao 2015/03/10 15:34:53 Done.
1215 return false;
1216 }
1217 } else {
1218 // for the FBO
1219 switch (attachment) {
1220 case GL_COLOR_ATTACHMENT0:
1221 case GL_DEPTH_ATTACHMENT:
1222 case GL_STENCIL_ATTACHMENT:
1223 break;
1224 case GL_DEPTH_STENCIL_ATTACHMENT:
1225 if (m_framebufferBinding->getAttachmentObject(GL_DEPTH_STENCIL_ATTAC HMENT) || (m_framebufferBinding->getAttachmentObject(GL_DEPTH_ATTACHMENT) == m_f ramebufferBinding->getAttachmentObject(GL_STENCIL_ATTACHMENT)))
1226 break;
1227 default:
1228 if (attachment > GL_COLOR_ATTACHMENT0
1229 && attachment < static_cast<GLenum>(GL_COLOR_ATTACHMENT0 + maxCo lorAttachments()))
1230 break;
1231 synthesizeGLError(GL_INVALID_OPERATION, functionName, "invalid attac hment");
Zhenyao Mo 2015/03/09 18:39:19 Same here, maybe INVALID_ENUM.
yunchao 2015/03/10 15:34:53 Done.
1232 return false;
1233 }
1234 }
1235 return true;
1236 }
1237
1238 ScriptValue WebGL2RenderingContextBase::getFramebufferAttachmentParameter(Script State* scriptState, GLenum target, GLenum attachment, GLenum pname)
1239 {
1240 if (isContextLost() || !validateGetFramebufferAttachmentParameterFunc("getFr amebufferAttachmentParameter", target, attachment))
1241 return ScriptValue::createNull(scriptState);
1242
1243 ASSERT(m_framebufferBinding && !m_framebufferBinding->object());
1244
1245 WebGLSharedObject* attachmentObject = m_framebufferBinding ? m_framebufferBi nding->getAttachmentObject(attachment) : 0;
1246 if (m_framebufferBinding && !attachmentObject) {
1247 if (pname == GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE)
1248 return WebGLAny(scriptState, GL_NONE);
1249 if (pname == GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME)
1250 return WebGLAny(scriptState, 0);
1251 synthesizeGLError(GL_INVALID_OPERATION, "getFramebufferAttachmentParamet er", "invalid parameter name");
1252 return ScriptValue::createNull(scriptState);
1253 }
1254
1255 switch (pname) {
1256 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE:
1257 if (!attachmentObject)
Zhenyao Mo 2015/03/09 18:39:19 nit: add ASSERT(!m_framebufferBinding) here to mak
yunchao 2015/03/10 15:34:54 Done.
1258 return WebGLAny(scriptState, GL_FRAMEBUFFER_DEFAULT);
1259 if (attachmentObject->isTexture())
1260 return WebGLAny(scriptState, GL_TEXTURE);
1261 if (attachmentObject->isRenderbuffer())
1262 return WebGLAny(scriptState, GL_RENDERBUFFER);
Zhenyao Mo 2015/03/09 18:39:19 nit: ASSERT(attachmentObject->isTexture() || attac
yunchao 2015/03/10 15:34:54 Done.
1263 break;
1264 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:
1265 if (!attachmentObject)
1266 break;
1267 return WebGLAny(scriptState, PassRefPtrWillBeRawPtr<WebGLObject>(attachm entObject));
1268 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE:
1269 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER:
1270 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL:
1271 if (!attachmentObject || !attachmentObject->isTexture())
1272 break;
1273 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE:
1274 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE:
1275 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE:
1276 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE:
1277 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE:
1278 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE:
1279 {
1280 GLint value = 0;
1281 webContext()->getFramebufferAttachmentParameteriv(target, attachment , pname, &value);
1282 return WebGLAny(scriptState, value);
1283 }
1284 case GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE:
1285 case GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING:
1286 {
1287 GLint value = 0;
1288 webContext()->getFramebufferAttachmentParameteriv(target, attachment , pname, &value);
1289 return WebGLAny(scriptState, static_cast<unsigned>(value));
1290 }
1291 default:
1292 break;
1293 }
1294 synthesizeGLError(GL_INVALID_ENUM, "getFramebufferAttachmentParameter", "inv alid parameter name");
1295 return ScriptValue::createNull(scriptState);
1296 }
1297
1199 DEFINE_TRACE(WebGL2RenderingContextBase) 1298 DEFINE_TRACE(WebGL2RenderingContextBase)
1200 { 1299 {
1201 WebGLRenderingContextBase::trace(visitor); 1300 WebGLRenderingContextBase::trace(visitor);
1202 } 1301 }
1203 1302
1204 } // namespace blink 1303 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698