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. | 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, | 21 float vertices[] = { quadVertexRect.x(), quadVertexRect.bottom(), 0.0f, 0.0f , 1.0f, |
| 22 quadVertexRect.x(), quadVertexRect.y(), 0.0f, 0.0f, 0. 0f, | 22 quadVertexRect.x(), quadVertexRect.y(), 0.0f, 0.0f, 0. 0f, |
| 23 quadVertexRect.right(), quadVertexRect.y(), 0.0f, 1.0f, 0.0f, | 23 quadVertexRect.right(), quadVertexRect.y(), 0.0f, 1.0f, 0.0f, |
| 24 quadVertexRect.right(), quadVertexRect.bottom(), 0.0f, 1.0f, 1.0f }; | 24 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. | 25 |
| 26 0, 1, 2, 3}; // A line path for drawing the layer bor der. | 26 // Vertex positions, texture coordinates and skinning values for the 4 corne rs of 8 1x1 quads. |
|
shawnsingh
2012/11/28 19:44:16
I think the word skinning might confuse/complicate
whunt
2012/11/28 22:01:15
Done, I made the language more uniform and avoided
| |
| 27 float vertexListData[] = { | |
|
shawnsingh
2012/11/28 19:44:16
If possible, we should make this an array of struc
whunt
2012/11/28 22:01:15
Done.
On 2012/11/28 19:44:16, shawnsingh wrote:
| |
| 28 -0.5f, 0.5f, 0.0f, 0.0f, 1.0f, 0.0f, | |
| 29 -0.5f, -0.5f, 0.0f, 0.0f, 0.0f, 0.0f, | |
| 30 0.5f, -0.5f, 0.0f, 1.0f, 0.0f, 0.0f, | |
| 31 0.5f, 0.5f, 0.0f, 1.0f, 1.0f, 0.0f, | |
| 32 -0.5f, 0.5f, 0.0f, 0.0f, 1.0f, 1.0f, | |
|
jamesr
2012/11/28 00:00:37
Can we generate this data with a loop instead of l
whunt
2012/11/28 22:01:15
Sure, Done.
On 2012/11/28 00:00:37, jamesr wrote:
| |
| 33 -0.5f, -0.5f, 0.0f, 0.0f, 0.0f, 1.0f, | |
| 34 0.5f, -0.5f, 0.0f, 1.0f, 0.0f, 1.0f, | |
| 35 0.5f, 0.5f, 0.0f, 1.0f, 1.0f, 1.0f, | |
| 36 -0.5f, 0.5f, 0.0f, 0.0f, 1.0f, 2.0f, | |
| 37 -0.5f, -0.5f, 0.0f, 0.0f, 0.0f, 2.0f, | |
| 38 0.5f, -0.5f, 0.0f, 1.0f, 0.0f, 2.0f, | |
| 39 0.5f, 0.5f, 0.0f, 1.0f, 1.0f, 2.0f, | |
| 40 -0.5f, 0.5f, 0.0f, 0.0f, 1.0f, 3.0f, | |
| 41 -0.5f, -0.5f, 0.0f, 0.0f, 0.0f, 3.0f, | |
| 42 0.5f, -0.5f, 0.0f, 1.0f, 0.0f, 3.0f, | |
| 43 0.5f, 0.5f, 0.0f, 1.0f, 1.0f, 3.0f, | |
| 44 -0.5f, 0.5f, 0.0f, 0.0f, 1.0f, 4.0f, | |
| 45 -0.5f, -0.5f, 0.0f, 0.0f, 0.0f, 4.0f, | |
| 46 0.5f, -0.5f, 0.0f, 1.0f, 0.0f, 4.0f, | |
| 47 0.5f, 0.5f, 0.0f, 1.0f, 1.0f, 4.0f, | |
| 48 -0.5f, 0.5f, 0.0f, 0.0f, 1.0f, 5.0f, | |
| 49 -0.5f, -0.5f, 0.0f, 0.0f, 0.0f, 5.0f, | |
| 50 0.5f, -0.5f, 0.0f, 1.0f, 0.0f, 5.0f, | |
| 51 0.5f, 0.5f, 0.0f, 1.0f, 1.0f, 5.0f, | |
| 52 -0.5f, 0.5f, 0.0f, 0.0f, 1.0f, 6.0f, | |
| 53 -0.5f, -0.5f, 0.0f, 0.0f, 0.0f, 6.0f, | |
| 54 0.5f, -0.5f, 0.0f, 1.0f, 0.0f, 6.0f, | |
| 55 0.5f, 0.5f, 0.0f, 1.0f, 1.0f, 6.0f, | |
| 56 -0.5f, 0.5f, 0.0f, 0.0f, 1.0f, 7.0f, | |
| 57 -0.5f, -0.5f, 0.0f, 0.0f, 0.0f, 7.0f, | |
| 58 0.5f, -0.5f, 0.0f, 1.0f, 0.0f, 7.0f, | |
| 59 0.5f, 0.5f, 0.0f, 1.0f, 1.0f, 7.0f, | |
| 60 }; | |
| 61 | |
| 62 // Index buffer for up to 8 quads. | |
| 63 uint16_t indices[] = { | |
| 64 0, 1, 2, | |
| 65 3, 0, 2, | |
| 66 4, 5, 6, | |
|
jamesr
2012/11/28 00:00:37
Same here - each 6-tuple is just the previous one
whunt
2012/11/28 22:01:15
Yes, but this one is slightly more subtle. You pr
| |
| 67 4, 6, 7, | |
| 68 8, 9, 10, | |
| 69 8, 10, 11, | |
| 70 12, 13, 14, | |
| 71 12, 14, 15, | |
| 72 16, 17, 18, | |
| 73 16, 18, 19, | |
| 74 20, 21, 22, | |
| 75 20, 22, 23, | |
| 76 24, 25, 26, | |
| 77 24, 26, 27, | |
| 78 28, 29, 30, | |
| 79 28, 30, 31, | |
| 80 }; | |
| 27 | 81 |
| 28 GLC(m_context, m_quadVerticesVbo = m_context->createBuffer()); | 82 GLC(m_context, m_quadVerticesVbo = m_context->createBuffer()); |
| 29 GLC(m_context, m_quadElementsVbo = m_context->createBuffer()); | 83 GLC(m_context, m_quadElementsVbo = m_context->createBuffer()); |
| 84 GLC(m_context, m_quadListVerticesVbo = m_context->createBuffer()); | |
| 30 GLC(m_context, m_context->bindBuffer(GL_ARRAY_BUFFER, m_quadVerticesVbo)); | 85 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)); | 86 GLC(m_context, m_context->bufferData(GL_ARRAY_BUFFER, sizeof(vertexListData) , vertexListData, GL_STATIC_DRAW)); |
| 32 GLC(m_context, m_context->bindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_quadElements Vbo)); | 87 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)); | 88 GLC(m_context, m_context->bufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices ), indices, GL_STATIC_DRAW)); |
| 34 | 89 |
| 35 m_initialized = true; | 90 m_initialized = true; |
| 36 } | 91 } |
| 37 | 92 |
| 38 GeometryBinding::~GeometryBinding() | 93 GeometryBinding::~GeometryBinding() |
| 39 { | 94 { |
| 40 GLC(m_context, m_context->deleteBuffer(m_quadVerticesVbo)); | 95 GLC(m_context, m_context->deleteBuffer(m_quadVerticesVbo)); |
| 41 GLC(m_context, m_context->deleteBuffer(m_quadElementsVbo)); | 96 GLC(m_context, m_context->deleteBuffer(m_quadElementsVbo)); |
| 42 } | 97 } |
| 43 | 98 |
| 44 void GeometryBinding::prepareForDraw() | 99 void GeometryBinding::prepareForDraw() |
| 45 { | 100 { |
| 101 GLC(m_context, m_context->bindBuffer(GL_ELEMENT_ARRAY_BUFFER, quadElementsVb o())); | |
| 102 | |
| 46 GLC(m_context, m_context->bindBuffer(GL_ARRAY_BUFFER, quadVerticesVbo())); | 103 GLC(m_context, m_context->bindBuffer(GL_ARRAY_BUFFER, quadVerticesVbo())); |
| 47 GLC(m_context, m_context->bindBuffer(GL_ELEMENT_ARRAY_BUFFER, quadElementsVb o())); | 104 GLC(m_context, m_context->vertexAttribPointer(positionAttribLocation(), 3, G L_FLOAT, false, 6 * sizeof(float), 0)); |
| 48 unsigned offset = 0; | 105 GLC(m_context, m_context->vertexAttribPointer(texCoordAttribLocation(), 2, G L_FLOAT, false, 6 * sizeof(float), 12)); |
|
shawnsingh
2012/11/28 19:44:16
This "12" should probably remain 3 * sizeof(float)
| |
| 49 GLC(m_context, m_context->vertexAttribPointer(positionAttribLocation(), 3, G L_FLOAT, false, 5 * sizeof(float), offset)); | 106 GLC(m_context, m_context->vertexAttribPointer(triangleIndexAttribLocation(), 1, GL_FLOAT, false, 6 * sizeof(float), 20)); |
|
shawnsingh
2012/11/28 19:44:16
And this "20" should probably remain 5 * sizeof(fl
| |
| 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())) ; | 107 GLC(m_context, m_context->enableVertexAttribArray(positionAttribLocation())) ; |
| 53 GLC(m_context, m_context->enableVertexAttribArray(texCoordAttribLocation())) ; | 108 GLC(m_context, m_context->enableVertexAttribArray(texCoordAttribLocation())) ; |
| 109 GLC(m_context, m_context->enableVertexAttribArray(triangleIndexAttribLocatio n())); | |
| 54 } | 110 } |
| 55 | 111 |
| 56 } // namespace cc | 112 } // namespace cc |
| OLD | NEW |