| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2009 Apple Inc. All rights reserved. | 2 * Copyright (C) 2009 Apple Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| 11 * documentation and/or other materials provided with the distribution. | 11 * documentation and/or other materials provided with the distribution. |
| 12 * | 12 * |
| 13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY | 13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY |
| 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR | 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR |
| 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 24 */ | 24 */ |
| 25 | 25 |
| 26 #include "config.h" | 26 #include "config.h" |
| 27 | 27 |
| 28 #include "core/html/canvas/WebGLFramebuffer.h" | 28 #include "core/html/canvas/WebGLFramebuffer.h" |
| 29 | 29 |
| 30 #include "core/html/canvas/WebGLRenderingContext.h" | 30 #include "core/html/canvas/WebGLRenderingContextBase.h" |
| 31 #include "platform/NotImplemented.h" | 31 #include "platform/NotImplemented.h" |
| 32 | 32 |
| 33 namespace WebCore { | 33 namespace WebCore { |
| 34 | 34 |
| 35 namespace { | 35 namespace { |
| 36 | 36 |
| 37 Platform3DObject objectOrZero(WebGLObject* object) | 37 Platform3DObject objectOrZero(WebGLObject* object) |
| 38 { | 38 { |
| 39 return object ? object->object() : 0; | 39 return object ? object->object() : 0; |
| 40 } | 40 } |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 } // anonymous namespace | 246 } // anonymous namespace |
| 247 | 247 |
| 248 WebGLFramebuffer::WebGLAttachment::WebGLAttachment() | 248 WebGLFramebuffer::WebGLAttachment::WebGLAttachment() |
| 249 { | 249 { |
| 250 } | 250 } |
| 251 | 251 |
| 252 WebGLFramebuffer::WebGLAttachment::~WebGLAttachment() | 252 WebGLFramebuffer::WebGLAttachment::~WebGLAttachment() |
| 253 { | 253 { |
| 254 } | 254 } |
| 255 | 255 |
| 256 PassRefPtr<WebGLFramebuffer> WebGLFramebuffer::create(WebGLRenderingContext* ctx
) | 256 PassRefPtr<WebGLFramebuffer> WebGLFramebuffer::create(WebGLRenderingContextBase*
ctx) |
| 257 { | 257 { |
| 258 return adoptRef(new WebGLFramebuffer(ctx)); | 258 return adoptRef(new WebGLFramebuffer(ctx)); |
| 259 } | 259 } |
| 260 | 260 |
| 261 WebGLFramebuffer::WebGLFramebuffer(WebGLRenderingContext* ctx) | 261 WebGLFramebuffer::WebGLFramebuffer(WebGLRenderingContextBase* ctx) |
| 262 : WebGLContextObject(ctx) | 262 : WebGLContextObject(ctx) |
| 263 , m_hasEverBeenBound(false) | 263 , m_hasEverBeenBound(false) |
| 264 { | 264 { |
| 265 ScriptWrappable::init(this); | 265 ScriptWrappable::init(this); |
| 266 setObject(ctx->webGraphicsContext3D()->createFramebuffer()); | 266 setObject(ctx->webGraphicsContext3D()->createFramebuffer()); |
| 267 } | 267 } |
| 268 | 268 |
| 269 WebGLFramebuffer::~WebGLFramebuffer() | 269 WebGLFramebuffer::~WebGLFramebuffer() |
| 270 { | 270 { |
| 271 deleteObject(0); | 271 deleteObject(0); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 323 ASSERT(object && (object->isTexture() || object->isRenderbuffer())); | 323 ASSERT(object && (object->isTexture() || object->isRenderbuffer())); |
| 324 | 324 |
| 325 if (attachment == GL_DEPTH_ATTACHMENT) { | 325 if (attachment == GL_DEPTH_ATTACHMENT) { |
| 326 if (object->isRenderbuffer()) { | 326 if (object->isRenderbuffer()) { |
| 327 if (internalformat != GL_DEPTH_COMPONENT16) { | 327 if (internalformat != GL_DEPTH_COMPONENT16) { |
| 328 *reason = "the internalformat of the attached renderbuffer is no
t DEPTH_COMPONENT16"; | 328 *reason = "the internalformat of the attached renderbuffer is no
t DEPTH_COMPONENT16"; |
| 329 return false; | 329 return false; |
| 330 } | 330 } |
| 331 } else if (object->isTexture()) { | 331 } else if (object->isTexture()) { |
| 332 GLenum type = attachedObject->type(); | 332 GLenum type = attachedObject->type(); |
| 333 if (!(context()->m_webglDepthTexture && internalformat == GL_DEPTH_C
OMPONENT | 333 if (!(context()->extensionEnabled(WebGLDepthTextureName) && internal
format == GL_DEPTH_COMPONENT |
| 334 && (type == GL_UNSIGNED_SHORT || type == GL_UNSIGNED_INT))) { | 334 && (type == GL_UNSIGNED_SHORT || type == GL_UNSIGNED_INT))) { |
| 335 *reason = "the attached texture is not a depth texture"; | 335 *reason = "the attached texture is not a depth texture"; |
| 336 return false; | 336 return false; |
| 337 } | 337 } |
| 338 } | 338 } |
| 339 } else if (attachment == GL_STENCIL_ATTACHMENT) { | 339 } else if (attachment == GL_STENCIL_ATTACHMENT) { |
| 340 // Depend on the underlying GL drivers to check stencil textures | 340 // Depend on the underlying GL drivers to check stencil textures |
| 341 // and check renderbuffer type here only. | 341 // and check renderbuffer type here only. |
| 342 if (object->isRenderbuffer()) { | 342 if (object->isRenderbuffer()) { |
| 343 if (internalformat != GL_STENCIL_INDEX8) { | 343 if (internalformat != GL_STENCIL_INDEX8) { |
| 344 *reason = "the internalformat of the attached renderbuffer is no
t STENCIL_INDEX8"; | 344 *reason = "the internalformat of the attached renderbuffer is no
t STENCIL_INDEX8"; |
| 345 return false; | 345 return false; |
| 346 } | 346 } |
| 347 } | 347 } |
| 348 } else if (attachment == GC3D_DEPTH_STENCIL_ATTACHMENT_WEBGL) { | 348 } else if (attachment == GC3D_DEPTH_STENCIL_ATTACHMENT_WEBGL) { |
| 349 if (object->isRenderbuffer()) { | 349 if (object->isRenderbuffer()) { |
| 350 if (internalformat != GL_DEPTH_STENCIL_OES) { | 350 if (internalformat != GL_DEPTH_STENCIL_OES) { |
| 351 *reason = "the internalformat of the attached renderbuffer is no
t DEPTH_STENCIL"; | 351 *reason = "the internalformat of the attached renderbuffer is no
t DEPTH_STENCIL"; |
| 352 return false; | 352 return false; |
| 353 } | 353 } |
| 354 } else if (object->isTexture()) { | 354 } else if (object->isTexture()) { |
| 355 GLenum type = attachedObject->type(); | 355 GLenum type = attachedObject->type(); |
| 356 if (!(context()->m_webglDepthTexture && internalformat == GL_DEPTH_S
TENCIL_OES | 356 if (!(context()->extensionEnabled(WebGLDepthTextureName) && internal
format == GL_DEPTH_STENCIL_OES |
| 357 && type == GL_UNSIGNED_INT_24_8_OES)) { | 357 && type == GL_UNSIGNED_INT_24_8_OES)) { |
| 358 *reason = "the attached texture is not a DEPTH_STENCIL texture"; | 358 *reason = "the attached texture is not a DEPTH_STENCIL texture"; |
| 359 return false; | 359 return false; |
| 360 } | 360 } |
| 361 } | 361 } |
| 362 } else if (attachment == GL_COLOR_ATTACHMENT0 | 362 } else if (attachment == GL_COLOR_ATTACHMENT0 |
| 363 || (context()->m_webglDrawBuffers && attachment > GL_COLOR_ATTACHMENT0 | 363 || (context()->extensionEnabled(WebGLDrawBuffersName) && attachment > GL
_COLOR_ATTACHMENT0 |
| 364 && attachment < static_cast<GLenum>(GL_COLOR_ATTACHMENT0 + context()
->maxColorAttachments()))) { | 364 && attachment < static_cast<GLenum>(GL_COLOR_ATTACHMENT0 + context()
->maxColorAttachments()))) { |
| 365 if (object->isRenderbuffer()) { | 365 if (object->isRenderbuffer()) { |
| 366 if (!isColorRenderable(internalformat)) { | 366 if (!isColorRenderable(internalformat)) { |
| 367 *reason = "the internalformat of the attached renderbuffer is no
t color-renderable"; | 367 *reason = "the internalformat of the attached renderbuffer is no
t color-renderable"; |
| 368 return false; | 368 return false; |
| 369 } | 369 } |
| 370 } else if (object->isTexture()) { | 370 } else if (object->isTexture()) { |
| 371 GLenum type = attachedObject->type(); | 371 GLenum type = attachedObject->type(); |
| 372 if (internalformat != GL_RGBA && internalformat != GL_RGB) { | 372 if (internalformat != GL_RGBA && internalformat != GL_RGB) { |
| 373 *reason = "the internalformat of the attached texture is not col
or-renderable"; | 373 *reason = "the internalformat of the attached texture is not col
or-renderable"; |
| 374 return false; | 374 return false; |
| 375 } | 375 } |
| 376 // TODO: WEBGL_color_buffer_float and EXT_color_buffer_half_float ex
tensions have not been implemented in | 376 // TODO: WEBGL_color_buffer_float and EXT_color_buffer_half_float ex
tensions have not been implemented in |
| 377 // WebGL yet. It would be better to depend on the underlying GL driv
ers to check on rendering to floating point textures | 377 // WebGL yet. It would be better to depend on the underlying GL driv
ers to check on rendering to floating point textures |
| 378 // and add the check back to WebGL when above two extensions are imp
lemented. | 378 // and add the check back to WebGL when above two extensions are imp
lemented. |
| 379 // Assume UNSIGNED_BYTE is renderable here without the need to expli
citly check if GL_OES_rgb8_rgba8 extension is supported. | 379 // Assume UNSIGNED_BYTE is renderable here without the need to expli
citly check if GL_OES_rgb8_rgba8 extension is supported. |
| 380 if (type != GL_UNSIGNED_BYTE | 380 if (type != GL_UNSIGNED_BYTE |
| 381 && type != GL_UNSIGNED_SHORT_5_6_5 | 381 && type != GL_UNSIGNED_SHORT_5_6_5 |
| 382 && type != GL_UNSIGNED_SHORT_4_4_4_4 | 382 && type != GL_UNSIGNED_SHORT_4_4_4_4 |
| 383 && type != GL_UNSIGNED_SHORT_5_5_5_1 | 383 && type != GL_UNSIGNED_SHORT_5_5_5_1 |
| 384 && !(type == GL_FLOAT && context()->m_oesTextureFloat) | 384 && !(type == GL_FLOAT && context()->extensionEnabled(OESTextureF
loatName)) |
| 385 && !(type == GL_HALF_FLOAT_OES && context()->m_oesTextureHalfFlo
at)) { | 385 && !(type == GL_HALF_FLOAT_OES && context()->extensionEnabled(OE
STextureHalfFloatName))) { |
| 386 *reason = "unsupported type: The attached texture is not support
ed to be rendered to"; | 386 *reason = "unsupported type: The attached texture is not support
ed to be rendered to"; |
| 387 return false; | 387 return false; |
| 388 } | 388 } |
| 389 } | 389 } |
| 390 } else { | 390 } else { |
| 391 *reason = "unknown framebuffer attachment point"; | 391 *reason = "unknown framebuffer attachment point"; |
| 392 return false; | 392 return false; |
| 393 } | 393 } |
| 394 | 394 |
| 395 if (!attachedObject->width() || !attachedObject->height()) { | 395 if (!attachedObject->width() || !attachedObject->height()) { |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 576 { | 576 { |
| 577 m_drawBuffers = bufs; | 577 m_drawBuffers = bufs; |
| 578 m_filteredDrawBuffers.resize(m_drawBuffers.size()); | 578 m_filteredDrawBuffers.resize(m_drawBuffers.size()); |
| 579 for (size_t i = 0; i < m_filteredDrawBuffers.size(); ++i) | 579 for (size_t i = 0; i < m_filteredDrawBuffers.size(); ++i) |
| 580 m_filteredDrawBuffers[i] = GL_NONE; | 580 m_filteredDrawBuffers[i] = GL_NONE; |
| 581 drawBuffersIfNecessary(true); | 581 drawBuffersIfNecessary(true); |
| 582 } | 582 } |
| 583 | 583 |
| 584 void WebGLFramebuffer::drawBuffersIfNecessary(bool force) | 584 void WebGLFramebuffer::drawBuffersIfNecessary(bool force) |
| 585 { | 585 { |
| 586 if (!context()->m_webglDrawBuffers) | 586 if (!context()->extensionEnabled(WebGLDrawBuffersName)) |
| 587 return; | 587 return; |
| 588 bool reset = force; | 588 bool reset = force; |
| 589 // This filtering works around graphics driver bugs on Mac OS X. | 589 // This filtering works around graphics driver bugs on Mac OS X. |
| 590 for (size_t i = 0; i < m_drawBuffers.size(); ++i) { | 590 for (size_t i = 0; i < m_drawBuffers.size(); ++i) { |
| 591 if (m_drawBuffers[i] != GL_NONE && getAttachment(m_drawBuffers[i])) { | 591 if (m_drawBuffers[i] != GL_NONE && getAttachment(m_drawBuffers[i])) { |
| 592 if (m_filteredDrawBuffers[i] != m_drawBuffers[i]) { | 592 if (m_filteredDrawBuffers[i] != m_drawBuffers[i]) { |
| 593 m_filteredDrawBuffers[i] = m_drawBuffers[i]; | 593 m_filteredDrawBuffers[i] = m_drawBuffers[i]; |
| 594 reset = true; | 594 reset = true; |
| 595 } | 595 } |
| 596 } else { | 596 } else { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 611 int index = static_cast<int>(drawBuffer - GL_DRAW_BUFFER0_EXT); | 611 int index = static_cast<int>(drawBuffer - GL_DRAW_BUFFER0_EXT); |
| 612 ASSERT(index >= 0); | 612 ASSERT(index >= 0); |
| 613 if (index < static_cast<int>(m_drawBuffers.size())) | 613 if (index < static_cast<int>(m_drawBuffers.size())) |
| 614 return m_drawBuffers[index]; | 614 return m_drawBuffers[index]; |
| 615 if (drawBuffer == GL_DRAW_BUFFER0_EXT) | 615 if (drawBuffer == GL_DRAW_BUFFER0_EXT) |
| 616 return GL_COLOR_ATTACHMENT0; | 616 return GL_COLOR_ATTACHMENT0; |
| 617 return GL_NONE; | 617 return GL_NONE; |
| 618 } | 618 } |
| 619 | 619 |
| 620 } | 620 } |
| OLD | NEW |