Changeset e3bef3a in opengl-game for graphics-pipeline_vulkan.hpp


Ignore:
Timestamp:
Nov 12, 2019, 6:55:07 AM (5 years ago)
Author:
Dmitry Portnoy <dmp1488@…>
Branches:
feature/imgui-sdl, master, points-test
Children:
cd487fb
Parents:
5a23277
Message:

Finish the rewrite of the original vulkangame project

File:
1 edited

Legend:

Unmodified
Added
Removed
  • graphics-pipeline_vulkan.hpp

    r5a23277 re3bef3a  
    44#include "graphics-pipeline.hpp"
    55
     6#include <iostream>
    67#include <vector>
    78
    89#include <vulkan/vulkan.h>
     10
     11#include "vulkan-utils.hpp"
     12
     13using namespace std;
     14
     15// TODO: Remove any instances of cout and instead throw exceptions
    916
    1017// TODO: Maybe change the name of this struct so I can call the list something other than descriptorInfoList
     
    2633      void updateRenderPass(VkRenderPass renderPass);
    2734
    28       template<class VertexType, class IndexType>
    29       void bindData(const vector<VertexType>& vertices, const vector<IndexType>& indices,
     35      template<class VertexType>
     36      void bindData(const vector<VertexType>& vertices, const vector<uint16_t>& indices,
    3037         VkCommandPool commandPool, VkQueue graphicsQueue);
    3138
     
    4855
    4956      void createRenderCommands(VkCommandBuffer& commandBuffer, uint32_t currentImage);
     57
     58      template<class VertexType>
     59      bool addObject(const vector<VertexType>& vertices, vector<uint16_t>& indices, VkCommandPool commandPool,
     60         VkQueue graphicsQueue);
    5061
    5162      void cleanup();
     
    8394};
    8495
    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
    87 template<class VertexType, class IndexType>
    88 void GraphicsPipeline_Vulkan::bindData(const vector<VertexType>& vertices, const vector<IndexType>& indices,
     96// TODO: Probably better to template the whole class
     97// TODO: Change the index type to uint32_t and check the Vulkan Tutorial loading model section as a reference
     98
     99// TODO: combine this function and the constructor since I call this right after the constructor anyway
     100template<class VertexType>
     101void GraphicsPipeline_Vulkan::bindData(const vector<VertexType>& vertices, const vector<uint16_t>& indices,
    89102      VkCommandPool commandPool, VkQueue graphicsQueue) {
    90103   numVertices = vertices.size();
     
    94107   numIndices = indices.size();
    95108   indexCapacity = numIndices * 2;
    96    createIndexBuffer(indices.data(), sizeof(IndexType), commandPool, graphicsQueue);
     109   createIndexBuffer(indices.data(), sizeof(uint16_t), commandPool, graphicsQueue);
     110}
     111
     112template<class VertexType>
     113bool GraphicsPipeline_Vulkan::addObject(const vector<VertexType>& vertices, vector<uint16_t>& indices,
     114      VkCommandPool commandPool, VkQueue graphicsQueue) {
     115   cout << "Adding object to pipeline..." << endl;
     116
     117   if (numVertices + vertices.size() > vertexCapacity) {
     118      cout << "ERROR: Need to resize vertex buffers" << endl;
     119   } else if (numIndices + indices.size() > indexCapacity) {
     120      cout << "ERROR: Need to resize index buffers" << endl;
     121   } else {
     122      cout << "Added object to scene" << endl;
     123
     124      for (uint16_t& idx : indices) {
     125         idx += numVertices;
     126      }
     127
     128      VulkanUtils::copyDataToBuffer(device, physicalDevice, commandPool, vertices, vertexBuffer, numVertices,
     129         graphicsQueue);
     130      numVertices += vertices.size();
     131
     132      VulkanUtils::copyDataToBuffer(device, physicalDevice, commandPool, indices, indexBuffer, numIndices,
     133         graphicsQueue);
     134      numIndices += indices.size();
     135
     136      return true;
     137   }
     138
     139   return false;
    97140}
    98141
Note: See TracChangeset for help on using the changeset viewer.