Changeset cefdf23 in opengl-game for vulkan-game.hpp


Ignore:
Timestamp:
Apr 5, 2021, 1:09:02 AM (3 years ago)
Author:
Dmitry Portnoy <dportnoy@…>
Branches:
feature/imgui-sdl
Children:
e469aed
Parents:
aa7e5f0
git-author:
Dmitry Portnoy <dportnoy@…> (04/05/21 01:07:42)
git-committer:
Dmitry Portnoy <dportnoy@…> (04/05/21 01:09:02)
Message:

Rename createImguiDescriptorPool and createImguiDescriptorPool to
initImGuiOverlay and cleanupImGuiOverlay respectively and move all
ImGui-related init and cleanup code into them

File:
1 edited

Legend:

Unmodified
Added
Removed
  • vulkan-game.hpp

    raa7e5f0 rcefdf23  
    3434   const bool ENABLE_VALIDATION_LAYERS = true;
    3535#endif
     36
     37// TODO: Consider if there is a better way of dealing with all the vertex types and ssbo types, maybe
     38// by consolidating some and trying to keep new ones to a minimum
    3639
    3740struct OverlayVertex {
     
    193196};
    194197
     198// TODO: Maybe move this to a different header
     199
    195200enum UIValueType {
    196201   UIVALUE_INT,
     
    208213class VulkanGame {
    209214   public:
     215
    210216      VulkanGame();
    211217      ~VulkanGame();
     
    213219      void run(int width, int height, unsigned char guiFlags);
    214220
    215       GraphicsPipeline_Vulkan<ModelVertex, SSBO_ModelObject> modelPipeline;
    216       GraphicsPipeline_Vulkan<ShipVertex, SSBO_ModelObject> shipPipeline;
    217       GraphicsPipeline_Vulkan<AsteroidVertex, SSBO_Asteroid> asteroidPipeline;
    218       GraphicsPipeline_Vulkan<LaserVertex, SSBO_Laser> laserPipeline;
    219       GraphicsPipeline_Vulkan<ExplosionVertex, SSBO_Explosion> explosionPipeline;
    220 
    221221   private:
     222
    222223      static VKAPI_ATTR VkBool32 VKAPI_CALL debugCallback(
    223224         VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity,
     
    226227         void* pUserData);
    227228
     229      // TODO: Maybe pass these in as parameters to some Camera class
    228230      const float NEAR_CLIP = 0.1f;
    229231      const float FAR_CLIP = 100.0f;
    230       const float FOV_ANGLE = 67.0f; // means the camera lens goes from -33 deg to 33 def
     232      const float FOV_ANGLE = 67.0f; // means the camera lens goes from -33 deg to 33 deg
    231233
    232234      const int EXPLOSION_PARTICLE_COUNT = 300;
     
    286288      bool shouldRecreateSwapChain;
    287289
    288       VkDescriptorPool imguiDescriptorPool;
    289 
    290290      VkSampler textureSampler;
    291291
     
    297297
    298298      mat4 viewMat, projMat;
     299
     300      // Maybe at some point create an imgui pipeline class, but I don't think it makes sense right now
     301      VkDescriptorPool imguiDescriptorPool;
     302
     303      // TODO: Probably restructure the GraphicsPipeline_Vulkan class based on what I learned about descriptors and textures
     304      // while working on graphics-library. Double-check exactly what this was and note it down here.
     305      // Basically, I think the point was that if I have several modesl that all use the same shaders and, therefore,
     306      // the same pipeline, but use different textures, the approach I took when initially creating GraphicsPipeline_Vulkan
     307      // wouldn't work since the whole pipeline couldn't have a common set of descriptors for the textures
     308      GraphicsPipeline_Vulkan<ModelVertex, SSBO_ModelObject> modelPipeline;
     309      GraphicsPipeline_Vulkan<ShipVertex, SSBO_ModelObject> shipPipeline;
     310      GraphicsPipeline_Vulkan<AsteroidVertex, SSBO_Asteroid> asteroidPipeline;
     311      GraphicsPipeline_Vulkan<LaserVertex, SSBO_Laser> laserPipeline;
     312      GraphicsPipeline_Vulkan<ExplosionVertex, SSBO_Explosion> explosionPipeline;
    299313
    300314      // TODO: Maybe make the ubo objects part of the pipeline class since there's only one ubo
     
    371385
    372386      // TODO: Make a separate TImer class
    373       // It could also deal with the steady_clock vs high_resolution_clock issue
    374387      time_point<steady_clock> startTime;
    375388      float fpsStartTime, curTime, prevTime, elapsedTime;
     
    398411      void createSwapChain();
    399412      void createImageViews();
     413      void createResourceCommandPool();
     414      void createImageResources();
     415      VkFormat findDepthFormat(); // TODO: Declare/define (in the cpp file) this function in some util functions section
    400416      void createRenderPass();
    401       VkFormat findDepthFormat(); // TODO: Declare/define (in the cpp file) this function in some util functions section
    402       void createResourceCommandPool();
    403417      void createCommandPools();
    404       void createImageResources();
    405418      void createFramebuffers();
    406419      void createCommandBuffers();
     
    409422      void createTextureSampler();
    410423
    411       void createImguiDescriptorPool();
    412       void destroyImguiDescriptorPool();
     424      void initImGuiOverlay();
     425      void cleanupImGuiOverlay();
     426
     427      void createBufferSet(VkDeviceSize bufferSize, VkBufferUsageFlags flags,
     428         vector<VkBuffer>& buffers, vector<VkDeviceMemory>& buffersMemory,
     429         vector<VkDescriptorBufferInfo>& bufferInfoList);
    413430
    414431      // TODO: Since addObject() returns a reference to the new object now,
     
    421438            bool pipelinesCreated);
    422439
     440      template<class VertexType>
     441      vector<VertexType> addObjectIndex(unsigned int objIndex, vector<VertexType> vertices);
     442
     443      template<class VertexType>
     444      vector<VertexType> addVertexNormals(vector<VertexType> vertices);
     445
     446      template<class VertexType, class SSBOType>
     447      void centerObject(SceneObject<VertexType, SSBOType>& object);
     448
    423449      template<class VertexType, class SSBOType>
    424450      void updateObject(vector<SceneObject<VertexType, SSBOType>>& objects,
     
    428454      void updateObjectVertices(GraphicsPipeline_Vulkan<VertexType, SSBOType>& pipeline,
    429455            SceneObject<VertexType, SSBOType>& obj, size_t index);
    430 
    431       template<class VertexType>
    432       vector<VertexType> addVertexNormals(vector<VertexType> vertices);
    433 
    434       template<class VertexType>
    435       vector<VertexType> addObjectIndex(unsigned int objIndex, vector<VertexType> vertices);
    436 
    437       template<class VertexType, class SSBOType>
    438       void centerObject(SceneObject<VertexType, SSBOType>& object);
    439456
    440457      void addLaser(vec3 start, vec3 end, vec3 color, float width);
     
    445462
    446463      void addExplosion(mat4 model_mat, float duration, float cur_time);
    447 
    448       void createBufferSet(VkDeviceSize bufferSize, VkBufferUsageFlags flags,
    449             vector<VkBuffer>& buffers, vector<VkDeviceMemory>& buffersMemory,
    450             vector<VkDescriptorBufferInfo>& bufferInfoList);
    451464
    452465      void renderFrame(ImDrawData* draw_data);
     
    503516   SceneObject<VertexType, SSBOType>& obj = objects.back();
    504517
     518   // TODO: Specify whether to center the object outside of this function or, worst case, maybe
     519   // with a boolean being passed in here, so that I don't have to rely on checking the specific object
     520   // type
    505521   if (!is_same_v<VertexType, LaserVertex> && !is_same_v<VertexType, ExplosionVertex>) {
    506522      centerObject(obj);
     
    533549}
    534550
    535 // TODO: Just pass in the single object instead of a list of all of them
    536 template<class VertexType, class SSBOType>
    537 void VulkanGame::updateObject(vector<SceneObject<VertexType, SSBOType>>& objects,
    538       GraphicsPipeline_Vulkan<VertexType, SSBOType>& pipeline, size_t index) {
    539    SceneObject<VertexType, SSBOType>& obj = objects[index];
    540 
    541    obj.ssbo.model = obj.model_transform * obj.model_base;
    542    obj.center = vec3(obj.ssbo.model * vec4(0.0f, 0.0f, 0.0f, 1.0f));
    543 
    544    pipeline.updateObject(index, obj.ssbo);
    545 
    546    obj.modified = false;
    547 }
    548 
    549 template<class VertexType, class SSBOType>
    550 void VulkanGame::updateObjectVertices(GraphicsPipeline_Vulkan<VertexType, SSBOType>& pipeline,
    551       SceneObject<VertexType, SSBOType>& obj, size_t index) {
    552    pipeline.updateObjectVertices(index, obj.vertices, resourceCommandPool, graphicsQueue);
     551template<class VertexType>
     552vector<VertexType> VulkanGame::addObjectIndex(unsigned int objIndex, vector<VertexType> vertices) {
     553   for (VertexType& vertex : vertices) {
     554      vertex.objIndex = objIndex;
     555   }
     556
     557   return vertices;
    553558}
    554559
     
    557562   for (unsigned int i = 0; i < vertices.size(); i += 3) {
    558563      vec3 p1 = vertices[i].pos;
    559       vec3 p2 = vertices[i+1].pos;
    560       vec3 p3 = vertices[i+2].pos;
     564      vec3 p2 = vertices[i + 1].pos;
     565      vec3 p3 = vertices[i + 2].pos;
    561566
    562567      vec3 normal = normalize(cross(p2 - p1, p3 - p1));
     
    564569      // Add the same normal for all 3 vertices
    565570      vertices[i].normal = normal;
    566       vertices[i+1].normal = normal;
    567       vertices[i+2].normal = normal;
    568    }
    569 
    570    return vertices;
    571 }
    572 
    573 template<class VertexType>
    574 vector<VertexType> VulkanGame::addObjectIndex(unsigned int objIndex, vector<VertexType> vertices) {
    575    for (VertexType& vertex : vertices) {
    576       vertex.objIndex = objIndex;
     571      vertices[i + 1].normal = normal;
     572      vertices[i + 2].normal = normal;
    577573   }
    578574
     
    626622}
    627623
     624// TODO: Just pass in the single object instead of a list of all of them
     625template<class VertexType, class SSBOType>
     626void VulkanGame::updateObject(vector<SceneObject<VertexType, SSBOType>>& objects,
     627      GraphicsPipeline_Vulkan<VertexType, SSBOType>& pipeline, size_t index) {
     628   SceneObject<VertexType, SSBOType>& obj = objects[index];
     629
     630   obj.ssbo.model = obj.model_transform * obj.model_base;
     631   obj.center = vec3(obj.ssbo.model * vec4(0.0f, 0.0f, 0.0f, 1.0f));
     632
     633   pipeline.updateObject(index, obj.ssbo);
     634
     635   obj.modified = false;
     636}
     637
     638template<class VertexType, class SSBOType>
     639void VulkanGame::updateObjectVertices(GraphicsPipeline_Vulkan<VertexType, SSBOType>& pipeline,
     640      SceneObject<VertexType, SSBOType>& obj, size_t index) {
     641   pipeline.updateObjectVertices(index, obj.vertices, resourceCommandPool, graphicsQueue);
     642}
     643
    628644#endif // _VULKAN_GAME_H
Note: See TracChangeset for help on using the changeset viewer.