From f0433f145c036f81efd5227fae572d9b7e476730 Mon Sep 17 00:00:00 2001 From: bailwillharr Date: Sat, 3 Sep 2022 05:56:51 +0100 Subject: [PATCH] Do some stuff --- include/components/camera.hpp | 2 +- include/components/component.hpp | 2 +- include/components/custom.hpp | 2 +- include/components/mesh_renderer.hpp | 2 +- include/components/text_ui_renderer.hpp | 2 +- include/components/transform.hpp | 2 +- include/export.h | 10 +-- include/input.hpp | 2 +- include/object.hpp | 2 +- include/resource_manager.hpp | 2 +- include/resources/font.hpp | 2 +- include/resources/mesh.hpp | 2 +- include/resources/resource.hpp | 2 +- include/resources/shader.hpp | 2 +- include/resources/texture.hpp | 2 +- include/sceneroot.hpp | 2 +- include/window.hpp | 4 +- renderer/CMakeLists.txt | 97 +++++++++++++++++++++++++ 18 files changed, 119 insertions(+), 22 deletions(-) create mode 100644 renderer/CMakeLists.txt diff --git a/include/components/camera.hpp b/include/components/camera.hpp index 8c7d9f8..e4b1874 100644 --- a/include/components/camera.hpp +++ b/include/components/camera.hpp @@ -13,7 +13,7 @@ namespace components { -class DECLSPEC Camera : public Component { +class ENGINE_API Camera : public Component { public: Camera(Object* parent); diff --git a/include/components/component.hpp b/include/components/component.hpp index cf0ea36..c6348f1 100644 --- a/include/components/component.hpp +++ b/include/components/component.hpp @@ -7,7 +7,7 @@ class Window; class Input; class ResourceManager; -class DECLSPEC Component { +class ENGINE_API Component { public: diff --git a/include/components/custom.hpp b/include/components/custom.hpp index 505d9d5..289a66e 100644 --- a/include/components/custom.hpp +++ b/include/components/custom.hpp @@ -8,7 +8,7 @@ namespace components { - class DECLSPEC CustomComponent : public Component { + class ENGINE_API CustomComponent : public Component { public: CustomComponent(Object* parent); diff --git a/include/components/mesh_renderer.hpp b/include/components/mesh_renderer.hpp index 8ad9aff..2ba163e 100644 --- a/include/components/mesh_renderer.hpp +++ b/include/components/mesh_renderer.hpp @@ -14,7 +14,7 @@ namespace components { -class DECLSPEC Renderer : public Component { +class ENGINE_API Renderer : public Component { public: Renderer(Object*); diff --git a/include/components/text_ui_renderer.hpp b/include/components/text_ui_renderer.hpp index b2ac461..176e428 100644 --- a/include/components/text_ui_renderer.hpp +++ b/include/components/text_ui_renderer.hpp @@ -11,7 +11,7 @@ namespace components { -class DECLSPEC UI : public Component { +class ENGINE_API UI : public Component { public: UI(Object*); diff --git a/include/components/transform.hpp b/include/components/transform.hpp index 7aeed1c..f2b1ea5 100644 --- a/include/components/transform.hpp +++ b/include/components/transform.hpp @@ -14,7 +14,7 @@ namespace components { -class DECLSPEC Transform : public Component { +class ENGINE_API Transform : public Component { // Scale, rotate (XYZ), translate diff --git a/include/export.h b/include/export.h index 7cfe1d1..366c7c1 100644 --- a/include/export.h +++ b/include/export.h @@ -1,13 +1,13 @@ #pragma once -#ifndef DECLSPEC +#ifndef ENGINE_API # ifdef _MSC_VER # ifdef ENGINE_EXPORTS -# define DECLSPEC __declspec(dllexport) +# define ENGINE_API __declspec(dllexport) # else -# define DECLSPEC __declspec(dllimport) +# define ENGINE_API __declspec(dllimport) # endif # else -# define DECLSPEC +# define ENGINE_API # endif -#endif \ No newline at end of file +#endif diff --git a/include/input.hpp b/include/input.hpp index 378178f..c3c9840 100644 --- a/include/input.hpp +++ b/include/input.hpp @@ -19,7 +19,7 @@ enum class InputDevice : int { }; // This class should be used to get platform/input-device independent input -class DECLSPEC Input { +class ENGINE_API Input { public: diff --git a/include/object.hpp b/include/object.hpp index 33edca8..22afa88 100644 --- a/include/object.hpp +++ b/include/object.hpp @@ -33,7 +33,7 @@ struct GameIO { // This object lives until it is deleted by its parent(s) or finally when the "Scene" is destroyed. // Therefore it is safe to return raw pointers -class DECLSPEC Object { +class ENGINE_API Object { public: Object(std::string name, Object* parent, SceneRoot& root, struct GameIO things); diff --git a/include/resource_manager.hpp b/include/resource_manager.hpp index 155345d..5baa20b 100644 --- a/include/resource_manager.hpp +++ b/include/resource_manager.hpp @@ -9,7 +9,7 @@ // Doesn't own resources, only holds weak_ptrs -class DECLSPEC ResourceManager { +class ENGINE_API ResourceManager { public: ResourceManager(); diff --git a/include/resources/font.hpp b/include/resources/font.hpp index dd3747a..82a5b96 100644 --- a/include/resources/font.hpp +++ b/include/resources/font.hpp @@ -12,7 +12,7 @@ namespace resources { -class DECLSPEC Font : public Resource { +class ENGINE_API Font : public Resource { public: diff --git a/include/resources/mesh.hpp b/include/resources/mesh.hpp index 330ddae..043f835 100644 --- a/include/resources/mesh.hpp +++ b/include/resources/mesh.hpp @@ -22,7 +22,7 @@ struct Vertex { namespace resources { -class DECLSPEC Mesh : public Resource { +class ENGINE_API Mesh : public Resource { public: Mesh(const std::vector& vertices); diff --git a/include/resources/resource.hpp b/include/resources/resource.hpp index 878d1a6..8bf4480 100644 --- a/include/resources/resource.hpp +++ b/include/resources/resource.hpp @@ -5,7 +5,7 @@ #include #include -class DECLSPEC Resource { +class ENGINE_API Resource { public: Resource(const std::filesystem::path& resPath, const std::string& type); diff --git a/include/resources/shader.hpp b/include/resources/shader.hpp index 4ea89c5..99951cd 100644 --- a/include/resources/shader.hpp +++ b/include/resources/shader.hpp @@ -13,7 +13,7 @@ namespace resources { -class DECLSPEC Shader : public Resource { +class ENGINE_API Shader : public Resource { public: Shader(const std::filesystem::path& resPath); diff --git a/include/resources/texture.hpp b/include/resources/texture.hpp index dbcb996..2a14ec1 100644 --- a/include/resources/texture.hpp +++ b/include/resources/texture.hpp @@ -8,7 +8,7 @@ namespace resources { -class DECLSPEC Texture : public Resource { +class ENGINE_API Texture : public Resource { private: diff --git a/include/sceneroot.hpp b/include/sceneroot.hpp index aa37be7..74b9e26 100644 --- a/include/sceneroot.hpp +++ b/include/sceneroot.hpp @@ -7,7 +7,7 @@ #include // Holds everything you would expect to find in a game scene -class DECLSPEC SceneRoot : public Object { +class ENGINE_API SceneRoot : public Object { public: // create a new empty scene diff --git a/include/window.hpp b/include/window.hpp index ef6181b..26f09f2 100644 --- a/include/window.hpp +++ b/include/window.hpp @@ -14,9 +14,9 @@ #include #include -DECLSPEC extern const uint64_t BILLION; +ENGINE_API extern const uint64_t BILLION; -class DECLSPEC Window { +class ENGINE_API Window { public: Window(const std::string& title); diff --git a/renderer/CMakeLists.txt b/renderer/CMakeLists.txt new file mode 100644 index 0000000..2152845 --- /dev/null +++ b/renderer/CMakeLists.txt @@ -0,0 +1,97 @@ +cmake_minimum_required(VERSION 3.4) + +# options + +project( + engine_renderer + LANGUAGES CXX + VERSION "0.1.0" +) + +add_library(${PROJECT_NAME} SHARED + + src/renderer.cpp + + # API + + include/renderer.hpp + +) + +# compiling options: + +target_compile_definitions(${PROJECT_NAME} PRIVATE DEFINITIONS "PROJECT_EXPORTS") + +set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 20) +set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD_REQUIRED ON) + +if (MSVC) + target_compile_options(${PROJECT_NAME} PRIVATE /W3) + target_compile_options(${PROJECT_NAME} PRIVATE /MP) +endif() + +target_include_directories(${PROJECT_NAME} PUBLIC include) +target_include_directories(${PROJECT_NAME} PRIVATE src) + +# Pass some project information into the source code +configure_file(config.h.in config.h) +target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_BINARY_DIR}) + +# libraries: + +# MinGW library if using it +if (MINGW) + target_link_libraries(${PROJECT_NAME} PUBLIC mingw32) +endif() + +# SDL2: +set(SDL2_DISABLE_INSTALL ON CACHE INTERNAL "" FORCE) +set(SDL_SHARED ON CACHE INTERNAL "" FORCE) +set(SDL_STATIC OFF CACHE INTERNAL "" FORCE) +set(SDL_TEST OFF CACHE INTERNAL "" FORCE) +set(BUILD_SHARED_LIBS ON) +add_subdirectory(dependencies/SDL) +target_include_directories(${PROJECT_NAME} PUBLIC dependencies/SDL/include) +target_link_libraries(${PROJECT_NAME} PUBLIC SDL2::SDL2) +target_link_libraries(${PROJECT_NAME} PUBLIC SDL2::SDL2main) + +# GLM: +set(BUILD_SHARED_LIBS OFF) +add_subdirectory(dependencies/glm) +target_include_directories(${PROJECT_NAME} PUBLIC dependencies/glm) + +# GLAD: +set(GLAD_PROFILE "core" CACHE INTERNAL "" FORCE) +set(GLAD_API "gl=3.3" CACHE INTERNAL "" FORCE) +if (CMAKE_BUILD_TYPE STREQUAL "Debug") + set(GLAD_GENERATOR "c-debug" CACHE INTERNAL "" FORCE) +else() + set(GLAD_GENERATOR "c" CACHE INTERNAL "" FORCE) +endif() +set(GLAD_SPEC "gl" CACHE INTERNAL "" FORCE) +set(BUILD_SHARED_LIBS OFF) +add_subdirectory(dependencies/glad) +set_property(TARGET glad PROPERTY POSITION_INDEPENDENT_CODE ON) +target_link_libraries(${PROJECT_NAME} PUBLIC glad) +target_include_directories(${PROJECT_NAME} PUBLIC dependencies/glad/include) + +# spdlog +set(SPDLOG_BUILD_SHARED ON CACHE INTERNAL "" FORCE) +set(BUILD_SHARED_LIBS ON) +add_subdirectory(dependencies/spdlog) +target_link_libraries(${PROJECT_NAME} PUBLIC spdlog) +target_include_directories(${PROJECT_NAME} PUBLIC dependencies/spdlog/include) + +# freetype +set(FT_DISABLE_ZLIB TRUE CACHE INTERNAL "" FORCE) +set(FT_DISABLE_BZIP2 TRUE CACHE INTERNAL "" FORCE) +set(FT_DISABLE_PNG TRUE CACHE INTERNAL "" FORCE) +set(FT_DISABLE_HARFBUZZ TRUE CACHE INTERNAL "" FORCE) +set(FT_DISABLE_BROTLI TRUE CACHE INTERNAL "" FORCE) +set(BUILD_SHARED_LIBS ON) +add_subdirectory(dependencies/freetype) +target_link_libraries(${PROJECT_NAME} PRIVATE freetype) +target_include_directories(${PROJECT_NAME} PRIVATE dependencies/freetype/include) + +# stb +target_include_directories(${PROJECT_NAME} PRIVATE dependencies/stb)