From 3e7e6acc3ac6fe9327448060d696a52eb7dc5c48 Mon Sep 17 00:00:00 2001 From: NaifBanana <30419422+NaifBanana@users.noreply.github.com> Date: Sun, 19 Jul 2026 22:19:12 -0500 Subject: [PATCH] Made NBGraphics installable --- engine/NBGraphics/CMakeLists.txt | 96 +++++++++++++++---- engine/NBGraphics/NBGraphicsConfig.cmake.in | 2 + .../{ => include/NBGraphics}/Buffers.hpp | 4 +- .../{ => include/NBGraphics}/Camera.hpp | 2 +- .../{ => include/NBGraphics}/Draw.hpp | 8 +- .../{ => include/NBGraphics}/FrameBuffers.hpp | 8 +- .../{ => include/NBGraphics}/GLLoad.hpp | 0 .../{ => include/NBGraphics}/Image.hpp | 0 .../{ => include/NBGraphics}/OGLObjects.hpp | 2 +- .../NBGraphics}/ProgramPipeline.hpp | 4 +- .../{ => include/NBGraphics}/Textures.hpp | 6 +- .../{ => include/NBGraphics}/VertexArray.hpp | 6 +- .../{ => include/NBGraphics}/Window.hpp | 3 +- engine/NBGraphics/src/Buffers.cpp | 2 +- engine/NBGraphics/src/Camera.cpp | 2 +- engine/NBGraphics/src/Draw.cpp | 2 +- engine/NBGraphics/src/FrameBuffers.cpp | 2 +- engine/NBGraphics/src/Image.cpp | 2 +- engine/NBGraphics/src/OGLObjects.cpp | 2 +- engine/NBGraphics/src/ProgramPipeline.cpp | 2 +- engine/NBGraphics/src/Textures.cpp | 2 +- engine/NBGraphics/src/VertexArray.cpp | 4 +- engine/NBGraphics/src/Window.cpp | 2 +- engine/NBGraphics/tests/CMakeLists.txt | 1 - engine/NBGraphics/tests/TestWindow.cpp | 12 +-- engine/NBGraphics/tests/testImages.cpp | 2 +- 26 files changed, 116 insertions(+), 62 deletions(-) create mode 100644 engine/NBGraphics/NBGraphicsConfig.cmake.in rename engine/NBGraphics/{ => include/NBGraphics}/Buffers.hpp (98%) rename engine/NBGraphics/{ => include/NBGraphics}/Camera.hpp (98%) rename engine/NBGraphics/{ => include/NBGraphics}/Draw.hpp (94%) rename engine/NBGraphics/{ => include/NBGraphics}/FrameBuffers.hpp (97%) rename engine/NBGraphics/{ => include/NBGraphics}/GLLoad.hpp (100%) rename engine/NBGraphics/{ => include/NBGraphics}/Image.hpp (100%) rename engine/NBGraphics/{ => include/NBGraphics}/OGLObjects.hpp (94%) rename engine/NBGraphics/{ => include/NBGraphics}/ProgramPipeline.hpp (97%) rename engine/NBGraphics/{ => include/NBGraphics}/Textures.hpp (96%) rename engine/NBGraphics/{ => include/NBGraphics}/VertexArray.hpp (97%) rename engine/NBGraphics/{ => include/NBGraphics}/Window.hpp (97%) diff --git a/engine/NBGraphics/CMakeLists.txt b/engine/NBGraphics/CMakeLists.txt index 31090ba..49d3e76 100644 --- a/engine/NBGraphics/CMakeLists.txt +++ b/engine/NBGraphics/CMakeLists.txt @@ -1,14 +1,24 @@ -find_package(OpenGL) -add_subdirectory(${GLFW_PATH} ${GLFW_PATH}/build) +cmake_minimum_required(VERSION 3.10) +project(NBGraphics VERSION 0.1) -include_directories( - ${GLFW_PATH}/include - ${GLAD_PATH}/include - ${STBIMAGE_PATH} +set(GLAD_PATH ${NBENGINE_ROOT}/../glad/) +set(STBIMAGE_PATH ${NBENGINE_ROOT}/../stbi_image) +get_filename_component(GLAD_PATH ${GLAD_PATH} ABSOLUTE) +get_filename_component(STBIMAGE_PATH ${STBIMAGE_PATH} ABSOLUTE) + +set(CMAKE_PREFIX_PATH + "${CMAKE_PREFIX_PATH}" + "C:/Program Files (x86)/GLFW/lib/cmake/glfw3/" ) +find_package(OpenGL REQUIRED) +find_package(glfw3 REQUIRED) set(GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE) -set(GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE) +if (NB_BUILD_TESTS) + set(GLFW_BUILD_TESTS ON CACHE BOOL "" FORCE) +else() + set(GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE) +endif() set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE) toAbsolutePath(NB_GRAPHICS_SOURCE @@ -21,19 +31,18 @@ toAbsolutePath(NB_GRAPHICS_SOURCE ./src/VertexArray.cpp ./src/Window.cpp ) - toAbsolutePath(NB_GRAPHICS_INCLUDE - ./Buffers.hpp - ./Camera.hpp - ./Draw.hpp - ./FrameBuffers.hpp - ./GLLoad.hpp - ./Image.hpp - ./OGLObjects.hpp - ./ProgramPipeline.hpp - ./Textures.hpp - ./VertexArray.hpp - ./Window.hpp + ./include/NBGraphics/Buffers.hpp + ./include/NBGraphics/Camera.hpp + ./include/NBGraphics/Draw.hpp + ./include/NBGraphics/FrameBuffers.hpp + ./include/NBGraphics/GLLoad.hpp + ./include/NBGraphics/Image.hpp + ./include/NBGraphics/OGLObjects.hpp + ./include/NBGraphics/ProgramPipeline.hpp + ./include/NBGraphics/Textures.hpp + ./include/NBGraphics/VertexArray.hpp + ./include/NBGraphics/Window.hpp ) set(NB_GRAPHICS_SOURCE ${NB_GRAPHICS_SOURCE} PARENT_SCOPE) @@ -43,9 +52,54 @@ add_library(NBGraphics ${NB_GRAPHICS_SOURCE} ${GLAD_PATH}/src/glad.c ) -target_link_libraries(NBGraphics glfw) +add_library(NBEngine::Graphics ALIAS NBGraphics) +target_link_libraries(NBGraphics + PUBLIC glfw + PUBLIC NBCore +) +get_target_property(GLFW_INTERFACE_INCLUDES glfw INTERFACE_INCLUDE_DIRECTORIES) +#include_directories(${GLFW_INTERFACE_INCLUDES}) +target_include_directories(NBGraphics + PUBLIC "$" + PUBLIC "$" + PUBLIC "${STBIMAGE_PATH}" + PUBLIC "${GLAD_PATH}/include" +) -target_include_directories(NBGraphics PUBLIC ./.) +if (NBENGINE_INSTALL) + message("Installing NBGraphics to ${CMAKE_INSTALL_PREFIX}") + include(GNUInstallDirs) + include(CMakePackageConfigHelpers) + install( + TARGETS NBGraphics + EXPORT NBGraphicsTargets + ) + install( + DIRECTORY "${PROJECT_SOURCE_DIR}/include/NBGraphics" + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" + FILES_MATCHING PATTERN "*.h" PATTERN "*.hpp" + ) + install( + EXPORT NBGraphicsTargets + DESTINATION ${CMAKE_INSTALL_PREFIX}/cmake + NAMESPACE NBEngine:: + ) + configure_package_config_file( + "NBGraphicsConfig.cmake.in" + "NBGraphicsConfig.cmake" + INSTALL_DESTINATION ${CMAKE_INSTALL_PREFIX}/cmake + PATH_VARS CMAKE_INSTALL_LIBDIR + ) + write_basic_package_version_file( + "${CMAKE_CURRENT_BINARY_DIR}/NBGraphicsConfigVersion.cmake" + COMPATIBILITY AnyNewerVersion + ) + install(FILES + "${CMAKE_CURRENT_BINARY_DIR}/NBGraphicsConfig.cmake" + "${CMAKE_CURRENT_BINARY_DIR}/NBGraphicsConfigVersion.cmake" + DESTINATION "${CMAKE_INSTALL_PREFIX}/cmake" + ) +endif() if (NB_BUILD_TESTS) add_subdirectory(./tests) diff --git a/engine/NBGraphics/NBGraphicsConfig.cmake.in b/engine/NBGraphics/NBGraphicsConfig.cmake.in new file mode 100644 index 0000000..bef4f69 --- /dev/null +++ b/engine/NBGraphics/NBGraphicsConfig.cmake.in @@ -0,0 +1,2 @@ +@PACKAGE_INIT@ +include("${CMAKE_CURRENT_LIST_DIR}/NBGraphicsTargets.cmake") \ No newline at end of file diff --git a/engine/NBGraphics/Buffers.hpp b/engine/NBGraphics/include/NBGraphics/Buffers.hpp similarity index 98% rename from engine/NBGraphics/Buffers.hpp rename to engine/NBGraphics/include/NBGraphics/Buffers.hpp index 31c5494..09d0244 100644 --- a/engine/NBGraphics/Buffers.hpp +++ b/engine/NBGraphics/include/NBGraphics/Buffers.hpp @@ -2,7 +2,7 @@ #ifndef _NB_BUFFER #define _NB_BUFFER -#include "GLLoad.hpp" +#include #include @@ -10,7 +10,7 @@ #include #include -#include "OGLObjects.hpp" +#include namespace nb { diff --git a/engine/NBGraphics/Camera.hpp b/engine/NBGraphics/include/NBGraphics/Camera.hpp similarity index 98% rename from engine/NBGraphics/Camera.hpp rename to engine/NBGraphics/include/NBGraphics/Camera.hpp index 8e31c8c..4cef888 100644 --- a/engine/NBGraphics/Camera.hpp +++ b/engine/NBGraphics/include/NBGraphics/Camera.hpp @@ -2,7 +2,7 @@ #ifndef _NB_CAMERA #define _NB_CAMERA -#include "GLLoad.hpp" +#include #include #include diff --git a/engine/NBGraphics/Draw.hpp b/engine/NBGraphics/include/NBGraphics/Draw.hpp similarity index 94% rename from engine/NBGraphics/Draw.hpp rename to engine/NBGraphics/include/NBGraphics/Draw.hpp index a9be811..d94d1af 100644 --- a/engine/NBGraphics/Draw.hpp +++ b/engine/NBGraphics/include/NBGraphics/Draw.hpp @@ -2,16 +2,16 @@ #ifndef _NB_DRAW #define _NB_DRAW -#include +#include #include #include #include #include -#include "Buffers.h" -#include "Shader.h" -#include "VAOManager.hpp" +#include +#include +#include #define THROW_DRAW_ERROR(msg) throw DrawError(msg, __FILE__, __LINE__); diff --git a/engine/NBGraphics/FrameBuffers.hpp b/engine/NBGraphics/include/NBGraphics/FrameBuffers.hpp similarity index 97% rename from engine/NBGraphics/FrameBuffers.hpp rename to engine/NBGraphics/include/NBGraphics/FrameBuffers.hpp index c7efa25..54c57df 100644 --- a/engine/NBGraphics/FrameBuffers.hpp +++ b/engine/NBGraphics/include/NBGraphics/FrameBuffers.hpp @@ -2,13 +2,13 @@ #ifndef _NB_FRAMEBUFFER #define _NB_FRAMEBUFFER -#include "GLLoad.hpp" +#include #include -#include "Image.hpp" -#include "OGLObjects.hpp" -#include "Textures.hpp" +#include +#include +#include namespace nb { diff --git a/engine/NBGraphics/GLLoad.hpp b/engine/NBGraphics/include/NBGraphics/GLLoad.hpp similarity index 100% rename from engine/NBGraphics/GLLoad.hpp rename to engine/NBGraphics/include/NBGraphics/GLLoad.hpp diff --git a/engine/NBGraphics/Image.hpp b/engine/NBGraphics/include/NBGraphics/Image.hpp similarity index 100% rename from engine/NBGraphics/Image.hpp rename to engine/NBGraphics/include/NBGraphics/Image.hpp diff --git a/engine/NBGraphics/OGLObjects.hpp b/engine/NBGraphics/include/NBGraphics/OGLObjects.hpp similarity index 94% rename from engine/NBGraphics/OGLObjects.hpp rename to engine/NBGraphics/include/NBGraphics/OGLObjects.hpp index 1df966a..0f7d46c 100644 --- a/engine/NBGraphics/OGLObjects.hpp +++ b/engine/NBGraphics/include/NBGraphics/OGLObjects.hpp @@ -2,7 +2,7 @@ #ifndef _NB_OGL_OBJECTS #define _NB_OGL_OBJECTS -#include "GLLoad.hpp" +#include #include diff --git a/engine/NBGraphics/ProgramPipeline.hpp b/engine/NBGraphics/include/NBGraphics/ProgramPipeline.hpp similarity index 97% rename from engine/NBGraphics/ProgramPipeline.hpp rename to engine/NBGraphics/include/NBGraphics/ProgramPipeline.hpp index 260a771..229c7fe 100644 --- a/engine/NBGraphics/ProgramPipeline.hpp +++ b/engine/NBGraphics/include/NBGraphics/ProgramPipeline.hpp @@ -2,14 +2,14 @@ #ifndef _NB_SHADER #define _NB_SHADER -#include "GLLoad.hpp" +#include #include #include #include -#include "OGLObjects.hpp" +#include namespace nb { diff --git a/engine/NBGraphics/Textures.hpp b/engine/NBGraphics/include/NBGraphics/Textures.hpp similarity index 96% rename from engine/NBGraphics/Textures.hpp rename to engine/NBGraphics/include/NBGraphics/Textures.hpp index 433abc7..619deeb 100644 --- a/engine/NBGraphics/Textures.hpp +++ b/engine/NBGraphics/include/NBGraphics/Textures.hpp @@ -2,9 +2,9 @@ #ifndef _NB_TEXTURES #define _NB_TEXTURES -#include "Buffers.hpp" -#include "Image.hpp" -#include "OGLObjects.hpp" +#include +#include +#include namespace nb { diff --git a/engine/NBGraphics/VertexArray.hpp b/engine/NBGraphics/include/NBGraphics/VertexArray.hpp similarity index 97% rename from engine/NBGraphics/VertexArray.hpp rename to engine/NBGraphics/include/NBGraphics/VertexArray.hpp index a2e494d..a77b352 100644 --- a/engine/NBGraphics/VertexArray.hpp +++ b/engine/NBGraphics/include/NBGraphics/VertexArray.hpp @@ -2,12 +2,12 @@ #ifndef _NB_VERTEX_ARRAY #define _NB_VERTEX_ARRAY -#include "GLLoad.hpp" +#include #include -#include "Buffers.hpp" -#include "OGLObjects.hpp" +#include +#include namespace nb { diff --git a/engine/NBGraphics/Window.hpp b/engine/NBGraphics/include/NBGraphics/Window.hpp similarity index 97% rename from engine/NBGraphics/Window.hpp rename to engine/NBGraphics/include/NBGraphics/Window.hpp index b72cfa6..8a2ea55 100644 --- a/engine/NBGraphics/Window.hpp +++ b/engine/NBGraphics/include/NBGraphics/Window.hpp @@ -2,11 +2,10 @@ #ifndef _NB_WINDOW #define _NB_WINDOW -#include "GLLoad.hpp" +#include #include #include -#include #include #include diff --git a/engine/NBGraphics/src/Buffers.cpp b/engine/NBGraphics/src/Buffers.cpp index e6fdbda..072177b 100644 --- a/engine/NBGraphics/src/Buffers.cpp +++ b/engine/NBGraphics/src/Buffers.cpp @@ -1,4 +1,4 @@ -#include "Buffers.hpp" +#include namespace nb { diff --git a/engine/NBGraphics/src/Camera.cpp b/engine/NBGraphics/src/Camera.cpp index e7aa711..e52fe10 100644 --- a/engine/NBGraphics/src/Camera.cpp +++ b/engine/NBGraphics/src/Camera.cpp @@ -1,4 +1,4 @@ -#include "Camera.hpp" +#include namespace nb { diff --git a/engine/NBGraphics/src/Draw.cpp b/engine/NBGraphics/src/Draw.cpp index dc3fc05..5438287 100644 --- a/engine/NBGraphics/src/Draw.cpp +++ b/engine/NBGraphics/src/Draw.cpp @@ -1,4 +1,4 @@ -#include "Draw.h" +#include namespace NB{ diff --git a/engine/NBGraphics/src/FrameBuffers.cpp b/engine/NBGraphics/src/FrameBuffers.cpp index 4dcd893..a0458df 100644 --- a/engine/NBGraphics/src/FrameBuffers.cpp +++ b/engine/NBGraphics/src/FrameBuffers.cpp @@ -1,4 +1,4 @@ -#include "FrameBuffers.hpp" +#include namespace nb { diff --git a/engine/NBGraphics/src/Image.cpp b/engine/NBGraphics/src/Image.cpp index ea44ede..48b883a 100644 --- a/engine/NBGraphics/src/Image.cpp +++ b/engine/NBGraphics/src/Image.cpp @@ -1,4 +1,4 @@ -#include "Image.hpp" +#include using ImageErrorCodes = nb::ImageError::Codes; const std::string nb::ImageError::type = "nb::ImageError"; diff --git a/engine/NBGraphics/src/OGLObjects.cpp b/engine/NBGraphics/src/OGLObjects.cpp index 9ba59e6..b5777a6 100644 --- a/engine/NBGraphics/src/OGLObjects.cpp +++ b/engine/NBGraphics/src/OGLObjects.cpp @@ -1,4 +1,4 @@ -#include "OGLObjects.hpp" +#include namespace nb { diff --git a/engine/NBGraphics/src/ProgramPipeline.cpp b/engine/NBGraphics/src/ProgramPipeline.cpp index 783c49a..6fbc77f 100644 --- a/engine/NBGraphics/src/ProgramPipeline.cpp +++ b/engine/NBGraphics/src/ProgramPipeline.cpp @@ -1,4 +1,4 @@ -#include "ProgramPipeline.hpp" +#include namespace nb{ diff --git a/engine/NBGraphics/src/Textures.cpp b/engine/NBGraphics/src/Textures.cpp index dc77258..e16de71 100644 --- a/engine/NBGraphics/src/Textures.cpp +++ b/engine/NBGraphics/src/Textures.cpp @@ -1,4 +1,4 @@ -#include "Textures.hpp" +#include namespace nb { diff --git a/engine/NBGraphics/src/VertexArray.cpp b/engine/NBGraphics/src/VertexArray.cpp index f080e38..1740572 100644 --- a/engine/NBGraphics/src/VertexArray.cpp +++ b/engine/NBGraphics/src/VertexArray.cpp @@ -1,4 +1,4 @@ -#include "VertexArray.hpp" +#include namespace nb { @@ -177,7 +177,7 @@ VertexDataVec VertexGroup::dropBuffers() { VertexData VertexGroup::dropBuffer(size_t idx) { if (idx >= _vertex_data.size()) { - THROW(NBError(NBError::INDEX_ERROR)); + THROW(Error(Error<>::INDEX_ERROR)); } VertexDataVec tmp; VertexData ret; diff --git a/engine/NBGraphics/src/Window.cpp b/engine/NBGraphics/src/Window.cpp index 7cffeca..53259f8 100644 --- a/engine/NBGraphics/src/Window.cpp +++ b/engine/NBGraphics/src/Window.cpp @@ -1,4 +1,4 @@ -#include "Window.hpp" +#include namespace nb { diff --git a/engine/NBGraphics/tests/CMakeLists.txt b/engine/NBGraphics/tests/CMakeLists.txt index bc5f12f..6ee28e0 100644 --- a/engine/NBGraphics/tests/CMakeLists.txt +++ b/engine/NBGraphics/tests/CMakeLists.txt @@ -8,7 +8,6 @@ if (NB_BUILD_TESTS) ./TestWindow.cpp ) target_link_libraries(TestWindow - NBCore NBGraphics ) diff --git a/engine/NBGraphics/tests/TestWindow.cpp b/engine/NBGraphics/tests/TestWindow.cpp index 42dff78..cda33b0 100644 --- a/engine/NBGraphics/tests/TestWindow.cpp +++ b/engine/NBGraphics/tests/TestWindow.cpp @@ -1,12 +1,12 @@ -#include "GLLoad.hpp" +#include #define STB_IMAGE_IMPLEMENTATION #include "stb_image.h" -#include "Image.hpp" -#include "ProgramPipeline.hpp" -#include "VertexArray.hpp" -#include "Window.hpp" -#include "Textures.hpp" +#include +#include +#include +#include +#include int main() { nb::logger.log("Howdy!"); diff --git a/engine/NBGraphics/tests/testImages.cpp b/engine/NBGraphics/tests/testImages.cpp index c7f5627..351975f 100644 --- a/engine/NBGraphics/tests/testImages.cpp +++ b/engine/NBGraphics/tests/testImages.cpp @@ -5,7 +5,7 @@ #define STB_IMAGE_IMPLEMENTATION #include "stb_image.h" -#include "Image.hpp" +#include TEST(TestImage, SinglePixel) { using RGB = nb::Pixel;