diff options
-rw-r--r-- | include/llmr/renderer/painter.hpp | 40 | ||||
-rw-r--r-- | include/llmr/renderer/shader.hpp | 3 | ||||
-rw-r--r-- | src/renderer/painter.cpp | 70 | ||||
-rw-r--r-- | src/renderer/shader-fill.cpp | 3 | ||||
-rw-r--r-- | src/renderer/shader-line.cpp | 5 | ||||
-rw-r--r-- | src/renderer/shader-outline.cpp | 3 | ||||
-rw-r--r-- | src/renderer/shader-pattern.cpp | 3 | ||||
-rw-r--r-- | src/renderer/shader-plain.cpp | 3 |
8 files changed, 35 insertions, 95 deletions
diff --git a/include/llmr/renderer/painter.hpp b/include/llmr/renderer/painter.hpp index 7688763acf..b638fcca18 100644 --- a/include/llmr/renderer/painter.hpp +++ b/include/llmr/renderer/painter.hpp @@ -6,20 +6,19 @@ #include <llmr/geometry/vertex_buffer.hpp> #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> + + namespace llmr { class Transform; class Settings; class Style; class Tile; -// class LayerDescription; - -class Shader; -class PlainShader; -class OutlineShader; -class FillShader; -class LineShader; -class PatternShader; class FillBucket; class LineBucket; @@ -34,29 +33,21 @@ public: Painter& operator=(const Painter&) = delete; Painter& operator=(const Painter && ) = delete; - void setup(); - void clear(); void changeMatrix(const Tile::ID& id); void render(const std::shared_ptr<Tile>& tile); - void renderLayers(const std::shared_ptr<Tile>& tile, const std::vector<LayerDescription>& layers); - void renderDebug(const std::shared_ptr<Tile>& tile); - void renderMatte(); void renderBackground(); void renderFill(FillBucket& bucket, const std::string& layer_name, const Tile::ID& id); void renderLine(LineBucket& bucket, const std::string& layer_name, const Tile::ID& id); - - void drawClippingMask(); - bool switchShader(std::shared_ptr<Shader> shader); - private: void setupShaders(); - -public: + void drawClippingMask(); + void renderLayers(const std::shared_ptr<Tile>& tile, const std::vector<LayerDescription>& layers); + void renderDebug(const std::shared_ptr<Tile>& tile); private: Transform& transform; @@ -67,12 +58,11 @@ private: mat4 matrix; mat4 exMatrix; - std::shared_ptr<Shader> currentShader; - std::shared_ptr<FillShader> fillShader; - std::shared_ptr<PlainShader> plainShader; - std::shared_ptr<OutlineShader> outlineShader; - std::shared_ptr<LineShader> lineShader; - std::shared_ptr<PatternShader> patternShader; + std::unique_ptr<FillShader> fillShader; + std::unique_ptr<PlainShader> plainShader; + std::unique_ptr<OutlineShader> outlineShader; + std::unique_ptr<LineShader> lineShader; + std::unique_ptr<PatternShader> patternShader; // Set up the stencil quad we're using to generate the stencil mask. VertexBuffer tileStencilBuffer = { diff --git a/include/llmr/renderer/shader.hpp b/include/llmr/renderer/shader.hpp index a32d0b647c..26674d2d62 100644 --- a/include/llmr/renderer/shader.hpp +++ b/include/llmr/renderer/shader.hpp @@ -1,7 +1,7 @@ #ifndef LLMR_RENDERER_SHADER #define LLMR_RENDERER_SHADER -#include <forward_list> +#include <cstdint> namespace llmr { @@ -18,7 +18,6 @@ public: bool valid; uint32_t program; - std::forward_list<uint32_t> attributes; private: bool compileShader(uint32_t *shader, uint32_t type, const char *source); diff --git a/src/renderer/painter.cpp b/src/renderer/painter.cpp index 3ef7fbe22b..4a3a4456f4 100644 --- a/src/renderer/painter.cpp +++ b/src/renderer/painter.cpp @@ -1,16 +1,13 @@ #include <cassert> #include <algorithm> -#include <llmr/util/std.hpp> + #include <llmr/renderer/painter.hpp> +#include <llmr/util/std.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> #include <llmr/renderer/fill_bucket.hpp> #include <llmr/renderer/line_bucket.hpp> + #include <llmr/map/transform.hpp> #include <llmr/map/settings.hpp> #include <llmr/geometry/debug_font_buffer.hpp> @@ -25,8 +22,7 @@ using namespace llmr; Painter::Painter(Transform& transform, Settings& settings, Style& style) : transform(transform), settings(settings), - style(style), - currentShader(NULL) { + style(style) { } @@ -48,11 +44,11 @@ void Painter::setup() { } void Painter::setupShaders() { - fillShader = std::make_shared<FillShader>(); - plainShader = std::make_shared<PlainShader>(); - outlineShader = std::make_shared<OutlineShader>(); - lineShader = std::make_shared<LineShader>(); - patternShader = std::make_shared<PatternShader>(); + fillShader = std::make_unique<FillShader>(); + plainShader = std::make_unique<PlainShader>(); + outlineShader = std::make_unique<OutlineShader>(); + lineShader = std::make_unique<LineShader>(); + patternShader = std::make_unique<PatternShader>(); } void Painter::changeMatrix(const Tile::ID& id) { @@ -439,51 +435,3 @@ void Painter::renderBackground() { glUniform4fv(plainShader->u_color, 1, white.data()); glDrawArrays(GL_TRIANGLES, 0, tileStencilBuffer.length()); } - - -// Switches to a different shader program. -/** - * @return boolean whether the shader was actually switched - */ -bool Painter::switchShader(std::shared_ptr<Shader> shader) { - assert(false); - if (currentShader != shader) { - glUseProgram(shader->program); - - // Disable all attributes from the existing shader that aren't used in - // the new shader. Note: attribute indices are *not* program specific! - if (currentShader) { - const std::forward_list<uint32_t>& hitherto = currentShader->attributes; - const std::forward_list<uint32_t>& henceforth = shader->attributes; - - // Find all attribute indices that are used in the old shader, - // but unused in the new one. - for (uint32_t i : hitherto) { - if (std::find(henceforth.begin(), henceforth.end(), i) == henceforth.end()) { - glDisableVertexAttribArray(i); - } - } - - // Enable all attributes for the new shader that were not already in - // use in the old one. - for (uint32_t i : henceforth) { - if (std::find(hitherto.begin(), hitherto.end(), i) == hitherto.end()) { - glEnableVertexAttribArray(i); - } - } - - currentShader = shader; - } else { - // Enable all attributes for the new shader (== first shader). - for (GLuint index : shader->attributes) { - glEnableVertexAttribArray(index); - } - } - - currentShader = shader; - - return true; - } else { - return false; - } -} diff --git a/src/renderer/shader-fill.cpp b/src/renderer/shader-fill.cpp index a5536bf83e..12e851de87 100644 --- a/src/renderer/shader-fill.cpp +++ b/src/renderer/shader-fill.cpp @@ -2,6 +2,8 @@ #include <llmr/shader/shaders.hpp> #include <llmr/platform/gl.hpp> +#include <cstdio> + using namespace llmr; FillShader::FillShader() @@ -15,7 +17,6 @@ FillShader::FillShader() } a_pos = glGetAttribLocation(program, "a_pos"); - attributes.emplace_front(a_pos); u_matrix = glGetUniformLocation(program, "u_matrix"); u_color = glGetUniformLocation(program, "u_color"); diff --git a/src/renderer/shader-line.cpp b/src/renderer/shader-line.cpp index 7a1c0b5a39..cbd2d15d72 100644 --- a/src/renderer/shader-line.cpp +++ b/src/renderer/shader-line.cpp @@ -2,6 +2,8 @@ #include <llmr/shader/shaders.hpp> #include <llmr/platform/gl.hpp> +#include <cstdio> + using namespace llmr; LineShader::LineShader() @@ -15,11 +17,8 @@ LineShader::LineShader() } a_pos = glGetAttribLocation(program, "a_pos"); - attributes.emplace_front(a_pos); a_extrude = glGetAttribLocation(program, "a_extrude"); - attributes.emplace_front(a_extrude); a_linesofar = glGetAttribLocation(program, "a_linesofar"); - attributes.emplace_front(a_linesofar); u_matrix = glGetUniformLocation(program, "u_matrix"); u_exmatrix = glGetUniformLocation(program, "u_exmatrix"); diff --git a/src/renderer/shader-outline.cpp b/src/renderer/shader-outline.cpp index 82f31e1dc2..6add2d231c 100644 --- a/src/renderer/shader-outline.cpp +++ b/src/renderer/shader-outline.cpp @@ -2,6 +2,8 @@ #include <llmr/shader/shaders.hpp> #include <llmr/platform/gl.hpp> +#include <cstdio> + using namespace llmr; OutlineShader::OutlineShader() @@ -15,7 +17,6 @@ OutlineShader::OutlineShader() } a_pos = glGetAttribLocation(program, "a_pos"); - attributes.emplace_front(a_pos); u_matrix = glGetUniformLocation(program, "u_matrix"); u_color = glGetUniformLocation(program, "u_color"); diff --git a/src/renderer/shader-pattern.cpp b/src/renderer/shader-pattern.cpp index 4a921c665b..4f3c252f4a 100644 --- a/src/renderer/shader-pattern.cpp +++ b/src/renderer/shader-pattern.cpp @@ -2,6 +2,8 @@ #include <llmr/shader/shaders.hpp> #include <llmr/platform/gl.hpp> +#include <cstdio> + using namespace llmr; PatternShader::PatternShader() @@ -15,7 +17,6 @@ PatternShader::PatternShader() } a_pos = glGetAttribLocation(program, "a_pos"); - attributes.emplace_front(a_pos); u_matrix = glGetUniformLocation(program, "u_matrix"); u_color = glGetUniformLocation(program, "u_color"); diff --git a/src/renderer/shader-plain.cpp b/src/renderer/shader-plain.cpp index 42c5ea5640..33cf172278 100644 --- a/src/renderer/shader-plain.cpp +++ b/src/renderer/shader-plain.cpp @@ -2,6 +2,8 @@ #include <llmr/shader/shaders.hpp> #include <llmr/platform/gl.hpp> +#include <cstdio> + using namespace llmr; PlainShader::PlainShader() @@ -15,7 +17,6 @@ PlainShader::PlainShader() } a_pos = glGetAttribLocation(program, "a_pos"); - attributes.emplace_front(a_pos); u_matrix = glGetUniformLocation(program, "u_matrix"); u_color = glGetUniformLocation(program, "u_color"); |