CachedFont destructor.
All checks were successful
Run ReCI Build Test / Explore-Gitea-Actions (push) Successful in 6m59s

This commit is contained in:
2024-10-18 10:01:21 -04:00
parent 5998bec833
commit 7b5ef6045b
7 changed files with 28 additions and 18 deletions

View File

@@ -35,7 +35,7 @@ namespace JGL {
/// @param window_size
void Update(const Vector2& window_size);
inline void PurgeFontCache() { fontCache.purgeCache(); }
inline void PurgeFontCache() { JGL::fontCache.purgeCache(); }
std::array<GLfloat, 16> OpenGLPerspectiveProjectionRH(float fovY, float aspect, float z_near, float z_far);
/// Returns true if the graphics driver meets the requirements (GL Version & Extensions).
bool MeetsRequirements();

View File

@@ -26,7 +26,7 @@ public:
//CachedGlyph(GLuint texture_id, char c);
CachedGlyph(char c, std::array<GLfloat, 12> texcoords, float x2o, float y2o, float w, float h, float advX, float advY);
char getCharacter();
char getCharacter() const;
[[nodiscard]] std::array<GLfloat, 12> getTexCoords() const;
};
@@ -38,16 +38,19 @@ private:
GLsizei texture_width = 0, texture_height = 0;
unsigned int font_size = 0;
unsigned int font_index = 0;
void Erase();
public:
void appendGlyph(CachedGlyph* glyph);
unsigned int getFontSize();
unsigned int getFontIndex();
unsigned int getFontSize() const;
unsigned int getFontIndex() const;
CachedGlyph* getGlyph(char c);
std::unordered_map<char, CachedGlyph*> getGlyphs();
const GLuint* getTexture();
const GLuint* getTextureHandle();
[[nodiscard]] GLsizei getTextureWidth() const;
[[nodiscard]] GLsizei getTextureHeight() const;
public:
CachedFont(GLuint texture_id, GLsizei texture_width, GLsizei texture_height, unsigned int font_size, unsigned int font_index);
~CachedFont();
};
class JGL::FontCache {

View File

@@ -121,7 +121,7 @@ public:
glDepthFunc(GL_LESS);
glDepthMask(GL_TRUE);
image = new Texture("assets/sprites/Re3D.png", TextureFilteringMode::BILINEAR);
j2d_render_target = new RenderTarget({540, 540}, {0,0,0,0}, false, MSAA_SAMPLE_RATE::MSAA_8X);
j2d_render_target = new RenderTarget({540, 540}, {0,0,0,0}, false, MSAA_SAMPLE_RATE::MSAA_NONE);
image2 = image;
image2_render_target = new RenderTarget(image2);
@@ -208,10 +208,9 @@ public:
//Draw the Render Target that we just drew all that stuff onto.
auto image3_render_target = image2_render_target;
J2D::Begin();
J2D::DrawSprite(j2d_render_target, {0, 0}, 0, {0.5, 0.5}, {1,1}, Colors::White);
J2D::DrawSprite(image3_render_target, {300, 500}, 0, {0.5, 0.5}, {1,1}, Colors::White);
J2D::DrawSprite(image2_render_target, {300, 500}, 0, {0.5, 0.5}, {1,1}, Colors::White);
J2D::End();
}

View File

@@ -726,7 +726,7 @@ namespace JGL {
DrawLine(color, last, first, thickness);
}
void J2D::OutlinePolygon(const Color4 &color, const Vector2* points, int points_size, float thickness) {
void J2D::OutlinePolygon(const Color4& color, const Vector2* points, int points_size, float thickness) {
if (!inJ2D)
Logger::Error("Drawing J2D element before J2D begin.");

View File

@@ -15,7 +15,7 @@
#include <JGL/types/Font.h>
#include <JGL/types/FontCache.h>
#include "JGL/logger/logger.h"
#include <JGL/logger/logger.h>
namespace JGL {
CachedFont* CacheFont(const Font& font, u32 size) {
@@ -121,7 +121,7 @@ namespace JGL {
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glEnable(GL_TEXTURE_2D);
//Texture parameters are restored when the texture_handle is bound
glBindTexture(GL_TEXTURE_2D, *cachedFont->getTexture());
glBindTexture(GL_TEXTURE_2D, *cachedFont->getTextureHandle());
std::vector<std::array<GLfloat, 12>> vertices(text.size());
std::vector<std::array<GLfloat, 12>> texcoords(text.size());
@@ -194,7 +194,7 @@ namespace JGL {
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glEnable(GL_TEXTURE_2D);
glColor4ubv(color.ptr());
glBindTexture(GL_TEXTURE_2D, *cachedFont->getTexture());
glBindTexture(GL_TEXTURE_2D, *cachedFont->getTextureHandle());
std::vector<std::array<GLfloat, 18>> vertices(text.size());
std::vector<std::array<GLfloat, 12>> texcoords(text.size());

View File

@@ -82,8 +82,7 @@ namespace JGL
//return newIndex;
}
Font::~Font()
{
Font::~Font() {
//Detail::UnloadFont(this->index);
}

View File

@@ -2,7 +2,7 @@
using namespace JGL;
char CachedGlyph::getCharacter() {
char CachedGlyph::getCharacter() const {
return character;
}
@@ -25,11 +25,11 @@ void JGL::CachedFont::appendGlyph(JGL::CachedGlyph* glyph) {
glyphs.emplace(glyph->getCharacter(), glyph);
}
unsigned int JGL::CachedFont::getFontSize() {
unsigned int JGL::CachedFont::getFontSize() const {
return font_size;
}
unsigned int JGL::CachedFont::getFontIndex() {
unsigned int JGL::CachedFont::getFontIndex() const {
return font_index;
}
@@ -52,7 +52,7 @@ std::unordered_map<char, CachedGlyph*> CachedFont::getGlyphs() {
return glyphs;
}
const GLuint* CachedFont::getTexture() {
const GLuint* CachedFont::getTextureHandle() {
return &texture;
}
@@ -64,6 +64,15 @@ GLsizei CachedFont::getTextureHeight() const {
return texture_height;
}
void CachedFont::Erase() {
if (texture != 0)
glDeleteTextures(1, &texture);
}
CachedFont::~CachedFont() {
Erase();
}
void FontCache::appendFont(CachedFont* font) {
cachedFonts.push_back(font);
}