GeometryBinding.cpp [plain text]
#include "config.h"
#if USE(ACCELERATED_COMPOSITING)
#include "GeometryBinding.h"
#include "GraphicsContext.h"
#include "GraphicsContext3D.h"
#include "LayerRendererChromium.h"
namespace WebCore {
GeometryBinding::GeometryBinding(GraphicsContext3D* context)
: m_context(context)
, m_quadVerticesVbo(0)
, m_quadElementsVbo(0)
, m_initialized(false)
{
float vertices[] = { -0.5f, 0.5f, 0.0f, 0.0f, 1.0f,
-0.5f, -0.5f, 0.0f, 0.0f, 0.0f,
0.5f, -0.5f, 0.0f, 1.0f, 0.0f,
0.5f, 0.5f, 0.0f, 1.0f, 1.0f };
uint16_t indices[] = { 0, 1, 2, 0, 2, 3, 0, 1, 2, 3};
GLC(m_context, m_quadVerticesVbo = m_context->createBuffer());
GLC(m_context, m_quadElementsVbo = m_context->createBuffer());
GLC(m_context, m_context->bindBuffer(GraphicsContext3D::ARRAY_BUFFER, m_quadVerticesVbo));
GLC(m_context, m_context->bufferData(GraphicsContext3D::ARRAY_BUFFER, sizeof(vertices), vertices, GraphicsContext3D::STATIC_DRAW));
GLC(m_context, m_context->bindBuffer(GraphicsContext3D::ELEMENT_ARRAY_BUFFER, m_quadElementsVbo));
GLC(m_context, m_context->bufferData(GraphicsContext3D::ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GraphicsContext3D::STATIC_DRAW));
m_initialized = true;
}
GeometryBinding::~GeometryBinding()
{
GLC(m_context, m_context->deleteBuffer(m_quadVerticesVbo));
GLC(m_context, m_context->deleteBuffer(m_quadElementsVbo));
}
void GeometryBinding::prepareForDraw()
{
GLC(m_context, m_context->bindBuffer(GraphicsContext3D::ARRAY_BUFFER, quadVerticesVbo()));
GLC(m_context, m_context->bindBuffer(GraphicsContext3D::ELEMENT_ARRAY_BUFFER, quadElementsVbo()));
unsigned offset = 0;
GLC(m_context, m_context->vertexAttribPointer(positionAttribLocation(), 3, GraphicsContext3D::FLOAT, false, 5 * sizeof(float), offset));
offset += 3 * sizeof(float);
GLC(m_context, m_context->vertexAttribPointer(texCoordAttribLocation(), 2, GraphicsContext3D::FLOAT, false, 5 * sizeof(float), offset));
GLC(m_context, m_context->enableVertexAttribArray(positionAttribLocation()));
GLC(m_context, m_context->enableVertexAttribArray(texCoordAttribLocation()));
}
}
#endif // USE(ACCELERATED_COMPOSITING)