textured fills & enforce vao program with templates
This commit is contained in:
@@ -7,28 +7,26 @@
|
||||
|
||||
namespace llmr {
|
||||
|
||||
template <typename Shader>
|
||||
class VertexArrayObject {
|
||||
public:
|
||||
template <typename Shader, typename VertexBuffer>
|
||||
void bind(Shader& shader, VertexBuffer& vertex_buffer, char *vertex_offset) {
|
||||
template <typename Buffer>
|
||||
void bind(Shader& shader, Buffer& buffer, char *offset) {
|
||||
if (!vao) {
|
||||
glGenVertexArrays(1, &vao);
|
||||
glBindVertexArray(vao);
|
||||
|
||||
vertex_buffer.bind();
|
||||
shader.bind_vertex(vertex_offset);
|
||||
buffer.bind();
|
||||
shader.bind(offset);
|
||||
|
||||
program = shader.program;
|
||||
buffer = &vertex_buffer;
|
||||
offset = vertex_offset;
|
||||
} else if (program != shader.program) {
|
||||
throw std::runtime_error("trying to bind VAO to different program");
|
||||
} else if (buffer != &vertex_buffer) {
|
||||
buffer_ptr = &buffer;
|
||||
offset_ptr = offset;
|
||||
} else if (buffer_ptr != &buffer) {
|
||||
throw std::runtime_error("trying to bind VAO to another buffer");
|
||||
} else if (offset != vertex_offset) {
|
||||
} else if (offset_ptr != offset) {
|
||||
throw std::runtime_error("trying to bind VAO to another offset");
|
||||
} else {
|
||||
// This is the correct program for this VAO.
|
||||
// We have been given the correct information.
|
||||
glBindVertexArray(vao);
|
||||
}
|
||||
}
|
||||
@@ -44,9 +42,8 @@ private:
|
||||
|
||||
// For debug reasons, we're storing the bind information so that we can
|
||||
// detect errors and report
|
||||
GLuint program = 0;
|
||||
void *buffer = NULL;
|
||||
char *offset = 0;
|
||||
void *buffer_ptr = NULL;
|
||||
char *offset_ptr = 0;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ class VectorTile;
|
||||
class VectorTileLayer;
|
||||
class FillBuffer;
|
||||
class LineBuffer;
|
||||
class PlainShader;
|
||||
|
||||
class Tile : public std::enable_shared_from_this<Tile> {
|
||||
public:
|
||||
@@ -73,7 +74,7 @@ public:
|
||||
|
||||
// Holds the actual geometries in this tile.
|
||||
DebugFontBuffer debugFontBuffer;
|
||||
VertexArrayObject debugFontArray;
|
||||
VertexArrayObject<PlainShader> debugFontArray;
|
||||
|
||||
std::shared_ptr<FillBuffer> fillBuffer;
|
||||
std::shared_ptr<LineBuffer> lineBuffer;
|
||||
|
||||
@@ -18,6 +18,8 @@ namespace llmr {
|
||||
class Style;
|
||||
class FillBuffer;
|
||||
class BucketDescription;
|
||||
class OutlineShader;
|
||||
class PlainShader;
|
||||
struct Coordinate;
|
||||
struct pbf;
|
||||
|
||||
@@ -31,8 +33,8 @@ public:
|
||||
void addGeometry(const std::vector<Coordinate>& line);
|
||||
uint32_t size() const;
|
||||
|
||||
template <typename Shader> void drawElements(Shader& shader);
|
||||
template <typename Shader> void drawVertices(Shader& shader);
|
||||
void drawElements(PlainShader& shader);
|
||||
void drawVertices(OutlineShader& shader);
|
||||
|
||||
public:
|
||||
const BucketGeometryDescription geom_desc;
|
||||
@@ -41,7 +43,7 @@ private:
|
||||
std::shared_ptr<FillBuffer> buffer;
|
||||
|
||||
struct group {
|
||||
VertexArrayObject array;
|
||||
VertexArrayObject<PlainShader> array;
|
||||
uint32_t vertex_length;
|
||||
uint32_t elements_length;
|
||||
|
||||
@@ -56,32 +58,10 @@ private:
|
||||
uint32_t vertex_start;
|
||||
uint32_t elements_start;
|
||||
uint32_t length;
|
||||
VertexArrayObject array;
|
||||
VertexArrayObject<OutlineShader> array;
|
||||
std::vector<group> groups;
|
||||
};
|
||||
|
||||
|
||||
template <typename Shader>
|
||||
void FillBucket::drawElements(Shader& shader) {
|
||||
char *vertex_index = BUFFER_OFFSET(vertex_start * 2 * sizeof(int16_t));
|
||||
char *elements_index = BUFFER_OFFSET(elements_start * 3 * sizeof(int16_t));
|
||||
for (group& group : groups) {
|
||||
group.array.bind(shader, *buffer, vertex_index);
|
||||
glDrawElements(GL_TRIANGLES, group.elements_length * 3 - 3, GL_UNSIGNED_SHORT, elements_index);
|
||||
vertex_index += group.vertex_length * 2 * sizeof(uint16_t);
|
||||
elements_index += group.elements_length * 3 * sizeof(uint16_t);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename Shader>
|
||||
void FillBucket::drawVertices(Shader& shader) {
|
||||
// Draw the entire line
|
||||
char *vertex_index = BUFFER_OFFSET(vertex_start * 2 * sizeof(int16_t));
|
||||
array.bind(shader, *buffer, vertex_index);
|
||||
glDrawArrays(GL_LINE_STRIP, 0, length);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -37,7 +37,7 @@ private:
|
||||
std::shared_ptr<LineBuffer> buffer;
|
||||
uint32_t start;
|
||||
uint32_t length;
|
||||
VertexArrayObject array;
|
||||
VertexArrayObject<LineShader> array;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
#include <llmr/util/mat4.hpp>
|
||||
|
||||
#include <llmr/renderer/shader-plain.hpp>
|
||||
#include <llmr/renderer/shader-fill.hpp>
|
||||
#include <llmr/renderer/shader-outline.hpp>
|
||||
#include <llmr/renderer/shader-pattern.hpp>
|
||||
#include <llmr/renderer/shader-line.hpp>
|
||||
@@ -58,7 +57,6 @@ private:
|
||||
mat4 matrix;
|
||||
mat4 exMatrix;
|
||||
|
||||
std::unique_ptr<FillShader> fillShader;
|
||||
std::unique_ptr<PlainShader> plainShader;
|
||||
std::unique_ptr<OutlineShader> outlineShader;
|
||||
std::unique_ptr<LineShader> lineShader;
|
||||
@@ -77,7 +75,8 @@ private:
|
||||
4096, 4096
|
||||
};
|
||||
|
||||
VertexArrayObject tileStencilArray;
|
||||
VertexArrayObject<PlainShader> coveringPlainArray;
|
||||
VertexArrayObject<PatternShader> coveringPatternArray;
|
||||
|
||||
// Set up the tile boundary lines we're using to draw the tile outlines.
|
||||
VertexBuffer tileBorderBuffer = {
|
||||
@@ -88,7 +87,7 @@ private:
|
||||
0, 0
|
||||
};
|
||||
|
||||
VertexArrayObject tileBorderArray;
|
||||
VertexArrayObject<PlainShader> tileBorderArray;
|
||||
|
||||
// Set up the matte buffer we're using to draw the filling background.
|
||||
VertexBuffer matteBuffer = {
|
||||
@@ -103,7 +102,7 @@ private:
|
||||
16384, 16384
|
||||
};
|
||||
|
||||
VertexArrayObject matteArray;
|
||||
VertexArrayObject<PlainShader> matteArray;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
#ifndef LLMR_RENDERER_SHADER_FILL
|
||||
#define LLMR_RENDERER_SHADER_FILL
|
||||
|
||||
#include "shader.hpp"
|
||||
|
||||
namespace llmr {
|
||||
|
||||
class FillShader : public Shader {
|
||||
public:
|
||||
FillShader();
|
||||
|
||||
void bind_vertex(char *offset);
|
||||
|
||||
int32_t a_pos;
|
||||
int32_t u_matrix;
|
||||
int32_t u_color;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -9,7 +9,7 @@ class LineShader : public Shader {
|
||||
public:
|
||||
LineShader();
|
||||
|
||||
void bind_vertex(char *offset);
|
||||
void bind(char *offset);
|
||||
|
||||
int32_t a_pos;
|
||||
int32_t a_extrude;
|
||||
|
||||
@@ -9,7 +9,7 @@ class OutlineShader : public Shader {
|
||||
public:
|
||||
OutlineShader();
|
||||
|
||||
void bind_vertex(char *offset);
|
||||
void bind(char *offset);
|
||||
|
||||
int32_t a_pos;
|
||||
int32_t u_matrix;
|
||||
|
||||
@@ -9,6 +9,8 @@ class PatternShader : public Shader {
|
||||
public:
|
||||
PatternShader();
|
||||
|
||||
void bind(char *offset);
|
||||
|
||||
int32_t a_pos;
|
||||
int32_t u_matrix;
|
||||
int32_t u_color;
|
||||
|
||||
@@ -9,7 +9,7 @@ class PlainShader : public Shader {
|
||||
public:
|
||||
PlainShader();
|
||||
|
||||
void bind_vertex(char *offset);
|
||||
void bind(char *offset);
|
||||
|
||||
int32_t a_pos;
|
||||
int32_t u_matrix;
|
||||
|
||||
@@ -11,7 +11,6 @@ struct shader_source {
|
||||
};
|
||||
|
||||
enum {
|
||||
FILL_SHADER,
|
||||
LINE_SHADER,
|
||||
OUTLINE_SHADER,
|
||||
PATTERN_SHADER,
|
||||
|
||||
Reference in New Issue
Block a user