Update shader to use new render resource system
This commit is contained in:
@@ -17,7 +17,8 @@ namespace OpenVulkano::Vulkan
|
||||
|
||||
VulkanShader::~VulkanShader()
|
||||
{
|
||||
if (shader) Close();
|
||||
if (owner) owner->RemoveShader(this);
|
||||
owner = nullptr;
|
||||
device.destroyPipeline(pipeline);
|
||||
for(auto& shaderModule : shaderModules)
|
||||
{
|
||||
@@ -28,12 +29,9 @@ namespace OpenVulkano::Vulkan
|
||||
device.destroyDescriptorSetLayout(descriptorSetLayout);
|
||||
}
|
||||
|
||||
void VulkanShader::Init(Context* context, Scene::Shader* shader, IShaderOwner* owner)
|
||||
VulkanShader::VulkanShader(Context* context, Scene::Shader* shader, IShaderOwner* owner)
|
||||
: IRenderResource<Scene::Shader>(shader), device(context->device->device), owner(owner), context(context)
|
||||
{
|
||||
this->device = context->device->device;
|
||||
this->shader = shader;
|
||||
this->owner = owner;
|
||||
this->context = context;
|
||||
shaderModules.reserve(shader->shaderPrograms.size());
|
||||
shaderStageCreateInfo.resize(shader->shaderPrograms.size());
|
||||
int i = 0;
|
||||
@@ -45,11 +43,11 @@ namespace OpenVulkano::Vulkan
|
||||
i++;
|
||||
}
|
||||
BuildPipeline();
|
||||
shader->renderShader = this;
|
||||
}
|
||||
|
||||
void VulkanShader::BuildPipeline()
|
||||
{
|
||||
Scene::Shader* shader = GetOwner();
|
||||
std::vector<vk::VertexInputBindingDescription> vertexBindDesc;
|
||||
std::vector<vk::VertexInputAttributeDescription> attributeDescriptions;
|
||||
vertexBindDesc.reserve(shader->vertexInputDescriptions.size());
|
||||
@@ -129,14 +127,6 @@ namespace OpenVulkano::Vulkan
|
||||
context->commandBuffer.bindPipeline(vk::PipelineBindPoint::eGraphics, pipeline);
|
||||
}
|
||||
|
||||
void VulkanShader::Close()
|
||||
{
|
||||
shader->renderShader = nullptr;
|
||||
shader = nullptr;
|
||||
if (owner) owner->RemoveShader(this);
|
||||
owner = nullptr;
|
||||
}
|
||||
|
||||
void VulkanShader::CreatePipelineLayout()
|
||||
{
|
||||
if (!descriptorSetLayouts.empty())
|
||||
@@ -150,6 +140,7 @@ namespace OpenVulkano::Vulkan
|
||||
descriptorSetLayouts.push_back(device.createDescriptorSetLayout({ {}, layoutBindings1.size(), layoutBindings1.data() }));
|
||||
descriptorSetLayouts.push_back(device.createDescriptorSetLayout({ {}, layoutBindings2.size(), layoutBindings2.data() }));
|
||||
|
||||
Scene::Shader* shader = GetOwner();
|
||||
for(const auto& set : shader->descriptorSets)
|
||||
{
|
||||
vk::DescriptorSetLayoutCreateInfo createInfo { {}, static_cast<uint32_t>(set.size()), reinterpret_cast<const vk::DescriptorSetLayoutBinding*>(set.data()) };
|
||||
@@ -159,4 +150,9 @@ namespace OpenVulkano::Vulkan
|
||||
vk::PipelineLayoutCreateInfo plci = {{}, static_cast<uint32_t>(descriptorSetLayouts.size()), descriptorSetLayouts.data(), static_cast<uint32_t>(shader->pushConstantRanges.size()), pcRanges };
|
||||
pipelineLayout = this->device.createPipelineLayout(plci);
|
||||
}
|
||||
|
||||
void VulkanShader::Release()
|
||||
{
|
||||
if (owner) owner->RemoveShader(this);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user