Index: cc/output/geometry_binding.cc |
diff --git a/cc/output/geometry_binding.cc b/cc/output/geometry_binding.cc |
index eda2a5ca827552f5593611be816b0079258f85d6..88a37deee82924cc137d58510ff739057d66fe40 100644 |
--- a/cc/output/geometry_binding.cc |
+++ b/cc/output/geometry_binding.cc |
@@ -10,70 +10,12 @@ |
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]; |
- }; |
- |
- 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}; |
- Quad x = {v0, v1, v2, v3}; |
- quad_list[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; |
- } |
- |
- 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)); |
-} |
- |
-GeometryBinding::~GeometryBinding() { |
- gl_->DeleteBuffers(1, &quad_vertices_vbo_); |
- gl_->DeleteBuffers(1, &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)); |
-void GeometryBinding::PrepareForDraw() { |
- 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 +25,56 @@ 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())); |
+} |
+ |
+GeometryBindingQuad::GeometryBindingQuad() { |
+ v0 = {{0, 0, 0}, {0, 0}, 0}; |
+ v1 = {{0, 0, 0}, {0, 0}, 0}; |
+ v2 = {{0, 0, 0}, {0, 0}, 0}; |
+ v3 = {{0, 0, 0}, {0, 0}, 0}; |
+} |
+ |
+GeometryBindingQuad::GeometryBindingQuad(const GeometryBindingVertex& vert0, |
+ const GeometryBindingVertex& vert1, |
+ const GeometryBindingVertex& vert2, |
+ const GeometryBindingVertex& vert3) { |
+ v0 = vert0; |
+ v1 = vert1; |
+ v2 = vert2; |
+ v3 = vert3; |
+} |
+ |
+GeometryBindingQuadIndex::GeometryBindingQuadIndex() { |
+ memset(data, 0x0, sizeof(data)); |
+} |
+ |
+GeometryBindingQuadIndex::GeometryBindingQuadIndex(uint16 index0, |
+ uint16 index1, |
+ uint16 index2, |
+ uint16 index3, |
+ uint16 index4, |
+ uint16 index5) { |
+ data[0] = index0; |
+ data[1] = index1; |
+ data[2] = index2; |
+ data[3] = index3; |
+ data[4] = index4; |
+ data[5] = index5; |
} |
} // namespace cc |