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