Changed defaults

This commit is contained in:
2026-05-21 15:08:36 +10:00
parent a9eeed30cf
commit 09efe2d6a0
6 changed files with 30 additions and 9 deletions

View File

@@ -110,7 +110,11 @@ std::vector<unsigned char> BuildRuntimeShaderGlobalParamsStd140(
AppendStd140Int(buffer, EnumIndexForDefault(definition, value)); AppendStd140Int(buffer, EnumIndexForDefault(definition, value));
break; break;
case ShaderParameterType::Text: case ShaderParameterType::Text:
{
const auto scaleIt = artifact.textTextureWidthScales.find(definition.id);
AppendStd140Float(buffer, scaleIt == artifact.textTextureWidthScales.end() ? 1.0f : scaleIt->second);
break; break;
}
case ShaderParameterType::Trigger: case ShaderParameterType::Trigger:
AppendStd140Int(buffer, value.numberValues.empty() ? 0 : static_cast<int>(value.numberValues[0])); AppendStd140Int(buffer, value.numberValues.empty() ? 0 : static_cast<int>(value.numberValues[0]));
AppendStd140Float(buffer, value.numberValues.size() > 1 ? static_cast<float>(value.numberValues[1]) : -1000000.0f); AppendStd140Float(buffer, value.numberValues.size() > 1 ? static_cast<float>(value.numberValues[1]) : -1000000.0f);

View File

@@ -61,7 +61,7 @@ bool RuntimeShaderRenderer::CommitPreparedProgram(RuntimePreparedShaderProgram&
DestroyProgram(); DestroyProgram();
return false; return false;
} }
mTextTextures.RefreshTextTextures(); mTextTextures.RefreshTextTextures(&mArtifact);
return true; return true;
} }
@@ -71,7 +71,7 @@ void RuntimeShaderRenderer::UpdateArtifactState(const RuntimeShaderArtifact& art
mArtifact.parameterValues = artifact.parameterValues; mArtifact.parameterValues = artifact.parameterValues;
mArtifact.message = artifact.message; mArtifact.message = artifact.message;
mTextTextures.UpdateArtifactState(artifact); mTextTextures.UpdateArtifactState(artifact);
mTextTextures.RefreshTextTextures(); mTextTextures.RefreshTextTextures(&mArtifact);
} }
bool RuntimeShaderRenderer::BuildPreparedProgram( bool RuntimeShaderRenderer::BuildPreparedProgram(

View File

@@ -102,11 +102,20 @@ void RuntimeTextTextureCache::UpdateArtifactState(const RuntimeShaderArtifact& a
mArtifact.parameterValues = artifact.parameterValues; mArtifact.parameterValues = artifact.parameterValues;
} }
void RuntimeTextTextureCache::RefreshTextTextures() void RuntimeTextTextureCache::RefreshTextTextures(RuntimeShaderArtifact* artifactState)
{ {
if (artifactState)
artifactState->textTextureWidthScales.clear();
for (TextTexture& textTexture : mTextTextures) for (TextTexture& textTexture : mTextTextures)
{ {
EnsureTextTexture(textTexture); EnsureTextTexture(textTexture);
if (artifactState)
{
const float scale = textTexture.width == 0
? 1.0f
: static_cast<float>(textTexture.liveWidth) / static_cast<float>(textTexture.width);
artifactState->textTextureWidthScales[textTexture.parameterId] = scale;
}
} }
} }
@@ -326,7 +335,8 @@ bool RuntimeTextTextureCache::EnsureTextTexture(TextTexture& texture)
unsigned width = 0; unsigned width = 0;
unsigned height = 0; unsigned height = 0;
std::vector<unsigned char> pixels = ComposeTextMask(*atlas, texture, text, width, height); unsigned liveWidth = 1;
std::vector<unsigned char> pixels = ComposeTextMask(*atlas, texture, text, width, height, liveWidth);
if (pixels.empty() || width == 0 || height == 0) if (pixels.empty() || width == 0 || height == 0)
return false; return false;
@@ -356,10 +366,11 @@ bool RuntimeTextTextureCache::EnsureTextTexture(TextTexture& texture)
texture.cachedText = text; texture.cachedText = text;
texture.width = width; texture.width = width;
texture.height = height; texture.height = height;
texture.liveWidth = liveWidth;
return texture.texture != 0; return texture.texture != 0;
} }
std::vector<unsigned char> RuntimeTextTextureCache::ComposeTextMask(const Atlas& atlas, const TextTexture& texture, const std::string& text, unsigned& width, unsigned& height) const std::vector<unsigned char> RuntimeTextTextureCache::ComposeTextMask(const Atlas& atlas, const TextTexture& texture, const std::string& text, unsigned& width, unsigned& height, unsigned& liveWidth) const
{ {
double advance = 0.0; double advance = 0.0;
for (unsigned char character : text) for (unsigned char character : text)
@@ -370,7 +381,8 @@ std::vector<unsigned char> RuntimeTextTextureCache::ComposeTextMask(const Atlas&
} }
const unsigned fixedWidth = static_cast<unsigned>(std::ceil(static_cast<double>(texture.maxLength) * kFontPixelsPerEm * 0.9)) + kTextTexturePadding * 2u; const unsigned fixedWidth = static_cast<unsigned>(std::ceil(static_cast<double>(texture.maxLength) * kFontPixelsPerEm * 0.9)) + kTextTexturePadding * 2u;
width = (std::max)(fixedWidth, static_cast<unsigned>(std::ceil(advance * kFontPixelsPerEm)) + kTextTexturePadding * 2u); liveWidth = (std::max)(1u, static_cast<unsigned>(std::ceil(advance * kFontPixelsPerEm)) + kTextTexturePadding * 2u);
width = (std::max)(fixedWidth, liveWidth);
height = kTextTextureHeight; height = kTextTextureHeight;
std::vector<unsigned char> mask(static_cast<std::size_t>(width) * height, 0); std::vector<unsigned char> mask(static_cast<std::size_t>(width) * height, 0);

View File

@@ -17,7 +17,7 @@ public:
bool Configure(const RuntimeShaderArtifact& artifact, std::string& error); bool Configure(const RuntimeShaderArtifact& artifact, std::string& error);
void UpdateArtifactState(const RuntimeShaderArtifact& artifact); void UpdateArtifactState(const RuntimeShaderArtifact& artifact);
void RefreshTextTextures(); void RefreshTextTextures(RuntimeShaderArtifact* artifactState = nullptr);
void BindTextTextures(GLuint program); void BindTextTextures(GLuint program);
void ShutdownGl(); void ShutdownGl();
@@ -58,6 +58,7 @@ private:
GLuint texture = 0; GLuint texture = 0;
unsigned width = 0; unsigned width = 0;
unsigned height = 0; unsigned height = 0;
unsigned liveWidth = 1;
unsigned maxLength = 64; unsigned maxLength = 64;
}; };
@@ -65,7 +66,7 @@ private:
bool LoadAtlasJson(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 LoadAtlasImage(const RenderCadenceCompositor::FontAtlasBuildOutput& output, Atlas& atlas, std::string& error) const;
bool EnsureTextTexture(TextTexture& texture); bool EnsureTextTexture(TextTexture& texture);
std::vector<unsigned char> ComposeTextMask(const Atlas& atlas, const TextTexture& texture, const std::string& text, unsigned& width, unsigned& height) const; std::vector<unsigned char> ComposeTextMask(const Atlas& atlas, const TextTexture& texture, const std::string& text, unsigned& width, unsigned& height, unsigned& liveWidth) const;
const Atlas* FindAtlas(const std::string& fontId) const; const Atlas* FindAtlas(const std::string& fontId) const;
static const ShaderParameterValue* FindParameterValue(const RuntimeShaderArtifact& artifact, const std::string& parameterId); static const ShaderParameterValue* FindParameterValue(const RuntimeShaderArtifact& artifact, const std::string& parameterId);
static std::string DefaultTextValue(const RuntimeShaderArtifact& artifact, const std::string& parameterId); static std::string DefaultTextValue(const RuntimeShaderArtifact& artifact, const std::string& parameterId);

View File

@@ -25,5 +25,6 @@ struct RuntimeShaderArtifact
std::string message; std::string message;
std::vector<ShaderParameterDefinition> parameterDefinitions; std::vector<ShaderParameterDefinition> parameterDefinitions;
std::map<std::string, ShaderParameterValue> parameterValues; std::map<std::string, ShaderParameterValue> parameterValues;
std::map<std::string, float> textTextureWidthScales;
std::vector<RenderCadenceCompositor::FontAtlasBuildOutput> fontAtlases; std::vector<RenderCadenceCompositor::FontAtlasBuildOutput> fontAtlases;
}; };

