Newer
Older
ForwardPlusRenderer / include / Buffer / DepthBuffer.h
#pragma once
#include <stdafx.h>
#include "Buffer/Buffer.h"
#include "Texture.h"
namespace fpr
{
class Device;
class SwapChain;

class DepthBuffer
{
  
  vk::UniqueImage        m_depth_image;
  vk::UniqueDeviceMemory m_depth_buffer_memory;
  vk::UniqueImageView    m_depth_image_view;
  vk::Format             m_depth_image_format;

  static vk::ImageTiling PREFERRED_IMAGE_TILING;

  static constexpr vk::FormatFeatureFlagBits REQUIRED_FEATURE_FLAGS =
      vk::FormatFeatureFlagBits::eDepthStencilAttachment;

  vk::Format QueryBestFormat(fpr::Device* device);


public:
  DepthBuffer(fpr::Device* device, fpr::SwapChain* swapchain, vk::ImageTiling tiling = vk::ImageTiling::eOptimal);

  [[nodiscard]] const vk::Image&        GetDepthImage() const FPR_NOEXCEPT;
  [[nodiscard]] const vk::DeviceMemory& GetDepthBufferMemory() const FPR_NOEXCEPT;
  [[nodiscard]] const vk::ImageView&    GetDepthBufferView() const FPR_NOEXCEPT;
  [[nodiscard]] const vk::Format&       GetDepthImageFormat() const FPR_NOEXCEPT;


  static vk::Format QueryBestImageFormat(
      const std::vector<vk::Format> possible_formats,
      vk::ImageTiling               tiling,
      vk::FormatFeatureFlags        required_flags);

  static constexpr std::array<vk::Format, 2> DEPTH_BUFFER_IMAGE_FORMATS = {
    vk::Format::eD32SfloatS8Uint,
    vk::Format::eD24UnormS8Uint,
  };

  DepthBuffer(const DepthBuffer& other)  = delete;
  DepthBuffer(const DepthBuffer&& other) = delete;
  DepthBuffer operator=(const DepthBuffer& other) = delete;
  DepthBuffer operator=(const DepthBuffer&& other) = delete;
};
} // namespace fpr