Change TextDrawable base class

This commit is contained in:
Georg Hagen
2025-01-04 03:08:06 +01:00
parent 94025c79c6
commit ca93036f31
5 changed files with 101 additions and 45 deletions

View File

@@ -0,0 +1,58 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#include "Scene/TextDrawable.hpp"
#include "VulkanGeometry.hpp"
#include "VulkanNode.hpp"
#include "Vulkan/VulkanDrawContext.hpp"
#include "Vulkan/Scene/VulkanUniformBuffer.hpp"
#include "VulkanTexture.hpp"
using namespace OpenVulkano::Scene;
namespace OpenVulkano::Vulkan
{
void EncodeTextDrawable(Drawable* instance, Vulkan::VulkanDrawContext* drawContext)
{
TextDrawable* drawable = static_cast<TextDrawable*>(instance);
Geometry* mesh = drawable->GetGeometry();
VulkanGeometry* renderGeo = mesh->GetRenderResource();
if (!renderGeo) renderGeo = drawContext->renderer->GetResourceManager().PrepareGeometry(mesh);
renderGeo->RecordBind(drawContext->commandBuffer);
if (drawable->GetUniformBuffer())
{
VulkanUniformBuffer* vkBuffer = drawable->GetUniformBuffer()->GetRenderResource();
if (!vkBuffer)
{
vkBuffer = drawContext->renderer->GetResourceManager().PrepareUniformBuffer(drawable->GetUniformBuffer());
}
vkBuffer->Record(drawContext);
}
if (Texture* texture = drawable->GetTexture())
{
VulkanTexture* renderTexture = texture->GetRenderResource();
if (!renderTexture)
{
renderTexture = drawContext->renderer->GetResourceManager().PrepareTexture(drawable->GetTexture());
}
renderTexture->Record(drawContext);
}
for(Node* node : instance->GetNodes())
{
if (!node->IsEnabled()) [[unlikely]] continue;
drawContext->EncodeNode(node);
renderGeo->RecordDraw(drawContext->commandBuffer);
}
}
}
namespace
{
[[maybe_unused]] void* textDrawableVulkanEncoderReg = DrawEncoder::RegisterVulkanEncodeFunction<TextDrawable>(&OpenVulkano::Vulkan::EncodeTextDrawable);
}