Skip to content

Commit 210db6b

Browse files
committed
Add vulkan support and remove support for opengl. The rendering engine is almost at par with the last commit, just needs to iron out some validation erros. Vulkan is newer, has better toolchains and alows for multithreading. So this rewrites the whole engine to support the above. Drop glfw to my own solution to win32 window creation (linux window creation planned in the future). Add my only library Taskus to ease multithreading in the engine.
1 parent 40fcdbe commit 210db6b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+3149
-886
lines changed

.gitmodules

+9-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
[submodule "libs/glm"]
22
path = libs/glm
33
url = https://github.com/g-truc/glm.git
4-
[submodule "libs/glfw"]
5-
path = libs/glfw
6-
url = https://github.com/glfw/glfw.git
7-
[submodule "libs/glew"]
8-
path = libs/glew
9-
url = https://github.com/Perlmint/glew-cmake.git
4+
[submodule "libs/VulkanMemoryAllocator"]
5+
path = libs/VulkanMemoryAllocator
6+
url = https://github.com/GPUOpen-LibrariesAndSDKs/VulkanMemoryAllocator.git
7+
[submodule "libs/Taskus"]
8+
path = libs/Taskus
9+
url = https://github.com/LuisDuarte1/Taskus
10+
[submodule "libs/WindowsHModular"]
11+
path = libs/WindowsHModular
12+
url = https://github.com/Leandros/WindowsHModular

CMakeLists.txt

+72-49
Original file line numberDiff line numberDiff line change
@@ -1,88 +1,80 @@
1-
cmake_minimum_required(VERSION 2.8)
2-
project(GraphicsEngine)
3-
set (CMAKE_CXX_STANDARD 17)
1+
cmake_minimum_required(VERSION 3.2)
2+
43

54

65
###
76
### Options
87
###
98
# Unsed previous parameters from cache for the sake of dynamism
10-
unset(GRAPHICSENGINE_SUPPORT_GLFW CACHE)
11-
unset(GRAPHICSENGINE_SUPPORT_GLAD CACHE)
12-
unset(GRAPHICSENGINE_SUPPORT_GLEW CACHE)
139
unset(GRAPHICSENGINE_SUPPORT_GLM CACHE)
1410
unset(GRAPHICSENGINE_SUPPORT_OPENSSL CACHE)
11+
unset(GRAPHICSENGINE_SUPPORT_VULKAN CACHE)
12+
unset(GRAPHICSENGINE_SUPPORT_TASKUS CACHE)
13+
unset(GRAPHICSENGINE_USE_VCPKG CACHE)
14+
1515

1616
# Enable desired libs
17-
option(GRAPHICSENGINE_SUPPORT_GLFW "Set ON/OFF to enable/disable GLFW support." ON)
18-
option(GRAPHICSENGINE_SUPPORT_GLAD "Set ON/OFF to enable/disable GLAD support." ON)
19-
option(GRAPHICSENGINE_SUPPORT_GLEW "Set ON/OFF to enable/disable GLEW support." ON)
20-
option(GRAPHICSENGINE_SUPPORT_GLM "Set ON/OFF to enable/disable GLM support." ON)
21-
option(GRAPHICSENGINE_SUPPORT_OPENSSL "Set ON/OFF to enable/disable OpenSLL support." ON)
17+
option(GRAPHICSENGINE_SUPPORT_GLM "Set ON/OFF to enable/disable GLM support" ON)
18+
option(GRAPHICSENGINE_SUPPORT_OPENSSL "Set ON/OFF to enable/disable OpenSSL support." ON)
19+
option(GRAPHICSENGINE_SUPPORT_VULKAN "Set ON/OFF to enable/disable Vulkan support." ON)
20+
option(GRAPHICSENGINE_SUPPORT_TASKUS "Set ON/OFF to enable/disable Taskus support" ON)
21+
option(GRAPHICSENGINE_USE_VCPKG "Use VCPKG in Windows" ON)
2222

23+
if(WIN32)
24+
if(GRAPHICSENGINE_USE_VCPKG)
25+
if(NOT DEFINED CMAKE_TOOLCHAIN_FILE)
26+
#use my own path in cmake_toolchain_file
27+
#you should replace this on your machine or specify it as a argument while configurng
28+
set(CMAKE_TOOLCHAIN_FILE "C:/dev-bin/vcpkg/scripts/buildsystems/vcpkg.cmake")
29+
endif()
30+
endif()
31+
32+
endif()
33+
34+
project(GraphicsEngine)
35+
set (CMAKE_CXX_STANDARD 20)
2336

2437
###
2538
### Initialization
2639
###
2740
# Project parameters
2841
set(PROJ_LINK_LIBS)
2942
set(PROJ_SRC)
30-
find_library( atomic-lib atomic )
31-
list(APPEND PROJ_LINK_LIBS atomic)
43+
set(PROJ_SHADERS)
44+
if(NOT WIN32)
45+
find_library( atomic-lib atomic )
46+
list(APPEND PROJ_LINK_LIBS atomic)
47+
endif()
3248
if(WIN32)
33-
set(CMAKE_RC_COMPILER "windres") #Windows only, for some reason mys2 mingw 64 gets the rc compiler wrong
49+
#set(CMAKE_RC_COMPILER "windres") #Windows only, for some reason mys2 mingw 64 gets the rc compiler wrong
3450
find_package(OpenGL REQUIRED)
3551

