1 /*
2  * Copyright © 2017 Collabora Ltd.
3  *
4  * This file is part of vkmark.
5  *
6  * vkmark is free software: you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation, either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * vkmark is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with vkmark. If not, see <http://www.gnu.org/licenses/>.
18  *
19  * Authors:
20  *   Alexandros Frantzis <alexandros.frantzis@collabora.com>
21  */
22 
23 #pragma once
24 
25 #include "scene.h"
26 #include "managed_resource.h"
27 #include "vkutil/texture.h"
28 
29 #include <memory>
30 
31 #define GLM_FORCE_DEPTH_ZERO_TO_ONE
32 #include <glm/glm.hpp>
33 #include <vulkan/vulkan.hpp>
34 
35 class Mesh;
36 
37 class Effect2DScene : public Scene
38 {
39 public:
40     Effect2DScene();
41     ~Effect2DScene();
42 
43     void setup(VulkanState&, std::vector<VulkanImage> const&) override;
44     void teardown() override;
45 
46     VulkanImage draw(VulkanImage const&) override;
47     void update() override;
48 
49 private:
50     void setup_vertex_buffer();
51     void setup_uniform_buffer();
52     void setup_texture();
53     void setup_shader_descriptor_set();
54     void setup_render_pass();
55     void setup_pipeline();
56     void setup_framebuffers(std::vector<VulkanImage> const&);
57     void setup_command_buffers();
58     void update_uniforms();
59 
60     VulkanState* vulkan;
61     vk::Extent2D extent;
62     vk::Format format;
63 
64     std::unique_ptr<Mesh> mesh;
65 
66     ManagedResource<vk::Buffer> vertex_buffer;
67     ManagedResource<vk::Buffer> uniform_buffer;
68     ManagedResource<void*> uniform_buffer_map;
69     vkutil::Texture texture;
70     ManagedResource<vk::DescriptorSet> descriptor_set;
71     ManagedResource<vk::RenderPass> render_pass;
72     ManagedResource<vk::PipelineLayout> pipeline_layout;
73     ManagedResource<vk::Pipeline> pipeline;
74     std::vector<ManagedResource<vk::ImageView>> image_views;
75     std::vector<ManagedResource<vk::Framebuffer>> framebuffers;
76     std::vector<vk::CommandBuffer> command_buffers;
77     ManagedResource<vk::Semaphore> submit_semaphore;
78 
79     vk::DeviceMemory uniform_buffer_memory;
80     vk::DescriptorSetLayout descriptor_set_layout;
81 };
82