Skip to content

Commit

Permalink
REFACTOR vulkan:
Browse files Browse the repository at this point in the history
- remove cppVulkanAPI submodule
- add vulkan.hpp and vulkan.cpp
  • Loading branch information
SaumonDesMers authored and afaure42 committed Feb 27, 2024
1 parent 53e75fa commit e986d21
Show file tree
Hide file tree
Showing 16 changed files with 1,605 additions and 159 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,4 @@ latex
html
build
glslc
glm
10 changes: 4 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ target_sources(${PROJECT_NAME}
src/app/threads/AThreadWrapper.cpp
src/app/threads/render/RenderThread.cpp
src/app/threads/update/UpdateThread.cpp
src/app/vulkan/VulkanAPI.cpp
src/app/window/window.cpp
src/app/window/input.cpp
)
Expand All @@ -47,12 +48,9 @@ target_include_directories(${PROJECT_NAME}
${CMAKE_CURRENT_SOURCE_DIR}/src/app/threads/render
${CMAKE_CURRENT_SOURCE_DIR}/src/app/threads/update
${CMAKE_CURRENT_SOURCE_DIR}/src/app/threads/block_update
${CMAKE_CURRENT_SOURCE_DIR}/src/app/vulkan
${CMAKE_CURRENT_SOURCE_DIR}/src/app/window
)

# link libraries
add_subdirectory(external/cppVulkanAPI)
target_link_libraries(${PROJECT_NAME}
PRIVATE
cppVulkanAPI
)
target_link_libraries(${PROJECT_NAME} glfw vulkan dl pthread X11 Xxf86vm Xrandr Xi)

4 changes: 2 additions & 2 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

# Sript to build the project

# Download the necessary external libraries
./scripts/download_cppVulkanAPI.sh
# Download dependencies
./scripts/download_glm.sh

# Compile shaders
./scripts/compile_shaders.sh
Expand Down
8 changes: 0 additions & 8 deletions scripts/download_cppVulkanAPI.sh

This file was deleted.

9 changes: 9 additions & 0 deletions scripts/download_glm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

if [ ! -d external/glm ]
then
echo "cloning 'https://github.com/g-truc/glm.git' in external/glm"

mkdir -p external/glm
git clone https://github.com/g-truc/glm.git external/glm
fi
16 changes: 3 additions & 13 deletions shaders/simple_shader.frag
Original file line number Diff line number Diff line change
@@ -1,19 +1,9 @@
#version 450

layout(set=1, binding = 0) uniform sampler2D texSampler;

layout(location = 0) in vec3 fragNormal;
layout(location = 1) in vec2 fragTexCoord;
layout(location = 0) in vec3 fragColor;

layout(location = 0) out vec4 outColor;
layout(location = 1) out vec3 outNormal;

void main() {
outColor = texture(texSampler, fragTexCoord);

vec3 abs_normal = abs(fragNormal);

float grey_shade = abs_normal.x * 0.299 + abs_normal.y * 0.587 + abs_normal.z * 0.114;

outNormal = vec3(grey_shade, grey_shade, grey_shade);
}
outColor = vec4(fragColor, 1.0);
}
34 changes: 14 additions & 20 deletions shaders/simple_shader.vert
Original file line number Diff line number Diff line change
@@ -1,26 +1,20 @@
#version 450

layout(set=0, binding = 0) uniform UniformBufferObject {
mat4 view;
mat4 proj;
} ubo;
layout(location = 0) out vec3 fragColor;

layout(push_constant) uniform PushConstantObject {
mat4 model;
} pc;
vec2 positions[3] = vec2[](
vec2(0.0, -0.5),
vec2(0.5, 0.5),
vec2(-0.5, 0.5)
);

layout(location = 0) in vec3 inPosition;
layout(location = 1) in vec3 inNormal;
layout(location = 2) in vec2 inTexCoord;

layout(location = 0) out vec3 fragNormal;
layout(location = 1) out vec2 fragTexCoord;
vec3 colors[3] = vec3[](
vec3(1.0, 0.0, 0.0),
vec3(0.0, 1.0, 0.0),
vec3(0.0, 0.0, 1.0)
);

void main() {
gl_Position = ubo.proj * ubo.view * pc.model * vec4(inPosition, 1.0);

// convert normal to world space
fragNormal = normalize((pc.model * vec4(inNormal, 0.0)).xyz);

fragTexCoord = inTexCoord;
}
gl_Position = vec4(positions[gl_VertexIndex], 0.0, 1.0);
fragColor = colors[gl_VertexIndex];
}
4 changes: 2 additions & 2 deletions src/app/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ Application::Application():
m_settings(),
m_world_scene(),
m_window("Vox", 800, 600),
m_renderAPI(m_window.getGLFWwindow()),
m_render_thread(m_settings, m_renderAPI, m_world_scene),
m_vulkan_api(m_window.getGLFWwindow()),
m_render_thread(m_settings, m_vulkan_api, m_world_scene),
m_update_thread(m_settings, m_window, m_world_scene, m_start_time)
{
LOG_INFO("Application::Application()");
Expand Down
5 changes: 2 additions & 3 deletions src/app/application.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
#include "RenderThread.hpp"
#include "WorldScene.hpp"
#include "UpdateThread.hpp"

#include <cppVulkanAPI.hpp>
#include "VulkanAPI.hpp"

#include <chrono>

Expand All @@ -28,7 +27,7 @@ class Application
Settings m_settings;
WorldScene m_world_scene;
Window m_window;
vk::RenderAPI m_renderAPI;
VulkanAPI m_vulkan_api;
RenderThread m_render_thread;
UpdateThread m_update_thread;
};
3 changes: 2 additions & 1 deletion src/app/scenes/WorldScene.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
#include "define.hpp"
#include "logger.hpp"

#include <cppVulkanAPI.hpp>
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>

#include <vector>
#include <mutex>
Expand Down
Loading

0 comments on commit e986d21

Please sign in to comment.