| 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 "modules/webgl/WebGL2RenderingContextBase.h" | 5 #include "modules/webgl/WebGL2RenderingContextBase.h" |
| 6 | 6 |
| 7 #include "bindings/modules/v8/WebGLAny.h" | 7 #include "bindings/modules/v8/WebGLAny.h" |
| 8 #include "core/frame/ImageBitmap.h" | 8 #include "core/frame/ImageBitmap.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 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 333 ScriptValue WebGL2RenderingContextBase::getInternalformatParameter(ScriptState*
scriptState, GLenum target, GLenum internalformat, GLenum pname) | 333 ScriptValue WebGL2RenderingContextBase::getInternalformatParameter(ScriptState*
scriptState, GLenum target, GLenum internalformat, GLenum pname) |
| 334 { | 334 { |
| 335 if (isContextLost()) | 335 if (isContextLost()) |
| 336 return ScriptValue::createNull(scriptState); | 336 return ScriptValue::createNull(scriptState); |
| 337 | 337 |
| 338 if (target != GL_RENDERBUFFER) { | 338 if (target != GL_RENDERBUFFER) { |
| 339 synthesizeGLError(GL_INVALID_ENUM, "getInternalformatParameter", "invali
d target"); | 339 synthesizeGLError(GL_INVALID_ENUM, "getInternalformatParameter", "invali
d target"); |
| 340 return ScriptValue::createNull(scriptState); | 340 return ScriptValue::createNull(scriptState); |
| 341 } | 341 } |
| 342 | 342 |
| 343 bool floatType = false; | |
| 344 | 343 |
| 345 switch (internalformat) { | 344 switch (internalformat) { |
| 346 // Renderbuffer doesn't support unsized internal formats, | 345 // Renderbuffer doesn't support unsized internal formats, |
| 347 // though GL_RGB and GL_RGBA are color-renderable. | 346 // though GL_RGB and GL_RGBA are color-renderable. |
| 348 case GL_RGB: | 347 case GL_RGB: |
| 349 case GL_RGBA: | 348 case GL_RGBA: |
| 350 // Multisampling is not supported for signed and unsigned integer internal f
ormats. | 349 // Multisampling is not supported for signed and unsigned integer internal f
ormats. |
| 351 case GL_R8UI: | 350 case GL_R8UI: |
| 352 case GL_R8I: | 351 case GL_R8I: |
| 353 case GL_R16UI: | 352 case GL_R16UI: |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 388 case GL_RG16F: | 387 case GL_RG16F: |
| 389 case GL_RGBA16F: | 388 case GL_RGBA16F: |
| 390 case GL_R32F: | 389 case GL_R32F: |
| 391 case GL_RG32F: | 390 case GL_RG32F: |
| 392 case GL_RGBA32F: | 391 case GL_RGBA32F: |
| 393 case GL_R11F_G11F_B10F: | 392 case GL_R11F_G11F_B10F: |
| 394 if (!extensionEnabled(EXTColorBufferFloatName)) { | 393 if (!extensionEnabled(EXTColorBufferFloatName)) { |
| 395 synthesizeGLError(GL_INVALID_ENUM, "getInternalformatParameter", "in
valid internalformat when EXT_color_buffer_float is not enabled"); | 394 synthesizeGLError(GL_INVALID_ENUM, "getInternalformatParameter", "in
valid internalformat when EXT_color_buffer_float is not enabled"); |
| 396 return ScriptValue::createNull(scriptState); | 395 return ScriptValue::createNull(scriptState); |
| 397 } | 396 } |
| 398 floatType = true; | |
| 399 break; | 397 break; |
| 400 default: | 398 default: |
| 401 synthesizeGLError(GL_INVALID_ENUM, "getInternalformatParameter", "invali
d internalformat"); | 399 synthesizeGLError(GL_INVALID_ENUM, "getInternalformatParameter", "invali
d internalformat"); |
| 402 return ScriptValue::createNull(scriptState); | 400 return ScriptValue::createNull(scriptState); |
| 403 } | 401 } |
| 404 | 402 |
| 405 switch (pname) { | 403 switch (pname) { |
| 406 case GL_SAMPLES: | 404 case GL_SAMPLES: |
| 407 { | 405 { |
| 408 std::unique_ptr<GLint[]> values; | 406 std::unique_ptr<GLint[]> values; |
| 409 GLint length = -1; | 407 GLint length = -1; |
| 410 if (!floatType) { | 408 contextGL()->GetInternalformativ(target, internalformat, GL_NUM_SAMP
LE_COUNTS, 1, &length); |
| 411 contextGL()->GetInternalformativ(target, internalformat, GL_NUM_
SAMPLE_COUNTS, 1, &length); | 409 if (length <= 0) |
| 412 if (length <= 0) | 410 return WebGLAny(scriptState, DOMInt32Array::create(0)); |
| 413 return WebGLAny(scriptState, DOMInt32Array::create(0)); | |
| 414 | 411 |
| 415 values = wrapArrayUnique(new GLint[length]); | 412 values = wrapArrayUnique(new GLint[length]); |
| 416 for (GLint ii = 0; ii < length; ++ii) | 413 for (GLint ii = 0; ii < length; ++ii) |
| 417 values[ii] = 0; | 414 values[ii] = 0; |
| 418 contextGL()->GetInternalformativ(target, internalformat, GL_SAMP
LES, length, values.get()); | 415 contextGL()->GetInternalformativ(target, internalformat, GL_SAMPLES,
length, values.get()); |
| 419 } else { | |
| 420 length = 1; | |
| 421 values = wrapArrayUnique(new GLint[1]); | |
| 422 values[0] = 1; | |
| 423 } | |
| 424 return WebGLAny(scriptState, DOMInt32Array::create(values.get(), len
gth)); | 416 return WebGLAny(scriptState, DOMInt32Array::create(values.get(), len
gth)); |
| 425 } | 417 } |
| 426 default: | 418 default: |
| 427 synthesizeGLError(GL_INVALID_ENUM, "getInternalformatParameter", "invali
d parameter name"); | 419 synthesizeGLError(GL_INVALID_ENUM, "getInternalformatParameter", "invali
d parameter name"); |
| 428 return ScriptValue::createNull(scriptState); | 420 return ScriptValue::createNull(scriptState); |
| 429 } | 421 } |
| 430 } | 422 } |
| 431 | 423 |
| 432 bool WebGL2RenderingContextBase::checkAndTranslateAttachments(const char* functi
onName, GLenum target, Vector<GLenum>& attachments) | 424 bool WebGL2RenderingContextBase::checkAndTranslateAttachments(const char* functi
onName, GLenum target, Vector<GLenum>& attachments) |
| 433 { | 425 { |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 622 return; | 614 return; |
| 623 | 615 |
| 624 clearIfComposited(); | 616 clearIfComposited(); |
| 625 | 617 |
| 626 { | 618 { |
| 627 ScopedDrawingBufferBinder binder(drawingBuffer(), framebuffer); | 619 ScopedDrawingBufferBinder binder(drawingBuffer(), framebuffer); |
| 628 contextGL()->ReadPixels(x, y, width, height, format, type, reinterpret_c
ast<void*>(offset)); | 620 contextGL()->ReadPixels(x, y, width, height, format, type, reinterpret_c
ast<void*>(offset)); |
| 629 } | 621 } |
| 630 } | 622 } |
| 631 | 623 |
| 624 void WebGL2RenderingContextBase::renderbufferStorageHelper(GLenum target, GLsize
i samples, GLenum internalformat, GLsizei width, GLsizei height, const char* fun
ctionName) |
| 625 { |
| 626 if (!samples) { |
| 627 contextGL()->RenderbufferStorage(target, internalformat, width, height); |
| 628 } else { |
| 629 GLint maxNumberOfSamples = 0; |
| 630 contextGL()->GetInternalformativ(target, internalformat, GL_SAMPLES, 1,
&maxNumberOfSamples); |
| 631 if (samples > maxNumberOfSamples) { |
| 632 synthesizeGLError(GL_INVALID_OPERATION, functionName, "samples out o
f range"); |
| 633 return; |
| 634 } |
| 635 contextGL()->RenderbufferStorageMultisampleCHROMIUM(target, samples, int
ernalformat, width, height); |
| 636 } |
| 637 } |
| 638 |
| 632 void WebGL2RenderingContextBase::renderbufferStorageImpl( | 639 void WebGL2RenderingContextBase::renderbufferStorageImpl( |
| 633 GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsize
i height, | 640 GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsize
i height, |
| 634 const char* functionName) | 641 const char* functionName) |
| 635 { | 642 { |
| 636 switch (internalformat) { | 643 switch (internalformat) { |
| 637 case GL_R8UI: | 644 case GL_R8UI: |
| 638 case GL_R8I: | 645 case GL_R8I: |
| 639 case GL_R16UI: | 646 case GL_R16UI: |
| 640 case GL_R16I: | 647 case GL_R16I: |
| 641 case GL_R32UI: | 648 case GL_R32UI: |
| (...skipping 24 matching lines...) Expand all Loading... |
| 666 case GL_SRGB8_ALPHA8: | 673 case GL_SRGB8_ALPHA8: |
| 667 case GL_RGB5_A1: | 674 case GL_RGB5_A1: |
| 668 case GL_RGBA4: | 675 case GL_RGBA4: |
| 669 case GL_RGB10_A2: | 676 case GL_RGB10_A2: |
| 670 case GL_DEPTH_COMPONENT16: | 677 case GL_DEPTH_COMPONENT16: |
| 671 case GL_DEPTH_COMPONENT24: | 678 case GL_DEPTH_COMPONENT24: |
| 672 case GL_DEPTH_COMPONENT32F: | 679 case GL_DEPTH_COMPONENT32F: |
| 673 case GL_DEPTH24_STENCIL8: | 680 case GL_DEPTH24_STENCIL8: |
| 674 case GL_DEPTH32F_STENCIL8: | 681 case GL_DEPTH32F_STENCIL8: |
| 675 case GL_STENCIL_INDEX8: | 682 case GL_STENCIL_INDEX8: |
| 676 if (!samples) { | 683 renderbufferStorageHelper(target, samples, internalformat, width, height
, functionName); |
| 677 contextGL()->RenderbufferStorage(target, internalformat, width, heig
ht); | |
| 678 } else { | |
| 679 GLint maxNumberOfSamples = 0; | |
| 680 contextGL()->GetInternalformativ(target, internalformat, GL_SAMPLES,
1, &maxNumberOfSamples); | |
| 681 if (samples > maxNumberOfSamples) { | |
| 682 synthesizeGLError(GL_INVALID_OPERATION, functionName, "samples o
ut of range"); | |
| 683 return; | |
| 684 } | |
| 685 contextGL()->RenderbufferStorageMultisampleCHROMIUM( | |
| 686 target, samples, internalformat, width, height); | |
| 687 } | |
| 688 break; | 684 break; |
| 689 case GL_DEPTH_STENCIL: | 685 case GL_DEPTH_STENCIL: |
| 690 // To be WebGL 1 backward compatible. | 686 // To be WebGL 1 backward compatible. |
| 691 if (samples > 0) { | 687 if (samples > 0) { |
| 692 synthesizeGLError(GL_INVALID_ENUM, functionName, "invalid internalfo
rmat"); | 688 synthesizeGLError(GL_INVALID_ENUM, functionName, "invalid internalfo
rmat"); |
| 693 return; | 689 return; |
| 694 } | 690 } |
| 695 contextGL()->RenderbufferStorage(target, GL_DEPTH24_STENCIL8, width, hei
ght); | 691 renderbufferStorageHelper(target, 0, GL_DEPTH24_STENCIL8, width, height,
functionName); |
| 696 break; | 692 break; |
| 697 case GL_R16F: | 693 case GL_R16F: |
| 698 case GL_RG16F: | 694 case GL_RG16F: |
| 699 case GL_RGBA16F: | 695 case GL_RGBA16F: |
| 700 case GL_R32F: | 696 case GL_R32F: |
| 701 case GL_RG32F: | 697 case GL_RG32F: |
| 702 case GL_RGBA32F: | 698 case GL_RGBA32F: |
| 703 case GL_R11F_G11F_B10F: | 699 case GL_R11F_G11F_B10F: |
| 704 if (!extensionEnabled(EXTColorBufferFloatName)) { | 700 if (!extensionEnabled(EXTColorBufferFloatName)) { |
| 705 synthesizeGLError(GL_INVALID_ENUM, functionName, "EXT_color_buffer_f
loat not enabled"); | 701 synthesizeGLError(GL_INVALID_ENUM, functionName, "EXT_color_buffer_f
loat not enabled"); |
| 706 return; | 702 return; |
| 707 } | 703 } |
| 708 if (samples) { | 704 renderbufferStorageHelper(target, samples, internalformat, width, height
, functionName); |
| 709 synthesizeGLError(GL_INVALID_VALUE, functionName, "multisampled floa
t buffers not supported"); | |
| 710 return; | |
| 711 } | |
| 712 contextGL()->RenderbufferStorage(target, internalformat, width, height); | |
| 713 break; | 705 break; |
| 714 default: | 706 default: |
| 715 synthesizeGLError(GL_INVALID_ENUM, functionName, "invalid internalformat
"); | 707 synthesizeGLError(GL_INVALID_ENUM, functionName, "invalid internalformat
"); |
| 716 return; | 708 return; |
| 717 } | 709 } |
| 718 m_renderbufferBinding->setInternalFormat(internalformat); | 710 m_renderbufferBinding->setInternalFormat(internalformat); |
| 719 m_renderbufferBinding->setSize(width, height); | 711 m_renderbufferBinding->setSize(width, height); |
| 720 } | 712 } |
| 721 | 713 |
| 722 void WebGL2RenderingContextBase::renderbufferStorageMultisample(GLenum target, G
Lsizei samples, GLenum internalformat, GLsizei width, GLsizei height) | 714 void WebGL2RenderingContextBase::renderbufferStorageMultisample(GLenum target, G
Lsizei samples, GLenum internalformat, GLsizei width, GLsizei height) |
| (...skipping 2646 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3369 params.skipPixels = m_unpackSkipPixels; | 3361 params.skipPixels = m_unpackSkipPixels; |
| 3370 params.skipRows = m_unpackSkipRows; | 3362 params.skipRows = m_unpackSkipRows; |
| 3371 if (dimension == Tex3D) { | 3363 if (dimension == Tex3D) { |
| 3372 params.imageHeight = m_unpackImageHeight; | 3364 params.imageHeight = m_unpackImageHeight; |
| 3373 params.skipImages = m_unpackSkipImages; | 3365 params.skipImages = m_unpackSkipImages; |
| 3374 } | 3366 } |
| 3375 return params; | 3367 return params; |
| 3376 } | 3368 } |
| 3377 | 3369 |
| 3378 } // namespace blink | 3370 } // namespace blink |
| OLD | NEW |