Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding OpenGL #26

Open
wants to merge 66 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
7581c67
add OpenGL and the base for the system of autodetermination of the Gr…
PatateDu609 Sep 1, 2024
a73949d
Merge branch 'feat/load-gltf' into feat/add-opengl
Sep 1, 2024
82b7255
OpenGL Renderer
Sep 1, 2024
3a59e84
Merge branch 'dev' into feat/add-opengl
Sep 2, 2024
26f8c8b
Merge branch 'feat/stone-objects-idendifications' into feat/add-opengl
Sep 2, 2024
57a9dd8
Merge branch 'dev' into feat/add-opengl
Sep 3, 2024
38878bb
glfw get framebuffer size for settings
Sep 3, 2024
f9f27b2
OpenGL Renderer object match
Sep 3, 2024
3f6ccfd
OpenGL RendererObjectManager
Sep 3, 2024
337f77d
render context structure
Sep 3, 2024
b985faf
OpenGLRenderer using RenderContext and RendererObjectManager
Sep 3, 2024
8dee2b2
check glfw init failure
Sep 3, 2024
dcd5ab5
OpenGL mesh render wip
amasson42 Sep 4, 2024
5a76c98
Renderer defaults instance
amasson42 Sep 4, 2024
eac5bd7
Merge branch 'feat/render-default-objects' into feat/add-opengl
amasson42 Sep 4, 2024
9106cbf
OpenGL default material
amasson42 Sep 4, 2024
b4bfd59
fix material instanciation
amasson42 Sep 4, 2024
eeedd96
Merge branch 'feat/render-default-objects' into feat/add-opengl
amasson42 Sep 4, 2024
8ffd0ae
OpenGL generate textures
Sep 4, 2024
f65fd5b
Update README.md
amasson42 Sep 5, 2024
b0a9a87
OpenGL texture channel
Oct 4, 2024
ab3020a
Scene fragment shader
Oct 4, 2024
97eabce
Compile and link opengl shaders with default materials
Oct 5, 2024
a80422a
fix format
Oct 5, 2024
71c3075
Merge branch 'feat/debug-shape' into feat/add-opengl
Oct 12, 2024
d697bf0
MacOS compilation
amasson42 Oct 18, 2024
31c5f44
Separate render api requirements
amasson42 Oct 18, 2024
ad455f3
add shaderc on MacOS readme
amasson42 Oct 18, 2024
78598b0
fix format
amasson42 Oct 20, 2024
cc7e9c8
fix format
amasson42 Oct 20, 2024
1ab3f84
Use linear mipmap texture filter #52
amasson42 Oct 20, 2024
2ddbbf9
Merge branch 'dev' into feat/add-opengl
amasson42 Oct 20, 2024
a841bd3
Merge branch 'dev' into feat/add-opengl
amasson42 Oct 21, 2024
4c287cd
Add wireframeshape to renderer object manager
amasson42 Oct 21, 2024
4fb3e23
Base Node definition not using macro
amasson42 Oct 21, 2024
24daacc
Using int as possible material location
amasson42 Nov 1, 2024
1afade2
Merge branch 'feat/node-metadata' into feat/add-opengl
amasson42 Nov 1, 2024
2985382
Merge branch 'feat/node-metadata' into feat/add-opengl
amasson42 Nov 1, 2024
b8711d8
write Meterial Location to stream
amasson42 Nov 1, 2024
37fef21
fix clang
amasson42 Nov 1, 2024
d9cbf45
prepare asset resources tests
amasson42 Nov 1, 2024
58d73e5
Merge branch 'feat/json-creating-no-ptr' into feat/add-opengl
Nov 2, 2024
af094f6
tidy naming
Nov 4, 2024
00d367b
Merge branch 'feat/mark-dirty-on-end-editing' into feat/add-opengl
amasson42 Nov 5, 2024
63b2f2e
Merge branch 'dev' into feat/add-opengl
Nov 5, 2024
43dd981
Merge branch 'feat/add-opengl' of https://github.com/LimpingPebble/St…
Nov 5, 2024
00b317e
Merge branch 'feat/mark-dirty-on-end-editing' into feat/add-opengl
Nov 5, 2024
208d95a
Update renderer objects undirty #63
Nov 5, 2024
cac1670
Merge branch 'dev' into feat/add-opengl
Nov 5, 2024
4bba0c4
Change children from vector to list #74
amasson42 Nov 8, 2024
23c53d5
Merge branch 'feat/node-children-list' into feat/add-opengl
amasson42 Nov 8, 2024
6cb59aa
material foreach split parameters from pair
amasson42 Nov 12, 2024
69f6d07
Shader generator functions
amasson42 Nov 12, 2024
131253c
shader generator example program
amasson42 Nov 12, 2024
fa05dac
remove default material from render defaults
amasson42 Nov 12, 2024
dd22faa
Replace RendererDefaults with Resources
amasson42 Nov 12, 2024
f5e96e2
Separate texture header and implementation
amasson42 Nov 13, 2024
1defeb0
fix format
amasson42 Nov 13, 2024
292287d
OpenGL shader uutilities
amasson42 Nov 13, 2024
b18aefe
Use shader collection
amasson42 Nov 13, 2024
78f479d
Gbuffer structure for render pipeline
Nov 13, 2024
e7843a3
Fragment shader using shader collection
Nov 13, 2024
f83376e
opengl make material use shader collection
Nov 13, 2024
77d8916
opengl mesh node pipeline
Nov 13, 2024
251b8db
use children list #74
amasson42 Nov 15, 2024
1e2df60
Use texture with program indices
amasson42 Nov 15, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
342 changes: 188 additions & 154 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,24 @@ project(StoneEngine LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED YES)

