2 * Copyright (c) 2010, Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 #include "DrawingBuffer.h"
35 #include "GraphicsContext3D.h"
39 static unsigned generateColorTexture(GraphicsContext3D* context, const IntSize& size)
41 unsigned offscreenColorTexture = context->createTexture();
42 if (!offscreenColorTexture)
45 context->bindTexture(GraphicsContext3D::TEXTURE_2D, offscreenColorTexture);
46 context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_MAG_FILTER, GraphicsContext3D::NEAREST);
47 context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_MIN_FILTER, GraphicsContext3D::NEAREST);
48 context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_WRAP_S, GraphicsContext3D::CLAMP_TO_EDGE);
49 context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_WRAP_T, GraphicsContext3D::CLAMP_TO_EDGE);
50 context->texImage2DResourceSafe(GraphicsContext3D::TEXTURE_2D, 0, GraphicsContext3D::RGBA, size.width(), size.height(), 0, GraphicsContext3D::RGBA, GraphicsContext3D::UNSIGNED_BYTE);
51 context->framebufferTexture2D(GraphicsContext3D::FRAMEBUFFER, GraphicsContext3D::COLOR_ATTACHMENT0, GraphicsContext3D::TEXTURE_2D, offscreenColorTexture, 0);
53 return offscreenColorTexture;
56 DrawingBuffer::DrawingBuffer(GraphicsContext3D* context,
58 bool multisampleExtensionSupported,
59 bool packedDepthStencilExtensionSupported)
62 , m_multisampleExtensionSupported(multisampleExtensionSupported)
63 , m_packedDepthStencilExtensionSupported(packedDepthStencilExtensionSupported)
66 , m_depthStencilBuffer(0)
70 , m_multisampleColorBuffer(0)
72 m_fbo = context->createFramebuffer();
73 context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_fbo);
74 m_colorBuffer = generateColorTexture(context, size);
75 createSecondaryBuffers();
82 DrawingBuffer::~DrawingBuffer()
90 #if USE(ACCELERATED_COMPOSITING)
91 void DrawingBuffer::publishToPlatformLayer()
98 m_context->makeContextCurrent();
103 #if USE(ACCELERATED_COMPOSITING)
104 PlatformLayer* DrawingBuffer::platformLayer()
110 Platform3DObject DrawingBuffer::platformColorBuffer() const
112 return m_colorBuffer;