summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2014-09-04 13:55:03 -0700
committerJohn Firebaugh <john.firebaugh@gmail.com>2014-09-04 16:22:25 -0700
commit1fedf0918aa5c529207ba8f2f1312d403a8ba7fc (patch)
treeb33bbb21744719b2f4b159051bcbe614caddd191 /src
parentc14ae3c477617d284d50daff668ab5716ff9a771 (diff)
downloadqtlocation-mapboxgl-1fedf0918aa5c529207ba8f2f1312d403a8ba7fc.tar.gz
Less shader boilerplate
Diffstat (limited to 'src')
-rw-r--r--src/renderer/painter.cpp4
-rw-r--r--src/renderer/painter_clipping.cpp2
-rw-r--r--src/renderer/painter_debug.cpp16
-rw-r--r--src/renderer/painter_fill.cpp34
-rw-r--r--src/renderer/painter_line.cpp56
-rw-r--r--src/renderer/painter_prerender.cpp19
-rw-r--r--src/renderer/painter_raster.cpp31
-rw-r--r--src/renderer/painter_symbol.cpp71
-rw-r--r--src/renderer/prerendered_texture.cpp8
-rw-r--r--src/renderer/raster_bucket.cpp4
-rw-r--r--src/shader/dot_shader.cpp32
-rw-r--r--src/shader/gaussian_shader.cpp23
-rw-r--r--src/shader/icon_shader.cpp95
-rw-r--r--src/shader/line_shader.cpp58
-rw-r--r--src/shader/linejoin_shader.cpp41
-rw-r--r--src/shader/linepattern_shader.cpp87
-rw-r--r--src/shader/outline_shader.cpp23
-rw-r--r--src/shader/pattern_shader.cpp60
-rw-r--r--src/shader/plain_shader.cpp19
-rw-r--r--src/shader/raster_shader.cpp79
-rw-r--r--src/shader/shader.cpp9
-rw-r--r--src/shader/text_shader.cpp121
-rw-r--r--src/shader/uniform.cpp45
23 files changed, 176 insertions, 761 deletions
diff --git a/src/renderer/painter.cpp b/src/renderer/painter.cpp
index 938bd5bd84..5f75287dbb 100644
--- a/src/renderer/painter.cpp
+++ b/src/renderer/painter.cpp
@@ -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);
diff --git a/src/renderer/painter_clipping.cpp b/src/renderer/painter_clipping.cpp
index d8fa3693bd..45b14a2f78 100644
--- a/src/renderer/painter_clipping.cpp
+++ b/src/renderer/painter_clipping.cpp
@@ -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());
diff --git a/src/renderer/painter_debug.cpp b/src/renderer/painter_debug.cpp
index eae655f1f5..f120533838 100644
--- a/src/renderer/painter_debug.cpp
+++ b/src/renderer/painter_debug.cpp
@@ -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());
}
diff --git a/src/renderer/painter_fill.cpp b/src/renderer/painter_fill.cpp
index 45706cca1b..6d56b9077e 100644
--- a/src/renderer/painter_fill.cpp
+++ b/src/renderer/painter_fill.cpp
@@ -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);
diff --git a/src/renderer/painter_line.cpp b/src/renderer/painter_line.cpp
index b68d46b010..161abcd6ff 100644
--- a/src/renderer/painter_line.cpp
+++ b/src/renderer/painter_line.cpp
@@ -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);
}
diff --git a/src/renderer/painter_prerender.cpp b/src/renderer/painter_prerender.cpp
index 14a15effe1..f38470530b 100644
--- a/src/renderer/painter_prerender.cpp
+++ b/src/renderer/painter_prerender.cpp
@@ -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());
diff --git a/src/renderer/painter_raster.cpp b/src/renderer/painter_raster.cpp
index 946f6216c7..7f7afc3e84 100644
--- a/src/renderer/painter_raster.cpp
+++ b/src/renderer/painter_raster.cpp
@@ -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);
diff --git a/src/renderer/painter_symbol.cpp b/src/renderer/painter_symbol.cpp
index e412bc49d7..61170efb69 100644
--- a/src/renderer/painter_symbol.cpp
+++ b/src/renderer/painter_symbol.cpp
@@ -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);
diff --git a/src/renderer/prerendered_texture.cpp b/src/renderer/prerendered_texture.cpp
index 52f7edc50b..0a47816323 100644
--- a/src/renderer/prerendered_texture.cpp
+++ b/src/renderer/prerendered_texture.cpp
@@ -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());
diff --git a/src/renderer/raster_bucket.cpp b/src/renderer/raster_bucket.cpp
index 10dadc03fc..492eea980d 100644
--- a/src/renderer/raster_bucket.cpp
+++ b/src/renderer/raster_bucket.cpp
@@ -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());
}
diff --git a/src/shader/dot_shader.cpp b/src/shader/dot_shader.cpp
index 54163d6982..a897f410a7 100644
--- a/src/shader/dot_shader.cpp
+++ b/src/shader/dot_shader.cpp
@@ -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;
- }
-}
diff --git a/src/shader/gaussian_shader.cpp b/src/shader/gaussian_shader.cpp
index d22006020c..9060f0ee71 100644
--- a/src/shader/gaussian_shader.cpp
+++ b/src/shader/gaussian_shader.cpp
@@ -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;
- }
-}
diff --git a/src/shader/icon_shader.cpp b/src/shader/icon_shader.cpp
index 4973dc4119..5c54177eb6 100644
--- a/src/shader/icon_shader.cpp
+++ b/src/shader/icon_shader.cpp
@@ -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;
- }
-}
-
diff --git a/src/shader/line_shader.cpp b/src/shader/line_shader.cpp
index 1b0527366e..8353f4c6ca 100644
--- a/src/shader/line_shader.cpp
+++ b/src/shader/line_shader.cpp
@@ -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;
- }
-}
diff --git a/src/shader/linejoin_shader.cpp b/src/shader/linejoin_shader.cpp
index e8ec306ed9..050e180e00 100644
--- a/src/shader/linejoin_shader.cpp
+++ b/src/shader/linejoin_shader.cpp
@@ -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;
- }
-}
diff --git a/src/shader/linepattern_shader.cpp b/src/shader/linepattern_shader.cpp
index 49ca9e00ff..954dbd2b3f 100644
--- a/src/shader/linepattern_shader.cpp
+++ b/src/shader/linepattern_shader.cpp
@@ -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;
- }
-};
diff --git a/src/shader/outline_shader.cpp b/src/shader/outline_shader.cpp
index d9c19fa805..ddabfa5d0d 100644
--- a/src/shader/outline_shader.cpp
+++ b/src/shader/outline_shader.cpp
@@ -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;
- }
-}
diff --git a/src/shader/pattern_shader.cpp b/src/shader/pattern_shader.cpp
index 8fe6a34e93..31374bc3e8 100644
--- a/src/shader/pattern_shader.cpp
+++ b/src/shader/pattern_shader.cpp
@@ -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;
- }
-}
-
diff --git a/src/shader/plain_shader.cpp b/src/shader/plain_shader.cpp
index bb0c228992..8a37837b30 100644
--- a/src/shader/plain_shader.cpp
+++ b/src/shader/plain_shader.cpp
@@ -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 }});
-}
diff --git a/src/shader/raster_shader.cpp b/src/shader/raster_shader.cpp
index 60d81c61bd..7351f7d0c4 100644
--- a/src/shader/raster_shader.cpp
+++ b/src/shader/raster_shader.cpp
@@ -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;
- }
-} \ No newline at end of file
diff --git a/src/shader/shader.cpp b/src/shader/shader.cpp
index 171ce9b7c1..91c9b58c89 100644
--- a/src/shader/shader.cpp
+++ b/src/shader/shader.cpp
@@ -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);
diff --git a/src/shader/text_shader.cpp b/src/shader/text_shader.cpp
index f6de934e2f..8cd72f5e4f 100644
--- a/src/shader/text_shader.cpp
+++ b/src/shader/text_shader.cpp
@@ -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;
- }
-}
diff --git a/src/shader/uniform.cpp b/src/shader/uniform.cpp
new file mode 100644
index 0000000000..14a6ae760e
--- /dev/null
+++ b/src/shader/uniform.cpp
@@ -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.