Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "cc/geometry_binding.h" | 5 #include "cc/geometry_binding.h" |
| 6 | 6 |
| 7 #include "cc/gl_renderer.h" // For the GLC() macro. | 7 #include "cc/gl_renderer.h" // For the GLC() macro. |
| 8 #include "third_party/khronos/GLES2/gl2.h" | 8 #include "third_party/khronos/GLES2/gl2.h" |
| 9 #include "ui/gfx/rect_f.h" | 9 #include "ui/gfx/rect_f.h" |
| 10 #include <public/WebGraphicsContext3D.h> | 10 #include <public/WebGraphicsContext3D.h> |
| 11 | 11 |
| 12 namespace cc { | 12 namespace cc { |
| 13 | 13 |
| 14 GeometryBinding::GeometryBinding(WebKit::WebGraphicsContext3D* context, const gf x::RectF& quadVertexRect) | 14 GeometryBinding::GeometryBinding(WebKit::WebGraphicsContext3D* context, const gf x::RectF& quadVertexRect) |
| 15 : m_context(context) | 15 : m_context(context) |
| 16 , m_quadVerticesVbo(0) | 16 , m_quadVerticesVbo(0) |
| 17 , m_quadElementsVbo(0) | 17 , m_quadElementsVbo(0) |
| 18 , m_initialized(false) | 18 , m_initialized(false) |
| 19 { | 19 { |
| 20 // Vertex positions and texture coordinates for the 4 corners of a 1x1 quad. | |
| 21 float vertices[] = { quadVertexRect.x(), quadVertexRect.bottom(), 0.0f, 0.0f , 1.0f, | 20 float vertices[] = { quadVertexRect.x(), quadVertexRect.bottom(), 0.0f, 0.0f , 1.0f, |
| 22 quadVertexRect.x(), quadVertexRect.y(), 0.0f, 0.0f, 0. 0f, | 21 quadVertexRect.x(), quadVertexRect.y(), 0.0f, 0.0f, 0. 0f, |
| 23 quadVertexRect.right(), quadVertexRect.y(), 0.0f, 1.0f, 0.0f, | 22 quadVertexRect.right(), quadVertexRect.y(), 0.0f, 1.0f, 0.0f, |
| 24 quadVertexRect.right(), quadVertexRect.bottom(), 0.0f, 1.0f, 1.0f }; | 23 quadVertexRect.right(), quadVertexRect.bottom(), 0.0f, 1.0f, 1.0f }; |
| 25 uint16_t indices[] = { 0, 1, 2, 0, 2, 3, // The two triangles that make up t he layer quad. | 24 |
| 26 0, 1, 2, 3}; // A line path for drawing the layer bor der. | 25 struct Vertex { |
| 26 float a_position[3]; | |
| 27 float a_texCoord[2]; | |
| 28 float a_index; // index into the matrix array for this quad | |
| 29 }; | |
| 30 struct Quad { Vertex v0, v1, v2, v3; }; | |
| 31 struct QuadIndex { uint16_t data[6]; }; | |
| 32 | |
| 33 COMPILE_ASSERT(sizeof(Quad) == 24 * sizeof(float)); | |
| 34 COMPILE_ASSERT(sizeof(QuadIndex) == 6 * sizeof(uint16_t)); | |
| 35 | |
| 36 Quad quad_list[8]; | |
| 37 QuadIndex quad_index_list[8]; | |
| 38 for (int i = 0; i < 8; i++) | |
| 39 { | |
|
jamesr
2012/11/30 00:31:21
{ belongs on previous line
| |
| 40 Vertex v0 = { quadVertexRect.x() , quadVertexRect.bottom(), 0.0f, 0. 0f, 1.0f, (float)i }; | |
| 41 Vertex v1 = { quadVertexRect.x() , quadVertexRect.y() , 0.0f, 0. 0f, 0.0f, (float)i }; | |
| 42 Vertex v2 = { quadVertexRect.right(), quadVertexRect.y() , 0.0f, 1. 0f, 0.0f, (float)i }; | |
| 43 Vertex v3 = { quadVertexRect.right(), quadVertexRect.bottom(), 0.0f, 1. 0f, 1.0f, (float)i }; | |
| 44 Quad x = { v0, v1, v2, v3 }; | |
| 45 quad_list[i] = x; | |
| 46 QuadIndex y = { 0 + 4 * i, 1 + 4 * i, 2 + 4 * i, 3 + 4 * i, 0 + 4 * i, 2 + 4 * i }; | |
| 47 quad_index_list[i] = y; | |
| 48 } | |
| 27 | 49 |
| 28 GLC(m_context, m_quadVerticesVbo = m_context->createBuffer()); | 50 GLC(m_context, m_quadVerticesVbo = m_context->createBuffer()); |
| 29 GLC(m_context, m_quadElementsVbo = m_context->createBuffer()); | 51 GLC(m_context, m_quadElementsVbo = m_context->createBuffer()); |
| 52 GLC(m_context, m_quadListVerticesVbo = m_context->createBuffer()); | |
| 30 GLC(m_context, m_context->bindBuffer(GL_ARRAY_BUFFER, m_quadVerticesVbo)); | 53 GLC(m_context, m_context->bindBuffer(GL_ARRAY_BUFFER, m_quadVerticesVbo)); |
| 31 GLC(m_context, m_context->bufferData(GL_ARRAY_BUFFER, sizeof(vertices), vert ices, GL_STATIC_DRAW)); | 54 GLC(m_context, m_context->bufferData(GL_ARRAY_BUFFER, sizeof(quad_list), qua d_list, GL_STATIC_DRAW)); |
| 32 GLC(m_context, m_context->bindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_quadElements Vbo)); | 55 GLC(m_context, m_context->bindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_quadElements Vbo)); |
| 33 GLC(m_context, m_context->bufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices ), indices, GL_STATIC_DRAW)); | 56 GLC(m_context, m_context->bufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(quad_in dex_list), quad_index_list, GL_STATIC_DRAW)); |
| 34 | 57 |
| 35 m_initialized = true; | 58 m_initialized = true; |
| 36 } | 59 } |
| 37 | 60 |
| 38 GeometryBinding::~GeometryBinding() | 61 GeometryBinding::~GeometryBinding() |
| 39 { | 62 { |
| 40 GLC(m_context, m_context->deleteBuffer(m_quadVerticesVbo)); | 63 GLC(m_context, m_context->deleteBuffer(m_quadVerticesVbo)); |
| 41 GLC(m_context, m_context->deleteBuffer(m_quadElementsVbo)); | 64 GLC(m_context, m_context->deleteBuffer(m_quadElementsVbo)); |
| 42 } | 65 } |
| 43 | 66 |
| 44 void GeometryBinding::prepareForDraw() | 67 void GeometryBinding::prepareForDraw() |
| 45 { | 68 { |
| 69 GLC(m_context, m_context->bindBuffer(GL_ELEMENT_ARRAY_BUFFER, quadElementsVb o())); | |
| 70 | |
| 46 GLC(m_context, m_context->bindBuffer(GL_ARRAY_BUFFER, quadVerticesVbo())); | 71 GLC(m_context, m_context->bindBuffer(GL_ARRAY_BUFFER, quadVerticesVbo())); |
| 47 GLC(m_context, m_context->bindBuffer(GL_ELEMENT_ARRAY_BUFFER, quadElementsVb o())); | 72 GLC(m_context, m_context->vertexAttribPointer(positionAttribLocation(), 3, G L_FLOAT, false, 6 * sizeof(float), 0)); |
| 48 unsigned offset = 0; | 73 GLC(m_context, m_context->vertexAttribPointer(texCoordAttribLocation(), 2, G L_FLOAT, false, 6 * sizeof(float), 3 * sizeof(float))); |
| 49 GLC(m_context, m_context->vertexAttribPointer(positionAttribLocation(), 3, G L_FLOAT, false, 5 * sizeof(float), offset)); | 74 GLC(m_context, m_context->vertexAttribPointer(triangleIndexAttribLocation(), 1, GL_FLOAT, false, 6 * sizeof(float), 5 * sizeof(float))); |
| 50 offset += 3 * sizeof(float); | |
| 51 GLC(m_context, m_context->vertexAttribPointer(texCoordAttribLocation(), 2, G L_FLOAT, false, 5 * sizeof(float), offset)); | |
| 52 GLC(m_context, m_context->enableVertexAttribArray(positionAttribLocation())) ; | 75 GLC(m_context, m_context->enableVertexAttribArray(positionAttribLocation())) ; |
| 53 GLC(m_context, m_context->enableVertexAttribArray(texCoordAttribLocation())) ; | 76 GLC(m_context, m_context->enableVertexAttribArray(texCoordAttribLocation())) ; |
| 77 GLC(m_context, m_context->enableVertexAttribArray(triangleIndexAttribLocatio n())); | |
| 54 } | 78 } |
| 55 | 79 |
| 56 } // namespace cc | 80 } // namespace cc |
| OLD | NEW |