3652
list(APPEND PROJ_LINK_LIBS opengl32)
3753
endif(WIN32)
3854

3955
# Add all files/folders under src folder automatically to the project
40-
file(GLOB_RECURSE PROJ_SRC src/*.h src/*.cpp)
41-
56+
file(GLOB_RECURSE PROJ_SRC_CPP src/*.cpp)
57+
file(GLOB_RECURSE PROJ_SRC_H src/*.h)
58+
file(GLOB PROJ_SHADERS src/shaders/*.vert src/shaders/*.frag)
4259

4360
###
4461
### Compiler settings
4562
###
4663

4764

48-
4965
###
50-
### GLFW
66+
### Taskus
5167
###
52-
if(GRAPHICSENGINE_SUPPORT_GLFW)
53-
# Disable internal builds
54-
unset(GLFW_BUILD_EXAMPLES CACHE)
55-
unset(GLFW_BUILD_TESTS CACHE)
56-
unset(GLFW_BUILD_DOCS CACHE)
57-
option(GLFW_BUILD_EXAMPLES "Build the GLFW example programs" OFF)
58-
option(GLFW_BUILD_TESTS "Build the GLFW test programs" OFF)
59-
option(GLFW_BUILD_DOCS "Build the GLFW documentation" OFF)
60-
61-
add_subdirectory(libs/glfw)
62-
list(APPEND PROJ_LINK_LIBS glfw)
63-
endif(GRAPHICSENGINE_SUPPORT_GLFW)
6468

69+
#MINGW IS NOT SUPPORTED BECAUSE OF TASKUS
70+
if(GRAPHICSENGINE_SUPPORT_TASKUS)
71+
add_subdirectory(libs/Taskus)
72+
list(APPEND PROJ_LINK_LIBS Taskus)
73+
endif()
6574

66-
###
67-
### GLAD
68-
###
69-
if(GRAPHICSENGINE_SUPPORT_GLAD)
70-
include_directories(libs/glfw/deps)
71-
endif(GRAPHICSENGINE_SUPPORT_GLAD)
7275

7376

74-
###
75-
### GLEW
76-
###
77-
if(GRAPHICSENGINE_SUPPORT_GLEW)
78-
# Disable internal builds
79-
unset(BUILD_UTILS CACHE)
80-
option(BUILD_UTILS "utilities" OFF)
8177

82-
add_subdirectory(libs/glew/build/cmake)
83-
include_directories(libs/glew/include)
84-
list(APPEND PROJ_LINK_LIBS glew)
85-
endif(GRAPHICSENGINE_SUPPORT_GLEW)
8678

8779
###
8880
### GLM
@@ -96,19 +88,50 @@ endif(GRAPHICSENGINE_SUPPORT_GLM)
9688
### OpenSSL
9789
###
9890
if(GRAPHICSENGINE_SUPPORT_OPENSSL)
99-
find_package(OpenSSL)
91+
find_package(OpenSSL REQUIRED)
10092
list(APPEND PROJ_LINK_LIBS OpenSSL::SSL)
10193
list(APPEND PROJ_LINK_LIBS OpenSSL::Crypto)
10294
endif(GRAPHICSENGINE_SUPPORT_OPENSSL)
10395

96+
###
97+
### Vulkan
98+
###
99+
100+
if(GRAPHICSENGINE_SUPPORT_VULKAN)
101+
if(WIN32)
102+
set(ENV{VULKAN_SDK} "C:\\VulkanSDK\\1.2.198.1") #default installation for vulkansdk in windows
103+
endif(WIN32)
104+
105+
find_package(Vulkan REQUIRED)
106+
list(APPEND PROJ_LINK_LIBS ${Vulkan_LIBRARIES})
107+
include_directories(${Vulkan_INCLUDE_DIRS})
108+
endif(GRAPHICSENGINE_SUPPORT_VULKAN)
109+
110+
111+
112+
113+
### Compile the shaders after building the source
114+
115+
foreach(shader ${PROJ_SHADERS})
116+
set(SHADER_FILENAME)
117+
118+
cmake_path(GET shader FILENAME SHADER_FILENAME)
119+
message(STATUS "Adding shader to compile: "${SHADER_FILENAME})
120+
set(COMMAND_TO_EXECUTE ${Vulkan_GLSLC_EXECUTABLE} ${shader} -o ${SHADER_FILENAME}.spv)
121+
add_custom_target(${SHADER_FILENAME} ALL
122+
COMMAND ${COMMAND_TO_EXECUTE})
123+
124+
endforeach()
104125

105126
###
106127
### Generating the project files
107128
###
108-
add_executable(${PROJECT_NAME} ${PROJ_SRC})
129+
add_executable(${PROJECT_NAME} ${PROJ_SRC_CPP} ${PROJ_SRC_H})
109130

110131

111132
###
112133
### Linking to the project
113134
###
114135
target_link_libraries(${PROJECT_NAME} ${PROJ_LINK_LIBS})
136+
137+

libs/Taskus

Submodule Taskus added at 9e5a728

libs/VulkanMemoryAllocator

Submodule VulkanMemoryAllocator added at ab16036

libs/glew

-1
This file was deleted.

libs/glfw

-1
This file was deleted.

src/camera/camera.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33

44
#include <iostream>
55
#include <atomic>
6+
#define GLM_FORCE_DEPTH_ZERO_TO_ONE
7+
#define GLM_FORCE_LEFT_HANDED
68
#include <glm/glm.hpp>
79
#include <glm/gtc/matrix_transform.hpp>
810

9-
using namespace glm;
1011

1112
class Camera{
1213
public:
@@ -17,6 +18,8 @@ class Camera{
1718
inline void ChangeWorldPosition(glm::vec3 newposition){world_position.store(newposition); };
1819
inline glm::vec3 GetWorldPosistion(){return world_position.load();};
1920
bool initialized = false;
21+
//it is controllable when it can be changed because of player input
22+
//this should be disabled for instance for cutscnes
2023
std::atomic<bool> controllable;
2124
private:
2225
std::atomic<glm::vec3> world_position;

src/gamelogic/gamelogic.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
#include <iostream>
1+
/*#include <iostream>
22
#include "gamelogic.h"
33
44
GameLogic::GameLogic(OpenGLRenderer* renderer){
55
/* We already assume that the renderer is already initialized and ready to render
6-
*/
6+
77
main_camera = new Camera(glm::vec3(4,3,3), vec3(0,0,0));
88
input = new InputSystem();
99
current_renderer = renderer; //this doesnt need to be atomic by default because it's only suppose to write once
@@ -95,4 +95,5 @@ void GameLogic::GameLoop(){ //GameLoop tries to run at a fixed rate (120 tps, ca
9595
break;
9696
}
9797
return;
98-
}
98+
}
99+
*/

