@@ -124,9 +124,10 @@ void GLLabel::InsertText(std::u32string text, size_t index, glm::vec4 color, FT_
124
124
// This theoretically could overflow, but the atlas position will
125
125
// never be over half the size of a uint16, so it's fine.
126
126
unsigned int k = (j < 4 ) ? j : 6 - j;
127
- unsigned int norm[2 ] = { k & 1 , k > 1 };
128
- v[j].data [0 ] = (glyph->bezierAtlasPos [0 ]<<1 ) + norm[0 ];
129
- v[j].data [1 ] = (glyph->bezierAtlasPos [1 ]<<1 ) + norm[1 ];
127
+ unsigned int normX = k & 1 ;
128
+ unsigned int normY = k > 1 ;
129
+ unsigned int norm = (normX << 1 ) + normY;
130
+ v[j].data = (glyph->bezierAtlasPos [0 ] << 2 ) + norm;
130
131
this ->verts [(index + i)*6 + j] = v[j];
131
132
}
132
133
@@ -240,7 +241,7 @@ void GLLabel::Render(float time, glm::mat4 transform)
240
241
glEnableVertexAttribArray (1 );
241
242
glEnableVertexAttribArray (2 );
242
243
glVertexAttribPointer (0 , 2 , GL_FLOAT, GL_FALSE, sizeof (GLLabel::GlyphVertex), (void *)offsetof (GLLabel::GlyphVertex, pos));
243
- glVertexAttribPointer (1 , 2 , GL_UNSIGNED_SHORT , GL_FALSE, sizeof (GLLabel::GlyphVertex), (void *)offsetof (GLLabel::GlyphVertex, data));
244
+ glVertexAttribPointer (1 , 1 , GL_UNSIGNED_INT , GL_FALSE, sizeof (GLLabel::GlyphVertex), (void *)offsetof (GLLabel::GlyphVertex, data));
244
245
glVertexAttribPointer (2 , 4 , GL_UNSIGNED_BYTE, GL_TRUE, sizeof (GLLabel::GlyphVertex), (void *)offsetof (GLLabel::GlyphVertex, color));
245
246
246
247
glDrawArrays (GL_TRIANGLES, 0 , this ->verts .size ());
@@ -276,14 +277,16 @@ void GLLabel::Render(float time, glm::mat4 transform)
276
277
// This theoretically could overflow, but the atlas position will
277
278
// never be over half the size of a uint16, so it's fine.
278
279
unsigned int k = (j < 4 ) ? j : 6 - j;
279
- x[j].data [0 ] = pipe ->bezierAtlasPos [0 ]*2 + ((k & 1 ) ? 1 : 0 );
280
- x[j].data [1 ] = pipe ->bezierAtlasPos [1 ]*2 + ((k > 1 ) ? 1 : 0 );
280
+ unsigned int normX = k & 1 ;
281
+ unsigned int normY = k > 1 ;
282
+ unsigned int norm = (normX << 1 ) + normY;
283
+ x[j].data = (pipe ->bezierAtlasPos [0 ] << 2 ) + norm;
281
284
// this->verts[(index + i)*6 + j] = v[j];
282
285
}
283
286
284
287
glBindBuffer (GL_ARRAY_BUFFER, this ->caretBuffer );
285
288
glVertexAttribPointer (0 , 2 , GL_FLOAT, GL_FALSE, sizeof (GLLabel::GlyphVertex), (void *)offsetof (GLLabel::GlyphVertex, pos));
286
- glVertexAttribPointer (1 , 2 , GL_UNSIGNED_SHORT , GL_FALSE, sizeof (GLLabel::GlyphVertex), (void *)offsetof (GLLabel::GlyphVertex, data));
289
+ glVertexAttribPointer (1 , 1 , GL_UNSIGNED_INT , GL_FALSE, sizeof (GLLabel::GlyphVertex), (void *)offsetof (GLLabel::GlyphVertex, data));
287
290
glVertexAttribPointer (2 , 4 , GL_UNSIGNED_BYTE, GL_TRUE, sizeof (GLLabel::GlyphVertex), (void *)offsetof (GLLabel::GlyphVertex, color));
288
291
289
292
glBufferData (GL_ARRAY_BUFFER, 6 * sizeof (GlyphVertex), &x[0 ], GL_STREAM_DRAW);
@@ -582,7 +585,7 @@ GLFontManager::Glyph * GLFontManager::GetGlyphForCodepoint(FT_Face face, uint32_
582
585
}
583
586
584
587
GLFontManager::Glyph glyph{};
585
- glyph.bezierAtlasPos [2 ] = -1 ;
588
+ glyph.bezierAtlasPos [1 ] = -1 ;
586
589
glyph.size [0 ] = glyphWidth;
587
590
glyph.size [1 ] = glyphHeight;
588
591
glyph.offset [0 ] = face->glyph ->metrics .horiBearingX ;
@@ -632,8 +635,7 @@ GLFontManager::Glyph * GLFontManager::GetGlyphForCodepoint(FT_Face face, uint32_
632
635
633
636
GLFontManager::Glyph glyph{};
634
637
glyph.bezierAtlasPos [0 ] = atlas->glyphDataBufOffset ;
635
- glyph.bezierAtlasPos [1 ] = 0 ;
636
- glyph.bezierAtlasPos [2 ] = this ->atlases .size ()-1 ;
638
+ glyph.bezierAtlasPos [1 ] = this ->atlases .size ()-1 ;
637
639
glyph.size [0 ] = glyphWidth;
638
640
glyph.size [1 ] = glyphHeight;
639
641
glyph.offset [0 ] = face->glyph ->metrics .horiBearingX ;
@@ -775,11 +777,11 @@ uniform samplerBuffer uGlyphData;
775
777
uniform mat4 uTransform;
776
778
777
779
layout(location = 0) in vec2 vPosition;
778
- layout(location = 1) in vec2 vData;
780
+ layout(location = 1) in uint vData;
779
781
layout(location = 2) in vec4 vColor;
780
782
781
783
out vec4 oColor;
782
- flat out ivec2 oBezierCoord ;
784
+ flat out uint glyphDataOffset ;
783
785
flat out ivec4 oGridRect;
784
786
out vec2 oNormCoord;
785
787
@@ -788,18 +790,18 @@ float ushortFromVec2(vec2 v)
788
790
return (v.y * 65280.0 + v.x * 255.0);
789
791
}
790
792
791
- ivec2 vec2FromPixel(ivec2 coord )
793
+ ivec2 vec2FromPixel(uint offset )
792
794
{
793
- vec4 pixel = texelFetch(uGlyphData, coord.x );
795
+ vec4 pixel = texelFetch(uGlyphData, int(offset) );
794
796
return ivec2(ushortFromVec2(pixel.xy), ushortFromVec2(pixel.zw));
795
797
}
796
798
797
799
void main()
798
800
{
799
801
oColor = vColor;
800
- oBezierCoord = ivec2( vData) / 2 ;
801
- oNormCoord = mod( vData, 2.0 );
802
- oGridRect = ivec4(vec2FromPixel(oBezierCoord ), vec2FromPixel(oBezierCoord + ivec2(1,0) ));
802
+ glyphDataOffset = vData >> 2u ;
803
+ oNormCoord = vec2(( vData & 2u) >> 1, vData & 1u );
804
+ oGridRect = ivec4(vec2FromPixel(glyphDataOffset ), vec2FromPixel(glyphDataOffset + 1u ));
803
805
gl_Position = uTransform*vec4(vPosition, 0.0, 1.0);
804
806
}
805
807
)" ;
@@ -819,7 +821,7 @@ uniform sampler2D uGridAtlas;
819
821
uniform samplerBuffer uGlyphData;
820
822
821
823
in vec4 oColor;
822
- flat in ivec2 oBezierCoord ;
824
+ flat in uint glyphDataOffset ;
823
825
flat in ivec4 oGridRect;
824
826
in vec2 oNormCoord;
825
827
@@ -846,15 +848,15 @@ float normalizedUshortFromVec2(vec2 v)
846
848
return (v.y * 65280.0 + v.x * 255.0) / 65536.0;
847
849
}
848
850
849
- vec4 getPixelByXY(ivec2 coord )
851
+ vec4 getPixelByOffset(int offset )
850
852
{
851
- return texelFetch(uGlyphData, coord.x );
853
+ return texelFetch(uGlyphData, offset );
852
854
}
853
855
854
856
void fetchBezier(int coordIndex, out vec2 p[3])
855
857
{
856
858
for (int i=0; i<3; i++) {
857
- vec4 pixel = getPixelByXY(ivec2(oBezierCoord.x + 2 + coordIndex*3 + i, oBezierCoord.y) );
859
+ vec4 pixel = getPixelByOffset(int(glyphDataOffset) + 2 + coordIndex*3 + i);
858
860
p[i] = vec2(normalizedUshortFromVec2(pixel.xy), normalizedUshortFromVec2(pixel.zw)) - oNormCoord;
859
861
}
860
862
}
0 commit comments