Renderer: Handle null textures in shader binding
This commit is contained in:
parent
c8f4e53244
commit
96d7b9424b
|
|
@ -65,16 +65,19 @@ namespace Nz
|
|||
|
||||
const TextureBinding& texBinding = std::get<TextureBinding>(binding.content);
|
||||
|
||||
OpenGLTexture& glTexture = static_cast<OpenGLTexture&>(*texBinding.texture);
|
||||
OpenGLTextureSampler& glSampler = static_cast<OpenGLTextureSampler&>(*texBinding.sampler);
|
||||
|
||||
auto& textureDescriptor = m_owner.GetTextureDescriptor(m_poolIndex, m_bindingIndex, resourceIndex);
|
||||
textureDescriptor.bindingIndex = binding.bindingIndex;
|
||||
|
||||
textureDescriptor.texture = glTexture.GetTexture().GetObjectId();
|
||||
textureDescriptor.sampler = glSampler.GetSampler(glTexture.GetLevelCount() > 1).GetObjectId();
|
||||
if (OpenGLTexture* glTexture = static_cast<OpenGLTexture*>(texBinding.texture))
|
||||
{
|
||||
textureDescriptor.texture = glTexture->GetTexture().GetObjectId();
|
||||
|
||||
switch (glTexture.GetType())
|
||||
if (OpenGLTextureSampler* glSampler = static_cast<OpenGLTextureSampler*>(texBinding.sampler))
|
||||
textureDescriptor.sampler = glSampler->GetSampler(glTexture->GetLevelCount() > 1).GetObjectId();
|
||||
else
|
||||
textureDescriptor.sampler = 0;
|
||||
|
||||
switch (glTexture->GetType())
|
||||
{
|
||||
case ImageType_2D:
|
||||
textureDescriptor.textureTarget = GL::TextureTarget::Target2D;
|
||||
|
|
@ -97,6 +100,14 @@ namespace Nz
|
|||
default:
|
||||
throw std::runtime_error("unsupported texture type");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
textureDescriptor.sampler = 0;
|
||||
textureDescriptor.texture = 0;
|
||||
textureDescriptor.textureTarget = GL::TextureTarget::Target2D;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
@ -107,15 +118,21 @@ namespace Nz
|
|||
|
||||
const UniformBufferBinding& uboBinding = std::get<UniformBufferBinding>(binding.content);
|
||||
|
||||
OpenGLBuffer& glBuffer = *static_cast<OpenGLBuffer*>(uboBinding.buffer);
|
||||
if (glBuffer.GetType() != BufferType_Uniform)
|
||||
throw std::runtime_error("expected uniform buffer");
|
||||
|
||||
auto& uboDescriptor = m_owner.GetUniformBufferDescriptor(m_poolIndex, m_bindingIndex, resourceIndex);
|
||||
uboDescriptor.bindingIndex = binding.bindingIndex;
|
||||
uboDescriptor.buffer = glBuffer.GetBuffer().GetObjectId();
|
||||
uboDescriptor.offset = uboBinding.offset;
|
||||
uboDescriptor.size = uboBinding.range;
|
||||
|
||||
if (OpenGLBuffer* glBuffer = static_cast<OpenGLBuffer*>(uboBinding.buffer))
|
||||
{
|
||||
if (glBuffer->GetType() != BufferType_Uniform)
|
||||
throw std::runtime_error("expected uniform buffer");
|
||||
|
||||
uboDescriptor.buffer = glBuffer->GetBuffer().GetObjectId();
|
||||
}
|
||||
else
|
||||
uboDescriptor.buffer = 0;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,31 +32,29 @@ namespace Nz
|
|||
|
||||
if constexpr (std::is_same_v<T, TextureBinding>)
|
||||
{
|
||||
VulkanTexture& vkTexture = *static_cast<VulkanTexture*>(arg.texture);
|
||||
VulkanTextureSampler& vkSampler = *static_cast<VulkanTextureSampler*>(arg.sampler);
|
||||
VulkanTexture* vkTexture = static_cast<VulkanTexture*>(arg.texture);
|
||||
VulkanTextureSampler* vkSampler = static_cast<VulkanTextureSampler*>(arg.sampler);
|
||||
|
||||
VkDescriptorImageInfo& imageInfo = imageBinding.emplace_back();
|
||||
imageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
|
||||
imageInfo.imageView = vkTexture.GetImageView();
|
||||
imageInfo.sampler = vkSampler.GetSampler();
|
||||
imageInfo.imageView = (vkTexture) ? vkTexture->GetImageView() : VK_NULL_HANDLE;
|
||||
imageInfo.sampler = (vkSampler) ? vkSampler->GetSampler() : VK_NULL_HANDLE;
|
||||
|
||||
writeOp.descriptorCount = 1;
|
||||
writeOp.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
|
||||
|
||||
writeOp.pImageInfo = &imageInfo;
|
||||
}
|
||||
else if constexpr (std::is_same_v<T, UniformBufferBinding>)
|
||||
{
|
||||
VulkanBuffer& vkBuffer = *static_cast<VulkanBuffer*>(arg.buffer);
|
||||
VulkanBuffer* vkBuffer = static_cast<VulkanBuffer*>(arg.buffer);
|
||||
|
||||
VkDescriptorBufferInfo& bufferInfo = bufferBinding.emplace_back();
|
||||
bufferInfo.buffer = vkBuffer.GetBuffer();
|
||||
bufferInfo.buffer = (vkBuffer) ? vkBuffer->GetBuffer() : VK_NULL_HANDLE;
|
||||
bufferInfo.offset = arg.offset;
|
||||
bufferInfo.range = arg.range;
|
||||
|
||||
writeOp.descriptorCount = 1;
|
||||
writeOp.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
|
||||
|
||||
writeOp.pBufferInfo = &bufferInfo;
|
||||
}
|
||||
else
|
||||
|
|
|
|||
Loading…
Reference in New Issue