OLD | NEW |
| (Empty) |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "cc/output/static_geometry_binding.h" | |
6 | |
7 #include "cc/output/gl_renderer.h" // For the GLC() macro. | |
8 #include "gpu/command_buffer/client/gles2_interface.h" | |
9 #include "ui/gfx/geometry/rect_f.h" | |
10 | |
11 namespace cc { | |
12 | |
13 StaticGeometryBinding::StaticGeometryBinding(gpu::gles2::GLES2Interface* gl, | |
14 const gfx::RectF& quad_vertex_rect) | |
15 : gl_(gl), quad_vertices_vbo_(0), quad_elements_vbo_(0) { | |
16 GeometryBindingQuad quads[8]; | |
17 GeometryBindingQuadIndex quad_indices[8]; | |
18 | |
19 static_assert(sizeof(GeometryBindingQuad) == 24 * sizeof(float), | |
20 "struct Quad should be densely packed"); | |
21 static_assert(sizeof(GeometryBindingQuadIndex) == 6 * sizeof(uint16_t), | |
22 "struct QuadIndex should be densely packed"); | |
23 | |
24 for (size_t i = 0; i < 8; i++) { | |
25 GeometryBindingVertex v0 = { | |
26 {quad_vertex_rect.x(), quad_vertex_rect.bottom(), 0.0f}, | |
27 {0.0f, 1.0f}, | |
28 i * 4.0f + 0.0f}; | |
29 GeometryBindingVertex v1 = { | |
30 {quad_vertex_rect.x(), quad_vertex_rect.y(), 0.0f}, | |
31 {0.0f, 0.0f}, | |
32 i * 4.0f + 1.0f}; | |
33 GeometryBindingVertex v2 = { | |
34 {quad_vertex_rect.right(), quad_vertex_rect.y(), 0.0f}, | |
35 {1.0f, 0.0f}, | |
36 i * 4.0f + 2.0f}; | |
37 GeometryBindingVertex v3 = { | |
38 {quad_vertex_rect.right(), quad_vertex_rect.bottom(), 0.0f}, | |
39 {1.0f, 1.0f}, | |
40 i * 4.0f + 3.0f}; | |
41 GeometryBindingQuad x(v0, v1, v2, v3); | |
42 quads[i] = x; | |
43 GeometryBindingQuadIndex y( | |
44 static_cast<uint16>(0 + 4 * i), static_cast<uint16>(1 + 4 * i), | |
45 static_cast<uint16>(2 + 4 * i), static_cast<uint16>(3 + 4 * i), | |
46 static_cast<uint16>(0 + 4 * i), static_cast<uint16>(2 + 4 * i)); | |
47 quad_indices[i] = y; | |
48 } | |
49 | |
50 GLC(gl_, gl_->GenBuffers(1, &quad_vertices_vbo_)); | |
51 GLC(gl_, gl_->GenBuffers(1, &quad_elements_vbo_)); | |
52 | |
53 GLC(gl_, gl_->BindBuffer(GL_ARRAY_BUFFER, quad_vertices_vbo_)); | |
54 GLC(gl_, gl_->BufferData(GL_ARRAY_BUFFER, sizeof(GeometryBindingQuad) * 8, | |
55 quads, GL_STATIC_DRAW)); | |
56 | |
57 GLC(gl_, gl_->BindBuffer(GL_ELEMENT_ARRAY_BUFFER, quad_elements_vbo_)); | |
58 GLC(gl_, gl_->BufferData(GL_ELEMENT_ARRAY_BUFFER, | |
59 sizeof(GeometryBindingQuadIndex) * 8, &quad_indices, | |
60 GL_STATIC_DRAW)); | |
61 } | |
62 | |
63 StaticGeometryBinding::~StaticGeometryBinding() { | |
64 gl_->DeleteBuffers(1, &quad_vertices_vbo_); | |
65 gl_->DeleteBuffers(1, &quad_elements_vbo_); | |
66 } | |
67 | |
68 void StaticGeometryBinding::PrepareForDraw() { | |
69 SetupGLContext(gl_, quad_elements_vbo_, quad_vertices_vbo_); | |
70 } | |
71 | |
72 } // namespace cc | |
OLD | NEW |