Changeset 187b0f5 in opengl-game


Ignore:
Timestamp:
Mar 11, 2021, 2:44:43 AM (4 years ago)
Author:
Dmitry Portnoy <dportnoy@…>
Branches:
feature/imgui-sdl
Children:
301c90a
Parents:
20e4c2b
git-author:
Dmitry Portnoy <dportnoy@…> (03/11/21 02:39:25)
git-committer:
Dmitry Portnoy <dportnoy@…> (03/11/21 02:44:43)
Message:

Change VulkanGame and SDLGame to only use discrete GPUs and switch the timer class to steady_clock

Files:
7 edited

Legend:

Unmodified
Added
Removed
  • .gitignore

    r20e4c2b r187b0f5  
    22vulkanref
    33openglgame
     4sdlgame
    45vulkangame
    56
  • compile.sh

    r20e4c2b r187b0f5  
    1 # TODO: Maybe turn this into a target in the makefile
     1# TODO: Figure out why calling this from a makefile gives an error about shopt not being found
     2
     3# This section is left here in case there's no easy way to get glslangValidator in the path on a Mac
    24
    35OS=$(uname)
     
    68   VULKAN_SDK_PATH=/Users/dportnoy15/Development/vulkan-sdk-macos-1.1.108.0/macOS
    79fi
    8 if [ $OS = "Linux" ]; then
    9    VULKAN_SDK_PATH=/home/dportnoy/Desktop/VulkanSDK/1.1.106.0/x86_64
    10 fi
    11 
    12 echo $VULKAN_SDK_PATH
    1310
    1411shopt -s nullglob
     
    2320   fOut="$shaderName-$shaderType.spv"
    2421
    25    $VULKAN_SDK_PATH/bin/glslangValidator -V $f -o $fOut
     22   glslangValidator -V $f -o $fOut
    2623done
  • makefile

    r20e4c2b r187b0f5  
    1 # CFLAGS are compiler flags and LIBFLAGS could be renamed LINKER_FLAGS
     1# CXX_FLAGS are C++ compiler flags and LIBFLAGS could be renamed LINKER_FLAGS
    22OS = $(shell uname)
    33CC = g++
    4 CFLAGS = -std=c++17 -Wall -pedantic -rdynamic
     4#CXX_FLAGS = -std=c++17 -Wall -pedantic -g3 -rdynamic
     5CXX_FLAGS = -std=c++17 -Wall -pedantic -O3
    56# -rdynamic is to generate debug info for dynamic symbols on debian-based
    67# systems (tested on Linux Mint)
     
    2425
    2526openglref: new-game.cpp logger.cpp utils.cpp crash-logger.cpp IMGUI/imgui_impl_glfw.cpp IMGUI/imgui_impl_opengl3.cpp $(IMGUI_FILES)
    26         $(CC) $^ $(DEP) $(CFLAGS) -o $@ -DGLEW_STATIC
     27        $(CC) $^ $(DEP) $(CXX_FLAGS) -o $@ -DGLEW_STATIC
    2728
    2829openglgame: main-opengl.cpp opengl-game.cpp crash-logger.cpp logger.cpp game-gui-glfw.cpp graphics-pipeline_opengl.cpp IMGUI/imgui_impl_glfw.cpp IMGUI/imgui_impl_opengl3.cpp $(IMGUI_FILES)
    29         $(CC) $^ $(DEP) $(CFLAGS) -o $@ -DGLEW_STATIC
    30 
    31 CXX_FLAGS = -std=c++17 -Wall -pedantic# -O3 -rdynamic
     30        $(CC) $^ $(DEP) $(CXX_FLAGS) -o $@ -DGLEW_STATIC
    3231
    3332ifeq ($(OS),Darwin)
     
    4645endif
    4746
    48 LIBS = `pkg-config --static --libs sdl2 sdl2_image sdl2_ttf sdl2_gfx`
     47LIBS = `pkg-config --static --libs sdl2 sdl2_image sdl2_ttf`
    4948ifeq ($(OS),Darwin)
    5049        LIBS := $(VULKAN_SDK_PATH)/lib/libvulkan.dylib $(LIBS)
    5150endif
    5251ifeq ($(OS),Linux)
    53         LIBS = `pkg-config --static --libs sdl2`
    54         LIBS := -lvulkan $(LIBS) -lSDL2_image -lSDL2_ttf -lSDL2_gfx # TODO: figure out how to statically link these, ideally using pkg-config
     52        #LIBS = `pkg-config --static --libs sdl2`
     53        LIBS =
     54        LIBS := -lvulkan $(LIBS) -lSDL2 -lSDL2_image -lSDL2_ttf # TODO: figure out how to statically link these, ideally using pkg-config
    5555endif
    5656
     
    6363GUI_HEADER_FILES = gui/screen.hpp gui/main-screen.hpp gui/game-screen.hpp gui/ui-element.hpp gui/button.hpp gui/panel.hpp gui/ui-value.hpp
    6464
    65 SRC_FILES = main-vulkan.cpp vulkan-game.cpp crash-logger.cpp logger.cpp vulkan-utils.cpp utils.cpp game-gui-sdl.cpp $(GUI_SRC_FILES)
    66 HEADER_FILES = vulkan-game.hpp crash-logger.hpp logger.hpp vulkan-utils.hpp utils.hpp game-gui-sdl.hpp game-gui.hpp graphics-pipeline_vulkan.hpp $(GUI_HEADER_FILES)
     65vulkangame: SRC_FILES = main-vulkan.cpp vulkan-game.cpp crash-logger.cpp logger.cpp vulkan-utils.cpp utils.cpp game-gui-sdl.cpp IMGUI/imgui_impl_sdl.cpp IMGUI/imgui_impl_vulkan.cpp $(IMGUI_FILES)
     66vulkangame: HEADER_FILES = vulkan-game.hpp crash-logger.hpp logger.hpp vulkan-utils.hpp utils.hpp game-gui-sdl.hpp game-gui.hpp graphics-pipeline_vulkan.hpp IMGUI/imgui_impl_sdl.h IMGUI/imgui_impl_vulkan.h
    6767
    6868vulkangame: $(SRC_FILES) $(HEADER_FILES)
    6969        $(CC) $(CXX_FLAGS) -o $@ $(SRC_FILES) $(LIB_FLAGS) -DGAMEGUI_INCLUDE_VULKAN
    7070
    71 SRC_FILES = main-vulkan.cpp sdl-game.cpp crash-logger.cpp logger.cpp vulkan-utils.cpp game-gui-sdl.cpp IMGUI/imgui_impl_sdl.cpp IMGUI/imgui_impl_vulkan.cpp $(IMGUI_FILES)
    72 HEADER_FILES = sdl-game.hpp crash-logger.hpp logger.hpp vulkan-utils.hpp game-gui.hpp game-gui-sdl.hpp IMGUI/imgui_impl_sdl.h IMGUI/imgui_impl_vulkan.h
     71sdlgame: SRC_FILES = main-vulkan.cpp sdl-game.cpp crash-logger.cpp logger.cpp vulkan-utils.cpp game-gui-sdl.cpp IMGUI/imgui_impl_sdl.cpp IMGUI/imgui_impl_vulkan.cpp $(IMGUI_FILES)
     72sdlgame: HEADER_FILES = sdl-game.hpp crash-logger.hpp logger.hpp vulkan-utils.hpp game-gui.hpp game-gui-sdl.hpp IMGUI/imgui_impl_sdl.h IMGUI/imgui_impl_vulkan.h
    7373
    7474sdlgame: $(SRC_FILES) $(HEADER_FILES)
  • sdl-game.cpp

    r20e4c2b r187b0f5  
    4949   swapChainPresentMode = VK_PRESENT_MODE_MAX_ENUM_KHR;
    5050   swapChainMinImageCount = 0;
    51 
     51   currentFrame = 0;
     52   imageIndex = 0;
    5253   shouldRecreateSwapChain = false;
    5354
     
    254255
    255256void VulkanGame::renderLoop() {
    256    startTime = high_resolution_clock::now();
    257    curTime = duration<float, seconds::period>(high_resolution_clock::now() - startTime).count();
     257   startTime = steady_clock::now();
     258   curTime = duration<float, seconds::period>(steady_clock::now() - startTime).count();
    258259
    259260   fpsStartTime = curTime;
     
    265266   while (!done) {
    266267
    267       curTime = duration<float, seconds::period>(high_resolution_clock::now() - startTime).count();
     268      curTime = duration<float, seconds::period>(steady_clock::now() - startTime).count();
    268269
    269270      if (curTime - fpsStartTime >= 1.0f) {
     
    333334            recreateSwapChain();
    334335
    335             imageIndex = 0;
    336336            shouldRecreateSwapChain = false;
    337337         }
     
    496496
    497497   cout << "Device: " << deviceProperties.deviceName << endl;
     498
     499   // TODO: Eventually, maybe let the user pick out of a set of GPUs in case the user does want to use
     500   // an integrated GPU. On my laptop, this function returns TRUE for the integrated GPU, but crashes
     501   // when trying to use it to render. Maybe I just need to figure out which other extensions and features
     502   // to check.
     503   if (deviceProperties.deviceType != VkPhysicalDeviceType::VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU) {
     504      return false;
     505   }
    498506
    499507   QueueFamilyIndices indices = VulkanUtils::findQueueFamilies(physicalDevice, surface);
     
    970978
    971979   createSyncObjects();
     980
     981   imageIndex = 0;
    972982}
    973983
  • vulkan-game.cpp

    r20e4c2b r187b0f5  
    5959   swapChainPresentMode = VK_PRESENT_MODE_MAX_ENUM_KHR;
    6060   swapChainMinImageCount = 0;
    61 
    6261   currentFrame = 0;
     62   imageIndex = 0;
    6363   shouldRecreateSwapChain = false;
    6464
     
    706706
    707707void VulkanGame::renderLoop() {
    708    startTime = high_resolution_clock::now();
    709    curTime = duration<float, seconds::period>(high_resolution_clock::now() - startTime).count();
     708   startTime = steady_clock::now();
     709   curTime = duration<float, seconds::period>(steady_clock::now() - startTime).count();
    710710
    711711   fpsStartTime = curTime;
     
    720720
    721721      this->prevTime = curTime;
    722       curTime = duration<float, seconds::period>(high_resolution_clock::now() - this->startTime).count();
     722      curTime = duration<float, seconds::period>(steady_clock::now() - this->startTime).count();
    723723      this->elapsedTime = curTime - this->prevTime;
    724724
     
    901901            recreateSwapChain();
    902902
    903             imageIndex = 0;
    904903            shouldRecreateSwapChain = false;
    905904         }
     
    12771276
    12781277   cout << "Device: " << deviceProperties.deviceName << endl;
     1278
     1279   // TODO: Eventually, maybe let the user pick out of a set of GPUs in case the user does want to use
     1280   // an integrated GPU. On my laptop, this function returns TRUE for the integrated GPU, but crashes
     1281   // when trying to use it to render. Maybe I just need to figure out which other extensions and features
     1282   // to check.
     1283   if (deviceProperties.deviceType != VkPhysicalDeviceType::VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU) {
     1284      return false;
     1285   }
    12791286
    12801287   QueueFamilyIndices indices = VulkanUtils::findQueueFamilies(physicalDevice, surface);
  • vulkan-game.hpp

    r20e4c2b r187b0f5  
    2424#include "vulkan-utils.hpp"
    2525#include "graphics-pipeline_vulkan.hpp"
    26 
    2726#include "game-gui-sdl.hpp"
    2827
  • vulkan-ref.cpp

    r20e4c2b r187b0f5  
    99#include <glm/glm.hpp>
    1010#include <glm/gtc/matrix_transform.hpp>
     11
     12#include <SDL2/SDL_ttf.h>
    1113
    1214#include <iostream>
Note: See TracChangeset for help on using the changeset viewer.