Skip to content

Commit

Permalink
Merge pull request #13 from arozx/my-code-sucks-to-im-rewriting-it
Browse files Browse the repository at this point in the history
optimise & abstract application
  • Loading branch information
arozx authored Jan 23, 2025
2 parents 328d0e4 + 36761dd commit 56f84e4
Show file tree
Hide file tree
Showing 71 changed files with 28,629 additions and 948 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
run: |
sudo apt update
sudo apt install -y cmake build-essential pkg-config \
libglfw3-dev libgl1-mesa-dev libx11-dev libgl-dev libglm-dev libfreetype6-dev
libglfw3-dev libgl1-mesa-dev libx11-dev libgl-dev libglm-dev libfreetype6-dev ccache
- name: Update submodules
run: git submodule update --init --recursive
Expand Down
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,9 @@ todo.md
todo
TODO
.todo

# Debug outputs
profile_results.json
profiler_n_frames.json

heightmap_chunk*.bmp
1 change: 1 addition & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[submodule "external/imgui"]
path = external/imgui
url = https://github.com/ocornut/imgui.git
branch = docking
81 changes: 49 additions & 32 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.16) # PCH support requires 3.16+
cmake_minimum_required(VERSION 3.16)
project(VoxelEngine)

set(CMAKE_CXX_STANDARD 17)
Expand All @@ -7,19 +7,26 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
# Export compile commands for SonarQube
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

set(OpenGL_GL_PREFERENCE GLVND)
find_package(OpenGL REQUIRED)
find_package(glfw3 REQUIRED)
set(CMAKE_CXX_COMPILER_LAUNCHER ccache)

# Find FreeType
# find_package(Freetype REQUIRED)
if(WIN32)
set(CMAKE_TOOLCHAIN_FILE "${CMAKE_SOURCE_DIR}/vcpkg/scripts/buildsystems/vcpkg.cmake")
else()
include_directories(/usr/include)
link_directories(/usr/lib)
endif()

include_directories(/usr/include)
# include_directories(${FREETYPE_INCLUDE_DIRS})
link_directories(/usr/lib)
set(OpenGL_GL_PREFERENCE GLVND)
find_package(OpenGL REQUIRED)
find_package(glfw3 CONFIG REQUIRED)

# Copy the INI file to the build directory
# file(COPY ${CMAKE_SOURCE_DIR}/conf.ini DESTINATION ${CMAKE_BINARY_DIR})
# Add GLAD
add_library(glad STATIC
external/glad/src/glad.c
)
target_include_directories(glad PUBLIC
external/glad/include
)

# Add ImGui source files
set(IMGUI_DIR external/imgui)
Expand All @@ -33,11 +40,8 @@ set(IMGUI_SOURCES
${IMGUI_DIR}/backends/imgui_impl_opengl3.cpp
)

