save 75% of font memory
This commit is contained in:
@@ -80,7 +80,7 @@ void GfxOpenGL3::BindTexture(TextureID id) {
|
||||
glUniform1i(pLocTex, 0);
|
||||
GLint fmt = 0;
|
||||
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_INTERNAL_FORMAT, &fmt);
|
||||
glUniform1i(pLocAlfa, fmt == GL_ALPHA);
|
||||
glUniform1i(pLocAlfa, fmt == GL_R8);
|
||||
}
|
||||
|
||||
void GfxOpenGL3::SysReset() {
|
||||
@@ -104,13 +104,23 @@ Li::Texture GfxOpenGL3::LoadTexture(const std::vector<PD::u8>& pixels, int w,
|
||||
|
||||
// Set base format (Always using RGBA as base)
|
||||
GLenum fmt = GL_RGBA;
|
||||
GLenum ifmt = GL_RGBA8;
|
||||
if (type == TextureFormat::RGB24) {
|
||||
ifmt = GL_RGB8;
|
||||
fmt = GL_RGB;
|
||||
} else if (type == TextureFormat::A8) {
|
||||
fmt = GL_ALPHA;
|
||||
ifmt = GL_R8;
|
||||
fmt = GL_RED;
|
||||
}
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, fmt, w, h, 0, fmt, GL_UNSIGNED_BYTE,
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, ifmt, w, h, 0, fmt, GL_UNSIGNED_BYTE,
|
||||
pixels.data());
|
||||
|
||||
if (type == TextureFormat::A8) {
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_A, GL_RED);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_R, GL_ONE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_G, GL_ONE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_B, GL_ONE);
|
||||
}
|
||||
if (filter == TextureFilter::Linear) {
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
|
||||
@@ -51,7 +51,7 @@ PD_API void Font::LoadTTF(const std::vector<u8>& data, int px_height) {
|
||||
// Cache to not render same codepoint tex twice
|
||||
std::map<u32, int> buf_cache;
|
||||
|
||||
std::vector<u8> font_tex(texszs * texszs * 4, 0);
|
||||
std::vector<u8> font_tex(texszs * texszs, 0);
|
||||
fvec2 off;
|
||||
|
||||
bool empty = true;
|
||||
@@ -116,12 +116,8 @@ PD_API void Font::LoadTTF(const std::vector<u8>& data, int px_height) {
|
||||
for (int y = 0; y < h; ++y) {
|
||||
for (int x = 0; x < w; ++x) {
|
||||
int map_pos = ((static_cast<int>(off.y) + y) * texszs +
|
||||
(static_cast<int>(off.x) + x)) *
|
||||
4;
|
||||
font_tex[map_pos + 0] = 255;
|
||||
font_tex[map_pos + 1] = 255;
|
||||
font_tex[map_pos + 2] = 255;
|
||||
font_tex[map_pos + 3] = bitmap[x + y * w];
|
||||
(static_cast<int>(off.x) + x));
|
||||
font_tex[map_pos] = bitmap[x + y * w];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -286,7 +282,7 @@ PD_API void Font::CleanupTMS() {}
|
||||
|
||||
PD_API void Font::BakeAndPush(bool final, std::vector<u8>& font_tex,
|
||||
int texszs) {
|
||||
auto t = PD::Gfx::LoadTexture(font_tex, texszs, texszs);
|
||||
auto t = PD::Gfx::LoadTexture(font_tex, texszs, texszs, TextureFormat::A8);
|
||||
PDLOG("Font: Texture backed as 0x{:X} at {}", t.GetID(), pCurrentTex);
|
||||
Textures.push_back(t.GetID());
|
||||
pCurrentTex = Textures.size();
|
||||
|
||||
Reference in New Issue
Block a user