Changeset 5ba732a in opengl-game


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

Add a modified flag to SceneObject and, instead of copying an object's data to the graphics card immediately after it is updated, instead set the flag to true and update all modified objects at once right before rendering

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • vulkan-game.cpp

    r4994692 r5ba732a  
    248248   texturedSquare->model_base =
    249249      translate(mat4(1.0f), vec3(0.0f, 0.0f, -2.0f));
    250    updateObject(modelObjects, modelPipeline, modelObjects.size() - 1);
     250   texturedSquare->modified = true;
    251251
    252252   texturedSquare = &addObject(modelObjects, modelPipeline,
     
    264264   texturedSquare->model_base =
    265265      translate(mat4(1.0f), vec3(0.0f, 0.0f, -1.5f));
    266    updateObject(modelObjects, modelPipeline, modelObjects.size() - 1);
     266   texturedSquare->modified = true;
    267267
    268268   modelPipeline.createDescriptorSetLayout();
     
    549549      translate(mat4(1.0f), vec3(0.0f, -1.2f, 1.65f)) *
    550550      scale(mat4(1.0f), vec3(0.1f, 0.1f, 0.1f));
    551    updateObject(shipObjects, shipPipeline, 0);
     551   ship.modified = true;
    552552}
    553553
     
    650650                  texturedSquare.model_base =
    651651                     translate(mat4(1.0f), vec3(0.0f, 0.0f, zOffset));
    652                   updateObject(modelObjects, modelPipeline, modelObjects.size() - 1);
     652                  texturedSquare.modified = true;
    653653               } else {
    654654                  cout << "Key event detected" << endl;
     
    682682         ship.model_transform = translate(mat4(1.0f), vec3(distance, 0.0f, 0.0f))
    683683            * shipObjects[0].model_transform;
    684 
    685          updateObject(shipObjects, shipPipeline, 0);
     684         ship.modified = true;
    686685      } else if (gui->keyPressed(SDL_SCANCODE_RIGHT)) {
    687686         float distance = this->shipSpeed * this->elapsedTime;
     
    689688         ship.model_transform = translate(mat4(1.0f), vec3(distance, 0.0f, 0.0f))
    690689            * shipObjects[0].model_transform;
    691 
    692          updateObject(shipObjects, shipPipeline, 0);
     690         ship.modified = true;
    693691      }
    694692
     
    704702// where it will run just once per frame
    705703void VulkanGame::updateScene(uint32_t currentImage) {
    706    for (int i = 0; i < modelObjects.size(); i++) {
    707       modelObjects[i].model_transform =
     704   for (SceneObject<ModelVertex, SSBO_ModelObject>& model : this->modelObjects) {
     705      model.model_transform =
    708706         translate(mat4(1.0f), vec3(0.0f, -2.0f, -0.0f)) *
    709707         rotate(mat4(1.0f), this->curTime * radians(90.0f), vec3(0.0f, 0.0f, 1.0f));
    710 
    711       updateObject(modelObjects, modelPipeline, i);
    712    }
    713 
    714    for (int i = 0; i < this->asteroidObjects.size(); i++) {
    715       if (!this->asteroidObjects[i].ssbo.deleted) {
    716          vec3 objCenter = vec3(viewMat * vec4(this->asteroidObjects[i].center, 1.0f));
    717 
    718          if ((objCenter.z - this->asteroidObjects[i].radius) > -NEAR_CLIP) {
    719             this->asteroidObjects[i].ssbo.deleted = true;
     708      model.modified = true;
     709   }
     710
     711   for (SceneObject<AsteroidVertex, SSBO_Asteroid>& asteroid : this->asteroidObjects) {
     712      if (!asteroid.ssbo.deleted) {
     713         vec3 objCenter = vec3(viewMat * vec4(asteroid.center, 1.0f));
     714
     715         if ((objCenter.z - asteroid.radius) > -NEAR_CLIP) {
     716            asteroid.ssbo.deleted = true;
     717
     718            // TODO: Create explosion here
    720719         } else {
    721             this->asteroidObjects[i].model_transform =
     720            asteroid.model_transform =
    722721               translate(mat4(1.0f), vec3(0.0f, 0.0f, this->asteroidSpeed * this->elapsedTime)) *
    723                this->asteroidObjects[i].model_transform;
     722               asteroid.model_transform;
    724723         }
    725724
    726          updateObject(asteroidObjects, asteroidPipeline, i);
     725         asteroid.modified = true;
    727726      }
    728727   }
     
    807806         rotate(mat4(1.0f), radians(60.0f), vec3(1.0f, 1.0f, -1.0f)) *
    808807         scale(mat4(1.0f), vec3(0.1f, 0.1f, 0.1f));
    809 
    810       updateObject(asteroidObjects, asteroidPipeline, asteroidObjects.size() - 1);
     808      asteroid.modified = true;
     809   }
     810
     811   for (size_t i = 0; i < shipObjects.size(); i++) {
     812      if (shipObjects[i].modified) {
     813         updateObject(shipObjects, shipPipeline, i);
     814      }
     815   }
     816
     817   for (size_t i = 0; i < modelObjects.size(); i++) {
     818      if (modelObjects[i].modified) {
     819         updateObject(modelObjects, modelPipeline, i);
     820      }
     821   }
     822
     823   for (size_t i = 0; i < asteroidObjects.size(); i++) {
     824      if (asteroidObjects[i].modified) {
     825         updateObject(asteroidObjects, asteroidPipeline, i);
     826      }
    811827   }
    812828
  • vulkan-game.hpp

    r4994692 r5ba732a  
    7777   mat4 model_base;
    7878   mat4 model_transform;
     79
     80   bool modified;
    7981
    8082   // TODO: Figure out if I should make child classes that have these fields instead of putting them in the
     
    295297   }
    296298
    297    objects.push_back({ vertices, indices, ssbo, mat4(1.0f), mat4(1.0f) });
     299   objects.push_back({ vertices, indices, ssbo, mat4(1.0f), mat4(1.0f), false });
    298300
    299301   SceneObject<VertexType, SSBOType>& obj = objects.back();
     
    333335
    334336   pipeline.updateObject(index, obj.ssbo);
     337
     338   obj.modified = false;
    335339}
    336340
Note: See TracChangeset for help on using the changeset viewer.