Less shader boilerplate
This commit is contained in:
@@ -88,6 +88,8 @@ public:
|
||||
void renderRaster(RasterBucket& bucket, std::shared_ptr<StyleLayer> layer_desc, const Tile::ID& id, const mat4 &matrix);
|
||||
void renderBackground(std::shared_ptr<StyleLayer> layer_desc);
|
||||
|
||||
float saturationFactor(float saturation);
|
||||
float contrastFactor(float contrast);
|
||||
std::array<float, 3> spinWeights(float spin_value);
|
||||
|
||||
void preparePrerender(RasterBucket &bucket);
|
||||
|
||||
@@ -2,30 +2,23 @@
|
||||
#define MBGL_SHADER_SHADER_DOT
|
||||
|
||||
#include <mbgl/shader/shader.hpp>
|
||||
#include <mbgl/shader/uniform.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
class DotShader : public Shader {
|
||||
public:
|
||||
DotShader();
|
||||
class DotShader : public Shader {
|
||||
public:
|
||||
DotShader();
|
||||
|
||||
void bind(char *offset);
|
||||
void bind(char *offset);
|
||||
|
||||
void setColor(const std::array<float, 4>& color);
|
||||
void setSize(float size);
|
||||
void setBlur(float blur);
|
||||
UniformMatrix<4> u_matrix = {"u_matrix", *this};
|
||||
Uniform<std::array<float, 4>> u_color = {"u_color", *this};
|
||||
Uniform<float> u_size = {"u_size", *this};
|
||||
Uniform<float> u_blur = {"u_blur", *this};
|
||||
|
||||
private:
|
||||
int32_t a_pos = -1;
|
||||
|
||||
std::array<float, 4> color = {{}};
|
||||
int32_t u_color = -1;
|
||||
|
||||
float size = 0;
|
||||
int32_t u_size = -1;
|
||||
|
||||
float blur = 0;
|
||||
int32_t u_blur = -1;
|
||||
private:
|
||||
int32_t a_pos = -1;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define MBGL_RENDERER_SHADER_GAUSSIAN
|
||||
|
||||
#include <mbgl/shader/shader.hpp>
|
||||
#include <mbgl/shader/uniform.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
@@ -11,17 +12,12 @@ public:
|
||||
|
||||
void bind(char *offset);
|
||||
|
||||
void setImage(int32_t image);
|
||||
void setOffset(const std::array<float, 2>& offset);
|
||||
UniformMatrix<4> u_matrix = {"u_matrix", *this};
|
||||
Uniform<std::array<float, 2>> u_offset = {"u_offset", *this};
|
||||
Uniform<int32_t> u_image = {"u_image", *this};
|
||||
|
||||
private:
|
||||
int32_t a_pos = -1;
|
||||
|
||||
int32_t image = 0;
|
||||
int32_t u_image = -1;
|
||||
|
||||
std::array<float, 2> offset = {{}};
|
||||
int32_t u_offset = -1;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define MBGL_SHADER_SHADER_ICON
|
||||
|
||||
#include <mbgl/shader/shader.hpp>
|
||||
#include <mbgl/shader/uniform.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
@@ -11,16 +12,17 @@ public:
|
||||
|
||||
void bind(char *offset);
|
||||
|
||||
void setExtrudeMatrix(const std::array<float, 16>& exmatrix);
|
||||
void setAngle(float angle);
|
||||
void setZoom(float zoom);
|
||||
void setFlip(float flip);
|
||||
void setFadeDist(float fadedist);
|
||||
void setMinFadeZoom(float minfadezoom);
|
||||
void setMaxFadeZoom(float maxfadezoom);
|
||||
void setFadeZoom(float fadezoom);
|
||||
void setOpacity(float opacity);
|
||||
void setTextureSize(const std::array<float, 2> &texsize);
|
||||
UniformMatrix<4> u_matrix = {"u_matrix", *this};
|
||||
UniformMatrix<4> u_exmatrix = {"u_exmatrix", *this};
|
||||
Uniform<float> u_angle = {"u_angle", *this};
|
||||
Uniform<float> u_zoom = {"u_zoom", *this};
|
||||
Uniform<float> u_flip = {"u_flip", *this};
|
||||
Uniform<float> u_fadedist = {"u_fadedist", *this};
|
||||
Uniform<float> u_minfadezoom = {"u_minfadezoom", *this};
|
||||
Uniform<float> u_maxfadezoom = {"u_maxfadezoom", *this};
|
||||
Uniform<float> u_fadezoom = {"u_fadezoom", *this};
|
||||
Uniform<float> u_opacity = {"u_opacity", *this};
|
||||
Uniform<std::array<float, 2>> u_texsize = {"u_texsize", *this};
|
||||
|
||||
private:
|
||||
int32_t a_pos = -1;
|
||||
@@ -32,36 +34,6 @@ private:
|
||||
int32_t a_rangeend = -1;
|
||||
int32_t a_rangestart = -1;
|
||||
int32_t a_labelminzoom = -1;
|
||||
|
||||
std::array<float, 16> exmatrix = {{}};
|
||||
int32_t u_exmatrix = -1;
|
||||
|
||||
float angle = 0;
|
||||
int32_t u_angle = -1;
|
||||
|
||||
float zoom = 0;
|
||||
int32_t u_zoom = -1;
|
||||
|
||||
float flip = 0;
|
||||
int32_t u_flip = -1;
|
||||
|
||||
float fadedist = 0;
|
||||
int32_t u_fadedist = -1;
|
||||
|
||||
float minfadezoom = 0;
|
||||
int32_t u_minfadezoom = -1;
|
||||
|
||||
float maxfadezoom = 0;
|
||||
int32_t u_maxfadezoom = -1;
|
||||
|
||||
float fadezoom = 0;
|
||||
int32_t u_fadezoom = -1;
|
||||
|
||||
float opacity = 0;
|
||||
int32_t u_opacity = -1;
|
||||
|
||||
std::array<float, 2> texsize = {{}};
|
||||
int32_t u_texsize = -1;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define MBGL_SHADER_SHADER_LINE
|
||||
|
||||
#include <mbgl/shader/shader.hpp>
|
||||
#include <mbgl/shader/uniform.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
@@ -11,36 +12,18 @@ public:
|
||||
|
||||
void bind(char *offset);
|
||||
|
||||
void setExtrudeMatrix(const std::array<float, 16>& exmatrix);
|
||||
void setColor(const std::array<float, 4>& color);
|
||||
void setLineWidth(const std::array<float, 2>& linewidth);
|
||||
void setRatio(float ratio);
|
||||
void setDashArray(const std::array<float, 2>& dasharray);
|
||||
void setBlur(float blur);
|
||||
void setDebug(float debug);
|
||||
UniformMatrix<4> u_matrix = {"u_matrix", *this};
|
||||
UniformMatrix<4> u_exmatrix = {"u_exmatrix", *this};
|
||||
Uniform<std::array<float, 4>> u_color = {"u_color", *this};
|
||||
Uniform<std::array<float, 2>> u_linewidth = {"u_linewidth", *this};
|
||||
Uniform<std::array<float, 2>> u_dasharray = {"u_dasharray", *this};
|
||||
Uniform<float> u_ratio = {"u_ratio", *this};
|
||||
Uniform<float> u_blur = {"u_blur", *this};
|
||||
|
||||
private:
|
||||
int32_t a_pos = -1;
|
||||
int32_t a_extrude = -1;
|
||||
int32_t a_linesofar = -1;
|
||||
|
||||
std::array<float, 16> exmatrix = {{}};
|
||||
int32_t u_exmatrix = -1;
|
||||
|
||||
std::array<float, 4> color = {{}};
|
||||
int32_t u_color = -1;
|
||||
|
||||
std::array<float, 2> linewidth = {{}};
|
||||
int32_t u_linewidth = -1;
|
||||
|
||||
float ratio = 0;
|
||||
int32_t u_ratio = -1;
|
||||
|
||||
std::array<float, 2> dasharray = {{}};
|
||||
int32_t u_dasharray = -1;
|
||||
|
||||
float blur = 0.0f;
|
||||
int32_t u_blur = -1;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define MBGL_SHADER_SHADER_LINEJOIN
|
||||
|
||||
#include <mbgl/shader/shader.hpp>
|
||||
#include <mbgl/shader/uniform.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
@@ -11,25 +12,14 @@ public:
|
||||
|
||||
void bind(char *offset);
|
||||
|
||||
void setColor(const std::array<float, 4>& color);
|
||||
void setWorld(const std::array<float, 2>& world);
|
||||
void setLineWidth(const std::array<float, 2>& linewidth);
|
||||
void setSize(float size);
|
||||
UniformMatrix<4> u_matrix = {"u_matrix", *this};
|
||||
Uniform<std::array<float, 4>> u_color = {"u_color", *this};
|
||||
Uniform<std::array<float, 2>> u_world = {"u_world", *this};
|
||||
Uniform<std::array<float, 2>> u_linewidth = {"u_linewidth", *this};
|
||||
Uniform<float> u_size = {"u_size", *this};
|
||||
|
||||
private:
|
||||
int32_t a_pos = -1;
|
||||
|
||||
std::array<float, 4> color = {{}};
|
||||
int32_t u_color = -1;
|
||||
|
||||
std::array<float, 2> world = {{}};
|
||||
int32_t u_world = -1;
|
||||
|
||||
std::array<float, 2> linewidth = {{}};
|
||||
int32_t u_linewidth = -1;
|
||||
|
||||
float size = 0;
|
||||
int32_t u_size = -1;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define MBGL_SHADER_SHADER_LINEPATTERN
|
||||
|
||||
#include <mbgl/shader/shader.hpp>
|
||||
#include <mbgl/shader/uniform.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
@@ -11,47 +12,21 @@ public:
|
||||
|
||||
void bind(char *offset);
|
||||
|
||||
void setExtrudeMatrix(const std::array<float, 16>& exmatrix);
|
||||
void setLineWidth(const std::array<float, 2>& linewidth);
|
||||
void setRatio(float ratio);
|
||||
void setPatternSize(const std::array<float, 2>& new_pattern_size);
|
||||
void setPatternTopLeft(const std::array<float, 2>& new_pattern_tl);
|
||||
void setPatternBottomRight(const std::array<float, 2>& new_pattern_br);
|
||||
void setPoint(float new_point);
|
||||
void setBlur(float new_blur);
|
||||
void setFade(float new_fade);
|
||||
UniformMatrix<4> u_matrix = {"u_posmatrix", *this};
|
||||
UniformMatrix<4> u_exmatrix = {"u_exmatrix", *this};
|
||||
Uniform<std::array<float, 2>> u_linewidth = {"u_linewidth", *this};
|
||||
Uniform<std::array<float, 2>> u_pattern_size = {"u_pattern_size", *this};
|
||||
Uniform<std::array<float, 2>> u_pattern_tl = {"u_pattern_tl", *this};
|
||||
Uniform<std::array<float, 2>> u_pattern_br = {"u_pattern_br", *this};
|
||||
Uniform<float> u_ratio = {"u_ratio", *this};
|
||||
Uniform<float> u_point = {"u_point", *this};
|
||||
Uniform<float> u_blur = {"u_blur", *this};
|
||||
Uniform<float> u_fade = {"u_fade", *this};
|
||||
|
||||
private:
|
||||
int32_t a_pos = -1;
|
||||
int32_t a_extrude = -1;
|
||||
int32_t a_linesofar = -1;
|
||||
|
||||
std::array<float, 16> exmatrix = {{}};
|
||||
int32_t u_exmatrix = -1;
|
||||
|
||||
std::array<float, 2> linewidth = {{}};
|
||||
int32_t u_linewidth = -1;
|
||||
|
||||
float ratio = 0;
|
||||
int32_t u_ratio = -1;
|
||||
|
||||
std::array<float, 2> pattern_size = {{}};
|
||||
int32_t u_pattern_size = -1;
|
||||
|
||||
std::array<float, 2> pattern_tl = {{}};
|
||||
int32_t u_pattern_tl = -1;
|
||||
|
||||
std::array<float, 2> pattern_br = {{}};
|
||||
int32_t u_pattern_br = -1;
|
||||
|
||||
float point = 0.0f;
|
||||
int32_t u_point = -1;
|
||||
|
||||
float blur = 0.0f;
|
||||
int32_t u_blur = -1;
|
||||
|
||||
float fade = 0;
|
||||
int32_t u_fade = -1;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define MBGL_SHADER_SHADER_OUTLINE
|
||||
|
||||
#include <mbgl/shader/shader.hpp>
|
||||
#include <mbgl/shader/uniform.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
@@ -11,17 +12,12 @@ public:
|
||||
|
||||
void bind(char *offset);
|
||||
|
||||
void setColor(const std::array<float, 4>& color);
|
||||
void setWorld(const std::array<float, 2>& world);
|
||||
UniformMatrix<4> u_matrix = {"u_matrix", *this};
|
||||
Uniform<std::array<float, 4>> u_color = {"u_color", *this};
|
||||
Uniform<std::array<float, 2>> u_world = {"u_world", *this};
|
||||
|
||||
private:
|
||||
int32_t a_pos = -1;
|
||||
|
||||
std::array<float, 4> color = {{}};
|
||||
int32_t u_color = -1;
|
||||
|
||||
std::array<float, 2> world = {{}};
|
||||
int32_t u_world = -1;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define MBGL_SHADER_SHADER_PATTERN
|
||||
|
||||
#include <mbgl/shader/shader.hpp>
|
||||
#include <mbgl/shader/uniform.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
@@ -11,33 +12,16 @@ public:
|
||||
|
||||
void bind(char *offset);
|
||||
|
||||
void setPatternTopLeft(const std::array<float, 2>& pattern_tl);
|
||||
void setPatternBottomRight(const std::array<float, 2>& pattern_br);
|
||||
void setOpacity(float opacity);
|
||||
void setImage(int image);
|
||||
void setMix(float mix);
|
||||
void setPatternMatrix(const std::array<float, 9> &patternmatrix);
|
||||
UniformMatrix<4> u_matrix = {"u_matrix", *this};
|
||||
Uniform<std::array<float, 2>> u_pattern_tl = {"u_pattern_tl", *this};
|
||||
Uniform<std::array<float, 2>> u_pattern_br = {"u_pattern_br", *this};
|
||||
Uniform<float> u_opacity = {"u_opacity", *this};
|
||||
Uniform<float> u_mix = {"u_mix", *this};
|
||||
Uniform<int32_t> u_image = {"u_image", *this};
|
||||
UniformMatrix<3> u_patternmatrix = {"u_patternmatrix", *this};
|
||||
|
||||
private:
|
||||
int32_t a_pos = -1;
|
||||
|
||||
std::array<float, 2> pattern_tl = {{}};
|
||||
int32_t u_pattern_tl = -1;
|
||||
|
||||
std::array<float, 2> pattern_br = {{}};
|
||||
int32_t u_pattern_br = -1;
|
||||
|
||||
float opacity = 0;
|
||||
int32_t u_opacity = -1;
|
||||
|
||||
int image = 0;
|
||||
int32_t u_image = -1;
|
||||
|
||||
float mix = 0;
|
||||
int32_t u_mix = -1;
|
||||
|
||||
std::array<float, 9> patternmatrix = {{}};
|
||||
int32_t u_patternmatrix = -1;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define MBGL_SHADER_SHADER_PLAIN
|
||||
|
||||
#include <mbgl/shader/shader.hpp>
|
||||
#include <mbgl/shader/uniform.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
@@ -11,14 +12,11 @@ public:
|
||||
|
||||
void bind(char *offset);
|
||||
|
||||
void setColor(float r, float g, float b, float a);
|
||||
void setColor(const std::array<float, 4>& color);
|
||||
UniformMatrix<4> u_matrix = {"u_matrix", *this};
|
||||
Uniform<std::array<float, 4>> u_color = {"u_color", *this};
|
||||
|
||||
private:
|
||||
int32_t a_pos = -1;
|
||||
|
||||
std::array<float, 4> color = {{}};
|
||||
int32_t u_color = -1;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define MBGL_RENDERER_SHADER_RASTER
|
||||
|
||||
#include <mbgl/shader/shader.hpp>
|
||||
#include <mbgl/shader/uniform.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
@@ -11,41 +12,18 @@ public:
|
||||
|
||||
void bind(char *offset);
|
||||
|
||||
void setImage(int32_t image);
|
||||
void setOpacity(float opacity);
|
||||
void setBuffer(float buffer);
|
||||
void setBrightness(float brightness_low, float brightness_high);
|
||||
void setSaturation(float saturation_factor);
|
||||
void setContrast(float contrast_factor);
|
||||
void setSpin(std::array<float, 3> spin_weights);
|
||||
UniformMatrix<4> u_matrix = {"u_matrix", *this};
|
||||
Uniform<int32_t> u_image = {"u_image", *this};
|
||||
Uniform<float> u_opacity = {"u_opacity", *this};
|
||||
Uniform<float> u_buffer = {"u_buffer", *this};
|
||||
Uniform<float> u_brightness_low = {"u_brightness_low", *this};
|
||||
Uniform<float> u_brightness_high = {"u_brightness_high", *this};
|
||||
Uniform<float> u_saturation_factor = {"u_saturation_factor", *this};
|
||||
Uniform<float> u_contrast_factor = {"u_contrast_factor", *this};
|
||||
Uniform<std::array<float, 3>> u_spin_weights = {"u_spin_weights", *this};
|
||||
|
||||
private:
|
||||
int32_t a_pos = -1;
|
||||
|
||||
int32_t image = 0;
|
||||
int32_t u_image = -1;
|
||||
|
||||
float opacity = 0;
|
||||
int32_t u_opacity = -1;
|
||||
|
||||
float buffer = 0;
|
||||
int32_t u_buffer = -1;
|
||||
|
||||
float brightness_low = 0;
|
||||
int32_t u_brightness_low = -1;
|
||||
|
||||
float brightness_high = 0;
|
||||
int32_t u_brightness_high = -1;
|
||||
|
||||
float saturation_factor = 0;
|
||||
int32_t u_saturation_factor = -1;
|
||||
|
||||
float contrast_factor = 1;
|
||||
int32_t u_contrast_factor = -1;
|
||||
|
||||
std::array<float, 3> spin_weights = {{}};
|
||||
int32_t u_spin_weights = -1;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -15,18 +15,12 @@ public:
|
||||
bool valid;
|
||||
uint32_t program;
|
||||
|
||||
void setMatrix(const std::array<float, 16>& matrix);
|
||||
|
||||
inline uint32_t getID() const {
|
||||
return program;
|
||||
}
|
||||
|
||||
private:
|
||||
bool compileShader(uint32_t *shader, uint32_t type, const char *source);
|
||||
|
||||
protected:
|
||||
std::array<float, 16> matrix = {{}};
|
||||
int32_t u_matrix = -1;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
#ifndef MBGL_SHADER_TEXT_SHADER
|
||||
#define MBGL_SHADER_TEXT_SHADER
|
||||
|
||||
#include "shader.hpp"
|
||||
#include <mbgl/shader/shader.hpp>
|
||||
#include <mbgl/shader/uniform.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
@@ -11,61 +12,25 @@ public:
|
||||
|
||||
void bind(char *offset);
|
||||
|
||||
void setColor(float r, float g, float b, float a);
|
||||
void setColor(const std::array<float, 4> &color);
|
||||
void setBuffer(float buffer);
|
||||
void setGamma(float gamma);
|
||||
void setExtrudeMatrix(const std::array<float, 16> &exmatrix);
|
||||
void setAngle(float angle);
|
||||
void setZoom(float zoom);
|
||||
void setFlip(float flip);
|
||||
void setFadeDist(float fadedist);
|
||||
void setMinFadeZoom(float minfadezoom);
|
||||
void setMaxFadeZoom(float maxfadezoom);
|
||||
void setFadeZoom(float fadezoom);
|
||||
void setTextureSize(const std::array<float, 2> &texsize);
|
||||
UniformMatrix<4> u_matrix = {"u_matrix", *this};
|
||||
UniformMatrix<4> u_exmatrix = {"u_exmatrix", *this};
|
||||
Uniform<std::array<float, 4>> u_color = {"u_color", *this};
|
||||
Uniform<std::array<float, 2>> u_texsize = {"u_texsize", *this};
|
||||
Uniform<float> u_buffer = {"u_buffer", *this};
|
||||
Uniform<float> u_gamma = {"u_gamma", *this};
|
||||
Uniform<float> u_angle = {"u_angle", *this};
|
||||
Uniform<float> u_zoom = {"u_zoom", *this};
|
||||
Uniform<float> u_flip = {"u_flip", *this};
|
||||
Uniform<float> u_fadedist = {"u_fadedist", *this};
|
||||
Uniform<float> u_minfadezoom = {"u_minfadezoom", *this};
|
||||
Uniform<float> u_maxfadezoom = {"u_maxfadezoom", *this};
|
||||
Uniform<float> u_fadezoom = {"u_fadezoom", *this};
|
||||
|
||||
private:
|
||||
int32_t a_pos = -1;
|
||||
int32_t a_offset = -1;
|
||||
int32_t a_data1 = -1;
|
||||
int32_t a_data2 = -1;
|
||||
|
||||
std::array<float, 4> color = {{}};
|
||||
int32_t u_color = -1;
|
||||
|
||||
float buffer = 0.0f;
|
||||
int32_t u_buffer = -1;
|
||||
|
||||
float gamma = 0.0f;
|
||||
int32_t u_gamma = -1;
|
||||
|
||||
std::array<float, 16> exmatrix = {{}};
|
||||
int32_t u_exmatrix = -1;
|
||||
|
||||
float angle = 0.0f;
|
||||
int32_t u_angle = -1;
|
||||
|
||||
float zoom = 0.0f;
|
||||
int32_t u_zoom = -1;
|
||||
|
||||
float flip = 0.0f;
|
||||
int32_t u_flip = -1;
|
||||
|
||||
float fadedist = 0.0f;
|
||||
int32_t u_fadedist = -1;
|
||||
|
||||
float minfadezoom = 0.0f;
|
||||
int32_t u_minfadezoom = -1;
|
||||
|
||||
float maxfadezoom = 0.0f;
|
||||
int32_t u_maxfadezoom = -1;
|
||||
|
||||
float fadezoom = 0.0f;
|
||||
int32_t u_fadezoom = -1;
|
||||
|
||||
std::array<float, 2> texsize = {{}};
|
||||
int32_t u_texsize = -1;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
53
include/mbgl/shader/uniform.hpp
Normal file
53
include/mbgl/shader/uniform.hpp
Normal file
@@ -0,0 +1,53 @@
|
||||
#ifndef MBGL_SHADER_UNIFORM
|
||||
#define MBGL_SHADER_UNIFORM
|
||||
|
||||
#include <mbgl/shader/shader.hpp>
|
||||
#include <mbgl/platform/gl.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
template <typename T>
|
||||
class Uniform {
|
||||
public:
|
||||
Uniform(const GLchar* name, const Shader& shader)
|
||||
: location(glGetUniformLocation(shader.program, name)) {}
|
||||
|
||||
void operator=(const T& t) {
|
||||
if (current != t) {
|
||||
current = t;
|
||||
bind(t);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
void bind(const T&);
|
||||
|
||||
T current;
|
||||
GLint location;
|
||||
};
|
||||
|
||||
template <size_t C, size_t R = C>
|
||||
class UniformMatrix {
|
||||
public:
|
||||
typedef std::array<float, C*R> T;
|
||||
|
||||
UniformMatrix(const GLchar* name, const Shader& shader)
|
||||
: location(glGetUniformLocation(shader.program, name)) {}
|
||||
|
||||
void operator=(const T& t) {
|
||||
if (current != t) {
|
||||
current = t;
|
||||
bind(t);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
void bind(const T&);
|
||||
|
||||
T current;
|
||||
GLint location;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -195,8 +195,8 @@ void Painter::renderBackground(std::shared_ptr<StyleLayer> layer_desc) {
|
||||
|
||||
if ((color[3] >= 1.0f) == (pass == RenderPass::Opaque)) {
|
||||
useProgram(plainShader->program);
|
||||
plainShader->setMatrix(identityMatrix);
|
||||
plainShader->setColor(color);
|
||||
plainShader->u_matrix = identityMatrix;
|
||||
plainShader->u_color = color;
|
||||
backgroundArray.bind(*plainShader, backgroundBuffer, BUFFER_OFFSET(0));
|
||||
|
||||
glDisable(GL_STENCIL_TEST);
|
||||
|
||||
@@ -28,7 +28,7 @@ void Painter::drawClippingMasks(const std::set<std::shared_ptr<StyleSource>> &so
|
||||
}
|
||||
|
||||
void Painter::drawClippingMask(const mat4& matrix, const ClipID &clip) {
|
||||
plainShader->setMatrix(matrix);
|
||||
plainShader->u_matrix = matrix;
|
||||
|
||||
const GLint ref = (GLint)(clip.reference.to_ulong());
|
||||
const GLuint mask = (GLuint)(clip.mask.to_ulong());
|
||||
|
||||
@@ -21,10 +21,10 @@ void Painter::renderDebugText(DebugBucket& bucket, const mat4 &matrix) {
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
|
||||
useProgram(plainShader->program);
|
||||
plainShader->setMatrix(matrix);
|
||||
plainShader->u_matrix = matrix;
|
||||
|
||||
// Draw white outline
|
||||
plainShader->setColor(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
plainShader->u_color = {{ 1.0f, 1.0f, 1.0f, 1.0f }};
|
||||
lineWidth(4.0f * map.getState().getPixelRatio());
|
||||
bucket.drawLines(*plainShader);
|
||||
|
||||
@@ -35,7 +35,7 @@ void Painter::renderDebugText(DebugBucket& bucket, const mat4 &matrix) {
|
||||
#endif
|
||||
|
||||
// Draw black text.
|
||||
plainShader->setColor(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
plainShader->u_color = {{ 0.0f, 0.0f, 0.0f, 1.0f }};
|
||||
lineWidth(2.0f * map.getState().getPixelRatio());
|
||||
bucket.drawLines(*plainShader);
|
||||
|
||||
@@ -51,11 +51,11 @@ void Painter::renderDebugFrame(const mat4 &matrix) {
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
|
||||
useProgram(plainShader->program);
|
||||
plainShader->setMatrix(matrix);
|
||||
plainShader->u_matrix = matrix;
|
||||
|
||||
// draw tile outline
|
||||
tileBorderArray.bind(*plainShader, tileBorderBuffer, BUFFER_OFFSET(0));
|
||||
plainShader->setColor(1.0f, 0.0f, 0.0f, 1.0f);
|
||||
plainShader->u_color = {{ 1.0f, 0.0f, 0.0f, 1.0f }};
|
||||
lineWidth(4.0f * map.getState().getPixelRatio());
|
||||
glDrawArrays(GL_LINE_STRIP, 0, (GLsizei)tileBorderBuffer.index());
|
||||
|
||||
@@ -73,7 +73,7 @@ void Painter::renderDebugText(const std::vector<std::string> &strings) {
|
||||
glStencilFunc(GL_ALWAYS, 0xFF, 0xFF);
|
||||
|
||||
useProgram(plainShader->program);
|
||||
plainShader->setMatrix(nativeMatrix);
|
||||
plainShader->u_matrix = nativeMatrix;
|
||||
|
||||
DebugFontBuffer debugFontBuffer;
|
||||
int line = 25;
|
||||
@@ -86,14 +86,14 @@ void Painter::renderDebugText(const std::vector<std::string> &strings) {
|
||||
// draw debug info
|
||||
VertexArrayObject debugFontArray;
|
||||
debugFontArray.bind(*plainShader, debugFontBuffer, BUFFER_OFFSET(0));
|
||||
plainShader->setColor(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
plainShader->u_color = {{ 1.0f, 1.0f, 1.0f, 1.0f }};
|
||||
lineWidth(4.0f * map.getState().getPixelRatio());
|
||||
glDrawArrays(GL_LINES, 0, (GLsizei)debugFontBuffer.index());
|
||||
#ifndef GL_ES_VERSION_2_0
|
||||
glPointSize(2);
|
||||
glDrawArrays(GL_POINTS, 0, (GLsizei)debugFontBuffer.index());
|
||||
#endif
|
||||
plainShader->setColor(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
plainShader->u_color = {{ 0.0f, 0.0f, 0.0f, 1.0f }};
|
||||
lineWidth(2.0f * map.getState().getPixelRatio());
|
||||
glDrawArrays(GL_LINES, 0, (GLsizei)debugFontBuffer.index());
|
||||
}
|
||||
|
||||
@@ -42,16 +42,16 @@ void Painter::renderFill(FillBucket& bucket, std::shared_ptr<StyleLayer> layer_d
|
||||
// below, we have to draw the outline first (!)
|
||||
if (outline && pass == RenderPass::Translucent) {
|
||||
useProgram(outlineShader->program);
|
||||
outlineShader->setMatrix(vtxMatrix);
|
||||
outlineShader->u_matrix = vtxMatrix;
|
||||
lineWidth(2.0f); // This is always fixed and does not depend on the pixelRatio!
|
||||
|
||||
outlineShader->setColor(stroke_color);
|
||||
outlineShader->u_color = stroke_color;
|
||||
|
||||
// Draw the entire line
|
||||
outlineShader->setWorld({{
|
||||
outlineShader->u_world = {{
|
||||
static_cast<float>(map.getState().getFramebufferWidth()),
|
||||
static_cast<float>(map.getState().getFramebufferHeight())
|
||||
}});
|
||||
}};
|
||||
depthRange(strata, 1.0f);
|
||||
bucket.drawVertices(*outlineShader);
|
||||
}
|
||||
@@ -70,13 +70,13 @@ void Painter::renderFill(FillBucket& bucket, std::shared_ptr<StyleLayer> layer_d
|
||||
matrix::scale(patternMatrix, patternMatrix, 1.0f / (pos.size[0] * factor), 1.0f / (pos.size[1] * factor));
|
||||
|
||||
useProgram(patternShader->program);
|
||||
patternShader->setMatrix(vtxMatrix);
|
||||
patternShader->setPatternTopLeft(pos.tl);
|
||||
patternShader->setPatternBottomRight(pos.br);
|
||||
patternShader->setOpacity(properties.opacity);
|
||||
patternShader->setImage(0);
|
||||
patternShader->setMix(mix);
|
||||
patternShader->setPatternMatrix(patternMatrix);
|
||||
patternShader->u_matrix = vtxMatrix;
|
||||
patternShader->u_pattern_tl = pos.tl;
|
||||
patternShader->u_pattern_br = pos.br;
|
||||
patternShader->u_opacity = properties.opacity;
|
||||
patternShader->u_image = 0;
|
||||
patternShader->u_mix = mix;
|
||||
patternShader->u_patternmatrix = patternMatrix;
|
||||
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
spriteAtlas.bind(true);
|
||||
@@ -94,8 +94,8 @@ void Painter::renderFill(FillBucket& bucket, std::shared_ptr<StyleLayer> layer_d
|
||||
// fragments
|
||||
// Draw filling rectangle.
|
||||
useProgram(plainShader->program);
|
||||
plainShader->setMatrix(vtxMatrix);
|
||||
plainShader->setColor(fill_color);
|
||||
plainShader->u_matrix = vtxMatrix;
|
||||
plainShader->u_color = fill_color;
|
||||
|
||||
// Draw the actual triangles into the color & stencil buffer.
|
||||
depthRange(strata + strata_epsilon, 1.0f);
|
||||
@@ -107,16 +107,16 @@ void Painter::renderFill(FillBucket& bucket, std::shared_ptr<StyleLayer> layer_d
|
||||
// below, we have to draw the outline first (!)
|
||||
if (fringeline && pass == RenderPass::Translucent) {
|
||||
useProgram(outlineShader->program);
|
||||
outlineShader->setMatrix(vtxMatrix);
|
||||
outlineShader->u_matrix = vtxMatrix;
|
||||
lineWidth(2.0f); // This is always fixed and does not depend on the pixelRatio!
|
||||
|
||||
outlineShader->setColor(fill_color);
|
||||
outlineShader->u_color = fill_color;
|
||||
|
||||
// Draw the entire line
|
||||
outlineShader->setWorld({{
|
||||
outlineShader->u_world = {{
|
||||
static_cast<float>(map.getState().getFramebufferWidth()),
|
||||
static_cast<float>(map.getState().getFramebufferHeight())
|
||||
}});
|
||||
}};
|
||||
|
||||
depthRange(strata + strata_epsilon, 1.0f);
|
||||
bucket.drawVertices(*outlineShader);
|
||||
|
||||
@@ -42,22 +42,20 @@ void Painter::renderLine(LineBucket& bucket, std::shared_ptr<StyleLayer> layer_d
|
||||
// We're only drawing end caps + round line joins if the line is > 2px. Otherwise, they aren't visible anyway.
|
||||
if (bucket.hasPoints() && outset > 1.0f) {
|
||||
useProgram(linejoinShader->program);
|
||||
linejoinShader->setMatrix(vtxMatrix);
|
||||
linejoinShader->setColor(color);
|
||||
linejoinShader->setWorld({{
|
||||
map.getState().getFramebufferWidth() * 0.5f,
|
||||
map.getState().getFramebufferHeight() * 0.5f
|
||||
}
|
||||
});
|
||||
linejoinShader->setLineWidth({{
|
||||
((outset - 0.25f) * map.getState().getPixelRatio()),
|
||||
((inset - 0.25f) * map.getState().getPixelRatio())
|
||||
}
|
||||
});
|
||||
linejoinShader->u_matrix = vtxMatrix;
|
||||
linejoinShader->u_color = color;
|
||||
linejoinShader->u_world = {{
|
||||
map.getState().getFramebufferWidth() * 0.5f,
|
||||
map.getState().getFramebufferHeight() * 0.5f
|
||||
}};
|
||||
linejoinShader->u_linewidth = {{
|
||||
((outset - 0.25f) * map.getState().getPixelRatio()),
|
||||
((inset - 0.25f) * map.getState().getPixelRatio())
|
||||
}};
|
||||
|
||||
float pointSize = std::ceil(map.getState().getPixelRatio() * outset * 2.0);
|
||||
#if defined(GL_ES_VERSION_2_0)
|
||||
linejoinShader->setSize(pointSize);
|
||||
linejoinShader->u_size = pointSize;
|
||||
#else
|
||||
glPointSize(pointSize);
|
||||
#endif
|
||||
@@ -73,16 +71,16 @@ void Painter::renderLine(LineBucket& bucket, std::shared_ptr<StyleLayer> layer_d
|
||||
|
||||
useProgram(linepatternShader->program);
|
||||
|
||||
linepatternShader->setMatrix(vtxMatrix);
|
||||
linepatternShader->setExtrudeMatrix(extrudeMatrix);
|
||||
linepatternShader->setLineWidth({{ outset, inset }});
|
||||
linepatternShader->setRatio(ratio);
|
||||
linepatternShader->setBlur(blur);
|
||||
linepatternShader->u_matrix = vtxMatrix;
|
||||
linepatternShader->u_exmatrix = extrudeMatrix;
|
||||
linepatternShader->u_linewidth = {{ outset, inset }};
|
||||
linepatternShader->u_ratio = ratio;
|
||||
linepatternShader->u_blur = blur;
|
||||
|
||||
linepatternShader->setPatternSize({{imagePos.size[0] * factor, imagePos.size[1]}});
|
||||
linepatternShader->setPatternTopLeft(imagePos.tl);
|
||||
linepatternShader->setPatternBottomRight(imagePos.br);
|
||||
linepatternShader->setFade(fade);
|
||||
linepatternShader->u_pattern_size = {{imagePos.size[0] * factor, imagePos.size[1]}};
|
||||
linepatternShader->u_pattern_tl = imagePos.tl;
|
||||
linepatternShader->u_pattern_br = imagePos.br;
|
||||
linepatternShader->u_fade = fade;
|
||||
|
||||
map.getSpriteAtlas()->bind(true);
|
||||
glDepthRange(strata + strata_epsilon, 1.0f); // may or may not matter
|
||||
@@ -92,14 +90,14 @@ void Painter::renderLine(LineBucket& bucket, std::shared_ptr<StyleLayer> layer_d
|
||||
} else {
|
||||
useProgram(lineShader->program);
|
||||
|
||||
lineShader->setMatrix(vtxMatrix);
|
||||
lineShader->setExtrudeMatrix(extrudeMatrix);
|
||||
lineShader->setLineWidth({{ outset, inset }});
|
||||
lineShader->setRatio(ratio);
|
||||
lineShader->setBlur(blur);
|
||||
lineShader->u_matrix = vtxMatrix;
|
||||
lineShader->u_exmatrix = extrudeMatrix;
|
||||
lineShader->u_linewidth = {{ outset, inset }};
|
||||
lineShader->u_ratio = ratio;
|
||||
lineShader->u_blur = blur;
|
||||
|
||||
lineShader->setColor(color);
|
||||
lineShader->setDashArray({{ dash_length, dash_gap }});
|
||||
lineShader->u_color = color;
|
||||
lineShader->u_dasharray = {{ dash_length, dash_gap }};
|
||||
|
||||
bucket.drawLines(*lineShader);
|
||||
}
|
||||
|
||||
@@ -25,19 +25,20 @@ void Painter::renderPrerenderedTexture(RasterBucket &bucket, const mat4 &matrix,
|
||||
|
||||
// draw the texture on a quad
|
||||
useProgram(rasterShader->program);
|
||||
rasterShader->setMatrix(matrix);
|
||||
rasterShader->setOpacity(1);
|
||||
rasterShader->u_matrix = matrix;
|
||||
rasterShader->u_opacity = 1;
|
||||
|
||||
depthRange(strata, 1.0f);
|
||||
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
rasterShader->setImage(0);
|
||||
rasterShader->setBuffer(buffer);
|
||||
rasterShader->setOpacity(properties.opacity);
|
||||
rasterShader->setBrightness(properties.brightness[0], properties.brightness[1]);
|
||||
rasterShader->setSaturation(properties.saturation);
|
||||
rasterShader->setContrast(properties.contrast);
|
||||
rasterShader->setSpin(spinWeights(properties.hue_rotate));
|
||||
rasterShader->u_image = 0;
|
||||
rasterShader->u_buffer = buffer;
|
||||
rasterShader->u_opacity = properties.opacity;
|
||||
rasterShader->u_brightness_low = properties.brightness[0];
|
||||
rasterShader->u_brightness_high = properties.brightness[1];
|
||||
rasterShader->u_saturation_factor = saturationFactor(properties.saturation);
|
||||
rasterShader->u_contrast_factor = contrastFactor(properties.contrast);
|
||||
rasterShader->u_spin_weights = spinWeights(properties.hue_rotate);
|
||||
bucket.texture.bindTexture();
|
||||
coveringRasterArray.bind(*rasterShader, tileStencilBuffer, BUFFER_OFFSET(0));
|
||||
glDrawArrays(GL_TRIANGLES, 0, (GLsizei)tileStencilBuffer.index());
|
||||
|
||||
@@ -63,13 +63,14 @@ void Painter::renderRaster(RasterBucket& bucket, std::shared_ptr<StyleLayer> lay
|
||||
depthMask(false);
|
||||
|
||||
useProgram(rasterShader->program);
|
||||
rasterShader->setMatrix(matrix);
|
||||
rasterShader->setBuffer(0);
|
||||
rasterShader->setOpacity(properties.opacity);
|
||||
rasterShader->setBrightness(properties.brightness[0], properties.brightness[1]);
|
||||
rasterShader->setSaturation(properties.saturation);
|
||||
rasterShader->setContrast(properties.contrast);
|
||||
rasterShader->setSpin(spinWeights(properties.hue_rotate));
|
||||
rasterShader->u_matrix = matrix;
|
||||
rasterShader->u_buffer = 0;
|
||||
rasterShader->u_opacity = properties.opacity;
|
||||
rasterShader->u_brightness_low = properties.brightness[0];
|
||||
rasterShader->u_brightness_high = properties.brightness[1];
|
||||
rasterShader->u_saturation_factor = saturationFactor(properties.saturation);
|
||||
rasterShader->u_contrast_factor = contrastFactor(properties.contrast);
|
||||
rasterShader->u_spin_weights = spinWeights(properties.hue_rotate);
|
||||
|
||||
depthRange(strata + strata_epsilon, 1.0f);
|
||||
|
||||
@@ -80,6 +81,22 @@ void Painter::renderRaster(RasterBucket& bucket, std::shared_ptr<StyleLayer> lay
|
||||
|
||||
}
|
||||
|
||||
float Painter::saturationFactor(float saturation) {
|
||||
if (saturation > 0) {
|
||||
return 1 - 1 / (1.001 - saturation);
|
||||
} else {
|
||||
return -saturation;
|
||||
}
|
||||
}
|
||||
|
||||
float Painter::contrastFactor(float contrast) {
|
||||
if (contrast > 0) {
|
||||
return 1 / (1 - contrast);
|
||||
} else {
|
||||
return 1 + contrast;
|
||||
}
|
||||
}
|
||||
|
||||
std::array<float, 3> Painter::spinWeights(float spin) {
|
||||
spin *= M_PI / 180;
|
||||
float s = std::sin(spin);
|
||||
|
||||
@@ -33,13 +33,15 @@ void Painter::renderSymbol(SymbolBucket &bucket, std::shared_ptr<StyleLayer> lay
|
||||
matrix::scale(exMatrix, exMatrix, fontSize / 24.0f, fontSize / 24.0f, 1.0f);
|
||||
|
||||
useProgram(textShader->program);
|
||||
textShader->setMatrix(vtxMatrix);
|
||||
textShader->setExtrudeMatrix(exMatrix);
|
||||
textShader->u_matrix = vtxMatrix;
|
||||
textShader->u_exmatrix = exMatrix;
|
||||
|
||||
GlyphAtlas &glyphAtlas = *map.getGlyphAtlas();
|
||||
glyphAtlas.bind();
|
||||
textShader->setTextureSize(
|
||||
{{static_cast<float>(glyphAtlas.width), static_cast<float>(glyphAtlas.height)}});
|
||||
textShader->u_texsize = {{
|
||||
static_cast<float>(glyphAtlas.width),
|
||||
static_cast<float>(glyphAtlas.height)
|
||||
}};
|
||||
|
||||
// Convert the -pi..pi to an int8 range.
|
||||
float angle = std::round((map.getState().getAngle()) / M_PI * 128);
|
||||
@@ -47,10 +49,9 @@ void Painter::renderSymbol(SymbolBucket &bucket, std::shared_ptr<StyleLayer> lay
|
||||
// adjust min/max zooms for variable font sies
|
||||
float zoomAdjust = log(fontSize / bucket.properties.text.max_size) / log(2);
|
||||
|
||||
textShader->setAngle((int32_t)(angle + 256) % 256);
|
||||
textShader->setFlip(bucket.properties.placement == PlacementType::Line ? 1 : 0);
|
||||
textShader->setZoom((map.getState().getNormalizedZoom() - zoomAdjust) *
|
||||
10); // current zoom level
|
||||
textShader->u_angle = (int32_t)(angle + 256) % 256;
|
||||
textShader->u_flip = (bucket.properties.placement == PlacementType::Line ? 1 : 0);
|
||||
textShader->u_zoom = (map.getState().getNormalizedZoom() - zoomAdjust) * 10; // current zoom level
|
||||
|
||||
// Label fading
|
||||
const timestamp duration = 300_milliseconds;
|
||||
@@ -83,10 +84,10 @@ void Painter::renderSymbol(SymbolBucket &bucket, std::shared_ptr<StyleLayer> lay
|
||||
// bump is how much farther it would have been if it had continued zooming at the same rate
|
||||
float bump = (currentTime - lastFrame.t) / duration * fadedist;
|
||||
|
||||
textShader->setFadeDist(fadedist * 10);
|
||||
textShader->setMinFadeZoom(std::floor(lowZ * 10));
|
||||
textShader->setMaxFadeZoom(std::floor(highZ * 10));
|
||||
textShader->setFadeZoom((map.getState().getNormalizedZoom() + bump) * 10);
|
||||
textShader->u_fadedist = fadedist * 10;
|
||||
textShader->u_minfadezoom = std::floor(lowZ * 10);
|
||||
textShader->u_maxfadezoom = std::floor(highZ * 10);
|
||||
textShader->u_fadezoom = (map.getState().getNormalizedZoom() + bump) * 10;
|
||||
}
|
||||
|
||||
// This defines the gamma around the SDF cutoff value.
|
||||
@@ -121,10 +122,9 @@ void Painter::renderSymbol(SymbolBucket &bucket, std::shared_ptr<StyleLayer> lay
|
||||
// Note that this does *not* have to be adjusted for retina screens, because we want
|
||||
// the
|
||||
// same blur width when we explicitly specify one.
|
||||
textShader->setGamma((properties.text.halo_blur / (fontSize / sdfFontSize)) / 8.0f /
|
||||
2.0f);
|
||||
textShader->u_gamma = (properties.text.halo_blur / (fontSize / sdfFontSize)) / 8.0f / 2.0f;
|
||||
} else {
|
||||
textShader->setGamma(sdfGamma);
|
||||
textShader->u_gamma = sdfGamma;
|
||||
}
|
||||
|
||||
if (properties.text.opacity < 1.0f) {
|
||||
@@ -133,29 +133,29 @@ void Painter::renderSymbol(SymbolBucket &bucket, std::shared_ptr<StyleLayer> lay
|
||||
color[1] *= properties.text.opacity;
|
||||
color[2] *= properties.text.opacity;
|
||||
color[3] *= properties.text.opacity;
|
||||
textShader->setColor(color);
|
||||
textShader->u_color = color;
|
||||
} else {
|
||||
textShader->setColor(properties.text.halo_color);
|
||||
textShader->u_color = properties.text.halo_color;
|
||||
}
|
||||
textShader->setBuffer(haloWidth);
|
||||
textShader->u_buffer = haloWidth;
|
||||
depthRange(strata, 1.0f);
|
||||
bucket.drawGlyphs(*textShader);
|
||||
}
|
||||
|
||||
if (properties.text.color[3] > 0.0f) {
|
||||
// Then, we draw the text over the halo
|
||||
textShader->setGamma(gamma);
|
||||
textShader->u_gamma = gamma;
|
||||
if (properties.text.opacity < 1.0f) {
|
||||
Color color = properties.text.color;
|
||||
color[0] *= properties.text.opacity;
|
||||
color[1] *= properties.text.opacity;
|
||||
color[2] *= properties.text.opacity;
|
||||
color[3] *= properties.text.opacity;
|
||||
textShader->setColor(color);
|
||||
textShader->u_color = color;
|
||||
} else {
|
||||
textShader->setColor(properties.text.color);
|
||||
textShader->u_color = properties.text.color;
|
||||
}
|
||||
textShader->setBuffer((256.0f - 64.0f) / 256.0f);
|
||||
textShader->u_buffer = (256.0f - 64.0f) / 256.0f;
|
||||
depthRange(strata + strata_epsilon, 1.0f);
|
||||
bucket.drawGlyphs(*textShader);
|
||||
}
|
||||
@@ -182,13 +182,15 @@ void Painter::renderSymbol(SymbolBucket &bucket, std::shared_ptr<StyleLayer> lay
|
||||
matrix::scale(exMatrix, exMatrix, fontScale, fontScale, 1.0f);
|
||||
|
||||
useProgram(iconShader->program);
|
||||
iconShader->setMatrix(vtxMatrix);
|
||||
iconShader->setExtrudeMatrix(exMatrix);
|
||||
iconShader->u_matrix = vtxMatrix;
|
||||
iconShader->u_exmatrix = exMatrix;
|
||||
|
||||
SpriteAtlas &spriteAtlas = *map.getSpriteAtlas();
|
||||
spriteAtlas.bind(map.getState().isChanging() || bucket.properties.placement == PlacementType::Line || angleOffset != 0 || fontScale != 1);
|
||||
iconShader->setTextureSize(
|
||||
{{static_cast<float>(spriteAtlas.getWidth()), static_cast<float>(spriteAtlas.getHeight())}});
|
||||
iconShader->u_texsize = {{
|
||||
static_cast<float>(spriteAtlas.getWidth()),
|
||||
static_cast<float>(spriteAtlas.getHeight())
|
||||
}};
|
||||
|
||||
// Convert the -pi..pi to an int8 range.
|
||||
const float angle = std::round((map.getState().getAngle()) / M_PI * 128);
|
||||
@@ -196,16 +198,15 @@ void Painter::renderSymbol(SymbolBucket &bucket, std::shared_ptr<StyleLayer> lay
|
||||
// adjust min/max zooms for variable font sies
|
||||
float zoomAdjust = log(fontSize / bucket.properties.icon.max_size) / log(2);
|
||||
|
||||
iconShader->setAngle((int32_t)(angle + 256) % 256);
|
||||
iconShader->setFlip(bucket.properties.placement == PlacementType::Line ? 1 : 0);
|
||||
iconShader->setZoom((map.getState().getNormalizedZoom() - zoomAdjust) *
|
||||
10); // current zoom level
|
||||
iconShader->u_angle = (int32_t)(angle + 256) % 256;
|
||||
iconShader->u_flip = bucket.properties.placement == PlacementType::Line ? 1 : 0;
|
||||
iconShader->u_zoom = (map.getState().getNormalizedZoom() - zoomAdjust) * 10; // current zoom level
|
||||
|
||||
iconShader->setFadeDist(0 * 10);
|
||||
iconShader->setMinFadeZoom(map.getState().getNormalizedZoom() * 10);
|
||||
iconShader->setMaxFadeZoom(map.getState().getNormalizedZoom() * 10);
|
||||
iconShader->setFadeZoom(map.getState().getNormalizedZoom() * 10);
|
||||
iconShader->setOpacity(properties.icon.opacity);
|
||||
iconShader->u_fadedist = 0 * 10;
|
||||
iconShader->u_minfadezoom = map.getState().getNormalizedZoom() * 10;
|
||||
iconShader->u_maxfadezoom = map.getState().getNormalizedZoom() * 10;
|
||||
iconShader->u_fadezoom = map.getState().getNormalizedZoom() * 10;
|
||||
iconShader->u_opacity = properties.icon.opacity;
|
||||
|
||||
depthRange(strata, 1.0f);
|
||||
bucket.drawIcons(*iconShader);
|
||||
|
||||
@@ -110,8 +110,8 @@ void PrerenderedTexture::blur(Painter& painter, uint16_t passes) {
|
||||
|
||||
|
||||
painter.useProgram(painter.gaussianShader->program);
|
||||
painter.gaussianShader->setMatrix(painter.flipMatrix);
|
||||
painter.gaussianShader->setImage(0);
|
||||
painter.gaussianShader->u_matrix = painter.flipMatrix;
|
||||
painter.gaussianShader->u_image = 0;
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
|
||||
for (int i = 0; i < passes; i++) {
|
||||
@@ -123,7 +123,7 @@ void PrerenderedTexture::blur(Painter& painter, uint16_t passes) {
|
||||
#endif
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
painter.gaussianShader->setOffset({{ 1.0f / float(properties.size), 0 }});
|
||||
painter.gaussianShader->u_offset = {{ 1.0f / float(properties.size), 0 }};
|
||||
glBindTexture(GL_TEXTURE_2D, original_texture);
|
||||
painter.coveringGaussianArray.bind(*painter.gaussianShader, painter.tileStencilBuffer, BUFFER_OFFSET(0));
|
||||
glDrawArrays(GL_TRIANGLES, 0, (GLsizei)painter.tileStencilBuffer.index());
|
||||
@@ -137,7 +137,7 @@ void PrerenderedTexture::blur(Painter& painter, uint16_t passes) {
|
||||
#endif
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
painter.gaussianShader->setOffset({{ 0, 1.0f / float(properties.size) }});
|
||||
painter.gaussianShader->u_offset = {{ 0, 1.0f / float(properties.size) }};
|
||||
glBindTexture(GL_TEXTURE_2D, secondary_texture);
|
||||
painter.coveringGaussianArray.bind(*painter.gaussianShader, painter.tileStencilBuffer, BUFFER_OFFSET(0));
|
||||
glDrawArrays(GL_TRIANGLES, 0, (GLsizei)painter.tileStencilBuffer.index());
|
||||
|
||||
@@ -19,14 +19,14 @@ bool RasterBucket::setImage(const std::string &data) {
|
||||
|
||||
void RasterBucket::drawRaster(RasterShader& shader, StaticVertexBuffer &vertices, VertexArrayObject &array) {
|
||||
raster.bind(true);
|
||||
shader.setImage(0);
|
||||
shader.u_image = 0;
|
||||
array.bind(shader, vertices, BUFFER_OFFSET(0));
|
||||
glDrawArrays(GL_TRIANGLES, 0, (GLsizei)vertices.index());
|
||||
}
|
||||
|
||||
void RasterBucket::drawRaster(RasterShader& shader, StaticVertexBuffer &vertices, VertexArrayObject &array, GLuint texture) {
|
||||
raster.bind(texture);
|
||||
shader.setImage(0);
|
||||
shader.u_image = 0;
|
||||
array.bind(shader, vertices, BUFFER_OFFSET(0));
|
||||
glDrawArrays(GL_TRIANGLES, 0, (GLsizei)vertices.index());
|
||||
}
|
||||
|
||||
@@ -18,41 +18,9 @@ DotShader::DotShader()
|
||||
}
|
||||
|
||||
a_pos = glGetAttribLocation(program, "a_pos");
|
||||
|
||||
u_matrix = glGetUniformLocation(program, "u_matrix");
|
||||
u_color = glGetUniformLocation(program, "u_color");
|
||||
u_size = glGetUniformLocation(program, "u_size");
|
||||
u_blur = glGetUniformLocation(program, "u_blur");
|
||||
|
||||
// fprintf(stderr, "DotShader:\n");
|
||||
// fprintf(stderr, " - u_matrix: %d\n", u_matrix);
|
||||
// fprintf(stderr, " - u_color: %d\n", u_color);
|
||||
// fprintf(stderr, " - u_size: %d\n", u_size);
|
||||
// fprintf(stderr, " - u_blur: %d\n", u_blur);
|
||||
}
|
||||
|
||||
void DotShader::bind(char *offset) {
|
||||
glEnableVertexAttribArray(a_pos);
|
||||
glVertexAttribPointer(a_pos, 2, GL_SHORT, false, 8, offset);
|
||||
}
|
||||
|
||||
void DotShader::setColor(const std::array<float, 4>& new_color) {
|
||||
if (color != new_color) {
|
||||
glUniform4fv(u_color, 1, new_color.data());
|
||||
color = new_color;
|
||||
}
|
||||
}
|
||||
|
||||
void DotShader::setSize(float new_size) {
|
||||
if (size != new_size) {
|
||||
glUniform1f(u_size, new_size);
|
||||
size = new_size;
|
||||
}
|
||||
}
|
||||
|
||||
void DotShader::setBlur(float new_blur) {
|
||||
if (blur != new_blur) {
|
||||
glUniform1f(u_blur, new_blur);
|
||||
blur = new_blur;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,32 +20,9 @@ GaussianShader::GaussianShader()
|
||||
}
|
||||
|
||||
a_pos = glGetAttribLocation(program, "a_pos");
|
||||
|
||||
u_matrix = glGetUniformLocation(program, "u_matrix");
|
||||
u_image = glGetUniformLocation(program, "u_image");
|
||||
u_offset = glGetUniformLocation(program, "u_offset");
|
||||
|
||||
// fprintf(stderr, "GaussianShader:\n");
|
||||
// fprintf(stderr, " - u_matrix: %d\n", u_matrix);
|
||||
// fprintf(stderr, " - u_image: %d\n", u_image);
|
||||
// fprintf(stderr, " - u_gaussian: %f\n", u_gaussian);
|
||||
}
|
||||
|
||||
void GaussianShader::bind(char *offset) {
|
||||
glEnableVertexAttribArray(a_pos);
|
||||
glVertexAttribPointer(a_pos, 2, GL_SHORT, false, 0, offset);
|
||||
}
|
||||
|
||||
void GaussianShader::setImage(int32_t new_image) {
|
||||
if (image != new_image) {
|
||||
glUniform1i(u_image, new_image);
|
||||
image = new_image;
|
||||
}
|
||||
}
|
||||
|
||||
void GaussianShader::setOffset(const std::array<float, 2>& new_offset) {
|
||||
if (offset != new_offset) {
|
||||
glUniform2fv(u_offset, 1, new_offset.data());
|
||||
offset = new_offset;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,30 +26,6 @@ IconShader::IconShader()
|
||||
a_rangeend = glGetAttribLocation(program, "a_rangeend");
|
||||
a_rangestart = glGetAttribLocation(program, "a_rangestart");
|
||||
a_labelminzoom = glGetAttribLocation(program, "a_labelminzoom");
|
||||
|
||||
u_matrix = glGetUniformLocation(program, "u_matrix");
|
||||
u_exmatrix = glGetUniformLocation(program, "u_exmatrix");
|
||||
u_angle = glGetUniformLocation(program, "u_angle");
|
||||
u_zoom = glGetUniformLocation(program, "u_zoom");
|
||||
u_flip = glGetUniformLocation(program, "u_flip");
|
||||
u_fadedist = glGetUniformLocation(program, "u_fadedist");
|
||||
u_minfadezoom = glGetUniformLocation(program, "u_minfadezoom");
|
||||
u_maxfadezoom = glGetUniformLocation(program, "u_maxfadezoom");
|
||||
u_fadezoom = glGetUniformLocation(program, "u_fadezoom");
|
||||
u_opacity = glGetUniformLocation(program, "u_opacity");
|
||||
u_texsize = glGetUniformLocation(program, "u_texsize");
|
||||
|
||||
// fprintf(stderr, "IconShader:\n");
|
||||
// fprintf(stderr, " - u_matrix: %d\n", u_matrix);
|
||||
// fprintf(stderr, " - u_exmatrix: %d\n", u_exmatrix);
|
||||
// fprintf(stderr, " - u_angle: %d\n", u_angle);
|
||||
// fprintf(stderr, " - u_zoom: %d\n", u_zoom);
|
||||
// fprintf(stderr, " - u_flip: %d\n", u_flip);
|
||||
// fprintf(stderr, " - u_fadedist: %d\n", u_fadedist);
|
||||
// fprintf(stderr, " - u_minfadezoom: %d\n", u_minfadezoom);
|
||||
// fprintf(stderr, " - u_maxfadezoom: %d\n", u_maxfadezoom);
|
||||
// fprintf(stderr, " - u_fadezoom: %d\n", u_fadezoom);
|
||||
// fprintf(stderr, " - u_opacity: %d\n", u_opacity);
|
||||
}
|
||||
|
||||
void IconShader::bind(char *offset) {
|
||||
@@ -82,74 +58,3 @@ void IconShader::bind(char *offset) {
|
||||
glEnableVertexAttribArray(a_tex);
|
||||
glVertexAttribPointer(a_tex, 2, GL_SHORT, false, stride, offset + 16);
|
||||
}
|
||||
|
||||
void IconShader::setExtrudeMatrix(const std::array<float, 16>& new_exmatrix) {
|
||||
if (exmatrix != new_exmatrix) {
|
||||
glUniformMatrix4fv(u_exmatrix, 1, GL_FALSE, new_exmatrix.data());
|
||||
exmatrix = new_exmatrix;
|
||||
}
|
||||
}
|
||||
|
||||
void IconShader::setAngle(float new_angle) {
|
||||
if (angle != new_angle) {
|
||||
glUniform1f(u_angle, new_angle);
|
||||
angle = new_angle;
|
||||
}
|
||||
}
|
||||
|
||||
void IconShader::setZoom(float new_zoom) {
|
||||
if (zoom != new_zoom) {
|
||||
glUniform1f(u_zoom, new_zoom);
|
||||
zoom = new_zoom;
|
||||
}
|
||||
}
|
||||
|
||||
void IconShader::setFlip(float new_flip) {
|
||||
if (flip != new_flip) {
|
||||
glUniform1f(u_flip, new_flip);
|
||||
flip = new_flip;
|
||||
}
|
||||
}
|
||||
|
||||
void IconShader::setFadeDist(float new_fadedist) {
|
||||
if (fadedist != new_fadedist) {
|
||||
glUniform1f(u_fadedist, new_fadedist);
|
||||
fadedist = new_fadedist;
|
||||
}
|
||||
}
|
||||
|
||||
void IconShader::setMinFadeZoom(float new_minfadezoom) {
|
||||
if (minfadezoom != new_minfadezoom) {
|
||||
glUniform1f(u_minfadezoom, new_minfadezoom);
|
||||
minfadezoom = new_minfadezoom;
|
||||
}
|
||||
}
|
||||
|
||||
void IconShader::setMaxFadeZoom(float new_maxfadezoom) {
|
||||
if (maxfadezoom != new_maxfadezoom) {
|
||||
glUniform1f(u_maxfadezoom, new_maxfadezoom);
|
||||
maxfadezoom = new_maxfadezoom;
|
||||
}
|
||||
}
|
||||
|
||||
void IconShader::setFadeZoom(float new_fadezoom) {
|
||||
if (fadezoom != new_fadezoom) {
|
||||
glUniform1f(u_fadezoom, new_fadezoom);
|
||||
fadezoom = new_fadezoom;
|
||||
}
|
||||
}
|
||||
|
||||
void IconShader::setOpacity(float new_opacity) {
|
||||
if (opacity != new_opacity) {
|
||||
glUniform1f(u_opacity, new_opacity);
|
||||
opacity = new_opacity;
|
||||
}
|
||||
}
|
||||
|
||||
void IconShader::setTextureSize(const std::array<float, 2> &new_texsize) {
|
||||
if (texsize != new_texsize) {
|
||||
glUniform2fv(u_texsize, 1, new_texsize.data());
|
||||
texsize = new_texsize;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,22 +20,6 @@ LineShader::LineShader()
|
||||
a_pos = glGetAttribLocation(program, "a_pos");
|
||||
a_extrude = glGetAttribLocation(program, "a_extrude");
|
||||
a_linesofar = glGetAttribLocation(program, "a_linesofar");
|
||||
|
||||
u_matrix = glGetUniformLocation(program, "u_matrix");
|
||||
u_exmatrix = glGetUniformLocation(program, "u_exmatrix");
|
||||
u_linewidth = glGetUniformLocation(program, "u_linewidth");
|
||||
u_color = glGetUniformLocation(program, "u_color");
|
||||
u_ratio = glGetUniformLocation(program, "u_ratio");
|
||||
u_dasharray = glGetUniformLocation(program, "u_dasharray");
|
||||
u_blur = glGetUniformLocation(program, "u_blur");
|
||||
|
||||
// fprintf(stderr, "LineShader:\n");
|
||||
// fprintf(stderr, " - u_matrix: %d\n", u_matrix);
|
||||
// fprintf(stderr, " - u_exmatrix: %d\n", u_exmatrix);
|
||||
// fprintf(stderr, " - u_linewidth: %d\n", u_linewidth);
|
||||
// fprintf(stderr, " - u_color: %d\n", u_color);
|
||||
// fprintf(stderr, " - u_ratio: %d\n", u_ratio);
|
||||
// fprintf(stderr, " - u_dasharray: %d\n", u_dasharray);
|
||||
}
|
||||
|
||||
void LineShader::bind(char *offset) {
|
||||
@@ -48,45 +32,3 @@ void LineShader::bind(char *offset) {
|
||||
glEnableVertexAttribArray(a_linesofar);
|
||||
glVertexAttribPointer(a_linesofar, 1, GL_SHORT, false, 8, offset + 6);
|
||||
}
|
||||
|
||||
void LineShader::setExtrudeMatrix(const std::array<float, 16>& new_exmatrix) {
|
||||
if (exmatrix != new_exmatrix) {
|
||||
glUniformMatrix4fv(u_exmatrix, 1, GL_FALSE, new_exmatrix.data());
|
||||
exmatrix = new_exmatrix;
|
||||
}
|
||||
}
|
||||
|
||||
void LineShader::setColor(const std::array<float, 4>& new_color) {
|
||||
if (color != new_color) {
|
||||
glUniform4fv(u_color, 1, new_color.data());
|
||||
color = new_color;
|
||||
}
|
||||
}
|
||||
|
||||
void LineShader::setLineWidth(const std::array<float, 2>& new_linewidth) {
|
||||
if (linewidth != new_linewidth) {
|
||||
glUniform2fv(u_linewidth, 1, new_linewidth.data());
|
||||
linewidth = new_linewidth;
|
||||
}
|
||||
}
|
||||
|
||||
void LineShader::setRatio(float new_ratio) {
|
||||
if (ratio != new_ratio) {
|
||||
glUniform1f(u_ratio, new_ratio);
|
||||
ratio = new_ratio;
|
||||
}
|
||||
}
|
||||
|
||||
void LineShader::setDashArray(const std::array<float, 2>& new_dasharray) {
|
||||
if (dasharray != new_dasharray) {
|
||||
glUniform2fv(u_dasharray, 1, new_dasharray.data());
|
||||
dasharray = new_dasharray;
|
||||
}
|
||||
}
|
||||
|
||||
void LineShader::setBlur(float new_blur) {
|
||||
if (blur != new_blur) {
|
||||
glUniform1f(u_blur, new_blur);
|
||||
blur = new_blur;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,19 +18,6 @@ LinejoinShader::LinejoinShader()
|
||||
}
|
||||
|
||||
a_pos = glGetAttribLocation(program, "a_pos");
|
||||
|
||||
u_matrix = glGetUniformLocation(program, "u_matrix");
|
||||
u_world = glGetUniformLocation(program, "u_world");
|
||||
u_linewidth = glGetUniformLocation(program, "u_linewidth");
|
||||
u_color = glGetUniformLocation(program, "u_color");
|
||||
u_size = glGetUniformLocation(program, "u_size");
|
||||
|
||||
// fprintf(stderr, "LinejoinShader:\n");
|
||||
// fprintf(stderr, " - u_matrix: %d\n", u_matrix);
|
||||
// fprintf(stderr, " - u_world: %d\n", u_world);
|
||||
// fprintf(stderr, " - u_linewidth: %d\n", u_linewidth);
|
||||
// fprintf(stderr, " - u_color: %d\n", u_color);
|
||||
// fprintf(stderr, " - u_size: %d\n", u_size);
|
||||
}
|
||||
|
||||
void LinejoinShader::bind(char *offset) {
|
||||
@@ -38,31 +25,3 @@ void LinejoinShader::bind(char *offset) {
|
||||
// Note: We're referring to the vertices in a line array, which are 8 bytes long!
|
||||
glVertexAttribPointer(a_pos, 2, GL_SHORT, false, 8, offset);
|
||||
}
|
||||
|
||||
void LinejoinShader::setColor(const std::array<float, 4>& new_color) {
|
||||
if (color != new_color) {
|
||||
glUniform4fv(u_color, 1, new_color.data());
|
||||
color = new_color;
|
||||
}
|
||||
}
|
||||
|
||||
void LinejoinShader::setWorld(const std::array<float, 2>& new_world) {
|
||||
if (world != new_world) {
|
||||
glUniform2fv(u_world, 1, new_world.data());
|
||||
world = new_world;
|
||||
}
|
||||
}
|
||||
|
||||
void LinejoinShader::setLineWidth(const std::array<float, 2>& new_linewidth) {
|
||||
if (linewidth != new_linewidth) {
|
||||
glUniform2fv(u_linewidth, 1, new_linewidth.data());
|
||||
linewidth = new_linewidth;
|
||||
}
|
||||
}
|
||||
|
||||
void LinejoinShader::setSize(float new_size) {
|
||||
if (size != new_size) {
|
||||
glUniform1f(u_size, new_size);
|
||||
size = new_size;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,30 +21,6 @@ LinepatternShader::LinepatternShader()
|
||||
a_pos = glGetAttribLocation(program, "a_pos");
|
||||
a_extrude = glGetAttribLocation(program, "a_extrude");
|
||||
a_linesofar = glGetAttribLocation(program, "a_linesofar");
|
||||
|
||||
u_matrix = glGetUniformLocation(program, "u_posmatrix");
|
||||
u_exmatrix = glGetUniformLocation(program, "u_exmatrix");
|
||||
u_linewidth = glGetUniformLocation(program, "u_linewidth");
|
||||
u_ratio = glGetUniformLocation(program, "u_ratio");
|
||||
u_pattern_size = glGetUniformLocation(program, "u_pattern_size");
|
||||
|
||||
u_pattern_tl = glGetUniformLocation(program, "u_pattern_tl");
|
||||
u_pattern_br = glGetUniformLocation(program, "u_pattern_br");
|
||||
u_point = glGetUniformLocation(program, "u_point");
|
||||
u_blur = glGetUniformLocation(program, "u_blur");
|
||||
u_fade = glGetUniformLocation(program, "u_fade");
|
||||
|
||||
//fprintf(stderr, "LinepatternShader:\n");
|
||||
//fprintf(stderr, " - u_matrix: %d\n", u_matrix);
|
||||
//fprintf(stderr, " - u_exmatrix: %d\n", u_exmatrix);
|
||||
//fprintf(stderr, " - u_linewidth: %d\n", u_linewidth);
|
||||
//fprintf(stderr, " - u_ratio: %d\n", u_ratio);
|
||||
//fprintf(stderr, " - u_pattern_size: %d\n", u_pattern_size);
|
||||
//fprintf(stderr, " - u_pattern_tl: %d\n", u_pattern_tl);
|
||||
//fprintf(stderr, " - u_pattern_br: %d\n", u_pattern_br);
|
||||
//fprintf(stderr, " - u_point: %d\n", u_point);
|
||||
//fprintf(stderr, " - u_blur: %d\n", u_blur);
|
||||
//fprintf(stderr, " - u_fade: %d\n", u_fade);
|
||||
}
|
||||
|
||||
void LinepatternShader::bind(char *offset) {
|
||||
@@ -57,66 +33,3 @@ void LinepatternShader::bind(char *offset) {
|
||||
glEnableVertexAttribArray(a_linesofar);
|
||||
glVertexAttribPointer(a_linesofar, 1, GL_SHORT, false, 8, offset + 6);
|
||||
}
|
||||
|
||||
void LinepatternShader::setExtrudeMatrix(const std::array<float, 16>& new_exmatrix) {
|
||||
if (exmatrix != new_exmatrix) {
|
||||
glUniformMatrix4fv(u_exmatrix, 1, GL_FALSE, new_exmatrix.data());
|
||||
exmatrix = new_exmatrix;
|
||||
}
|
||||
}
|
||||
|
||||
void LinepatternShader::setPatternSize(const std::array<float, 2>& new_pattern_size) {
|
||||
if (pattern_size != new_pattern_size) {
|
||||
glUniform2fv(u_pattern_size, 1, new_pattern_size.data());
|
||||
pattern_size = new_pattern_size;
|
||||
}
|
||||
}
|
||||
|
||||
void LinepatternShader::setLineWidth(const std::array<float, 2>& new_linewidth) {
|
||||
if (linewidth != new_linewidth) {
|
||||
glUniform2fv(u_linewidth, 1, new_linewidth.data());
|
||||
linewidth = new_linewidth;
|
||||
}
|
||||
}
|
||||
|
||||
void LinepatternShader::setRatio(float new_ratio) {
|
||||
if (ratio != new_ratio) {
|
||||
glUniform1f(u_ratio, new_ratio);
|
||||
ratio = new_ratio;
|
||||
}
|
||||
}
|
||||
|
||||
void LinepatternShader::setPatternTopLeft(const std::array<float, 2>& new_pattern_tl) {
|
||||
if (pattern_tl != new_pattern_tl) {
|
||||
glUniform2fv(u_pattern_tl, 1, new_pattern_tl.data());
|
||||
pattern_tl = new_pattern_tl;
|
||||
}
|
||||
}
|
||||
|
||||
void LinepatternShader::setPatternBottomRight(const std::array<float, 2>& new_pattern_br) {
|
||||
if (pattern_br != new_pattern_br) {
|
||||
glUniform2fv(u_pattern_br, 1, new_pattern_br.data());
|
||||
pattern_br = new_pattern_br;
|
||||
}
|
||||
}
|
||||
|
||||
void LinepatternShader::setPoint(float new_point) {
|
||||
if (point != new_point) {
|
||||
glUniform1f(u_point, new_point);
|
||||
point = new_point;
|
||||
}
|
||||
}
|
||||
|
||||
void LinepatternShader::setBlur(float new_blur) {
|
||||
if (blur != new_blur) {
|
||||
glUniform1f(u_blur, new_blur);
|
||||
blur = new_blur;
|
||||
}
|
||||
}
|
||||
|
||||
void LinepatternShader::setFade(float new_fade) {
|
||||
if (fade != new_fade) {
|
||||
glUniform1f(u_fade, new_fade);
|
||||
fade = new_fade;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -18,32 +18,9 @@ OutlineShader::OutlineShader()
|
||||
}
|
||||
|
||||
a_pos = glGetAttribLocation(program, "a_pos");
|
||||
|
||||
u_matrix = glGetUniformLocation(program, "u_matrix");
|
||||
u_color = glGetUniformLocation(program, "u_color");
|
||||
u_world = glGetUniformLocation(program, "u_world");
|
||||
|
||||
// fprintf(stderr, "OutlineShader:\n");
|
||||
// fprintf(stderr, " - u_matrix: %d\n", u_matrix);
|
||||
// fprintf(stderr, " - u_color: %d\n", u_color);
|
||||
// fprintf(stderr, " - u_world: %d\n", u_world);
|
||||
}
|
||||
|
||||
void OutlineShader::bind(char *offset) {
|
||||
glEnableVertexAttribArray(a_pos);
|
||||
glVertexAttribPointer(a_pos, 2, GL_SHORT, false, 0, offset);
|
||||
}
|
||||
|
||||
void OutlineShader::setColor(const std::array<float, 4>& new_color) {
|
||||
if (color != new_color) {
|
||||
glUniform4fv(u_color, 1, new_color.data());
|
||||
color = new_color;
|
||||
}
|
||||
}
|
||||
|
||||
void OutlineShader::setWorld(const std::array<float, 2>& new_world) {
|
||||
if (world != new_world) {
|
||||
glUniform2fv(u_world, 1, new_world.data());
|
||||
world = new_world;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,69 +18,9 @@ PatternShader::PatternShader()
|
||||
}
|
||||
|
||||
a_pos = glGetAttribLocation(program, "a_pos");
|
||||
|
||||
u_matrix = glGetUniformLocation(program, "u_matrix");
|
||||
u_pattern_tl = glGetUniformLocation(program, "u_pattern_tl");
|
||||
u_pattern_br = glGetUniformLocation(program, "u_pattern_br");
|
||||
u_opacity = glGetUniformLocation(program, "u_opacity");
|
||||
u_image = glGetUniformLocation(program, "u_image");
|
||||
u_mix = glGetUniformLocation(program, "u_mix");
|
||||
u_patternmatrix = glGetUniformLocation(program, "u_patternmatrix");
|
||||
|
||||
// fprintf(stderr, "PatternShader:\n");
|
||||
// fprintf(stderr, " - u_matrix: %d\n", u_matrix);
|
||||
// fprintf(stderr, " - u_pattern_tl: %d\n", u_pattern_tl);
|
||||
// fprintf(stderr, " - u_pattern_br: %d\n", u_pattern_br);
|
||||
// fprintf(stderr, " - u_opacity: %d\n", u_opacity);
|
||||
// fprintf(stderr, " - u_image: %d\n", u_image);
|
||||
// fprintf(stderr, " - u_mix: %d\n", u_mix);
|
||||
// fprintf(stderr, " - u_patternmatrix: %d\n", u_patternmatrix);
|
||||
}
|
||||
|
||||
void PatternShader::bind(char *offset) {
|
||||
glEnableVertexAttribArray(a_pos);
|
||||
glVertexAttribPointer(a_pos, 2, GL_SHORT, false, 0, offset);
|
||||
}
|
||||
|
||||
void PatternShader::setPatternTopLeft(const std::array<float, 2>& new_pattern_tl) {
|
||||
if (pattern_tl != new_pattern_tl) {
|
||||
glUniform2fv(u_pattern_tl, 1, new_pattern_tl.data());
|
||||
pattern_tl = new_pattern_tl;
|
||||
}
|
||||
}
|
||||
|
||||
void PatternShader::setPatternBottomRight(const std::array<float, 2>& new_pattern_br) {
|
||||
if (pattern_br != new_pattern_br) {
|
||||
glUniform2fv(u_pattern_br, 1, new_pattern_br.data());
|
||||
pattern_br = new_pattern_br;
|
||||
}
|
||||
}
|
||||
|
||||
void PatternShader::setOpacity(float new_opacity) {
|
||||
if (opacity != new_opacity) {
|
||||
glUniform1f(u_opacity, new_opacity);
|
||||
opacity = new_opacity;
|
||||
}
|
||||
}
|
||||
|
||||
void PatternShader::setImage(int new_image) {
|
||||
if (image != new_image) {
|
||||
glUniform1i(u_image, new_image);
|
||||
image = new_image;
|
||||
}
|
||||
}
|
||||
|
||||
void PatternShader::setMix(float new_mix) {
|
||||
if (mix != new_mix) {
|
||||
glUniform1f(u_mix, new_mix);
|
||||
mix = new_mix;
|
||||
}
|
||||
}
|
||||
|
||||
void PatternShader::setPatternMatrix(const std::array<float, 9>& new_patternmatrix) {
|
||||
if (patternmatrix != new_patternmatrix) {
|
||||
glUniformMatrix3fv(u_patternmatrix, 1, GL_FALSE, new_patternmatrix.data());
|
||||
patternmatrix = new_patternmatrix;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,28 +18,9 @@ PlainShader::PlainShader()
|
||||
}
|
||||
|
||||
a_pos = glGetAttribLocation(program, "a_pos");
|
||||
|
||||
u_matrix = glGetUniformLocation(program, "u_matrix");
|
||||
u_color = glGetUniformLocation(program, "u_color");
|
||||
|
||||
// fprintf(stderr, "PlainShader:\n");
|
||||
// fprintf(stderr, " - a_pos: %d\n", a_pos);
|
||||
// fprintf(stderr, " - u_matrix: %d\n", u_matrix);
|
||||
// fprintf(stderr, " - u_color: %d\n", u_color);
|
||||
}
|
||||
|
||||
void PlainShader::bind(char *offset) {
|
||||
glEnableVertexAttribArray(a_pos);
|
||||
glVertexAttribPointer(a_pos, 2, GL_SHORT, false, 0, offset);
|
||||
}
|
||||
|
||||
void PlainShader::setColor(const std::array<float, 4>& new_color) {
|
||||
if (color != new_color) {
|
||||
glUniform4fv(u_color, 1, new_color.data());
|
||||
color = new_color;
|
||||
}
|
||||
}
|
||||
|
||||
void PlainShader::setColor(float r, float g, float b, float a) {
|
||||
setColor({{ r, g, b, a }});
|
||||
}
|
||||
|
||||
@@ -20,88 +20,9 @@ RasterShader::RasterShader()
|
||||
}
|
||||
|
||||
a_pos = glGetAttribLocation(program, "a_pos");
|
||||
|
||||
u_matrix = glGetUniformLocation(program, "u_matrix");
|
||||
u_image = glGetUniformLocation(program, "u_image");
|
||||
u_opacity = glGetUniformLocation(program, "u_opacity");
|
||||
u_buffer = glGetUniformLocation(program, "u_buffer");
|
||||
u_brightness_low = glGetUniformLocation(program, "u_brightness_low");
|
||||
u_brightness_high = glGetUniformLocation(program, "u_brightness_high");
|
||||
u_saturation_factor = glGetUniformLocation(program, "u_saturation_factor");
|
||||
u_contrast_factor = glGetUniformLocation(program, "u_contrast_factor");
|
||||
u_spin_weights = glGetUniformLocation(program, "u_spin_weights");
|
||||
|
||||
// fprintf(stderr, "RasterShader:\n");
|
||||
// fprintf(stderr, " - u_matrix: %d\n", u_matrix);
|
||||
// fprintf(stderr, " - u_image: %d\n", u_image);
|
||||
// fprintf(stderr, " - u_opacity: %f\n", u_opacity);
|
||||
// fprintf(stderr, " - u_buffer: %f\n", u_buffer);
|
||||
}
|
||||
|
||||
void RasterShader::bind(char *offset) {
|
||||
glEnableVertexAttribArray(a_pos);
|
||||
glVertexAttribPointer(a_pos, 2, GL_SHORT, false, 0, offset);
|
||||
}
|
||||
|
||||
void RasterShader::setImage(int32_t new_image) {
|
||||
if (image != new_image) {
|
||||
glUniform1i(u_image, new_image);
|
||||
image = new_image;
|
||||
}
|
||||
}
|
||||
|
||||
void RasterShader::setOpacity(float new_opacity) {
|
||||
if (opacity != new_opacity) {
|
||||
glUniform1f(u_opacity, new_opacity);
|
||||
opacity = new_opacity;
|
||||
}
|
||||
}
|
||||
|
||||
void RasterShader::setBuffer(float new_buffer) {
|
||||
if (buffer != new_buffer) {
|
||||
glUniform1f(u_buffer, new_buffer);
|
||||
buffer = new_buffer;
|
||||
}
|
||||
}
|
||||
|
||||
void RasterShader::setBrightness(float new_brightness_low, float new_brightness_high) {
|
||||
if (brightness_low != new_brightness_low) {
|
||||
glUniform1f(u_brightness_low, new_brightness_low);
|
||||
brightness_low = new_brightness_low;
|
||||
}
|
||||
if (brightness_high != new_brightness_high) {
|
||||
glUniform1f(u_brightness_high, new_brightness_high);
|
||||
brightness_high = new_brightness_high;
|
||||
}
|
||||
}
|
||||
|
||||
void RasterShader::setSaturation(float new_saturation_factor) {
|
||||
if (saturation_factor != new_saturation_factor) {
|
||||
if (new_saturation_factor > 0) {
|
||||
new_saturation_factor = 1 - 1 / (1.001 - new_saturation_factor);
|
||||
} else {
|
||||
new_saturation_factor = -new_saturation_factor;
|
||||
}
|
||||
glUniform1f(u_saturation_factor, new_saturation_factor);
|
||||
saturation_factor = new_saturation_factor;
|
||||
}
|
||||
}
|
||||
|
||||
void RasterShader::setContrast(float new_contrast_factor) {
|
||||
if (contrast_factor != new_contrast_factor) {
|
||||
if (new_contrast_factor > 0) {
|
||||
new_contrast_factor = 1 / (1 - new_contrast_factor);
|
||||
} else {
|
||||
new_contrast_factor = 1 + new_contrast_factor;
|
||||
}
|
||||
glUniform1f(u_contrast_factor, new_contrast_factor);
|
||||
contrast_factor = new_contrast_factor;
|
||||
}
|
||||
}
|
||||
|
||||
void RasterShader::setSpin(std::array<float, 3> new_spin_weights) {
|
||||
if (spin_weights != new_spin_weights) {
|
||||
glUniform3fv(u_spin_weights, 1, new_spin_weights.data());
|
||||
spin_weights = new_spin_weights;
|
||||
}
|
||||
}
|
||||
@@ -124,15 +124,6 @@ bool Shader::compileShader(GLuint *shader, GLenum type, const GLchar *source) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void Shader::setMatrix(const std::array<float, 16>& newMatrix) {
|
||||
if (matrix != newMatrix) {
|
||||
glUniformMatrix4fv(u_matrix, 1, GL_FALSE, newMatrix.data());
|
||||
matrix = newMatrix;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Shader::~Shader() {
|
||||
if (program) {
|
||||
glDeleteProgram(program);
|
||||
|
||||
@@ -21,39 +21,6 @@ TextShader::TextShader()
|
||||
a_offset = glGetAttribLocation(program, "a_offset");
|
||||
a_data1 = glGetAttribLocation(program, "a_data1");
|
||||
a_data2 = glGetAttribLocation(program, "a_data2");
|
||||
|
||||
u_matrix = glGetUniformLocation(program, "u_matrix");
|
||||
u_color = glGetUniformLocation(program, "u_color");
|
||||
u_buffer = glGetUniformLocation(program, "u_buffer");
|
||||
u_gamma = glGetUniformLocation(program, "u_gamma");
|
||||
u_exmatrix = glGetUniformLocation(program, "u_exmatrix");
|
||||
u_angle = glGetUniformLocation(program, "u_angle");
|
||||
u_zoom = glGetUniformLocation(program, "u_zoom");
|
||||
u_flip = glGetUniformLocation(program, "u_flip");
|
||||
u_fadedist = glGetUniformLocation(program, "u_fadedist");
|
||||
u_minfadezoom = glGetUniformLocation(program, "u_minfadezoom");
|
||||
u_maxfadezoom = glGetUniformLocation(program, "u_maxfadezoom");
|
||||
u_fadezoom = glGetUniformLocation(program, "u_fadezoom");
|
||||
u_texsize = glGetUniformLocation(program, "u_texsize");
|
||||
|
||||
// fprintf(stderr, "TextShader:\n");
|
||||
// fprintf(stderr, " - a_pos: %d\n", a_pos);
|
||||
// fprintf(stderr, " - a_offset: %d\n", a_offset);
|
||||
// fprintf(stderr, " - a_data1: %d\n", a_tex);
|
||||
// fprintf(stderr, " - a_data2: %d\n", a_tex);
|
||||
// fprintf(stderr, " - u_color: %d\n", u_color);
|
||||
// fprintf(stderr, " - u_buffer: %d\n", u_buffer);
|
||||
// fprintf(stderr, " - u_gamma: %d\n", u_gamma);
|
||||
// fprintf(stderr, " - u_exmatrix: %d\n", u_exmatrix);
|
||||
// fprintf(stderr, " - u_angle: %d\n", u_angle);
|
||||
// fprintf(stderr, " - u_zoom: %d\n", u_zoom);
|
||||
// fprintf(stderr, " - u_flip: %d\n", u_flip);
|
||||
// fprintf(stderr, " - u_fadedist: %d\n", u_fadedist);
|
||||
// fprintf(stderr, " - u_minfadezoom: %d\n", u_minfadezoom);
|
||||
// fprintf(stderr, " - u_maxfadezoom: %d\n", u_maxfadezoom);
|
||||
// fprintf(stderr, " - u_fadezoom: %d\n", u_fadezoom);
|
||||
// fprintf(stderr, " - u_texsize: %d\n", u_texsize);
|
||||
// fprintf(stderr, " - u_opacity: %d\n", u_opacity);
|
||||
}
|
||||
|
||||
void TextShader::bind(char *offset) {
|
||||
@@ -69,91 +36,3 @@ void TextShader::bind(char *offset) {
|
||||
glEnableVertexAttribArray(a_data2);
|
||||
glVertexAttribPointer(a_data2, 4, GL_UNSIGNED_BYTE, false, 16, offset + 12);
|
||||
}
|
||||
|
||||
void TextShader::setColor(const std::array<float, 4>& new_color) {
|
||||
if (color != new_color) {
|
||||
glUniform4fv(u_color, 1, new_color.data());
|
||||
color = new_color;
|
||||
}
|
||||
}
|
||||
|
||||
void TextShader::setColor(float r, float g, float b, float a) {
|
||||
setColor({{ r, g, b, a }});
|
||||
}
|
||||
|
||||
void TextShader::setBuffer(float new_buffer) {
|
||||
if (buffer != new_buffer) {
|
||||
glUniform1f(u_buffer, new_buffer);
|
||||
buffer = new_buffer;
|
||||
}
|
||||
}
|
||||
|
||||
void TextShader::setGamma(float new_gamma) {
|
||||
if (gamma != new_gamma) {
|
||||
glUniform1f(u_gamma, new_gamma);
|
||||
gamma = new_gamma;
|
||||
}
|
||||
}
|
||||
|
||||
void TextShader::setExtrudeMatrix(const std::array<float, 16> &new_exmatrix) {
|
||||
if (exmatrix != new_exmatrix) {
|
||||
glUniformMatrix4fv(u_exmatrix, 1, GL_FALSE, new_exmatrix.data());
|
||||
exmatrix = new_exmatrix;
|
||||
}
|
||||
}
|
||||
|
||||
void TextShader::setAngle(float new_angle) {
|
||||
if (angle != new_angle) {
|
||||
glUniform1f(u_angle, new_angle);
|
||||
angle = new_angle;
|
||||
}
|
||||
}
|
||||
|
||||
void TextShader::setZoom(float new_zoom) {
|
||||
if (zoom != new_zoom) {
|
||||
glUniform1f(u_zoom, new_zoom);
|
||||
zoom = new_zoom;
|
||||
}
|
||||
}
|
||||
|
||||
void TextShader::setFlip(float new_flip) {
|
||||
if (flip != new_flip) {
|
||||
glUniform1f(u_flip, new_flip);
|
||||
flip = new_flip;
|
||||
}
|
||||
}
|
||||
|
||||
void TextShader::setFadeDist(float new_fadedist) {
|
||||
if (fadedist != new_fadedist) {
|
||||
glUniform1f(u_fadedist, new_fadedist);
|
||||
fadedist = new_fadedist;
|
||||
}
|
||||
}
|
||||
|
||||
void TextShader::setMinFadeZoom(float new_minfadezoom) {
|
||||
if (minfadezoom != new_minfadezoom) {
|
||||
glUniform1f(u_minfadezoom, new_minfadezoom);
|
||||
minfadezoom = new_minfadezoom;
|
||||
}
|
||||
}
|
||||
|
||||
void TextShader::setMaxFadeZoom(float new_maxfadezoom) {
|
||||
if (maxfadezoom != new_maxfadezoom) {
|
||||
glUniform1f(u_maxfadezoom, new_maxfadezoom);
|
||||
maxfadezoom = new_maxfadezoom;
|
||||
}
|
||||
}
|
||||
|
||||
void TextShader::setFadeZoom(float new_fadezoom) {
|
||||
if (fadezoom != new_fadezoom) {
|
||||
glUniform1f(u_fadezoom, new_fadezoom);
|
||||
fadezoom = new_fadezoom;
|
||||
}
|
||||
}
|
||||
|
||||
void TextShader::setTextureSize(const std::array<float, 2> &new_texsize) {
|
||||
if (texsize != new_texsize) {
|
||||
glUniform2fv(u_texsize, 1, new_texsize.data());
|
||||
texsize = new_texsize;
|
||||
}
|
||||
}
|
||||
|
||||
45
src/shader/uniform.cpp
Normal file
45
src/shader/uniform.cpp
Normal file
@@ -0,0 +1,45 @@
|
||||
#include <mbgl/shader/uniform.hpp>
|
||||
|
||||
using namespace mbgl;
|
||||
|
||||
template <>
|
||||
void Uniform<float>::bind(const float& t) {
|
||||
glUniform1f(location, t);
|
||||
}
|
||||
|
||||
template <>
|
||||
void Uniform<int32_t>::bind(const int32_t& t) {
|
||||
glUniform1i(location, t);
|
||||
}
|
||||
|
||||
template <>
|
||||
void Uniform<std::array<float, 2>>::bind(const std::array<float, 2>& t) {
|
||||
glUniform2fv(location, 1, t.data());
|
||||
}
|
||||
|
||||
template <>
|
||||
void Uniform<std::array<float, 3>>::bind(const std::array<float, 3>& t) {
|
||||
glUniform3fv(location, 1, t.data());
|
||||
}
|
||||
|
||||
template <>
|
||||
void Uniform<std::array<float, 4>>::bind(const std::array<float, 4>& t) {
|
||||
glUniform4fv(location, 1, t.data());
|
||||
}
|
||||
|
||||
template <>
|
||||
void UniformMatrix<2>::bind(const std::array<float, 4>& t) {
|
||||
glUniformMatrix2fv(location, 1, GL_FALSE, t.data());
|
||||
}
|
||||
|
||||
template <>
|
||||
void UniformMatrix<3>::bind(const std::array<float, 9>& t) {
|
||||
glUniformMatrix3fv(location, 1, GL_FALSE, t.data());
|
||||
}
|
||||
|
||||
template <>
|
||||
void UniformMatrix<4>::bind(const std::array<float, 16>& t) {
|
||||
glUniformMatrix4fv(location, 1, GL_FALSE, t.data());
|
||||
}
|
||||
|
||||
// Add more as needed.
|
||||
Reference in New Issue
Block a user