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

Unified Diff: cc/output/geometry_binding.cc

Issue 595593002: Splitting of layers for correct intersections (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixes from issues introduced by the rebase, added tests for video_quads. Created 5 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: cc/output/geometry_binding.cc
diff --git a/cc/output/geometry_binding.cc b/cc/output/geometry_binding.cc
index eda2a5ca827552f5593611be816b0079258f85d6..8148aaee5bf6f1dabb1131f371c99cb4b7d2eda8 100644
--- a/cc/output/geometry_binding.cc
+++ b/cc/output/geometry_binding.cc
@@ -10,70 +10,72 @@
namespace cc {
-GeometryBinding::GeometryBinding(gpu::gles2::GLES2Interface* gl,
- const gfx::RectF& quad_vertex_rect)
- : gl_(gl), quad_vertices_vbo_(0), quad_elements_vbo_(0) {
- struct Vertex {
+struct Vertex {
float a_position[3];
float a_texCoord[2];
// Index of the vertex, divide by 4 to have the matrix for this quad.
float a_index;
- };
- struct Quad {
- Vertex v0, v1, v2, v3;
- };
- struct QuadIndex {
- uint16 data[6];
- };
+};
+
+struct Quad {
+ Vertex v0, v1, v2, v3;
+};
+
+struct QuadIndex {
+ uint16 data[6];
+};
+
+StaticGeometryBinding::StaticGeometryBinding(gpu::gles2::GLES2Interface* gl,
+ const gfx::RectF& quad_vertex_rect)
+ : gl_(gl), quad_vertices_vbo_(0), quad_elements_vbo_(0) {
+ Quad quads[8];
+ QuadIndex quad_indices[8];
static_assert(sizeof(Quad) == 24 * sizeof(float),
"struct Quad should be densely packed");
static_assert(sizeof(QuadIndex) == 6 * sizeof(uint16_t),
"struct QuadIndex should be densely packed");
- Quad quad_list[8];
- QuadIndex quad_index_list[8];
- for (int i = 0; i < 8; i++) {
- Vertex v0 = {{quad_vertex_rect.x(), quad_vertex_rect.bottom(), 0.0f, },
- {0.0f, 1.0f, }, i * 4.0f + 0.0f};
- Vertex v1 = {{quad_vertex_rect.x(), quad_vertex_rect.y(), 0.0f, },
- {0.0f, 0.0f, }, i * 4.0f + 1.0f};
- Vertex v2 = {{quad_vertex_rect.right(), quad_vertex_rect.y(), 0.0f, },
- {1.0f, .0f, }, i * 4.0f + 2.0f};
- Vertex v3 = {{quad_vertex_rect.right(), quad_vertex_rect.bottom(), 0.0f, },
- {1.0f, 1.0f, }, i * 4.0f + 3.0f};
+ for (size_t i = 0; i < 8; i++) {
+ Vertex v0 = {{quad_vertex_rect.x(), quad_vertex_rect.bottom(), 0.0f},
+ {0.0f, 1.0f},
+ i * 4.0f + 0.0f};
+ Vertex v1 = {{quad_vertex_rect.x(), quad_vertex_rect.y(), 0.0f},
+ {0.0f, 0.0f},
+ i * 4.0f + 1.0f};
+ Vertex v2 = {{quad_vertex_rect.right(), quad_vertex_rect.y(), 0.0f},
+ {1.0f, 0.0f},
+ i * 4.0f + 2.0f};
+ Vertex v3 = {{quad_vertex_rect.right(), quad_vertex_rect.bottom(), 0.0f},
+ {1.0f, 1.0f},
+ i * 4.0f + 3.0f};
Quad x = {v0, v1, v2, v3};
- quad_list[i] = x;
+ quads[i] = x;
QuadIndex y = {
{static_cast<uint16>(0 + 4 * i), static_cast<uint16>(1 + 4 * i),
static_cast<uint16>(2 + 4 * i), static_cast<uint16>(3 + 4 * i),
static_cast<uint16>(0 + 4 * i), static_cast<uint16>(2 + 4 * i)}};
- quad_index_list[i] = y;
+ quad_indices[i] = y;
}
- gl_->GenBuffers(1, &quad_vertices_vbo_);
- gl_->GenBuffers(1, &quad_elements_vbo_);
+ GLC(gl_, gl_->GenBuffers(1, &quad_vertices_vbo_));
+ GLC(gl_, gl_->GenBuffers(1, &quad_elements_vbo_));
+
GLC(gl_, gl_->BindBuffer(GL_ARRAY_BUFFER, quad_vertices_vbo_));
- GLC(gl_,
- gl_->BufferData(
- GL_ARRAY_BUFFER, sizeof(quad_list), quad_list, GL_STATIC_DRAW));
- GLC(gl_, gl_->BindBuffer(GL_ELEMENT_ARRAY_BUFFER, quad_elements_vbo_));
- GLC(gl_,
- gl_->BufferData(GL_ELEMENT_ARRAY_BUFFER,
- sizeof(quad_index_list),
- quad_index_list,
- GL_STATIC_DRAW));
-}
+ GLC(gl_, gl_->BufferData(GL_ARRAY_BUFFER, sizeof(Quad) * 8, quads,
+ GL_STATIC_DRAW));
-GeometryBinding::~GeometryBinding() {
- gl_->DeleteBuffers(1, &quad_vertices_vbo_);
- gl_->DeleteBuffers(1, &quad_elements_vbo_);
+ GLC(gl_, gl_->BindBuffer(GL_ELEMENT_ARRAY_BUFFER, quad_elements_vbo_));
+ GLC(gl_, gl_->BufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(QuadIndex) * 8,
+ &quad_indices, GL_STATIC_DRAW));
}
-void GeometryBinding::PrepareForDraw() {
- GLC(gl_, gl_->BindBuffer(GL_ELEMENT_ARRAY_BUFFER, quad_elements_vbo_));
+void SetupGLContext(gpu::gles2::GLES2Interface* gl,
+ GLuint quad_elements_vbo,
+ GLuint quad_vertices_vbo) {
+ GLC(gl, gl->BindBuffer(GL_ELEMENT_ARRAY_BUFFER, quad_elements_vbo));
- GLC(gl_, gl_->BindBuffer(GL_ARRAY_BUFFER, quad_vertices_vbo_));
+ GLC(gl, gl->BindBuffer(GL_ARRAY_BUFFER, quad_vertices_vbo));
// OpenGL defines the last parameter to VertexAttribPointer as type
// "const GLvoid*" even though it is actually an offset into the buffer
// object's data store and not a pointer to the client's address space.
@@ -83,15 +85,81 @@ void GeometryBinding::PrepareForDraw() {
reinterpret_cast<const void*>(5 * sizeof(float)),
};
- GLC(gl_, gl_->VertexAttribPointer(PositionAttribLocation(), 3, GL_FLOAT,
- false, 6 * sizeof(float), offsets[0]));
- GLC(gl_, gl_->VertexAttribPointer(TexCoordAttribLocation(), 2, GL_FLOAT,
- false, 6 * sizeof(float), offsets[1]));
- GLC(gl_, gl_->VertexAttribPointer(TriangleIndexAttribLocation(), 1, GL_FLOAT,
- false, 6 * sizeof(float), offsets[2]));
- GLC(gl_, gl_->EnableVertexAttribArray(PositionAttribLocation()));
- GLC(gl_, gl_->EnableVertexAttribArray(TexCoordAttribLocation()));
- GLC(gl_, gl_->EnableVertexAttribArray(TriangleIndexAttribLocation()));
+ GLC(gl,
+ gl->VertexAttribPointer(GeometryBinding::PositionAttribLocation(), 3,
+ GL_FLOAT, false, 6 * sizeof(float), offsets[0]));
+ GLC(gl,
+ gl->VertexAttribPointer(GeometryBinding::TexCoordAttribLocation(), 2,
+ GL_FLOAT, false, 6 * sizeof(float), offsets[1]));
+ GLC(gl,
+ gl->VertexAttribPointer(GeometryBinding::TriangleIndexAttribLocation(), 1,
+ GL_FLOAT, false, 6 * sizeof(float), offsets[2]));
+ GLC(gl,
+ gl->EnableVertexAttribArray(GeometryBinding::PositionAttribLocation()));
+ GLC(gl,
+ gl->EnableVertexAttribArray(GeometryBinding::TexCoordAttribLocation()));
+ GLC(gl, gl->EnableVertexAttribArray(
+ GeometryBinding::TriangleIndexAttribLocation()));
+}
+
+StaticGeometryBinding::~StaticGeometryBinding() {
+ gl_->DeleteBuffers(1, &quad_vertices_vbo_);
+ gl_->DeleteBuffers(1, &quad_elements_vbo_);
+}
+
+void StaticGeometryBinding::PrepareForDraw() {
+ SetupGLContext(gl_, quad_elements_vbo_, quad_vertices_vbo_);
+}
+
+DynamicGeometryBinding::DynamicGeometryBinding(gpu::gles2::GLES2Interface* gl)
+ : gl_(gl), quad_vertices_vbo_(0), quad_elements_vbo_(0) {
+ Quad quads[8];
+ QuadIndex quad_indices[8];
+
+ static_assert(sizeof(Quad) == 24 * sizeof(float),
+ "struct Quad should be densely packed");
+ static_assert(sizeof(QuadIndex) == 6 * sizeof(uint16_t),
+ "struct QuadIndex should be densely packed");
+
+ GLC(gl_, gl_->GenBuffers(1, &quad_vertices_vbo_));
+ GLC(gl_, gl_->GenBuffers(1, &quad_elements_vbo_));
+
+ GLC(gl_, gl_->BindBuffer(GL_ARRAY_BUFFER, quad_vertices_vbo_));
+ GLC(gl_, gl_->BufferData(GL_ARRAY_BUFFER, sizeof(Quad) * 1, quads,
+ GL_DYNAMIC_DRAW));
+
+ GLC(gl_, gl_->BindBuffer(GL_ELEMENT_ARRAY_BUFFER, quad_elements_vbo_));
+ GLC(gl_, gl_->BufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(QuadIndex) * 1,
+ &quad_indices, GL_DYNAMIC_DRAW));
+}
+
+void DynamicGeometryBinding::InitializeCustomQuad(const gfx::QuadF& quad) {
+ float uv[] = {0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f};
+ InitializeCustomQuadWithUVs(quad, uv);
+}
+
+void DynamicGeometryBinding::InitializeCustomQuadWithUVs(const gfx::QuadF& quad,
+ const float uv[8]) {
+ Vertex v0 = {{quad.p1().x(), quad.p1().y(), 0.0f}, {uv[0], uv[1]}, 0.0f};
+ Vertex v1 = {{quad.p2().x(), quad.p2().y(), 0.0f}, {uv[2], uv[3]}, 1.0f};
+ Vertex v2 = {{quad.p3().x(), quad.p3().y(), 0.0f}, {uv[4], uv[5]}, 2.0f};
+ Vertex v3 = {{quad.p4().x(), quad.p4().y(), 0.0f}, {uv[6], uv[7]}, 3.0f};
+
+ Quad local_quad = {v0, v1, v2, v3};
+ QuadIndex quad_index = {{static_cast<uint16>(0),
+ static_cast<uint16>(1),
+ static_cast<uint16>(2),
+ static_cast<uint16>(3),
+ static_cast<uint16>(0),
+ static_cast<uint16>(2)}};
+
+ GLC(gl_, gl_->BufferSubData(GL_ARRAY_BUFFER, 0, sizeof(Quad), &local_quad));
+ GLC(gl_, gl_->BufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, sizeof(QuadIndex),
+ &quad_index));
+}
+
+void DynamicGeometryBinding::PrepareForDraw() {
+ SetupGLContext(gl_, quad_elements_vbo_, quad_vertices_vbo_);
}
} // namespace cc

Powered by Google App Engine
This is Rietveld 408576698