Changeset 2d87297 in opengl-game for graphics-pipeline_vulkan.hpp


Ignore:
Timestamp:
Feb 16, 2020, 8:22:40 PM (5 years ago)
Author:
Dmitry Portnoy <dmitry.portnoy@…>
Branches:
feature/imgui-sdl, master, points-test
Children:
d25381b
Parents:
5a1ace0
Message:

In VulkanGame, add an ssbo field to SceneObject to hold per-object ssbo info, and add a new SSBOType template parameter to SceneObject and GraphicsPipeline_Vulkan

File:
1 edited

Legend:

Unmodified
Added
Removed
  • graphics-pipeline_vulkan.hpp

    r5a1ace0 r2d87297  
    3131};
    3232
    33 template<class VertexType>
     33template<class VertexType, class SSBOType>
    3434class GraphicsPipeline_Vulkan : public GraphicsPipeline {
    3535   public:
     
    9999/*** PUBLIC METHODS ***/
    100100
    101 template<class VertexType>
    102 GraphicsPipeline_Vulkan<VertexType>::GraphicsPipeline_Vulkan() {
     101template<class VertexType, class SSBOType>
     102GraphicsPipeline_Vulkan<VertexType, SSBOType>::GraphicsPipeline_Vulkan() {
    103103}
    104104
    105105// TODO: Verify that vertex capacity and index capacity are both > 0
    106 template<class VertexType>
    107 GraphicsPipeline_Vulkan<VertexType>::GraphicsPipeline_Vulkan(VkPhysicalDevice physicalDevice, VkDevice device,
     106template<class VertexType, class SSBOType>
     107GraphicsPipeline_Vulkan<VertexType, SSBOType>::GraphicsPipeline_Vulkan(
     108      VkPhysicalDevice physicalDevice, VkDevice device,
    108109      VkRenderPass renderPass, Viewport viewport, size_t vertexCapacity, size_t indexCapacity) {
    109110   this->physicalDevice = physicalDevice;
     
    134135}
    135136
    136 template<class VertexType>
    137 GraphicsPipeline_Vulkan<VertexType>::~GraphicsPipeline_Vulkan() {
    138 }
    139 
    140 template<class VertexType>
    141 size_t GraphicsPipeline_Vulkan<VertexType>::getNumVertices() {
     137template<class VertexType, class SSBOType>
     138GraphicsPipeline_Vulkan<VertexType, SSBOType>::~GraphicsPipeline_Vulkan() {
     139}
     140
     141template<class VertexType, class SSBOType>
     142size_t GraphicsPipeline_Vulkan<VertexType, SSBOType>::getNumVertices() {
    142143   return numVertices;
    143144}
    144145
    145 template<class VertexType>
    146 void GraphicsPipeline_Vulkan<VertexType>::updateRenderPass(VkRenderPass renderPass) {
     146template<class VertexType, class SSBOType>
     147void GraphicsPipeline_Vulkan<VertexType, SSBOType>::updateRenderPass(VkRenderPass renderPass) {
    147148   this->renderPass = renderPass;
    148149}
    149150
    150 template<class VertexType>
    151 void GraphicsPipeline_Vulkan<VertexType>::addAttribute(VkFormat format, size_t offset) {
     151template<class VertexType, class SSBOType>
     152void GraphicsPipeline_Vulkan<VertexType, SSBOType>::addAttribute(VkFormat format, size_t offset) {
    152153   VkVertexInputAttributeDescription attributeDesc = {};
    153154
     
    160161}
    161162
    162 template<class VertexType>
    163 void GraphicsPipeline_Vulkan<VertexType>::addDescriptorInfo(VkDescriptorType type, VkShaderStageFlags stageFlags, vector<VkDescriptorBufferInfo>* bufferData) {
     163template<class VertexType, class SSBOType>
     164void GraphicsPipeline_Vulkan<VertexType, SSBOType>::addDescriptorInfo(VkDescriptorType type, VkShaderStageFlags stageFlags, vector<VkDescriptorBufferInfo>* bufferData) {
    164165   this->descriptorInfoList.push_back({ type, stageFlags, bufferData, nullptr });
    165166}
    166167
    167 template<class VertexType>
    168 void GraphicsPipeline_Vulkan<VertexType>::addDescriptorInfo(VkDescriptorType type, VkShaderStageFlags stageFlags, VkDescriptorImageInfo* imageData) {
     168template<class VertexType, class SSBOType>
     169void GraphicsPipeline_Vulkan<VertexType, SSBOType>::addDescriptorInfo(VkDescriptorType type, VkShaderStageFlags stageFlags, VkDescriptorImageInfo* imageData) {
    169170   this->descriptorInfoList.push_back({ type, stageFlags, nullptr, imageData });
    170171}
    171172
    172 template<class VertexType>
    173 void GraphicsPipeline_Vulkan<VertexType>::createPipeline(string vertShaderFile, string fragShaderFile) {
     173template<class VertexType, class SSBOType>
     174void GraphicsPipeline_Vulkan<VertexType, SSBOType>::createPipeline(string vertShaderFile, string fragShaderFile) {
    174175   vector<char> vertShaderCode = readFile(vertShaderFile);
    175176   vector<char> fragShaderCode = readFile(fragShaderFile);
     
    308309}
    309310
    310 template<class VertexType>
    311 void GraphicsPipeline_Vulkan<VertexType>::createDescriptorSetLayout() {
     311template<class VertexType, class SSBOType>
     312void GraphicsPipeline_Vulkan<VertexType, SSBOType>::createDescriptorSetLayout() {
    312313   vector<VkDescriptorSetLayoutBinding> bindings(this->descriptorInfoList.size());
    313314
     
    330331}
    331332
    332 template<class VertexType>
    333 void GraphicsPipeline_Vulkan<VertexType>::createDescriptorPool(vector<VkImage>& swapChainImages) {
     333template<class VertexType, class SSBOType>
     334void GraphicsPipeline_Vulkan<VertexType, SSBOType>::createDescriptorPool(vector<VkImage>& swapChainImages) {
    334335   vector<VkDescriptorPoolSize> poolSizes(this->descriptorInfoList.size());
    335336
     
    350351}
    351352
    352 template<class VertexType>
    353 void GraphicsPipeline_Vulkan<VertexType>::createDescriptorSets(vector<VkImage>& swapChainImages) {
     353template<class VertexType, class SSBOType>
     354void GraphicsPipeline_Vulkan<VertexType, SSBOType>::createDescriptorSets(vector<VkImage>& swapChainImages) {
    354355   vector<VkDescriptorSetLayout> layouts(swapChainImages.size(), this->descriptorSetLayout);
    355356
     
    396397}
    397398
    398 template<class VertexType>
    399 void GraphicsPipeline_Vulkan<VertexType>::createRenderCommands(VkCommandBuffer& commandBuffer, uint32_t currentImage) {
     399template<class VertexType, class SSBOType>
     400void GraphicsPipeline_Vulkan<VertexType, SSBOType>::createRenderCommands(VkCommandBuffer& commandBuffer, uint32_t currentImage) {
    400401   vkCmdBindPipeline(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
    401402   vkCmdBindDescriptorSets(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout, 0, 1,
     
    411412}
    412413
    413 template<class VertexType>
    414 void GraphicsPipeline_Vulkan<VertexType>::addVertices(const vector<VertexType>& vertices, vector<uint16_t> indices,
     414template<class VertexType, class SSBOType>
     415void GraphicsPipeline_Vulkan<VertexType, SSBOType>::addVertices(const vector<VertexType>& vertices, vector<uint16_t> indices,
    415416      VkCommandPool commandPool, VkQueue graphicsQueue) {
    416417
     
    431432}
    432433
    433 template<class VertexType>
    434 void GraphicsPipeline_Vulkan<VertexType>::cleanup() {
     434template<class VertexType, class SSBOType>
     435void GraphicsPipeline_Vulkan<VertexType, SSBOType>::cleanup() {
    435436   vkDestroyPipeline(device, pipeline, nullptr);
    436437   vkDestroyDescriptorPool(device, descriptorPool, nullptr);
     
    438439}
    439440
    440 template<class VertexType>
    441 void GraphicsPipeline_Vulkan<VertexType>::cleanupBuffers() {
     441template<class VertexType, class SSBOType>
     442void GraphicsPipeline_Vulkan<VertexType, SSBOType>::cleanupBuffers() {
    442443   vkDestroyDescriptorSetLayout(device, descriptorSetLayout, nullptr);
    443444
     
    450451/*** PRIVATE METHODS ***/
    451452
    452 template<class VertexType>
    453 VkShaderModule GraphicsPipeline_Vulkan<VertexType>::createShaderModule(const vector<char>& code) {
     453template<class VertexType, class SSBOType>
     454VkShaderModule GraphicsPipeline_Vulkan<VertexType, SSBOType>::createShaderModule(const vector<char>& code) {
    454455   VkShaderModuleCreateInfo createInfo = {};
    455456   createInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
     
    465466}
    466467
    467 template<class VertexType>
    468 vector<char> GraphicsPipeline_Vulkan<VertexType>::readFile(const string& filename) {
     468template<class VertexType, class SSBOType>
     469vector<char> GraphicsPipeline_Vulkan<VertexType, SSBOType>::readFile(const string& filename) {
    469470   ifstream file(filename, ios::ate | ios::binary);
    470471
     
    484485}
    485486
    486 template<class VertexType>
    487 void GraphicsPipeline_Vulkan<VertexType>::resizeVertexBuffer(VkCommandPool commandPool, VkQueue graphicsQueue) {
     487template<class VertexType, class SSBOType>
     488void GraphicsPipeline_Vulkan<VertexType, SSBOType>::resizeVertexBuffer(VkCommandPool commandPool, VkQueue graphicsQueue) {
    488489   VkBuffer newVertexBuffer;
    489490   VkDeviceMemory newVertexBufferMemory;
     
    503504}
    504505
    505 template<class VertexType>
    506 void GraphicsPipeline_Vulkan<VertexType>::resizeIndexBuffer(VkCommandPool commandPool, VkQueue graphicsQueue) {
     506template<class VertexType, class SSBOType>
     507void GraphicsPipeline_Vulkan<VertexType, SSBOType>::resizeIndexBuffer(VkCommandPool commandPool, VkQueue graphicsQueue) {
    507508   VkBuffer newIndexBuffer;
    508509   VkDeviceMemory newIndexBufferMemory;
Note: See TracChangeset for help on using the changeset viewer.