Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(521)

Side by Side Diff: Source/core/html/canvas/WebGLFramebuffer.cpp

Issue 24096029: Moved the majority of WebGL functionality into WebGLRenderingContextBase (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Revamped extension testing, added featureLevel Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "core/platform/NotImplemented.h" 31 #include "core/platform/NotImplemented.h"
32 #include "core/platform/graphics/Extensions3D.h" 32 #include "core/platform/graphics/Extensions3D.h"
33 33
34 namespace WebCore { 34 namespace WebCore {
35 35
36 namespace { 36 namespace {
37 37
38 Platform3DObject objectOrZero(WebGLObject* object) 38 Platform3DObject objectOrZero(WebGLObject* object)
39 { 39 {
40 return object ? object->object() : 0; 40 return object ? object->object() : 0;
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 } // anonymous namespace 271 } // anonymous namespace
272 272
273 WebGLFramebuffer::WebGLAttachment::WebGLAttachment() 273 WebGLFramebuffer::WebGLAttachment::WebGLAttachment()
274 { 274 {
275 } 275 }
276 276
277 WebGLFramebuffer::WebGLAttachment::~WebGLAttachment() 277 WebGLFramebuffer::WebGLAttachment::~WebGLAttachment()
278 { 278 {
279 } 279 }
280 280
281 PassRefPtr<WebGLFramebuffer> WebGLFramebuffer::create(WebGLRenderingContext* ctx ) 281 PassRefPtr<WebGLFramebuffer> WebGLFramebuffer::create(WebGLRenderingContextBase* ctx)
282 { 282 {
283 return adoptRef(new WebGLFramebuffer(ctx)); 283 return adoptRef(new WebGLFramebuffer(ctx));
284 } 284 }
285 285
286 WebGLFramebuffer::WebGLFramebuffer(WebGLRenderingContext* ctx) 286 WebGLFramebuffer::WebGLFramebuffer(WebGLRenderingContextBase* ctx)
287 : WebGLContextObject(ctx) 287 : WebGLContextObject(ctx)
288 , m_hasEverBeenBound(false) 288 , m_hasEverBeenBound(false)
289 { 289 {
290 ScriptWrappable::init(this); 290 ScriptWrappable::init(this);
291 setObject(ctx->graphicsContext3D()->createFramebuffer()); 291 setObject(ctx->graphicsContext3D()->createFramebuffer());
292 } 292 }
293 293
294 WebGLFramebuffer::~WebGLFramebuffer() 294 WebGLFramebuffer::~WebGLFramebuffer()
295 { 295 {
296 deleteObject(0); 296 deleteObject(0);
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 ASSERT(object && (object->isTexture() || object->isRenderbuffer())); 348 ASSERT(object && (object->isTexture() || object->isRenderbuffer()));
349 349
350 if (attachment == GraphicsContext3D::DEPTH_ATTACHMENT) { 350 if (attachment == GraphicsContext3D::DEPTH_ATTACHMENT) {
351 if (object->isRenderbuffer()) { 351 if (object->isRenderbuffer()) {
352 if (internalformat != GraphicsContext3D::DEPTH_COMPONENT16) { 352 if (internalformat != GraphicsContext3D::DEPTH_COMPONENT16) {
353 *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";
354 return false; 354 return false;
355 } 355 }
356 } else if (object->isTexture()) { 356 } else if (object->isTexture()) {
357 GC3Denum type = attachedObject->getType(); 357 GC3Denum type = attachedObject->getType();
358 if (!(context()->m_webglDepthTexture && internalformat == GraphicsCo ntext3D::DEPTH_COMPONENT 358 if (!(context()->extensionEnabled(WebGLDepthTextureName) && internal format == GraphicsContext3D::DEPTH_COMPONENT
359 && (type == GraphicsContext3D::UNSIGNED_SHORT || type == Graphic sContext3D::UNSIGNED_INT))) { 359 && (type == GraphicsContext3D::UNSIGNED_SHORT || type == Graphic sContext3D::UNSIGNED_INT))) {
360 *reason = "the attached texture is not a depth texture"; 360 *reason = "the attached texture is not a depth texture";
361 return false; 361 return false;
362 } 362 }
363 } 363 }
364 } else if (attachment == GraphicsContext3D::STENCIL_ATTACHMENT) { 364 } else if (attachment == GraphicsContext3D::STENCIL_ATTACHMENT) {
365 // Depend on the underlying GL drivers to check stencil textures 365 // Depend on the underlying GL drivers to check stencil textures
366 // and check renderbuffer type here only. 366 // and check renderbuffer type here only.
367 if (object->isRenderbuffer()) { 367 if (object->isRenderbuffer()) {
368 if (internalformat != GraphicsContext3D::STENCIL_INDEX8) { 368 if (internalformat != GraphicsContext3D::STENCIL_INDEX8) {
369 *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";
370 return false; 370 return false;
371 } 371 }
372 } 372 }
373 } else if (attachment == GraphicsContext3D::DEPTH_STENCIL_ATTACHMENT) { 373 } else if (attachment == GraphicsContext3D::DEPTH_STENCIL_ATTACHMENT) {
374 if (object->isRenderbuffer()) { 374 if (object->isRenderbuffer()) {
375 if (internalformat != GraphicsContext3D::DEPTH_STENCIL) { 375 if (internalformat != GraphicsContext3D::DEPTH_STENCIL) {
376 *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";
377 return false; 377 return false;
378 } 378 }
379 } else if (object->isTexture()) { 379 } else if (object->isTexture()) {
380 GC3Denum type = attachedObject->getType(); 380 GC3Denum type = attachedObject->getType();
381 if (!(context()->m_webglDepthTexture && internalformat == GraphicsCo ntext3D::DEPTH_STENCIL 381 if (!(context()->extensionEnabled(WebGLDepthTextureName) && internal format == GraphicsContext3D::DEPTH_STENCIL
382 && type == GraphicsContext3D::UNSIGNED_INT_24_8)) { 382 && type == GraphicsContext3D::UNSIGNED_INT_24_8)) {
383 *reason = "the attached texture is not a DEPTH_STENCIL texture"; 383 *reason = "the attached texture is not a DEPTH_STENCIL texture";
384 return false; 384 return false;
385 } 385 }
386 } 386 }
387 } else if (attachment == GraphicsContext3D::COLOR_ATTACHMENT0 387 } else if (attachment == GraphicsContext3D::COLOR_ATTACHMENT0
388 || (context()->m_webglDrawBuffers && attachment > GraphicsContext3D::COL OR_ATTACHMENT0 388 || (context()->extensionEnabled(WebGLDrawBuffersName) && attachment > Gr aphicsContext3D::COLOR_ATTACHMENT0
389 && attachment < static_cast<GC3Denum>(GraphicsContext3D::COLOR_ATTAC HMENT0 + context()->getMaxColorAttachments()))) { 389 && attachment < static_cast<GC3Denum>(GraphicsContext3D::COLOR_ATTAC HMENT0 + context()->getMaxColorAttachments()))) {
390 if (object->isRenderbuffer()) { 390 if (object->isRenderbuffer()) {
391 if (!isColorRenderable(internalformat)) { 391 if (!isColorRenderable(internalformat)) {
392 *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";
393 return false; 393 return false;
394 } 394 }
395 } else if (object->isTexture()) { 395 } else if (object->isTexture()) {
396 GC3Denum type = attachedObject->getType(); 396 GC3Denum type = attachedObject->getType();
397 if (internalformat != GraphicsContext3D::RGBA && internalformat != G raphicsContext3D::RGB) { 397 if (internalformat != GraphicsContext3D::RGBA && internalformat != G raphicsContext3D::RGB) {
398 *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";
399 return false; 399 return false;
400 } 400 }
401 // 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
402 // 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
403 // 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.
404 // 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.
405 if (type != GraphicsContext3D::UNSIGNED_BYTE 405 if (type != GraphicsContext3D::UNSIGNED_BYTE
406 && type != GraphicsContext3D::UNSIGNED_SHORT_5_6_5 406 && type != GraphicsContext3D::UNSIGNED_SHORT_5_6_5
407 && type != GraphicsContext3D::UNSIGNED_SHORT_4_4_4_4 407 && type != GraphicsContext3D::UNSIGNED_SHORT_4_4_4_4
408 && type != GraphicsContext3D::UNSIGNED_SHORT_5_5_5_1 408 && type != GraphicsContext3D::UNSIGNED_SHORT_5_5_5_1
409 && !(type == GraphicsContext3D::FLOAT && context()->m_oesTexture Float) 409 && !(type == GraphicsContext3D::FLOAT && context()->extensionEna bled(OESTextureFloatName))
410 && !(type == GraphicsContext3D::HALF_FLOAT_OES && context()->m_o esTextureHalfFloat)) { 410 && !(type == GraphicsContext3D::HALF_FLOAT_OES && context()->ext ensionEnabled(OESTextureHalfFloatName))) {
411 *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";
412 return false; 412 return false;
413 } 413 }
414 } 414 }
415 } else { 415 } else {
416 *reason = "unknown framebuffer attachment point"; 416 *reason = "unknown framebuffer attachment point";
417 return false; 417 return false;
418 } 418 }
419 419
420 if (!attachedObject->getWidth() || !attachedObject->getHeight()) { 420 if (!attachedObject->getWidth() || !attachedObject->getHeight()) {
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
601 { 601 {
602 m_drawBuffers = bufs; 602 m_drawBuffers = bufs;
603 m_filteredDrawBuffers.resize(m_drawBuffers.size()); 603 m_filteredDrawBuffers.resize(m_drawBuffers.size());
604 for (size_t i = 0; i < m_filteredDrawBuffers.size(); ++i) 604 for (size_t i = 0; i < m_filteredDrawBuffers.size(); ++i)
605 m_filteredDrawBuffers[i] = GraphicsContext3D::NONE; 605 m_filteredDrawBuffers[i] = GraphicsContext3D::NONE;
606 drawBuffersIfNecessary(true); 606 drawBuffersIfNecessary(true);
607 } 607 }
608 608
609 void WebGLFramebuffer::drawBuffersIfNecessary(bool force) 609 void WebGLFramebuffer::drawBuffersIfNecessary(bool force)
610 { 610 {
611 if (!context()->m_webglDrawBuffers) 611 if (!context()->extensionEnabled(WebGLDrawBuffersName))
612 return; 612 return;
613 bool reset = force; 613 bool reset = force;
614 // This filtering works around graphics driver bugs on Mac OS X. 614 // This filtering works around graphics driver bugs on Mac OS X.
615 for (size_t i = 0; i < m_drawBuffers.size(); ++i) { 615 for (size_t i = 0; i < m_drawBuffers.size(); ++i) {
616 if (m_drawBuffers[i] != GraphicsContext3D::NONE && getAttachment(m_drawB uffers[i])) { 616 if (m_drawBuffers[i] != GraphicsContext3D::NONE && getAttachment(m_drawB uffers[i])) {
617 if (m_filteredDrawBuffers[i] != m_drawBuffers[i]) { 617 if (m_filteredDrawBuffers[i] != m_drawBuffers[i]) {
618 m_filteredDrawBuffers[i] = m_drawBuffers[i]; 618 m_filteredDrawBuffers[i] = m_drawBuffers[i];
619 reset = true; 619 reset = true;
620 } 620 }
621 } else { 621 } else {
(...skipping 14 matching lines...) Expand all
636 int index = static_cast<int>(drawBuffer - Extensions3D::DRAW_BUFFER0_EXT); 636 int index = static_cast<int>(drawBuffer - Extensions3D::DRAW_BUFFER0_EXT);
637 ASSERT(index >= 0); 637 ASSERT(index >= 0);
638 if (index < static_cast<int>(m_drawBuffers.size())) 638 if (index < static_cast<int>(m_drawBuffers.size()))
639 return m_drawBuffers[index]; 639 return m_drawBuffers[index];
640 if (drawBuffer == Extensions3D::DRAW_BUFFER0_EXT) 640 if (drawBuffer == Extensions3D::DRAW_BUFFER0_EXT)
641 return GraphicsContext3D::COLOR_ATTACHMENT0; 641 return GraphicsContext3D::COLOR_ATTACHMENT0;
642 return GraphicsContext3D::NONE; 642 return GraphicsContext3D::NONE;
643 } 643 }
644 644
645 } 645 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698