set(USE_SYSTEM_GLM OFF CACHE BOOL "Uses glm from system libraries")
set(USE_SYSTEM_BOOST ON CACHE BOOL "Uses boost from system libraries")
set(SKIP_TESTS ON CACHE BOOL "Disables tests")
set(USE_SYSTEM_PAUSE OFF CACHE BOOL "Enables the use of Windows' pause after ending console only programs. (Windows only)")
set(FULL_CONFIGURE ON CACHE BOOL "Full configure project (may be used in pipeline to avoid the setup of all the dependencies)")
set(ENABLE_DOCS OFF CACHE BOOL "Builds documentation with doxygen")
option(USE_SYSTEM_GLM "Uses glm from system libraries" OFF)
option(USE_SYSTEM_BOOST "Uses boost from system libraries" ON)
option(SKIP_TESTS "Disables tests" ON)
option(USE_SYSTEM_PAUSE "Enables the use of Windows' pause after ending console only programs. (Windows only)" OFF)
option(FULL_CONFIGURE "Full configure project (may be used in pipeline to avoid the setup of all the dependencies)" ON)
option(ENABLE_DOCS "Builds documentation with doxygen" OFF)

set(VALID_GRAPHICS_APIs "AUTO" "VULKAN" "OPENGL")
option(GRAPHICS_API "Configures the graphics API to use, can be AUTO, VULKAN, OPENGL" "AUTO")

string(TOUPPER ${GRAPHICS_API} tmp)
set(GRAPHICS_API "${tmp}")
unset(tmp)

if (NOT GRAPHICS_API IN_LIST VALID_GRAPHICS_APIs)
list(JOIN VALID_GRAPHICS_APIs ", " lst_str)
message(FATAL_ERROR "Expecting GRAPHICS_API value to be in the list [${lst_str}]")
endif ()

# TODO: dependencies are not mandatory
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake")
Expand All @@ -19,64 +31,72 @@ include(OSDetection)

include(FetchContent)

if ( FULL_CONFIGURE )
# Require Vulkan
find_package(Vulkan)
find_package(Python REQUIRED COMPONENTS Interpreter)

if ( ${Python_VERSION_MAJOR} STRLESS 3 AND ${Python_VERSION_MINOR} STRLESS 10 )
message(FATAL_ERROR "Got bad version of python: ${Python_VERSION}")
endif ()

file(DOWNLOAD https://raw.githubusercontent.com/nothings/stb/013ac3beddff3dbffafd5177e7972067cd2b5083/stb_image.h
${CMAKE_BINARY_DIR}/include/stb_image.h
EXPECTED_HASH SHA256=594c2fe35d49488b4382dbfaec8f98366defca819d916ac95becf3e75f4200b3
)

# Require ShaderC (google's shader compiler, compatible with GLSL or HLSL)
FetchContent_Declare(
shaderc
GIT_REPOSITORY https://github.com/google/shaderc
GIT_TAG 9a658e242ad4d1a4b3491383c1c58c780e3c01ff # tag/v2024.1
)
FetchContent_GetProperties(shaderc)

if ( NOT shaderc_POPULATED )
FetchContent_Populate(shaderc)
set($ENV{GIT_SYNC_DEPS_QUIET} 1)
execute_process(
COMMAND ${Python_EXECUTABLE} utils/git-sync-deps
WORKING_DIRECTORY ${shaderc_SOURCE_DIR}
COMMAND_ERROR_IS_FATAL ANY
OUTPUT_FILE git-sync-deps.out
)

