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
RevLine 
[7d2b0b9]1#ifndef _GRAPHICS_PIPELINE_VULKAN_H
2#define _GRAPHICS_PIPELINE_VULKAN_H
3
4#include "graphics-pipeline.hpp"
5
6#include <vector>
7
[771b33a]8#include <vulkan/vulkan.h>
9
[b794178]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
[7d2b0b9]20class GraphicsPipeline_Vulkan : public GraphicsPipeline {
21 public:
[87c8f1a]22 GraphicsPipeline_Vulkan(VkPhysicalDevice physicalDevice, VkDevice device, VkRenderPass renderPass,
23 Viewport viewport, int vertexSize);
[7d2b0b9]24 ~GraphicsPipeline_Vulkan();
25
[87c8f1a]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
[b794178]35 // Maybe I should rename these to addVertexAttribute (addVaryingAttribute) and addUniformAttribute
36
[771b33a]37 void addAttribute(VkFormat format, size_t offset);
[b794178]38
39 void addDescriptorInfo(VkDescriptorType type, VkShaderStageFlags stageFlags, vector<VkDescriptorBufferInfo>* bufferData);
40 void addDescriptorInfo(VkDescriptorType type, VkShaderStageFlags stageFlags, VkDescriptorImageInfo* imageData);
41
[7d2b0b9]42 void createPipeline(string vertShaderFile, string fragShaderFile);
[b794178]43 void createDescriptorSetLayout();
44 void createDescriptorPool(vector<VkImage>& swapChainImages);
45 void createDescriptorSets(vector<VkImage>& swapChainImages);
46
[603b5bc]47 void createRenderCommands(VkCommandBuffer& commandBuffer, uint32_t currentImage);
48
[b794178]49 void cleanup();
50 void cleanupBuffers();
[7d2b0b9]51
52 private:
[b794178]53 VkShaderModule createShaderModule(const vector<char>& code);
54 vector<char> readFile(const string& filename);
55
[87c8f1a]56 VkPhysicalDevice physicalDevice;
[7d2b0b9]57 VkDevice device;
[b794178]58 VkRenderPass renderPass;
59
60 VkPipeline pipeline;
61 VkPipelineLayout pipelineLayout;
62
[771b33a]63 VkVertexInputBindingDescription bindingDescription;
[b794178]64
[771b33a]65 vector<VkVertexInputAttributeDescription> attributeDescriptions;
[b794178]66 vector<DescriptorInfo> descriptorInfoList;
[7d2b0b9]67
[b794178]68 VkDescriptorSetLayout descriptorSetLayout;
69 VkDescriptorPool descriptorPool;
70 vector<VkDescriptorSet> descriptorSets;
[87c8f1a]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;
[7d2b0b9]81};
82
[87c8f1a]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
[7d2b0b9]97#endif // _GRAPHICS_PIPELINE_VULKAN_H
Note: See TracBrowser for help on using the repository browser.