View File

@@ -52,7 +52,10 @@ std::string BuildParameterUniforms(const std::vector<ShaderParameterDefinition>&
for (const ShaderParameterDefinition& definition : parameters) for (const ShaderParameterDefinition& definition : parameters)
{ {
if (definition.type == ShaderParameterType::Text) if (definition.type == ShaderParameterType::Text)
{
source << "\tfloat " << definition.id << "TextureWidthScale;\n";
continue; continue;
}
if (definition.type == ShaderParameterType::Trigger) if (definition.type == ShaderParameterType::Trigger)
{ {
source << "\tint " << definition.id << ";\n"; source << "\tint " << definition.id << ";\n";
@@ -109,7 +112,7 @@ std::string BuildTextHelpers(const std::vector<ShaderParameterDefinition>& param
<< "{\n" << "{\n"
<< "\tif (uv.x < 0.0 || uv.x > 1.0 || uv.y < 0.0 || uv.y > 1.0)\n" << "\tif (uv.x < 0.0 || uv.x > 1.0 || uv.y < 0.0 || uv.y > 1.0)\n"
<< "\t\treturn 0.0;\n" << "\t\treturn 0.0;\n"
<< "\treturn " << definition.id << "Texture.Sample(uv).r;\n" << "\treturn " << definition.id << "Texture.Sample(float2(uv.x * " << definition.id << "TextureWidthScale, uv.y)).r;\n"
<< "}\n\n" << "}\n\n"
<< "float4 draw" << suffix << "(float2 uv, float4 fillColor)\n" << "float4 draw" << suffix << "(float2 uv, float4 fillColor)\n"
<< "{\n" << "{\n"