source: opengl-game/graphics-pipeline_vulkan.hpp@ 87c8f1a

feature/imgui-sdl points-test
Last change on this file since 87c8f1a was 87c8f1a, checked in by Dmitry Portnoy <dmitry.portnoy@…>, 5 years ago

In vaulkangame, define vertex buffer and index buffer data and transfer it to the gpu

  • Property mode set to 100644
File size: 3.5 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 template<class VertexType, class IndexType>
27 void bindData(const vector<VertexType>& vertices, const vector<IndexType>& indices,
28 VkCommandPool commandPool, VkQueue graphicsQueue);
29
30 void createVertexBuffer(const void* bufferData, int vertexSize, VkCommandPool commandPool,
31 VkQueue graphicsQueue);
32 void createIndexBuffer(const void* bufferData, int indexSize, VkCommandPool commandPool,
33 VkQueue graphicsQueue);
34
35 // Maybe I should rename these to addVertexAttribute (addVaryingAttribute) and addUniformAttribute
36
37 void addAttribute(VkFormat format, size_t offset);
38
39 void addDescriptorInfo(VkDescriptorType type, VkShaderStageFlags stageFlags, vector<VkDescriptorBufferInfo>* bufferData);
40 void addDescriptorInfo(VkDescriptorType type, VkShaderStageFlags stageFlags, VkDescriptorImageInfo* imageData);
41
42 void createPipeline(string vertShaderFile, string fragShaderFile);
43 void createDescriptorSetLayout();
44 void createDescriptorPool(vector<VkImage>& swapChainImages);
45 void createDescriptorSets(vector<VkImage>& swapChainImages);
46
47 void createRenderCommands(VkCommandBuffer& commandBuffer, uint32_t currentImage);
48
49 void cleanup();
50 void cleanupBuffers();
51
52 private:
53 VkShaderModule createShaderModule(const vector<char>& code);
54 vector<char> readFile(const string& filename);
55
56 VkPhysicalDevice physicalDevice;
57 VkDevice device;
58 VkRenderPass renderPass;
59
60 VkPipeline pipeline;
61 VkPipelineLayout pipelineLayout;
62
63 VkVertexInputBindingDescription bindingDescription;
64
65 vector<VkVertexInputAttributeDescription> attributeDescriptions;
66 vector<DescriptorInfo> descriptorInfoList;
67
68 VkDescriptorSetLayout descriptorSetLayout;
69 VkDescriptorPool descriptorPool;
70 vector<VkDescriptorSet> descriptorSets;
71
72 size_t numVertices;
73 size_t vertexCapacity;
74 VkBuffer vertexBuffer;
75 VkDeviceMemory vertexBufferMemory;
76
77 size_t numIndices;
78 size_t indexCapacity;
79 VkBuffer indexBuffer;
80 VkDeviceMemory indexBufferMemory;
81};
82
83// TODO: Probably better to template the whole class and to also combine this function
84// and the constructor since I call this right after the constructor anyway
85template<class VertexType, class IndexType>
86void GraphicsPipeline_Vulkan::bindData(const vector<VertexType>& vertices, const vector<IndexType>& indices,
87 VkCommandPool commandPool, VkQueue graphicsQueue) {
88 numVertices = vertices.size();
89 vertexCapacity = numVertices * 2;
90 createVertexBuffer(vertices.data(), sizeof(VertexType), commandPool, graphicsQueue);
91
92 numIndices = indices.size();
93 indexCapacity = numIndices * 2;
94 createIndexBuffer(indices.data(), sizeof(IndexType), commandPool, graphicsQueue);
95}
96
97#endif // _GRAPHICS_PIPELINE_VULKAN_H
Note: See TracBrowser for help on using the repository browser.