Change TextDrawable base class
This commit is contained in:
@@ -44,7 +44,8 @@ namespace OpenVulkano::Scene
|
||||
Shader DEFAULT_SHADER_MSDF = MakeDefaultShader(FontAtlasType::MSDF);
|
||||
}
|
||||
|
||||
TextDrawable::TextDrawable(const TextConfig& config) : m_cfg(config)
|
||||
TextDrawable::TextDrawable(const TextConfig& config)
|
||||
: Drawable(DrawEncoder::GetDrawEncoder<TextDrawable>()), m_cfg(config)
|
||||
{
|
||||
m_uniBuffer.Init(sizeof(TextConfig), &m_cfg, 3);
|
||||
m_uniBuffer.binding.stageFlags = ShaderProgramType::FRAGMENT;
|
||||
@@ -63,7 +64,7 @@ namespace OpenVulkano::Scene
|
||||
{}
|
||||
|
||||
TextDrawable::TextDrawable(const Array<char>& atlasMetadata, Texture* atlasTex, const TextConfig& config)
|
||||
: m_cfg(config)
|
||||
: Drawable(DrawEncoder::GetDrawEncoder<TextDrawable>()), m_cfg(config)
|
||||
{
|
||||
uint32_t isPacked;
|
||||
std::memcpy(&isPacked, atlasMetadata.Data() + (atlasMetadata.Size() - sizeof(uint32_t)), sizeof(uint32_t));
|
||||
@@ -74,18 +75,17 @@ namespace OpenVulkano::Scene
|
||||
m_atlasData = std::make_shared<AtlasData>();
|
||||
if (isPacked)
|
||||
{
|
||||
m_material.texture = &m_atlasData->texture;
|
||||
Texture* texture = &m_atlasData->texture;
|
||||
m_atlasData->img = Image::IImageLoader::loadData(reinterpret_cast<const uint8_t*>(atlasMetadata.Data()), offsetToMetadata);
|
||||
m_material.texture->format = m_atlasData->img->dataFormat;
|
||||
m_material.texture->resolution = m_atlasData->img->resolution;
|
||||
m_material.texture->size = m_atlasData->img->data.Size();
|
||||
m_material.texture->textureBuffer = m_atlasData->img->data.Data();
|
||||
texture->format = m_atlasData->img->dataFormat;
|
||||
texture->resolution = m_atlasData->img->resolution;
|
||||
texture->size = m_atlasData->img->data.Size();
|
||||
texture->textureBuffer = m_atlasData->img->data.Data();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (atlasTex == nullptr) { throw std::runtime_error("Atlas texture cannot be null with non-packed atlas metadata"); }
|
||||
m_atlasData->texture = *atlasTex;
|
||||
m_material.texture = atlasTex;
|
||||
}
|
||||
|
||||
// metadata info
|
||||
@@ -110,12 +110,12 @@ namespace OpenVulkano::Scene
|
||||
m_uniBuffer.binding.stageFlags = ShaderProgramType::FRAGMENT;
|
||||
if (m_atlasData->meta.atlasType == FontAtlasType::BITMAP)
|
||||
{
|
||||
m_material.texture->m_samplerConfig = &SamplerConfig::NEAREST;
|
||||
m_atlasData->texture.m_samplerConfig = &SamplerConfig::NEAREST;
|
||||
}
|
||||
}
|
||||
|
||||
TextDrawable::TextDrawable(const std::shared_ptr<AtlasData>& atlasData, const TextConfig& config)
|
||||
: m_atlasData(atlasData), m_cfg(config)
|
||||
: Drawable(DrawEncoder::GetDrawEncoder<TextDrawable>()), m_atlasData(atlasData), m_cfg(config)
|
||||
{
|
||||
if (!atlasData || !*atlasData) throw std::runtime_error("Cannot initialize text drawable with empty atlas data");
|
||||
m_uniBuffer.Init(sizeof(TextConfig), &m_cfg, 3);
|
||||
@@ -216,16 +216,16 @@ namespace OpenVulkano::Scene
|
||||
}
|
||||
m_bbox.Init(bmin, bmax);
|
||||
|
||||
Shader* shader = nullptr;
|
||||
switch (m_atlasData->meta.atlasType)
|
||||
if (!GetShader())
|
||||
{
|
||||
case FontAtlasType::SDF: shader = &DEFAULT_SHADER_SDF; break;
|
||||
case FontAtlasType::MSDF: shader = &DEFAULT_SHADER_MSDF; break;
|
||||
default: Logger::RENDER->warn("No default shader for atlas type: {}", m_atlasData->meta.atlasType.GetName());
|
||||
case FontAtlasType::BITMAP: shader = &DEFAULT_SHADER_BITMAP; break;
|
||||
switch (m_atlasData->meta.atlasType)
|
||||
{
|
||||
case FontAtlasType::SDF: SetShader(&DEFAULT_SHADER_SDF); break;
|
||||
case FontAtlasType::MSDF: SetShader(&DEFAULT_SHADER_MSDF); break;
|
||||
default: Logger::RENDER->warn("No default shader for atlas type: {}", m_atlasData->meta.atlasType.GetName());
|
||||
case FontAtlasType::BITMAP: SetShader(&DEFAULT_SHADER_BITMAP); break;
|
||||
}
|
||||
}
|
||||
|
||||
SimpleDrawable::Init(shader, &m_geometry, &m_material, &m_uniBuffer);
|
||||
}
|
||||
|
||||
void TextDrawable::SetAtlasData(const std::shared_ptr<AtlasData>& atlasData)
|
||||
|
||||
@@ -6,9 +6,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "SimpleDrawable.hpp"
|
||||
#include "Drawable.hpp"
|
||||
#include "Texture.hpp"
|
||||
#include "Material.hpp"
|
||||
#include "Geometry.hpp"
|
||||
#include "UniformBuffer.hpp"
|
||||
#include "AtlasData.hpp"
|
||||
@@ -26,10 +25,9 @@ namespace OpenVulkano::Scene
|
||||
float smoothing = 1.f/32.f;
|
||||
};
|
||||
|
||||
class TextDrawable : public SimpleDrawable
|
||||
class TextDrawable : public Drawable
|
||||
{
|
||||
Geometry m_geometry;
|
||||
Material m_material;
|
||||
UniformBuffer m_uniBuffer;
|
||||
std::shared_ptr<AtlasData> m_atlasData;
|
||||
Math::AABB m_bbox;
|
||||
@@ -52,5 +50,9 @@ namespace OpenVulkano::Scene
|
||||
[[nodiscard]] TextConfig& GetConfig() { return m_cfg; }
|
||||
[[nodiscard]] const std::string& GetText() const { return m_text; }
|
||||
[[nodiscard]] const std::shared_ptr<AtlasData> GetAtlasData() { return m_atlasData; }
|
||||
|
||||
[[nodiscard]] Geometry* GetGeometry() { return &m_geometry; }
|
||||
[[nodiscard]] Texture* GetTexture() { return &m_atlasData->texture; }
|
||||
[[nodiscard]] UniformBuffer* GetUniformBuffer() { return &m_uniBuffer; }
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user