Changeset 6486ba8 in opengl-game for sdl-game.hpp


Ignore:
Timestamp:
Jun 11, 2021, 8:12:29 PM (3 years ago)
Author:
Dmitry Portnoy <dportnoy@…>
Branches:
feature/imgui-sdl
Children:
5ea0a37
Parents:
c1ec4f6
Message:

Rewrite some parts of SDLGame and VulkanGame to store per-object buffer object
data contiguously and copied to the GPU in one call

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sdl-game.hpp

    rc1ec4f6 r6486ba8  
    9393// TODO: Create a typedef for index type so I can easily change uin16_t to something else later
    9494// TODO: Maybe create a typedef for each of the templated SceneObject types
    95 template<class VertexType, class SSBOType>
     95template<class VertexType>
    9696struct SceneObject {
    9797   vector<VertexType> vertices;
    9898   vector<uint16_t> indices;
    99    SSBOType ssbo;
    10099
    101100   mat4 model_base;
     
    109108   // Move the targetAsteroid stuff out of this class since it is very specific to lasers
    110109   // and makes moving SceneObject into its own header file more problematic
    111    SceneObject<ModelVertex, SSBO_Asteroid>* targetAsteroid; // currently only used for lasers
    112 };
    113 
    114 // TODO: Have to figure out how to include an optional ssbo parameter for each object
     110   SceneObject<ModelVertex>* targetAsteroid; // currently only used for lasers
     111};
     112
     113// TODO: Figure out how to include an optional ssbo parameter for each object
    115114// Could probably use the same approach to make indices optional
    116115// Figure out if there are sufficient use cases to make either of these optional or is it fine to make
     
    238237      // if there is a need to add other uniform variables to one or more of the shaders
    239238
    240       vector<SceneObject<ModelVertex, SSBO_ModelObject>> modelObjects;
     239      vector<SceneObject<ModelVertex>> modelObjects;
    241240
    242241      UBO_VP_mats object_VP_mats;
     
    307306      // stop using objects.back() to access the object that was just created
    308307      template<class VertexType, class SSBOType>
    309       SceneObject<VertexType, SSBOType>& addObject(vector<SceneObject<VertexType, SSBOType>>& objects,
    310                                                    GraphicsPipeline_Vulkan<VertexType>& pipeline,
    311                                                    const vector<VertexType>& vertices, vector<uint16_t> indices,
    312                                                    VulkanBuffer<SSBOType>& objectBuffer, SSBOType ssbo);
     308      SceneObject<VertexType>& addObject(vector<SceneObject<VertexType>>& objects,
     309                                         GraphicsPipeline_Vulkan<VertexType>& pipeline,
     310                                         const vector<VertexType>& vertices, vector<uint16_t> indices,
     311                                         VulkanBuffer<SSBOType>& objectBuffer, SSBOType ssbo);
    313312
    314313      template<class VertexType>
     
    318317      vector<VertexType> addVertexNormals(vector<VertexType> vertices);
    319318
    320       template<class VertexType, class SSBOType>
    321       void centerObject(SceneObject<VertexType, SSBOType>& object);
     319      template<class VertexType>
     320      void centerObject(SceneObject<VertexType>& object);
    322321
    323322      void renderFrame(ImDrawData* draw_data);
     
    352351// Figure out a better way to allow the model matrix to be set during object creation
    353352template<class VertexType, class SSBOType>
    354 SceneObject<VertexType, SSBOType>& VulkanGame::addObject(vector<SceneObject<VertexType, SSBOType>>& objects,
    355                                                          GraphicsPipeline_Vulkan<VertexType>& pipeline,
    356                                                          const vector<VertexType>& vertices, vector<uint16_t> indices,
    357                                                          VulkanBuffer<SSBOType>& objectBuffer, SSBOType ssbo) {
     353SceneObject<VertexType>& VulkanGame::addObject(vector<SceneObject<VertexType>>& objects,
     354                                               GraphicsPipeline_Vulkan<VertexType>& pipeline,
     355                                               const vector<VertexType>& vertices, vector<uint16_t> indices,
     356                                               VulkanBuffer<SSBOType>& objectBuffer, SSBOType ssbo) {
    358357   // TODO: Use the model field of ssbo to set the object's model_base
    359358   // currently, the passed-in model is useless since it gets overridden when ssbo.model is recalculated
     
    364363   }
    365364
    366    objects.push_back({ vertices, indices, ssbo, mat4(1.0f), mat4(1.0f) });
     365   objects.push_back({ vertices, indices, mat4(1.0f), mat4(1.0f) });
    367366   objectBuffer.add(ssbo);
    368367
    369    SceneObject<VertexType, SSBOType>& obj = objects.back();
     368   SceneObject<VertexType>& obj = objects.back();
    370369
    371370   // TODO: Specify whether to center the object outside of this function or, worst case, maybe
     
    410409}
    411410
    412 template<class VertexType, class SSBOType>
    413 void VulkanGame::centerObject(SceneObject<VertexType, SSBOType>& object) {
     411template<class VertexType>
     412void VulkanGame::centerObject(SceneObject<VertexType>& object) {
    414413   vector<VertexType>& vertices = object.vertices;
    415414
Note: See TracChangeset for help on using the changeset viewer.