set(SHADERC_SKIP_TESTS ON CACHE INTERNAL "Disables tests in ShaderC")
set(SHADERC_SKIP_EXAMPLES ON CACHE INTERNAL "Disables examples in ShaderC")
set(SHADERC_SKIP_INSTALL ON CACHE INTERNAL "Disables installation in ShaderC")

add_subdirectory(${shaderc_SOURCE_DIR} ${shaderc_BINARY_DIR})
endif ()

# Fetches GLM
if ( USE_SYSTEM_GLM )
find_package(glm)

if ( NOT GLM_FOUND )
message(STATUS "Couldn't find glm in system, will use online source instead")
endif ()
else ()
message(STATUS "Will fetch glm from online source")
endif ()

if ( NOT GLM_FOUND )
FetchContent_Declare(
glm
GIT_REPOSITORY https://github.com/g-truc/glm.git
GIT_TAG 33b0eb9fa336ffd8551024b1d2690e418014553b # refs/tags/1.0.0
)
if (GRAPHICS_API STREQUAL "AUTO")
set(GRAPHICS_API "OPENGL")
endif ()

set(GLM_ENABLE_CXX_17 ON CACHE INTERNAL "Forces C++17 in GLM")
if (FULL_CONFIGURE)
add_library(gfx_api INTERFACE)
if (GRAPHICS_API STREQUAL "VULKAN")
# Require Vulkan
message(STATUS "Setup gfx_api to use Vulkan rendering API")
find_package(Vulkan REQUIRED)
target_link_libraries(gfx_api INTERFACE ${Vulkan_LIBRARIES})
target_include_directories(gfx_api INTERFACE ${Vulkan_INCLUDE_DIRS})
elseif (GRAPHICS_API STREQUAL "OPENGL")
message(STATUS "Setup gfx_api to use OPENGL rendering API")
find_package(OpenGL REQUIRED)
find_package(GLEW REQUIRED)
if (APPLE)
target_link_libraries(gfx_api INTERFACE "-framework OpenGL" GLEW::GLEW)
else ()
target_link_libraries(gfx_api INTERFACE OpenGL::GL GLEW::GLEW)
endif ()
target_include_directories(gfx_api INTERFACE ${GLEW_INCLUDE_DIRS})
else ()
message(FATAL_ERROR "Unexpected value for GRAPHICS_API, unknown API ${GRAPHICS_API}")
endif()

find_package(Python REQUIRED COMPONENTS Interpreter)

if (${Python_VERSION_MAJOR} STRLESS 3 AND ${Python_VERSION_MINOR} STRLESS 10)
message(FATAL_ERROR "Got bad version of python: ${Python_VERSION}")
endif ()

file(DOWNLOAD https://raw.githubusercontent.com/nothings/stb/013ac3beddff3dbffafd5177e7972067cd2b5083/stb_image.h
${CMAKE_BINARY_DIR}/include/stb_image.h
EXPECTED_HASH SHA256=594c2fe35d49488b4382dbfaec8f98366defca819d916ac95becf3e75f4200b3
)

# Require ShaderC (google's shader compiler, compatible with GLSL or HLSL)
FetchContent_Declare(
shaderc
GIT_REPOSITORY https://github.com/google/shaderc
GIT_TAG 9a658e242ad4d1a4b3491383c1c58c780e3c01ff # tag/v2024.1
)
FetchContent_GetProperties(shaderc)

if (NOT shaderc_POPULATED)
FetchContent_Populate(shaderc)
set($ENV{GIT_SYNC_DEPS_QUIET} 1)
execute_process(
COMMAND ${Python_EXECUTABLE} utils/git-sync-deps
WORKING_DIRECTORY ${shaderc_SOURCE_DIR}
COMMAND_ERROR_IS_FATAL ANY
OUTPUT_FILE git-sync-deps.out
)

set(SHADERC_SKIP_TESTS ON CACHE INTERNAL "Disables tests in ShaderC")
set(SHADERC_SKIP_EXAMPLES ON CACHE INTERNAL "Disables examples in ShaderC")
set(SHADERC_SKIP_INSTALL ON CACHE INTERNAL "Disables installation in ShaderC")

add_subdirectory(${shaderc_SOURCE_DIR} ${shaderc_BINARY_DIR})
endif ()

