Skip to content

Commit 18b59ca

Browse files
committed
testing shadercross and workflows (closes #28)
1 parent 9bf9390 commit 18b59ca

61 files changed

Lines changed: 1457 additions & 49 deletions

Some content is hidden

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

.github/workflows/build.yml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: Build
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
jobs:
8+
build:
9+
strategy:
10+
matrix:
11+
os:
12+
- ubuntu-latest
13+
- windows-2025
14+
- macos-latest
15+
runs-on: ${{ matrix.os }}
16+
17+
steps:
18+
- name: Checkout
19+
uses: actions/checkout@v4
20+
with:
21+
submodules: recursive
22+
23+
- name: Dependencies
24+
if: runner.os == 'Linux'
25+
run: |
26+
sudo apt-get update
27+
sudo apt-get install -y \
28+
build-essential \
29+
git \
30+
make \
31+
pkg-config \
32+
cmake \
33+
ninja-build \
34+
gnome-desktop-testing \
35+
libasound2-dev \
36+
libpulse-dev \
37+
libaudio-dev \
38+
libfribidi-dev \
39+
libjack-dev \
40+
libsndio-dev \
41+
libx11-dev \
42+
libxext-dev \
43+
libxrandr-dev \
44+
libxcursor-dev \
45+
libxfixes-dev \
46+
libxi-dev \
47+
libxss-dev \
48+
libxtst-dev \
49+
libxkbcommon-dev \
50+
libdrm-dev \
51+
libgbm-dev \
52+
libgl1-mesa-dev \
53+
libgles2-mesa-dev \
54+
libegl1-mesa-dev \
55+
libdbus-1-dev \
56+
libibus-1.0-dev \
57+
libudev-dev \
58+
libthai-dev
59+
60+
- name: Configure
61+
run: cmake -S . -B build
62+
63+
- name: Build
64+
run: cmake --build build

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
*.sqlite3
12
build

.vscode/launch.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66
"type": "cppvsdbg",
77
"request": "launch",
88
"program": "${workspaceFolder}/build/bin/blocks.exe",
9-
"cwd": "${workspaceFolder}/build/bin",
9+
"cwd": "${workspaceFolder}",
1010
"preLaunchTask": "CMake: build",
1111
},
1212
{
1313
"name": "linux",
1414
"type": "cppdbg",
1515
"request": "launch",
1616
"program": "${workspaceFolder}/build/bin/blocks",
17-
"cwd": "${workspaceFolder}/build/bin",
17+
"cwd": "${workspaceFolder}",
1818
"preLaunchTask": "CMake: build",
1919
},
2020
]

CMakeLists.txt

Lines changed: 51 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,26 +27,62 @@ add_executable(blocks WIN32
2727
src/world.c
2828
)
2929
target_link_libraries(blocks PUBLIC SDL3::SDL3)
30-
if(UNIX)
31-
target_link_libraries(blocks PUBLIC m)
32-
endif()
3330
target_include_directories(blocks PUBLIC lib/sqlite3)
3431
target_include_directories(blocks PUBLIC lib/stb)
3532
set_target_properties(blocks PROPERTIES C_STANDARD 11)
3633

