Changeset 87c8f1a in opengl-game for graphics-pipeline_vulkan.hpp


Ignore:
Timestamp:
Nov 1, 2019, 5:11:45 PM (5 years ago)
Author:
Dmitry Portnoy <dmitry.portnoy@…>
Branches:
feature/imgui-sdl, master, points-test
Children:
d2d9286
Parents:
34bdf3a
git-author:
Dmitry Portnoy <dmitry.portnoy@…> (11/01/19 17:09:16)
git-committer:
Dmitry Portnoy <dmitry.portnoy@…> (11/01/19 17:11:45)
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • graphics-pipeline_vulkan.hpp

    r34bdf3a r87c8f1a  
    2020class GraphicsPipeline_Vulkan : public GraphicsPipeline {
    2121   public:
    22       GraphicsPipeline_Vulkan(VkDevice device, VkRenderPass renderPass, Viewport viewport, int vertexSize);
     22      GraphicsPipeline_Vulkan(VkPhysicalDevice physicalDevice, VkDevice device, VkRenderPass renderPass,
     23         Viewport viewport, int vertexSize);
    2324      ~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);
    2434
    2535      // Maybe I should rename these to addVertexAttribute (addVaryingAttribute) and addUniformAttribute
     
    4454      vector<char> readFile(const string& filename);
    4555
     56      VkPhysicalDevice physicalDevice;
    4657      VkDevice device;
    4758      VkRenderPass renderPass;
     
    5869      VkDescriptorPool descriptorPool;
    5970      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;
    6081};
    6182
     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
    6297#endif // _GRAPHICS_PIPELINE_VULKAN_H
Note: See TracChangeset for help on using the changeset viewer.