# Fetches GLM
if (USE_SYSTEM_GLM)
find_package(glm)

FetchContent_MakeAvailable(glm)
set(GLM_FOUND ON)
Expand All @@ -88,102 +108,116 @@ if ( FULL_CONFIGURE )
)
endif ()

# Fetches GoogleTest only if needed
if ( NOT SKIP_TESTS )
FetchContent_Declare(
gtest
GIT_REPOSITORY https://github.com/google/googletest
GIT_TAG f8d7d77c06936315286eb55f8de22cd23c188571
)

# For Windows: Prevent overriding the parent project's compiler/linker settings
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(gtest)
set_target_properties(gtest PROPERTIES SYSTEM ON)

if ( NOT SKIP_TESTS )
enable_testing()
endif ()
endif ()

# Setup Glfw
FetchContent_Declare(
glfw
GIT_REPOSITORY https://github.com/glfw/glfw
GIT_TAG 7b6aead9fb88b3623e3b3725ebb42670cbe4c579 # tag/3.4
)
FetchContent_GetProperties(glfw)

if ( NOT glfw_POPULATED )
FetchContent_Populate(glfw)

set(GLFW_BUILD_EXAMPLES OFF CACHE INTERNAL "Build the GLFW example programs")
set(GLFW_BUILD_TESTS OFF CACHE INTERNAL "Build the GLFW test programs")
set(GLFW_BUILD_DOCS OFF CACHE INTERNAL "Build the GLFW documentation")
set(GLFW_INSTALL OFF CACHE INTERNAL "Generate installation target")

if ( STONE_ENGINE_OS_NAME STREQUAL Linux )
set(GLFW_BUILD_WAYLAND OFF CACHE INTERNAL "Enables the use of Wayland (Linux only)")
set(GLFW_BUILD_X11 ON CACHE INTERNAL "Enables the use of X11 (Linux only)")
endif ()

add_subdirectory(${glfw_SOURCE_DIR} ${glfw_BINARY_DIR})
endif ()

set_target_properties(glfw PROPERTIES SYSTEM ON)

# Setup Json
FetchContent_Declare(
json
GIT_REPOSITORY https://github.com/nlohmann/json
GIT_TAG 9cca280a4d0ccf0c08f47a99aa71d1b0e52f8d03 # tag/v3.11.3
)
FetchContent_MakeAvailable(json)
add_library(json ALIAS nlohmann_json)

set_target_properties(nlohmann_json PROPERTIES SYSTEM ON)

