summaryrefslogtreecommitdiff
path: root/include/llmr/geometry
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2014-02-18 15:56:23 +0100
committerKonstantin Käfer <mail@kkaefer.com>2014-02-18 15:56:23 +0100
commitea80daa129aa784b12c2baf5a4add1756127ee52 (patch)
treee1445b37038b06c87de2907701463f5e19091442 /include/llmr/geometry
parent004ff9ea10b712985002a67aef07c174664edbfb (diff)
downloadqtlocation-mapboxgl-ea80daa129aa784b12c2baf5a4add1756127ee52.tar.gz
allow switching the vao if we switch the style from plain color to pattern fill
Diffstat (limited to 'include/llmr/geometry')
-rw-r--r--include/llmr/geometry/elements_buffer.hpp7
-rw-r--r--include/llmr/geometry/vao.hpp27
2 files changed, 20 insertions, 14 deletions
diff --git a/include/llmr/geometry/elements_buffer.hpp b/include/llmr/geometry/elements_buffer.hpp
index 684b3acd3b..a058312bda 100644
--- a/include/llmr/geometry/elements_buffer.hpp
+++ b/include/llmr/geometry/elements_buffer.hpp
@@ -2,15 +2,12 @@
#define LLMR_GEOMETRY_TRIANGLE_ELEMENTS_BUFFER
#include <llmr/geometry/buffer.hpp>
+#include <llmr/geometry/vao.hpp>
namespace llmr {
-template <typename Shader>
-class VertexArrayObject;
-
-template <typename Shader>
struct ElementGroup {
- VertexArrayObject<Shader> array;
+ VertexArrayObject array;
uint32_t vertex_length;
uint32_t elements_length;
diff --git a/include/llmr/geometry/vao.hpp b/include/llmr/geometry/vao.hpp
index a2a5a8a0d0..aa22e45e31 100644
--- a/include/llmr/geometry/vao.hpp
+++ b/include/llmr/geometry/vao.hpp
@@ -7,18 +7,26 @@
namespace llmr {
-template <typename Shader>
class VertexArrayObject {
public:
- template <typename VertexBuffer>
+ template <typename Shader, typename VertexBuffer>
void bind(Shader& shader, VertexBuffer& vertex_buffer, char *offset) {
if (!vao) {
glGenVertexArrays(1, &vao);
glBindVertexArray(vao);
+ } else {
+ // We have been given the correct information.
+ glBindVertexArray(vao);
+ }
+ if (shader_ptr != &shader) {
+ if (shader_ptr != nullptr) {
+ fprintf(stderr, "shader rebind!");
+ }
vertex_buffer.bind();
shader.bind(offset);
+ shader_ptr = &shader;
vertex_buffer_ptr = &vertex_buffer;
elements_buffer_ptr = nullptr;
offset_ptr = offset;
@@ -28,22 +36,25 @@ public:
throw std::runtime_error("trying to bind VAO to another elements buffer");
} else if (offset_ptr != offset) {
throw std::runtime_error("trying to bind VAO to another offset");
- } else {
- // We have been given the correct information.
- glBindVertexArray(vao);
}
}
- template <typename VertexBuffer, typename ElementsBuffer>
+ template <typename Shader, typename VertexBuffer, typename ElementsBuffer>
void bind(Shader& shader, VertexBuffer& vertex_buffer, ElementsBuffer& elements_buffer, char *offset) {
if (!vao) {
glGenVertexArrays(1, &vao);
glBindVertexArray(vao);
+ } else {
+ // We have been given the correct information.
+ glBindVertexArray(vao);
+ }
+ if (shader_ptr != &shader) {
vertex_buffer.bind();
elements_buffer.bind();
shader.bind(offset);
+ shader_ptr = &shader;
vertex_buffer_ptr = &vertex_buffer;
elements_buffer_ptr = &elements_buffer;
offset_ptr = offset;
@@ -53,9 +64,6 @@ public:
throw std::runtime_error("trying to bind VAO to another elements buffer");
} else if (offset_ptr != offset) {
throw std::runtime_error("trying to bind VAO to another offset");
- } else {
- // We have been given the correct information.
- glBindVertexArray(vao);
}
}
@@ -70,6 +78,7 @@ private:
// For debug reasons, we're storing the bind information so that we can
// detect errors and report
+ void *shader_ptr = nullptr;
void *vertex_buffer_ptr = nullptr;
void *elements_buffer_ptr = nullptr;
char *offset_ptr = 0;