Skip to content

Commit

Permalink
Add nullptr constructor overload for ref_ptr
Browse files Browse the repository at this point in the history
This time, use decltype(nullptr) instead of std::nullptr_t as the latter
requires <cstddef>. The standard guarantees that these are the same
type.
  • Loading branch information
AnyOldName3 committed Mar 2, 2024
1 parent 6d6d2de commit 3e7ef80
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
4 changes: 4 additions & 0 deletions include/vsg/core/ref_ptr.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ namespace vsg
if (_ptr) _ptr->ref();
}

// std::nullptr_t requires extra header
ref_ptr(decltype(nullptr)) noexcept :
ref_ptr() {}

~ref_ptr()
{
if (_ptr) _ptr->unref();
Expand Down
4 changes: 2 additions & 2 deletions src/vsg/state/DescriptorImage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ uint32_t DescriptorImage::getNumDescriptors() const

VSG_DECLSPEC ref_ptr<DescriptorImage> vsg::createSamplerDescriptor(ref_ptr<Sampler> sampler, uint32_t dstBinding, uint32_t dstArrayElement)
{
ref_ptr<ImageInfo> imageImageInfo = ImageInfo::create(sampler, ref_ptr<ImageView>(), VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
ref_ptr<ImageInfo> imageImageInfo = ImageInfo::create(sampler, nullptr, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
return DescriptorImage::create(imageImageInfo, dstBinding, dstArrayElement, VK_DESCRIPTOR_TYPE_SAMPLER);
}

Expand All @@ -176,6 +176,6 @@ VSG_DECLSPEC ref_ptr<DescriptorImage> vsg::createCombinedImageSamplerDescriptor(

VSG_DECLSPEC ref_ptr<DescriptorImage> vsg::createSampedImageDescriptor(ref_ptr<Data> image, uint32_t dstBinding, uint32_t dstArrayElement)
{
ref_ptr<ImageInfo> imageImageInfo = ImageInfo::create(ref_ptr<Sampler>(), image, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
ref_ptr<ImageInfo> imageImageInfo = ImageInfo::create(nullptr, image, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
return DescriptorImage::create(imageImageInfo, dstBinding, dstArrayElement, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE);
}
4 changes: 2 additions & 2 deletions src/vsg/state/ViewDependentState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ void ViewDependentState::init(ResourceRequirements& requirements)
depthImageView->subresourceRange.baseArrayLayer = 0;
depthImageView->subresourceRange.layerCount = maxShadowMaps;

auto depthImageInfo = ImageInfo::create(vsg::ref_ptr<Sampler>(), depthImageView, VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL);
auto depthImageInfo = ImageInfo::create(nullptr, depthImageView, VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL);

shadowMapImages = DescriptorImage::create(ImageInfoList{depthImageInfo}, 2, 0, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE);
}
Expand All @@ -323,7 +323,7 @@ void ViewDependentState::init(ResourceRequirements& requirements)
depthImageView->subresourceRange.baseArrayLayer = 0;
depthImageView->subresourceRange.layerCount = 1;

auto depthImageInfo = ImageInfo::create(vsg::ref_ptr<Sampler>(), depthImageView, VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL);
auto depthImageInfo = ImageInfo::create(nullptr, depthImageView, VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL);

shadowMapImages = DescriptorImage::create(ImageInfoList{depthImageInfo}, 2, 0 , VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE);
}
Expand Down

0 comments on commit 3e7ef80

Please sign in to comment.