From e94cb1b00b81685a958219e749ea638dc087adb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20Ka=CC=88fer?= Date: Wed, 5 Feb 2014 18:35:19 +0100 Subject: [PATCH] remove switchShader() --- include/llmr/renderer/painter.hpp | 40 +++++++---------- include/llmr/renderer/shader.hpp | 3 +- src/renderer/painter.cpp | 72 +++++-------------------------- src/renderer/shader-fill.cpp | 3 +- src/renderer/shader-line.cpp | 5 +-- src/renderer/shader-outline.cpp | 3 +- src/renderer/shader-pattern.cpp | 3 +- src/renderer/shader-plain.cpp | 3 +- 8 files changed, 36 insertions(+), 96 deletions(-) diff --git a/include/llmr/renderer/painter.hpp b/include/llmr/renderer/painter.hpp index 7688763ac..b638fcca1 100644 --- a/include/llmr/renderer/painter.hpp +++ b/include/llmr/renderer/painter.hpp @@ -6,20 +6,19 @@ #include #include +#include +#include +#include +#include +#include + + 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); - void renderLayers(const std::shared_ptr& tile, const std::vector& layers); - void renderDebug(const std::shared_ptr& 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); - private: void setupShaders(); - -public: + void drawClippingMask(); + void renderLayers(const std::shared_ptr& tile, const std::vector& layers); + void renderDebug(const std::shared_ptr& tile); private: Transform& transform; @@ -67,12 +58,11 @@ private: mat4 matrix; mat4 exMatrix; - std::shared_ptr currentShader; - std::shared_ptr fillShader; - std::shared_ptr plainShader; - std::shared_ptr outlineShader; - std::shared_ptr lineShader; - std::shared_ptr patternShader; + std::unique_ptr fillShader; + std::unique_ptr plainShader; + std::unique_ptr outlineShader; + std::unique_ptr lineShader; + std::unique_ptr 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 a32d0b647..26674d2d6 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 +#include namespace llmr { @@ -18,7 +18,6 @@ public: bool valid; uint32_t program; - std::forward_list 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 3ef7fbe22..4a3a4456f 100644 --- a/src/renderer/painter.cpp +++ b/src/renderer/painter.cpp @@ -1,16 +1,13 @@ #include #include -#include -#include -#include -#include -#include -#include -#include +#include +#include + #include #include + #include #include #include @@ -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(); - plainShader = std::make_shared(); - outlineShader = std::make_shared(); - lineShader = std::make_shared(); - patternShader = std::make_shared(); + fillShader = std::make_unique(); + plainShader = std::make_unique(); + outlineShader = std::make_unique(); + lineShader = std::make_unique(); + patternShader = std::make_unique(); } 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) { - 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& hitherto = currentShader->attributes; - const std::forward_list& 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 a5536bf83..12e851de8 100644 --- a/src/renderer/shader-fill.cpp +++ b/src/renderer/shader-fill.cpp @@ -2,6 +2,8 @@ #include #include +#include + 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 7a1c0b5a3..cbd2d15d7 100644 --- a/src/renderer/shader-line.cpp +++ b/src/renderer/shader-line.cpp @@ -2,6 +2,8 @@ #include #include +#include + 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 82f31e1dc..6add2d231 100644 --- a/src/renderer/shader-outline.cpp +++ b/src/renderer/shader-outline.cpp @@ -2,6 +2,8 @@ #include #include +#include + 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 4a921c665..4f3c252f4 100644 --- a/src/renderer/shader-pattern.cpp +++ b/src/renderer/shader-pattern.cpp @@ -2,6 +2,8 @@ #include #include +#include + 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 42c5ea564..33cf17227 100644 --- a/src/renderer/shader-plain.cpp +++ b/src/renderer/shader-plain.cpp @@ -2,6 +2,8 @@ #include #include +#include + 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");