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
|
||||
Reference in New Issue
Block a user