Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[core] Put VertexArrayObject in gl namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
jfirebaugh committed Oct 5, 2016
1 parent 73334ac commit b9b8657
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 37 deletions.
18 changes: 10 additions & 8 deletions src/mbgl/gl/vao.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
#include <mbgl/gl/gl.hpp>

namespace mbgl {
namespace gl {

VertexArrayObject::VertexArrayObject() {
}

VertexArrayObject::~VertexArrayObject() = default;

void VertexArrayObject::bindVertexArrayObject(gl::Context& context) {
if (!gl::GenVertexArrays || !gl::BindVertexArray) {
void VertexArrayObject::bindVertexArrayObject(Context& context) {
if (!GenVertexArrays || !BindVertexArray) {
static bool reported = false;
if (!reported) {
Log::Warning(Event::OpenGL, "Not using Vertex Array Objects");
Expand All @@ -30,9 +31,9 @@ void VertexArrayObject::bindVertexArrayObject(gl::Context& context) {
context.vertexArrayObject = *vertexArray;
}

void VertexArrayObject::verifyBinding(gl::Shader& shader,
gl::BufferID vertexBuffer,
gl::BufferID elementsBuffer,
void VertexArrayObject::verifyBinding(Shader& shader,
BufferID vertexBuffer,
BufferID elementsBuffer,
int8_t* offset) {
if (bound_shader != shader.getID()) {
throw std::runtime_error(std::string("trying to rebind VAO to another shader from " +
Expand All @@ -47,9 +48,9 @@ void VertexArrayObject::verifyBinding(gl::Shader& shader,
}
}

void VertexArrayObject::storeBinding(gl::Shader& shader,
gl::BufferID vertexBuffer,
gl::BufferID elementsBuffer,
void VertexArrayObject::storeBinding(Shader& shader,
BufferID vertexBuffer,
BufferID elementsBuffer,
int8_t* offset) {
bound_shader = shader.getID();
bound_shader_name = shader.name;
Expand All @@ -58,4 +59,5 @@ void VertexArrayObject::storeBinding(gl::Shader& shader,
bound_elements_buffer = elementsBuffer;
}

} // namespace gl
} // namespace mbgl
36 changes: 19 additions & 17 deletions src/mbgl/gl/vao.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <stdexcept>

namespace mbgl {
namespace gl {

class VertexArrayObject : public util::noncopyable {
public:
Expand All @@ -17,9 +18,9 @@ class VertexArrayObject : public util::noncopyable {

template <typename Shader, typename T>
void bind(Shader& shader,
const gl::VertexBuffer<T>& vertexBuffer,
const VertexBuffer<T>& vertexBuffer,
int8_t* offset,
gl::Context& context) {
Context& context) {
bindVertexArrayObject(context);
if (bound_shader == 0) {
context.vertexBuffer = vertexBuffer.buffer;
Expand All @@ -34,10 +35,10 @@ class VertexArrayObject : public util::noncopyable {

template <typename Shader, typename T, typename P>
void bind(Shader& shader,
const gl::VertexBuffer<T>& vertexBuffer,
const gl::IndexBuffer<P>& indexBuffer,
const VertexBuffer<T>& vertexBuffer,
const IndexBuffer<P>& indexBuffer,
int8_t* offset,
gl::Context& context) {
Context& context) {
bindVertexArrayObject(context);
if (bound_shader == 0) {
context.vertexBuffer = vertexBuffer.buffer;
Expand All @@ -51,30 +52,31 @@ class VertexArrayObject : public util::noncopyable {
}
}

gl::VertexArrayID getID() const {
VertexArrayID getID() const {
return *vertexArray;
}

private:
void bindVertexArrayObject(gl::Context&);
void storeBinding(gl::Shader& shader,
gl::BufferID vertexBuffer,
gl::BufferID elementsBuffer,
void bindVertexArrayObject(Context&);
void storeBinding(Shader& shader,
BufferID vertexBuffer,
BufferID elementsBuffer,
int8_t* offset);
void verifyBinding(gl::Shader& shader,
gl::BufferID vertexBuffer,
gl::BufferID elementsBuffer,
void verifyBinding(Shader& shader,
BufferID vertexBuffer,
BufferID elementsBuffer,
int8_t* offset);

mbgl::optional<gl::UniqueVertexArray> vertexArray;
optional<UniqueVertexArray> vertexArray;

// For debug reasons, we're storing the bind information so that we can
// detect errors and report
gl::ProgramID bound_shader = 0;
ProgramID bound_shader = 0;
const char* bound_shader_name = "";
gl::BufferID bound_vertex_buffer = 0;
gl::BufferID bound_elements_buffer = 0;
BufferID bound_vertex_buffer = 0;
BufferID bound_elements_buffer = 0;
int8_t *bound_offset = nullptr;
};

} // namespace gl
} // namespace mbgl
2 changes: 1 addition & 1 deletion src/mbgl/renderer/debug_bucket.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class DebugBucket : private util::noncopyable {

private:
gl::VertexBuffer<PlainVertex> textVertexes;
VertexArrayObject array;
gl::VertexArrayObject array;
};

} // namespace mbgl
2 changes: 1 addition & 1 deletion src/mbgl/renderer/painter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ class Painter : private util::noncopyable {
gl::VertexBuffer<PlainVertex> tileLineStripVertexes;
gl::VertexBuffer<RasterVertex> rasterVertexes;

VertexArrayObject tileBorderArray;
gl::VertexArrayObject tileBorderArray;
};

} // namespace mbgl
4 changes: 2 additions & 2 deletions src/mbgl/renderer/raster_bucket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <mbgl/shader/raster_shader.hpp>
#include <mbgl/renderer/painter.hpp>
#include <mbgl/gl/gl.hpp>

#include <mbgl/gl/context.hpp>

namespace mbgl {

Expand All @@ -27,7 +27,7 @@ void RasterBucket::render(Painter& painter,

void RasterBucket::drawRaster(RasterShader& shader,
gl::VertexBuffer<RasterVertex>& vertices,
VertexArrayObject& array,
gl::VertexArrayObject& array,
gl::Context& context) {
assert(texture);
context.bindTexture(*texture, 0, gl::TextureFilter::Linear);
Expand Down
9 changes: 5 additions & 4 deletions src/mbgl/renderer/raster_bucket.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@

#include <mbgl/renderer/bucket.hpp>
#include <mbgl/util/image.hpp>
#include <mbgl/gl/context.hpp>
#include <mbgl/util/optional.hpp>
#include <mbgl/gl/texture.hpp>

namespace mbgl {

class RasterShader;
class RasterVertex;
class StaticRasterVertexBuffer;
class VertexArrayObject;

namespace gl {
class Context;
template <class> class VertexBuffer;
class VertexArrayObject;
} // namespace gl

class RasterBucket : public Bucket {
Expand All @@ -24,7 +25,7 @@ class RasterBucket : public Bucket {
bool hasData() const override;
bool needsClipping() const override;

void drawRaster(RasterShader&, gl::VertexBuffer<RasterVertex>&, VertexArrayObject&, gl::Context&);
void drawRaster(RasterShader&, gl::VertexBuffer<RasterVertex>&, gl::VertexArrayObject&, gl::Context&);

private:
PremultipliedImage image;
Expand Down
8 changes: 4 additions & 4 deletions src/mbgl/shader/shaders.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ class Shaders {
CollisionBoxShader collisionBox;
CircleShader circle;

VertexArrayObject coveringPlainArray;
VertexArrayObject coveringRasterArray;
VertexArrayObject backgroundPatternArray;
VertexArrayObject backgroundArray;
gl::VertexArrayObject coveringPlainArray;
gl::VertexArrayObject coveringRasterArray;
gl::VertexArrayObject backgroundPatternArray;
gl::VertexArrayObject backgroundArray;
};

} // namespace mbgl

0 comments on commit b9b8657

Please sign in to comment.