Cleanup duplicated text shader

This commit is contained in:
Georg Hagen
2025-01-04 01:52:11 +01:00
parent 519be60c8c
commit f124a22910
3 changed files with 20 additions and 39 deletions

View File

@@ -29,20 +29,23 @@ namespace OpenVulkano::Scene
public:
enum Type : int16_t
{
SDF = 0,
BITMAP = 0,
SDF,
MSDF,
BITMAP,
UNKNOWN
};
static constexpr std::string_view DEFAULT_FG_SHADERS[] = { "Shader/text", "Shader/msdfText" };
public:
FontAtlasType(Type type) : m_type(type) {}
Type GetType() const { return m_type; }
const std::string_view& GetDefaultFragmentShader() const
static constexpr std::string_view DEFAULT_FG_SHADERS[] = { "Shader/text", "Shader/sdfText", "Shader/msdfText" };
constexpr FontAtlasType(Type type) : m_type(type) {}
[[nodiscard]] constexpr Type GetType() const { return m_type; }
[[nodiscard]] constexpr const std::string_view& GetDefaultFragmentShader() const
{
return DEFAULT_FG_SHADERS[static_cast<int>(m_type)];
}
private:
Type m_type;
};
@@ -60,6 +63,8 @@ namespace OpenVulkano::Scene
AtlasMetadata meta;
Unique<Image::Image> img;
Texture texture;
operator bool() const { return !glyphs.empty(); }
};
}

View File

@@ -22,11 +22,13 @@ namespace OpenVulkano::Scene
{
namespace
{
Shader MakeDefaultShader(const std::string& vertexShader, const std::string& fragmentShader)
constexpr uint32_t MISSING_GLYPH_SYMBOL = '?';
Shader MakeDefaultShader(FontAtlasType type)
{
Shader shader;
shader.AddShaderProgram(ShaderProgramType::VERTEX, "Shader/" + vertexShader);
shader.AddShaderProgram(ShaderProgramType::FRAGMENT, "Shader/" + fragmentShader);
shader.AddShaderProgram(ShaderProgramType::VERTEX, "Shader/text");
shader.AddShaderProgram(ShaderProgramType::FRAGMENT, std::string(type.GetDefaultFragmentShader()));
shader.AddVertexInputDescription(Vertex::GetVertexInputDescription());
shader.AddDescriptorSetLayoutBinding(Texture::DESCRIPTOR_SET_LAYOUT_BINDING);
DescriptorSetLayoutBinding desc = UniformBuffer::DESCRIPTOR_SET_LAYOUT_BINDING;
@@ -38,9 +40,9 @@ namespace OpenVulkano::Scene
}
}
Shader TextDrawable::DEFAULT_SHADER_BITMAP = MakeDefaultShader("text", "text");
Shader TextDrawable::DEFAULT_SHADER_SDF = MakeDefaultShader("sdfText", "sdfText");
Shader TextDrawable::DEFAULT_SHADER_MSDF = MakeDefaultShader("sdfText", "msdfText");
Shader TextDrawable::DEFAULT_SHADER_BITMAP = MakeDefaultShader(FontAtlasType::BITMAP);
Shader TextDrawable::DEFAULT_SHADER_SDF = MakeDefaultShader(FontAtlasType::SDF);
Shader TextDrawable::DEFAULT_SHADER_MSDF = MakeDefaultShader(FontAtlasType::MSDF);
TextDrawable::TextDrawable(const TextConfig& config) : m_cfg(config)
{

View File

@@ -1,26 +0,0 @@
#version 450
layout(location = 0) in vec3 position;
layout(location = 1) in vec3 normal;
layout(location = 2) in vec3 tangent;
layout(location = 3) in vec3 biTangent;
layout(location = 4) in vec3 textureCoordinates;
layout(location = 5) in vec4 color;
layout(location = 1) out vec2 fragTextureCoordinates;
layout(set = 0, binding = 0) uniform NodeData
{
mat4 world;
} node;
layout(set = 1, binding = 0) uniform CameraData
{
mat4 viewProjection;
mat4 view;
mat4 projection;
vec4 camPos;
} cam;
void main() {
gl_Position = cam.viewProjection * node.world * vec4(position, 1.0);
fragTextureCoordinates.xy = textureCoordinates.xy;
}