# Setup Assimp
FetchContent_Declare(
assimp
GIT_REPOSITORY https://github.com/assimp/assimp
GIT_TAG 8b9ed34eaa3e6ad24254cb7e058fb9150f66b865 # tag/v5.4.0
)
set(BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE)
set(ASSIMP_BUILD_TESTS OFF CACHE BOOL "" FORCE)
set(ASSIMP_INJECT_DEBUG_POSTFIX OFF CACHE BOOL "" FORCE)
set(ASSIMP_INSTALL OFF CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(assimp)

set_target_properties(assimp PROPERTIES SYSTEM ON)

if ( USE_SYSTEM_BOOST )
find_package(Boost 1.74.0)
endif ()

if ( NOT USE_SYSTEM_BOOST OR NOT Boost_FOUND )
set(BOOST_GIT_TAG a7090e8ce184501cfc9e80afa6cafb5bfd3b371c) # tag/boost-1.74.0
FetchContent_Declare(Boost
GIT_REPOSITORY https://github.com/boostorg/boost
GIT_TAG ${BOOST_GIT_TAG}
)
if ( NOT Boost_POPULATED )
message(STATUS "Fetching Boost from git repository")

FetchContent_Populate(Boost)

message(STATUS "Configuring Boost")
add_subdirectory(${boost_SOURCE_DIR} ${boost_BINARY_DIR} EXCLUDE_FROM_ALL)
endif ()
endif ()
if (NOT GLM_FOUND)
FetchContent_Declare(
glm
GIT_REPOSITORY https://github.com/g-truc/glm.git
GIT_TAG 33b0eb9fa336ffd8551024b1d2690e418014553b # refs/tags/1.0.0
)

set(GLM_ENABLE_CXX_17 ON CACHE INTERNAL "Forces C++17 in GLM")

FetchContent_MakeAvailable(glm)
set(GLM_FOUND ON)
set_target_properties(glm PROPERTIES SYSTEM ON)
endif ()

# Fetches GoogleTest only if needed
if (NOT SKIP_TESTS)
FetchContent_Declare(
gtest
GIT_REPOSITORY https://github.com/google/googletest
GIT_TAG f8d7d77c06936315286eb55f8de22cd23c188571
)

# For Windows: Prevent overriding the parent project's compiler/linker settings
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(gtest)
set_target_properties(gtest PROPERTIES SYSTEM ON)

if (NOT SKIP_TESTS)
enable_testing()
endif ()
endif ()

# Setup Glfw
FetchContent_Declare(
glfw
GIT_REPOSITORY https://github.com/glfw/glfw
GIT_TAG 7b6aead9fb88b3623e3b3725ebb42670cbe4c579 # tag/3.4
)
FetchContent_GetProperties(glfw)

if (NOT glfw_POPULATED)
FetchContent_Populate(glfw)

set(GLFW_BUILD_EXAMPLES OFF CACHE INTERNAL "Build the GLFW example programs")
set(GLFW_BUILD_TESTS OFF CACHE INTERNAL "Build the GLFW test programs")
set(GLFW_BUILD_DOCS OFF CACHE INTERNAL "Build the GLFW documentation")
set(GLFW_INSTALL OFF CACHE INTERNAL "Generate installation target")

if (STONE_ENGINE_OS_NAME STREQUAL Linux)
set(GLFW_BUILD_WAYLAND OFF CACHE INTERNAL "Enables the use of Wayland (Linux only)")
set(GLFW_BUILD_X11 ON CACHE INTERNAL "Enables the use of X11 (Linux only)")
endif ()

add_subdirectory(${glfw_SOURCE_DIR} ${glfw_BINARY_DIR})
endif ()

set_target_properties(glfw PROPERTIES SYSTEM ON)

# Setup Json
FetchContent_Declare(
json
GIT_REPOSITORY https://github.com/nlohmann/json
GIT_TAG 9cca280a4d0ccf0c08f47a99aa71d1b0e52f8d03 # tag/v3.11.3
)
FetchContent_MakeAvailable(json)
add_library(json ALIAS nlohmann_json)

set_target_properties(nlohmann_json PROPERTIES SYSTEM ON)

# Setup Assimp
FetchContent_Declare(
assimp
GIT_REPOSITORY https://github.com/assimp/assimp
GIT_TAG 8b9ed34eaa3e6ad24254cb7e058fb9150f66b865 # tag/v5.4.0
)
set(BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE)
set(ASSIMP_BUILD_TESTS OFF CACHE BOOL "" FORCE)
set(ASSIMP_INJECT_DEBUG_POSTFIX OFF CACHE BOOL "" FORCE)
set(ASSIMP_INSTALL OFF CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(assimp)

set_target_properties(assimp PROPERTIES SYSTEM ON)

if (USE_SYSTEM_BOOST)
find_package(Boost 1.74.0)
endif ()

if (NOT USE_SYSTEM_BOOST OR NOT Boost_FOUND)
set(BOOST_GIT_TAG a7090e8ce184501cfc9e80afa6cafb5bfd3b371c) # tag/boost-1.74.0
FetchContent_Declare(Boost
GIT_REPOSITORY https://github.com/boostorg/boost
GIT_TAG ${BOOST_GIT_TAG}
)
if (NOT Boost_POPULATED)
message(STATUS "Fetching Boost from git repository")

FetchContent_Populate(Boost)

message(STATUS "Configuring Boost")
add_subdirectory(${boost_SOURCE_DIR} ${boost_BINARY_DIR} EXCLUDE_FROM_ALL)
endif ()
endif ()
endif ()

add_subdirectory(Engine)

if ( FULL_CONFIGURE )
add_subdirectory(examples)
if (FULL_CONFIGURE)
add_subdirectory(examples)
endif ()

if ( ENABLE_DOCS )
include(Doxygen)
if (ENABLE_DOCS)
include(Doxygen)
endif ()
3 changes: 2 additions & 1 deletion CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
"SKIP_TESTS": {
"type": "BOOL",
"value": "OFF"
}
},
"GRAPHICS_API": "AUTO"
},
"condition": {
"type": "notEquals",
Expand Down
2 changes: 1 addition & 1 deletion Engine/Core/include/Core/Image/ImageSource.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class ImageSource : public Assets::Resource {
[[nodiscard]] Size getSize() const;

void unloadData();
void loadData(bool force);
void loadData(bool force = false);

[[nodiscard]] bool isLoaded() const;
[[nodiscard]] std::shared_ptr<ImageData> getLoadedImage() const;
Expand Down
Loading