TextShader ⇢ SDFShader
This commit is contained in:
@@ -17,7 +17,7 @@
|
||||
#include <mbgl/shader/linepattern_shader.hpp>
|
||||
#include <mbgl/shader/icon_shader.hpp>
|
||||
#include <mbgl/shader/raster_shader.hpp>
|
||||
#include <mbgl/shader/text_shader.hpp>
|
||||
#include <mbgl/shader/sdf_shader.hpp>
|
||||
#include <mbgl/shader/dot_shader.hpp>
|
||||
#include <mbgl/shader/gaussian_shader.hpp>
|
||||
|
||||
@@ -176,7 +176,7 @@ public:
|
||||
std::unique_ptr<PatternShader> patternShader;
|
||||
std::unique_ptr<IconShader> iconShader;
|
||||
std::unique_ptr<RasterShader> rasterShader;
|
||||
std::unique_ptr<TextShader> textShader;
|
||||
std::unique_ptr<SDFShader> sdfShader;
|
||||
std::unique_ptr<DotShader> dotShader;
|
||||
std::unique_ptr<GaussianShader> gaussianShader;
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
namespace mbgl {
|
||||
|
||||
class Style;
|
||||
class TextShader;
|
||||
class SDFShader;
|
||||
class IconShader;
|
||||
class DotShader;
|
||||
class Collision;
|
||||
@@ -68,7 +68,7 @@ public:
|
||||
void addGlyphs(const PlacedGlyphs &glyphs, float placementZoom, PlacementRange placementRange,
|
||||
float zoom);
|
||||
|
||||
void drawGlyphs(TextShader &shader);
|
||||
void drawGlyphs(SDFShader &shader);
|
||||
void drawIcons(IconShader& shader);
|
||||
|
||||
private:
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
#ifndef MBGL_SHADER_TEXT_SHADER
|
||||
#define MBGL_SHADER_TEXT_SHADER
|
||||
#ifndef MBGL_SHADER_SDF_SHADER
|
||||
#define MBGL_SHADER_SDF_SHADER
|
||||
|
||||
#include <mbgl/shader/shader.hpp>
|
||||
#include <mbgl/shader/uniform.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
class TextShader : public Shader {
|
||||
class SDFShader : public Shader {
|
||||
public:
|
||||
TextShader();
|
||||
SDFShader();
|
||||
|
||||
void bind(char *offset);
|
||||
|
||||
@@ -44,7 +44,7 @@ void Painter::setup() {
|
||||
assert(linepatternShader);
|
||||
assert(patternShader);
|
||||
assert(rasterShader);
|
||||
assert(textShader);
|
||||
assert(sdfShader);
|
||||
assert(dotShader);
|
||||
assert(gaussianShader);
|
||||
|
||||
@@ -75,7 +75,7 @@ void Painter::setupShaders() {
|
||||
if (!patternShader) patternShader = std::make_unique<PatternShader>();
|
||||
if (!iconShader) iconShader = std::make_unique<IconShader>();
|
||||
if (!rasterShader) rasterShader = std::make_unique<RasterShader>();
|
||||
if (!textShader) textShader = std::make_unique<TextShader>();
|
||||
if (!sdfShader) sdfShader = std::make_unique<SDFShader>();
|
||||
if (!dotShader) dotShader = std::make_unique<DotShader>();
|
||||
if (!gaussianShader) gaussianShader = std::make_unique<GaussianShader>();
|
||||
}
|
||||
|
||||
@@ -32,13 +32,13 @@ void Painter::renderSymbol(SymbolBucket &bucket, std::shared_ptr<StyleLayer> lay
|
||||
float fontSize = std::fmin(properties.text.size, bucket.properties.text.max_size);
|
||||
matrix::scale(exMatrix, exMatrix, fontSize / 24.0f, fontSize / 24.0f, 1.0f);
|
||||
|
||||
useProgram(textShader->program);
|
||||
textShader->u_matrix = vtxMatrix;
|
||||
textShader->u_exmatrix = exMatrix;
|
||||
useProgram(sdfShader->program);
|
||||
sdfShader->u_matrix = vtxMatrix;
|
||||
sdfShader->u_exmatrix = exMatrix;
|
||||
|
||||
GlyphAtlas &glyphAtlas = *map.getGlyphAtlas();
|
||||
glyphAtlas.bind();
|
||||
textShader->u_texsize = {{
|
||||
sdfShader->u_texsize = {{
|
||||
static_cast<float>(glyphAtlas.width),
|
||||
static_cast<float>(glyphAtlas.height)
|
||||
}};
|
||||
@@ -49,9 +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->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
|
||||
sdfShader->u_angle = (int32_t)(angle + 256) % 256;
|
||||
sdfShader->u_flip = (bucket.properties.placement == PlacementType::Line ? 1 : 0);
|
||||
sdfShader->u_zoom = (map.getState().getNormalizedZoom() - zoomAdjust) * 10; // current zoom level
|
||||
|
||||
// Label fading
|
||||
const timestamp duration = 300_milliseconds;
|
||||
@@ -84,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->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;
|
||||
sdfShader->u_fadedist = fadedist * 10;
|
||||
sdfShader->u_minfadezoom = std::floor(lowZ * 10);
|
||||
sdfShader->u_maxfadezoom = std::floor(highZ * 10);
|
||||
sdfShader->u_fadezoom = (map.getState().getNormalizedZoom() + bump) * 10;
|
||||
}
|
||||
|
||||
// This defines the gamma around the SDF cutoff value.
|
||||
@@ -122,9 +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->u_gamma = (properties.text.halo_blur / (fontSize / sdfFontSize)) / 8.0f / 2.0f;
|
||||
sdfShader->u_gamma = (properties.text.halo_blur / (fontSize / sdfFontSize)) / 8.0f / 2.0f;
|
||||
} else {
|
||||
textShader->u_gamma = sdfGamma;
|
||||
sdfShader->u_gamma = sdfGamma;
|
||||
}
|
||||
|
||||
if (properties.text.opacity < 1.0f) {
|
||||
@@ -133,31 +133,31 @@ 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->u_color = color;
|
||||
sdfShader->u_color = color;
|
||||
} else {
|
||||
textShader->u_color = properties.text.halo_color;
|
||||
sdfShader->u_color = properties.text.halo_color;
|
||||
}
|
||||
textShader->u_buffer = haloWidth;
|
||||
sdfShader->u_buffer = haloWidth;
|
||||
depthRange(strata, 1.0f);
|
||||
bucket.drawGlyphs(*textShader);
|
||||
bucket.drawGlyphs(*sdfShader);
|
||||
}
|
||||
|
||||
if (properties.text.color[3] > 0.0f) {
|
||||
// Then, we draw the text over the halo
|
||||
textShader->u_gamma = gamma;
|
||||
sdfShader->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->u_color = color;
|
||||
sdfShader->u_color = color;
|
||||
} else {
|
||||
textShader->u_color = properties.text.color;
|
||||
sdfShader->u_color = properties.text.color;
|
||||
}
|
||||
textShader->u_buffer = (256.0f - 64.0f) / 256.0f;
|
||||
sdfShader->u_buffer = (256.0f - 64.0f) / 256.0f;
|
||||
depthRange(strata + strata_epsilon, 1.0f);
|
||||
bucket.drawGlyphs(*textShader);
|
||||
bucket.drawGlyphs(*sdfShader);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -373,7 +373,7 @@ void SymbolBucket::addSymbols(Buffer &buffer, const PlacedGlyphs &symbols, float
|
||||
}
|
||||
}
|
||||
|
||||
void SymbolBucket::drawGlyphs(TextShader &shader) {
|
||||
void SymbolBucket::drawGlyphs(SDFShader &shader) {
|
||||
char *vertex_index = BUFFER_OFFSET(0);
|
||||
char *elements_index = BUFFER_OFFSET(0);
|
||||
for (TextElementGroup &group : text.groups) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#include <mbgl/shader/text_shader.hpp>
|
||||
#include <mbgl/shader/sdf_shader.hpp>
|
||||
#include <mbgl/shader/shaders.hpp>
|
||||
#include <mbgl/platform/gl.hpp>
|
||||
|
||||
@@ -6,14 +6,14 @@
|
||||
|
||||
using namespace mbgl;
|
||||
|
||||
TextShader::TextShader()
|
||||
SDFShader::SDFShader()
|
||||
: Shader(
|
||||
"text",
|
||||
shaders[TEXT_SHADER].vertex,
|
||||
shaders[TEXT_SHADER].fragment
|
||||
"sdf",
|
||||
shaders[SDF_SHADER].vertex,
|
||||
shaders[SDF_SHADER].fragment
|
||||
) {
|
||||
if (!valid) {
|
||||
fprintf(stderr, "invalid text shader\n");
|
||||
fprintf(stderr, "invalid sdf shader\n");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ TextShader::TextShader()
|
||||
a_data2 = glGetAttribLocation(program, "a_data2");
|
||||
}
|
||||
|
||||
void TextShader::bind(char *offset) {
|
||||
void SDFShader::bind(char *offset) {
|
||||
glEnableVertexAttribArray(a_pos);
|
||||
glVertexAttribPointer(a_pos, 2, GL_SHORT, false, 16, offset + 0);
|
||||
|
||||
Reference in New Issue
Block a user