remove switchShader()
This commit is contained in:
@@ -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 = {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -1,16 +1,13 @@
|
||||
#include <cassert>
|
||||
#include <algorithm>
|
||||
|
||||
#include <llmr/util/std.hpp>
|
||||
#include <llmr/renderer/painter.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/painter.hpp>
|
||||
#include <llmr/util/std.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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user