Changeset 237cbec in opengl-game for vulkan-game.cpp


Ignore:
Timestamp:
Apr 19, 2020, 2:35:55 AM (5 years ago)
Author:
Dmitry Portnoy <dmitry.portnoy@…>
Branches:
feature/imgui-sdl, master, points-test
Children:
1f81ecc
Parents:
6104594
Message:

Create a pipeline and shaders to render multicolored lasers

File:
1 edited

Legend:

Unmodified
Added
Removed
  • vulkan-game.cpp

    r6104594 r237cbec  
    2727   this->ship_VP_mats = {};
    2828   this->asteroid_VP_mats = {};
     29   this->laser_VP_mats = {};
    2930}
    3031
     
    540541   asteroidPipeline.createDescriptorSets(swapChainImages);
    541542
     543   laserPipeline.addAttribute(VK_FORMAT_R32G32B32_SFLOAT, offset_of(&LaserVertex::pos));
     544   laserPipeline.addAttribute(VK_FORMAT_R32G32B32_SFLOAT, offset_of(&LaserVertex::texCoord));
     545   laserPipeline.addAttribute(VK_FORMAT_R32_UINT, offset_of(&LaserVertex::objIndex));
     546
     547   createBufferSet(sizeof(UBO_VP_mats), VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
     548      uniformBuffers_laserPipeline, uniformBuffersMemory_laserPipeline, uniformBufferInfoList_laserPipeline);
     549
     550   laserPipeline.addDescriptorInfo(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
     551      VK_SHADER_STAGE_VERTEX_BIT, &uniformBufferInfoList_laserPipeline);
     552   laserPipeline.addStorageDescriptor(VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT);
     553   laserPipeline.addDescriptorInfo(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
     554      VK_SHADER_STAGE_FRAGMENT_BIT, &laserTextureImageDescriptor);
     555
     556   laserPipeline.createDescriptorSetLayout();
     557   laserPipeline.createPipeline("shaders/laser-vert.spv", "shaders/laser-frag.spv");
     558   laserPipeline.createDescriptorPool(swapChainImages);
     559   laserPipeline.createDescriptorSets(swapChainImages);
     560
    542561   cout << "Created all the graphics pipelines" << endl;
    543562
     
    564583   asteroidPipeline = GraphicsPipeline_Vulkan<AsteroidVertex, SSBO_Asteroid>(physicalDevice, device, renderPass,
    565584      { 0, 0, (int)swapChainExtent.width, (int)swapChainExtent.height }, swapChainImages, 24, 36, 10);
     585
     586   laserPipeline = GraphicsPipeline_Vulkan<LaserVertex, SSBO_Laser>(physicalDevice, device, renderPass,
     587      { 0, 0, (int)swapChainExtent.width, (int)swapChainExtent.height }, swapChainImages, 8, 18, 2);
    566588}
    567589
     
    591613   asteroid_VP_mats.view = viewMat;
    592614   asteroid_VP_mats.proj = projMat;
     615
     616   laser_VP_mats.view = viewMat;
     617   laser_VP_mats.proj = projMat;
    593618}
    594619
     
    827852   }
    828853
     854   for (size_t i = 0; i < laserObjects.size(); i++) {
     855      if (laserObjects[i].modified) {
     856         updateObject(laserObjects, laserPipeline, i);
     857      }
     858   }
     859
    829860   VulkanUtils::copyDataToMemory(device, uniformBuffersMemory_modelPipeline[currentImage], 0, object_VP_mats);
    830861
     
    832863
    833864   VulkanUtils::copyDataToMemory(device, uniformBuffersMemory_asteroidPipeline[currentImage], 0, asteroid_VP_mats);
     865
     866   VulkanUtils::copyDataToMemory(device, uniformBuffersMemory_laserPipeline[currentImage], 0, laser_VP_mats);
    834867}
    835868
     
    929962   VulkanUtils::destroyVulkanImage(device, sdlOverlayImage);
    930963   VulkanUtils::destroyVulkanImage(device, floorTextureImage);
     964   VulkanUtils::destroyVulkanImage(device, laserTextureImage);
    931965
    932966   vkDestroySampler(device, textureSampler, nullptr);
     
    936970   shipPipeline.cleanupBuffers();
    937971   asteroidPipeline.cleanupBuffers();
     972   laserPipeline.cleanupBuffers();
    938973
    939974   for (size_t i = 0; i < MAX_FRAMES_IN_FLIGHT; i++) {
     
    13251360   floorTextureImageDescriptor.imageView = floorTextureImage.imageView;
    13261361   floorTextureImageDescriptor.sampler = textureSampler;
     1362
     1363   VulkanUtils::createVulkanImageFromFile(device, physicalDevice, commandPool, "textures/laser.png",
     1364      laserTextureImage, graphicsQueue);
     1365
     1366   laserTextureImageDescriptor = {};
     1367   laserTextureImageDescriptor.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
     1368   laserTextureImageDescriptor.imageView = laserTextureImage.imageView;
     1369   laserTextureImageDescriptor.sampler = textureSampler;
    13271370}
    13281371
     
    14191462      shipPipeline.createRenderCommands(commandBuffers[i], i);
    14201463      asteroidPipeline.createRenderCommands(commandBuffers[i], i);
     1464      laserPipeline.createRenderCommands(commandBuffers[i], i);
    14211465
    14221466      // Always render this pipeline last
     
    15231567   asteroidPipeline.createDescriptorSets(swapChainImages);
    15241568
     1569   createBufferSet(sizeof(UBO_VP_mats), VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
     1570      uniformBuffers_laserPipeline, uniformBuffersMemory_laserPipeline, uniformBufferInfoList_laserPipeline);
     1571
     1572   laserPipeline.updateRenderPass(renderPass);
     1573   laserPipeline.createPipeline("shaders/laser-vert.spv", "shaders/laser-frag.spv");
     1574   laserPipeline.createDescriptorPool(swapChainImages);
     1575   laserPipeline.createDescriptorSets(swapChainImages);
     1576
    15251577   createCommandBuffers();
    15261578}
     
    15391591   shipPipeline.cleanup();
    15401592   asteroidPipeline.cleanup();
     1593   laserPipeline.cleanup();
    15411594
    15421595   for (size_t i = 0; i < uniformBuffers_modelPipeline.size(); i++) {
     
    15551608   }
    15561609
     1610   for (size_t i = 0; i < uniformBuffers_laserPipeline.size(); i++) {
     1611      vkDestroyBuffer(device, uniformBuffers_laserPipeline[i], nullptr);
     1612      vkFreeMemory(device, uniformBuffersMemory_laserPipeline[i], nullptr);
     1613   }
     1614
    15571615   vkDestroyRenderPass(device, renderPass, nullptr);
    15581616
Note: See TracChangeset for help on using the changeset viewer.