# Add source files
set(SOURCES
external/glad/src/glad.c
external/stb_image/src/stb_image.cpp
src/EntryPoint.cpp
# Engine library sources
set(ENGINE_SOURCES
src/Application.cpp
src/Window/OpenGLWindow.cpp
src/Renderer/Buffer.cpp
Expand All @@ -50,39 +54,52 @@ set(SOURCES
src/Camera/PerspectiveCamera.cpp
src/Renderer/Material.cpp
src/Renderer/Texture.cpp
src/Shader/DefaultShaders.h
src/Renderer/MeshTemplates.h
src/Debug/Profiler.cpp
src/Threading/ThreadPool.cpp
src/VoxelTerrain.cpp
src/VoidNoise.cpp
src/Noise/VoidNoise/VoidNoise.cpp
src/Noise/PerlinNoise/PerlinNoise.cpp
src/Input/InputSystem.cpp
src/TerrainSystem/TerrainSystem.cpp
src/UI/ImGuiOverlay.cpp
src/UI/ImGuiFlameGraph.cpp
src/VoxelChunk.cpp
src/Core/FPSCounter.cpp
src/Shader/ShaderHotReload.cpp
src/Noise/SimplexNoise/SimplexNoise.cpp
src/Noise/ValueNoise/ValueNoise.cpp
external/stb_image/src/stb_image.cpp
${IMGUI_SOURCES}
)

# Add executable
add_executable(voxel-engine ${SOURCES})
# Create engine library
add_library(voxel-engine STATIC ${ENGINE_SOURCES})

target_include_directories(voxel-engine PRIVATE external/glad/include)

# Link OpenGL and FreeType libraries
target_link_libraries(voxel-engine PRIVATE glfw OpenGL::GL ${FREETYPE_LIBRARIES})

# Set Clang-Tidy as the CMake static analysis tool
set(CMAKE_CXX_CLANG_TIDY "clang-tidy;-checks=*,-modernize-use-auto")

target_include_directories(voxel-engine PRIVATE
target_include_directories(voxel-engine PUBLIC
${CMAKE_SOURCE_DIR}/src
${IMGUI_DIR}
${IMGUI_DIR}/backends
${CMAKE_SOURCE_DIR}/external/stb_image/src
${CMAKE_SOURCE_DIR}/external/json
${CMAKE_SOURCE_DIR}/external/glad/include
)

target_link_libraries(voxel-engine PUBLIC
glfw
OpenGL::GL
glad
)

# Create sandbox executable
set(SANDBOX_SOURCES
sandbox/src/SandboxApp.cpp
)

add_executable(sandbox ${SANDBOX_SOURCES})
target_link_libraries(sandbox PRIVATE voxel-engine)

# Enable precompiled headers - specify C++ explicitly
target_precompile_headers(voxel-engine
target_precompile_headers(voxel-engine
PRIVATE
$<INSTALL_INTERFACE:pch.h>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/pch.h>
Expand All @@ -98,4 +115,4 @@ set_source_files_properties(
# Ensure PCH is used for all C++ files
set_target_properties(voxel-engine PROPERTIES
COMPILE_FLAGS "-include pch.h"
)
)
39 changes: 39 additions & 0 deletions assets/shaders/lit.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@

#version 330 core

in vec2 v_TexCoord;
in vec3 v_Normal;
in vec3 v_FragPos;

uniform vec3 u_LightPos;
uniform vec3 u_ViewPos;
uniform vec4 u_Color;
uniform sampler2D u_Texture;

uniform vec3 u_LightColor;
uniform float u_AmbientStrength;
uniform float u_SpecularStrength;
uniform float u_Shininess;

out vec4 FragColor;

void main() {
// Ambient
vec3 ambient = u_AmbientStrength * u_LightColor;

// Diffuse
vec3 norm = normalize(v_Normal);
vec3 lightDir = normalize(u_LightPos - v_FragPos);
float diff = max(dot(norm, lightDir), 0.0);
vec3 diffuse = diff * u_LightColor;

// Specular
vec3 viewDir = normalize(u_ViewPos - v_FragPos);
vec3 reflectDir = reflect(-lightDir, norm);
float spec = pow(max(dot(viewDir, reflectDir), 0.0), u_Shininess);
vec3 specular = u_SpecularStrength * spec * u_LightColor;

vec4 texColor = texture(u_Texture, v_TexCoord) * u_Color;
vec3 result = (ambient + diffuse + specular) * texColor.rgb;
FragColor = vec4(result, texColor.a);
}
20 changes: 20 additions & 0 deletions assets/shaders/lit.vert
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

#version 330 core

layout(location = 0) in vec3 aPosition;
layout(location = 1) in vec2 aTexCoord;
layout(location = 2) in vec3 aNormal;

uniform mat4 u_ViewProjection;
uniform mat4 u_Transform;

out vec2 v_TexCoord;
out vec3 v_Normal;
out vec3 v_FragPos;

void main() {
v_TexCoord = aTexCoord;
v_Normal = mat3(transpose(inverse(u_Transform))) * aNormal;
v_FragPos = vec3(u_Transform * vec4(aPosition, 1.0));
gl_Position = u_ViewProjection * u_Transform * vec4(aPosition, 1.0);
}
Binary file added assets/textures/terrain_atlas.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion external/imgui
Submodule imgui updated 78 files
+3 −0 .gitignore
+2 −1 backends/imgui_impl_allegro5.cpp
+1 −0 backends/imgui_impl_allegro5.h
+1 −0 backends/imgui_impl_android.cpp
+1 −0 backends/imgui_impl_android.h
+135 −2 backends/imgui_impl_dx10.cpp
+1 −0 backends/imgui_impl_dx10.h
+134 −1 backends/imgui_impl_dx11.cpp
+1 −0 backends/imgui_impl_dx11.h
+376 −57 backends/imgui_impl_dx12.cpp
+1 −0 backends/imgui_impl_dx12.h
+162 −1 backends/imgui_impl_dx9.cpp
+1 −0 backends/imgui_impl_dx9.h
+561 −33 backends/imgui_impl_glfw.cpp
+4 −0 backends/imgui_impl_glfw.h
+1 −0 backends/imgui_impl_glut.cpp
+1 −0 backends/imgui_impl_glut.h
+1 −0 backends/imgui_impl_metal.h
+161 −2 backends/imgui_impl_metal.mm
+51 −1 backends/imgui_impl_opengl2.cpp
+1 −0 backends/imgui_impl_opengl2.h
+39 −1 backends/imgui_impl_opengl3.cpp
+1 −0 backends/imgui_impl_opengl3.h
+4 −0 backends/imgui_impl_osx.h
+345 −12 backends/imgui_impl_osx.mm
+421 −21 backends/imgui_impl_sdl2.cpp
+4 −0 backends/imgui_impl_sdl2.h
+412 −28 backends/imgui_impl_sdl3.cpp
+6 −5 backends/imgui_impl_sdl3.h
+65 −66 backends/imgui_impl_sdlgpu3.cpp
+13 −8 backends/imgui_impl_sdlgpu3.h
+11 −6 backends/imgui_impl_sdlrenderer2.cpp
+9 −5 backends/imgui_impl_sdlrenderer2.h
+12 −9 backends/imgui_impl_sdlrenderer3.cpp
+10 −8 backends/imgui_impl_sdlrenderer3.h
+374 −34 backends/imgui_impl_vulkan.cpp
+5 −5 backends/imgui_impl_vulkan.h
+2 −0 backends/imgui_impl_wgpu.cpp
+2 −0 backends/imgui_impl_wgpu.h
+493 −14 backends/imgui_impl_win32.cpp
+1 −0 backends/imgui_impl_win32.h
+597 −9 docs/CHANGELOG.txt
+43 −1 docs/TODO.txt
+1 −0 examples/example_allegro5/main.cpp
+19 −6 examples/example_apple_metal/example_apple_metal.xcodeproj/project.pbxproj
+17 −0 examples/example_apple_metal/main.mm
+17 −0 examples/example_apple_opengl2/main.mm
+18 −1 examples/example_glfw_metal/main.mm
+23 −0 examples/example_glfw_opengl2/main.cpp
+23 −0 examples/example_glfw_opengl3/main.cpp
+37 −19 examples/example_glfw_vulkan/main.cpp
+1 −0 examples/example_glfw_wgpu/main.cpp
+1 −1 examples/example_glut_opengl2/main.cpp
+19 −0 examples/example_sdl2_directx11/main.cpp
+17 −0 examples/example_sdl2_metal/main.mm
+25 −0 examples/example_sdl2_opengl2/main.cpp
+25 −0 examples/example_sdl2_opengl3/main.cpp
+1 −0 examples/example_sdl2_sdlrenderer2/main.cpp
+37 −19 examples/example_sdl2_vulkan/main.cpp
+25 −0 examples/example_sdl3_opengl3/main.cpp
+1 −1 examples/example_sdl3_sdlgpu3/main.cpp
+1 −0 examples/example_sdl3_sdlrenderer3/main.cpp
+37 −19 examples/example_sdl3_vulkan/main.cpp
+19 −1 examples/example_win32_directx10/main.cpp
+37 −1 examples/example_win32_directx11/main.cpp
+21 −3 examples/example_win32_directx12/main.cpp
+33 −1 examples/example_win32_directx9/main.cpp
+70 −0 examples/example_win32_opengl3/main.cpp
+49 −19 examples/example_win32_vulkan/main.cpp
+6,122 −236 imgui.cpp
+295 −35 imgui.h
+344 −29 imgui_demo.cpp
+42 −17 imgui_draw.cpp
+349 −28 imgui_internal.h
+37 −10 imgui_tables.cpp
+166 −40 imgui_widgets.cpp
+4 −0 misc/debuggers/imgui.natvis
+4 −4 misc/freetype/imgui_freetype.cpp
Loading

0 comments on commit 56f84e4

Please sign in to comment.