Skip to content

Commit 7048a6b

Browse files
committed
Replace OpenGL with Vulkan and update automatic build script
1 parent efcfb5b commit 7048a6b

File tree

11 files changed

+1201
-33123
lines changed

11 files changed

+1201
-33123
lines changed

.github/workflows/build.yml

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ jobs:
2727
build-essential \
2828
cmake \
2929
git \
30-
libgl1-mesa-dev \
30+
libvulkan-dev \
31+
vulkan-tools \
32+
glslang-tools \
3133
libx11-dev \
3234
libxrandr-dev \
3335
libxi-dev \
@@ -46,17 +48,16 @@ jobs:
4648
cd build
4749
cmake --build . --config Release
4850
49-
- name: Zip Linux executable only
51+
- name: Zip Linux executable and shaders
5052
run: |
5153
cd build
52-
# Replace 'game' with your actual executable name
5354
if [ -f game ]; then
5455
zip -j ../linux-x86_64.zip game
56+
zip -r ../linux-x86_64.zip shaders/
5557
else
5658
echo "Executable not found!"
5759
exit 1
5860
fi
59-
cd ..
6061
6162
- name: Upload Linux artifact
6263
uses: actions/upload-artifact@v4
@@ -73,6 +74,12 @@ jobs:
7374
with:
7475
submodules: recursive
7576

