| 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 = {{static_cast<uint16>(0 + 4 * i), | |
| 44 static_cast<uint16>(1 + 4 * i), | |
| 45 static_cast<uint16>(2 + 4 * i), | |
| 46 static_cast<uint16>(3 + 4 * i), | |
| 47 static_cast<uint16>(0 + 4 * i), | |
| 48 static_cast<uint16>(2 + 4 * i)}}; | |
| 49 quad_indices[i] = y; | |
| 50 } | |
| 51 | |
| 52 GLC(gl_, gl_->GenBuffers(1, &quad_vertices_vbo_)); | |
| 53 GLC(gl_, gl_->GenBuffers(1, &quad_elements_vbo_)); | |
| 54 | |
| 55 GLC(gl_, gl_->BindBuffer(GL_ARRAY_BUFFER, quad_vertices_vbo_)); | |
| 56 GLC(gl_, gl_->BufferData(GL_ARRAY_BUFFER, sizeof(GeometryBindingQuad) * 8, | |
| 57 quads, GL_STATIC_DRAW)); | |
| 58 | |
| 59 GLC(gl_, gl_->BindBuffer(GL_ELEMENT_ARRAY_BUFFER, quad_elements_vbo_)); | |
| 60 GLC(gl_, gl_->BufferData(GL_ELEMENT_ARRAY_BUFFER, | |
| 61 sizeof(GeometryBindingQuadIndex) * 8, &quad_indices, | |
| 62 GL_STATIC_DRAW)); | |
| 63 } | |
| 64 | |
| 65 StaticGeometryBinding::~StaticGeometryBinding() { | |
| 66 gl_->DeleteBuffers(1, &quad_vertices_vbo_); | |
| 67 gl_->DeleteBuffers(1, &quad_elements_vbo_); | |
| 68 } | |
| 69 | |
| 70 void StaticGeometryBinding::PrepareForDraw() { | |
| 71 SetupGLContext(gl_, quad_elements_vbo_, quad_vertices_vbo_); | |
| 72 } | |
| 73 | |
| 74 } // namespace cc | |
| OLD | NEW |