Upgrade ReadPixels to ES3 semantic in command buffer.
[chromium-blink-merge.git] / cc / output / static_geometry_binding.cc
blobe4af11d9491f5f16cb3c56a0dc98a795d5ba8195
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.
5 #include "cc/output/static_geometry_binding.h"
7 #include "gpu/command_buffer/client/gles2_interface.h"
8 #include "ui/gfx/geometry/rect_f.h"
10 namespace cc {
12 StaticGeometryBinding::StaticGeometryBinding(gpu::gles2::GLES2Interface* gl,
13 const gfx::RectF& quad_vertex_rect)
14 : gl_(gl), quad_vertices_vbo_(0), quad_elements_vbo_(0) {
15 GeometryBindingQuad quads[8];
16 GeometryBindingQuadIndex quad_indices[8];
18 static_assert(sizeof(GeometryBindingQuad) == 24 * sizeof(float),
19 "struct Quad should be densely packed");
20 static_assert(sizeof(GeometryBindingQuadIndex) == 6 * sizeof(uint16_t),
21 "struct QuadIndex should be densely packed");
23 for (size_t i = 0; i < 8; i++) {
24 GeometryBindingVertex v0 = {
25 {quad_vertex_rect.x(), quad_vertex_rect.bottom(), 0.0f},
26 {0.0f, 1.0f},
27 i * 4.0f + 0.0f};
28 GeometryBindingVertex v1 = {
29 {quad_vertex_rect.x(), quad_vertex_rect.y(), 0.0f},
30 {0.0f, 0.0f},
31 i * 4.0f + 1.0f};
32 GeometryBindingVertex v2 = {
33 {quad_vertex_rect.right(), quad_vertex_rect.y(), 0.0f},
34 {1.0f, 0.0f},
35 i * 4.0f + 2.0f};
36 GeometryBindingVertex v3 = {
37 {quad_vertex_rect.right(), quad_vertex_rect.bottom(), 0.0f},
38 {1.0f, 1.0f},
39 i * 4.0f + 3.0f};
40 GeometryBindingQuad x(v0, v1, v2, v3);
41 quads[i] = x;
42 GeometryBindingQuadIndex y(
43 static_cast<uint16>(0 + 4 * i), static_cast<uint16>(1 + 4 * i),
44 static_cast<uint16>(2 + 4 * i), static_cast<uint16>(3 + 4 * i),
45 static_cast<uint16>(0 + 4 * i), static_cast<uint16>(2 + 4 * i));
46 quad_indices[i] = y;
49 gl_->GenBuffers(1, &quad_vertices_vbo_);
50 gl_->GenBuffers(1, &quad_elements_vbo_);
52 gl_->BindBuffer(GL_ARRAY_BUFFER, quad_vertices_vbo_);
53 gl_->BufferData(GL_ARRAY_BUFFER, sizeof(GeometryBindingQuad) * 8, quads,
54 GL_STATIC_DRAW);
56 gl_->BindBuffer(GL_ELEMENT_ARRAY_BUFFER, quad_elements_vbo_);
57 gl_->BufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(GeometryBindingQuadIndex) * 8,
58 &quad_indices, GL_STATIC_DRAW);
61 StaticGeometryBinding::~StaticGeometryBinding() {
62 gl_->DeleteBuffers(1, &quad_vertices_vbo_);
63 gl_->DeleteBuffers(1, &quad_elements_vbo_);
66 void StaticGeometryBinding::PrepareForDraw() {
67 SetupGLContext(gl_, quad_elements_vbo_, quad_vertices_vbo_);
70 } // namespace cc