34+
find_package(Vulkan)
35+
if(MSVC AND ${Vulkan_glslc_FOUND})
36+
set(BUILD_SHADERS TRUE)
37+
else()
38+
message("Won't build shaders since dependencies are missing")
39+
endif()
3740
function(shader FILE)
38-
set(SOURCE shaders/${FILE})
39-
set(OUTPUT ${BINARY_DIR}/${FILE})
40-
add_custom_command(
41-
OUTPUT ${OUTPUT}
42-
COMMAND glslc ${SOURCE} -o ${OUTPUT} -I src
43-
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
44-
DEPENDS ${SOURCE} shaders/helpers.glsl src/config.h
45-
COMMENT ${SOURCE}
46-
)
47-
string(REPLACE . _ NAME ${FILE})
48-
add_custom_target(${NAME} DEPENDS ${OUTPUT})
49-
add_dependencies(blocks ${NAME})
41+
set(GLSL ${CMAKE_SOURCE_DIR}/shaders/${FILE})
42+
set(SPV ${CMAKE_SOURCE_DIR}/shaders/bin/${FILE}.spv)
43+
set(DXIL ${CMAKE_SOURCE_DIR}/shaders/bin/${FILE}.dxil)
44+
set(MSL ${CMAKE_SOURCE_DIR}/shaders/bin/${FILE}.msl)
45+
set(JSON ${CMAKE_SOURCE_DIR}/shaders/bin/${FILE}.json)
46+
function(compile PROGRAM SOURCE OUTPUT)
47+
add_custom_command(
48+
OUTPUT ${OUTPUT}
49+
COMMAND ${PROGRAM} ${SOURCE} -o ${OUTPUT} -I src
50+
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
51+
DEPENDS ${SOURCE} shaders/helpers.glsl src/config.h
52+
COMMENT "${SOURCE} -> ${OUTPUT}"
53+
)
54+
get_filename_component(NAME ${OUTPUT} NAME)
55+
string(REPLACE . _ NAME ${NAME})
56+
set(NAME compile_${NAME})
57+
add_custom_target(${NAME} DEPENDS ${OUTPUT})
58+
add_dependencies(blocks ${NAME})
59+
endfunction()
60+
if(${BUILD_SHADERS})
61+
set(SHADERCROSS lib/SDL_shadercross/msvc/shadercross.exe)
62+
compile(${Vulkan_GLSLC_EXECUTABLE} ${GLSL} ${SPV})
63+
compile(${SHADERCROSS} ${SPV} ${MSL})
64+
compile(${SHADERCROSS} ${SPV} ${JSON})
65+
endif()
66+
function(package OUTPUT)
67+
get_filename_component(NAME ${OUTPUT} NAME)
68+
set(BINARY ${BINARY_DIR}/${NAME})
69+
add_custom_command(
70+
OUTPUT ${BINARY}
71+
COMMAND ${CMAKE_COMMAND} -E copy ${OUTPUT} ${BINARY}
72+
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
73+
DEPENDS ${OUTPUT}
74+
COMMENT "${OUTPUT} -> ${BINARY}"
75+
)
76+
string(REPLACE . _ NAME ${NAME})
77+
set(NAME package_${NAME})
78+
add_custom_target(${NAME} DEPENDS ${BINARY})
79+
add_dependencies(blocks ${NAME})
80+
endfunction()
81+
if(NOT APPLE)
82+
package(${SPV})
83+
else()
84+
package(${MSL})
85+
endif()
5086
endfunction()
5187
shader(composite.frag)
5288
shader(fullscreen.vert)

README.md

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,14 @@ Tiny Minecraft clone in C and GLSL using the new SDL3 GPU API
1212
- Transparency (limited)
1313
- Deferred rendering
1414
- Directional shadows
15-
- SSAO (ish)
15+
- SSAO
1616
- Water depth shading
1717
- Persistent worlds
1818

1919
### Building
2020

2121
#### Windows
2222

23-
Install the [Vulkan SDK](https://www.lunarg.com/vulkan-sdk/) for glslc
24-
2523
```bash
2624
git clone https://github.com/jsoulier/blocks --recurse-submodules
2725
cd blocks
@@ -35,10 +33,6 @@ cd bin
3533

3634
#### Linux
3735

38-
```bash
39-
sudo apt install glslc
40-
```
41-
4236
```bash
4337
git clone https://github.com/jsoulier/blocks --recurse-submodules
4438
cd blocks

lib/SDL_shadercross/msvc/SDL3.dll

5.49 MB
Binary file not shown.
29 KB
Binary file not shown.
17.2 MB
Binary file not shown.

lib/SDL_shadercross/msvc/dxil.dll

1.44 MB
Binary file not shown.
19 KB
Binary file not shown.

0 commit comments

Comments
 (0)