Files
OpenVulkano/openVulkanoCpp/Vulkan/FrameBuffer.hpp
2023-10-03 19:52:23 +02:00

113 lines
2.0 KiB
C++

/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#pragma once
#include "Base/ICloseable.hpp"
#include "Image.hpp"
#include "Device.hpp"
#include <cstdint>
#include <vulkan/vulkan.hpp>
namespace OpenVulkano::Vulkan
{
class RenderPass;
class FrameBuffer : ICloseable
{
Image depthBuffer;
std::vector<vk::Framebuffer> frameBuffers;
vk::Format depthBufferFormat = vk::Format::eUndefined, colorFormat = vk::Format::eUndefined;
vk::Extent3D size;
std::vector<RenderPass*> renderPasses;
bool useDepthBuffer;
Device* device = nullptr;
protected:
uint32_t currentFrameBufferId = 0;
FrameBuffer() = default;
virtual ~FrameBuffer()
{
if (device) FrameBuffer::Close();
}
void Init(Device* device, vk::Extent3D size, bool useDepthBuffer = true);
void SetCurrentFrameId(uint32_t id)
{
currentFrameBufferId = id;
}
uint32_t GetCurrentFrameId() const
{
return currentFrameBufferId;
}
public:
void RegisterRenderPass(RenderPass* renderPass);
protected:
void Resize(vk::Extent3D size);
void Close() override
{
DestroyFrameBuffer();
if(depthBuffer) depthBuffer.Close();
device = nullptr;
}
protected:
virtual void CreateDepthStencil();
virtual void CreateFrameBuffer();
void DestroyFrameBuffer();
virtual vk::Format FindColorFormat() = 0;
virtual vk::Format FindDepthFormat()
{
return device->GetSupportedDepthFormat();
}
public:
virtual vk::Format GetColorFormat()
{
return colorFormat;
}
virtual vk::Format GetDepthFormat()
{
return depthBufferFormat;
}
virtual std::vector<IImage*> GetImages() = 0;
bool UseDepthBuffer() const
{
return useDepthBuffer;
}
vk::Extent3D GetSize3D() const
{
return size;
}
vk::Extent2D GetSize2D() const
{
return { size.width, size.height };
}
vk::Framebuffer& GetCurrentFrameBuffer()
{
return frameBuffers[currentFrameBufferId];
}
};
}