INtial text again

This commit is contained in:
2026-05-20 16:26:36 +10:00
parent 081364e764
commit e43ac21b2f
12 changed files with 608 additions and 15 deletions

View File

@@ -0,0 +1,76 @@
#pragma once
#include "GLExtensions.h"
#include "../../runtime/RuntimeShaderArtifact.h"
#include <map>
#include <string>
#include <vector>
class RuntimeTextTextureCache
{
public:
RuntimeTextTextureCache() = default;
RuntimeTextTextureCache(const RuntimeTextTextureCache&) = delete;
RuntimeTextTextureCache& operator=(const RuntimeTextTextureCache&) = delete;
~RuntimeTextTextureCache();
bool Configure(const RuntimeShaderArtifact& artifact, std::string& error);
void UpdateArtifactState(const RuntimeShaderArtifact& artifact);
void BindTextTextures(GLuint program);
void ShutdownGl();
static void AssignSamplerUniforms(GLuint program, const RuntimeShaderArtifact& artifact);
private:
struct Glyph
{
double advance = 0.0;
double planeLeft = 0.0;
double planeTop = 0.0;
double planeRight = 0.0;
double planeBottom = 0.0;
double atlasLeft = 0.0;
double atlasTop = 0.0;
double atlasRight = 0.0;
double atlasBottom = 0.0;
bool hasBounds = false;
};
struct Atlas
{
std::string fontId;
unsigned width = 0;
unsigned height = 0;
double ascender = -0.9;
double descender = 0.25;
double lineHeight = 1.2;
std::vector<unsigned char> rgbaPixels;
std::map<unsigned, Glyph> glyphsByCodepoint;
};
struct TextTexture
{
std::string parameterId;
std::string fontId;
std::string cachedText;
GLuint texture = 0;
unsigned width = 0;
unsigned height = 0;
};
bool LoadAtlas(const RenderCadenceCompositor::FontAtlasBuildOutput& output, Atlas& atlas, std::string& error) const;
bool LoadAtlasJson(const RenderCadenceCompositor::FontAtlasBuildOutput& output, Atlas& atlas, std::string& error) const;
bool LoadAtlasImage(const RenderCadenceCompositor::FontAtlasBuildOutput& output, Atlas& atlas, std::string& error) const;
bool EnsureTextTexture(TextTexture& texture);
std::vector<unsigned char> ComposeTextMask(const Atlas& atlas, const std::string& text, unsigned& width, unsigned& height) const;
const Atlas* FindAtlas(const std::string& fontId) const;
static const ShaderParameterValue* FindParameterValue(const RuntimeShaderArtifact& artifact, const std::string& parameterId);
static std::string DefaultTextValue(const RuntimeShaderArtifact& artifact, const std::string& parameterId);
static unsigned char SampleAtlasAlpha(const Atlas& atlas, double x, double y);
static void DestroyTexture(TextTexture& texture);
RuntimeShaderArtifact mArtifact;
std::vector<Atlas> mAtlases;
std::vector<TextTexture> mTextTextures;
};