source: opengl-game/graphics-pipeline_vulkan.hpp@ 0ae182f

feature/imgui-sdl points-test
Last change on this file since 0ae182f was 0ae182f, checked in by Dmitry Portnoy <dmp1488@…>, 5 years ago

In vulkangame, finish implementing recreateSwapChain()

  • Property mode set to 100644
File size: 3.6 KB
Line 
1#ifndef _GRAPHICS_PIPELINE_VULKAN_H
2#define _GRAPHICS_PIPELINE_VULKAN_H
3
4#include "graphics-pipeline.hpp"
5
6#include <vector>
7
8#include <vulkan/vulkan.h>
9
10// TODO: Maybe change the name of this struct so I can call the list something other than descriptorInfoList
11struct DescriptorInfo {
12 VkDescriptorType type;
13 VkShaderStageFlags stageFlags;
14
15 // Only one of the below properties should be set
16 vector<VkDescriptorBufferInfo>* bufferDataList;
17 VkDescriptorImageInfo* imageData;
18};
19
20class GraphicsPipeline_Vulkan : public GraphicsPipeline {
21 public:
22 GraphicsPipeline_Vulkan(VkPhysicalDevice physicalDevice, VkDevice device, VkRenderPass renderPass,
23 Viewport viewport, int vertexSize);
24 ~GraphicsPipeline_Vulkan();
25
26 void updateRenderPass(VkRenderPass renderPass);
27
28 template<class VertexType, class IndexType>
29 void bindData(const vector<VertexType>& vertices, const vector<IndexType>& indices,
30 VkCommandPool commandPool, VkQueue graphicsQueue);
31
32 void createVertexBuffer(const void* bufferData, int vertexSize, VkCommandPool commandPool,
33 VkQueue graphicsQueue);
34 void createIndexBuffer(const void* bufferData, int indexSize, VkCommandPool commandPool,
35 VkQueue graphicsQueue);
36
37 // Maybe I should rename these to addVertexAttribute (addVaryingAttribute) and addUniformAttribute
38
39 void addAttribute(VkFormat format, size_t offset);
40
41 void addDescriptorInfo(VkDescriptorType type, VkShaderStageFlags stageFlags, vector<VkDescriptorBufferInfo>* bufferData);
42 void addDescriptorInfo(VkDescriptorType type, VkShaderStageFlags stageFlags, VkDescriptorImageInfo* imageData);
43
44 void createPipeline(string vertShaderFile, string fragShaderFile);
45 void createDescriptorSetLayout();
46 void createDescriptorPool(vector<VkImage>& swapChainImages);
47 void createDescriptorSets(vector<VkImage>& swapChainImages);
48
49 void createRenderCommands(VkCommandBuffer& commandBuffer, uint32_t currentImage);
50
51 void cleanup();
52 void cleanupBuffers();
53
54 private:
55 VkShaderModule createShaderModule(const vector<char>& code);
56 vector<char> readFile(const string& filename);
57
58 VkPhysicalDevice physicalDevice;
59 VkDevice device;
60 VkRenderPass renderPass;
61
62 VkPipeline pipeline;
63 VkPipelineLayout pipelineLayout;
64
65 VkVertexInputBindingDescription bindingDescription;
66
67 vector<VkVertexInputAttributeDescription> attributeDescriptions;
68 vector<DescriptorInfo> descriptorInfoList;
69
70 VkDescriptorSetLayout descriptorSetLayout;
71 VkDescriptorPool descriptorPool;
72 vector<VkDescriptorSet> descriptorSets;
73
74 size_t numVertices;
75 size_t vertexCapacity;
76 VkBuffer vertexBuffer;
77 VkDeviceMemory vertexBufferMemory;
78
79 size_t numIndices;
80 size_t indexCapacity;
81 VkBuffer indexBuffer;
82 VkDeviceMemory indexBufferMemory;
83};
84
85// TODO: Probably better to template the whole class and to also combine this function
86// and the constructor since I call this right after the constructor anyway
87template<class VertexType, class IndexType>
88void GraphicsPipeline_Vulkan::bindData(const vector<VertexType>& vertices, const vector<IndexType>& indices,
89 VkCommandPool commandPool, VkQueue graphicsQueue) {
90 numVertices = vertices.size();
91 vertexCapacity = numVertices * 2;
92 createVertexBuffer(vertices.data(), sizeof(VertexType), commandPool, graphicsQueue);
93
94 numIndices = indices.size();
95 indexCapacity = numIndices * 2;
96 createIndexBuffer(indices.data(), sizeof(IndexType), commandPool, graphicsQueue);
97}
98
99#endif // _GRAPHICS_PIPELINE_VULKAN_H
Note: See TracBrowser for help on using the repository browser.