OLD | NEW |
---|---|
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 "modules/webgl/WebGL2RenderingContextBase.h" | 6 #include "modules/webgl/WebGL2RenderingContextBase.h" |
7 | 7 |
8 #include "bindings/modules/v8/WebGLAny.h" | 8 #include "bindings/modules/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 2279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2290 break; | 2290 break; |
2291 synthesizeGLError(GL_INVALID_ENUM, functionName, "invalid attachment "); | 2291 synthesizeGLError(GL_INVALID_ENUM, functionName, "invalid attachment "); |
2292 return false; | 2292 return false; |
2293 } | 2293 } |
2294 } | 2294 } |
2295 return true; | 2295 return true; |
2296 } | 2296 } |
2297 | 2297 |
2298 ScriptValue WebGL2RenderingContextBase::getFramebufferAttachmentParameter(Script State* scriptState, GLenum target, GLenum attachment, GLenum pname) | 2298 ScriptValue WebGL2RenderingContextBase::getFramebufferAttachmentParameter(Script State* scriptState, GLenum target, GLenum attachment, GLenum pname) |
2299 { | 2299 { |
2300 if (isContextLost() || !validateGetFramebufferAttachmentParameterFunc("getFr amebufferAttachmentParameter", target, attachment)) | 2300 const char kFunctionName[] = "getFramebufferAttachmentParameter"; |
2301 if (isContextLost() || !validateGetFramebufferAttachmentParameterFunc(kFunct ionName, target, attachment)) | |
2301 return ScriptValue::createNull(scriptState); | 2302 return ScriptValue::createNull(scriptState); |
2302 | 2303 |
2303 WebGLFramebuffer* framebufferBinding = getFramebufferBinding(target); | 2304 WebGLFramebuffer* framebufferBinding = getFramebufferBinding(target); |
2304 ASSERT(!framebufferBinding || framebufferBinding->object()); | 2305 ASSERT(!framebufferBinding || framebufferBinding->object()); |
2305 | 2306 |
2306 WebGLSharedObject* attachmentObject = framebufferBinding ? framebufferBindin g->getAttachmentObject(attachment) : 0; | 2307 // Default framebuffer (an internal fbo) |
2307 if (framebufferBinding && !attachmentObject) { | 2308 if (!framebufferBinding) { |
2308 if (pname == GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE) | 2309 // We can use m_requestedAttribs because in WebGL 2, they are required t o be honored. |
2309 return WebGLAny(scriptState, GL_NONE); | 2310 bool hasDepth = m_requestedAttributes.depth(); |
2310 if (pname == GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME) | 2311 bool hasStencil = m_requestedAttributes.stencil(); |
2312 bool hasAlpha = m_requestedAttributes.alpha(); | |
2313 bool missingImage = (attachment == GL_DEPTH && !hasDepth) | |
2314 || (attachment == GL_STENCIL && !hasStencil); | |
2315 if (missingImage) { | |
2316 switch (pname) { | |
2317 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE: | |
2318 return WebGLAny(scriptState, GL_FRAMEBUFFER_DEFAULT); | |
2319 default: | |
2320 synthesizeGLError(GL_INVALID_ENUM, kFunctionName, "invalid param eter name"); | |
2321 return ScriptValue::createNull(scriptState); | |
2322 } | |
2323 } | |
2324 switch (pname) { | |
2325 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE: | |
2326 return WebGLAny(scriptState, GL_FRAMEBUFFER_DEFAULT); | |
2327 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE: | |
2328 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE: | |
2329 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE: | |
2330 { | |
2331 GLint value = attachment == GL_BACK ? 8 : 0; | |
2332 return WebGLAny(scriptState, value); | |
2333 } | |
2334 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE: | |
2335 { | |
2336 GLint value = (attachment == GL_BACK && hasAlpha) ? 8 : 0; | |
2337 return WebGLAny(scriptState, value); | |
2338 } | |
2339 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE: | |
2340 { | |
2341 // For ES3 capable backend, DEPTH24_STENCIL8 has to be supported . | |
2342 GLint value = attachment == GL_DEPTH ? 24 : 0; | |
2343 return WebGLAny(scriptState, value); | |
2344 } | |
2345 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE: | |
2346 { | |
2347 GLint value = attachment == GL_STENCIL ? 8 : 0; | |
2348 return WebGLAny(scriptState, value); | |
2349 } | |
2350 case GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE: | |
2351 return WebGLAny(scriptState, GL_UNSIGNED_NORMALIZED); | |
2352 case GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING: | |
2353 return WebGLAny(scriptState, GL_LINEAR); | |
2354 default: | |
2355 synthesizeGLError(GL_INVALID_ENUM, kFunctionName, "invalid parameter name"); | |
Ken Russell (switch to Gerrit)
2015/09/04 00:51:18
Is it specified that querying GL_FRAMEBUFFER_ATTAC
Zhenyao Mo
2015/09/04 20:44:54
Yes, that's how I interpret the spec.
| |
2311 return ScriptValue::createNull(scriptState); | 2356 return ScriptValue::createNull(scriptState); |
2312 synthesizeGLError(GL_INVALID_OPERATION, "getFramebufferAttachmentParamet er", "invalid parameter name"); | |
2313 return ScriptValue::createNull(scriptState); | |
2314 } | |
2315 | |
2316 // translate attachment for default framebuffer (an internal fbo) | |
2317 if (!framebufferBinding) { | |
2318 switch (attachment) { | |
2319 case GL_BACK: | |
2320 attachment = GL_COLOR_ATTACHMENT0; | |
2321 break; | |
2322 case GL_DEPTH: | |
2323 attachment = GL_DEPTH_ATTACHMENT; | |
2324 break; | |
2325 case GL_STENCIL: | |
2326 attachment = GL_STENCIL_ATTACHMENT; | |
2327 break; | |
2328 default: | |
2329 ASSERT_NOT_REACHED(); | |
2330 break; | |
2331 } | 2357 } |
2332 } | 2358 } |
2333 | 2359 |
2360 WebGLSharedObject* attachmentObject = nullptr; | |
2361 if (attachment == GL_DEPTH_STENCIL_ATTACHMENT) { | |
2362 WebGLSharedObject* depthAttachment = framebufferBinding->getAttachmentOb ject(GL_DEPTH_ATTACHMENT); | |
2363 WebGLSharedObject* stencilAttachment = framebufferBinding->getAttachment Object(GL_STENCIL_ATTACHMENT); | |
2364 if (depthAttachment != stencilAttachment) { | |
2365 synthesizeGLError(GL_INVALID_OPERATION, kFunctionName, | |
2366 "different objects bound to DEPTH_ATTACHMENT and STENCIL_ATTACHM ENT"); | |
2367 return ScriptValue::createNull(scriptState); | |
2368 } | |
2369 attachmentObject = depthAttachment; | |
2370 } else { | |
2371 attachmentObject = framebufferBinding->getAttachmentObject(attachment); | |
2372 } | |
2373 | |
2374 if (!attachmentObject) { | |
2375 switch (pname) { | |
2376 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE: | |
2377 return WebGLAny(scriptState, GL_NONE); | |
2378 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME: | |
2379 return ScriptValue::createNull(scriptState); | |
2380 default: | |
2381 synthesizeGLError(GL_INVALID_OPERATION, kFunctionName, "invalid para meter name"); | |
2382 return ScriptValue::createNull(scriptState); | |
2383 } | |
2384 } | |
2385 ASSERT(attachmentObject->isTexture() || attachmentObject->isRenderbuffer()); | |
2386 | |
2334 switch (pname) { | 2387 switch (pname) { |
2335 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE: | 2388 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE: |
2336 if (!attachmentObject) { | |
2337 ASSERT(!framebufferBinding); | |
2338 return WebGLAny(scriptState, GL_FRAMEBUFFER_DEFAULT); | |
2339 } | |
2340 ASSERT(attachmentObject->isTexture() || attachmentObject->isRenderbuffer ()); | |
2341 if (attachmentObject->isTexture()) | 2389 if (attachmentObject->isTexture()) |
2342 return WebGLAny(scriptState, GL_TEXTURE); | 2390 return WebGLAny(scriptState, GL_TEXTURE); |
2343 if (attachmentObject->isRenderbuffer()) | 2391 return WebGLAny(scriptState, GL_RENDERBUFFER); |
2344 return WebGLAny(scriptState, GL_RENDERBUFFER); | |
2345 break; | |
2346 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME: | 2392 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME: |
2347 if (!attachmentObject) | |
2348 break; | |
2349 return WebGLAny(scriptState, attachmentObject); | 2393 return WebGLAny(scriptState, attachmentObject); |
2350 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE: | 2394 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE: |
2351 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER: | 2395 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER: |
2352 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL: | 2396 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL: |
2353 if (!attachmentObject || !attachmentObject->isTexture()) | 2397 if (!attachmentObject->isTexture()) |
2354 break; | 2398 break; |
2355 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE: | 2399 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE: |
2356 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE: | 2400 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE: |
2357 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE: | 2401 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE: |
2358 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE: | 2402 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE: |
2359 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE: | 2403 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE: |
2360 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE: | 2404 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE: |
2361 { | 2405 { |
2362 GLint value = 0; | 2406 GLint value = 0; |
2363 webContext()->getFramebufferAttachmentParameteriv(target, attachment , pname, &value); | 2407 webContext()->getFramebufferAttachmentParameteriv(target, attachment , pname, &value); |
2364 return WebGLAny(scriptState, value); | 2408 return WebGLAny(scriptState, value); |
2365 } | 2409 } |
2366 case GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE: | 2410 case GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE: |
2411 if (attachment == GL_DEPTH_STENCIL_ATTACHMENT) { | |
2412 synthesizeGLError(GL_INVALID_OPERATION, kFunctionName, | |
2413 "COMPONENT_TYPE can't be queried for DEPTH_STENCIL_ATTACHMENT"); | |
2414 return ScriptValue::createNull(scriptState); | |
2415 } | |
2367 case GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING: | 2416 case GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING: |
2368 { | 2417 { |
2369 GLint value = 0; | 2418 GLint value = 0; |
2370 webContext()->getFramebufferAttachmentParameteriv(target, attachment , pname, &value); | 2419 webContext()->getFramebufferAttachmentParameteriv(target, attachment , pname, &value); |
2371 return WebGLAny(scriptState, static_cast<unsigned>(value)); | 2420 return WebGLAny(scriptState, static_cast<unsigned>(value)); |
2372 } | 2421 } |
2373 default: | 2422 default: |
2374 break; | 2423 break; |
2375 } | 2424 } |
2376 synthesizeGLError(GL_INVALID_ENUM, "getFramebufferAttachmentParameter", "inv alid parameter name"); | 2425 synthesizeGLError(GL_INVALID_ENUM, kFunctionName, "invalid parameter name"); |
2377 return ScriptValue::createNull(scriptState); | 2426 return ScriptValue::createNull(scriptState); |
2378 } | 2427 } |
2379 | 2428 |
2380 DEFINE_TRACE(WebGL2RenderingContextBase) | 2429 DEFINE_TRACE(WebGL2RenderingContextBase) |
2381 { | 2430 { |
2382 visitor->trace(m_readFramebufferBinding); | 2431 visitor->trace(m_readFramebufferBinding); |
2383 visitor->trace(m_transformFeedbackBinding); | 2432 visitor->trace(m_transformFeedbackBinding); |
2384 visitor->trace(m_boundCopyReadBuffer); | 2433 visitor->trace(m_boundCopyReadBuffer); |
2385 visitor->trace(m_boundCopyWriteBuffer); | 2434 visitor->trace(m_boundCopyWriteBuffer); |
2386 visitor->trace(m_boundPixelPackBuffer); | 2435 visitor->trace(m_boundPixelPackBuffer); |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2545 GLenum WebGL2RenderingContextBase::boundFramebufferColorFormat() | 2594 GLenum WebGL2RenderingContextBase::boundFramebufferColorFormat() |
2546 { | 2595 { |
2547 if (m_readFramebufferBinding && m_readFramebufferBinding->object()) | 2596 if (m_readFramebufferBinding && m_readFramebufferBinding->object()) |
2548 return m_readFramebufferBinding->colorBufferFormat(); | 2597 return m_readFramebufferBinding->colorBufferFormat(); |
2549 if (m_requestedAttributes.alpha()) | 2598 if (m_requestedAttributes.alpha()) |
2550 return GL_RGBA; | 2599 return GL_RGBA; |
2551 return GL_RGB; | 2600 return GL_RGB; |
2552 } | 2601 } |
2553 | 2602 |
2554 } // namespace blink | 2603 } // namespace blink |
OLD | NEW |