[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 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. |
| 4 | |
| 5 | #include "config.h" |
| 6 | |
[email protected] | a8461d8 | 2012-10-16 21:11:14 | [diff] [blame] | 7 | #include "cc/geometry_binding.h" |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 8 | |
[email protected] | c4040a52 | 2012-10-21 15:01:40 | [diff] [blame] | 9 | #include "cc/gl_renderer.h" // For the GLC() macro. |
[email protected] | d9c2852 | 2012-10-18 23:35:43 | [diff] [blame] | 10 | #include "third_party/khronos/GLES2/gl2.h" |
[email protected] | d0f9836 | 2012-11-01 23:02:38 | [diff] [blame] | 11 | #include "ui/gfx/rect_f.h" |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 12 | #include <public/WebGraphicsContext3D.h> |
| 13 | |
[email protected] | 9c88e56 | 2012-09-14 22:21:30 | [diff] [blame] | 14 | namespace cc { |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 15 | |
[email protected] | d0f9836 | 2012-11-01 23:02:38 | [diff] [blame] | 16 | GeometryBinding::GeometryBinding(WebKit::WebGraphicsContext3D* context, const gfx::RectF& quadVertexRect) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 17 | : 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] | d0f9836 | 2012-11-01 23:02:38 | [diff] [blame] | 23 | float vertices[] = { quadVertexRect.x(), quadVertexRect.bottom(), 0.0f, 0.0f, 1.0f, |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 24 | quadVertexRect.x(), quadVertexRect.y(), 0.0f, 0.0f, 0.0f, |
[email protected] | d0f9836 | 2012-11-01 23:02:38 | [diff] [blame] | 25 | quadVertexRect.right(), quadVertexRect.y(), 0.0f, 1.0f, 0.0f, |
| 26 | quadVertexRect.right(), quadVertexRect.bottom(), 0.0f, 1.0f, 1.0f }; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 27 | 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] | d9c2852 | 2012-10-18 23:35:43 | [diff] [blame] | 32 | 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] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 36 | |
| 37 | m_initialized = true; |
| 38 | } |
| 39 | |
| 40 | GeometryBinding::~GeometryBinding() |
| 41 | { |
| 42 | GLC(m_context, m_context->deleteBuffer(m_quadVerticesVbo)); |
| 43 | GLC(m_context, m_context->deleteBuffer(m_quadElementsVbo)); |
| 44 | } |
| 45 | |
| 46 | void GeometryBinding::prepareForDraw() |
| 47 | { |
[email protected] | d9c2852 | 2012-10-18 23:35:43 | [diff] [blame] | 48 | GLC(m_context, m_context->bindBuffer(GL_ARRAY_BUFFER, quadVerticesVbo())); |
| 49 | GLC(m_context, m_context->bindBuffer(GL_ELEMENT_ARRAY_BUFFER, quadElementsVbo())); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 50 | unsigned offset = 0; |
[email protected] | d9c2852 | 2012-10-18 23:35:43 | [diff] [blame] | 51 | GLC(m_context, m_context->vertexAttribPointer(positionAttribLocation(), 3, GL_FLOAT, false, 5 * sizeof(float), offset)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 52 | offset += 3 * sizeof(float); |
[email protected] | d9c2852 | 2012-10-18 23:35:43 | [diff] [blame] | 53 | GLC(m_context, m_context->vertexAttribPointer(texCoordAttribLocation(), 2, GL_FLOAT, false, 5 * sizeof(float), offset)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 54 | GLC(m_context, m_context->enableVertexAttribArray(positionAttribLocation())); |
| 55 | GLC(m_context, m_context->enableVertexAttribArray(texCoordAttribLocation())); |
| 56 | } |
| 57 | |
[email protected] | bc5e77c | 2012-11-05 20:00:49 | [diff] [blame^] | 58 | } // namespace cc |