Skip to content

Commit

Permalink
Replace DepthFormat with SurfaceFormat
Browse files Browse the repository at this point in the history
  • Loading branch information
mogemimi committed Dec 15, 2020
1 parent d4abbce commit 858fa09
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 28 deletions.
2 changes: 1 addition & 1 deletion src/Graphics.Vulkan/GraphicsDeviceVulkan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ GraphicsDeviceVulkan::CreateRenderTarget2D(
std::int32_t height,
std::int32_t mipmapLevels,
SurfaceFormat format,
DepthFormat depthStencilFormat,
SurfaceFormat depthStencilFormat,
std::int32_t multiSampleCount)
{
POMDOG_ASSERT(impl);
Expand Down
2 changes: 1 addition & 1 deletion src/Graphics.Vulkan/GraphicsDeviceVulkan.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class GraphicsDeviceVulkan final : public GraphicsDevice {
std::int32_t height,
bool generateMipmap,
SurfaceFormat format,
DepthFormat depthStencilFormat) noexcept override;
SurfaceFormat depthStencilFormat) noexcept override;

/// Creates a sampler state object.
std::tuple<std::shared_ptr<SamplerState>, std::shared_ptr<Error>>
Expand Down
4 changes: 2 additions & 2 deletions src/Graphics.Vulkan/PipelineStateVulkan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -395,13 +395,13 @@ void CreateRenderPass(
}
const auto colorAttachemntCount = attachmentIndex;

if (description.DepthStencilViewFormat != DepthFormat::None) {
if (description.DepthStencilViewFormat != SurfaceFormat::Invalid) {
POMDOG_ASSERT(attachmentIndex < colorAttachments.size());
POMDOG_ASSERT(attachmentIndex < colorAttachmentRefs.size());

auto& depthAttachment = colorAttachments[attachmentIndex];
depthAttachment.flags = 0;
depthAttachment.format = ToDepthFormat(description.DepthStencilViewFormat);
depthAttachment.format = ToSurfaceFormat(description.DepthStencilViewFormat);
depthAttachment.samples = VK_SAMPLE_COUNT_1_BIT;
depthAttachment.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
depthAttachment.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
Expand Down
4 changes: 2 additions & 2 deletions src/Graphics.Vulkan/RenderTarget2DVulkan.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) 2013-2020 mogemimi. Distributed under the MIT license.

#include "RenderTarget2DVulkan.hpp"
#include "Pomdog/Graphics/DepthFormat.hpp"
#include "Pomdog/Graphics/SurfaceFormat.hpp"
#include "Pomdog/Utility/Assert.hpp"
#include "Pomdog/Utility/Exception.hpp"

Expand All @@ -13,7 +13,7 @@ RenderTarget2DVulkan::RenderTarget2DVulkan(
std::int32_t pixelHeight,
std::int32_t levelCount,
SurfaceFormat format,
DepthFormat depthStencilFormat,
SurfaceFormat depthStencilFormat,
std::int32_t multiSampleCount)
{
POMDOG_ASSERT(device != nullptr);
Expand Down
4 changes: 2 additions & 2 deletions src/Graphics.Vulkan/RenderTarget2DVulkan.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class RenderTarget2DVulkan final : public RenderTarget2D {
std::int32_t pixelHeight,
std::int32_t levelCount,
SurfaceFormat format,
DepthFormat depthStencilFormat,
SurfaceFormat depthStencilFormat,
std::int32_t multiSampleCount);

/// Gets the width of the texture data, in pixels.
Expand All @@ -33,7 +33,7 @@ class RenderTarget2DVulkan final : public RenderTarget2D {
SurfaceFormat GetFormat() const noexcept override;

/// Gets the format of the pixel data in the depth-stencil buffer.
DepthFormat GetDepthStencilFormat() const noexcept override;
SurfaceFormat GetDepthStencilFormat() const noexcept override;

/// Gets the size of the texture resource.
Rectangle GetBounds() const noexcept override;
Expand Down
26 changes: 9 additions & 17 deletions src/Graphics.Vulkan/VulkanFormatHelper.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
// Copyright (c) 2013-2020 mogemimi. Distributed under the MIT license.

#include "VulkanFormatHelper.hpp"
#include "Pomdog/Graphics/DepthFormat.hpp"
#include "Pomdog/Graphics/SurfaceFormat.hpp"
#include "Pomdog/Utility/Assert.hpp"

namespace Pomdog::Detail::Vulkan {

VkFormat ToSurfaceFormat(SurfaceFormat format) noexcept
VkFormat
ToSurfaceFormat(SurfaceFormat format) noexcept
{
switch (format) {
case SurfaceFormat::Invalid:
return VK_FORMAT_UNDEFINED;
case SurfaceFormat::A8_UNorm:
return VK_FORMAT_R8_UNORM;
case SurfaceFormat::B8G8R8A8_UNorm:
Expand Down Expand Up @@ -38,26 +40,16 @@ VkFormat ToSurfaceFormat(SurfaceFormat format) noexcept
return VK_FORMAT_R8G8_UNORM;
case SurfaceFormat::R8_UNorm:
return VK_FORMAT_R8_UNORM;
}
return VK_FORMAT_R8_UNORM;
}

VkFormat ToDepthFormat(DepthFormat depthFormat) noexcept
{
POMDOG_ASSERT(depthFormat != DepthFormat::None);
switch (depthFormat) {
case DepthFormat::Depth16:
case SurfaceFormat::Depth16:
return VK_FORMAT_D16_UNORM;
case DepthFormat::Depth24Stencil8:
case SurfaceFormat::Depth24Stencil8:
return VK_FORMAT_D24_UNORM_S8_UINT;
case DepthFormat::Depth32:
case SurfaceFormat::Depth32:
return VK_FORMAT_D32_SFLOAT;
case DepthFormat::Depth32_Float_Stencil8_Uint:
case SurfaceFormat::Depth32_Float_Stencil8_Uint:
return VK_FORMAT_D32_SFLOAT_S8_UINT;
case DepthFormat::None:
break;
}
return VK_FORMAT_D24_UNORM_S8_UINT;
return VK_FORMAT_UNDEFINED;
}

} // namespace Pomdog::Detail::Vulkan
5 changes: 2 additions & 3 deletions src/Graphics.Vulkan/VulkanFormatHelper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@

namespace Pomdog::Detail::Vulkan {

VkFormat ToSurfaceFormat(SurfaceFormat format) noexcept;

VkFormat ToDepthFormat(DepthFormat depthFormat) noexcept;
[[nodiscard]] VkFormat
ToSurfaceFormat(SurfaceFormat format) noexcept;

} // namespace Pomdog::Detail::Vulkan

0 comments on commit 858fa09

Please sign in to comment.