Archived
1
Fork 0

Move instance creation into Renderer class

This commit is contained in:
Joshua Goins 2018-09-27 20:09:42 -04:00
parent 98665fbc66
commit 1249c97f24
4 changed files with 32 additions and 11 deletions

View file

@ -6,6 +6,8 @@ list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
find_package(SDL2 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_include_directories(Graph PUBLIC ${Vulkan_INCLUDE_DIRS})

View file

@ -1,18 +1,13 @@
#include <iostream>
#include <SDL.h>
#include <vulkan/vulkan.h>
#include "renderer.h"
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)
return -1;
VkInstanceCreateInfo info = {};
VkInstance instance;
vkCreateInstance(&info, nullptr, &instance);
if(!instance)
return -1;
Renderer* renderer = new Renderer();
bool running = true;
while(running) {
@ -23,7 +18,7 @@ int main(int, char*[]) {
}
}
vkDestroyInstance(instance, nullptr);
delete renderer;
SDL_DestroyWindow(window);

12
renderer.cpp Normal file
View 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
View file

@ -0,0 +1,12 @@
#pragma once
#include <vulkan/vulkan.h>
class Renderer {
public:
Renderer();
~Renderer();
private:
VkInstance instance_ = nullptr;
};