| OLD | NEW |
| 1 // Copyright 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "config.h" | 5 #include "config.h" |
| 6 | 6 |
| 7 #include "cc/geometry_binding.h" | 7 #include "cc/geometry_binding.h" |
| 8 | 8 |
| 9 #include "third_party/khronos/GLES2/gl2.h" |
| 9 #include "CCRendererGL.h" // For the GLC() macro. | 10 #include "CCRendererGL.h" // For the GLC() macro. |
| 10 #include "GraphicsContext3D.h" | |
| 11 #include <public/WebGraphicsContext3D.h> | 11 #include <public/WebGraphicsContext3D.h> |
| 12 | 12 |
| 13 namespace cc { | 13 namespace cc { |
| 14 | 14 |
| 15 GeometryBinding::GeometryBinding(WebKit::WebGraphicsContext3D* context, const Fl
oatRect& quadVertexRect) | 15 GeometryBinding::GeometryBinding(WebKit::WebGraphicsContext3D* context, const Fl
oatRect& quadVertexRect) |
| 16 : m_context(context) | 16 : m_context(context) |
| 17 , m_quadVerticesVbo(0) | 17 , m_quadVerticesVbo(0) |
| 18 , m_quadElementsVbo(0) | 18 , m_quadElementsVbo(0) |
| 19 , m_initialized(false) | 19 , m_initialized(false) |
| 20 { | 20 { |
| 21 // Vertex positions and texture coordinates for the 4 corners of a 1x1 quad. | 21 // Vertex positions and texture coordinates for the 4 corners of a 1x1 quad. |
| 22 float vertices[] = { quadVertexRect.x(), quadVertexRect.maxY(), 0.0f, 0.0f,
1.0f, | 22 float vertices[] = { quadVertexRect.x(), quadVertexRect.maxY(), 0.0f, 0.0f,
1.0f, |
| 23 quadVertexRect.x(), quadVertexRect.y(), 0.0f, 0.0f, 0.
0f, | 23 quadVertexRect.x(), quadVertexRect.y(), 0.0f, 0.0f, 0.
0f, |
| 24 quadVertexRect.maxX(), quadVertexRect.y(), 0.0f, 1.0f,
0.0f, | 24 quadVertexRect.maxX(), quadVertexRect.y(), 0.0f, 1.0f,
0.0f, |
| 25 quadVertexRect.maxX(), quadVertexRect.maxY(), 0.0f, 1.
0f, 1.0f }; | 25 quadVertexRect.maxX(), quadVertexRect.maxY(), 0.0f, 1.
0f, 1.0f }; |
| 26 uint16_t indices[] = { 0, 1, 2, 0, 2, 3, // The two triangles that make up t
he layer quad. | 26 uint16_t indices[] = { 0, 1, 2, 0, 2, 3, // The two triangles that make up t
he layer quad. |
| 27 0, 1, 2, 3}; // A line path for drawing the layer bor
der. | 27 0, 1, 2, 3}; // A line path for drawing the layer bor
der. |
| 28 | 28 |
| 29 GLC(m_context, m_quadVerticesVbo = m_context->createBuffer()); | 29 GLC(m_context, m_quadVerticesVbo = m_context->createBuffer()); |
| 30 GLC(m_context, m_quadElementsVbo = m_context->createBuffer()); | 30 GLC(m_context, m_quadElementsVbo = m_context->createBuffer()); |
| 31 GLC(m_context, m_context->bindBuffer(GraphicsContext3D::ARRAY_BUFFER, m_quad
VerticesVbo)); | 31 GLC(m_context, m_context->bindBuffer(GL_ARRAY_BUFFER, m_quadVerticesVbo)); |
| 32 GLC(m_context, m_context->bufferData(GraphicsContext3D::ARRAY_BUFFER, sizeof
(vertices), vertices, GraphicsContext3D::STATIC_DRAW)); | 32 GLC(m_context, m_context->bufferData(GL_ARRAY_BUFFER, sizeof(vertices), vert
ices, GL_STATIC_DRAW)); |
| 33 GLC(m_context, m_context->bindBuffer(GraphicsContext3D::ELEMENT_ARRAY_BUFFER
, m_quadElementsVbo)); | 33 GLC(m_context, m_context->bindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_quadElements
Vbo)); |
| 34 GLC(m_context, m_context->bufferData(GraphicsContext3D::ELEMENT_ARRAY_BUFFER
, sizeof(indices), indices, GraphicsContext3D::STATIC_DRAW)); | 34 GLC(m_context, m_context->bufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices
), indices, GL_STATIC_DRAW)); |
| 35 | 35 |
| 36 m_initialized = true; | 36 m_initialized = true; |
| 37 } | 37 } |
| 38 | 38 |
| 39 GeometryBinding::~GeometryBinding() | 39 GeometryBinding::~GeometryBinding() |
| 40 { | 40 { |
| 41 GLC(m_context, m_context->deleteBuffer(m_quadVerticesVbo)); | 41 GLC(m_context, m_context->deleteBuffer(m_quadVerticesVbo)); |
| 42 GLC(m_context, m_context->deleteBuffer(m_quadElementsVbo)); | 42 GLC(m_context, m_context->deleteBuffer(m_quadElementsVbo)); |
| 43 } | 43 } |
| 44 | 44 |
| 45 void GeometryBinding::prepareForDraw() | 45 void GeometryBinding::prepareForDraw() |
| 46 { | 46 { |
| 47 GLC(m_context, m_context->bindBuffer(GraphicsContext3D::ARRAY_BUFFER, quadVe
rticesVbo())); | 47 GLC(m_context, m_context->bindBuffer(GL_ARRAY_BUFFER, quadVerticesVbo())); |
| 48 GLC(m_context, m_context->bindBuffer(GraphicsContext3D::ELEMENT_ARRAY_BUFFER
, quadElementsVbo())); | 48 GLC(m_context, m_context->bindBuffer(GL_ELEMENT_ARRAY_BUFFER, quadElementsVb
o())); |
| 49 unsigned offset = 0; | 49 unsigned offset = 0; |
| 50 GLC(m_context, m_context->vertexAttribPointer(positionAttribLocation(), 3, G
raphicsContext3D::FLOAT, false, 5 * sizeof(float), offset)); | 50 GLC(m_context, m_context->vertexAttribPointer(positionAttribLocation(), 3, G
L_FLOAT, false, 5 * sizeof(float), offset)); |
| 51 offset += 3 * sizeof(float); | 51 offset += 3 * sizeof(float); |
| 52 GLC(m_context, m_context->vertexAttribPointer(texCoordAttribLocation(), 2, G
raphicsContext3D::FLOAT, false, 5 * sizeof(float), offset)); | 52 GLC(m_context, m_context->vertexAttribPointer(texCoordAttribLocation(), 2, G
L_FLOAT, false, 5 * sizeof(float), offset)); |
| 53 GLC(m_context, m_context->enableVertexAttribArray(positionAttribLocation()))
; | 53 GLC(m_context, m_context->enableVertexAttribArray(positionAttribLocation()))
; |
| 54 GLC(m_context, m_context->enableVertexAttribArray(texCoordAttribLocation()))
; | 54 GLC(m_context, m_context->enableVertexAttribArray(texCoordAttribLocation()))
; |
| 55 } | 55 } |
| 56 | 56 |
| 57 } // namespace cc | 57 } // namespace cc |
| OLD | NEW |