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));
break;
case ShaderParameterType::Text:
{
const auto scaleIt = artifact.textTextureWidthScales.find(definition.id);
AppendStd140Float(buffer, scaleIt == artifact.textTextureWidthScales.end() ? 1.0f : scaleIt->second);
break;
}
case ShaderParameterType::Trigger:
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);

View File

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

View File

@@ -102,11 +102,20 @@ void RuntimeTextTextureCache::UpdateArtifactState(const RuntimeShaderArtifact& a
mArtifact.parameterValues = artifact.parameterValues;
}
void RuntimeTextTextureCache::RefreshTextTextures()
void RuntimeTextTextureCache::RefreshTextTextures(RuntimeShaderArtifact* artifactState)
{
if (artifactState)
artifactState->textTextureWidthScales.clear();
for (TextTexture& textTexture : mTextTextures)
{
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 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)
return false;
@@ -356,10 +366,11 @@ bool RuntimeTextTextureCache::EnsureTextTexture(TextTexture& texture)
texture.cachedText = text;
texture.width = width;
texture.height = height;
texture.liveWidth = liveWidth;
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;
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;
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;
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);
void UpdateArtifactState(const RuntimeShaderArtifact& artifact);
void RefreshTextTextures();
void RefreshTextTextures(RuntimeShaderArtifact* artifactState = nullptr);
void BindTextTextures(GLuint program);
void ShutdownGl();
@@ -58,6 +58,7 @@ private:
GLuint texture = 0;
unsigned width = 0;
unsigned height = 0;
unsigned liveWidth = 1;
unsigned maxLength = 64;
};
@@ -65,7 +66,7 @@ private:
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 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;
static const ShaderParameterValue* FindParameterValue(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::vector<ShaderParameterDefinition> parameterDefinitions;
std::map<std::string, ShaderParameterValue> parameterValues;
std::map<std::string, float> textTextureWidthScales;
std::vector<RenderCadenceCompositor::FontAtlasBuildOutput> fontAtlases;
};

View File

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