77+
- name: Install Vulkan SDK
78+
uses: humbletim/install-vulkan-sdk@v1.1.1
79+
with:
80+
version: latest
81+
cache: true
82+
7683
- name: Configure CMake (Windows)
7784
run: |
7885
mkdir build
@@ -84,12 +91,15 @@ jobs:
8491
cd build
8592
cmake --build . --config Release
8693
87-
- name: Zip Windows executable only
94+
- name: Zip Windows executable and shaders
8895
run: |
89-
# Adjust path if using multi-config generator
9096
$exe = "build\Release\game.exe"
97+
$shaders = "build\Release\shaders"
9198
if (Test-Path $exe) {
9299
Compress-Archive -Path $exe -DestinationPath windows-x86_64.zip -Force
100+
if (Test-Path $shaders) {
101+
Compress-Archive -Path $shaders -DestinationPath windows-x86_64.zip -Update
102+
}
93103
} else {
94104
Write-Error "Executable not found at $exe"
95105
exit 1
@@ -109,6 +119,8 @@ jobs:
109119
steps:
110120
- name: Checkout code
111121
uses: actions/checkout@v4
122+
with:
123+
fetch-depth: 0 # needed to see all tags
112124

113125
- name: Download Linux artifact
114126
uses: actions/download-artifact@v4
@@ -125,7 +137,7 @@ jobs:
125137
- name: Create tag
126138
id: tag
127139
env:
128-
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
140+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
129141
run: |
130142
git config user.name "github-actions"
131143
git config user.email "actions@github.com"
@@ -148,10 +160,9 @@ jobs:
148160
git tag $new_tag
149161
git push https://x-access-token:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git $new_tag
150162
echo "tag=$new_tag" >> $GITHUB_OUTPUT
151-
sleep 5
152163
153164
- name: Create GitHub Release with artifacts
154-
uses: softprops/action-gh-release@v1
165+
uses: softprops/action-gh-release@v2
155166
with:
156167
tag_name: ${{ steps.tag.outputs.tag }}
157168
name: Release ${{ steps.tag.outputs.tag }}
@@ -160,4 +171,4 @@ jobs:
160171
linux-x86_64.zip
161172
windows-x86_64.zip
162173
env:
163-
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
174+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

CMakeLists.txt

Lines changed: 59 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,77 @@ if(POLICY CMP0072)
44
cmake_policy(SET CMP0072 NEW)
55
endif()
66

7-
# Project renamed to 'game'
87
project(game VERSION 1.0)
98

109
set(CMAKE_CXX_STANDARD 23)
1110
set(CMAKE_CXX_STANDARD_REQUIRED True)
1211

13-
set(GLFW_BUILD_WAYLAND OFF CACHE BOOL "Disable Wayland backend in GLFW")
14-
set(GLFW_BUILD_X11 ON CACHE BOOL "Enable X11 backend in GLFW")
12+
# ── GLFW (cross-platform, disable platform backends we don't need) ──────────
13+
if(WIN32)
14+
set(GLFW_BUILD_WIN32 ON CACHE BOOL "" FORCE)
15+
set(GLFW_BUILD_WAYLAND OFF CACHE BOOL "" FORCE)
16+
set(GLFW_BUILD_X11 OFF CACHE BOOL "" FORCE)
17+
elseif(APPLE)
18+
set(GLFW_BUILD_WAYLAND OFF CACHE BOOL "" FORCE)
19+
set(GLFW_BUILD_X11 OFF CACHE BOOL "" FORCE)
20+
else() # Linux
21+
set(GLFW_BUILD_WAYLAND OFF CACHE BOOL "" FORCE)
22+
set(GLFW_BUILD_X11 ON CACHE BOOL "" FORCE)
23+
endif()
1524

1625
add_subdirectory(vendors/glfw)
17-
add_subdirectory(vendors/cglm)
26+
add_subdirectory(vendors/cglm)
27+
28+
# ── Vulkan ───────────────────────────────────────────────────────────────────
29+
find_package(Vulkan REQUIRED)
30+
31+
# ── Shader compilation ───────────────────────────────────────────────────────
32+
# Requires glslc (ships with the Vulkan SDK) to be on PATH
33+
set(SHADER_DIR ${CMAKE_SOURCE_DIR}/src/shaders)
34+
set(SHADER_OUT ${CMAKE_BINARY_DIR}/shaders)
35+
file(MAKE_DIRECTORY ${SHADER_OUT})
1836

19-
find_package(OpenGL REQUIRED)
37+
set(VERT_SHADER ${SHADER_DIR}/vert.vert)
38+
set(FRAG_SHADER ${SHADER_DIR}/frag.frag)
39+
set(VERT_SPV ${SHADER_OUT}/vert.spv)
40+
set(FRAG_SPV ${SHADER_OUT}/frag.spv)
41+
42+
add_custom_command(
43+
OUTPUT ${VERT_SPV}
44+
COMMAND Vulkan::glslc ${VERT_SHADER} -o ${VERT_SPV}
45+
DEPENDS ${VERT_SHADER}
46+
COMMENT "Compiling vertex shader"
47+
)
48+
add_custom_command(
49+
OUTPUT ${FRAG_SPV}
50+
COMMAND Vulkan::glslc ${FRAG_SHADER} -o ${FRAG_SPV}
51+
DEPENDS ${FRAG_SHADER}
52+
COMMENT "Compiling fragment shader"
53+
)
54+
add_custom_target(shaders ALL DEPENDS ${VERT_SPV} ${FRAG_SPV})
2055

21-
# Executable renamed to 'game'
56+
# ── Executable ───────────────────────────────────────────────────────────────
2257
add_executable(game
2358
src/main.cpp
24-
src/glad.c
2559
)
2660

27-
target_include_directories(game PRIVATE include)
61+
add_dependencies(game shaders)
62+
63+
target_include_directories(game PRIVATE
64+
include
65+
${Vulkan_INCLUDE_DIRS}
66+
)
67+
68+
target_link_libraries(game PRIVATE
69+
glfw
70+
Vulkan::Vulkan
71+
cglm
72+
)
2873

29-
target_link_libraries(game
30-
PRIVATE glfw OpenGL::GL cglm
74+
# Copy compiled shaders next to the executable after build
75+
add_custom_command(TARGET game POST_BUILD
76+
COMMAND ${CMAKE_COMMAND} -E copy_directory
77+
${SHADER_OUT}
78+
$<TARGET_FILE_DIR:game>/shaders
79+
COMMENT "Copying shaders to output directory"
3180
)

0 commit comments

Comments
 (0)