Changeset 8dcbf62 in opengl-game


Ignore:
Timestamp:
Jun 8, 2021, 11:19:16 PM (3 years ago)
Author:
Dmitry Portnoy <dportnoy@…>
Branches:
feature/imgui-sdl
Children:
6bac215
Parents:
8aa4888
git-author:
Dmitry Portnoy <dportnoy@…> (06/08/21 20:38:16)
git-committer:
Dmitry Portnoy <dportnoy@…> (06/08/21 23:19:16)
Message:

Add some functionality to VulkanBuffer, and modify VulkanGame::addObject() to call VulkanBuffer::add()

Files:
5 edited

Legend:

Unmodified
Added
Removed
  • sdl-game.cpp

    r8aa4888 r8dcbf62  
    136136      {
    137137         0, 1, 2, 3, 4, 5
    138       }, {
     138      }, objects_modelPipeline, {
    139139         mat4(1.0f)
    140140      });
    141 
    142    objects_modelPipeline.numObjects++;
    143141
    144142   texturedSquare->model_base =
     
    157155         })), {
    158156            0, 1, 2, 3, 4, 5
    159       }, {
     157      }, objects_modelPipeline, {
    160158         mat4(1.0f)
    161159      });
    162 
    163    objects_modelPipeline.numObjects++;
    164160
    165161   texturedSquare->model_base =
     
    381377                        {
    382378                           0, 1, 2, 3, 4, 5
    383                         }, {
     379                        }, objects_modelPipeline, {
    384380                           mat4(1.0f)
    385381                        });
    386 
    387                   objects_modelPipeline.numObjects++;
    388382
    389383                  texturedSquare.model_base =
     
    834828void VulkanGame::createImageResources() {
    835829   VulkanUtils::createDepthImage(device, physicalDevice, resourceCommandPool, findDepthFormat(), swapChainExtent,
    836       depthImage, graphicsQueue);
     830                                 depthImage, graphicsQueue);
    837831
    838832   createTextureSampler();
     
    12521246   // and resizing the window is a common reason to recreate the swapchain
    12531247   VulkanUtils::createDepthImage(device, physicalDevice, resourceCommandPool, findDepthFormat(), swapChainExtent,
    1254       depthImage, graphicsQueue);
     1248                                 depthImage, graphicsQueue);
    12551249
    12561250   createRenderPass();
  • sdl-game.hpp

    r8aa4888 r8dcbf62  
    311311                                                   GraphicsPipeline_Vulkan<VertexType>& pipeline,
    312312                                                   const vector<VertexType>& vertices, vector<uint16_t> indices,
    313                                                    SSBOType ssbo);
     313                                                   VulkanBuffer<SSBOType>& objectBuffer, SSBOType ssbo);
    314314
    315315      template<class VertexType>
     
    399399                                                         GraphicsPipeline_Vulkan<VertexType>& pipeline,
    400400                                                         const vector<VertexType>& vertices, vector<uint16_t> indices,
    401                                                          SSBOType ssbo) {
     401                                                         VulkanBuffer<SSBOType>& objectBuffer, SSBOType ssbo) {
    402402   // TODO: Use the model field of ssbo to set the object's model_base
    403403   // currently, the passed in model is useless since it gets overridden in updateObject() anyway
     
    409409
    410410   objects.push_back({ vertices, indices, ssbo, mat4(1.0f), mat4(1.0f), false });
     411   objectBuffer.add(ssbo);
    411412
    412413   SceneObject<VertexType, SSBOType>& obj = objects.back();
     
    415416   // with a boolean being passed in here, so that I don't have to rely on checking the specific object
    416417   // type
     418   // TODO: Actually, I've already defined a no-op centerObject method for explosions
     419   // Maybe I should do the same for lasers and remove this conditional altogether
    417420   if (!is_same_v<VertexType, LaserVertex> && !is_same_v<VertexType, ExplosionVertex>) {
    418421      centerObject(obj);
  • vulkan-buffer.hpp

    r8aa4888 r8dcbf62  
    11#ifndef _VULKAN_BUFFER_H
    22#define _VULKAN_BUFFER_H
    3 
    4 #include <iostream>
    5 #include <vector>
    6 
    7 using namespace std;
    83
    94/*
     
    1611   public:
    1712
    18       size_t alignment;
     13      // TODO: Make these private (maybe make a getter for numObjects)
     14      // Externally, they are only used in resizeBufferSet
    1915      size_t capacity;
    2016      size_t numObjects;
     
    2218      VulkanBuffer();
    2319      VulkanBuffer(size_t capacity, size_t minOffsetAlignment);
    24       VulkanBuffer(vector<T>* vData, size_t capacity);
    2520      ~VulkanBuffer();
    2621
    2722      VulkanBuffer<T>& operator=(const VulkanBuffer<T>& other);
    2823
    29       T* data();
    30       void* mappedData(); // TODO: Maybe rename this to just mapped()
     24      void add(T obj);
    3125
    3226      // TODO: Add a resize function
    3327
    3428   private:
     29
     30      size_t alignment;
    3531
    3632      T* srcData; // TODO: Rename this to something else probably and rename rawData to data
     
    8177
    8278template<class T>
    83 VulkanBuffer<T>::VulkanBuffer(vector<T>* vData, size_t capacity)
    84                               : alignment(sizeof(T))
    85                               , capacity(capacity)
    86                               , numObjects(0)
    87                               , srcData(nullptr)
    88                               , rawData(nullptr)
    89                               , vData(vData) {
    90    // TODO: Allocate initial capacity in vector
    91 }
    92 
    93 template<class T>
    9479VulkanBuffer<T>::~VulkanBuffer() {
    9580   if (srcData != nullptr) {
     
    132117
    133118template<class T>
    134 T* VulkanBuffer<T>::data() {
    135    if (srcData != nullptr) {
    136       return srcData;
    137    } else {
    138       return vData->data();
    139    }
    140 }
    141 
    142 template<class T>
    143 void* VulkanBuffer<T>::mappedData() {
    144    return rawData;
     119void VulkanBuffer<T>::add(T obj) {
     120   numObjects++;
    145121}
    146122
  • vulkan-game.cpp

    r8aa4888 r8dcbf62  
    160160      {
    161161         0, 1, 2, 3, 4, 5
    162       }, {
     162      }, objects_modelPipeline, {
    163163         mat4(1.0f)
    164164      });
    165 
    166    objects_modelPipeline.numObjects++;
    167165
    168166   texturedSquare->model_base =
     
    182180      {
    183181         0, 1, 2, 3, 4, 5
    184       }, {
     182      }, objects_modelPipeline, {
    185183         mat4(1.0f)
    186184      });
    187 
    188    objects_modelPipeline.numObjects++;
    189185
    190186   texturedSquare->model_base =
     
    445441         132, 133, 134,
    446442         135, 136, 137,
    447       }, {
     443      }, objects_shipPipeline, {
    448444         mat4(1.0f)
    449445      });
    450 
    451    objects_shipPipeline.numObjects++;
    452446
    453447   ship.model_base =
     
    781775                        {
    782776                           0, 1, 2, 3, 4, 5
    783                         }, {
     777                        }, objects_modelPipeline, {
    784778                           mat4(1.0f)
    785779                        });
    786 
    787                   objects_modelPipeline.numObjects++;
    788780
    789781                  texturedSquare.model_base =
     
    10631055               24, 25, 26, 27, 28, 29,
    10641056               30, 31, 32, 33, 34, 35,
    1065             }, {
     1057            }, objects_asteroidPipeline, {
    10661058               mat4(1.0f),
    10671059               10.0f,
    10681060               false
    10691061            });
    1070 
    1071       objects_asteroidPipeline.numObjects++;
    10721062
    10731063      // This accounts for the scaling in model_base.
     
    15511541void VulkanGame::createImageResources() {
    15521542   VulkanUtils::createDepthImage(device, physicalDevice, resourceCommandPool, findDepthFormat(), swapChainExtent,
    1553       depthImage, graphicsQueue);
     1543                                 depthImage, graphicsQueue);
    15541544
    15551545   createTextureSampler();
     
    19791969          4, 5, 1, 4, 1, 0,
    19801970          6, 7, 5, 6, 5, 4
    1981       }, {
     1971      }, objects_laserPipeline, {
    19821972         mat4(1.0f),
    19831973         color,
    19841974         false
    19851975      });
    1986 
    1987    objects_laserPipeline.numObjects++;
    19881976
    19891977   float xAxisRotation = asin(ray.y / length);
     
    21872175   iota(indices.begin(), indices.end(), 0);
    21882176
    2189    SceneObject<ExplosionVertex, SSBO_Explosion>& explosion = addObject(
    2190       explosionObjects, explosionPipeline, addObjectIndex(explosionObjects.size(), vertices), indices, {
     2177   SceneObject<ExplosionVertex, SSBO_Explosion>& explosion = addObject(explosionObjects, explosionPipeline,
     2178      addObjectIndex(explosionObjects.size(), vertices), indices, objects_explosionPipeline, {
    21912179         mat4(1.0f),
    21922180         cur_time,
     
    21952183      });
    21962184
    2197    objects_explosionPipeline.numObjects++;
    2198 
    21992185   explosion.model_base = model_mat;
    22002186   explosion.model_transform = mat4(1.0f);
     
    22162202   // and resizing the window is a common reason to recreate the swapchain
    22172203   VulkanUtils::createDepthImage(device, physicalDevice, resourceCommandPool, findDepthFormat(), swapChainExtent,
    2218       depthImage, graphicsQueue);
     2204                                 depthImage, graphicsQueue);
    22192205
    22202206   createRenderPass();
  • vulkan-game.hpp

    r8aa4888 r8dcbf62  
    446446                                                   GraphicsPipeline_Vulkan<VertexType>& pipeline,
    447447                                                   const vector<VertexType>& vertices, vector<uint16_t> indices,
    448                                                    SSBOType ssbo);
     448                                                   VulkanBuffer<SSBOType>& objectBuffer, SSBOType ssbo);
    449449
    450450      template<class VertexType>
     
    554554                                                         GraphicsPipeline_Vulkan<VertexType>& pipeline,
    555555                                                         const vector<VertexType>& vertices, vector<uint16_t> indices,
    556                                                          SSBOType ssbo) {
     556                                                         VulkanBuffer<SSBOType>& objectBuffer, SSBOType ssbo) {
    557557   // TODO: Use the model field of ssbo to set the object's model_base
    558558   // currently, the passed in model is useless since it gets overridden in updateObject() anyway
     
    564564
    565565   objects.push_back({ vertices, indices, ssbo, mat4(1.0f), mat4(1.0f), false });
     566   objectBuffer.add(ssbo);
    566567
    567568   SceneObject<VertexType, SSBOType>& obj = objects.back();
     
    570571   // with a boolean being passed in here, so that I don't have to rely on checking the specific object
    571572   // type
     573   // TODO: Actually, I've already defined a no-op centerObject method for explosions
     574   // Maybe I should do the same for lasers and remove this conditional altogether
    572575   if (!is_same_v<VertexType, LaserVertex> && !is_same_v<VertexType, ExplosionVertex>) {
    573576      centerObject(obj);
Note: See TracChangeset for help on using the changeset viewer.