Add vulkan resources
This commit is contained in:
19
src/CMakeLists.txt
Normal file
19
src/CMakeLists.txt
Normal file
@@ -0,0 +1,19 @@
|
||||
|
||||
# Add source to this project's executable.
|
||||
add_executable(vulkan_guide
|
||||
main.cpp
|
||||
vk_engine.cpp
|
||||
vk_engine.h
|
||||
vk_types.h
|
||||
vk_initializers.cpp
|
||||
vk_initializers.h)
|
||||
|
||||
|
||||
set_property(TARGET vulkan_guide PROPERTY VS_DEBUGGER_WORKING_DIRECTORY "$<TARGET_FILE_DIR:vulkan_guide>")
|
||||
|
||||
target_include_directories(vulkan_guide PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}")
|
||||
target_link_libraries(vulkan_guide vkbootstrap vma glm tinyobjloader imgui stb_image)
|
||||
|
||||
target_link_libraries(vulkan_guide Vulkan::Vulkan sdl2)
|
||||
|
||||
add_dependencies(vulkan_guide Shaders)
|
16
src/main.cpp
16
src/main.cpp
@@ -1,6 +1,14 @@
|
||||
#include <iostream>
|
||||
#include <vk_engine.h>
|
||||
|
||||
int main() {
|
||||
std::cout << "Hello, World!";
|
||||
return 0;
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
VulkanEngine engine;
|
||||
|
||||
engine.init();
|
||||
|
||||
engine.run();
|
||||
|
||||
engine.cleanup();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
60
src/vk_engine.cpp
Normal file
60
src/vk_engine.cpp
Normal file
@@ -0,0 +1,60 @@
|
||||
|
||||
#include "vk_engine.h"
|
||||
|
||||
#include <SDL.h>
|
||||
#include <SDL_vulkan.h>
|
||||
|
||||
#include <vk_types.h>
|
||||
#include <vk_initializers.h>
|
||||
|
||||
void VulkanEngine::init()
|
||||
{
|
||||
// We initialize SDL and create a window with it.
|
||||
SDL_Init(SDL_INIT_VIDEO);
|
||||
|
||||
SDL_WindowFlags window_flags = (SDL_WindowFlags)(SDL_WINDOW_VULKAN);
|
||||
|
||||
_window = SDL_CreateWindow(
|
||||
"Vulkan Engine",
|
||||
SDL_WINDOWPOS_UNDEFINED,
|
||||
SDL_WINDOWPOS_UNDEFINED,
|
||||
_windowExtent.width,
|
||||
_windowExtent.height,
|
||||
window_flags
|
||||
);
|
||||
|
||||
//everything went fine
|
||||
_isInitialized = true;
|
||||
}
|
||||
void VulkanEngine::cleanup()
|
||||
{
|
||||
if (_isInitialized) {
|
||||
|
||||
SDL_DestroyWindow(_window);
|
||||
}
|
||||
}
|
||||
|
||||
void VulkanEngine::draw()
|
||||
{
|
||||
//nothing yet
|
||||
}
|
||||
|
||||
void VulkanEngine::run()
|
||||
{
|
||||
SDL_Event e;
|
||||
bool bQuit = false;
|
||||
|
||||
//main loop
|
||||
while (!bQuit)
|
||||
{
|
||||
//Handle events on queue
|
||||
while (SDL_PollEvent(&e) != 0)
|
||||
{
|
||||
//close the window when user alt-f4s or clicks the X button
|
||||
if (e.type == SDL_QUIT) bQuit = true;
|
||||
}
|
||||
|
||||
draw();
|
||||
}
|
||||
}
|
||||
|
29
src/vk_engine.h
Normal file
29
src/vk_engine.h
Normal file
@@ -0,0 +1,29 @@
|
||||
// vulkan_guide.h : Include file for standard system include files,
|
||||
// or project specific include files.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <vk_types.h>
|
||||
|
||||
class VulkanEngine {
|
||||
public:
|
||||
|
||||
bool _isInitialized{ false };
|
||||
int _frameNumber {0};
|
||||
|
||||
VkExtent2D _windowExtent{ 1700 , 900 };
|
||||
|
||||
struct SDL_Window* _window{ nullptr };
|
||||
|
||||
//initializes everything in the engine
|
||||
void init();
|
||||
|
||||
//shuts down the engine
|
||||
void cleanup();
|
||||
|
||||
//draw loop
|
||||
void draw();
|
||||
|
||||
//run main loop
|
||||
void run();
|
||||
};
|
1
src/vk_initializers.cpp
Normal file
1
src/vk_initializers.cpp
Normal file
@@ -0,0 +1 @@
|
||||
#include <vk_initializers.h>
|
12
src/vk_initializers.h
Normal file
12
src/vk_initializers.h
Normal file
@@ -0,0 +1,12 @@
|
||||
// vulkan_guide.h : Include file for standard system include files,
|
||||
// or project specific include files.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <vk_types.h>
|
||||
|
||||
namespace vkinit {
|
||||
|
||||
//vulkan init code goes here
|
||||
}
|
||||
|
8
src/vk_types.h
Normal file
8
src/vk_types.h
Normal file
@@ -0,0 +1,8 @@
|
||||
// vulkan_guide.h : Include file for standard system include files,
|
||||
// or project specific include files.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <vulkan/vulkan.h>
|
||||
|
||||
//we will add our main reusable types here
|
Reference in New Issue
Block a user