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