~ 5% speedup for font-rendering overall
Some checks failed
Run ReCI Build Test / Explore-Gitea-Actions (push) Failing after 1m55s

This is probably the last speedup for this.
This commit is contained in:
2024-09-11 18:33:29 -04:00
parent 9903fc19c9
commit f6e8875eb9
4 changed files with 12 additions and 40 deletions

View File

@@ -1,9 +1,9 @@
#pragma once
#include <array>
#include <map>
#include <vector>
#include <glad/glad.h>
#include <vector>
#include <array>
#include <unordered_map>
/// TODO: FontCache mechanism works amazing, but makes no fucking sense
@@ -33,7 +33,7 @@ public:
/// Represents a Font object as it exists in the font-cache.
class JGL::CachedFont {
private:
std::map<char, CachedGlyph*> glyphs;
std::unordered_map<char, CachedGlyph*> glyphs;
GLuint texture = 0;
GLsizei texture_width = 0, texture_height = 0;
unsigned int font_size = 0;
@@ -43,7 +43,7 @@ public:
unsigned int getFontSize();
unsigned int getFontIndex();
CachedGlyph* getGlyph(char c);
std::map<char, CachedGlyph*> getGlyphs();
std::unordered_map<char, CachedGlyph*> getGlyphs();
const GLuint* getTexture();
[[nodiscard]] GLsizei getTextureWidth() const;
[[nodiscard]] GLsizei getTextureHeight() const;

View File

@@ -26,51 +26,31 @@ public:
void Grab() {
if (hovered)
{
dragging = true;
}
}
void Release() {
dragging = false;
}
void Update(const Vector2& mouse)
{
void Update(const Vector2& mouse) {
if (dragging)
{
position = position.Lerp(mouse, 0.25f);
}
if (mouse.Distance(position) < range)
{
hovered = true;
} else
{
hovered = false;
}
hovered = mouse.Distance(position) < range;
}
void Draw()
{
void Draw() {
if (dragging)
{
J2D::DrawPoint(Colors::White, position, 4.f);
} else if (hovered)
{
else if (hovered)
J2D::DrawPoint(Colors::Reds::Crimson, position, 6.f);
} else
{
else
J2D::DrawPoint(Colors::Reds::Salmon, position, 3.f);
}
J2D::DrawString(Colors::White, std::format("{:.1f},{:.1f}", position.x, position.y), position.x, position.y, 1.f, 10, FreeSans);
}
protected:
private:
};
Texture* image;
class Camera {
@@ -111,8 +91,6 @@ struct point {
GLfloat t;
};
Gizmo a({250, 150});
Gizmo b({200, 250});
Gizmo c({350, 300});
@@ -191,7 +169,6 @@ public:
J2D::FillCircle(Colors::White, {52, 204}, 50, 24);
J2D::OutlineCircle(Colors::White, {153, 204}, 50, 24);
//J2D::FillTriangle(Colors::Red, {{0, 275}, {0, 375}, {100, 375}});
J2D::FillGradientTriangle(Color4(Colors::Red), Color4(Colors::Green), Color4(Colors::Blue), {{0, 275}, {0, 375}, {100, 375}});
J2D::OutlineTriangle(Colors::Blue, {{100, 275}, {0, 275}, {100, 375}});
J2D::DrawGradientLine(Colors::Red, Colors::Blue, {105, 375}, {200, 275}, 2);

View File

@@ -34,10 +34,9 @@ namespace JGL {
if (font.face == nullptr)
return;
FT_Set_Pixel_Sizes(font.face, 0, size);
//If the font doesn't exist in the cache yet.
if (!cachedFont) {
FT_Set_Pixel_Sizes(font.face, 0, size);
jlog::Debug("Caching font data...");
GLuint texture_id;
glGenTextures(1, &texture_id);

View File

@@ -21,9 +21,6 @@ CachedGlyph::CachedGlyph(char c, std::array<GLfloat, 12> texcoords, float x2offs
this->texcoords = texcoords;
}
//TODO
//Because most things shown would be english characters. We can cut down on the iteration time significantly
//by putting each english character at the beginning of the list in order of how often they usually occur in text.
void JGL::CachedFont::appendGlyph(JGL::CachedGlyph* glyph) {
glyphs.emplace(glyph->getCharacter(), glyph);
}
@@ -36,7 +33,6 @@ unsigned int JGL::CachedFont::getFontIndex() {
return font_index;
}
//TODO make this code go faster.
CachedGlyph* JGL::CachedFont::getGlyph(char c) {
auto it = glyphs.find(c);
if (it != glyphs.end())
@@ -52,7 +48,7 @@ CachedFont::CachedFont(GLuint texture_id, GLsizei texture_width, GLsizei texture
this->font_index = font_index;
}
std::map<char, CachedGlyph*> CachedFont::getGlyphs() {
std::unordered_map<char, CachedGlyph*> CachedFont::getGlyphs() {
return glyphs;
}