| 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 |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 } | 80 } |
| 81 | 81 |
| 82 GC3Dsizei WebGLRenderbufferAttachment::height() const | 82 GC3Dsizei WebGLRenderbufferAttachment::height() const |
| 83 { | 83 { |
| 84 return m_renderbuffer->height(); | 84 return m_renderbuffer->height(); |
| 85 } | 85 } |
| 86 | 86 |
| 87 GC3Denum WebGLRenderbufferAttachment::format() const | 87 GC3Denum WebGLRenderbufferAttachment::format() const |
| 88 { | 88 { |
| 89 GC3Denum format = m_renderbuffer->internalFormat(); | 89 GC3Denum format = m_renderbuffer->internalFormat(); |
| 90 if (format == GraphicsContext3D::DEPTH_STENCIL | 90 if (format == GL_DEPTH_STENCIL_OES |
| 91 && m_renderbuffer->emulatedStencilBuffer() | 91 && m_renderbuffer->emulatedStencilBuffer() |
| 92 && m_renderbuffer->emulatedStencilBuffer()->internalFormat() != Grap
hicsContext3D::STENCIL_INDEX8) { | 92 && m_renderbuffer->emulatedStencilBuffer()->internalFormat() != GL_S
TENCIL_INDEX8) { |
| 93 return 0; | 93 return 0; |
| 94 } | 94 } |
| 95 return format; | 95 return format; |
| 96 } | 96 } |
| 97 | 97 |
| 98 WebGLSharedObject* WebGLRenderbufferAttachment::object() const | 98 WebGLSharedObject* WebGLRenderbufferAttachment::object() const |
| 99 { | 99 { |
| 100 return m_renderbuffer->object() ? m_renderbuffer.get() : 0; | 100 return m_renderbuffer->object() ? m_renderbuffer.get() : 0; |
| 101 } | 101 } |
| 102 | 102 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 122 } | 122 } |
| 123 | 123 |
| 124 void WebGLRenderbufferAttachment::onDetached(GraphicsContext3D* context) | 124 void WebGLRenderbufferAttachment::onDetached(GraphicsContext3D* context) |
| 125 { | 125 { |
| 126 m_renderbuffer->onDetached(context); | 126 m_renderbuffer->onDetached(context); |
| 127 } | 127 } |
| 128 | 128 |
| 129 void WebGLRenderbufferAttachment::attach(GraphicsContext3D* context, GC3Denu
m attachment) | 129 void WebGLRenderbufferAttachment::attach(GraphicsContext3D* context, GC3Denu
m attachment) |
| 130 { | 130 { |
| 131 Platform3DObject object = objectOrZero(m_renderbuffer.get()); | 131 Platform3DObject object = objectOrZero(m_renderbuffer.get()); |
| 132 if (attachment == GraphicsContext3D::DEPTH_STENCIL_ATTACHMENT && m_rende
rbuffer->emulatedStencilBuffer()) { | 132 if (attachment == GC3D_DEPTH_STENCIL_ATTACHMENT_WEBGL && m_renderbuffer-
>emulatedStencilBuffer()) { |
| 133 context->framebufferRenderbuffer(GraphicsContext3D::FRAMEBUFFER, Gra
phicsContext3D::DEPTH_ATTACHMENT, GraphicsContext3D::RENDERBUFFER, object); | 133 context->framebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT
, GL_RENDERBUFFER, object); |
| 134 context->framebufferRenderbuffer(GraphicsContext3D::FRAMEBUFFER, Gra
phicsContext3D::STENCIL_ATTACHMENT, GraphicsContext3D::RENDERBUFFER, objectOrZer
o(m_renderbuffer->emulatedStencilBuffer())); | 134 context->framebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHME
NT, GL_RENDERBUFFER, objectOrZero(m_renderbuffer->emulatedStencilBuffer())); |
| 135 } else { | 135 } else { |
| 136 context->framebufferRenderbuffer(GraphicsContext3D::FRAMEBUFFER, att
achment, GraphicsContext3D::RENDERBUFFER, object); | 136 context->framebufferRenderbuffer(GL_FRAMEBUFFER, attachment, GL_REND
ERBUFFER, object); |
| 137 } | 137 } |
| 138 } | 138 } |
| 139 | 139 |
| 140 void WebGLRenderbufferAttachment::unattach(GraphicsContext3D* context, GC3De
num attachment) | 140 void WebGLRenderbufferAttachment::unattach(GraphicsContext3D* context, GC3De
num attachment) |
| 141 { | 141 { |
| 142 if (attachment == GraphicsContext3D::DEPTH_STENCIL_ATTACHMENT) { | 142 if (attachment == GC3D_DEPTH_STENCIL_ATTACHMENT_WEBGL) { |
| 143 context->framebufferRenderbuffer(GraphicsContext3D::FRAMEBUFFER, Gra
phicsContext3D::DEPTH_ATTACHMENT, GraphicsContext3D::RENDERBUFFER, 0); | 143 context->framebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT
, GL_RENDERBUFFER, 0); |
| 144 context->framebufferRenderbuffer(GraphicsContext3D::FRAMEBUFFER, Gra
phicsContext3D::STENCIL_ATTACHMENT, GraphicsContext3D::RENDERBUFFER, 0); | 144 context->framebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHME
NT, GL_RENDERBUFFER, 0); |
| 145 } else | 145 } else { |
| 146 context->framebufferRenderbuffer(GraphicsContext3D::FRAMEBUFFER, att
achment, GraphicsContext3D::RENDERBUFFER, 0); | 146 context->framebufferRenderbuffer(GL_FRAMEBUFFER, attachment, GL_REND
ERBUFFER, 0); |
| 147 } |
| 147 } | 148 } |
| 148 | 149 |
| 149 GC3Denum WebGLRenderbufferAttachment::type() const | 150 GC3Denum WebGLRenderbufferAttachment::type() const |
| 150 { | 151 { |
| 151 notImplemented(); | 152 notImplemented(); |
| 152 return 0; | 153 return 0; |
| 153 } | 154 } |
| 154 | 155 |
| 155 class WebGLTextureAttachment : public WebGLFramebuffer::WebGLAttachment { | 156 class WebGLTextureAttachment : public WebGLFramebuffer::WebGLAttachment { |
| 156 public: | 157 public: |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 } | 233 } |
| 233 | 234 |
| 234 void WebGLTextureAttachment::onDetached(GraphicsContext3D* context) | 235 void WebGLTextureAttachment::onDetached(GraphicsContext3D* context) |
| 235 { | 236 { |
| 236 m_texture->onDetached(context); | 237 m_texture->onDetached(context); |
| 237 } | 238 } |
| 238 | 239 |
| 239 void WebGLTextureAttachment::attach(GraphicsContext3D* context, GC3Denum att
achment) | 240 void WebGLTextureAttachment::attach(GraphicsContext3D* context, GC3Denum att
achment) |
| 240 { | 241 { |
| 241 Platform3DObject object = objectOrZero(m_texture.get()); | 242 Platform3DObject object = objectOrZero(m_texture.get()); |
| 242 context->framebufferTexture2D(GraphicsContext3D::FRAMEBUFFER, attachment
, m_target, object, m_level); | 243 context->framebufferTexture2D(GL_FRAMEBUFFER, attachment, m_target, obje
ct, m_level); |
| 243 } | 244 } |
| 244 | 245 |
| 245 void WebGLTextureAttachment::unattach(GraphicsContext3D* context, GC3Denum a
ttachment) | 246 void WebGLTextureAttachment::unattach(GraphicsContext3D* context, GC3Denum a
ttachment) |
| 246 { | 247 { |
| 247 if (attachment == GraphicsContext3D::DEPTH_STENCIL_ATTACHMENT) { | 248 if (attachment == GC3D_DEPTH_STENCIL_ATTACHMENT_WEBGL) { |
| 248 context->framebufferTexture2D(GraphicsContext3D::FRAMEBUFFER, Graphi
csContext3D::DEPTH_ATTACHMENT, m_target, 0, m_level); | 249 context->framebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, m
_target, 0, m_level); |
| 249 context->framebufferTexture2D(GraphicsContext3D::FRAMEBUFFER, Graphi
csContext3D::STENCIL_ATTACHMENT, m_target, 0, m_level); | 250 context->framebufferTexture2D(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT,
m_target, 0, m_level); |
| 250 } else | 251 } else { |
| 251 context->framebufferTexture2D(GraphicsContext3D::FRAMEBUFFER, attach
ment, m_target, 0, m_level); | 252 context->framebufferTexture2D(GL_FRAMEBUFFER, attachment, m_target,
0, m_level); |
| 253 } |
| 252 } | 254 } |
| 253 | 255 |
| 254 GC3Denum WebGLTextureAttachment::type() const | 256 GC3Denum WebGLTextureAttachment::type() const |
| 255 { | 257 { |
| 256 return m_texture->getType(m_target, m_level); | 258 return m_texture->getType(m_target, m_level); |
| 257 } | 259 } |
| 258 | 260 |
| 259 bool isColorRenderable(GC3Denum internalformat) | 261 bool isColorRenderable(GC3Denum internalformat) |
| 260 { | 262 { |
| 261 switch (internalformat) { | 263 switch (internalformat) { |
| 262 case GraphicsContext3D::RGBA4: | 264 case GL_RGBA4: |
| 263 case GraphicsContext3D::RGB5_A1: | 265 case GL_RGB5_A1: |
| 264 case GraphicsContext3D::RGB565: | 266 case GL_RGB565: |
| 265 return true; | 267 return true; |
| 266 default: | 268 default: |
| 267 return false; | 269 return false; |
| 268 } | 270 } |
| 269 } | 271 } |
| 270 | 272 |
| 271 } // anonymous namespace | 273 } // anonymous namespace |
| 272 | 274 |
| 273 WebGLFramebuffer::WebGLAttachment::WebGLAttachment() | 275 WebGLFramebuffer::WebGLAttachment::WebGLAttachment() |
| 274 { | 276 { |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 | 342 |
| 341 bool WebGLFramebuffer::isAttachmentComplete(WebGLAttachment* attachedObject, GC3
Denum attachment, const char** reason) const | 343 bool WebGLFramebuffer::isAttachmentComplete(WebGLAttachment* attachedObject, GC3
Denum attachment, const char** reason) const |
| 342 { | 344 { |
| 343 ASSERT(attachedObject && attachedObject->valid()); | 345 ASSERT(attachedObject && attachedObject->valid()); |
| 344 ASSERT(reason); | 346 ASSERT(reason); |
| 345 | 347 |
| 346 GC3Denum internalformat = attachedObject->format(); | 348 GC3Denum internalformat = attachedObject->format(); |
| 347 WebGLSharedObject* object = attachedObject->object(); | 349 WebGLSharedObject* object = attachedObject->object(); |
| 348 ASSERT(object && (object->isTexture() || object->isRenderbuffer())); | 350 ASSERT(object && (object->isTexture() || object->isRenderbuffer())); |
| 349 | 351 |
| 350 if (attachment == GraphicsContext3D::DEPTH_ATTACHMENT) { | 352 if (attachment == GL_DEPTH_ATTACHMENT) { |
| 351 if (object->isRenderbuffer()) { | 353 if (object->isRenderbuffer()) { |
| 352 if (internalformat != GraphicsContext3D::DEPTH_COMPONENT16) { | 354 if (internalformat != GL_DEPTH_COMPONENT16) { |
| 353 *reason = "the internalformat of the attached renderbuffer is no
t DEPTH_COMPONENT16"; | 355 *reason = "the internalformat of the attached renderbuffer is no
t DEPTH_COMPONENT16"; |
| 354 return false; | 356 return false; |
| 355 } | 357 } |
| 356 } else if (object->isTexture()) { | 358 } else if (object->isTexture()) { |
| 357 GC3Denum type = attachedObject->type(); | 359 GC3Denum type = attachedObject->type(); |
| 358 if (!(context()->m_webglDepthTexture && internalformat == GraphicsCo
ntext3D::DEPTH_COMPONENT | 360 if (!(context()->m_webglDepthTexture && internalformat == GL_DEPTH_C
OMPONENT |
| 359 && (type == GraphicsContext3D::UNSIGNED_SHORT || type == Graphic
sContext3D::UNSIGNED_INT))) { | 361 && (type == GL_UNSIGNED_SHORT || type == GL_UNSIGNED_INT))) { |
| 360 *reason = "the attached texture is not a depth texture"; | 362 *reason = "the attached texture is not a depth texture"; |
| 361 return false; | 363 return false; |
| 362 } | 364 } |
| 363 } | 365 } |
| 364 } else if (attachment == GraphicsContext3D::STENCIL_ATTACHMENT) { | 366 } else if (attachment == GL_STENCIL_ATTACHMENT) { |
| 365 // Depend on the underlying GL drivers to check stencil textures | 367 // Depend on the underlying GL drivers to check stencil textures |
| 366 // and check renderbuffer type here only. | 368 // and check renderbuffer type here only. |
| 367 if (object->isRenderbuffer()) { | 369 if (object->isRenderbuffer()) { |
| 368 if (internalformat != GraphicsContext3D::STENCIL_INDEX8) { | 370 if (internalformat != GL_STENCIL_INDEX8) { |
| 369 *reason = "the internalformat of the attached renderbuffer is no
t STENCIL_INDEX8"; | 371 *reason = "the internalformat of the attached renderbuffer is no
t STENCIL_INDEX8"; |
| 370 return false; | 372 return false; |
| 371 } | 373 } |
| 372 } | 374 } |
| 373 } else if (attachment == GraphicsContext3D::DEPTH_STENCIL_ATTACHMENT) { | 375 } else if (attachment == GC3D_DEPTH_STENCIL_ATTACHMENT_WEBGL) { |
| 374 if (object->isRenderbuffer()) { | 376 if (object->isRenderbuffer()) { |
| 375 if (internalformat != GraphicsContext3D::DEPTH_STENCIL) { | 377 if (internalformat != GL_DEPTH_STENCIL_OES) { |
| 376 *reason = "the internalformat of the attached renderbuffer is no
t DEPTH_STENCIL"; | 378 *reason = "the internalformat of the attached renderbuffer is no
t DEPTH_STENCIL"; |
| 377 return false; | 379 return false; |
| 378 } | 380 } |
| 379 } else if (object->isTexture()) { | 381 } else if (object->isTexture()) { |
| 380 GC3Denum type = attachedObject->type(); | 382 GC3Denum type = attachedObject->type(); |
| 381 if (!(context()->m_webglDepthTexture && internalformat == GraphicsCo
ntext3D::DEPTH_STENCIL | 383 if (!(context()->m_webglDepthTexture && internalformat == GL_DEPTH_S
TENCIL_OES |
| 382 && type == GraphicsContext3D::UNSIGNED_INT_24_8)) { | 384 && type == GL_UNSIGNED_INT_24_8_OES)) { |
| 383 *reason = "the attached texture is not a DEPTH_STENCIL texture"; | 385 *reason = "the attached texture is not a DEPTH_STENCIL texture"; |
| 384 return false; | 386 return false; |
| 385 } | 387 } |
| 386 } | 388 } |
| 387 } else if (attachment == GraphicsContext3D::COLOR_ATTACHMENT0 | 389 } else if (attachment == GL_COLOR_ATTACHMENT0 |
| 388 || (context()->m_webglDrawBuffers && attachment > GraphicsContext3D::COL
OR_ATTACHMENT0 | 390 || (context()->m_webglDrawBuffers && attachment > GL_COLOR_ATTACHMENT0 |
| 389 && attachment < static_cast<GC3Denum>(GraphicsContext3D::COLOR_ATTAC
HMENT0 + context()->maxColorAttachments()))) { | 391 && attachment < static_cast<GC3Denum>(GL_COLOR_ATTACHMENT0 + context
()->maxColorAttachments()))) { |
| 390 if (object->isRenderbuffer()) { | 392 if (object->isRenderbuffer()) { |
| 391 if (!isColorRenderable(internalformat)) { | 393 if (!isColorRenderable(internalformat)) { |
| 392 *reason = "the internalformat of the attached renderbuffer is no
t color-renderable"; | 394 *reason = "the internalformat of the attached renderbuffer is no
t color-renderable"; |
| 393 return false; | 395 return false; |
| 394 } | 396 } |
| 395 } else if (object->isTexture()) { | 397 } else if (object->isTexture()) { |
| 396 GC3Denum type = attachedObject->type(); | 398 GC3Denum type = attachedObject->type(); |
| 397 if (internalformat != GraphicsContext3D::RGBA && internalformat != G
raphicsContext3D::RGB) { | 399 if (internalformat != GL_RGBA && internalformat != GL_RGB) { |
| 398 *reason = "the internalformat of the attached texture is not col
or-renderable"; | 400 *reason = "the internalformat of the attached texture is not col
or-renderable"; |
| 399 return false; | 401 return false; |
| 400 } | 402 } |
| 401 // TODO: WEBGL_color_buffer_float and EXT_color_buffer_half_float ex
tensions have not been implemented in | 403 // TODO: WEBGL_color_buffer_float and EXT_color_buffer_half_float ex
tensions have not been implemented in |
| 402 // WebGL yet. It would be better to depend on the underlying GL driv
ers to check on rendering to floating point textures | 404 // WebGL yet. It would be better to depend on the underlying GL driv
ers to check on rendering to floating point textures |
| 403 // and add the check back to WebGL when above two extensions are imp
lemented. | 405 // and add the check back to WebGL when above two extensions are imp
lemented. |
| 404 // Assume UNSIGNED_BYTE is renderable here without the need to expli
citly check if GL_OES_rgb8_rgba8 extension is supported. | 406 // Assume UNSIGNED_BYTE is renderable here without the need to expli
citly check if GL_OES_rgb8_rgba8 extension is supported. |
| 405 if (type != GraphicsContext3D::UNSIGNED_BYTE | 407 if (type != GL_UNSIGNED_BYTE |
| 406 && type != GraphicsContext3D::UNSIGNED_SHORT_5_6_5 | 408 && type != GL_UNSIGNED_SHORT_5_6_5 |
| 407 && type != GraphicsContext3D::UNSIGNED_SHORT_4_4_4_4 | 409 && type != GL_UNSIGNED_SHORT_4_4_4_4 |
| 408 && type != GraphicsContext3D::UNSIGNED_SHORT_5_5_5_1 | 410 && type != GL_UNSIGNED_SHORT_5_5_5_1 |
| 409 && !(type == GraphicsContext3D::FLOAT && context()->m_oesTexture
Float) | 411 && !(type == GL_FLOAT && context()->m_oesTextureFloat) |
| 410 && !(type == GraphicsContext3D::HALF_FLOAT_OES && context()->m_o
esTextureHalfFloat)) { | 412 && !(type == GL_HALF_FLOAT_OES && context()->m_oesTextureHalfFlo
at)) { |
| 411 *reason = "unsupported type: The attached texture is not support
ed to be rendered to"; | 413 *reason = "unsupported type: The attached texture is not support
ed to be rendered to"; |
| 412 return false; | 414 return false; |
| 413 } | 415 } |
| 414 } | 416 } |
| 415 } else { | 417 } else { |
| 416 *reason = "unknown framebuffer attachment point"; | 418 *reason = "unknown framebuffer attachment point"; |
| 417 return false; | 419 return false; |
| 418 } | 420 } |
| 419 | 421 |
| 420 if (!attachedObject->width() || !attachedObject->height()) { | 422 if (!attachedObject->width() || !attachedObject->height()) { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 435 ASSERT(isBound()); | 437 ASSERT(isBound()); |
| 436 if (!object()) | 438 if (!object()) |
| 437 return; | 439 return; |
| 438 | 440 |
| 439 WebGLAttachment* attachmentObject = getAttachment(attachment); | 441 WebGLAttachment* attachmentObject = getAttachment(attachment); |
| 440 if (attachmentObject) { | 442 if (attachmentObject) { |
| 441 attachmentObject->onDetached(context()->graphicsContext3D()); | 443 attachmentObject->onDetached(context()->graphicsContext3D()); |
| 442 m_attachments.remove(attachment); | 444 m_attachments.remove(attachment); |
| 443 drawBuffersIfNecessary(false); | 445 drawBuffersIfNecessary(false); |
| 444 switch (attachment) { | 446 switch (attachment) { |
| 445 case GraphicsContext3D::DEPTH_STENCIL_ATTACHMENT: | 447 case GC3D_DEPTH_STENCIL_ATTACHMENT_WEBGL: |
| 446 attach(GraphicsContext3D::DEPTH_ATTACHMENT, GraphicsContext3D::DEPTH
_ATTACHMENT); | 448 attach(GL_DEPTH_ATTACHMENT, GL_DEPTH_ATTACHMENT); |
| 447 attach(GraphicsContext3D::STENCIL_ATTACHMENT, GraphicsContext3D::STE
NCIL_ATTACHMENT); | 449 attach(GL_STENCIL_ATTACHMENT, GL_STENCIL_ATTACHMENT); |
| 448 break; | 450 break; |
| 449 case GraphicsContext3D::DEPTH_ATTACHMENT: | 451 case GL_DEPTH_ATTACHMENT: |
| 450 attach(GraphicsContext3D::DEPTH_STENCIL_ATTACHMENT, GraphicsContext3
D::DEPTH_ATTACHMENT); | 452 attach(GC3D_DEPTH_STENCIL_ATTACHMENT_WEBGL, GL_DEPTH_ATTACHMENT); |
| 451 break; | 453 break; |
| 452 case GraphicsContext3D::STENCIL_ATTACHMENT: | 454 case GL_STENCIL_ATTACHMENT: |
| 453 attach(GraphicsContext3D::DEPTH_STENCIL_ATTACHMENT, GraphicsContext3
D::STENCIL_ATTACHMENT); | 455 attach(GC3D_DEPTH_STENCIL_ATTACHMENT_WEBGL, GL_STENCIL_ATTACHMENT); |
| 454 break; | 456 break; |
| 455 } | 457 } |
| 456 } | 458 } |
| 457 } | 459 } |
| 458 | 460 |
| 459 void WebGLFramebuffer::removeAttachmentFromBoundFramebuffer(WebGLSharedObject* a
ttachment) | 461 void WebGLFramebuffer::removeAttachmentFromBoundFramebuffer(WebGLSharedObject* a
ttachment) |
| 460 { | 462 { |
| 461 ASSERT(isBound()); | 463 ASSERT(isBound()); |
| 462 if (!object()) | 464 if (!object()) |
| 463 return; | 465 return; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 477 break; | 479 break; |
| 478 } | 480 } |
| 479 } | 481 } |
| 480 } | 482 } |
| 481 } | 483 } |
| 482 | 484 |
| 483 GC3Dsizei WebGLFramebuffer::colorBufferWidth() const | 485 GC3Dsizei WebGLFramebuffer::colorBufferWidth() const |
| 484 { | 486 { |
| 485 if (!object()) | 487 if (!object()) |
| 486 return 0; | 488 return 0; |
| 487 WebGLAttachment* attachment = getAttachment(GraphicsContext3D::COLOR_ATTACHM
ENT0); | 489 WebGLAttachment* attachment = getAttachment(GL_COLOR_ATTACHMENT0); |
| 488 if (!attachment) | 490 if (!attachment) |
| 489 return 0; | 491 return 0; |
| 490 | 492 |
| 491 return attachment->width(); | 493 return attachment->width(); |
| 492 } | 494 } |
| 493 | 495 |
| 494 GC3Dsizei WebGLFramebuffer::colorBufferHeight() const | 496 GC3Dsizei WebGLFramebuffer::colorBufferHeight() const |
| 495 { | 497 { |
| 496 if (!object()) | 498 if (!object()) |
| 497 return 0; | 499 return 0; |
| 498 WebGLAttachment* attachment = getAttachment(GraphicsContext3D::COLOR_ATTACHM
ENT0); | 500 WebGLAttachment* attachment = getAttachment(GL_COLOR_ATTACHMENT0); |
| 499 if (!attachment) | 501 if (!attachment) |
| 500 return 0; | 502 return 0; |
| 501 | 503 |
| 502 return attachment->height(); | 504 return attachment->height(); |
| 503 } | 505 } |
| 504 | 506 |
| 505 GC3Denum WebGLFramebuffer::colorBufferFormat() const | 507 GC3Denum WebGLFramebuffer::colorBufferFormat() const |
| 506 { | 508 { |
| 507 if (!object()) | 509 if (!object()) |
| 508 return 0; | 510 return 0; |
| 509 WebGLAttachment* attachment = getAttachment(GraphicsContext3D::COLOR_ATTACHM
ENT0); | 511 WebGLAttachment* attachment = getAttachment(GL_COLOR_ATTACHMENT0); |
| 510 if (!attachment) | 512 if (!attachment) |
| 511 return 0; | 513 return 0; |
| 512 return attachment->format(); | 514 return attachment->format(); |
| 513 } | 515 } |
| 514 | 516 |
| 515 GC3Denum WebGLFramebuffer::checkStatus(const char** reason) const | 517 GC3Denum WebGLFramebuffer::checkStatus(const char** reason) const |
| 516 { | 518 { |
| 517 unsigned int count = 0; | 519 unsigned int count = 0; |
| 518 GC3Dsizei width = 0, height = 0; | 520 GC3Dsizei width = 0, height = 0; |
| 519 bool haveDepth = false; | 521 bool haveDepth = false; |
| 520 bool haveStencil = false; | 522 bool haveStencil = false; |
| 521 bool haveDepthStencil = false; | 523 bool haveDepthStencil = false; |
| 522 for (AttachmentMap::const_iterator it = m_attachments.begin(); it != m_attac
hments.end(); ++it) { | 524 for (AttachmentMap::const_iterator it = m_attachments.begin(); it != m_attac
hments.end(); ++it) { |
| 523 WebGLAttachment* attachment = it->value.get(); | 525 WebGLAttachment* attachment = it->value.get(); |
| 524 if (!isAttachmentComplete(attachment, it->key, reason)) | 526 if (!isAttachmentComplete(attachment, it->key, reason)) |
| 525 return GraphicsContext3D::FRAMEBUFFER_INCOMPLETE_ATTACHMENT; | 527 return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; |
| 526 if (!attachment->valid()) { | 528 if (!attachment->valid()) { |
| 527 *reason = "attachment is not valid"; | 529 *reason = "attachment is not valid"; |
| 528 return GraphicsContext3D::FRAMEBUFFER_UNSUPPORTED; | 530 return GL_FRAMEBUFFER_UNSUPPORTED; |
| 529 } | 531 } |
| 530 if (!attachment->format()) { | 532 if (!attachment->format()) { |
| 531 *reason = "attachment is an unsupported format"; | 533 *reason = "attachment is an unsupported format"; |
| 532 return GraphicsContext3D::FRAMEBUFFER_INCOMPLETE_ATTACHMENT; | 534 return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; |
| 533 } | 535 } |
| 534 switch (it->key) { | 536 switch (it->key) { |
| 535 case GraphicsContext3D::DEPTH_ATTACHMENT: | 537 case GL_DEPTH_ATTACHMENT: |
| 536 haveDepth = true; | 538 haveDepth = true; |
| 537 break; | 539 break; |
| 538 case GraphicsContext3D::STENCIL_ATTACHMENT: | 540 case GL_STENCIL_ATTACHMENT: |
| 539 haveStencil = true; | 541 haveStencil = true; |
| 540 break; | 542 break; |
| 541 case GraphicsContext3D::DEPTH_STENCIL_ATTACHMENT: | 543 case GC3D_DEPTH_STENCIL_ATTACHMENT_WEBGL: |
| 542 haveDepthStencil = true; | 544 haveDepthStencil = true; |
| 543 break; | 545 break; |
| 544 } | 546 } |
| 545 if (!count) { | 547 if (!count) { |
| 546 width = attachment->width(); | 548 width = attachment->width(); |
| 547 height = attachment->height(); | 549 height = attachment->height(); |
| 548 } else { | 550 } else { |
| 549 if (width != attachment->width() || height != attachment->height())
{ | 551 if (width != attachment->width() || height != attachment->height())
{ |
| 550 *reason = "attachments do not have the same dimensions"; | 552 *reason = "attachments do not have the same dimensions"; |
| 551 return GraphicsContext3D::FRAMEBUFFER_INCOMPLETE_DIMENSIONS; | 553 return GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS; |
| 552 } | 554 } |
| 553 } | 555 } |
| 554 ++count; | 556 ++count; |
| 555 } | 557 } |
| 556 if (!count) { | 558 if (!count) { |
| 557 *reason = "no attachments"; | 559 *reason = "no attachments"; |
| 558 return GraphicsContext3D::FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT; | 560 return GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT; |
| 559 } | 561 } |
| 560 if (!width || !height) { | 562 if (!width || !height) { |
| 561 *reason = "framebuffer has a 0 dimension"; | 563 *reason = "framebuffer has a 0 dimension"; |
| 562 return GraphicsContext3D::FRAMEBUFFER_INCOMPLETE_ATTACHMENT; | 564 return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; |
| 563 } | 565 } |
| 564 // WebGL specific: no conflicting DEPTH/STENCIL/DEPTH_STENCIL attachments. | 566 // WebGL specific: no conflicting DEPTH/STENCIL/DEPTH_STENCIL attachments. |
| 565 if ((haveDepthStencil && (haveDepth || haveStencil)) || (haveDepth && haveSt
encil)) { | 567 if ((haveDepthStencil && (haveDepth || haveStencil)) || (haveDepth && haveSt
encil)) { |
| 566 *reason = "conflicting DEPTH/STENCIL/DEPTH_STENCIL attachments"; | 568 *reason = "conflicting DEPTH/STENCIL/DEPTH_STENCIL attachments"; |
| 567 return GraphicsContext3D::FRAMEBUFFER_UNSUPPORTED; | 569 return GL_FRAMEBUFFER_UNSUPPORTED; |
| 568 } | 570 } |
| 569 return GraphicsContext3D::FRAMEBUFFER_COMPLETE; | 571 return GL_FRAMEBUFFER_COMPLETE; |
| 570 } | 572 } |
| 571 | 573 |
| 572 bool WebGLFramebuffer::onAccess(GraphicsContext3D* context3d, const char** reaso
n) | 574 bool WebGLFramebuffer::onAccess(GraphicsContext3D* context3d, const char** reaso
n) |
| 573 { | 575 { |
| 574 if (checkStatus(reason) != GraphicsContext3D::FRAMEBUFFER_COMPLETE) | 576 if (checkStatus(reason) != GL_FRAMEBUFFER_COMPLETE) |
| 575 return false; | 577 return false; |
| 576 return true; | 578 return true; |
| 577 } | 579 } |
| 578 | 580 |
| 579 bool WebGLFramebuffer::hasStencilBuffer() const | 581 bool WebGLFramebuffer::hasStencilBuffer() const |
| 580 { | 582 { |
| 581 WebGLAttachment* attachment = getAttachment(GraphicsContext3D::STENCIL_ATTAC
HMENT); | 583 WebGLAttachment* attachment = getAttachment(GL_STENCIL_ATTACHMENT); |
| 582 if (!attachment) | 584 if (!attachment) |
| 583 attachment = getAttachment(GraphicsContext3D::DEPTH_STENCIL_ATTACHMENT); | 585 attachment = getAttachment(GC3D_DEPTH_STENCIL_ATTACHMENT_WEBGL); |
| 584 return attachment && attachment->valid(); | 586 return attachment && attachment->valid(); |
| 585 } | 587 } |
| 586 | 588 |
| 587 void WebGLFramebuffer::deleteObjectImpl(GraphicsContext3D* context3d, Platform3D
Object object) | 589 void WebGLFramebuffer::deleteObjectImpl(GraphicsContext3D* context3d, Platform3D
Object object) |
| 588 { | 590 { |
| 589 for (AttachmentMap::iterator it = m_attachments.begin(); it != m_attachments
.end(); ++it) | 591 for (AttachmentMap::iterator it = m_attachments.begin(); it != m_attachments
.end(); ++it) |
| 590 it->value->onDetached(context3d); | 592 it->value->onDetached(context3d); |
| 591 | 593 |
| 592 context3d->deleteFramebuffer(object); | 594 context3d->deleteFramebuffer(object); |
| 593 } | 595 } |
| 594 | 596 |
| 595 bool WebGLFramebuffer::isBound() const | 597 bool WebGLFramebuffer::isBound() const |
| 596 { | 598 { |
| 597 return (context()->m_framebufferBinding.get() == this); | 599 return (context()->m_framebufferBinding.get() == this); |
| 598 } | 600 } |
| 599 | 601 |
| 600 void WebGLFramebuffer::drawBuffers(const Vector<GC3Denum>& bufs) | 602 void WebGLFramebuffer::drawBuffers(const Vector<GC3Denum>& bufs) |
| 601 { | 603 { |
| 602 m_drawBuffers = bufs; | 604 m_drawBuffers = bufs; |
| 603 m_filteredDrawBuffers.resize(m_drawBuffers.size()); | 605 m_filteredDrawBuffers.resize(m_drawBuffers.size()); |
| 604 for (size_t i = 0; i < m_filteredDrawBuffers.size(); ++i) | 606 for (size_t i = 0; i < m_filteredDrawBuffers.size(); ++i) |
| 605 m_filteredDrawBuffers[i] = GraphicsContext3D::NONE; | 607 m_filteredDrawBuffers[i] = GL_NONE; |
| 606 drawBuffersIfNecessary(true); | 608 drawBuffersIfNecessary(true); |
| 607 } | 609 } |
| 608 | 610 |
| 609 void WebGLFramebuffer::drawBuffersIfNecessary(bool force) | 611 void WebGLFramebuffer::drawBuffersIfNecessary(bool force) |
| 610 { | 612 { |
| 611 if (!context()->m_webglDrawBuffers) | 613 if (!context()->m_webglDrawBuffers) |
| 612 return; | 614 return; |
| 613 bool reset = force; | 615 bool reset = force; |
| 614 // This filtering works around graphics driver bugs on Mac OS X. | 616 // This filtering works around graphics driver bugs on Mac OS X. |
| 615 for (size_t i = 0; i < m_drawBuffers.size(); ++i) { | 617 for (size_t i = 0; i < m_drawBuffers.size(); ++i) { |
| 616 if (m_drawBuffers[i] != GraphicsContext3D::NONE && getAttachment(m_drawB
uffers[i])) { | 618 if (m_drawBuffers[i] != GL_NONE && getAttachment(m_drawBuffers[i])) { |
| 617 if (m_filteredDrawBuffers[i] != m_drawBuffers[i]) { | 619 if (m_filteredDrawBuffers[i] != m_drawBuffers[i]) { |
| 618 m_filteredDrawBuffers[i] = m_drawBuffers[i]; | 620 m_filteredDrawBuffers[i] = m_drawBuffers[i]; |
| 619 reset = true; | 621 reset = true; |
| 620 } | 622 } |
| 621 } else { | 623 } else { |
| 622 if (m_filteredDrawBuffers[i] != GraphicsContext3D::NONE) { | 624 if (m_filteredDrawBuffers[i] != GL_NONE) { |
| 623 m_filteredDrawBuffers[i] = GraphicsContext3D::NONE; | 625 m_filteredDrawBuffers[i] = GL_NONE; |
| 624 reset = true; | 626 reset = true; |
| 625 } | 627 } |
| 626 } | 628 } |
| 627 } | 629 } |
| 628 if (reset) { | 630 if (reset) { |
| 629 context()->graphicsContext3D()->extensions()->drawBuffersEXT( | 631 context()->graphicsContext3D()->extensions()->drawBuffersEXT( |
| 630 m_filteredDrawBuffers.size(), m_filteredDrawBuffers.data()); | 632 m_filteredDrawBuffers.size(), m_filteredDrawBuffers.data()); |
| 631 } | 633 } |
| 632 } | 634 } |
| 633 | 635 |
| 634 GC3Denum WebGLFramebuffer::getDrawBuffer(GC3Denum drawBuffer) | 636 GC3Denum WebGLFramebuffer::getDrawBuffer(GC3Denum drawBuffer) |
| 635 { | 637 { |
| 636 int index = static_cast<int>(drawBuffer - Extensions3D::DRAW_BUFFER0_EXT); | 638 int index = static_cast<int>(drawBuffer - Extensions3D::DRAW_BUFFER0_EXT); |
| 637 ASSERT(index >= 0); | 639 ASSERT(index >= 0); |
| 638 if (index < static_cast<int>(m_drawBuffers.size())) | 640 if (index < static_cast<int>(m_drawBuffers.size())) |
| 639 return m_drawBuffers[index]; | 641 return m_drawBuffers[index]; |
| 640 if (drawBuffer == Extensions3D::DRAW_BUFFER0_EXT) | 642 if (drawBuffer == Extensions3D::DRAW_BUFFER0_EXT) |
| 641 return GraphicsContext3D::COLOR_ATTACHMENT0; | 643 return GL_COLOR_ATTACHMENT0; |
| 642 return GraphicsContext3D::NONE; | 644 return GL_NONE; |
| 643 } | 645 } |
| 644 | 646 |
| 645 } | 647 } |
| OLD | NEW |