Add Sad Tab resources to the iOS build.
[chromium-blink-merge.git] / cc / geometry_binding.cc
blob6a76ccca9eeb26bfbeeb3e22ec909d82ab9818c1
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.
5 #include "config.h"
7 #include "cc/geometry_binding.h"
9 #include "cc/gl_renderer.h" // For the GLC() macro.
10 #include "third_party/khronos/GLES2/gl2.h"
11 #include "ui/gfx/rect_f.h"
12 #include <public/WebGraphicsContext3D.h>
14 namespace cc {
16 GeometryBinding::GeometryBinding(WebKit::WebGraphicsContext3D* context, const gfx::RectF& quadVertexRect)
17 : m_context(context)
18 , m_quadVerticesVbo(0)
19 , m_quadElementsVbo(0)
20 , m_initialized(false)
22 // Vertex positions and texture coordinates for the 4 corners of a 1x1 quad.
23 float vertices[] = { quadVertexRect.x(), quadVertexRect.bottom(), 0.0f, 0.0f, 1.0f,
24 quadVertexRect.x(), quadVertexRect.y(), 0.0f, 0.0f, 0.0f,
25 quadVertexRect.right(), quadVertexRect.y(), 0.0f, 1.0f, 0.0f,
26 quadVertexRect.right(), quadVertexRect.bottom(), 0.0f, 1.0f, 1.0f };
27 uint16_t indices[] = { 0, 1, 2, 0, 2, 3, // The two triangles that make up the layer quad.
28 0, 1, 2, 3}; // A line path for drawing the layer border.
30 GLC(m_context, m_quadVerticesVbo = m_context->createBuffer());
31 GLC(m_context, m_quadElementsVbo = m_context->createBuffer());
32 GLC(m_context, m_context->bindBuffer(GL_ARRAY_BUFFER, m_quadVerticesVbo));
33 GLC(m_context, m_context->bufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW));
34 GLC(m_context, m_context->bindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_quadElementsVbo));
35 GLC(m_context, m_context->bufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW));
37 m_initialized = true;
40 GeometryBinding::~GeometryBinding()
42 GLC(m_context, m_context->deleteBuffer(m_quadVerticesVbo));
43 GLC(m_context, m_context->deleteBuffer(m_quadElementsVbo));
46 void GeometryBinding::prepareForDraw()
48 GLC(m_context, m_context->bindBuffer(GL_ARRAY_BUFFER, quadVerticesVbo()));
49 GLC(m_context, m_context->bindBuffer(GL_ELEMENT_ARRAY_BUFFER, quadElementsVbo()));
50 unsigned offset = 0;
51 GLC(m_context, m_context->vertexAttribPointer(positionAttribLocation(), 3, GL_FLOAT, false, 5 * sizeof(float), offset));
52 offset += 3 * sizeof(float);
53 GLC(m_context, m_context->vertexAttribPointer(texCoordAttribLocation(), 2, GL_FLOAT, false, 5 * sizeof(float), offset));
54 GLC(m_context, m_context->enableVertexAttribArray(positionAttribLocation()));
55 GLC(m_context, m_context->enableVertexAttribArray(texCoordAttribLocation()));
58 } // namespace cc