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 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
368 values[ii] = 0; | 368 values[ii] = 0; |
369 webContext()->getInternalformativ(target, internalformat, GL_SAMPLES , length, values.get()); | 369 webContext()->getInternalformativ(target, internalformat, GL_SAMPLES , length, values.get()); |
370 return WebGLAny(scriptState, DOMInt32Array::create(values.get(), len gth)); | 370 return WebGLAny(scriptState, DOMInt32Array::create(values.get(), len gth)); |
371 } | 371 } |
372 default: | 372 default: |
373 synthesizeGLError(GL_INVALID_ENUM, "getInternalformatParameter", "invali d parameter name"); | 373 synthesizeGLError(GL_INVALID_ENUM, "getInternalformatParameter", "invali d parameter name"); |
374 return ScriptValue::createNull(scriptState); | 374 return ScriptValue::createNull(scriptState); |
375 } | 375 } |
376 } | 376 } |
377 | 377 |
378 bool WebGL2RenderingContextBase::checkAndTranslateAttachments(const char* functi onName, GLenum target, Vector<GLenum>& attachments) | |
Ken Russell (switch to Gerrit)
2015/11/17 23:06:37
It's a little nasty to modify the Vector which com
yunchao
2015/11/19 01:43:00
Done.
| |
379 { | |
380 GLsizei size = attachments.size(); | |
381 GLenum* buffer = attachments.data(); | |
Ken Russell (switch to Gerrit)
2015/11/17 23:06:37
It's not necessary to fetch the data pointer out o
yunchao
2015/11/19 01:42:59
Done.
yunchao
2015/11/19 01:42:59
Done.
| |
382 | |
383 WebGLFramebuffer* framebufferBinding = getFramebufferBinding(target); | |
384 ASSERT(framebufferBinding || drawingBuffer()); | |
385 if (!framebufferBinding) { | |
386 // For the default framebuffer | |
387 // Translate GL_BACK/GL_DEPTH/GL_STENCIL, because the default framebuffe r of WebGL is not fb 0, it is an internal fbo | |
388 for (GLsizei i = 0; i < size; ++i) { | |
389 switch (buffer[i]) { | |
390 case GL_BACK: | |
yunchao
2015/11/12 12:14:50
In GLES spec, it is GL_COLOR, but in WebGL spec, i
Ken Russell (switch to Gerrit)
2015/11/17 23:06:37
Sorry, but no, this should follow the OpenGL ES sp
yunchao
2015/11/19 01:42:59
Done.
| |
391 buffer[i] = GL_COLOR_ATTACHMENT0; | |
392 break; | |
393 case GL_DEPTH: | |
394 buffer[i] = GL_DEPTH_ATTACHMENT; | |
395 break; | |
396 case GL_STENCIL: | |
397 buffer[i] = GL_STENCIL_ATTACHMENT; | |
398 break; | |
399 default: | |
400 synthesizeGLError(GL_INVALID_ENUM, functionName, "invalid attach ment"); | |
401 return false; | |
402 } | |
403 } | |
404 } else { | |
405 // For the FBO | |
406 for (GLsizei i = 0; i < size; ++i) { | |
407 switch (buffer[i]) { | |
408 case GL_COLOR_ATTACHMENT0: | |
409 case GL_DEPTH_ATTACHMENT: | |
410 case GL_STENCIL_ATTACHMENT: | |
411 case GL_DEPTH_STENCIL_ATTACHMENT: | |
412 break; | |
413 default: | |
414 if (buffer[i] > GL_COLOR_ATTACHMENT0 | |
415 && buffer[i] < static_cast<GLenum>(GL_COLOR_ATTACHMENT0 + ma xColorAttachments())) | |
416 break; | |
417 synthesizeGLError(GL_INVALID_OPERATION, functionName, "invalid a ttachment"); | |
418 return false; | |
419 } | |
420 } | |
421 } | |
422 return true; | |
423 } | |
424 | |
378 void WebGL2RenderingContextBase::invalidateFramebuffer(GLenum target, Vector<GLe num>& attachments) | 425 void WebGL2RenderingContextBase::invalidateFramebuffer(GLenum target, Vector<GLe num>& attachments) |
379 { | 426 { |
380 if (isContextLost()) | 427 if (isContextLost()) |
381 return; | 428 return; |
382 | 429 |
430 if (!validateFramebufferTarget(target)) { | |
431 synthesizeGLError(GL_INVALID_ENUM, "invalidateFramebuffer", "invalid tar get"); | |
432 return; | |
433 } | |
434 | |
435 if (!checkAndTranslateAttachments("invalidateFramebuffe", target, attachment s)) | |
Ken Russell (switch to Gerrit)
2015/11/17 23:06:37
invalidateFramebuffe -> invalidateFramebuffer
yunchao
2015/11/19 01:42:59
Done.
| |
436 return; | |
437 | |
383 webContext()->invalidateFramebuffer(target, attachments.size(), attachments. data()); | 438 webContext()->invalidateFramebuffer(target, attachments.size(), attachments. data()); |
384 } | 439 } |
385 | 440 |
386 void WebGL2RenderingContextBase::invalidateSubFramebuffer(GLenum target, Vector< GLenum>& attachments, GLint x, GLint y, GLsizei width, GLsizei height) | 441 void WebGL2RenderingContextBase::invalidateSubFramebuffer(GLenum target, Vector< GLenum>& attachments, GLint x, GLint y, GLsizei width, GLsizei height) |
387 { | 442 { |
388 if (isContextLost()) | 443 if (isContextLost()) |
389 return; | 444 return; |
390 | 445 |
446 if (!validateFramebufferTarget(target)) { | |
447 synthesizeGLError(GL_INVALID_ENUM, "invalidateFramebuffer", "invalid tar get"); | |
448 return; | |
449 } | |
450 | |
451 if (width < 0 || height < 0) { | |
yunchao
2015/11/12 12:14:51
Not sure about this code snippet, In OGL spec, it
Ken Russell (switch to Gerrit)
2015/11/17 23:06:37
In this case it seems better to be safer by genera
yunchao
2015/11/19 01:43:00
OK, let's generate GL_INVALID_ENUM for this case.
| |
452 synthesizeGLError(GL_INVALID_VALUE, "invalidateSubFramebuffer", "invalid width or height"); | |
453 return; | |
454 } | |
455 | |
456 if (!checkAndTranslateAttachments("invalidateSubFramebuffe", target, attachm ents)) | |
Ken Russell (switch to Gerrit)
2015/11/17 23:06:37
invalidateSubFramebuffe -> invalidateSubFramebuffe
yunchao
2015/11/19 01:43:00
Done.
| |
457 return; | |
458 | |
391 webContext()->invalidateSubFramebuffer(target, attachments.size(), attachmen ts.data(), x, y, width, height); | 459 webContext()->invalidateSubFramebuffer(target, attachments.size(), attachmen ts.data(), x, y, width, height); |
392 } | 460 } |
393 | 461 |
394 void WebGL2RenderingContextBase::readBuffer(GLenum mode) | 462 void WebGL2RenderingContextBase::readBuffer(GLenum mode) |
395 { | 463 { |
396 if (isContextLost()) | 464 if (isContextLost()) |
397 return; | 465 return; |
398 | 466 |
399 switch (mode) { | 467 switch (mode) { |
400 case GL_BACK: | 468 case GL_BACK: |
(...skipping 2681 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3082 GLenum WebGL2RenderingContextBase::boundFramebufferColorFormat() | 3150 GLenum WebGL2RenderingContextBase::boundFramebufferColorFormat() |
3083 { | 3151 { |
3084 if (m_readFramebufferBinding && m_readFramebufferBinding->object()) | 3152 if (m_readFramebufferBinding && m_readFramebufferBinding->object()) |
3085 return m_readFramebufferBinding->colorBufferFormat(); | 3153 return m_readFramebufferBinding->colorBufferFormat(); |
3086 if (m_requestedAttributes.alpha()) | 3154 if (m_requestedAttributes.alpha()) |
3087 return GL_RGBA; | 3155 return GL_RGBA; |
3088 return GL_RGB; | 3156 return GL_RGB; |
3089 } | 3157 } |
3090 | 3158 |
3091 } // namespace blink | 3159 } // namespace blink |
OLD | NEW |