| 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(sizeof(Quad) == 24 * sizeof(float), struct_is_densely_packed); | 32 COMPILE_ASSERT(sizeof(Quad) == 24 * sizeof(float), struct_is_densely_packed); |
| 41 COMPILE_ASSERT(sizeof(QuadIndex) == 6 * sizeof(uint16_t), | 33 COMPILE_ASSERT(sizeof(QuadIndex) == 6 * sizeof(uint16_t), |
| 42 struct_is_densely_packed); | 34 struct_is_densely_packed); |
| 43 | 35 |
| 44 Quad quad_list[8]; | 36 Quad quad_list[8]; |
| 45 QuadIndex quad_index_list[8]; | 37 QuadIndex quad_index_list[8]; |
| 46 for (int i = 0; i < 8; i++) { | 38 for (int i = 0; i < 8; i++) { |
| 47 Vertex v0 = { quad_vertex_rect.x(), quad_vertex_rect.bottom(), 0.0f, 0.0f, | 39 Vertex v0 = { { quad_vertex_rect.x(), quad_vertex_rect.bottom(), 0.0f, }, |
| 48 1.0f, i * 4.0f + 0.0f }; | 40 { 0.0f, 1.0f, }, |
| 49 Vertex v1 = { quad_vertex_rect.x(), quad_vertex_rect.y(), 0.0f, 0.0f, 0.0f, | 41 i * 4.0f + 0.0f }; |
| 42 Vertex v1 = { { quad_vertex_rect.x(), quad_vertex_rect.y(), 0.0f, }, |
| 43 { 0.0f, 0.0f, }, |
| 50 i * 4.0f + 1.0f }; | 44 i * 4.0f + 1.0f }; |
| 51 Vertex v2 = { quad_vertex_rect.right(), quad_vertex_rect.y(), 0.0f, 1.0f, | 45 Vertex v2 = { { quad_vertex_rect.right(), quad_vertex_rect.y(), 0.0f, }, |
| 52 0.0f, i * 4.0f + 2.0f }; | 46 { 1.0f, .0f, }, |
| 53 Vertex v3 = { quad_vertex_rect.right(), quad_vertex_rect.bottom(), 0.0f, | 47 i * 4.0f + 2.0f }; |
| 54 1.0f, 1.0f, i * 4.0f + 3.0f }; | 48 Vertex v3 = { { quad_vertex_rect.right(), |
| 49 quad_vertex_rect.bottom(), |
| 50 0.0f, }, |
| 51 { 1.0f, 1.0f, }, |
| 52 i * 4.0f + 3.0f }; |
| 55 Quad x = { v0, v1, v2, v3 }; | 53 Quad x = { v0, v1, v2, v3 }; |
| 56 quad_list[i] = x; | 54 quad_list[i] = x; |
| 57 QuadIndex y = { 0 + 4 * i, 1 + 4 * i, 2 + 4 * i, 3 + 4 * i, 0 + 4 * i, | 55 QuadIndex y = { { 0 + 4 * i, |
| 58 2 + 4 * i }; | 56 1 + 4 * i, |
| 57 2 + 4 * i, |
| 58 3 + 4 * i, |
| 59 0 + 4 * i, |
| 60 2 + 4 * i } }; |
| 59 quad_index_list[i] = y; | 61 quad_index_list[i] = y; |
| 60 } | 62 } |
| 61 | 63 |
| 62 GLC(context_, quad_vertices_vbo_ = context_->createBuffer()); | 64 GLC(context_, quad_vertices_vbo_ = context_->createBuffer()); |
| 63 GLC(context_, quad_elements_vbo_ = context_->createBuffer()); | 65 GLC(context_, quad_elements_vbo_ = context_->createBuffer()); |
| 64 GLC(context_, context_->bindBuffer(GL_ARRAY_BUFFER, quad_vertices_vbo_)); | 66 GLC(context_, context_->bindBuffer(GL_ARRAY_BUFFER, quad_vertices_vbo_)); |
| 65 GLC(context_, | 67 GLC(context_, |
| 66 context_->bufferData( | 68 context_->bufferData( |
| 67 GL_ARRAY_BUFFER, sizeof(quad_list), quad_list, GL_STATIC_DRAW)); | 69 GL_ARRAY_BUFFER, sizeof(quad_list), quad_list, GL_STATIC_DRAW)); |
| 68 GLC(context_, | 70 GLC(context_, |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 false, | 103 false, |
| 102 6 * sizeof(float), | 104 6 * sizeof(float), |
| 103 5 * sizeof(float))); | 105 5 * sizeof(float))); |
| 104 GLC(context_, context_->enableVertexAttribArray(PositionAttribLocation())); | 106 GLC(context_, context_->enableVertexAttribArray(PositionAttribLocation())); |
| 105 GLC(context_, context_->enableVertexAttribArray(TexCoordAttribLocation())); | 107 GLC(context_, context_->enableVertexAttribArray(TexCoordAttribLocation())); |
| 106 GLC(context_, | 108 GLC(context_, |
| 107 context_->enableVertexAttribArray(TriangleIndexAttribLocation())); | 109 context_->enableVertexAttribArray(TriangleIndexAttribLocation())); |
| 108 } | 110 } |
| 109 | 111 |
| 110 } // namespace cc | 112 } // namespace cc |
| OLD | NEW |