2017-01-23 18:33:12 -05:00
|
|
|
// Copyright 2017 The Servo Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2017-01-25 23:25:54 -05:00
|
|
|
#version 330
|
2017-01-23 18:33:12 -05:00
|
|
|
|
2017-01-25 14:52:18 -05:00
|
|
|
#define MAX_GLYPHS 2048
|
|
|
|
|
|
|
|
// Accessors to work around Apple driver bugs.
|
|
|
|
#define GLYPH_DESCRIPTOR_UNITS_PER_EM(d) (d).misc.x
|
|
|
|
#define IMAGE_DESCRIPTOR_ATLAS_POS(d) (d).xy
|
|
|
|
#define IMAGE_DESCRIPTOR_POINT_SIZE(d) (d).z
|
2017-01-24 01:03:40 -05:00
|
|
|
|
|
|
|
// Information about the metrics of each glyph.
|
|
|
|
layout(std140) struct GlyphDescriptor {
|
2017-01-25 14:52:18 -05:00
|
|
|
// The left/bottom/right/top offsets of the glyph from point (0, 0) in glyph space.
|
2017-01-24 01:03:40 -05:00
|
|
|
ivec4 extents;
|
2017-01-25 14:52:18 -05:00
|
|
|
// x: Units per em.
|
|
|
|
uvec4 misc;
|
2017-01-23 22:39:51 -05:00
|
|
|
};
|
2017-01-23 18:33:12 -05:00
|
|
|
|
|
|
|
// The size of the atlas in pixels.
|
|
|
|
uniform uvec2 uAtlasSize;
|
|
|
|
|
2017-01-24 01:03:40 -05:00
|
|
|
layout(std140) uniform ubGlyphDescriptors {
|
|
|
|
GlyphDescriptor uGlyphs[MAX_GLYPHS];
|
|
|
|
};
|
2017-01-23 22:39:51 -05:00
|
|
|
|
2017-01-24 18:30:14 -05:00
|
|
|
layout(std140) uniform ubImageDescriptors {
|
2017-01-25 14:52:18 -05:00
|
|
|
uvec4 uImages[MAX_GLYPHS];
|
2017-01-23 18:33:12 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
// The position of each vertex in glyph space.
|
|
|
|
in ivec2 aPosition;
|
|
|
|
|
2017-01-24 18:30:14 -05:00
|
|
|
// Which glyph the vertex belongs to.
|
2017-01-23 18:33:12 -05:00
|
|
|
//
|
|
|
|
// TODO(pcwalton): See if this is faster as a binary search on the vertex ID.
|
2017-01-24 18:30:14 -05:00
|
|
|
in uint aGlyphIndex;
|
2017-01-23 18:33:12 -05:00
|
|
|
|
|
|
|
// The vertex ID, passed along onto the TCS.
|
2017-01-25 23:25:54 -05:00
|
|
|
flat out int vVertexID;
|
2017-01-23 18:33:12 -05:00
|
|
|
|
|
|
|
void main() {
|
|
|
|
vVertexID = gl_VertexID;
|
|
|
|
|
2017-01-25 14:52:18 -05:00
|
|
|
uvec4 image = uImages[aGlyphIndex];
|
2017-01-24 18:30:14 -05:00
|
|
|
GlyphDescriptor glyph = uGlyphs[aGlyphIndex];
|
2017-01-24 01:03:40 -05:00
|
|
|
|
2017-01-24 18:30:14 -05:00
|
|
|
vec2 glyphPos = vec2(aPosition.x - glyph.extents.x, glyph.extents.w - aPosition.y);
|
2017-01-25 14:52:18 -05:00
|
|
|
float pointSize = float(IMAGE_DESCRIPTOR_POINT_SIZE(image)) / 65536.0f;
|
|
|
|
vec2 glyphPxPos = glyphPos * pointSize / GLYPH_DESCRIPTOR_UNITS_PER_EM(glyph);
|
|
|
|
vec2 atlasPos = glyphPxPos + vec2(IMAGE_DESCRIPTOR_ATLAS_POS(image));
|
2017-01-24 01:03:40 -05:00
|
|
|
|
2017-01-23 18:33:12 -05:00
|
|
|
gl_Position = vec4(atlasPos, 0.0f, 1.0f);
|
|
|
|
}
|
|
|
|
|