aboutsummaryrefslogtreecommitdiffstatsci
path: root/src/rendertarget.hpp
blob: ffc17e97926b12d40edd5dfbdcf7cb5d34ee3139 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#pragma once

#include "vke.h"
#include "texture.hpp"

namespace vke {
    enum AttachmentType {ColorAttach, DepthAttach, ResolveAttach};

    struct AttachmentDef {
        VkImageUsageFlags       usage       = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
        VkAttachmentLoadOp      loadOp      = VK_ATTACHMENT_LOAD_OP_CLEAR;
        VkAttachmentStoreOp     storeOp     = VK_ATTACHMENT_STORE_OP_STORE;
        VkImageLayout           inLayout    = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
        VkImageLayout           outLayout   = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
        VkSampleCountFlagBits   samples     = VK_SAMPLE_COUNT_1_BIT;
    };

    struct render_target_t {
        device_t*                   device;

        uint32_t                    width;
        uint32_t                    height;
        VkSampleCountFlagBits       samples;
        std::vector<AttachmentDef>  attachmentDefs;
        std::vector<vke::Texture>   attachments;
        int                         presentableAttachment = -1;

        swap_chain_t*    			swapChain   = nullptr;

        VkRenderPass                renderPass;
        std::vector<VkFramebuffer>  frameBuffers;

        render_target_t(device_t* _device, VkSampleCountFlagBits _samples = VK_SAMPLE_COUNT_1_BIT);
        virtual ~render_target_t();

        /** @brief create default offscreen rendertarget with 1 color and 1 depth attachments */
        void createDefaultOffscreenTarget (uint32_t _width, uint32_t _height, VkFormat _colorFormat, VkFormat _depthFormat);
        /** @brief create default presentable rendertarget bound to a swapchain */
        void createDefaultPresentableTarget (swap_chain_t* _swapChain);

        void cleanupAttachments();
        void createAttachments(VkFormat _colorFormat, VkFormat _depthFormat);
        void createDefaultRenderPass();
        void createFrameBuffers();

        void updateSize();
    };
}