2021-08-16 15:49:54 -07:00
|
|
|
//
|
|
|
|
|
// KRSurface.h
|
2021-08-16 16:35:36 -07:00
|
|
|
// Kraken Engine
|
2021-08-16 15:49:54 -07:00
|
|
|
//
|
2022-04-03 21:56:23 -07:00
|
|
|
// Copyright 2022 Kearwood Gilbert. All rights reserved.
|
2021-08-16 15:49:54 -07:00
|
|
|
//
|
|
|
|
|
// Redistribution and use in source and binary forms, with or without modification, are
|
|
|
|
|
// permitted provided that the following conditions are met:
|
|
|
|
|
//
|
|
|
|
|
// 1. Redistributions of source code must retain the above copyright notice, this list of
|
|
|
|
|
// conditions and the following disclaimer.
|
|
|
|
|
//
|
|
|
|
|
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
|
|
|
|
// of conditions and the following disclaimer in the documentation and/or other materials
|
|
|
|
|
// provided with the distribution.
|
|
|
|
|
//
|
|
|
|
|
// THIS SOFTWARE IS PROVIDED BY KEARWOOD GILBERT ''AS IS'' AND ANY EXPRESS OR IMPLIED
|
|
|
|
|
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
|
|
|
// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KEARWOOD GILBERT OR
|
|
|
|
|
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
|
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
|
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
|
|
|
|
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
|
|
|
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
|
|
|
|
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
//
|
|
|
|
|
// The views and conclusions contained in the software and documentation are those of the
|
|
|
|
|
// authors and should not be interpreted as representing official policies, either expressed
|
|
|
|
|
// or implied, of Kearwood Gilbert.
|
|
|
|
|
//
|
|
|
|
|
|
2022-07-07 23:09:30 -07:00
|
|
|
#pragma once
|
|
|
|
|
|
2021-08-16 15:49:54 -07:00
|
|
|
#include "KREngine-common.h"
|
2021-08-16 19:51:15 -07:00
|
|
|
#include "KRContext.h"
|
2021-08-16 15:49:54 -07:00
|
|
|
|
2022-02-27 22:10:17 -08:00
|
|
|
class KRDevice;
|
2022-03-27 21:34:19 -07:00
|
|
|
class KRRenderPass;
|
2022-04-03 21:49:54 -07:00
|
|
|
class KRSwapchain;
|
2022-02-27 22:10:17 -08:00
|
|
|
|
2021-08-16 19:51:15 -07:00
|
|
|
class KRSurface : public KRContextObject
|
2021-08-16 15:49:54 -07:00
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
#ifdef WIN32
|
2022-09-26 22:06:09 -07:00
|
|
|
KRSurface(KRContext& context, KrSurfaceHandle handle, HWND hWnd);
|
2021-08-16 19:51:15 -07:00
|
|
|
#else
|
2022-09-26 22:06:09 -07:00
|
|
|
KRSurface(KRContext& context, KrSurfaceHandle handle);
|
2021-08-16 15:49:54 -07:00
|
|
|
#endif
|
2021-08-16 19:51:15 -07:00
|
|
|
~KRSurface();
|
|
|
|
|
void destroy();
|
2022-02-27 22:10:17 -08:00
|
|
|
uint32_t getWidth() const;
|
|
|
|
|
uint32_t getHeight() const;
|
2023-08-05 21:14:53 -07:00
|
|
|
hydra::Vector2i getDimensions() const;
|
2022-03-01 23:53:42 -08:00
|
|
|
VkFormat getDepthFormat() const;
|
2021-08-16 19:51:15 -07:00
|
|
|
|
|
|
|
|
KRSurface(const KRSurface&) = delete;
|
|
|
|
|
KRSurface& operator=(const KRSurface&) = delete;
|
2022-02-27 22:10:17 -08:00
|
|
|
std::unique_ptr<KRDevice>& getDevice();
|
2021-08-16 19:51:15 -07:00
|
|
|
|
|
|
|
|
KrResult initialize();
|
2021-08-18 00:41:31 -07:00
|
|
|
KrResult recreateSwapChain();
|
2022-03-27 21:56:45 -07:00
|
|
|
KRRenderPass& getForwardOpaquePass();
|
2021-08-16 19:51:15 -07:00
|
|
|
|
2022-07-04 22:08:05 -07:00
|
|
|
KRRenderPass& getDeferredGBufferPass();
|
|
|
|
|
KRRenderPass& getDeferredOpaquePass();
|
|
|
|
|
|
2022-03-27 22:14:41 -07:00
|
|
|
void endFrame();
|
2022-09-26 22:06:09 -07:00
|
|
|
KrSurfaceHandle m_handle;
|
2022-03-27 22:14:41 -07:00
|
|
|
|
2021-08-16 19:51:15 -07:00
|
|
|
#ifdef WIN32
|
|
|
|
|
HWND m_hWnd;
|
|
|
|
|
#endif
|
|
|
|
|
KrDeviceHandle m_deviceHandle;
|
|
|
|
|
VkSurfaceKHR m_surface;
|
2022-08-08 01:07:26 -07:00
|
|
|
|
2022-09-15 19:20:10 -07:00
|
|
|
VkSemaphore m_imageAvailableSemaphores[KRENGINE_MAX_FRAMES_IN_FLIGHT];
|
|
|
|
|
VkSemaphore m_renderFinishedSemaphores[KRENGINE_MAX_FRAMES_IN_FLIGHT];
|
|
|
|
|
VkFence m_inFlightFences[KRENGINE_MAX_FRAMES_IN_FLIGHT];
|
2021-08-16 19:51:15 -07:00
|
|
|
|
2022-04-03 21:49:54 -07:00
|
|
|
std::unique_ptr<KRSwapchain> m_swapChain;
|
2022-03-27 21:34:19 -07:00
|
|
|
std::unique_ptr<KRRenderPass> m_forwardOpaquePass;
|
2022-07-04 22:08:05 -07:00
|
|
|
std::unique_ptr<KRRenderPass> m_deferredGBufferPass;
|
|
|
|
|
std::unique_ptr<KRRenderPass> m_deferredOpaquePass;
|
2021-08-16 15:49:54 -07:00
|
|
|
|
2022-03-27 22:14:41 -07:00
|
|
|
// TODO - This needs to be advanced per swap chain
|
|
|
|
|
uint64_t m_frameIndex;
|
|
|
|
|
|
2021-08-16 15:49:54 -07:00
|
|
|
private:
|
2021-08-18 00:41:31 -07:00
|
|
|
void destroySwapChain();
|
|
|
|
|
KrResult createSwapChain();
|
2021-08-16 15:49:54 -07:00
|
|
|
};
|