Changeset 3b84bb6 in opengl-game for vulkan-game.hpp


Ignore:
Timestamp:
Feb 25, 2020, 6:51:02 PM (5 years ago)
Author:
Dmitry Portnoy <dmitry.portnoy@…>
Branches:
feature/imgui-sdl, master, points-test
Children:
44f23af
Parents:
2da64ef
Message:

In VulkanGame, call centerObject() on all objects when they are created and move that call inside VulkanGame::addObject(), rename GraphicsPipeline_Vulkan::addVertices() to addObject, add start adding generic support for objects to be added after pipeline creation is complete

File:
1 edited

Legend:

Unmodified
Added
Removed
  • vulkan-game.hpp

    r2da64ef r3b84bb6  
    5858   mat4 model_base;
    5959   mat4 model_transform;
     60   vec3 center;
     61   float radius;
    6062};
    6163
     
    217219      void addObject(vector<SceneObject<VertexType, SSBOType>>& objects,
    218220         GraphicsPipeline_Vulkan<VertexType, SSBOType>& pipeline,
    219          const vector<VertexType>& vertices, vector<uint16_t> indices, SSBOType ssbo);
     221         const vector<VertexType>& vertices, vector<uint16_t> indices, SSBOType ssbo,
     222         bool pipelinesCreated);
    220223
    221224      template<class VertexType, class SSBOType>
     
    229232      vector<VertexType> addObjectIndex(unsigned int objIndex, vector<VertexType> vertices);
    230233
    231       template<class VertexType>
    232       vector<VertexType> centerObject(vector<VertexType> vertices);
     234      template<class VertexType, class SSBOType>
     235      void centerObject(SceneObject<VertexType, SSBOType>& object);
    233236
    234237      void createBufferSet(VkDeviceSize bufferSize, VkBufferUsageFlags flags,
     
    246249};
    247250
     251// TODO: Right now, it's basically necessary to pass the identity matrix in for ssbo.model
     252// and to change the model matrix later by setting model_transform and then calling updateObject()
     253// Figure out a better way to allow the model matrix to be set during objecting creation
    248254template<class VertexType, class SSBOType>
    249255void VulkanGame::addObject(vector<SceneObject<VertexType, SSBOType>>& objects,
    250256      GraphicsPipeline_Vulkan<VertexType, SSBOType>& pipeline,
    251       const vector<VertexType>& vertices, vector<uint16_t> indices, SSBOType ssbo) {
     257      const vector<VertexType>& vertices, vector<uint16_t> indices, SSBOType ssbo,
     258      bool pipelinesCreated) {
    252259   size_t numVertices = pipeline.getNumVertices();
    253260
     
    257264
    258265   objects.push_back({ vertices, indices, ssbo, mat4(1.0f), mat4(1.0f) });
    259 
    260    pipeline.addVertices(vertices, indices, commandPool, graphicsQueue);
     266   centerObject(objects.back());
     267
     268   bool storageBufferResized = pipeline.addObject(vertices, indices, ssbo, commandPool, graphicsQueue);
     269
     270   if (pipelinesCreated) {
     271      if (storageBufferResized) {
     272      }
     273
     274      createCommandBuffers();
     275   }
    261276}
    262277
     
    302317}
    303318
    304 template<class VertexType>
    305 vector<VertexType> VulkanGame::centerObject(vector<VertexType> vertices) {
     319template<class VertexType, class SSBOType>
     320void VulkanGame::centerObject(SceneObject<VertexType, SSBOType>& object) {
     321   vector<VertexType>& vertices = object.vertices;
     322
    306323   float min_x = vertices[0].pos.x;
    307324   float max_x = vertices[0].pos.x;
     
    313330   // start from the second point
    314331   for (unsigned int i = 1; i < vertices.size(); i++) {
    315       if (min_x > vertices[i].pos.x) {
    316          min_x = vertices[i].pos.x;
    317       } else if (max_x < vertices[i].pos.x) {
    318          max_x = vertices[i].pos.x;
     332      vec3& pos = vertices[i].pos;
     333
     334      if (min_x > pos.x) {
     335         min_x = pos.x;
     336      } else if (max_x < pos.x) {
     337         max_x = pos.x;
    319338      }
    320339
    321       if (min_y > vertices[i].pos.y) {
    322          min_y = vertices[i].pos.y;
    323       } else if (max_y < vertices[i].pos.y) {
    324          max_y = vertices[i].pos.y;
     340      if (min_y > pos.y) {
     341         min_y = pos.y;
     342      } else if (max_y < pos.y) {
     343         max_y = pos.y;
    325344      }
    326345
    327       if (min_z > vertices[i].pos.z) {
    328          min_z = vertices[i].pos.z;
    329       } else if (max_z < vertices[i].pos.z) {
    330          max_z = vertices[i].pos.z;
     346      if (min_z > pos.z) {
     347         min_z = pos.z;
     348      } else if (max_z < pos.z) {
     349         max_z = pos.z;
    331350      }
    332351   }
     
    338357   }
    339358
    340    return vertices;
     359   object.radius = std::max(center.x, center.y);
     360   object.radius = std::max(object.radius, center.z);
     361   object.center = vec3(0.0f, 0.0f, 0.0f);
    341362}
    342363
Note: See TracChangeset for help on using the changeset viewer.