Changeset 20e4c2b in opengl-game for vulkan-game.hpp


Ignore:
Timestamp:
Mar 9, 2021, 2:59:40 AM (4 years ago)
Author:
Dmitry Portnoy <dportnoy@…>
Branches:
feature/imgui-sdl
Children:
187b0f5
Parents:
40eb092
Message:

In VulkanGame, use ImGui for the UI instead of using SDL to draw elements onto an overlay, and remove everything associated with the overlay pipeline

File:
1 edited

Legend:

Unmodified
Added
Removed
  • vulkan-game.hpp

    r40eb092 r20e4c2b  
    77#include <vector>
    88
     9#include <vulkan/vulkan.h>
     10
     11#include <SDL2/SDL.h>
     12#include <SDL2/SDL_ttf.h>
     13
    914#define GLM_FORCE_RADIANS
    1015#define GLM_FORCE_DEPTH_ZERO_TO_ONE // Since, in Vulkan, the depth range is 0 to 1 instead of -1 to 1
     
    1419#include <glm/gtc/matrix_transform.hpp>
    1520
    16 #include <vulkan/vulkan.h>
    17 
    18 #include <SDL2/SDL.h>
    19 #include <SDL2/SDL_ttf.h>
    20 
    2121#include "IMGUI/imgui_impl_vulkan.h"
    2222
     
    2626
    2727#include "game-gui-sdl.hpp"
    28 
    29 #include "gui/screen.hpp"
    3028
    3129using namespace glm;
     
    196194};
    197195
     196enum UIValueType {
     197   UIVALUE_INT,
     198   UIVALUE_DOUBLE,
     199};
     200
     201struct UIValue {
     202   UIValueType type;
     203   string label;
     204   void* value;
     205
     206   UIValue(UIValueType _type, string _label, void* _value) : type(_type), label(_label), value(_value) {}
     207};
     208
    198209class VulkanGame {
    199210   public:
     
    203214      void run(int width, int height, unsigned char guiFlags);
    204215
    205       void goToScreen(Screen* screen);
    206       void quitGame();
    207 
    208       map<ScreenType, Screen*> screens;
    209       Screen* currentScreen;
    210 
    211       TTF_Font* lazyFont;
    212       TTF_Font* proggyFont;
    213 
    214       int score;
    215       float fps;
    216 
    217       GraphicsPipeline_Vulkan<OverlayVertex, void*> overlayPipeline;
    218 
    219216      GraphicsPipeline_Vulkan<ModelVertex, SSBO_ModelObject> modelPipeline;
    220 
    221217      GraphicsPipeline_Vulkan<ShipVertex, SSBO_ModelObject> shipPipeline;
    222 
    223218      GraphicsPipeline_Vulkan<AsteroidVertex, SSBO_Asteroid> asteroidPipeline;
    224 
    225219      GraphicsPipeline_Vulkan<LaserVertex, SSBO_Laser> laserPipeline;
    226 
    227220      GraphicsPipeline_Vulkan<ExplosionVertex, SSBO_Explosion> explosionPipeline;
    228221
     
    250243      SDL_version sdlVersion;
    251244      SDL_Window* window = nullptr;
    252       SDL_Renderer* renderer = nullptr;
    253 
    254       SDL_Texture* uiOverlay = nullptr;
    255245
    256246      VkInstance instance;
     
    299289      VkSampler textureSampler;
    300290
    301       VulkanImage sdlOverlayImage;
    302       VkDescriptorImageInfo sdlOverlayImageDescriptor;
    303 
    304291      VulkanImage floorTextureImage;
    305292      VkDescriptorImageInfo floorTextureImageDescriptor;
     
    318305      // if there is a need to add other uniform variables to one or more of the shaders
    319306
    320       vector<SceneObject<OverlayVertex, void*>> overlayObjects;
    321 
    322307      vector<SceneObject<ModelVertex, SSBO_ModelObject>> modelObjects;
    323308
     
    361346
    362347      vector<BaseEffectOverTime*> effects;
     348
     349      float shipSpeed = 0.5f;
     350      float asteroidSpeed = 2.0f;
     351
     352      float spawnRate_asteroid = 0.5;
     353      float lastSpawn_asteroid;
     354
     355      unsigned int leftLaserIdx = -1;
     356      EffectOverTime<AsteroidVertex, SSBO_Asteroid>* leftLaserEffect = nullptr;
     357
     358      unsigned int rightLaserIdx = -1;
     359      EffectOverTime<AsteroidVertex, SSBO_Asteroid>* rightLaserEffect = nullptr;
     360
     361      /*** High-level vars ***/
     362
     363      void (VulkanGame::* currentRenderScreenFn)();
     364
     365      map<string, vector<UIValue>> valueLists;
     366
     367      int score;
     368      float fps;
    363369
    364370      // TODO: Make a separate TImer class
     
    369375      int frameCount;
    370376
    371       float shipSpeed = 0.5f;
    372       float asteroidSpeed = 2.0f;
    373 
    374       float spawnRate_asteroid = 0.5;
    375       float lastSpawn_asteroid;
    376 
    377       unsigned int leftLaserIdx = -1;
    378       EffectOverTime<AsteroidVertex, SSBO_Asteroid>* leftLaserEffect = nullptr;
    379 
    380       unsigned int rightLaserIdx = -1;
    381       EffectOverTime<AsteroidVertex, SSBO_Asteroid>* rightLaserEffect = nullptr;
     377      /*** Functions ***/
    382378
    383379      bool initUI(int width, int height, unsigned char guiFlags);
     
    385381      void initGraphicsPipelines();
    386382      void initMatrices();
    387       void mainLoop();
     383      void renderLoop();
    388384      void updateScene();
    389385      void cleanup();
     
    458454
    459455      void cleanupSwapChain();
     456
     457      /*** High-level functions ***/
     458
     459      void renderMainScreen();
     460      void renderGameScreen();
     461
     462      void initGuiValueLists(map<string, vector<UIValue>>& valueLists);
     463      void renderGuiValueList(vector<UIValue>& values);
     464
     465      void goToScreen(void (VulkanGame::* renderScreenFn)());
     466      void quitGame();
    460467};
    461468
Note: See TracChangeset for help on using the changeset viewer.