Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
First pass at port of mapbox/mapbox-gl-js#2668
Browse files Browse the repository at this point in the history
  • Loading branch information
yhahn committed Jun 8, 2016
1 parent 685d238 commit bad41e6
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 21 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"csscolorparser": "^1.0.2",
"ejs": "^2.4.1",
"express": "^4.11.1",
"mapbox-gl-shaders": "mapbox/mapbox-gl-shaders#8dfd9653e6659cb2837a4b98f3e8e1d559b29a09",
"mapbox-gl-shaders": "mapbox/mapbox-gl-shaders#50390dd173a6aec50652873903adf5ef53e5db39",
"mapbox-gl-style-spec": "^8.5.1",
"mapbox-gl-test-suite": "mapbox/mapbox-gl-test-suite#f45fd7aba98650c7f3bf778c9cbbfd3b548a4ee8",
"node-gyp": "^3.3.1",
Expand Down
3 changes: 2 additions & 1 deletion src/mbgl/geometry/icon_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace mbgl {

size_t IconVertexBuffer::add(int16_t x, int16_t y, float ox, float oy, int16_t tx, int16_t ty, float minzoom, float maxzoom, float labelminzoom) {
size_t IconVertexBuffer::add(int16_t x, int16_t y, float ox, float oy, int16_t tx, int16_t ty, float minzoom, float maxzoom, float labelminzoom, uint8_t labelangle) {
const size_t idx = index();
void *data = addElement();

Expand All @@ -21,6 +21,7 @@ size_t IconVertexBuffer::add(int16_t x, int16_t y, float ox, float oy, int16_t t
ubytes[8] /* tex */ = tx / 4;
ubytes[9] /* tex */ = ty / 4;
ubytes[10] /* labelminzoom */ = labelminzoom * 10;
ubytes[11] /* labelangle */ = labelangle;

// a_data2
ubytes[12] /* minzoom */ = minzoom * 10; // 1/10 zoom levels: z16 == 160.
Expand Down
2 changes: 1 addition & 1 deletion src/mbgl/geometry/icon_buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace mbgl {
16
> {
public:
size_t add(int16_t x, int16_t y, float ox, float oy, int16_t tx, int16_t ty, float minzoom, float maxzoom, float labelminzoom);
size_t add(int16_t x, int16_t y, float ox, float oy, int16_t tx, int16_t ty, float minzoom, float maxzoom, float labelminzoom, uint8_t labelangle);

};

Expand Down
3 changes: 2 additions & 1 deletion src/mbgl/geometry/text_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace mbgl {

size_t TextVertexBuffer::add(int16_t x, int16_t y, float ox, float oy, uint16_t tx, uint16_t ty, float minzoom, float maxzoom, float labelminzoom) {
size_t TextVertexBuffer::add(int16_t x, int16_t y, float ox, float oy, uint16_t tx, uint16_t ty, float minzoom, float maxzoom, float labelminzoom, uint8_t labelangle) {
const size_t idx = index();
void *data = addElement();

Expand All @@ -21,6 +21,7 @@ size_t TextVertexBuffer::add(int16_t x, int16_t y, float ox, float oy, uint16_t
ubytes[8] /* tex */ = tx / 4;
ubytes[9] /* tex */ = ty / 4;
ubytes[10] /* labelminzoom */ = labelminzoom * 10;
ubytes[11] /* labelangle */ = labelangle;

// a_data2
ubytes[12] /* minzoom */ = minzoom * 10; // 1/10 zoom levels: z16 == 160.
Expand Down
2 changes: 1 addition & 1 deletion src/mbgl/geometry/text_buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class TextVertexBuffer : public Buffer <
public:
typedef int16_t vertex_type;

size_t add(int16_t x, int16_t y, float ox, float oy, uint16_t tx, uint16_t ty, float minzoom, float maxzoom, float labelminzoom);
size_t add(int16_t x, int16_t y, float ox, float oy, uint16_t tx, uint16_t ty, float minzoom, float maxzoom, float labelminzoom, uint8_t labelangle);
};


Expand Down
4 changes: 3 additions & 1 deletion src/mbgl/renderer/painter_symbol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ void Painter::renderSDF(SymbolBucket &bucket,
bool alignedWithMap = rotationAlignment == RotationAlignmentType::Map;
float gammaScale = 1.0f;

if (alignedWithMap) {
if (false && alignedWithMap) {
scale *= tileID.pixelsToTileUnits(1, state.getZoom());
exScale.fill(scale);
gammaScale /= std::cos(state.getPitch());
Expand All @@ -62,6 +62,8 @@ void Painter::renderSDF(SymbolBucket &bucket,
sdfShader.u_texsize = texsize;
sdfShader.u_skewed = alignedWithMap;
sdfShader.u_texture = 0;
sdfShader.u_pitch = state.getPitch() / 360 * 2 * M_PI;
sdfShader.u_aspect_ratio = (state.getWidth() * 1.0f) / (state.getHeight() * 1.0f);

// adjust min/max zooms for variable font sies
float zoomAdjust = std::log(fontSize / layoutSize) / std::log(2);
Expand Down
13 changes: 8 additions & 5 deletions src/mbgl/renderer/symbol_bucket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ void SymbolBucket::addSymbols(Buffer &buffer, const SymbolQuads &symbols, float
const auto &anchorPoint = symbol.anchorPoint;

// drop upside down versions of glyphs
const float a = std::fmod(symbol.angle + placementAngle + M_PI, M_PI * 2);
const float a = std::fmod(symbol.anchorAngle + placementAngle + M_PI, M_PI * 2);
if (keepUpright && alongLine && (a <= M_PI / 2 || a > M_PI * 3 / 2)) continue;


Expand All @@ -521,15 +521,18 @@ void SymbolBucket::addSymbols(Buffer &buffer, const SymbolQuads &symbols, float
auto &triangleGroup = *buffer.groups.back();
GLsizei triangleIndex = triangleGroup.vertex_length;

// Encode angle of glyph
uint8_t glyphAngle = std::round((symbol.glyphAngle / (M_PI * 2)) * 256);

// coordinates (2 triangles)
buffer.vertices.add(anchorPoint.x, anchorPoint.y, tl.x, tl.y, tex.x, tex.y, minZoom,
maxZoom, placementZoom);
maxZoom, placementZoom, glyphAngle);
buffer.vertices.add(anchorPoint.x, anchorPoint.y, tr.x, tr.y, tex.x + tex.w, tex.y,
minZoom, maxZoom, placementZoom);
minZoom, maxZoom, placementZoom, glyphAngle);
buffer.vertices.add(anchorPoint.x, anchorPoint.y, bl.x, bl.y, tex.x, tex.y + tex.h,
minZoom, maxZoom, placementZoom);
minZoom, maxZoom, placementZoom, glyphAngle);
buffer.vertices.add(anchorPoint.x, anchorPoint.y, br.x, br.y, tex.x + tex.w, tex.y + tex.h,
minZoom, maxZoom, placementZoom);
minZoom, maxZoom, placementZoom, glyphAngle);

// add the two triangles, referencing the four coordinates we just inserted.
buffer.triangles.add(triangleIndex + 0, triangleIndex + 1, triangleIndex + 2);
Expand Down
2 changes: 2 additions & 0 deletions src/mbgl/shader/sdf_shader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ class SDFShader : public Shader {
Uniform<GLfloat> u_buffer = {"u_buffer", *this};
Uniform<GLfloat> u_gamma = {"u_gamma", *this};
Uniform<GLfloat> u_zoom = {"u_zoom", *this};
Uniform<GLfloat> u_pitch = {"u_pitch", *this};
Uniform<GLfloat> u_aspect_ratio = {"u_aspect_ratio", *this};
Uniform<GLint> u_skewed = {"u_skewed", *this};
Uniform<GLint> u_texture = {"u_texture", *this};
Uniform<GLint> u_fadetexture = {"u_fadetexture", *this};
Expand Down
14 changes: 7 additions & 7 deletions src/mbgl/text/quads.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ SymbolQuads getIconQuads(Anchor& anchor, const PositionedIcon& shapedIcon,
}

SymbolQuads quads;
quads.emplace_back(tl, tr, bl, br, image.pos, 0, anchor.point, globalMinScale, std::numeric_limits<float>::infinity());
quads.emplace_back(tl, tr, bl, br, image.pos, 0, 0, anchor.point, globalMinScale, std::numeric_limits<float>::infinity());
return quads;
}

Expand Down Expand Up @@ -188,12 +188,11 @@ SymbolQuads getGlyphQuads(Anchor& anchor, const Shaping& shapedText,
Point<float> tr = otr;
Point<float> bl = obl;
Point<float> br = obr;
const float angle = instance.angle + textRotate;

if (angle) {
if (textRotate) {
// Compute the transformation matrix.
float angle_sin = std::sin(angle);
float angle_cos = std::cos(angle);
float angle_sin = std::sin(textRotate);
float angle_cos = std::cos(textRotate);
std::array<float, 4> matrix = {{angle_cos, -angle_sin, angle_sin, angle_cos}};

tl = util::matrixMultiply(matrix, tl);
Expand All @@ -205,8 +204,9 @@ SymbolQuads getGlyphQuads(Anchor& anchor, const Shaping& shapedText,
// Prevent label from extending past the end of the line
const float glyphMinScale = std::max(instance.minScale, anchor.scale);

const float glyphAngle = std::fmod((anchor.angle + textRotate + instance.offset + 2 * M_PI), (2 * M_PI));
quads.emplace_back(tl, tr, bl, br, rect, glyphAngle, instance.anchorPoint, glyphMinScale, instance.maxScale);
const float anchorAngle = std::fmod((anchor.angle + textRotate + instance.offset + 2 * M_PI), (2 * M_PI));
const float glyphAngle = std::fmod((instance.angle + textRotate + instance.offset + 2 * M_PI), (2 * M_PI));
quads.emplace_back(tl, tr, bl, br, rect, anchorAngle, glyphAngle, instance.anchorPoint, glyphMinScale, instance.maxScale);

}

Expand Down
7 changes: 4 additions & 3 deletions src/mbgl/text/quads.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,22 @@ class SymbolLayoutProperties;
struct SymbolQuad {
explicit SymbolQuad(const Point<float> &tl_, const Point<float> &tr_,
const Point<float> &bl_, const Point<float> &br_,
const Rect<uint16_t> &tex_, float angle_, const Point<float> &anchorPoint_,
const Rect<uint16_t> &tex_, float anchorAngle_, float glyphAngle_, const Point<float> &anchorPoint_,
float minScale_, float maxScale_)
: tl(tl_),
tr(tr_),
bl(bl_),
br(br_),
tex(tex_),
angle(angle_),
anchorAngle(anchorAngle_),
glyphAngle(glyphAngle_),
anchorPoint(anchorPoint_),
minScale(minScale_),
maxScale(maxScale_) {}

Point<float> tl, tr, bl, br;
Rect<uint16_t> tex;
float angle;
float anchorAngle, glyphAngle;
Point<float> anchorPoint;
float minScale, maxScale;
};
Expand Down

0 comments on commit bad41e6

Please sign in to comment.