CONGE-2 : (WIP) adding the basic structure for the engine
This commit is contained in:
parent
85746cfadf
commit
dccbcf3cca
@ -1,19 +1,35 @@
|
|||||||
cmake_minimum_required(VERSION 3.26)
|
cmake_minimum_required(VERSION 3.26)
|
||||||
|
|
||||||
|
|
||||||
set(CMAKE_CXX_STANDARD 20)
|
set(CMAKE_CXX_STANDARD 20)
|
||||||
|
|
||||||
project(ConjureEngine)
|
project(ConjureEngine)
|
||||||
|
|
||||||
|
set(HEADER_FILES
|
||||||
|
src/ConjureEngine/Application.h
|
||||||
|
src/ConjureEngine/Engine.h
|
||||||
|
src/ConjureEngine/Window.h
|
||||||
|
)
|
||||||
|
|
||||||
|
set(SOURCES_FILES
|
||||||
|
src/ConjureEngine/Application.cpp
|
||||||
|
src/ConjureEngine/Engine.cpp
|
||||||
|
src/ConjureEngine/Window.cpp
|
||||||
|
)
|
||||||
|
|
||||||
find_package(glm REQUIRED)
|
find_package(glm REQUIRED)
|
||||||
find_package(SDL2 REQUIRED)
|
find_package(SDL2 REQUIRED)
|
||||||
find_package(Vulkan REQUIRED)
|
find_package(Vulkan REQUIRED)
|
||||||
|
|
||||||
add_library(${PROJECT_NAME} STATIC src/ConjureEngine/ConjureEngine.h src/ConjureEngine/ConjureEngine.cpp)
|
add_library(${PROJECT_NAME} STATIC ${HEADER_FILES} ${SOURCES_FILES})
|
||||||
|
|
||||||
# Specify include directories
|
# Specify include directories
|
||||||
target_include_directories(${PROJECT_NAME} PUBLIC include)
|
target_include_directories(${PROJECT_NAME} PUBLIC include)
|
||||||
target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_BINARY_DIR}/include)
|
target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_BINARY_DIR}/include)
|
||||||
|
|
||||||
target_link_libraries(${PROJECT_NAME} SDL2::SDL2 glm::glm)
|
target_link_libraries(${PROJECT_NAME} SDL2::SDL2 glm::glm Vulkan::Vulkan)
|
||||||
|
|
||||||
|
target_precompile_headers(
|
||||||
|
${PROJECT_NAME}
|
||||||
|
PUBLIC
|
||||||
|
src/ConjureEngine/PCH.h
|
||||||
|
)
|
||||||
8
ConjureEngine/src/ConjureEngine/Application.cpp
Normal file
8
ConjureEngine/src/ConjureEngine/Application.cpp
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
//
|
||||||
|
// Created by calap on 11/21/2024.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "Application.h"
|
||||||
|
|
||||||
|
namespace ConjureEngine {
|
||||||
|
} // ConjureEngine
|
||||||
13
ConjureEngine/src/ConjureEngine/Application.h
Normal file
13
ConjureEngine/src/ConjureEngine/Application.h
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
//
|
||||||
|
// Created by calap on 11/21/2024.
|
||||||
|
//
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
namespace ConjureEngine {
|
||||||
|
|
||||||
|
class Application {
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
} // ConjureEngine
|
||||||
@ -1,10 +0,0 @@
|
|||||||
//
|
|
||||||
// Created by Jimmy Tremblay-bernier on 2024-11-14.
|
|
||||||
//
|
|
||||||
#include "ConjureEngine.h"
|
|
||||||
#include <cstdio>
|
|
||||||
|
|
||||||
void ConjureEngine::SayHello()
|
|
||||||
{
|
|
||||||
printf("Hello World\n");
|
|
||||||
}
|
|
||||||
4
ConjureEngine/src/ConjureEngine/Engine.cpp
Normal file
4
ConjureEngine/src/ConjureEngine/Engine.cpp
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
//
|
||||||
|
// Created by Jimmy Tremblay-bernier on 2024-11-14.
|
||||||
|
//
|
||||||
|
#include "Engine.h"
|
||||||
@ -3,6 +3,5 @@
|
|||||||
#include "glm/glm.hpp"
|
#include "glm/glm.hpp"
|
||||||
|
|
||||||
namespace ConjureEngine {
|
namespace ConjureEngine {
|
||||||
void SayHello();
|
|
||||||
glm::vec3& Forward();
|
|
||||||
}
|
}
|
||||||
21
ConjureEngine/src/ConjureEngine/PCH.h
Normal file
21
ConjureEngine/src/ConjureEngine/PCH.h
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
//
|
||||||
|
// Created by calap on 11/21/2024.
|
||||||
|
//
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
// STANDARD LIBS
|
||||||
|
#include <memory>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
// GLM
|
||||||
|
#include "glm/glm.hpp"
|
||||||
|
|
||||||
|
// SDL2
|
||||||
|
#include "SDL2/SDL.h"
|
||||||
|
#include "SDL2/SDL_vulkan.h"
|
||||||
|
#include "SDL2/SDL_video.h"
|
||||||
|
|
||||||
|
// VULKAN
|
||||||
|
#include "Vulkan/vulkan.h"
|
||||||
119
ConjureEngine/src/ConjureEngine/Window.cpp
Normal file
119
ConjureEngine/src/ConjureEngine/Window.cpp
Normal file
@ -0,0 +1,119 @@
|
|||||||
|
//
|
||||||
|
// Created by calap on 11/21/2024.
|
||||||
|
//
|
||||||
|
#include "Window.h"
|
||||||
|
|
||||||
|
namespace ConjureEngine {
|
||||||
|
|
||||||
|
Window::Window(const WindowInfo& windowInfo)
|
||||||
|
{
|
||||||
|
SDL_Init(SDL_INIT_VIDEO);
|
||||||
|
SDL_Vulkan_LoadLibrary(nullptr);
|
||||||
|
m_window = std::shared_ptr<SDL_Window>(
|
||||||
|
SDL_CreateWindow(windowInfo.title.c_str(), 0, 0, windowInfo.width, windowInfo.height, SDL_WINDOW_SHOWN |SDL_WINDOW_VULKAN)
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
SDL_Vulkan_GetInstanceExtensions(m_window.get(), &m_extensionCount, nullptr);
|
||||||
|
m_extensionNames = new const char *[m_extensionCount];
|
||||||
|
SDL_Vulkan_GetInstanceExtensions(m_window.get(), &m_extensionCount, m_extensionNames);
|
||||||
|
const VkInstanceCreateInfo instInfo = {
|
||||||
|
VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO, // sType
|
||||||
|
nullptr, // pNext
|
||||||
|
0, // flags
|
||||||
|
nullptr, // pApplicationInfo
|
||||||
|
0, // enabledLayerCount
|
||||||
|
nullptr, // ppEnabledLayerNames
|
||||||
|
m_extensionCount, // enabledExtensionCount
|
||||||
|
m_extensionNames, // ppEnabledExtensionNames
|
||||||
|
};
|
||||||
|
vkCreateInstance(&instInfo, nullptr, &m_vkInst);
|
||||||
|
|
||||||
|
vkEnumeratePhysicalDevices(m_vkInst, &m_physicalDeviceCount, nullptr);
|
||||||
|
m_physicalDevices = std::vector<VkPhysicalDevice>(m_physicalDeviceCount);
|
||||||
|
|
||||||
|
vkEnumeratePhysicalDevices(m_vkInst, &m_physicalDeviceCount, m_physicalDevices.data());
|
||||||
|
|
||||||
|
// TODO - I'M AT THIS POINT
|
||||||
|
VkPhysicalDevice physicalDevice = m_physicalDevices[0];
|
||||||
|
|
||||||
|
uint32_t queueFamilyCount;
|
||||||
|
vkGetPhysicalDeviceQueueFamilyProperties(physicalDevice, &queueFamilyCount, nullptr);
|
||||||
|
std::vector<VkQueueFamilyProperties> queueFamilies(queueFamilyCount);
|
||||||
|
vkGetPhysicalDeviceQueueFamilyProperties(physicalDevice, &queueFamilyCount, queueFamilies.data());
|
||||||
|
|
||||||
|
VkSurfaceKHR surface;
|
||||||
|
SDL_Vulkan_CreateSurface(window, vkInst, &surface);
|
||||||
|
|
||||||
|
uint32_t graphicsQueueIndex = UINT32_MAX;
|
||||||
|
uint32_t presentQueueIndex = UINT32_MAX;
|
||||||
|
VkBool32 support;
|
||||||
|
uint32_t i = 0;
|
||||||
|
for (VkQueueFamilyProperties queueFamily : queueFamilies) {
|
||||||
|
if (graphicsQueueIndex == UINT32_MAX && queueFamily.queueCount > 0 && queueFamily.queueFlags & VK_QUEUE_GRAPHICS_BIT)
|
||||||
|
graphicsQueueIndex = i;
|
||||||
|
if (presentQueueIndex == UINT32_MAX) {
|
||||||
|
vkGetPhysicalDeviceSurfaceSupportKHR(physicalDevice, i, surface, &support);
|
||||||
|
if(support)
|
||||||
|
presentQueueIndex = i;
|
||||||
|
}
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
|
||||||
|
float queuePriority = 1.0f;
|
||||||
|
VkDeviceQueueCreateInfo queueInfo = {
|
||||||
|
VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO, // sType
|
||||||
|
nullptr, // pNext
|
||||||
|
0, // flags
|
||||||
|
graphicsQueueIndex, // graphicsQueueIndex
|
||||||
|
1, // queueCount
|
||||||
|
&queuePriority, // pQueuePriorities
|
||||||
|
};
|
||||||
|
|
||||||
|
VkPhysicalDeviceFeatures deviceFeatures = {};
|
||||||
|
const char* deviceExtensionNames[] = {VK_KHR_SWAPCHAIN_EXTENSION_NAME};
|
||||||
|
VkDeviceCreateInfo createInfo = {
|
||||||
|
VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO, // sType
|
||||||
|
nullptr, // pNext
|
||||||
|
0, // flags
|
||||||
|
1, // queueCreateInfoCount
|
||||||
|
&queueInfo, // pQueueCreateInfos
|
||||||
|
0, // enabledLayerCount
|
||||||
|
nullptr, // ppEnabledLayerNames
|
||||||
|
1, // enabledExtensionCount
|
||||||
|
deviceExtensionNames, // ppEnabledExtensionNames
|
||||||
|
&deviceFeatures, // pEnabledFeatures
|
||||||
|
};
|
||||||
|
VkDevice device;
|
||||||
|
vkCreateDevice(physicalDevice, &createInfo, nullptr, &device);
|
||||||
|
|
||||||
|
VkQueue graphicsQueue;
|
||||||
|
vkGetDeviceQueue(device, graphicsQueueIndex, 0, &graphicsQueue);
|
||||||
|
|
||||||
|
VkQueue presentQueue;
|
||||||
|
vkGetDeviceQueue(device, presentQueueIndex, 0, &presentQueue);
|
||||||
|
|
||||||
|
SDL_Log("Initialized with errors: %s", SDL_GetError());
|
||||||
|
|
||||||
|
bool running = true;
|
||||||
|
while(running) {
|
||||||
|
SDL_Event windowEvent;
|
||||||
|
while(SDL_PollEvent(&windowEvent))
|
||||||
|
if(windowEvent.type == SDL_QUIT) {
|
||||||
|
running = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
vkDestroyDevice(device, nullptr);
|
||||||
|
vkDestroyInstance(vkInst, nullptr);
|
||||||
|
SDL_DestroyWindow(window);
|
||||||
|
SDL_Vulkan_UnloadLibrary();
|
||||||
|
SDL_Quit();
|
||||||
|
|
||||||
|
SDL_Log("Cleaned up with errors: %s", SDL_GetError());
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // ConjureEngine
|
||||||
29
ConjureEngine/src/ConjureEngine/Window.h
Normal file
29
ConjureEngine/src/ConjureEngine/Window.h
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
//
|
||||||
|
// Created by calap on 11/21/2024.
|
||||||
|
//
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
namespace ConjureEngine {
|
||||||
|
|
||||||
|
struct WindowInfo {
|
||||||
|
std::string title;
|
||||||
|
int width;
|
||||||
|
int height;
|
||||||
|
};
|
||||||
|
|
||||||
|
class Window {
|
||||||
|
public:
|
||||||
|
explicit Window(const WindowInfo& windowInfo);
|
||||||
|
private:
|
||||||
|
public:
|
||||||
|
private:
|
||||||
|
std::shared_ptr<SDL_Window> m_window;
|
||||||
|
uint32_t m_extensionCount{0};
|
||||||
|
const char** m_extensionNames{nullptr};
|
||||||
|
VkInstance m_vkInst;
|
||||||
|
uint32_t m_physicalDeviceCount{0};
|
||||||
|
std::vector<VkPhysicalDevice> m_physicalDevices;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // ConjureEngine
|
||||||
@ -1,6 +1,5 @@
|
|||||||
#include "ConjureEngine/ConjureEngine.h"
|
#include "ConjureEngine/Engine.h"
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
ConjureEngine::SayHello();
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user