the power of two

This commit is contained in:
jrkb 2023-04-03 16:07:18 +02:00
parent 5c4627f247
commit 61ae05c003

View file

@ -17,6 +17,22 @@
#define F16DOT16_TO_DOUBLE(x) (1 / 65536. * double(x)) #define F16DOT16_TO_DOUBLE(x) (1 / 65536. * double(x))
#define DOUBLE_TO_F16DOT16(x) FT_Fixed(65536. * x) #define DOUBLE_TO_F16DOT16(x) FT_Fixed(65536. * x)
inline int32_t calculateUpperPowerOfTwo(int32_t v){
v--;
v |= v >> 1;
v |= v >> 2;
v |= v >> 4;
v |= v >> 8;
v |= v >> 16;
v++;
return v;
}
inline bool isPowerOfTwo(int i){
return (i & (i - 1)) == 0;
}
class Font { class Font {
struct Glyph { struct Glyph {
FT_UInt index; FT_UInt index;
@ -369,10 +385,15 @@ class Font {
GL_NEAREST); GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
GL_NEAREST); GL_NEAREST);
int bufferGlyphsSize = bufferGlyphs.size();
if(!isPowerOfTwo(bufferGlyphsSize)){
bufferGlyphsSize = calculateUpperPowerOfTwo(bufferGlyphsSize);
}
glTexImage2D(GL_TEXTURE_2D, glTexImage2D(GL_TEXTURE_2D,
0, 0,
GL_RG32I, GL_RG32I,
bufferGlyphs.size(), bufferGlyphsSize,
1, 1,
0, 0,
GL_RG_INTEGER, GL_RG_INTEGER,
@ -412,6 +433,10 @@ class Font {
//GL_INT, //GL_INT,
//data); //data);
int bufferCurvesSize = bufferCurves.size();
if(!isPowerOfTwo(bufferCurvesSize)){
bufferCurvesSize = calculateUpperPowerOfTwo(bufferCurvesSize);
}
glActiveTexture(GL_TEXTURE1); glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, curveBuffer); glBindTexture(GL_TEXTURE_2D, curveBuffer);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
@ -423,7 +448,7 @@ class Font {
glTexImage2D(GL_TEXTURE_2D, glTexImage2D(GL_TEXTURE_2D,
0, 0,
GL_RG32F, GL_RG32F,
bufferCurves.size(), bufferCurvesSize,
1, 1,
0, 0,
GL_RG, GL_RG,