Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(191)

Side by Side Diff: cc/geometry_binding.cc

Issue 12912006: Part 4 of cc/ directory shuffles: output (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "cc/geometry_binding.h"
6
7 #include "cc/gl_renderer.h" // For the GLC() macro.
8 #include "third_party/WebKit/Source/Platform/chromium/public/WebGraphicsContext3 D.h"
9 #include "third_party/khronos/GLES2/gl2.h"
10 #include "ui/gfx/rect_f.h"
11
12 namespace cc {
13
14 GeometryBinding::GeometryBinding(WebKit::WebGraphicsContext3D* context,
15 const gfx::RectF& quad_vertex_rect)
16 : context_(context),
17 quad_vertices_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 {
28 float a_position[3];
29 float a_texCoord[2];
30 // Index of the vertex, divide by 4 to have the matrix for this quad.
31 float a_index;
32 };
33 struct Quad {
34 Vertex v0, v1, v2, v3;
35 };
36 struct QuadIndex {
37 uint16_t data[6];
38 };
39
40 COMPILE_ASSERT(sizeof(Quad) == 24 * sizeof(float), struct_is_densely_packed);
41 COMPILE_ASSERT(sizeof(QuadIndex) == 6 * sizeof(uint16_t),
42 struct_is_densely_packed);
43
44 Quad quad_list[8];
45 QuadIndex quad_index_list[8];
46 for (int i = 0; i < 8; i++) {
47 Vertex v0 = { quad_vertex_rect.x(), quad_vertex_rect.bottom(), 0.0f, 0.0f,
48 1.0f, i * 4.0f + 0.0f };
49 Vertex v1 = { quad_vertex_rect.x(), quad_vertex_rect.y(), 0.0f, 0.0f, 0.0f,
50 i * 4.0f + 1.0f };
51 Vertex v2 = { quad_vertex_rect.right(), quad_vertex_rect.y(), 0.0f, 1.0f,
52 0.0f, i * 4.0f + 2.0f };
53 Vertex v3 = { quad_vertex_rect.right(), quad_vertex_rect.bottom(), 0.0f,
54 1.0f, 1.0f, i * 4.0f + 3.0f };
55 Quad x = { v0, v1, v2, v3 };
56 quad_list[i] = x;
57 QuadIndex y = { 0 + 4 * i, 1 + 4 * i, 2 + 4 * i, 3 + 4 * i, 0 + 4 * i,
58 2 + 4 * i };
59 quad_index_list[i] = y;
60 }
61
62 GLC(context_, quad_vertices_vbo_ = context_->createBuffer());
63 GLC(context_, quad_elements_vbo_ = context_->createBuffer());
64 GLC(context_, context_->bindBuffer(GL_ARRAY_BUFFER, quad_vertices_vbo_));
65 GLC(context_,
66 context_->bufferData(
67 GL_ARRAY_BUFFER, sizeof(quad_list), quad_list, GL_STATIC_DRAW));
68 GLC(context_,
69 context_->bindBuffer(GL_ELEMENT_ARRAY_BUFFER, quad_elements_vbo_));
70 GLC(context_,
71 context_->bufferData(GL_ELEMENT_ARRAY_BUFFER,
72 sizeof(quad_index_list),
73 quad_index_list,
74 GL_STATIC_DRAW));
75 }
76
77 GeometryBinding::~GeometryBinding() {
78 GLC(context_, context_->deleteBuffer(quad_vertices_vbo_));
79 GLC(context_, context_->deleteBuffer(quad_elements_vbo_));
80 }
81
82 void GeometryBinding::PrepareForDraw() {
83 GLC(context_,
84 context_->bindBuffer(GL_ELEMENT_ARRAY_BUFFER, quad_elements_vbo_));
85
86 GLC(context_, context_->bindBuffer(GL_ARRAY_BUFFER, quad_vertices_vbo_));
87 GLC(context_,
88 context_->vertexAttribPointer(
89 PositionAttribLocation(), 3, GL_FLOAT, false, 6 * sizeof(float), 0));
90 GLC(context_,
91 context_->vertexAttribPointer(TexCoordAttribLocation(),
92 2,
93 GL_FLOAT,
94 false,
95 6 * sizeof(float),
96 3 * sizeof(float)));
97 GLC(context_,
98 context_->vertexAttribPointer(TriangleIndexAttribLocation(),
99 1,
100 GL_FLOAT,
101 false,
102 6 * sizeof(float),
103 5 * sizeof(float)));
104 GLC(context_, context_->enableVertexAttribArray(PositionAttribLocation()));
105 GLC(context_, context_->enableVertexAttribArray(TexCoordAttribLocation()));
106 GLC(context_,
107 context_->enableVertexAttribArray(TriangleIndexAttribLocation()));
108 }
109
110 } // namespace cc
OLDNEW
« no previous file with comments | « cc/geometry_binding.h ('k') | cc/gl_frame_data.h » ('j') | content/common/view_messages.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698