Fix some issue with deinitializing textures

This commit is contained in:
Georg Hagen
2024-07-23 22:01:07 +02:00
parent d262daa66f
commit 02ff22d193
3 changed files with 23 additions and 10 deletions

View File

@@ -14,22 +14,36 @@
namespace OpenVulkano::Scene namespace OpenVulkano::Scene
{ {
class Texture;
struct RenderTexture
{
Texture* m_texture = nullptr;
};
class Texture class Texture
{ {
public: public:
static Texture PLACEHOLDER; static Texture PLACEHOLDER;
static constexpr inline DescriptorSetLayoutBinding DESCRIPTOR_SET_LAYOUT_BINDING = { 0, DescriptorSetLayoutBinding::Type::TYPE_COMBINED_IMAGE_SAMPLER, 1, ShaderProgramType::ALL_GRAPHICS }; static constexpr inline DescriptorSetLayoutBinding DESCRIPTOR_SET_LAYOUT_BINDING = { 0, DescriptorSetLayoutBinding::Type::TYPE_COMBINED_IMAGE_SAMPLER, 1, ShaderProgramType::ALL_GRAPHICS };
Texture(bool placeholder = false) { if (placeholder) MakePlaceholder(); } RenderTexture* renderTexture = nullptr;
ICloseable* renderTexture = nullptr;
void* textureBuffer = nullptr; void* textureBuffer = nullptr;
Math::Vector3ui resolution = {0,0,0};
size_t size = 0; size_t size = 0;
Math::Vector3ui resolution = {0,0,0};
DataFormat format = DataFormat::B8G8R8A8_UNORM; DataFormat format = DataFormat::B8G8R8A8_UNORM;
bool updated = true; bool updated = true;
UpdateFrequency updateFrequency = UpdateFrequency::Never; UpdateFrequency updateFrequency = UpdateFrequency::Never;
Texture(bool placeholder = false) { if (placeholder) MakePlaceholder(); }
~Texture()
{
if (renderTexture)
{
renderTexture->m_texture = nullptr;
}
}
void MakePlaceholder(uint32_t width = 32, uint32_t height = 32, void MakePlaceholder(uint32_t width = 32, uint32_t height = 32,
Math::Vector4uc color1 = {248, 123, 255, 255}, Math::Vector4uc color2 = {250, 19, 255, 255}); Math::Vector4uc color1 = {248, 123, 255, 255}, Math::Vector4uc color2 = {250, 19, 255, 255});
@@ -43,4 +57,4 @@ namespace OpenVulkano::Scene
operator bool() const { return setId >= 0 && texture; } operator bool() const { return setId >= 0 && texture; }
}; };
} }

View File

@@ -64,7 +64,7 @@ namespace OpenVulkano::Vulkan
void MetalBackedTexture::Close() void MetalBackedTexture::Close()
{ {
m_vulkanTexture.Close(); if (m_vulkanTexture) m_vulkanTexture.Close();
if (m_metalTexture) if (m_metalTexture)
{ {
[m_metalTexture release]; [m_metalTexture release];

View File

@@ -16,11 +16,10 @@
namespace OpenVulkano::Vulkan namespace OpenVulkano::Vulkan
{ {
class VulkanTexture : public IRecordable, public Image class VulkanTexture : public Scene::RenderTexture, public IRecordable, public Image
{ {
public: public:
static inline vk::SamplerCreateInfo DEFAULT_SAMPLER_CONFIG {}; static inline vk::SamplerCreateInfo DEFAULT_SAMPLER_CONFIG {};
Scene::Texture* m_texture = nullptr;
vk::Sampler m_sampler; vk::Sampler m_sampler;
vk::DescriptorSet m_descriptorSet; vk::DescriptorSet m_descriptorSet;
@@ -52,7 +51,7 @@ namespace OpenVulkano::Vulkan
virtual ~VulkanTexture() override virtual ~VulkanTexture() override
{ {
if (m_texture) Close(); if (m_sampler) Close();
} }
void Close() override void Close() override
@@ -138,4 +137,4 @@ namespace OpenVulkano::Vulkan
VulkanTexture::Record(context, setId); VulkanTexture::Record(context, setId);
} }
}; };
} }