diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 8fec609b..95f2d53a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -109,7 +109,11 @@ jobs: working-directory: ${{github.workspace}}/build # Execute tests defined by the CMake configuration. # See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail - run: ctest + run: | + export DISPLAY=:99 + sudo Xvfb :99 -screen 0 800x600x24 & + sleep 5 + MESA_GL_VERSION_OVERRIDE=3.3 ctest --output-on-failure --verbose - name: buildArtifact uses: actions/upload-artifact@v4 @@ -154,7 +158,12 @@ jobs: working-directory: ${{github.workspace}}/build # Execute tests defined by the CMake configuration. # See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail - run: MESA_GL_VERSION_OVERRIDE=3.3 ctest --exclude-regex Vulkan + run: | + cp *.dll TestAssetStore/ + export DISPLAY=:99 + sudo Xvfb :99 -screen 0 800x600x24 & + sleep 5 + MESA_GL_VERSION_OVERRIDE=3.3 ctest --output-on-failure --verbose --exclude-regex Vulkan - name: buildArtifact uses: actions/upload-artifact@v4 @@ -204,7 +213,7 @@ jobs: working-directory: ${{github.workspace}}/build # Execute tests defined by the CMake configuration. # See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail - run: MESA_GL_VERSION_OVERRIDE=3.3 ctest --exclude-regex Vulkan + run: MESA_GL_VERSION_OVERRIDE=3.3 ctest --output-on-failure --verbose --exclude-regex Vulkan --exclude-regex assetStore - name: buildArtifact uses: actions/upload-artifact@v4 diff --git a/include/Util/assetStore.h b/include/Util/assetStore.h new file mode 100644 index 00000000..3da7c380 --- /dev/null +++ b/include/Util/assetStore.h @@ -0,0 +1,88 @@ +#ifndef ASSETSTORE_H +#define ASSETSTORE_H + +#include +#include + +#include +#include +#include +#include + +namespace Hop::Util::Assets +{ + template + class AssetStore + { + public: + + AssetStore(std::filesystem::path root) + : root(root) + {} + + void scan() + { + if (std::filesystem::is_directory(root)) + { + scanDirectory(root); + } + }; + + virtual void load(std::filesystem::path assetPath) = 0; + + std::shared_ptr get(std::filesystem::path relative_path) { return assets[relative_path]; } + + typename std::map>::const_iterator begin() { return assets.cbegin(); } + typename std::map>::const_iterator end() { return assets.cend(); } + + protected: + std::filesystem::path root; + std::map> assets; + + virtual bool matchesAssetType(std::filesystem::path file) = 0; + + void scanDirectory(std::filesystem::path dir) + { + for (auto const & entry : std::filesystem::directory_iterator{dir}) + { + if (entry.is_regular_file()) + { + if (matchesAssetType(entry)) { load(entry); } + } + else + { + scanDirectory(entry); + } + } + } + }; + + class TextureAssetStore : public AssetStore + { + public: + + TextureAssetStore(std::filesystem::path root, std::unique_ptr & instance) + : AssetStore(root), instance(instance) + {} + + void load(std::filesystem::path assetPath) + { + std::filesystem::path relative = std::filesystem::relative(assetPath, root); + assets[relative] = instance->createTexture + ( + assetPath.generic_string(), + jGL::Texture::Type::RGBA + ); + }; + + protected: + std::unique_ptr & instance; + + bool matchesAssetType(std::filesystem::path file) + { + static std::vector extensions = {".png"}; + return std::find(extensions.begin(), extensions.end(), file.extension().generic_string()) != extensions.end(); + } + }; +} +#endif /* ASSETSTORE_H */ diff --git a/tests/regression/CMakeLists.txt b/tests/regression/CMakeLists.txt index 31222f4e..995c939a 100644 --- a/tests/regression/CMakeLists.txt +++ b/tests/regression/CMakeLists.txt @@ -1 +1,2 @@ -add_subdirectory(scriptPack) \ No newline at end of file +add_subdirectory(scriptPack) +add_subdirectory(assets) \ No newline at end of file diff --git a/tests/regression/assets/CMakeLists.txt b/tests/regression/assets/CMakeLists.txt new file mode 100644 index 00000000..5d809ddf --- /dev/null +++ b/tests/regression/assets/CMakeLists.txt @@ -0,0 +1,33 @@ +set(OUTPUT_NAME TestAssetStore) + +include_directories(.) + +if (WINDOWS) + if (RELEASE) + # launch as windows, not console app - so cmd does not open as well + add_link_options(-mwindows) + endif () +else() + # so nautilus etc recognise target as executable rather than .so + add_link_options(-no-pie) +endif() + +add_executable(${OUTPUT_NAME} "main.cpp") + +target_link_libraries(${OUTPUT_NAME} Hop) + +set_target_properties(${OUTPUT_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${OUTPUT_NAME}") + +file(COPY "resource" DESTINATION "${CMAKE_BINARY_DIR}/${OUTPUT_NAME}/") + +if (TEST_SUITE) + if(WINDOWS) + add_test(NAME assetStore COMMAND "${CMAKE_CROSSCOMPILING_EMULATOR}" "${CMAKE_BINARY_DIR}/${OUTPUT_NAME}/${OUTPUT_NAME}.exe") + else() + add_test(NAME assetStore COMMAND "/${CMAKE_BINARY_DIR}/${OUTPUT_NAME}/${OUTPUT_NAME}") + endif() + set_tests_properties(assetStore PROPERTIES + PASS_REGULAR_EXPRESSION "HEART\.png.*Pi\.png.*random\.png" + WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/${OUTPUT_NAME}/" + ) +endif() \ No newline at end of file diff --git a/tests/regression/assets/main.cpp b/tests/regression/assets/main.cpp new file mode 100644 index 00000000..afe44d1c --- /dev/null +++ b/tests/regression/assets/main.cpp @@ -0,0 +1,22 @@ +#include "main.h" +#include + +int main(int argc, char ** argv) +{ + + jGL::DesktopDisplay::Config conf; + conf.VULKAN = false; + conf.COCOA_RETINA = false; + + jGL::DesktopDisplay display(glm::ivec2(1,1),"Test TextureAssetStore", conf); + glewInit(); + std::unique_ptr jGLInstance = std::move(std::make_unique(display.getRes())); + Hop::Util::Assets::TextureAssetStore textureStore(std::filesystem::path("resource"), jGLInstance); + textureStore.scan(); + for (auto tex : textureStore) + { + std::cout << tex.first << " "; + } + + return 0; +} diff --git a/tests/regression/assets/main.h b/tests/regression/assets/main.h new file mode 100644 index 00000000..f60ea77a --- /dev/null +++ b/tests/regression/assets/main.h @@ -0,0 +1,10 @@ +#ifndef MAIN_H +#define MAIN_H + +#include +#include + +#include +#include + +#endif /* MAIN_H */ diff --git a/tests/regression/assets/resource/texture/HEART.png b/tests/regression/assets/resource/texture/HEART.png new file mode 100644 index 00000000..9d44ab97 Binary files /dev/null and b/tests/regression/assets/resource/texture/HEART.png differ diff --git a/tests/regression/assets/resource/texture/Pi.png b/tests/regression/assets/resource/texture/Pi.png new file mode 100644 index 00000000..c811289d Binary files /dev/null and b/tests/regression/assets/resource/texture/Pi.png differ diff --git a/tests/regression/assets/resource/texture/random.png b/tests/regression/assets/resource/texture/random.png new file mode 100644 index 00000000..8d5dc5b3 Binary files /dev/null and b/tests/regression/assets/resource/texture/random.png differ