Changeset a8f0577 in opengl-game


Ignore:
Timestamp:
Jul 8, 2019, 5:01:29 PM (5 years ago)
Author:
Dmitry Portnoy <dmitry.portnoy@…>
Branches:
feature/imgui-sdl, master, points-test
Children:
80de39d
Parents:
7dcd925
Message:

Fix validation layer integration

Files:
1 deleted
2 edited

Legend:

Unmodified
Added
Removed
  • makefile

    r7dcd925 ra8f0577  
    3434        $(CC) $^ $(DEP) $(CFLAGS) -o $@
    3535
    36 CXX_FLAGS = -std=c++17 -Wall -pedantic # -O3 -rdynamic
     36CXX_FLAGS = -std=c++17 -Wall -pedantic# -O3 -rdynamic
    3737
    3838ifeq ($(OS),Darwin)
     
    5151endif
    5252
    53 LIBS = -lSDL2
     53LIBS = `pkg-config --static --libs sdl2`
    5454ifeq ($(OS),Darwin)
    5555        LIBS := $(VULKAN_SDK_PATH)/lib/libvulkan.dylib $(LIBS)
     
    6161LIB_FLAGS = $(LIB_PATHS) $(LIBS)
    6262
    63 vulkangame: vulkan-game-ref.cpp #vulkan-game.cpp game-gui-sdl.cpp
     63vulkangame: vulkan-game.cpp game-gui-sdl.cpp
    6464        $(CC) $(CXX_FLAGS) -o $@ $^ $(LIB_FLAGS)
    6565
  • vulkan-game.cpp

    r7dcd925 ra8f0577  
    2020using namespace std;
    2121using namespace glm;
    22 
    23 bool checkValidationLayerSupport();
    24 vector<const char*> getRequiredExtensions(SDL_Window* window);
    2522
    2623const int SCREEN_WIDTH = 800;
     
    6865         }
    6966         initVulkan();
    70          createInstance();
    7167         mainLoop();
    7268         cleanup();
     
    125121         createInfo.pApplicationInfo = &appInfo;
    126122
    127          auto extensions = getRequiredExtensions(window);
     123         vector<const char*> extensions = getRequiredExtensions();
    128124         createInfo.enabledExtensionCount = static_cast<uint32_t>(extensions.size());
    129125         createInfo.ppEnabledExtensionNames = extensions.data();
     
    156152      }
    157153
     154      bool checkValidationLayerSupport() {
     155         uint32_t layerCount;
     156         vkEnumerateInstanceLayerProperties(&layerCount, nullptr);
     157
     158         vector<VkLayerProperties> availableLayers(layerCount);
     159         vkEnumerateInstanceLayerProperties(&layerCount, availableLayers.data());
     160
     161         for (const char* layerName : validationLayers) {
     162            bool layerFound = false;
     163
     164            for (const auto& layerProperties : availableLayers) {
     165               if (strcmp(layerName, layerProperties.layerName) == 0) {
     166                  layerFound = true;
     167                  break;
     168               }
     169            }
     170
     171            if (!layerFound) {
     172               return false;
     173            }
     174         }
     175
     176         return true;
     177      }
     178
     179      vector<const char*> getRequiredExtensions() {
     180         uint32_t extensionCount = 0;
     181         SDL_Vulkan_GetInstanceExtensions(window, &extensionCount, nullptr);
     182
     183         vector<const char*> extensions(extensionCount);
     184         SDL_Vulkan_GetInstanceExtensions(window, &extensionCount, extensions.data());
     185
     186         if (enableValidationLayers) {
     187            extensions.push_back(VK_EXT_DEBUG_UTILS_EXTENSION_NAME);
     188         }
     189
     190         return extensions;
     191      }
     192
    158193      void mainLoop() {
    159194         // TODO: Create some generic event-handling functions in game-gui-*
     
    204239      }
    205240};
    206 
    207 vector<const char*> getRequiredExtensions(SDL_Window* window) {
    208    uint32_t extensionCount;
    209    SDL_Vulkan_GetInstanceExtensions(window, &extensionCount, nullptr);
    210 
    211    vector<const char*> extensions(extensionCount);
    212    SDL_Vulkan_GetInstanceExtensions(window, &extensionCount, extensions.data());
    213 
    214    if (enableValidationLayers) {
    215       extensions.push_back(VK_EXT_DEBUG_UTILS_EXTENSION_NAME);
    216    }
    217 
    218    return extensions;
    219 }
    220 
    221 bool checkValidationLayerSupport() {
    222    uint32_t layerCount;
    223    vkEnumerateInstanceLayerProperties(&layerCount, nullptr);
    224 
    225    vector<VkLayerProperties> availableLayers(layerCount);
    226    vkEnumerateInstanceLayerProperties(&layerCount, availableLayers.data());
    227 
    228    for (const char* layerName : validationLayers) {
    229       bool layerFound = false;
    230 
    231       for (const auto& layerProperties : availableLayers) {
    232          if (strcmp(layerName, layerProperties.layerName) == 0) {
    233             layerFound = true;
    234             break;
    235          }
    236       }
    237 
    238       if (!layerFound) {
    239          return false;
    240       }
    241    }
    242 
    243    return true;
    244 }
    245241
    246242int main() {
     
    251247   cout << "DEBUGGING IS ON" << endl;
    252248#endif
     249
    253250   /*
    254251   mat4 matrix;
Note: See TracChangeset for help on using the changeset viewer.