1 // Copyright 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
7 #if USE(ACCELERATED_COMPOSITING)
9 #include "GeometryBinding.h"
11 #include "CCRendererGL.h" // For the GLC() macro.
12 #include "GraphicsContext3D.h"
13 #include <public/WebGraphicsContext3D.h>
17 GeometryBinding::GeometryBinding(WebKit::WebGraphicsContext3D
* context
, const FloatRect
& quadVertexRect
)
19 , m_quadVerticesVbo(0)
20 , m_quadElementsVbo(0)
21 , m_initialized(false)
23 // Vertex positions and texture coordinates for the 4 corners of a 1x1 quad.
24 float vertices
[] = { quadVertexRect
.x(), quadVertexRect
.maxY(), 0.0f
, 0.0f
, 1.0f
,
25 quadVertexRect
.x(), quadVertexRect
.y(), 0.0f
, 0.0f
, 0.0f
,
26 quadVertexRect
.maxX(), quadVertexRect
.y(), 0.0f
, 1.0f
, 0.0f
,
27 quadVertexRect
.maxX(), quadVertexRect
.maxY(), 0.0f
, 1.0f
, 1.0f
};
28 uint16_t indices
[] = { 0, 1, 2, 0, 2, 3, // The two triangles that make up the layer quad.
29 0, 1, 2, 3}; // A line path for drawing the layer border.
31 GLC(m_context
, m_quadVerticesVbo
= m_context
->createBuffer());
32 GLC(m_context
, m_quadElementsVbo
= m_context
->createBuffer());
33 GLC(m_context
, m_context
->bindBuffer(GraphicsContext3D::ARRAY_BUFFER
, m_quadVerticesVbo
));
34 GLC(m_context
, m_context
->bufferData(GraphicsContext3D::ARRAY_BUFFER
, sizeof(vertices
), vertices
, GraphicsContext3D::STATIC_DRAW
));
35 GLC(m_context
, m_context
->bindBuffer(GraphicsContext3D::ELEMENT_ARRAY_BUFFER
, m_quadElementsVbo
));
36 GLC(m_context
, m_context
->bufferData(GraphicsContext3D::ELEMENT_ARRAY_BUFFER
, sizeof(indices
), indices
, GraphicsContext3D::STATIC_DRAW
));
41 GeometryBinding::~GeometryBinding()
43 GLC(m_context
, m_context
->deleteBuffer(m_quadVerticesVbo
));
44 GLC(m_context
, m_context
->deleteBuffer(m_quadElementsVbo
));
47 void GeometryBinding::prepareForDraw()
49 GLC(m_context
, m_context
->bindBuffer(GraphicsContext3D::ARRAY_BUFFER
, quadVerticesVbo()));
50 GLC(m_context
, m_context
->bindBuffer(GraphicsContext3D::ELEMENT_ARRAY_BUFFER
, quadElementsVbo()));
52 GLC(m_context
, m_context
->vertexAttribPointer(positionAttribLocation(), 3, GraphicsContext3D::FLOAT
, false, 5 * sizeof(float), offset
));
53 offset
+= 3 * sizeof(float);
54 GLC(m_context
, m_context
->vertexAttribPointer(texCoordAttribLocation(), 2, GraphicsContext3D::FLOAT
, false, 5 * sizeof(float), offset
));
55 GLC(m_context
, m_context
->enableVertexAttribArray(positionAttribLocation()));
56 GLC(m_context
, m_context
->enableVertexAttribArray(texCoordAttribLocation()));
61 #endif // USE(ACCELERATED_COMPOSITING)