Index: cc/output/geometry_binding.cc |
diff --git a/cc/output/geometry_binding.cc b/cc/output/geometry_binding.cc |
index b8c9759618551d9327f858af423d366624d51276..0fd72787a716024ebe5fc6d5a55dc8bb63706b00 100644 |
--- a/cc/output/geometry_binding.cc |
+++ b/cc/output/geometry_binding.cc |
@@ -3,7 +3,6 @@ |
// found in the LICENSE file. |
#include "cc/output/geometry_binding.h" |
- |
#include "cc/output/gl_renderer.h" // For the GLC() macro. |
#include "gpu/command_buffer/client/gles2_interface.h" |
#include "ui/gfx/geometry/rect_f.h" |
@@ -11,20 +10,15 @@ |
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 { |
- 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]; |
- }; |
+ const gfx::RectF& quad_vertex_rect, |
+ size_t buffer_size) |
+ : gl_(gl), |
+ quad_vertices_vbo_(0), |
+ quad_elements_vbo_(0), |
+ quad_vertex_rect_(quad_vertex_rect), |
+ initialized_(false) { |
+ Quad quads[buffer_size]; |
+ QuadIndex quad_indexes[buffer_size]; |
COMPILE_ASSERT(sizeof(Quad) == 24 * sizeof(float), // NOLINT(runtime/sizeof) |
struct_is_densely_packed); |
@@ -32,17 +26,40 @@ GeometryBinding::GeometryBinding(gpu::gles2::GLES2Interface* gl, |
sizeof(QuadIndex) == 6 * sizeof(uint16_t), // NOLINT(runtime/sizeof) |
struct_is_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}; |
+ // XXX: Should check for OUT_OF_MEMORY here |
+ 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(quads), quads, GL_DYNAMIC_DRAW)); |
+ |
+ GLC(gl_, gl_->BindBuffer(GL_ELEMENT_ARRAY_BUFFER, quad_elements_vbo_)); |
+ GLC(gl_, |
+ gl_->BufferData(GL_ELEMENT_ARRAY_BUFFER, |
+ sizeof(quad_indexes), |
+ quad_indexes, |
+ GL_DYNAMIC_DRAW)); |
+ |
+ InitializeBaseQuads(buffer_size); |
+} |
+ |
+void GeometryBinding::InitializeBaseQuads(size_t buffer_size) { |
+ Quad quad_list[buffer_size]; |
+ QuadIndex quad_index_list[buffer_size]; |
+ for (size_t i = 0; i < buffer_size; 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; |
QuadIndex y = { |
@@ -51,19 +68,8 @@ GeometryBinding::GeometryBinding(gpu::gles2::GLES2Interface* gl, |
static_cast<uint16>(0 + 4 * i), static_cast<uint16>(2 + 4 * i)}}; |
quad_index_list[i] = y; |
} |
- |
- gl_->GenBuffers(1, &quad_vertices_vbo_); |
- 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)); |
+ SetBuffers<Quad, QuadIndex>( |
+ quad_list, quad_index_list, 0, 0, buffer_size, buffer_size); |
} |
GeometryBinding::~GeometryBinding() { |
@@ -111,4 +117,29 @@ void GeometryBinding::PrepareForDraw() { |
GLC(gl_, gl_->EnableVertexAttribArray(TriangleIndexAttribLocation())); |
} |
+GeometryBindingQuad::GeometryBindingQuad(gpu::gles2::GLES2Interface* gl, |
+ const gfx::RectF& quad_vertex_rect) |
+ : GeometryBinding(gl, quad_vertex_rect, 1) { |
+} |
+ |
+void GeometryBindingQuad::InitializeCustomQuad(const gfx::QuadF& quad) { |
enne (OOO)
2014/09/24 17:35:30
Can the GeometryBinding stuff become two classes,
|
+ float uv[] = {0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f}; |
+ InitializeCustomQuadWithUVs(quad, uv); |
+} |
+ |
+void GeometryBindingQuad::InitializeCustomQuadWithUVs(const gfx::QuadF& quad, |
+ 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)}}; |
+ |
+ SetBuffers<Quad, QuadIndex>(&local_quad, &quad_index, 0, 0, 1, 1); |
+} |
+ |
} // namespace cc |