Move instance creation into Renderer class
This commit is contained in:
parent
98665fbc66
commit
1249c97f24
4 changed files with 32 additions and 11 deletions
|
@ -6,6 +6,8 @@ list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
|
||||||
find_package(SDL2 REQUIRED)
|
find_package(SDL2 REQUIRED)
|
||||||
find_package(Vulkan REQUIRED)
|
find_package(Vulkan REQUIRED)
|
||||||
|
|
||||||
add_executable(Graph main.cpp)
|
add_executable(Graph
|
||||||
|
main.cpp
|
||||||
|
renderer.cpp)
|
||||||
target_link_libraries(Graph PUBLIC SDL2::SDL2 SDL2::SDL2main ${Vulkan_LIBRARY})
|
target_link_libraries(Graph PUBLIC SDL2::SDL2 SDL2::SDL2main ${Vulkan_LIBRARY})
|
||||||
target_include_directories(Graph PUBLIC ${Vulkan_INCLUDE_DIRS})
|
target_include_directories(Graph PUBLIC ${Vulkan_INCLUDE_DIRS})
|
||||||
|
|
15
main.cpp
15
main.cpp
|
@ -1,18 +1,13 @@
|
||||||
#include <iostream>
|
|
||||||
#include <SDL.h>
|
#include <SDL.h>
|
||||||
#include <vulkan/vulkan.h>
|
|
||||||
|
#include "renderer.h"
|
||||||
|
|
||||||
int main(int, char*[]) {
|
int main(int, char*[]) {
|
||||||
SDL_Window* window = SDL_CreateWindow("Graph", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 640, 480, SDL_WINDOW_VULKAN);
|
SDL_Window* window = SDL_CreateWindow("Graph", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 640, 480, 0);
|
||||||
if(!window)
|
if(!window)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
VkInstanceCreateInfo info = {};
|
Renderer* renderer = new Renderer();
|
||||||
|
|
||||||
VkInstance instance;
|
|
||||||
vkCreateInstance(&info, nullptr, &instance);
|
|
||||||
if(!instance)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
bool running = true;
|
bool running = true;
|
||||||
while(running) {
|
while(running) {
|
||||||
|
@ -23,7 +18,7 @@ int main(int, char*[]) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
vkDestroyInstance(instance, nullptr);
|
delete renderer;
|
||||||
|
|
||||||
SDL_DestroyWindow(window);
|
SDL_DestroyWindow(window);
|
||||||
|
|
||||||
|
|
12
renderer.cpp
Normal file
12
renderer.cpp
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
#include "renderer.h"
|
||||||
|
|
||||||
|
Renderer::Renderer() {
|
||||||
|
VkInstanceCreateInfo instanceCreateInfo = {};
|
||||||
|
instanceCreateInfo.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
|
||||||
|
|
||||||
|
vkCreateInstance(&instanceCreateInfo, nullptr, &instance_);
|
||||||
|
}
|
||||||
|
|
||||||
|
Renderer::~Renderer() {
|
||||||
|
vkDestroyInstance(instance_, nullptr);
|
||||||
|
}
|
12
renderer.h
Normal file
12
renderer.h
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <vulkan/vulkan.h>
|
||||||
|
|
||||||
|
class Renderer {
|
||||||
|
public:
|
||||||
|
Renderer();
|
||||||
|
~Renderer();
|
||||||
|
|
||||||
|
private:
|
||||||
|
VkInstance instance_ = nullptr;
|
||||||
|
};
|
Reference in a new issue