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 "third_party/WebKit/Source/Platform/chromium/public/WebGraphicsContext3
D.h" | 8 #include "third_party/WebKit/Source/Platform/chromium/public/WebGraphicsContext3
D.h" |
9 #include "third_party/khronos/GLES2/gl2.h" | 9 #include "third_party/khronos/GLES2/gl2.h" |
10 #include "ui/gfx/rect_f.h" | 10 #include "ui/gfx/rect_f.h" |
11 | 11 |
12 namespace cc { | 12 namespace cc { |
13 | 13 |
14 GeometryBinding::GeometryBinding(WebKit::WebGraphicsContext3D* context, | 14 GeometryBinding::GeometryBinding(WebKit::WebGraphicsContext3D* context, |
15 const gfx::RectF& quad_vertex_rect) | 15 const gfx::RectF& quad_vertex_rect) |
16 : context_(context), | 16 : context_(context), |
17 quad_vertices_vbo_(0), | 17 quad_vertices_vbo_(0), |
18 quad_elements_vbo_(0) { | 18 quad_elements_vbo_(0) { |
19 float vertices[] = { | |
20 quad_vertex_rect.x(), quad_vertex_rect.bottom(), 0.0f, 0.0f, | |
21 1.0f, quad_vertex_rect.x(), quad_vertex_rect.y(), 0.0f, | |
22 0.0f, 0.0f, quad_vertex_rect.right(), quad_vertex_rect.y(), | |
23 0.0f, 1.0f, 0.0f, quad_vertex_rect.right(), | |
24 quad_vertex_rect.bottom(), 0.0f, 1.0f, 1.0f | |
25 }; | |
26 | |
27 struct Vertex { | 19 struct Vertex { |
28 float a_position[3]; | 20 float a_position[3]; |
29 float a_texCoord[2]; | 21 float a_texCoord[2]; |
30 // Index of the vertex, divide by 4 to have the matrix for this quad. | 22 // Index of the vertex, divide by 4 to have the matrix for this quad. |
31 float a_index; | 23 float a_index; |
32 }; | 24 }; |
33 struct Quad { | 25 struct Quad { |
34 Vertex v0, v1, v2, v3; | 26 Vertex v0, v1, v2, v3; |
35 }; | 27 }; |
36 struct QuadIndex { | 28 struct QuadIndex { |
37 uint16_t data[6]; | 29 uint16_t data[6]; |
38 }; | 30 }; |
39 | 31 |
40 COMPILE_ASSERT( | 32 COMPILE_ASSERT( |
41 sizeof(Quad) == 24 * sizeof(float), // NOLINT(runtime/sizeof) | 33 sizeof(Quad) == 24 * sizeof(float), // NOLINT(runtime/sizeof) |
42 struct_is_densely_packed); | 34 struct_is_densely_packed); |
43 COMPILE_ASSERT( | 35 COMPILE_ASSERT( |
44 sizeof(QuadIndex) == 6 * sizeof(uint16_t), // NOLINT(runtime/sizeof) | 36 sizeof(QuadIndex) == 6 * sizeof(uint16_t), // NOLINT(runtime/sizeof) |
45 struct_is_densely_packed); | 37 struct_is_densely_packed); |
46 | 38 |
47 Quad quad_list[8]; | 39 Quad quad_list[8]; |
48 QuadIndex quad_index_list[8]; | 40 QuadIndex quad_index_list[8]; |
49 for (int i = 0; i < 8; i++) { | 41 for (int i = 0; i < 8; i++) { |
50 Vertex v0 = { quad_vertex_rect.x(), quad_vertex_rect.bottom(), 0.0f, 0.0f, | 42 Vertex v0 = { { quad_vertex_rect.x(), quad_vertex_rect.bottom(), 0.0f, }, |
51 1.0f, i * 4.0f + 0.0f }; | 43 { 0.0f, 1.0f, }, |
52 Vertex v1 = { quad_vertex_rect.x(), quad_vertex_rect.y(), 0.0f, 0.0f, 0.0f, | 44 i * 4.0f + 0.0f }; |
| 45 Vertex v1 = { { quad_vertex_rect.x(), quad_vertex_rect.y(), 0.0f, }, |
| 46 { 0.0f, 0.0f, }, |
53 i * 4.0f + 1.0f }; | 47 i * 4.0f + 1.0f }; |
54 Vertex v2 = { quad_vertex_rect.right(), quad_vertex_rect.y(), 0.0f, 1.0f, | 48 Vertex v2 = { { quad_vertex_rect.right(), quad_vertex_rect.y(), 0.0f, }, |
55 0.0f, i * 4.0f + 2.0f }; | 49 { 1.0f, .0f, }, |
56 Vertex v3 = { quad_vertex_rect.right(), quad_vertex_rect.bottom(), 0.0f, | 50 i * 4.0f + 2.0f }; |
57 1.0f, 1.0f, i * 4.0f + 3.0f }; | 51 Vertex v3 = { { quad_vertex_rect.right(), |
| 52 quad_vertex_rect.bottom(), |
| 53 0.0f, }, |
| 54 { 1.0f, 1.0f, }, |
| 55 i * 4.0f + 3.0f }; |
58 Quad x = { v0, v1, v2, v3 }; | 56 Quad x = { v0, v1, v2, v3 }; |
59 quad_list[i] = x; | 57 quad_list[i] = x; |
60 QuadIndex y = { 0 + 4 * i, 1 + 4 * i, 2 + 4 * i, 3 + 4 * i, 0 + 4 * i, | 58 QuadIndex y = { { 0 + 4 * i, |
61 2 + 4 * i }; | 59 1 + 4 * i, |
| 60 2 + 4 * i, |
| 61 3 + 4 * i, |
| 62 0 + 4 * i, |
| 63 2 + 4 * i } }; |
62 quad_index_list[i] = y; | 64 quad_index_list[i] = y; |
63 } | 65 } |
64 | 66 |
65 GLC(context_, quad_vertices_vbo_ = context_->createBuffer()); | 67 GLC(context_, quad_vertices_vbo_ = context_->createBuffer()); |
66 GLC(context_, quad_elements_vbo_ = context_->createBuffer()); | 68 GLC(context_, quad_elements_vbo_ = context_->createBuffer()); |
67 GLC(context_, context_->bindBuffer(GL_ARRAY_BUFFER, quad_vertices_vbo_)); | 69 GLC(context_, context_->bindBuffer(GL_ARRAY_BUFFER, quad_vertices_vbo_)); |
68 GLC(context_, | 70 GLC(context_, |
69 context_->bufferData( | 71 context_->bufferData( |
70 GL_ARRAY_BUFFER, sizeof(quad_list), quad_list, GL_STATIC_DRAW)); | 72 GL_ARRAY_BUFFER, sizeof(quad_list), quad_list, GL_STATIC_DRAW)); |
71 GLC(context_, | 73 GLC(context_, |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 false, | 113 false, |
112 6 * sizeof(float), // NOLINT(runtime/sizeof) | 114 6 * sizeof(float), // NOLINT(runtime/sizeof) |
113 5 * sizeof(float))); // NOLINT(runtime/sizeof) | 115 5 * sizeof(float))); // NOLINT(runtime/sizeof) |
114 GLC(context_, context_->enableVertexAttribArray(PositionAttribLocation())); | 116 GLC(context_, context_->enableVertexAttribArray(PositionAttribLocation())); |
115 GLC(context_, context_->enableVertexAttribArray(TexCoordAttribLocation())); | 117 GLC(context_, context_->enableVertexAttribArray(TexCoordAttribLocation())); |
116 GLC(context_, | 118 GLC(context_, |
117 context_->enableVertexAttribArray(TriangleIndexAttribLocation())); | 119 context_->enableVertexAttribArray(TriangleIndexAttribLocation())); |
118 } | 120 } |
119 | 121 |
120 } // namespace cc | 122 } // namespace cc |
OLD | NEW |