Change build system to CMake
According to my own documentation, the project tree should look entirely different. Also, it should use CMake instead of Make. This commit introduces changes that will make my project tree to adhere to my own documentation.
This commit is contained in:
1 parent
0c45da5cc4
commit
649e7f76fe
17 files changed
+109
-53
No files matched your search
@@ -0,0 +1,51 @@
|
||||
add_library(rse_graphics)
|
||||
|
||||
find_package(Vulkan REQUIRED)
|
||||
find_package(glfw3 REQUIRED)
|
||||
find_package(glm REQUIRED)
|
||||
|
||||
find_package(Vulkan COMPONENTS glslc)
|
||||
find_program(glslc_executable NAMES glslc HINTS Vulkan::glslc)
|
||||
|
||||
function(compile_shader)
|
||||
cmake_parse_arguments(PARSE_ARGV 1 arg "" "ENV;FORMAT" "SOURCES")
|
||||
foreach(source ${arg_SOURCES})
|
||||
add_custom_command(
|
||||
OUTPUT ${source}.${arg_FORMAT}
|
||||
DEPENDS ${source}
|
||||
DEPFILE ${source}.d
|
||||
COMMAND
|
||||
${glslc_executable}
|
||||
-o ${source}.${arg_FORMAT}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/${source}
|
||||
)
|
||||
endforeach()
|
||||
endfunction()
|
||||
|
||||
|
||||
target_include_directories(rse_graphics PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include
|
||||
${CMAKE_SOURCE_DIR}/third_party/vma/include
|
||||
${CMAKE_SOURCE_DIR}/Utilities/include
|
||||
${Vulkan_INCLUDE_DIR}
|
||||
${glfw3_INCLUDE_DIR}
|
||||
${glm_INCLUDE_DIR})
|
||||
|
||||
|
||||
target_sources(rse_graphics PRIVATE
|
||||
src/window.cpp
|
||||
src/vulkanBase.cpp)
|
||||
|
||||
target_link_libraries(rse_graphics PRIVATE
|
||||
rse_utilities
|
||||
${Vulkan_LIBRARIES}
|
||||
glfw
|
||||
glm)
|
||||
|
||||
compile_shader(rse_graphics
|
||||
ENV opengl
|
||||
FORMAT num
|
||||
SOURCES
|
||||
shaders/shader.vert
|
||||
shaders/shader.frag
|
||||
)
|
||||
@@ -0,0 +1,43 @@
|
||||
/**
|
||||
* @file vulkanBase.h
|
||||
* @author Piotr Krygier (everyonecancode@gmail.com)
|
||||
* @brief Vulkan wrapper functions used by other parts of Graphics component
|
||||
* @version 0.1
|
||||
* @date 2022-05-13
|
||||
*
|
||||
* @copyright Copyright (c) 2022
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef RSE_GRAPHICS_VULKANBASE_HPP
|
||||
#define RSE_GRAPHICS_VULKANBASE_HPP
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace rse::graphics::vulkanbase
|
||||
{
|
||||
|
||||
/**
|
||||
* @brief Initialize Vulkan backend
|
||||
*
|
||||
* @return uint8_t 0 on success. Status code on failure
|
||||
*/
|
||||
|
||||
|
||||
uint8_t initVulkan();
|
||||
|
||||
/**
|
||||
* @brief Deinitialize Vulkan backend
|
||||
*
|
||||
*/
|
||||
void deinitVulkan();
|
||||
|
||||
/**
|
||||
* @brief Draw frame on the screen.
|
||||
*
|
||||
*/
|
||||
void drawFrame();
|
||||
|
||||
} /* namespace rse::graphics::vulkanbase */
|
||||
|
||||
#endif /* RSE_GRAPHICS_VULKANBASE_HPP */
|
||||
@@ -0,0 +1,47 @@
|
||||
/**
|
||||
* @file window.h
|
||||
* @author Piotr Krygier (everyonencancode@gmail.com)
|
||||
* @brief Window control system
|
||||
* @version 0.1
|
||||
* @date 2022-02-15
|
||||
*
|
||||
* @copyright Copyright (c) 2022
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <vulkan/vulkan.h>
|
||||
|
||||
/* Vulkan header MUST be included before glfw */
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
namespace rse::graphics::window
|
||||
{
|
||||
|
||||
/**
|
||||
* @brief Initialize window
|
||||
*
|
||||
* @return uint16_t WINDOW_SUCCESS on success. Possible errors:
|
||||
* WINDOW_VULKAN_NOT_LOADED
|
||||
* WINDOW_WINDOW_NOT_CREATED
|
||||
*
|
||||
*/
|
||||
uint16_t windowInit();
|
||||
|
||||
/**
|
||||
* @brief Main window loop
|
||||
*
|
||||
* @return uint16_t WINDOW_SUCCESS or error code
|
||||
*/
|
||||
uint16_t windowLoop();
|
||||
|
||||
/**
|
||||
* @brief Closes window and terminates GLFW
|
||||
*
|
||||
*/
|
||||
void windowTerminate();
|
||||
|
||||
GLFWwindow* getWindowHandle();
|
||||
|
||||
} /* namespace rse::graphics::window */
|
||||
@@ -0,0 +1,8 @@
|
||||
#version 450
|
||||
|
||||
layout(location = 0) in vec3 fragColor;
|
||||
layout(location = 0) out vec4 outColor;
|
||||
|
||||
void main() {
|
||||
outColor = vec4(fragColor, 1.0);
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
#version 450
|
||||
|
||||
layout(binding = 0) uniform UniformBufferObject {
|
||||
mat4 model;
|
||||
mat4 view;
|
||||
mat4 proj;
|
||||
} ubo;
|
||||
|
||||
layout(location = 0) in vec2 inPosition;
|
||||
layout(location = 1) in vec3 inColor;
|
||||
|
||||
layout(location = 0) out vec3 fragColor;
|
||||
|
||||
void main() {
|
||||
gl_Position = ubo.proj * ubo.view * ubo.model * vec4(inPosition, 0.0, 1.0);
|
||||
fragColor = inColor;
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
/**
|
||||
* @file localeVulkan.h
|
||||
* @author Piotr Krygier (everyonecancode@gmail.com)
|
||||
* @brief Error messages for Vulkan initializers
|
||||
* @version 0.1
|
||||
* @date 2022-05-13
|
||||
*
|
||||
* @copyright Copyright (c) 2022
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
#include <vector>
|
||||
|
||||
#include "localization.hpp"
|
||||
|
||||
|
||||
namespace rse::locale::vulkan
|
||||
{
|
||||
|
||||
#define vulkanErrorMesssages vulkanErrorMesssages_nolocale[SELECTED_LANGUAGE]
|
||||
|
||||
enum Errors
|
||||
{
|
||||
VULKAN_LAYER_NOT_SUPPORTED,
|
||||
VULKAN_EXTENSION_NOT_SUPPORTED,
|
||||
VULKAN_INTANCE_INIT_FAILED,
|
||||
VULKAN_NO_PHYSICAL_DEVICES,
|
||||
VULKAN_NO_SUITABLE_PHYSICAL_DEVICES,
|
||||
VULKAN_QUEUE_NOT_SUPPORTED,
|
||||
VULKAN_FAILED_TO_CREATE_DEVICE,
|
||||
VULKAN_ALLOCATOR_CREATION_FAILED,
|
||||
VULKAN_COMMAND_POOL_CREATION_FAILED,
|
||||
VULKAN_BUFFER_CREATION_FAILED,
|
||||
VULKAN_VERTEX_BUFFER_MAPPING_FAILED,
|
||||
VULKAN_COMMAND_BUFFER_ALLOCATION_FAILED,
|
||||
VULKAN_SURFACE_CREATION_FAILED,
|
||||
VULKAN_SWAPCHAIN_CREATION_FAILED,
|
||||
VULKAN_SWAPCHAIN_IMVIEW_CREATION_FAILED,
|
||||
VULKAN_SHADER_UNABLE_TO_OPEN,
|
||||
VULKAN_SHADER_UNABLE_TO_CREATE_SHADER,
|
||||
VULKAN_PIPELAYOUT_CREATION_FAILED,
|
||||
VULKAN_RENDERPASS_CREATION_FAILED,
|
||||
VULKAN_DESCRIPTOR_POOL_CREATION_FAILED,
|
||||
VULKAN_DESCRIPTOR_SETS_ALLOCATION_FAILED,
|
||||
VULKAN_DESCRIPTORSETLAYOUT_CREATION_FAILED,
|
||||
VULKAN_GRAPHICSPIPELINE_CREATION_FAILED,
|
||||
VULKAN_FRAMEBUFFERS_CREATION_FAILED,
|
||||
VULKAN_RECORD_COMMAND_BUFFER_FAILED,
|
||||
VULKAN_SYNCOBJCTS_CREATION_FAILED,
|
||||
LAST_MESSAGE
|
||||
};
|
||||
|
||||
std::array<std::array<const char*, LAST_MESSAGE>, LAST_LANGUAGE> vulkanErrorMesssages_nolocale = {
|
||||
{/* EN_US */
|
||||
/* VULKAN_LAYER_NOT_SUPPORTED */
|
||||
"Selected layer is not supported: ",
|
||||
/* VULKAN_EXTENSION_NOT_SUPPORTED */
|
||||
"Selected extension is not supported: ",
|
||||
/* VULKAN_INTANCE_INIT_FAILED */
|
||||
"Vulkan instance initialization failed",
|
||||
/* VULKAN_NO_PHYSICAL_DEVICES */
|
||||
"No physical graphical physical devices found in system",
|
||||
/* VULKAN_NO_SUITABLE_PHYSICAL_DEVICES */
|
||||
"No suitable physical device found",
|
||||
/* VULKAN_QUEUE_NOT_SUPPORTED */
|
||||
"Selected physical device does not support required queue capabilities",
|
||||
/* VULKAN_FAILED_TO_CREATE_DEVICE */
|
||||
"Failed to create logical device",
|
||||
/* VULKAN_ALLOCATOR_CREATION_FAILED */
|
||||
"Failed to create Vulkan Memory Allocator",
|
||||
/* VULKAN_COMMAND_POOL_CREATION_FAILED */
|
||||
"Failed to create command pool",
|
||||
/* VULKAN_BUFFER_CREATION_FAILED */
|
||||
"Failed to create a vertex buffer",
|
||||
/* VULKAN_VERTEX_BUFFER_MAPPING_FAILED */
|
||||
"Failed to map vulkan memory buffer",
|
||||
/* VULKAN_COMMAND_BUFFER_ALLOCATION_FAILED */
|
||||
"Failed to allocate command buffers",
|
||||
/* VULKAN_SURFACE_CREATION_FAILED */
|
||||
"Failed to create window surface",
|
||||
/* VULKAN_SWAPCHAIN_CREATION_FAILED */
|
||||
"Failed to create swapchain",
|
||||
/* VULKAN_SWAPCHAIN_IMVIEW_CREATION_FAILED */
|
||||
"Failed to create swapchain image view",
|
||||
/* VULKAN_SHADER_UNABLE_TO_OPEN */
|
||||
"Failed to open a file containing shader code",
|
||||
/* VULKAN_SHADER_UNABLE_TO_CREATE_SHADER */
|
||||
"Failed to create a shader",
|
||||
/* VULKAN_PIPELAYOUT_CREATION_FAILED */
|
||||
"Failed to create pipeline layout",
|
||||
/* VULKAN_RENDERPASS_CREATION_FAILED */
|
||||
"Failed to create render pass",
|
||||
/* VULKAN_DESCRIPTOR_POOL_CREATION_FAILED */
|
||||
"Failed to create descriptor pool",
|
||||
/* VULKAN_DESCRIPTOR_SETS_ALLOCATION_FAILED */
|
||||
"Failed to allocate descriptor sets",
|
||||
/* VULKAN_DESCRIPTORSETLAYOUT_CREATION_FAILED */
|
||||
"Failed to create descriptor set layout",
|
||||
/* VULKAN_GRAPHICSPIPELINE_CREATION_FAILED */
|
||||
"Failed to create graphics pipeline",
|
||||
/* VULKAN_FRAMEBUFFERS_CREATION_FAILED */
|
||||
"Failed to create framebuffer",
|
||||
/* VULKAN_RECORD_COMMAND_BUFFER_FAILED */
|
||||
"Failed to record command buffer. Validate your commands.",
|
||||
/* VULKAN_SYNCOBJCTS_CREATION_FAILED */
|
||||
"Failed to create sync objects"
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace rse::locale::vulkan
|
||||
@@ -0,0 +1,43 @@
|
||||
/**
|
||||
* @file localeWindow.hxx
|
||||
* @author Piotr Krygier (everyonencancode@gmail.com)
|
||||
* @brief Error messages
|
||||
* @version 0.1
|
||||
* @date 2022-02-15
|
||||
*
|
||||
* @copyright Copyright (c) 2022
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
|
||||
#include "localization.hpp"
|
||||
|
||||
|
||||
namespace rse::locale::window
|
||||
{
|
||||
|
||||
#define windowErrorMesssages windowErrorMesssages_nolocale[SELECTED_LANGUAGE]
|
||||
|
||||
enum Errors
|
||||
{
|
||||
WINDOW_GLFW_INIT_FAILED,
|
||||
WINDOW_VULKAN_NOT_SUPPORTED,
|
||||
WINDOW_NOT_CREATED,
|
||||
LAST_MESSAGE
|
||||
};
|
||||
|
||||
std::array<std::array<const char*, LAST_LANGUAGE>, LAST_MESSAGE> windowErrorMesssages_nolocale = {
|
||||
{/* EN_US */
|
||||
/* WINDOW_GLFW_INIT_FAILED */
|
||||
"GLFW init failed!"
|
||||
/* WINDOW_VULKAN_NOT_SUPPORTED */
|
||||
"Unable to load Vulkan"
|
||||
/*WINDOW_NOT_CREATED*/
|
||||
"Window context creation failed"
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace rse::locale::window
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,121 @@
|
||||
/**
|
||||
* @file window.cxx
|
||||
* @author Piotr Krygier (everyonencancode@gmail.com)
|
||||
* @brief
|
||||
* @version 0.1
|
||||
* @date 2022-02-15
|
||||
*
|
||||
* @copyright Copyright (c) 2022
|
||||
*
|
||||
*/
|
||||
|
||||
#include "window.hpp"
|
||||
|
||||
#include "localeWindow.hpp"
|
||||
#include "logger.hpp"
|
||||
#include "vulkanBase.hpp"
|
||||
|
||||
namespace rse::graphics::window
|
||||
{
|
||||
|
||||
using namespace locale::window;
|
||||
|
||||
/* Error codes */
|
||||
typedef enum {
|
||||
WINDOW_ERROR_NO_ERROR = 0U,
|
||||
WINDOW_ERROR_GLFW_INIT_FAILED,
|
||||
WINDOW_ERROR_VULKAN_NOT_LOADED,
|
||||
WINDOW_ERROR_WINDOW_NOT_CREATED
|
||||
} WINDOW_ERROR;
|
||||
|
||||
GLFWwindow *gpWindowHandle = NULL;
|
||||
|
||||
/**
|
||||
* @brief GLFW erro callback
|
||||
*
|
||||
* @param error Error code
|
||||
* @param description Error description
|
||||
*/
|
||||
static void errrorCallback(int error, const char* description)
|
||||
{
|
||||
(void)error;
|
||||
LOGE << "Error: " << description;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Pressed key callback
|
||||
*
|
||||
* @param window Window in which contex the key has been pressed
|
||||
* @param key The keyboard key that was pressed or released
|
||||
* @param scancode The system-specific scancode of the key.
|
||||
* @param action GLFW_PRESS, GLFW_RELEASE or GLFW_REPEAT
|
||||
* @param mods Bit field describing which modifier keys were held down
|
||||
*/
|
||||
static void keyCallback(GLFWwindow* window, int key, int scancode, int action, int mods)
|
||||
{
|
||||
(void)scancode;
|
||||
(void)action;
|
||||
(void)mods;
|
||||
if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) {
|
||||
glfwSetWindowShouldClose(window, GLFW_TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
uint16_t windowInit()
|
||||
{
|
||||
/* Initiliaze GLFW AP */
|
||||
if (GLFW_TRUE != glfwInit())
|
||||
{
|
||||
LOGF << windowErrorMesssages[WINDOW_GLFW_INIT_FAILED];
|
||||
return WINDOW_ERROR_GLFW_INIT_FAILED;
|
||||
}
|
||||
|
||||
|
||||
/* Check for Vulkan support */
|
||||
if (GLFW_FALSE == glfwVulkanSupported()) {
|
||||
LOGF << windowErrorMesssages[WINDOW_VULKAN_NOT_SUPPORTED];
|
||||
return WINDOW_ERROR_VULKAN_NOT_LOADED;
|
||||
}
|
||||
|
||||
/* Set error callback */
|
||||
glfwSetErrorCallback(errrorCallback);
|
||||
|
||||
/* Create window */
|
||||
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
|
||||
|
||||
gpWindowHandle = glfwCreateWindow(640, 480, "RedScarfEngine", NULL, NULL);
|
||||
|
||||
if (NULL == gpWindowHandle) {
|
||||
LOGF << windowErrorMesssages[WINDOW_NOT_CREATED];
|
||||
return WINDOW_ERROR_WINDOW_NOT_CREATED;
|
||||
}
|
||||
|
||||
glfwSetKeyCallback(gpWindowHandle, keyCallback);
|
||||
|
||||
return WINDOW_ERROR_NO_ERROR;
|
||||
}
|
||||
|
||||
uint16_t windowLoop()
|
||||
{
|
||||
while (!glfwWindowShouldClose(gpWindowHandle)) {
|
||||
glfwPollEvents();
|
||||
rse::graphics::vulkanbase::drawFrame();
|
||||
}
|
||||
|
||||
return WINDOW_ERROR_NO_ERROR;
|
||||
}
|
||||
|
||||
void windowTerminate()
|
||||
{
|
||||
glfwDestroyWindow(gpWindowHandle);
|
||||
glfwTerminate();
|
||||
}
|
||||
|
||||
|
||||
GLFWwindow* getWindowHandle()
|
||||
{
|
||||
return gpWindowHandle;
|
||||
}
|
||||
|
||||
} /* namespace rse::graphics::window */
|
||||
Reference in new issue
Block a user