blob: 6a76ccca9eeb26bfbeeb3e22ec909d82ab9818c1 [file] [log] [blame]
[email protected]94f206c12012-08-25 00:09:141// 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.
4
5#include "config.h"
6
[email protected]a8461d82012-10-16 21:11:147#include "cc/geometry_binding.h"
[email protected]94f206c12012-08-25 00:09:148
[email protected]c4040a522012-10-21 15:01:409#include "cc/gl_renderer.h" // For the GLC() macro.
[email protected]d9c28522012-10-18 23:35:4310#include "third_party/khronos/GLES2/gl2.h"
[email protected]d0f98362012-11-01 23:02:3811#include "ui/gfx/rect_f.h"
[email protected]94f206c12012-08-25 00:09:1412#include <public/WebGraphicsContext3D.h>
13
[email protected]9c88e562012-09-14 22:21:3014namespace cc {
[email protected]94f206c12012-08-25 00:09:1415
[email protected]d0f98362012-11-01 23:02:3816GeometryBinding::GeometryBinding(WebKit::WebGraphicsContext3D* context, const gfx::RectF& quadVertexRect)
[email protected]94f206c12012-08-25 00:09:1417 : m_context(context)
18 , m_quadVerticesVbo(0)
19 , m_quadElementsVbo(0)
20 , m_initialized(false)
21{
22 // Vertex positions and texture coordinates for the 4 corners of a 1x1 quad.
[email protected]d0f98362012-11-01 23:02:3823 float vertices[] = { quadVertexRect.x(), quadVertexRect.bottom(), 0.0f, 0.0f, 1.0f,
[email protected]94f206c12012-08-25 00:09:1424 quadVertexRect.x(), quadVertexRect.y(), 0.0f, 0.0f, 0.0f,
[email protected]d0f98362012-11-01 23:02:3825 quadVertexRect.right(), quadVertexRect.y(), 0.0f, 1.0f, 0.0f,
26 quadVertexRect.right(), quadVertexRect.bottom(), 0.0f, 1.0f, 1.0f };
[email protected]94f206c12012-08-25 00:09:1427 uint16_t indices[] = { 0, 1, 2, 0, 2, 3, // The two triangles that make up the layer quad.
28 0, 1, 2, 3}; // A line path for drawing the layer border.
29
30 GLC(m_context, m_quadVerticesVbo = m_context->createBuffer());
31 GLC(m_context, m_quadElementsVbo = m_context->createBuffer());
[email protected]d9c28522012-10-18 23:35:4332 GLC(m_context, m_context->bindBuffer(GL_ARRAY_BUFFER, m_quadVerticesVbo));
33 GLC(m_context, m_context->bufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW));
34 GLC(m_context, m_context->bindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_quadElementsVbo));
35 GLC(m_context, m_context->bufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW));
[email protected]94f206c12012-08-25 00:09:1436
37 m_initialized = true;
38}
39
40GeometryBinding::~GeometryBinding()
41{
42 GLC(m_context, m_context->deleteBuffer(m_quadVerticesVbo));
43 GLC(m_context, m_context->deleteBuffer(m_quadElementsVbo));
44}
45
46void GeometryBinding::prepareForDraw()
47{
[email protected]d9c28522012-10-18 23:35:4348 GLC(m_context, m_context->bindBuffer(GL_ARRAY_BUFFER, quadVerticesVbo()));
49 GLC(m_context, m_context->bindBuffer(GL_ELEMENT_ARRAY_BUFFER, quadElementsVbo()));
[email protected]94f206c12012-08-25 00:09:1450 unsigned offset = 0;
[email protected]d9c28522012-10-18 23:35:4351 GLC(m_context, m_context->vertexAttribPointer(positionAttribLocation(), 3, GL_FLOAT, false, 5 * sizeof(float), offset));
[email protected]94f206c12012-08-25 00:09:1452 offset += 3 * sizeof(float);
[email protected]d9c28522012-10-18 23:35:4353 GLC(m_context, m_context->vertexAttribPointer(texCoordAttribLocation(), 2, GL_FLOAT, false, 5 * sizeof(float), offset));
[email protected]94f206c12012-08-25 00:09:1454 GLC(m_context, m_context->enableVertexAttribArray(positionAttribLocation()));
55 GLC(m_context, m_context->enableVertexAttribArray(texCoordAttribLocation()));
56}
57
[email protected]bc5e77c2012-11-05 20:00:4958} // namespace cc