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