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/output/geometry_binding.h" | 5 #include "cc/output/geometry_binding.h" |
6 | 6 |
7 #include "cc/output/gl_renderer.h" // For the GLC() macro. | 7 #include "cc/output/gl_renderer.h" // For the GLC() macro. |
8 #include "gpu/command_buffer/client/gles2_interface.h" | 8 #include "gpu/command_buffer/client/gles2_interface.h" |
9 #include "ui/gfx/geometry/rect_f.h" | 9 #include "ui/gfx/geometry/rect_f.h" |
10 | 10 |
11 namespace cc { | 11 namespace cc { |
12 | 12 |
13 GeometryBinding::GeometryBinding(gpu::gles2::GLES2Interface* gl, | 13 GeometryBinding::GeometryBinding(gpu::gles2::GLES2Interface* gl, |
14 const gfx::RectF& quad_vertex_rect) | 14 const gfx::RectF& quad_vertex_rect) |
15 : gl_(gl), quad_vertices_vbo_(0), quad_elements_vbo_(0) { | 15 : gl_(gl), quad_vertices_vbo_(0), quad_elements_vbo_(0) { |
16 struct Vertex { | 16 struct Vertex { |
17 float a_position[3]; | 17 float a_position[3]; |
18 float a_texCoord[2]; | 18 float a_texCoord[2]; |
19 // Index of the vertex, divide by 4 to have the matrix for this quad. | 19 // Index of the vertex, divide by 4 to have the matrix for this quad. |
20 float a_index; | 20 float a_index; |
21 }; | 21 }; |
22 struct Quad { | 22 struct Quad { |
23 Vertex v0, v1, v2, v3; | 23 Vertex v0, v1, v2, v3; |
24 }; | 24 }; |
25 struct QuadIndex { | 25 struct QuadIndex { |
26 uint16 data[6]; | 26 uint16 data[6]; |
27 }; | 27 }; |
28 | 28 |
29 COMPILE_ASSERT(sizeof(Quad) == 24 * sizeof(float), // NOLINT(runtime/sizeof) | 29 COMPILE_ASSERT(sizeof(Quad) == 24 * sizeof(float), struct_is_densely_packed); |
| 30 COMPILE_ASSERT(sizeof(QuadIndex) == 6 * sizeof(uint16_t), |
30 struct_is_densely_packed); | 31 struct_is_densely_packed); |
31 COMPILE_ASSERT( | |
32 sizeof(QuadIndex) == 6 * sizeof(uint16_t), // NOLINT(runtime/sizeof) | |
33 struct_is_densely_packed); | |
34 | 32 |
35 Quad quad_list[8]; | 33 Quad quad_list[8]; |
36 QuadIndex quad_index_list[8]; | 34 QuadIndex quad_index_list[8]; |
37 for (int i = 0; i < 8; i++) { | 35 for (int i = 0; i < 8; i++) { |
38 Vertex v0 = {{quad_vertex_rect.x(), quad_vertex_rect.bottom(), 0.0f, }, | 36 Vertex v0 = {{quad_vertex_rect.x(), quad_vertex_rect.bottom(), 0.0f, }, |
39 {0.0f, 1.0f, }, i * 4.0f + 0.0f}; | 37 {0.0f, 1.0f, }, i * 4.0f + 0.0f}; |
40 Vertex v1 = {{quad_vertex_rect.x(), quad_vertex_rect.y(), 0.0f, }, | 38 Vertex v1 = {{quad_vertex_rect.x(), quad_vertex_rect.y(), 0.0f, }, |
41 {0.0f, 0.0f, }, i * 4.0f + 1.0f}; | 39 {0.0f, 0.0f, }, i * 4.0f + 1.0f}; |
42 Vertex v2 = {{quad_vertex_rect.right(), quad_vertex_rect.y(), 0.0f, }, | 40 Vertex v2 = {{quad_vertex_rect.right(), quad_vertex_rect.y(), 0.0f, }, |
43 {1.0f, .0f, }, i * 4.0f + 2.0f}; | 41 {1.0f, .0f, }, i * 4.0f + 2.0f}; |
(...skipping 28 matching lines...) Expand all Loading... |
72 } | 70 } |
73 | 71 |
74 void GeometryBinding::PrepareForDraw() { | 72 void GeometryBinding::PrepareForDraw() { |
75 GLC(gl_, gl_->BindBuffer(GL_ELEMENT_ARRAY_BUFFER, quad_elements_vbo_)); | 73 GLC(gl_, gl_->BindBuffer(GL_ELEMENT_ARRAY_BUFFER, quad_elements_vbo_)); |
76 | 74 |
77 GLC(gl_, gl_->BindBuffer(GL_ARRAY_BUFFER, quad_vertices_vbo_)); | 75 GLC(gl_, gl_->BindBuffer(GL_ARRAY_BUFFER, quad_vertices_vbo_)); |
78 // OpenGL defines the last parameter to VertexAttribPointer as type | 76 // OpenGL defines the last parameter to VertexAttribPointer as type |
79 // "const GLvoid*" even though it is actually an offset into the buffer | 77 // "const GLvoid*" even though it is actually an offset into the buffer |
80 // object's data store and not a pointer to the client's address space. | 78 // object's data store and not a pointer to the client's address space. |
81 const void* offsets[3] = { | 79 const void* offsets[3] = { |
82 0, reinterpret_cast<const void*>( | 80 0, |
83 3 * sizeof(float)), // NOLINT(runtime/sizeof) | 81 reinterpret_cast<const void*>(3 * sizeof(float)), |
84 reinterpret_cast<const void*>(5 * | 82 reinterpret_cast<const void*>(5 * sizeof(float)), |
85 sizeof(float)), // NOLINT(runtime/sizeof) | |
86 }; | 83 }; |
87 | 84 |
88 GLC(gl_, | 85 GLC(gl_, gl_->VertexAttribPointer(PositionAttribLocation(), 3, GL_FLOAT, |
89 gl_->VertexAttribPointer(PositionAttribLocation(), | 86 false, 6 * sizeof(float), offsets[0])); |
90 3, | 87 GLC(gl_, gl_->VertexAttribPointer(TexCoordAttribLocation(), 2, GL_FLOAT, |
91 GL_FLOAT, | 88 false, 6 * sizeof(float), offsets[1])); |
92 false, | 89 GLC(gl_, gl_->VertexAttribPointer(TriangleIndexAttribLocation(), 1, GL_FLOAT, |
93 6 * sizeof(float), // NOLINT(runtime/sizeof) | 90 false, 6 * sizeof(float), offsets[2])); |
94 offsets[0])); | |
95 GLC(gl_, | |
96 gl_->VertexAttribPointer(TexCoordAttribLocation(), | |
97 2, | |
98 GL_FLOAT, | |
99 false, | |
100 6 * sizeof(float), // NOLINT(runtime/sizeof) | |
101 offsets[1])); | |
102 GLC(gl_, | |
103 gl_->VertexAttribPointer(TriangleIndexAttribLocation(), | |
104 1, | |
105 GL_FLOAT, | |
106 false, | |
107 6 * sizeof(float), // NOLINT(runtime/sizeof) | |
108 offsets[2])); | |
109 GLC(gl_, gl_->EnableVertexAttribArray(PositionAttribLocation())); | 91 GLC(gl_, gl_->EnableVertexAttribArray(PositionAttribLocation())); |
110 GLC(gl_, gl_->EnableVertexAttribArray(TexCoordAttribLocation())); | 92 GLC(gl_, gl_->EnableVertexAttribArray(TexCoordAttribLocation())); |
111 GLC(gl_, gl_->EnableVertexAttribArray(TriangleIndexAttribLocation())); | 93 GLC(gl_, gl_->EnableVertexAttribArray(TriangleIndexAttribLocation())); |
112 } | 94 } |
113 | 95 |
114 } // namespace cc | 96 } // namespace cc |
OLD | NEW |