src/gamelogic/gamelogic.h

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
#ifndef GAMELOGIC_H
1+
/*#ifndef GAMELOGIC_H
22
#define GAMELOGIC_H
33
#include <iostream>
44
#include <vector>
5-
#include <time.h> /* time */
5+
#include <time.h>
66
#include <random>
77
#include <thread>
88
#include <chrono>
@@ -32,4 +32,5 @@ class GameLogic{
3232
3333
};
3434
35-
#endif
35+
#endif
36+
*/

src/input/input.cpp

+5-13
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,14 @@
11
#include "input.h"
22

33
InputSystem::InputSystem(){
4-
for(int i = 0; i < NUM_OF_SCANCODES; i++){
5-
is_pressed[i] = false;
6-
}
74
}
85

96
void InputSystem::ProcessInputMessage(InputMessage m){
10-
assert(m.scancode < NUM_OF_SCANCODES);
11-
if(m.action == 0){
12-
is_pressed[m.scancode] = false;
13-
}
14-
if(m.action == 1){
15-
is_pressed[m.scancode] = true;
16-
}
7+
keyboardMap.insert_or_assign(m.keycode,m.keyDown);
178
}
189

19-
bool InputSystem::GetIfKeyIsPressed(int scancode){
20-
assert(scancode < NUM_OF_SCANCODES);
21-
return is_pressed[scancode];
10+
bool InputSystem::GetIfKeyIsPressed(char inputchar){
11+
auto r = keyboardMap.find(inputchar);
12+
if(r == keyboardMap.end()) assert(false); //crash if not found
13+
return (*r).second;
2214
}

src/input/input.h

+9-3
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,25 @@
33

44
#include <iostream>
55
#include <cassert>
6-
#include "../thread_communication/threadcommunication.h"
6+
#include <map>
7+
78

89
#define NUM_OF_SCANCODES 240
910

1011

12+
struct InputMessage{
13+
char keycode;
14+
bool keyDown; //useful for representing if key is down or up
15+
//TODO: mouse input
16+
};
1117

1218
class InputSystem{
1319
public:
1420
InputSystem();
1521
void ProcessInputMessage(InputMessage m);
16-
bool GetIfKeyIsPressed(int scancode);
22+
bool GetIfKeyIsPressed(char wchar);
1723
private:
18-
bool is_pressed[NUM_OF_SCANCODES];
24+
std::map<char, bool> keyboardMap;
1925

2026
};
2127

src/light/light.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#ifndef LIGHT_H
1+
/*#ifndef LIGHT_H
22
#define LIGHT_H
33
44
#include <iostream>
@@ -48,4 +48,5 @@ class Light: public WorldObject{
4848
4949
};
5050
51-
#endif
51+
#endif
52+
*/

0 commit comments

Comments
 (0)