Files
OpenVulkano/openVulkanoCpp/Vulkan/Scene/VulkanTexture.hpp

75 lines
2.6 KiB
C++

/*
* 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/.
*/
#pragma once
#include "IRecordable.hpp"
#include "Vulkan/Image.hpp"
#include "Vulkan/Context.hpp"
#include "Vulkan/Resources/ResourceManager.hpp"
#include "Vulkan/Scene/VulkanShader.hpp"
#include "Scene/Texture.hpp"
namespace OpenVulkano::Vulkan
{
class VulkanTexture : public IRecordable, public Image
{
public:
Scene::Texture* m_texture = nullptr;
vk::DescriptorSet m_descriptorSet;
uint32_t m_setId;
virtual void Init(ResourceManager* resManager, Scene::Texture* texture, vk::DescriptorSetLayout* descriptorSetLayout, const DescriptorSetLayoutBinding& binding, uint32_t setId)
{
m_texture = texture;
m_setId = setId;
Image::Init(resManager->GetContext()->device.get(), { texture->resolution.x, texture->resolution.y, texture->resolution.z });
resManager->CopyDataToImage(m_texture->size, m_texture->textureBuffer, this);
texture->updated = false;
// Setup Descriptor set
const vk::DescriptorSetAllocateInfo descSetAllocInfo = { ResourceManager::INSTANCE->descriptorPool, 1, descriptorSetLayout };
m_descriptorSet = resManager->GetContext()->device->device.allocateDescriptorSets(descSetAllocInfo)[0];
vk::DescriptorImageInfo imageInfo = { sampler, view, vk::ImageLayout::eShaderReadOnlyOptimal };
vk::WriteDescriptorSet writeDescriptorSet = { m_descriptorSet, binding.bindingId, 0, 1 };
writeDescriptorSet.descriptorType = static_cast<vk::DescriptorType>(binding.descriptorType);
writeDescriptorSet.pImageInfo = &imageInfo;
resManager->GetContext()->device->device.updateDescriptorSets(1, &writeDescriptorSet, 0, nullptr);
texture->renderTexture = this;
}
void Record(VulkanDrawContext* context) override
{
context->commandBuffer.bindDescriptorSets(vk::PipelineBindPoint::eGraphics, context->GetShader()->pipelineLayout, m_setId, 1, &m_descriptorSet, 0, nullptr);
}
};
/*class VulkanTextureDynamic : VulkanTexture
{
public:
uint32_t lastUpdate = -1;
ResourceManager* resourceManager;
void Init(ResourceManager* resManager, Scene::Texture* texture) override
{
resourceManager = resManager;
VulkanTexture::Init(resourceManager, texture);
lastUpdate = -1;
}
void Record(VulkanDrawContext* context) override
{
if(bufferId != lastUpdate && m_texture->updated)
{
lastUpdate = bufferId;
resourceManager->CopyDataToImage(m_texture->size, m_texture->textureBuffer, this);
m_texture->updated = false;
}
VulkanTexture::Record(cmdBuffer, bufferId);
}
};*/
}