Skip to content

Commit

Permalink
Merge branch 'refactor-separate-app-from-engine'
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucodivo committed Feb 16, 2024
2 parents 64dbbc7 + 303da41 commit b790167
Show file tree
Hide file tree
Showing 21 changed files with 1,303 additions and 527 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ CMakeSettings.json
cmake*/
Asset-Baker-Cache.asb
scratch.txt
imgui.ini
imgui.ini
vkstudy.ini
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@ foreach(GLSL ${GLSL_SOURCE_FILES})
endforeach(GLSL)

add_custom_target(
Shaders
build_shaders
DEPENDS ${SPIRV_BINARY_FILES}
)
18 changes: 15 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,33 @@ Project for studying Vulkan and a general rendering engine playground for myself
executable also partitions the information about external file formats away from the rest of the project. Removing
dependencies from `vk_study`.
- External formats include: .jpg, .png, .tga, .gltf, .glb, .obj
- `build_shaders` is a simple configuration for validating GLSL shaders and converting them to SPIR-V.
- Some source files are compiled separately as static libraries:
- `assetlib`: This library contains the definitions of the custom asset file formats. It defines how the structure
of the custom assets, implements saving/compressing and loading/decompressing. This library is the communication line
between `asset_baker` and `vk_study`.
- `noop_math`: Custom math library originating from [NoopScenes](https://github.com/Lucodivo/NoopScenes) project
- `sdl2_DIR` environment variable in third_party/CMakeLists.txt must be set to the SDL2 library path
- Ex: "C:/developer/dependencies/libs/SDL2-2.0.18"
- `sdl2_DIR` environment variable in third_party/CMakeLists.txt must be set to the SDL2 library path. This is the path
that is the parent directory to both the include and lib directories.
- Hardcoding the path in the CMakeLists.txt file is an acceptable option. However, the variable is also cached in the
Cmake build directory, in a file titled 'CMakeCache.txt' and can be manually edited there with no changes to the
project. CMake GUI should also present one with the option of adjusting cache variables.
- Example of SDL path: "C:/developer/dependencies/libs/SDL2-2.0.18"

### Running (⚠IN PROGRESS⚠)
- Ensure that the working directory when running `vk_study` or `vk_baker` is the root directory of the project.
- `vk_baker` takes two command line string arguments.
- Argument 1: Directory of the assets
- Argument 2: Directory of include file metadata output
- Ex: `asset_baker.exe assets/ assets_metadata/`
- `SDL2.dll` must be placed in same directory as `vk_study.exe`.
- `SDL2.dll` must be accessible to Windows when running as `vk_study.exe`.
- This can be accomplished by ensuring that a directory containing `SDL2.dll` is appended to the PATH environment variables.
- Note: If an environment variable is edited, whatever process being used to build this project (ex: CLion) must be restarted to access the updated environment variables.
- You have the option of placing `SDL2.dll` in the same directory as the `vk_study.exe`
- In my experience, this can lead to annoyances when cleaning your project and rebuilding everything from scratch.
- Errors you might see if `SDL2.dll` cannot be found:
- "The code execution cannot proceed because SDL2.dll was not found. Reinstalling the program may fix this problem."
- "Process finished with exit code -1073741515 (0xC0000135)"

### Example Render

Expand Down
5 changes: 2 additions & 3 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# vk_study
add_executable(vk_study vk_study.cpp)
target_include_directories(vk_study PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}")
set(LIBS vkbootstrap vma imgui spirv_reflect assetlib json lz4 noop_math Vulkan::Vulkan sdl2)
set(LIBS vkbootstrap vma imgui spirv_reflect assetlib json lz4 noop_math Vulkan::Vulkan sdl2 inih)
target_link_libraries(vk_study ${LIBS})
set_property(TARGET vk_study PROPERTY VS_DEBUGGER_WORKING_DIRECTORY "$<TARGET_FILE_DIR:vk_study>")

add_dependencies(vk_study Shaders)
add_dependencies(vk_study build_shaders)
10 changes: 5 additions & 5 deletions src/camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,25 +42,25 @@ void Camera::turn(f32 yawDelta, f32 pitchDelta) {
configVectorsFromForward();
}

void Camera::setForward(vec3 forward) {
Assert(magnitude(forward) > 0);
vec3 newForward = normalize(forward);
void Camera::setForward(vec3 dir) {
Assert(magnitude(dir) > 0);
vec3 newForward = normalize(dir);

// invalid forward
if(newForward.z > maxPitch_invSine || newForward.z < -maxPitch_invSine) {
std::cout << "ERROR: invalid forward vector sent to camera" << std::endl;
return;
}

this->forward = newForward;
forward = newForward;
configVectorsFromForward();
}

void Camera::lookAt(vec3 focusPoint) {
setForward(focusPoint - pos);
}

mat4 Camera::getViewMatrix() {
mat4 Camera::getViewMatrix() const {
mat4 measure{
right.x, up.x, -forward.x, 0.f,
right.y, up.y, -forward.y, 0.f,
Expand Down
2 changes: 1 addition & 1 deletion src/camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Camera {

void turn(f32 yawDelta, f32 pitchDelta);

mat4 getViewMatrix();
mat4 getViewMatrix() const;

void setForward(vec3 forward);
void lookAt(vec3 focusPoint);
Expand Down
24 changes: 0 additions & 24 deletions src/imgui_util.cpp

This file was deleted.

2 changes: 1 addition & 1 deletion src/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ add_executable(
shader_reflect_test.cpp
)
target_link_libraries(shader_reflect_test ${LIBS})
add_dependencies(shader_reflect_test Shaders)
add_dependencies(shader_reflect_test build_shaders)

# play_ground_test
add_executable(
Expand Down
4 changes: 2 additions & 2 deletions src/util.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
void StartTimer(Timer& timer) {
timer.prev = std::chrono::high_resolution_clock::now();
timer.prev = std::chrono::steady_clock::now();
timer.delta = 0.0;
}

f64 StopTimer(Timer& timer) {
std::chrono::steady_clock::time_point prevPrev = timer.prev;
timer.prev = std::chrono::high_resolution_clock::now();
timer.prev = std::chrono::steady_clock::now();
std::chrono::duration<double, std::milli> dur = timer.prev - prevPrev;
timer.delta = dur.count();
return timer.delta;
Expand Down
Loading

0 comments on commit b790167

Please sign in to comment.