diff --git a/.vscode/launch.json b/.vscode/launch.json index 39f778c..cfa3daa 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -24,5 +24,29 @@ "traceResponse": true } }, + { + "name": "Editor (Linux)", + "type": "cppdbg", + "request": "launch", + "program": "${workspaceRoot}/bin/Editor", + "args": [], + "stopAtEntry": false, + "cwd": "${workspaceRoot}/bin", + "environment": [], + "externalConsole": false, + "MIMode": "gdb", + "setupCommands": [ + { + "description": "Enable pretty-printing for gdb", + "text": "-enable-pretty-printing", + "ignoreFailures": true + }, + { + "description": "Set Disassembly Flavor to Intel", + "text": "-gdb-set disassembly-flavor intel", + "ignoreFailures": true + } + ] + }, ] } \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 71ff025..807455c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -124,14 +124,20 @@ if(MSVC) Seele.natvis DESTINATION .) else() - target_compile_options(Engine PUBLIC -g -Wall -Wextra -Wno-delete-incomplete -pedantic -std=c++20) + target_compile_options(Engine PUBLIC -g -Wall -Wextra -Wno-error -pedantic -std=c++20 -Wno-missing-field-initializers -Wno-unused-function) + target_compile_options(Editor PUBLIC -g -Wall -Wextra -Wno-error -pedantic -std=c++20) endif() add_subdirectory(src/) +set(COPY_DLL_COMMAND "true") +if(WIN32) + set(COPY_DLL_COMMAND "copy $ $") +endif() + add_custom_target(SeeleEngine ALL COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/res $ - COMMAND ${CMAKE_COMMAND} -E copy $ $ + COMMAND ${CMAKE_COMMAND} -E ${COPY_DLL_COMMAND} COMMAND_EXPAND_LISTS DEPENDS Editor slang-build) diff --git a/cmake/SuperBuild.cmake b/cmake/SuperBuild.cmake index 205e785..eb8e56c 100644 --- a/cmake/SuperBuild.cmake +++ b/cmake/SuperBuild.cmake @@ -54,6 +54,10 @@ add_subdirectory(${GLFW_ROOT}) add_subdirectory(${ENTT_ROOT}) #--------------thread-pool------------------------------ +set(TP_BUILD_TESTS OFF) +set(TP_BUILD_EXAMPLES OFF) +set(TP_BUILD_BENCHMARKS OFF) + add_subdirectory(${THREADPOOL_ROOT}) if(MSVC) @@ -63,39 +67,49 @@ endif() #--------------SLang------------------------------ string(TOLOWER release_x64 SLANG_CONFIG) if(WIN32) -string(TOLOWER ${SLANG_ROOT}/bin/windows-${CMAKE_PLATFORM}/release SLANG_BINARY_DIR) +string(TOLOWER ${SLANG_ROOT}/bin/windows-x64/release SLANG_BINARY_DIR) ExternalProject_Add(slang-build SOURCE_DIR ${SLANG_ROOT} BINARY_DIR ${SLANG_ROOT} CONFIGURE_COMMAND ${SLANG_ROOT}/premake.bat vs2019 --file=${SLANG_ROOT}/premake5.lua gmake --arch=x64 --deps=true - BUILD_COMMAND msbuild slang.sln -p:PlatformToolset=v143 -p:Configuration=Release -p:Platform=${CMAKE_PLATFORM} + BUILD_COMMAND msbuild slang.sln -p:PlatformToolset=v143 -p:Configuration=Release -p:Platform=x64 INSTALL_COMMAND "" ) elseif(UNIX) +set(SLANG_BINARY_DIR ${SLANG_ROOT}/bin/linux-x64/release) ExternalProject_Add(slang-build SOURCE_DIR ${SLANG_ROOT} BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR} - CONFIGURE_COMMAND ${CMAKE_SOURCE_DIR}/premake5 --file=${CMAKE_SOURCE_DIR}/external/slang/premake5.lua gmake2 --arch=x64 --deps=true --build-location=build/linux + CONFIGURE_COMMAND premake5 --file=${CMAKE_SOURCE_DIR}/external/slang/premake5.lua gmake2 --arch=x64 --deps=true --build-location=build/linux BUILD_COMMAND make -C ${CMAKE_SOURCE_DIR}/external/slang/build/linux config=${SLANG_CONFIG} INSTALL_COMMAND "" ) endif() add_library(slang-llvm SHARED IMPORTED) -target_link_libraries(slang-llvm INTERFACE - $ - $ -) -set_target_properties(slang-llvm PROPERTIES IMPORTED_IMPLIB ${SLANG_BINARY_DIR}/slang.lib) -set_target_properties(slang-llvm PROPERTIES IMPORTED_LOCATION ${SLANG_BINARY_DIR}/slang-llvm.dll) +if(WIN32) + target_link_libraries(slang-llvm INTERFACE + $ + $ + ) + set_target_properties(slang-llvm PROPERTIES IMPORTED_IMPLIB ${SLANG_BINARY_DIR}/slang.lib) + set_target_properties(slang-llvm PROPERTIES IMPORTED_LOCATION ${SLANG_BINARY_DIR}/slang-llvm.dll) +else() + set_target_properties(slang-llvm PROPERTIES IMPORTED_LOCATION ${SLANG_BINARY_DIR}/libslang-llvm.so) +endif() add_library(slang-glslang SHARED IMPORTED) -target_link_libraries(slang-glslang INTERFACE - $ - $ -) -set_target_properties(slang-glslang PROPERTIES IMPORTED_IMPLIB ${SLANG_BINARY_DIR}/slang.lib) -set_target_properties(slang-glslang PROPERTIES IMPORTED_LOCATION ${SLANG_BINARY_DIR}/slang-glslang.dll) + +if(WIN32) + target_link_libraries(slang-glslang INTERFACE + $ + $ + ) + set_target_properties(slang-glslang PROPERTIES IMPORTED_IMPLIB ${SLANG_BINARY_DIR}/slang.lib) + set_target_properties(slang-glslang PROPERTIES IMPORTED_LOCATION ${SLANG_BINARY_DIR}/slang-glslang.dll) +else() + set_target_properties(slang-glslang PROPERTIES IMPORTED_LOCATION ${SLANG_BINARY_DIR}/libslang-glslang.so) +endif() add_library(slang SHARED IMPORTED) @@ -103,14 +117,18 @@ target_include_directories(slang INTERFACE $ $ ) -target_link_libraries(slang INTERFACE - $ - $ -) +if(WIN32) + target_link_libraries(slang INTERFACE + $ + $ + ) + set_target_properties(slang PROPERTIES IMPORTED_IMPLIB ${SLANG_BINARY_DIR}/slang.lib) + set_target_properties(slang PROPERTIES IMPORTED_LOCATION ${SLANG_BINARY_DIR}/slang.dll) +else() + set_target_properties(slang PROPERTIES IMPORTED_LOCATION ${SLANG_BINARY_DIR}/libslang.so) +endif() target_link_libraries(slang INTERFACE slang-glslang) target_link_libraries(slang INTERFACE slang-llvm) -set_target_properties(slang PROPERTIES IMPORTED_IMPLIB ${SLANG_BINARY_DIR}/slang.lib) -set_target_properties(slang PROPERTIES IMPORTED_LOCATION ${SLANG_BINARY_DIR}/slang.dll) install(DIRECTORY ${SLANG_ROOT} diff --git a/external/slang b/external/slang index 4547125..cc22270 160000 --- a/external/slang +++ b/external/slang @@ -1 +1 @@ -Subproject commit 4547125ce945140dc10542e9606b225dd06159b8 +Subproject commit cc222702a8d7a1fccf8ad14b256570bcec1554ae diff --git a/premake5 b/premake5 index 0526ed6..bcb51ce 100755 Binary files a/premake5 and b/premake5 differ diff --git a/src/AssetViewer/main.cpp b/src/AssetViewer/main.cpp index 9aee2e7..4b5a1e8 100644 --- a/src/AssetViewer/main.cpp +++ b/src/AssetViewer/main.cpp @@ -10,7 +10,7 @@ using namespace Seele; AssetRegistry * instance = new AssetRegistry(); -int main(int argc, char** argv) +int main(int, char**) { //if(argc < 2) //{ diff --git a/src/Editor/Asset/MaterialLoader.cpp b/src/Editor/Asset/MaterialLoader.cpp index 8cb354a..d4b7ca9 100644 --- a/src/Editor/Asset/MaterialLoader.cpp +++ b/src/Editor/Asset/MaterialLoader.cpp @@ -51,7 +51,7 @@ void MaterialLoader::import(MaterialImportArgs args, PMaterialAsset asset) uint32 uniformBufferOffset = 0; uint32 bindingCounter = 0; // Uniform buffers are always binding 0 - uint32 uniformBinding = -1; + int32 uniformBinding = -1; Map expressions; uint32 key = 0; uint32 auxKey = 0; @@ -205,7 +205,7 @@ void MaterialLoader::import(MaterialImportArgs args, PMaterialAsset asset) mat.profile = obj["profile"].get(); for(auto& val : obj["values"].items()) { - mat.variables[val.key()] = val.value(); + mat.variables[val.key()] = referenceExpression(val.value()); } } } diff --git a/src/Editor/Asset/MeshLoader.cpp b/src/Editor/Asset/MeshLoader.cpp index 6518b33..7459c5a 100644 --- a/src/Editor/Asset/MeshLoader.cpp +++ b/src/Editor/Asset/MeshLoader.cpp @@ -6,6 +6,7 @@ #include "Asset/AssetImporter.h" #include "Asset/MaterialAsset.h" #include +#include #include #include #include @@ -249,13 +250,16 @@ void MeshLoader::loadGlobalMeshes(const aiScene* scene, const ArraycreateIndexBuffer(idxInfo); + Gfx::OIndexBuffer indexBuffer = graphics->createIndexBuffer(idxInfo); indexBuffer->transferOwnership(Gfx::QueueType::GRAPHICS); globalMeshes[meshIndex] = new Mesh(); globalMeshes[meshIndex]->vertexData = vertexData; globalMeshes[meshIndex]->id = id; - globalMeshes[meshIndex]->referencedMaterial = materials[mesh->mMaterialIndex]->getMaterial()->instantiate(); + globalMeshes[meshIndex]->referencedMaterial = materials[mesh->mMaterialIndex]->instantiate(InstantiationParameter{ + .name = std::format("{0}_Inst_0", materials[mesh->mMaterialIndex]->getName()), + .folderPath = materials[mesh->mMaterialIndex]->getFolderPath(), + }); globalMeshes[meshIndex]->meshlets = std::move(meshlets); globalMeshes[meshIndex]->vertexCount = mesh->mNumVertices; } diff --git a/src/Editor/Asset/TextureLoader.cpp b/src/Editor/Asset/TextureLoader.cpp index 3442e5c..a4e4fca 100644 --- a/src/Editor/Asset/TextureLoader.cpp +++ b/src/Editor/Asset/TextureLoader.cpp @@ -3,10 +3,15 @@ #include "Graphics/Graphics.h" #include "Asset/AssetRegistry.h" #include "Graphics/Vulkan/Enums.h" +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wsign-compare" +#pragma GCC diagnostic ignored "-Wunused-but-set-variable" +#pragma GCC diagnostic ignored "-Wunused-variable" #define STB_IMAGE_IMPLEMENTATION #include #define STB_IMAGE_WRITE_IMPLEMENTATION #include +#pragma GCC diagnostic pop #include "ktx.h" using namespace Seele; @@ -17,7 +22,7 @@ TextureLoader::TextureLoader(Gfx::PGraphics graphics) OTextureAsset placeholder = new TextureAsset(); placeholderAsset = placeholder; import(TextureImportArgs{ - .filePath = std::filesystem::absolute("./textures/placeholder.png"), + .filePath = std::filesystem::absolute("textures/placeholder.png"), .importPath = "", }, placeholderAsset); AssetRegistry::get().assetRoot->textures[""] = std::move(placeholder); @@ -46,10 +51,9 @@ PTextureAsset TextureLoader::getPlaceholderTexture() void TextureLoader::import(TextureImportArgs args, PTextureAsset textureAsset) { - - int totalWidth, totalHeight, n; + int totalWidth = 0, totalHeight = 0, n = 0; unsigned char* data = stbi_load(args.filePath.string().c_str(), &totalWidth, &totalHeight, &n, 4); - ktxTexture2* kTexture; + ktxTexture2* kTexture = nullptr; ktxTextureCreateInfo createInfo; createInfo.vkFormat = VK_FORMAT_R8G8B8A8_UNORM; createInfo.baseDepth = 1; @@ -61,7 +65,7 @@ void TextureLoader::import(TextureImportArgs args, PTextureAsset textureAsset) if (args.type == TextureImportType::TEXTURE_CUBEMAP) { uint32 faceWidth = totalWidth / 4; - uint32 faceHeight = totalHeight / 3; + // uint32 faceHeight = totalHeight / 3; // Cube map createInfo.baseWidth = totalWidth / 4; createInfo.baseHeight = totalHeight / 3; @@ -75,9 +79,9 @@ void TextureLoader::import(TextureImportArgs args, PTextureAsset textureAsset) auto loadCubeFace = [&kTexture, &faceWidth, &totalWidth, &data](int xPos, int yPos, int faceName) { std::vector vec(faceWidth * faceWidth * 4); - for (int y = 0; y < faceWidth; ++y) + for (uint32 y = 0; y < faceWidth; ++y) { - for (int x = 0; x < faceWidth; ++x) + for (uint32 x = 0; x < faceWidth; ++x) { int imgX = x + (xPos * faceWidth); int imgY = y + (yPos * faceWidth); @@ -114,7 +118,7 @@ void TextureLoader::import(TextureImportArgs args, PTextureAsset textureAsset) .structSize = sizeof(ktxBasisParams), .uastc = false, .threadCount = std::thread::hardware_concurrency(), - .compressionLevel = 5, + .compressionLevel = 0, .qualityLevel = 0, }; diff --git a/src/Editor/Window/PlayView.cpp b/src/Editor/Window/PlayView.cpp index e7434bc..a9a6b35 100644 --- a/src/Editor/Window/PlayView.cpp +++ b/src/Editor/Window/PlayView.cpp @@ -5,7 +5,7 @@ using namespace Seele; using namespace Seele::Editor; PlayView::PlayView(Gfx::PGraphics graphics, PWindow window, const ViewportCreateInfo& createInfo, std::string dllPath) - : GameView(std::move(graphics), std::move(window), std::move(createInfo), dllPath) + : GameView(graphics, window, createInfo, dllPath) { } diff --git a/src/Editor/Window/SceneView.cpp b/src/Editor/Window/SceneView.cpp index 9534a6b..20f6d84 100644 --- a/src/Editor/Window/SceneView.cpp +++ b/src/Editor/Window/SceneView.cpp @@ -60,15 +60,11 @@ void SceneView::render() renderGraph.render(viewportCamera); } -static float cameraSpeed = 1; - void SceneView::keyCallback(KeyCode code, InputAction action, KeyModifier) { cameraSystem.keyCallback(code, action); } -static bool mouseDown = false; - void SceneView::mouseMoveCallback(double xPos, double yPos) { cameraSystem.mouseMoveCallback(xPos, yPos); diff --git a/src/Editor/Window/ViewportControl.cpp b/src/Editor/Window/ViewportControl.cpp index da7ff27..7738fdd 100644 --- a/src/Editor/Window/ViewportControl.cpp +++ b/src/Editor/Window/ViewportControl.cpp @@ -8,8 +8,8 @@ ViewportControl::ViewportControl(const URect& viewportDimensions, Vector initial : position(initialPos) , fieldOfView(glm::radians(70.f)) , aspectRatio(static_cast(viewportDimensions.size.x) / viewportDimensions.size.y) - , yaw(glm::pi()/-2.0f) , pitch(0) + , yaw(glm::pi()/-2.0f) { std::cout << yaw << " " << pitch << std::endl; } diff --git a/src/Editor/main.cpp b/src/Editor/main.cpp index 5092f2e..2180f72 100644 --- a/src/Editor/main.cpp +++ b/src/Editor/main.cpp @@ -12,6 +12,7 @@ #include "Asset/FontLoader.h" #include "Asset/AssetImporter.h" #include "Graphics/StaticMeshVertexData.h" +#include using namespace Seele; using namespace Seele::Editor; @@ -20,11 +21,17 @@ extern AssetRegistry* instance; int main() { - std::string outputPath = "C:/Users/Dynamitos/TrackClearGame"; - std::string cmakePath = "C:/Users/Dynamitos/TrackClearGame/cmake"; +#ifdef WIN32 + std::filesystem::path outputPath = "C:/Users/Dynamitos/TrackClearGame"; + std::filesystem::path sourcePath= "C:/Users/Dynamitos/TrackClear"; + std::filesystem::path binaryPath = sourcePath / "bin" / "TrackClear.dll"; +#else + std::filesystem::path outputPath = "/home/dynamitos/TrackClearGame"; + std::filesystem::path sourcePath= "/home/dynamitos/TrackClear"; + std::filesystem::path binaryPath = sourcePath / "cmake" / "libTrackClear.so"; +#endif std::string gameName = "TrackClear"; - std::string sourcePath = "C:/Users/Dynamitos/TrackClear/"; - std::string binaryPath = "C:/Users/Dynamitos/TrackClear/bin/TrackClear.dll"; + std::filesystem::path cmakePath = outputPath / "cmake"; Gfx::OGraphics graphics = new Vulkan::Graphics(); @@ -33,177 +40,177 @@ int main() StaticMeshVertexData* vd = StaticMeshVertexData::getInstance(); vd->init(graphics); PWindowManager windowManager = new WindowManager(); - AssetRegistry::init(std::string("C:/Users/Dynamitos/TrackClear/Assets"), graphics); + AssetRegistry::init(sourcePath / "Assets", graphics); AssetImporter::init(graphics, AssetRegistry::getInstance()); AssetImporter::importFont(FontImportArgs{ .filePath = "./fonts/Calibri.ttf", }); AssetImporter::importMesh(MeshImportArgs{ - .filePath = "C:/Users/Dynamitos/TrackClear/old_resources/models/arena.fbx", + .filePath = sourcePath / "old_resources/models/arena.fbx", }); AssetImporter::importMesh(MeshImportArgs{ - .filePath = "C:/Users/Dynamitos/TrackClear/old_resources/models/train.fbx", + .filePath = sourcePath / "old_resources/models/train.fbx", }); AssetImporter::importMesh(MeshImportArgs{ - .filePath = "C:/Users/Dynamitos/TrackClear/old_resources/models/bird.fbx", + .filePath= sourcePath / "old_resources/models/bird.fbx", }); AssetImporter::importMesh(MeshImportArgs{ - .filePath = "C:/Users/Dynamitos/TrackClear/old_resources/models/cube.fbx", + .filePath= sourcePath / "old_resources/models/cube.fbx", }); AssetImporter::importMesh(MeshImportArgs{ - .filePath = "C:/Users/Dynamitos/TrackClear/old_resources/models/flameThrower.fbx", + .filePath= sourcePath / "old_resources/models/flameThrower.fbx", }); AssetImporter::importMesh(MeshImportArgs{ - .filePath = "C:/Users/Dynamitos/TrackClear/old_resources/models/player.fbx", + .filePath= sourcePath / "old_resources/models/player.fbx", }); AssetImporter::importMesh(MeshImportArgs{ - .filePath = "C:/Users/Dynamitos/TrackClear/old_resources/models/shotgun.fbx", + .filePath= sourcePath / "old_resources/models/shotgun.fbx", }); AssetImporter::importMesh(MeshImportArgs{ - .filePath = "C:/Users/Dynamitos/TrackClear/old_resources/models/track.fbx", + .filePath= sourcePath / "old_resources/models/track.fbx", }); AssetImporter::importMesh(MeshImportArgs{ - .filePath = "C:/Users/Dynamitos/TrackClear/old_resources/models/zombie.fbx", + .filePath= sourcePath / "old_resources/models/zombie.fbx", }); AssetImporter::importTexture(TextureImportArgs{ - .filePath = "C:/Users/Dynamitos/TrackClear/old_resources/textures/Dirt.png", + .filePath= sourcePath / "old_resources/textures/Dirt.png", }); AssetImporter::importTexture(TextureImportArgs{ - .filePath = "C:/Users/Dynamitos/TrackClear/old_resources/textures/DirtGrass.png", + .filePath= sourcePath / "old_resources/textures/DirtGrass.png", }); AssetImporter::importTexture(TextureImportArgs{ - .filePath = "C:/Users/Dynamitos/TrackClear/old_resources/textures/Grass.png", + .filePath= sourcePath / "old_resources/textures/Grass.png", }); AssetImporter::importTexture(TextureImportArgs{ - .filePath = "C:/Users/Dynamitos/TrackClear/old_resources/textures/Ice.png", + .filePath= sourcePath / "old_resources/textures/Ice.png", }); AssetImporter::importTexture(TextureImportArgs{ - .filePath = "C:/Users/Dynamitos/TrackClear/old_resources/textures/Lava.png", + .filePath= sourcePath / "old_resources/textures/Lava.png", }); AssetImporter::importTexture(TextureImportArgs{ - .filePath = "C:/Users/Dynamitos/TrackClear/old_resources/textures/Obsidian.png", + .filePath= sourcePath / "old_resources/textures/Obsidian.png", }); AssetImporter::importTexture(TextureImportArgs{ - .filePath = "C:/Users/Dynamitos/TrackClear/old_resources/textures/Rocks.png", + .filePath= sourcePath / "old_resources/textures/Rocks.png", }); AssetImporter::importTexture(TextureImportArgs{ - .filePath = "C:/Users/Dynamitos/TrackClear/old_resources/textures/Sand.png", + .filePath= sourcePath / "old_resources/textures/Sand.png", }); AssetImporter::importTexture(TextureImportArgs{ - .filePath = "C:/Users/Dynamitos/TrackClear/old_resources/textures/Water.png", + .filePath= sourcePath / "old_resources/textures/Water.png", }); AssetImporter::importTexture(TextureImportArgs{ - .filePath = "C:/Users/Dynamitos/TrackClear/old_resources/textures/Wood.png", + .filePath= sourcePath / "old_resources/textures/Wood.png", }); AssetImporter::importTexture(TextureImportArgs{ - .filePath = "C:/Users/Dynamitos/TrackClear/old_resources/textures/level0/blendMap.png", + .filePath= sourcePath / "old_resources/textures/level0/blendMap.png", .importPath = "level0", }); AssetImporter::importTexture(TextureImportArgs{ - .filePath = "C:/Users/Dynamitos/TrackClear/old_resources/textures/level0/heightMap.png", + .filePath= sourcePath / "old_resources/textures/level0/heightMap.png", .importPath = "level0", }); AssetImporter::importTexture(TextureImportArgs{ - .filePath = "C:/Users/Dynamitos/TrackClear/old_resources/textures/level0/trackMap.png", + .filePath= sourcePath / "old_resources/textures/level0/trackMap.png", .importPath = "level0", }); AssetImporter::importMaterial(MaterialImportArgs{ - .filePath = "C:/Users/Dynamitos/TrackClear/old_resources/shaders/TerrainMaterial.json", + .filePath= sourcePath / "old_resources/shaders/TerrainMaterial.json", .importPath = "level0", }); AssetImporter::importTexture(TextureImportArgs{ - .filePath = "C:/Users/Dynamitos/TrackClear/old_resources/textures/level1/blendMap.png", + .filePath= sourcePath / "old_resources/textures/level1/blendMap.png", .importPath = "level1", }); AssetImporter::importTexture(TextureImportArgs{ - .filePath = "C:/Users/Dynamitos/TrackClear/old_resources/textures/level1/heightMap.png", + .filePath= sourcePath / "old_resources/textures/level1/heightMap.png", .importPath = "level1", }); AssetImporter::importTexture(TextureImportArgs{ - .filePath = "C:/Users/Dynamitos/TrackClear/old_resources/textures/level1/trackMap.png", + .filePath= sourcePath / "old_resources/textures/level1/trackMap.png", .importPath = "level1", }); AssetImporter::importTexture(TextureImportArgs{ - .filePath = "C:/Users/Dynamitos/TrackClear/old_resources/textures/level2/blendMap.png", + .filePath= sourcePath / "old_resources/textures/level2/blendMap.png", .importPath = "level2", }); AssetImporter::importTexture(TextureImportArgs{ - .filePath = "C:/Users/Dynamitos/TrackClear/old_resources/textures/level2/heightMap.png", + .filePath= sourcePath / "old_resources/textures/level2/heightMap.png", .importPath = "level2", }); AssetImporter::importTexture(TextureImportArgs{ - .filePath = "C:/Users/Dynamitos/TrackClear/old_resources/textures/level2/trackMap.png", + .filePath= sourcePath / "old_resources/textures/level2/trackMap.png", .importPath = "level2", }); AssetImporter::importTexture(TextureImportArgs{ - .filePath = "C:/Users/Dynamitos/TrackClear/old_resources/textures/level3/blendMap.png", + .filePath= sourcePath / "old_resources/textures/level3/blendMap.png", .importPath = "level3", }); AssetImporter::importTexture(TextureImportArgs{ - .filePath = "C:/Users/Dynamitos/TrackClear/old_resources/textures/level3/heightMap.png", + .filePath= sourcePath / "old_resources/textures/level3/heightMap.png", .importPath = "level3", }); AssetImporter::importTexture(TextureImportArgs{ - .filePath = "C:/Users/Dynamitos/TrackClear/old_resources/textures/level3/trackMap.png", + .filePath= sourcePath / "old_resources/textures/level3/trackMap.png", .importPath = "level3", }); AssetImporter::importTexture(TextureImportArgs{ - .filePath = "C:/Users/Dynamitos/TrackClear/old_resources/textures/level4/blendMap.png", + .filePath= sourcePath / "old_resources/textures/level4/blendMap.png", .importPath = "level4", }); AssetImporter::importTexture(TextureImportArgs{ - .filePath = "C:/Users/Dynamitos/TrackClear/old_resources/textures/level4/heightMap.png", + .filePath= sourcePath / "old_resources/textures/level4/heightMap.png", .importPath = "level4", }); AssetImporter::importTexture(TextureImportArgs{ - .filePath = "C:/Users/Dynamitos/TrackClear/old_resources/textures/level4/trackMap.png", + .filePath= sourcePath / "old_resources/textures/level4/trackMap.png", .importPath = "level4", }); AssetImporter::importTexture(TextureImportArgs{ - .filePath = "C:/Users/Dynamitos/TrackClear/old_resources/textures/level5/blendMap.png", + .filePath= sourcePath / "old_resources/textures/level5/blendMap.png", .importPath = "level5", }); AssetImporter::importTexture(TextureImportArgs{ - .filePath = "C:/Users/Dynamitos/TrackClear/old_resources/textures/level5/heightMap.png", + .filePath= sourcePath / "old_resources/textures/level5/heightMap.png", .importPath = "level5", }); AssetImporter::importTexture(TextureImportArgs{ - .filePath = "C:/Users/Dynamitos/TrackClear/old_resources/textures/level5/trackMap.png", + .filePath= sourcePath / "old_resources/textures/level5/trackMap.png", .importPath = "level5", }); AssetImporter::importTexture(TextureImportArgs{ - .filePath = "C:/Users/Dynamitos/TrackClear/old_resources/textures/level6/blendMap.png", + .filePath= sourcePath / "old_resources/textures/level6/blendMap.png", .importPath = "level6", }); AssetImporter::importTexture(TextureImportArgs{ - .filePath = "C:/Users/Dynamitos/TrackClear/old_resources/textures/level6/heightMap.png", + .filePath= sourcePath / "old_resources/textures/level6/heightMap.png", .importPath = "level6", }); AssetImporter::importTexture(TextureImportArgs{ - .filePath = "C:/Users/Dynamitos/TrackClear/old_resources/textures/level6/trackMap.png", + .filePath= sourcePath / "old_resources/textures/level6/trackMap.png", .importPath = "level6", }); AssetImporter::importTexture(TextureImportArgs{ - .filePath = "C:/Users/Dynamitos/TrackClear/old_resources/textures/level7/blendMap.png", + .filePath= sourcePath / "old_resources/textures/level7/blendMap.png", .importPath = "level7", }); AssetImporter::importTexture(TextureImportArgs{ - .filePath = "C:/Users/Dynamitos/TrackClear/old_resources/textures/level7/heightMap.png", + .filePath= sourcePath / "old_resources/textures/level7/heightMap.png", .importPath = "level7", }); AssetImporter::importTexture(TextureImportArgs{ - .filePath = "C:/Users/Dynamitos/TrackClear/old_resources/textures/level7/trackMap.png", + .filePath= sourcePath / "old_resources/textures/level7/trackMap.png", .importPath = "level7", }); AssetImporter::importTexture(TextureImportArgs{ - .filePath = "C:/Users/Dynamitos/TrackClear/old_resources/skyboxes/FS000_Day_01.png", + .filePath= sourcePath / "old_resources/skyboxes/FS000_Day_01.png", .type = TextureImportType::TEXTURE_CUBEMAP, }); AssetImporter::importTexture(TextureImportArgs{ - .filePath = "C:/Users/Dynamitos/TrackClear/old_resources/skyboxes/FS000_Night_01.png", + .filePath= sourcePath / "old_resources/skyboxes/FS000_Night_01.png", .type = TextureImportType::TEXTURE_CUBEMAP, }); @@ -220,7 +227,7 @@ int main() sceneViewInfo.dimensions.size.y = 720; sceneViewInfo.dimensions.offset.x = 0; sceneViewInfo.dimensions.offset.y = 0; - PGameView sceneView = new Editor::PlayView(graphics, window, sceneViewInfo, binaryPath); + OGameView sceneView = new Editor::PlayView(graphics, window, sceneViewInfo, binaryPath); //ViewportCreateInfo inspectorViewInfo; //inspectorViewInfo.dimensions.size.x = 640; @@ -235,16 +242,17 @@ int main() //export game std::filesystem::create_directories(outputPath); - std::system(std::format("cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -DGAME_TITLE=\"{}\" -DGAME_DESTINATION=\"{}\" -DGAME_BINARY=\"{}\" -P ./cmake/ExportProject.cmake", gameName, outputPath, binaryPath).c_str()); - std::system(std::format("cmake -S {} -B {}", cmakePath, cmakePath).c_str()); - std::system(std::format("cmake --build {}", cmakePath).c_str()); - std::filesystem::copy(std::filesystem::path(sourcePath) / "Assets", std::filesystem::path(outputPath) / "Assets", std::filesystem::copy_options::recursive); - std::filesystem::copy("shaders", std::filesystem::path(outputPath) / "shaders", std::filesystem::copy_options::recursive); - std::filesystem::copy("textures", std::filesystem::path(outputPath) / "textures", std::filesystem::copy_options::recursive); - std::filesystem::copy_file("assimp-vc143-mt.dll", std::filesystem::path(outputPath) / "assimp-vc143-mt.dll"); - std::filesystem::copy_file("slang.dll", std::filesystem::path(outputPath) / "slang.dll"); - std::filesystem::copy_file("slang-glslang.dll", std::filesystem::path(outputPath) / "slang-glslang.dll"); - std::filesystem::copy_file("slang-llvm.dll", std::filesystem::path(outputPath) / "slang-llvm.dll"); - + std::system(std::format("cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -DGAME_TITLE=\"{}\" -DGAME_DESTINATION=\"{}\" -DGAME_BINARY=\"{}\" -P ./cmake/ExportProject.cmake", gameName, outputPath.generic_string(), binaryPath.generic_string()).c_str()); + std::system(std::format("cmake -S {} -B {}", cmakePath.generic_string(), cmakePath.generic_string()).c_str()); + std::system(std::format("cmake --build {}", cmakePath.generic_string()).c_str()); + std::filesystem::copy(sourcePath / "Assets", outputPath / "Assets", std::filesystem::copy_options::recursive); + std::filesystem::copy("shaders", outputPath / "shaders", std::filesystem::copy_options::recursive); + std::filesystem::copy("textures", outputPath / "textures", std::filesystem::copy_options::recursive); +#ifdef WIN32 + std::filesystem::copy_file("assimp-vc143-mt.dll", outputPath / "assimp-vc143-mt.dll"); + std::filesystem::copy_file("slang.dll", outputPath / "slang.dll"); + std::filesystem::copy_file("slang-glslang.dll", outputPath / "slang-glslang.dll"); + std::filesystem::copy_file("slang-llvm.dll", outputPath / "slang-llvm.dll"); +#endif return 0; } \ No newline at end of file diff --git a/src/Engine/Actor/Entity.cpp b/src/Engine/Actor/Entity.cpp index 6282557..3b8bb4f 100644 --- a/src/Engine/Actor/Entity.cpp +++ b/src/Engine/Actor/Entity.cpp @@ -3,8 +3,8 @@ using namespace Seele; Entity::Entity(PScene scene) - : identifier(scene->createEntity()) - , scene(scene) + : scene(scene) + , identifier(scene->createEntity()) { } diff --git a/src/Engine/Asset/Asset.cpp b/src/Engine/Asset/Asset.cpp index da51349..a7fdd3a 100644 --- a/src/Engine/Asset/Asset.cpp +++ b/src/Engine/Asset/Asset.cpp @@ -12,9 +12,9 @@ Asset::Asset() { } Asset::Asset(std::string_view _folderPath, std::string_view _name) - : status(Status::Uninitialized) - , folderPath(_folderPath) + : folderPath(_folderPath) , name(_name) + , status(Status::Uninitialized) { if (folderPath.empty()) { diff --git a/src/Engine/Asset/AssetRegistry.cpp b/src/Engine/Asset/AssetRegistry.cpp index 07dfbda..ff72a96 100644 --- a/src/Engine/Asset/AssetRegistry.cpp +++ b/src/Engine/Asset/AssetRegistry.cpp @@ -31,7 +31,7 @@ PMeshAsset AssetRegistry::findMesh(const std::string &filePath) AssetFolder* folder = get().assetRoot; std::string fileName = filePath; size_t slashLoc = filePath.rfind("/"); - if(slashLoc != -1) + if(slashLoc != std::string::npos) { folder = get().getOrCreateFolder(filePath.substr(0, slashLoc)); fileName = filePath.substr(slashLoc+1, filePath.size()); @@ -44,7 +44,7 @@ PTextureAsset AssetRegistry::findTexture(const std::string &filePath) AssetFolder* folder = get().assetRoot; std::string fileName = filePath; size_t slashLoc = filePath.rfind("/"); - if (slashLoc != -1) + if (slashLoc != std::string::npos) { folder = get().getOrCreateFolder(filePath.substr(0, slashLoc)); fileName = filePath.substr(slashLoc + 1, filePath.size()); @@ -57,7 +57,7 @@ PFontAsset AssetRegistry::findFont(const std::string& filePath) AssetFolder* folder = get().assetRoot; std::string fileName = filePath; size_t slashLoc = filePath.rfind("/"); - if(slashLoc != -1) + if(slashLoc != std::string::npos) { folder = get().getOrCreateFolder(filePath.substr(0, slashLoc)); fileName = filePath.substr(slashLoc+1, filePath.size()); @@ -70,7 +70,7 @@ PMaterialAsset AssetRegistry::findMaterial(const std::string &filePath) AssetFolder* folder = get().assetRoot; std::string fileName = filePath; size_t slashLoc = filePath.rfind("/"); - if (slashLoc != -1) + if (slashLoc != std::string::npos) { folder = get().getOrCreateFolder(filePath.substr(0, slashLoc)); fileName = filePath.substr(slashLoc + 1, filePath.size()); @@ -78,6 +78,19 @@ PMaterialAsset AssetRegistry::findMaterial(const std::string &filePath) return folder->materials.at(fileName); } +PMaterialInstanceAsset AssetRegistry::findMaterialInstance(const std::string &filePath) +{ + AssetFolder* folder = get().assetRoot; + std::string fileName = filePath; + size_t slashLoc = filePath.rfind("/"); + if (slashLoc != std::string::npos) + { + folder = get().getOrCreateFolder(filePath.substr(0, slashLoc)); + fileName = filePath.substr(slashLoc + 1, filePath.size()); + } + return folder->instances.at(fileName); +} + std::ofstream AssetRegistry::createWriteStream(const std::filesystem::path& relativePath, std::ios_base::openmode openmode) { return get().internalCreateWriteStream(relativePath, openmode); @@ -356,7 +369,7 @@ AssetRegistry::AssetFolder* AssetRegistry::getOrCreateFolder(std::string fullPat while(!fullPath.empty()) { size_t slashLoc = fullPath.find("/"); - if(slashLoc == -1) + if(slashLoc == std::string::npos) { if (!result->children.contains(fullPath)) { diff --git a/src/Engine/Asset/AssetRegistry.h b/src/Engine/Asset/AssetRegistry.h index b9f2c17..1ce9ce8 100644 --- a/src/Engine/Asset/AssetRegistry.h +++ b/src/Engine/Asset/AssetRegistry.h @@ -75,6 +75,7 @@ private: Gfx::PGraphics graphics; ArchiveBuffer assetBuffer; bool release = false; + friend class MaterialAsset; friend class TextureLoader; friend class FontLoader; friend class MaterialLoader; diff --git a/src/Engine/Asset/FontAsset.cpp b/src/Engine/Asset/FontAsset.cpp index 4071cde..fab1011 100644 --- a/src/Engine/Asset/FontAsset.cpp +++ b/src/Engine/Asset/FontAsset.cpp @@ -30,7 +30,9 @@ void FontAsset::save(ArchiveBuffer& buffer) const Array textureData; ktxTexture2* kTexture; ktxTextureCreateInfo createInfo = { + .glInternalformat = 0, .vkFormat = (uint32_t)glyph.texture->getFormat(), + .pDfd = nullptr, .baseWidth = glyph.texture->getSizeX(), .baseHeight = glyph.texture->getSizeY(), .baseDepth = glyph.texture->getSizeZ(), diff --git a/src/Engine/Asset/LevelAsset.cpp b/src/Engine/Asset/LevelAsset.cpp index 538a578..75073d0 100644 --- a/src/Engine/Asset/LevelAsset.cpp +++ b/src/Engine/Asset/LevelAsset.cpp @@ -18,12 +18,12 @@ LevelAsset::~LevelAsset() } -void LevelAsset::save(ArchiveBuffer& buffer) const +void LevelAsset::save(ArchiveBuffer&) const { } -void LevelAsset::load(ArchiveBuffer& buffer) +void LevelAsset::load(ArchiveBuffer&) { } diff --git a/src/Engine/Asset/MaterialAsset.cpp b/src/Engine/Asset/MaterialAsset.cpp index 5cf5916..3107055 100644 --- a/src/Engine/Asset/MaterialAsset.cpp +++ b/src/Engine/Asset/MaterialAsset.cpp @@ -2,6 +2,7 @@ #include "Material/Material.h" #include "Graphics/Graphics.h" #include "MaterialInstanceAsset.h" +#include "Asset/AssetRegistry.h" using namespace Seele; @@ -30,13 +31,15 @@ void MaterialAsset::load(ArchiveBuffer& buffer) material->compile(); } -OMaterialInstanceAsset Seele::MaterialAsset::instantiate(const InstantiationParameter& params) +PMaterialInstanceAsset MaterialAsset::instantiate(const InstantiationParameter& params) { OMaterialInstance instance = material->instantiate(); instance->setBaseMaterial(this); OMaterialInstanceAsset asset = new MaterialInstanceAsset(params.folderPath, params.name); asset->setHandle(std::move(instance)); - return asset; + asset->setBase(this); + PMaterialInstanceAsset ref = asset; + AssetRegistry::get().saveAsset(ref, MaterialInstanceAsset::IDENTIFIER, ref->getFolderPath(), ref->getName()); + AssetRegistry::get().registerMaterialInstance(std::move(asset)); + return ref; } - - diff --git a/src/Engine/Asset/MaterialAsset.h b/src/Engine/Asset/MaterialAsset.h index ce38668..7aab9aa 100644 --- a/src/Engine/Asset/MaterialAsset.h +++ b/src/Engine/Asset/MaterialAsset.h @@ -20,7 +20,7 @@ public: virtual void save(ArchiveBuffer& buffer) const override; virtual void load(ArchiveBuffer& buffer) override; PMaterial getMaterial() const { return material; } - OMaterialInstanceAsset instantiate(const InstantiationParameter& params); + PMaterialInstanceAsset instantiate(const InstantiationParameter& params); private: OMaterial material; friend class MaterialLoader; diff --git a/src/Engine/Asset/MaterialInstanceAsset.h b/src/Engine/Asset/MaterialInstanceAsset.h index 3a14fa3..6995cbf 100644 --- a/src/Engine/Asset/MaterialInstanceAsset.h +++ b/src/Engine/Asset/MaterialInstanceAsset.h @@ -15,6 +15,7 @@ public: virtual void load(ArchiveBuffer& buffer) override; void setHandle(OMaterialInstance handle) { material = std::move(handle); } void setBase(PMaterialAsset base) { baseMaterial = base; } + PMaterialInstance getHandle() const { return material; } private: OMaterialInstance material; PMaterialAsset baseMaterial; diff --git a/src/Engine/Asset/MeshAsset.cpp b/src/Engine/Asset/MeshAsset.cpp index e05de62..dff7038 100644 --- a/src/Engine/Asset/MeshAsset.cpp +++ b/src/Engine/Asset/MeshAsset.cpp @@ -21,7 +21,6 @@ MeshAsset::~MeshAsset() void MeshAsset::save(ArchiveBuffer& buffer) const { Serialization::save(buffer, meshes); - } void MeshAsset::load(ArchiveBuffer& buffer) diff --git a/src/Engine/Asset/TextureAsset.cpp b/src/Engine/Asset/TextureAsset.cpp index 6370a35..8b73638 100644 --- a/src/Engine/Asset/TextureAsset.cpp +++ b/src/Engine/Asset/TextureAsset.cpp @@ -2,6 +2,7 @@ #include "Graphics/Graphics.h" #include "Window/WindowManager.h" #include "Graphics/Vulkan/Enums.h" +#include "Graphics/Texture.h" #include "ktx.h" using namespace Seele; @@ -22,7 +23,7 @@ TextureAsset::~TextureAsset() } -void TextureAsset::save(ArchiveBuffer& buffer) const +void TextureAsset::save(ArchiveBuffer&) const { /*ktxTexture2* kTexture; ktxTextureCreateInfo createInfo = { @@ -113,3 +114,8 @@ void TextureAsset::load(ArchiveBuffer& buffer) texture->transferOwnership(Gfx::QueueType::GRAPHICS); ktxTexture_Destroy(ktxTexture(kTexture)); } + +void TextureAsset::setTexture(Gfx::OTexture _texture) +{ + texture = std::move(_texture); +} diff --git a/src/Engine/Asset/TextureAsset.h b/src/Engine/Asset/TextureAsset.h index 784c17b..634376d 100644 --- a/src/Engine/Asset/TextureAsset.h +++ b/src/Engine/Asset/TextureAsset.h @@ -13,10 +13,7 @@ public: virtual ~TextureAsset(); virtual void save(ArchiveBuffer& buffer) const override; virtual void load(ArchiveBuffer& buffer) override; - void setTexture(Gfx::OTexture _texture) - { - texture = std::move(_texture); - } + void setTexture(Gfx::OTexture _texture); Gfx::PTexture getTexture() { return texture; diff --git a/src/Engine/Component/Camera.cpp b/src/Engine/Component/Camera.cpp index 6cefc83..588e619 100644 --- a/src/Engine/Component/Camera.cpp +++ b/src/Engine/Component/Camera.cpp @@ -8,8 +8,8 @@ using namespace Seele::Component; using namespace Seele::Math; Camera::Camera() - : bNeedsViewBuild(false) - , viewMatrix(Matrix4()) + : viewMatrix(Matrix4()) + , bNeedsViewBuild(false) { yaw = 0; pitch = 0; diff --git a/src/Engine/Component/Component.h b/src/Engine/Component/Component.h index d9cc2e7..1e593d3 100644 --- a/src/Engine/Component/Component.h +++ b/src/Engine/Component/Component.h @@ -21,7 +21,6 @@ struct Dependencies : public Dependencies namespace Component { -#pragma warning(disable: 4505) template static int accessComponent(Comp& comp); } diff --git a/src/Engine/Component/Mesh.h b/src/Engine/Component/Mesh.h index 7d2f6e9..7ea0f0d 100644 --- a/src/Engine/Component/Mesh.h +++ b/src/Engine/Component/Mesh.h @@ -2,6 +2,7 @@ #include "Asset/MeshAsset.h" #include "Graphics/VertexData.h" #include "Material/MaterialInstance.h" +#include "Graphics/Mesh.h" namespace Seele { @@ -9,9 +10,9 @@ namespace Component { struct Mesh { - VertexData* vertexData; - MeshId id; - PMaterialInstance instance; + PMeshAsset asset; + Mesh() {} + Mesh(PMeshAsset asset) : asset(asset) {} }; } // namespace Component } // namespace Seele diff --git a/src/Engine/Containers/Array.h b/src/Engine/Containers/Array.h index 37eb7ae..9a8e6c0 100644 --- a/src/Engine/Containers/Array.h +++ b/src/Engine/Containers/Array.h @@ -56,6 +56,11 @@ public: { return (int)(p - other.p); } + constexpr IteratorBase& operator+=(difference_type other) + { + p+=other; + return *this; + } constexpr bool operator<(const IteratorBase& other) const { return p < other.p; @@ -725,7 +730,7 @@ public: } StaticArray(T value) { - for (int i = 0; i < N; ++i) + for (size_t i = 0; i < N; ++i) { _data[i] = value; } @@ -736,7 +741,7 @@ public: { assert(init.size() == N); auto beg = init.begin(); - for (int i = 0; i < N; ++i) + for (size_t i = 0; i < N; ++i) { _data[i] = *beg; beg++; diff --git a/src/Engine/Containers/Map.h b/src/Engine/Containers/Map.h index 8ff3416..8b81723 100644 --- a/src/Engine/Containers/Map.h +++ b/src/Engine/Containers/Map.h @@ -209,17 +209,17 @@ public: constexpr Map(const Map& other) : nodeContainer(other.nodeContainer) , root(other.root) + , iteratorsDirty(true) , _size(other._size) , comp(other.comp) - , iteratorsDirty(true) { } constexpr Map(Map&& other) noexcept : nodeContainer(std::move(other.nodeContainer)) , root(std::move(other.root)) + , iteratorsDirty(true) , _size(std::move(other._size)) , comp(std::move(other.comp)) - , iteratorsDirty(true) { } constexpr ~Map() noexcept @@ -502,7 +502,7 @@ private: endIt = calcEndIterator(); iteratorsDirty = false; } - inline Iterator calcBeginIterator() const + constexpr Iterator calcBeginIterator() const { size_t beginIndex = root; Array beginTraversal; @@ -518,7 +518,7 @@ private: } return Iterator(beginIndex, &nodeContainer, std::move(beginTraversal)); } - inline Iterator calcEndIterator() const + constexpr Iterator calcEndIterator() const { size_t endIndex = root; Array endTraversal; diff --git a/src/Engine/Game.h b/src/Engine/Game.h index 36b1c53..2913093 100644 --- a/src/Engine/Game.h +++ b/src/Engine/Game.h @@ -8,7 +8,7 @@ namespace Seele class Game { public: - Game(AssetRegistry* registry) {} + Game(AssetRegistry*) {} virtual ~Game() {} virtual void setupScene(PScene scene, PSystemGraph graph) = 0; }; diff --git a/src/Engine/Graphics/CMakeLists.txt b/src/Engine/Graphics/CMakeLists.txt index 2ea9e45..3aa2cf5 100644 --- a/src/Engine/Graphics/CMakeLists.txt +++ b/src/Engine/Graphics/CMakeLists.txt @@ -32,6 +32,7 @@ target_sources(Engine Buffer.h DebugVertex.h Descriptor.h + Enums.h Graphics.h Initializer.h Mesh.h diff --git a/src/Engine/Graphics/Enums.cpp b/src/Engine/Graphics/Enums.cpp index 8aa47cb..7fa2a0e 100644 --- a/src/Engine/Graphics/Enums.cpp +++ b/src/Engine/Graphics/Enums.cpp @@ -110,6 +110,7 @@ FormatCompatibilityInfo Gfx::getFormatInfo(SeFormat format) .blockExtent = Vector(1, 1, 1), .texelsPerBlock = 1, }; + default: + throw new std::logic_error("not yet implemented"); } - throw new std::logic_error("not yet implemented"); } diff --git a/src/Engine/Graphics/Enums.h b/src/Engine/Graphics/Enums.h index fbddc34..cabc738 100644 --- a/src/Engine/Graphics/Enums.h +++ b/src/Engine/Graphics/Enums.h @@ -166,7 +166,7 @@ namespace Gfx static constexpr bool useAsyncCompute = true; static constexpr bool waitIdleOnSubmit = true; static constexpr bool useMeshShading = true; -static constexpr uint32 numFramesBuffered = 8; +static constexpr uint32 numFramesBuffered = 3; // meshlet dimensions curated by NVIDIA static constexpr uint32 numVerticesPerMeshlet = 64; diff --git a/src/Engine/Graphics/Mesh.cpp b/src/Engine/Graphics/Mesh.cpp index c374689..edcd265 100644 --- a/src/Engine/Graphics/Mesh.cpp +++ b/src/Engine/Graphics/Mesh.cpp @@ -1,5 +1,6 @@ #include "Mesh.h" #include "Graphics/Graphics.h" +#include "Asset/AssetRegistry.h" using namespace Seele; @@ -16,6 +17,7 @@ void Mesh::save(ArchiveBuffer& buffer) const Serialization::save(buffer, vertexData->getTypeName()); Serialization::save(buffer, vertexCount); Serialization::save(buffer, meshlets); + Serialization::save(buffer, referencedMaterial->getAssetIdentifier()); vertexData->serializeMesh(id, vertexCount, buffer); } @@ -26,6 +28,9 @@ void Mesh::load(ArchiveBuffer& buffer) Serialization::load(buffer, vertexCount); vertexData = VertexData::findByTypeName(typeName); Serialization::load(buffer, meshlets); + std::string refId; + Serialization::load(buffer, refId); + referencedMaterial = AssetRegistry::findMaterialInstance(refId); id = vertexData->allocateVertexData(vertexCount); vertexData->loadMesh(id, meshlets); vertexData->deserializeMesh(id, buffer); diff --git a/src/Engine/Graphics/Mesh.h b/src/Engine/Graphics/Mesh.h index fec3fb7..469e8d8 100644 --- a/src/Engine/Graphics/Mesh.h +++ b/src/Engine/Graphics/Mesh.h @@ -13,7 +13,7 @@ public: VertexData* vertexData; MeshId id; uint64 vertexCount; - PMaterialInstance referencedMaterial; + PMaterialInstanceAsset referencedMaterial; Array meshlets; void save(ArchiveBuffer& buffer) const; void load(ArchiveBuffer& buffer); @@ -23,12 +23,12 @@ DEFINE_REF(Mesh) namespace Serialization { template<> - static void save(ArchiveBuffer& buffer, const OMesh& ptr) + void save(ArchiveBuffer& buffer, const OMesh& ptr) { ptr->save(buffer); } template<> - static void load(ArchiveBuffer& buffer, OMesh& ptr) + void load(ArchiveBuffer& buffer, OMesh& ptr) { ptr = new Mesh(); ptr->load(buffer); diff --git a/src/Engine/Graphics/RenderPass/BasePass.cpp b/src/Engine/Graphics/RenderPass/BasePass.cpp index d835105..b875617 100644 --- a/src/Engine/Graphics/RenderPass/BasePass.cpp +++ b/src/Engine/Graphics/RenderPass/BasePass.cpp @@ -152,6 +152,6 @@ void BasePass::createRenderPass() tLightGrid = resources->requestTexture("LIGHTCULLING_TLIGHTGRID"); } -void BasePass::modifyRenderPassMacros(Map& defines) +void BasePass::modifyRenderPassMacros(Map&) { } diff --git a/src/Engine/Graphics/RenderPass/LightCullingPass.cpp b/src/Engine/Graphics/RenderPass/LightCullingPass.cpp index fbd96cb..a46ba2f 100644 --- a/src/Engine/Graphics/RenderPass/LightCullingPass.cpp +++ b/src/Engine/Graphics/RenderPass/LightCullingPass.cpp @@ -20,8 +20,6 @@ LightCullingPass::~LightCullingPass() void LightCullingPass::beginFrame(const Component::Camera& cam) { RenderPass::beginFrame(cam); - uint32_t viewportWidth = viewport->getSizeX(); - uint32_t viewportHeight = viewport->getSizeY(); uint32 reset = 0; DataSource counterReset = { diff --git a/src/Engine/Graphics/RenderPass/RenderPass.cpp b/src/Engine/Graphics/RenderPass/RenderPass.cpp index d58db43..7aa23bf 100644 --- a/src/Engine/Graphics/RenderPass/RenderPass.cpp +++ b/src/Engine/Graphics/RenderPass/RenderPass.cpp @@ -30,6 +30,7 @@ void RenderPass::beginFrame(const Component::Camera& cam) .projectionMatrix = viewport->getProjectionMatrix(), .cameraPosition = Vector4(cam.getCameraPosition(), 1), .screenDimensions = Vector2(static_cast(viewport->getSizeX()), static_cast(viewport->getSizeY())), + .pad0 = Vector2(0), }; DataSource uniformUpdate = { .size = sizeof(ViewParameter), diff --git a/src/Engine/Graphics/RenderTarget.h b/src/Engine/Graphics/RenderTarget.h index 5eafb8a..299d588 100644 --- a/src/Engine/Graphics/RenderTarget.h +++ b/src/Engine/Graphics/RenderTarget.h @@ -75,13 +75,13 @@ public: SeAttachmentStoreOp storeOp = SE_ATTACHMENT_STORE_OP_STORE, SeAttachmentLoadOp stencilLoadOp = SE_ATTACHMENT_LOAD_OP_DONT_CARE, SeAttachmentStoreOp stencilStoreOp = SE_ATTACHMENT_STORE_OP_DONT_CARE) - : loadOp(loadOp) + : clear() + , componentFlags(0) + , loadOp(loadOp) , storeOp(storeOp) , stencilLoadOp(stencilLoadOp) , stencilStoreOp(stencilStoreOp) , texture(texture) - , clear() - , componentFlags(0) { } virtual ~RenderTargetAttachment() diff --git a/src/Engine/Graphics/Shader.cpp b/src/Engine/Graphics/Shader.cpp index 484c72d..9e5dd8d 100644 --- a/src/Engine/Graphics/Shader.cpp +++ b/src/Engine/Graphics/Shader.cpp @@ -1,6 +1,7 @@ #include "Shader.h" #include "Graphics/RenderPass/DepthPrepass.h" #include "Graphics/RenderPass/BasePass.h" +#include using namespace Seele; using namespace Seele::Gfx; @@ -52,11 +53,9 @@ void ShaderCompiler::compile() for (const auto& [name, pass] : passes) { std::memset(&permutation, 0, sizeof(ShaderPermutation)); - permutation = { - .hasFragment = pass.hasFragmentShader, - .useMeshShading = pass.useMeshShading, - .hasTaskShader = pass.hasTaskShader, - }; + permutation.hasFragment = pass.hasFragmentShader; + permutation.useMeshShading = pass.useMeshShading; + permutation.hasTaskShader = pass.hasTaskShader; std::memcpy(permutation.vertexMeshFile, pass.mainFile.c_str(), sizeof(permutation.vertexMeshFile)); if (pass.hasFragmentShader) { diff --git a/src/Engine/Graphics/VertexData.cpp b/src/Engine/Graphics/VertexData.cpp index 83e6840..be1e86e 100644 --- a/src/Engine/Graphics/VertexData.cpp +++ b/src/Engine/Graphics/VertexData.cpp @@ -8,7 +8,7 @@ using namespace Seele; -constexpr static uint64 NUM_DEFAULT_ELEMENTS = 1024; +constexpr static uint64 NUM_DEFAULT_ELEMENTS = 1024 * 1024; void VertexData::resetMeshData() { @@ -19,13 +19,13 @@ void VertexData::resetMeshData() } } -void VertexData::updateMesh(const Component::Transform& transform, const Component::Mesh& mesh) +void VertexData::updateMesh(const Component::Transform& transform, PMesh mesh) { - PMaterial mat = mesh.instance->getBaseMaterial(); + PMaterial mat = mesh->referencedMaterial->getHandle()->getBaseMaterial(); MaterialData& matData = materialData[mat->getName()]; - MaterialInstanceData& matInstanceData = matData.instances[mesh.instance->getId()]; + MaterialInstanceData& matInstanceData = matData.instances[mesh->referencedMaterial->getHandle()->getId()]; matInstanceData.meshes.add(MeshInstanceData{ - .id = mesh.id, + .id = mesh->id, .instance = InstanceData { .transformMatrix = transform.toMatrix(), } @@ -45,10 +45,10 @@ void VertexData::loadMesh(MeshId id, Array loadedMeshlets) Meshlet& m = loadedMeshlets[currentMesh + i]; uint32 vertexOffset = vertexIndices.size(); vertexIndices.resize(vertexOffset + m.numVertices); - std::memcpy(vertexIndices.data() + vertexOffset, m.uniqueVertices.data(), sizeof(m.uniqueVertices)); + std::memcpy(vertexIndices.data() + vertexOffset, m.uniqueVertices.data(), m.numVertices * sizeof(uint32)); uint32 primitiveOffset = primitiveIndices.size(); primitiveIndices.resize(primitiveOffset + (m.numPrimitives * 3)); - std::memcpy(primitiveIndices.data() + primitiveOffset, m.primitiveLayout.data(), sizeof(m.primitiveLayout)); + std::memcpy(primitiveIndices.data() + primitiveOffset, m.primitiveLayout.data(), m.numPrimitives * 3 * sizeof(uint8)); meshlets.add(MeshletDescription{ .boundingBox = MeshletAABB(), .vertexCount = m.numVertices, @@ -193,9 +193,9 @@ void Seele::VertexData::init(Gfx::PGraphics graphics) VertexData::VertexData() : idCounter(0) - , dirty(false) , head(0) , verticesAllocated(0) + , dirty(false) { } diff --git a/src/Engine/Graphics/VertexData.h b/src/Engine/Graphics/VertexData.h index 9e67823..3513cc8 100644 --- a/src/Engine/Graphics/VertexData.h +++ b/src/Engine/Graphics/VertexData.h @@ -8,10 +8,7 @@ namespace Seele { -namespace Component -{ - struct Mesh; -} +DECLARE_REF(Mesh) struct MeshId { uint64 id; @@ -60,7 +57,7 @@ public: uint32 indicesOffset; }; void resetMeshData(); - void updateMesh(const Component::Transform& transform, const Component::Mesh& mesh); + void updateMesh(const Component::Transform& transform, PMesh mesh); void loadMesh(MeshId id, Array meshlets); void createDescriptors(); MeshId allocateVertexData(uint64 numVertices); diff --git a/src/Engine/Graphics/Vulkan/Allocator.cpp b/src/Engine/Graphics/Vulkan/Allocator.cpp index ff87c72..5c46108 100644 --- a/src/Engine/Graphics/Vulkan/Allocator.cpp +++ b/src/Engine/Graphics/Vulkan/Allocator.cpp @@ -18,22 +18,12 @@ SubAllocation::~SubAllocation() owner->markFree(this); } -constexpr VkDeviceMemory SubAllocation::getHandle() const +VkDeviceMemory SubAllocation::getHandle() const { return owner->getHandle(); } -constexpr VkDeviceSize SubAllocation::getSize() const -{ - return size; -} - -constexpr VkDeviceSize SubAllocation::getOffset() const -{ - return alignedOffset; -} - -constexpr bool SubAllocation::isReadable() const +bool SubAllocation::isReadable() const { return owner->isReadable(); } @@ -203,30 +193,6 @@ void Allocation::markFree(PSubAllocation allocation) } } -constexpr VkDeviceMemory Allocation::getHandle() const -{ - return allocatedMemory; -} - -constexpr void* Allocation::getMappedPointer() -{ - if (!canMap) - { - return nullptr; - } - if (!isMapped) - { - vkMapMemory(device, allocatedMemory, 0, bytesAllocated, 0, &mappedPointer); - isMapped = true; - } - return mappedPointer; -} - -constexpr bool Allocation::isReadable() const -{ - return readable; -} - void Allocation::flushMemory() { VkMappedMemoryRange range = { @@ -260,6 +226,7 @@ Allocator::Allocator(PGraphics graphics) VkMemoryHeap memoryHeap = memProperties.memoryHeaps[i]; HeapInfo heapInfo; heapInfo.maxSize = memoryHeap.size; + std::cout << "Creating heap " << i << " with properties " << memoryHeap.flags << " size " << memoryHeap.size << std::endl; heaps.add(std::move(heapInfo)); } } @@ -293,6 +260,7 @@ OSubAllocation Allocator::allocate(const VkMemoryRequirements2 &memRequirements2 { OAllocation newAllocation = new Allocation(graphics, this, requirements.size, memoryTypeIndex, properties, dedicatedInfo); heaps[heapIndex].inUse += newAllocation->bytesAllocated; + std::cout << "Heap " << heapIndex << " +" <bytesAllocated << ": " << (float)heaps[heapIndex].inUse / heaps[heapIndex].maxSize << "%" << std::endl; heaps[heapIndex].allocations.add(std::move(newAllocation)); return heaps[heapIndex].allocations.back()->getSuballocation(requirements.size, requirements.alignment); } @@ -312,7 +280,7 @@ OSubAllocation Allocator::allocate(const VkMemoryRequirements2 &memRequirements2 // no suitable allocations found, allocate new block OAllocation newAllocation = new Allocation(graphics, this, (requirements.size > MemoryBlockSize) ? requirements.size : (VkDeviceSize)MemoryBlockSize, memoryTypeIndex, properties, nullptr); heaps[heapIndex].inUse += newAllocation->bytesAllocated; - heaps[heapIndex].allocations.add(std::move(newAllocation)); + std::cout << "Heap " << heapIndex << " +" <bytesAllocated << ": " << (float)heaps[heapIndex].inUse / heaps[heapIndex].maxSize << "%" << std::endl; heaps[heapIndex].allocations.add(std::move(newAllocation)); return heaps[heapIndex].allocations.back()->getSuballocation(requirements.size, requirements.alignment); } @@ -321,12 +289,13 @@ void Allocator::free(Allocation *allocation) std::scoped_lock lck(lock); for (auto& heap : heaps) { - for (uint32 i = 0; i < heap.allocations.size(); ++i) + for (uint32 heapIndex = 0; heapIndex < heap.allocations.size(); ++heapIndex) { - if (heap.allocations[i] == allocation) + if (heap.allocations[heapIndex] == allocation) { heap.inUse -= allocation->bytesAllocated; - heap.allocations.removeAt(i, false); + std::cout << "Heap " << heapIndex << " -" <bytesAllocated << ":" << (float)heaps[heapIndex].inUse / heaps[heapIndex].maxSize << "%" << std::endl; + heap.allocations.removeAt(heapIndex, false); return; } } @@ -374,31 +343,21 @@ void StagingBuffer::invalidateMemory() allocation->invalidateMemory(); } -constexpr VkDeviceMemory StagingBuffer::getMemoryHandle() const +VkDeviceMemory StagingBuffer::getMemoryHandle() const { return allocation->getHandle(); } -constexpr VkDeviceSize StagingBuffer::getOffset() const +VkDeviceSize StagingBuffer::getOffset() const { return allocation->getOffset(); } -constexpr uint64 StagingBuffer::getSize() const +uint64 StagingBuffer::getSize() const { return allocation->getSize(); } -constexpr bool StagingBuffer::isReadable() const -{ - return readable; -} - -constexpr VkBufferUsageFlags StagingBuffer::getUsage() const -{ - return usage; -} - StagingManager::StagingManager(PGraphics graphics, PAllocator allocator) : graphics(graphics), allocator(allocator) { @@ -422,8 +381,9 @@ OStagingBuffer StagingManager::allocateStagingBuffer(uint64 size, VkBufferUsageF { //std::cout << "Reusing staging buffer" << std::endl; activeBuffers.add(freeBuffer); + OStagingBuffer owner = std::move(freeBuffer); freeBuffers.remove(it, false); - return std::move(freeBuffer); + return owner; } } //std::cout << "Creating new stagingbuffer" << std::endl; @@ -463,6 +423,8 @@ OStagingBuffer StagingManager::allocateStagingBuffer(uint64 size, VkBufferUsageF ); vkBindBufferMemory(graphics->getDevice(), buffer, stagingBuffer->getMemoryHandle(), stagingBuffer->getOffset()); + std::cout << "Creating new stagingbuffer size " << stagingBuffer->getSize() << std::endl; + activeBuffers.add(stagingBuffer); return stagingBuffer; @@ -471,6 +433,11 @@ OStagingBuffer StagingManager::allocateStagingBuffer(uint64 size, VkBufferUsageF void StagingManager::releaseStagingBuffer(OStagingBuffer buffer) { std::scoped_lock l(lock); + if(activeBuffers.find(buffer) == activeBuffers.end()) + { + return; + } activeBuffers.remove(buffer); + std::cout << "Releasing stagingbuffer size " << buffer->getSize() << std::endl; freeBuffers.add(std::move(buffer)); } \ No newline at end of file diff --git a/src/Engine/Graphics/Vulkan/Allocator.h b/src/Engine/Graphics/Vulkan/Allocator.h index dda6762..87a9991 100644 --- a/src/Engine/Graphics/Vulkan/Allocator.h +++ b/src/Engine/Graphics/Vulkan/Allocator.h @@ -17,10 +17,20 @@ class SubAllocation public: SubAllocation(PAllocation owner, VkDeviceSize allocatedOffset, VkDeviceSize size, VkDeviceSize alignedOffset, VkDeviceSize allocatedSize); ~SubAllocation(); - constexpr VkDeviceMemory getHandle() const; - constexpr VkDeviceSize getSize() const; - constexpr VkDeviceSize getOffset() const; - constexpr bool isReadable() const; + VkDeviceMemory getHandle() const; + + constexpr VkDeviceSize getSize() const + { + return size; + } + + constexpr VkDeviceSize getOffset() const + { + return alignedOffset; + } + + bool isReadable() const; + void *getMappedPointer(); void flushMemory(); void invalidateMemory(); @@ -43,9 +53,30 @@ public: ~Allocation(); OSubAllocation getSuballocation(VkDeviceSize size, VkDeviceSize alignment); void markFree(PSubAllocation alloc); - constexpr VkDeviceMemory getHandle() const; - constexpr void* getMappedPointer(); - constexpr bool isReadable() const; + constexpr VkDeviceMemory getHandle() const + { + return allocatedMemory; + } + + constexpr void* getMappedPointer() + { + if (!canMap) + { + return nullptr; + } + if (!isMapped) + { + vkMapMemory(device, allocatedMemory, 0, bytesAllocated, 0, &mappedPointer); + isMapped = true; + } + return mappedPointer; + } + + constexpr bool isReadable() const + { + return readable; + } + void flushMemory(); void invalidateMemory(); @@ -134,11 +165,19 @@ public: { return buffer; } - constexpr VkDeviceMemory getMemoryHandle() const; - constexpr VkDeviceSize getOffset() const; - constexpr uint64 getSize() const; - constexpr bool isReadable() const; - constexpr VkBufferUsageFlags getUsage() const; + VkDeviceMemory getMemoryHandle() const; + VkDeviceSize getOffset() const; + uint64 getSize() const; + constexpr bool isReadable() const + { + return readable; + } + + constexpr VkBufferUsageFlags getUsage() const + { + return usage; + } + private: OSubAllocation allocation; VkBuffer buffer; diff --git a/src/Engine/Graphics/Vulkan/Buffer.cpp b/src/Engine/Graphics/Vulkan/Buffer.cpp index 0b8fac2..6e1ccb1 100644 --- a/src/Engine/Graphics/Vulkan/Buffer.cpp +++ b/src/Engine/Graphics/Vulkan/Buffer.cpp @@ -291,6 +291,7 @@ UniformBuffer::UniformBuffer(PGraphics graphics, const UniformBufferCreateInfo & UniformBuffer::~UniformBuffer() { + graphics->getStagingManager()->releaseStagingBuffer(std::move(dedicatedStagingBuffer)); } bool UniformBuffer::updateContents(const DataSource &sourceData) @@ -363,7 +364,12 @@ VkAccessFlags UniformBuffer::getDestAccessMask() ShaderBuffer::ShaderBuffer(PGraphics graphics, const ShaderBufferCreateInfo &sourceData) : Gfx::ShaderBuffer(graphics->getFamilyMapping(), sourceData.stride, sourceData.sourceData.size / sourceData.stride, sourceData.sourceData) , Vulkan::Buffer(graphics, sourceData.sourceData.size, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, currentOwner, sourceData.dynamic) + , dedicatedStagingBuffer(nullptr) { + if(sourceData.dynamic) + { + dedicatedStagingBuffer = graphics->getStagingManager()->allocateStagingBuffer(sourceData.sourceData.size, VK_BUFFER_USAGE_TRANSFER_SRC_BIT); + } if (sourceData.sourceData.data != nullptr) { void *data = lock(); @@ -374,6 +380,7 @@ ShaderBuffer::ShaderBuffer(PGraphics graphics, const ShaderBufferCreateInfo &sou ShaderBuffer::~ShaderBuffer() { + graphics->getStagingManager()->releaseStagingBuffer(std::move(dedicatedStagingBuffer)); } bool ShaderBuffer::updateContents(const DataSource &sourceData) @@ -422,13 +429,13 @@ void ShaderBuffer::requestOwnershipTransfer(Gfx::QueueType newOwner) void ShaderBuffer::executeOwnershipBarrier(Gfx::QueueType newOwner) { - Vulkan::ShaderBuffer::executeOwnershipBarrier(newOwner); + Vulkan::Buffer::executeOwnershipBarrier(newOwner); } void ShaderBuffer::executePipelineBarrier(VkAccessFlags srcAccess, VkPipelineStageFlags srcStage, VkAccessFlags dstAccess, VkPipelineStageFlags dstStage) { - Vulkan::ShaderBuffer::executePipelineBarrier(srcAccess, srcStage, dstAccess, dstStage); + Vulkan::Buffer::executePipelineBarrier(srcAccess, srcStage, dstAccess, dstStage); } VkAccessFlags ShaderBuffer::getSourceAccessMask() diff --git a/src/Engine/Graphics/Vulkan/Buffer.h b/src/Engine/Graphics/Vulkan/Buffer.h index a8ef84d..46228ba 100644 --- a/src/Engine/Graphics/Vulkan/Buffer.h +++ b/src/Engine/Graphics/Vulkan/Buffer.h @@ -34,7 +34,7 @@ protected: struct BufferAllocation { VkBuffer buffer; - PSubAllocation allocation; + OSubAllocation allocation; }; PGraphics graphics; uint32 currentBuffer; @@ -140,6 +140,5 @@ protected: VkAccessFlags dstAccess, VkPipelineStageFlags dstStage); }; DEFINE_REF(IndexBuffer) - } } \ No newline at end of file diff --git a/src/Engine/Graphics/Vulkan/Initializer.cpp b/src/Engine/Graphics/Vulkan/Initializer.cpp index 11fe525..9cb8c4e 100644 --- a/src/Engine/Graphics/Vulkan/Initializer.cpp +++ b/src/Engine/Graphics/Vulkan/Initializer.cpp @@ -172,6 +172,8 @@ VkDeviceCreateInfo init::DeviceCreateInfo(VkDeviceQueueCreateInfo *queueInfos, u createInfo.enabledLayerCount = layerCount; createInfo.ppEnabledLayerNames = layers; #else + (void)layers; + (void)layerCount; createInfo.enabledLayerCount = 0; layerCount = 0; layers = nullptr; diff --git a/src/Engine/Graphics/Vulkan/Texture.cpp b/src/Engine/Graphics/Vulkan/Texture.cpp index 6b71cdf..5adc018 100644 --- a/src/Engine/Graphics/Vulkan/Texture.cpp +++ b/src/Engine/Graphics/Vulkan/Texture.cpp @@ -217,7 +217,7 @@ void TextureHandle::download(uint32 mipLevel, uint32 arrayLayer, uint32 face, Ar auto prevlayout = layout; changeLayout(Gfx::SE_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL); PCmdBuffer cmdBuffer = graphics->getQueueCommands(currentOwner)->getCommands(); - Gfx::FormatCompatibilityInfo formatInfo = Gfx::getFormatInfo(format); + //Gfx::FormatCompatibilityInfo formatInfo = Gfx::getFormatInfo(format); VkBufferImageCopy region = { .bufferOffset = 0, .bufferRowLength = 0, diff --git a/src/Engine/Material/MaterialInstance.cpp b/src/Engine/Material/MaterialInstance.cpp index e04ff90..62fc021 100644 --- a/src/Engine/Material/MaterialInstance.cpp +++ b/src/Engine/Material/MaterialInstance.cpp @@ -14,21 +14,24 @@ MaterialInstance::MaterialInstance(uint64 id, Array params, uint32 uniformBinding, uint32 uniformSize) - : id(id) - , graphics(graphics) + : graphics(graphics) , uniformBinding(uniformBinding) + , id(id) { - uniformBuffer = graphics->createUniformBuffer(UniformBufferCreateInfo{ - .sourceData = { - .size = uniformSize, - }, - .dynamic = true, - } - ); + if(uniformSize > 0) + { + uniformBuffer = graphics->createUniformBuffer(UniformBufferCreateInfo{ + .sourceData = { + .size = uniformSize, + }, + .dynamic = true, + } + ); + } uniformData.resize(uniformSize); ArchiveBuffer buffer(graphics); parameters.reserve(params.size()); - for (int i = 0; i < params.size(); ++i) + for (size_t i = 0; i < params.size(); ++i) { Serialization::save(buffer, expressions[params[i]]); buffer.rewind(); @@ -52,6 +55,14 @@ void MaterialInstance::updateDescriptor() { param->updateDescriptorSet(descriptor, uniformData.data()); } + if(uniformData.size() > 0) + { + uniformBuffer->updateContents(DataSource{ + .size = uniformData.size(), + .data = uniformData.data(), + }); + descriptor->updateBuffer(uniformBinding, uniformBuffer); + } descriptor->writeChanges(); } @@ -62,13 +73,16 @@ Gfx::PDescriptorSet MaterialInstance::getDescriptorSet() const void MaterialInstance::setBaseMaterial(PMaterialAsset asset) { - uniformBuffer = graphics->createUniformBuffer(UniformBufferCreateInfo{ - .sourceData = { - .size = uniformData.size(), - }, - .dynamic = true, - } - ); + if(uniformData.size() > 0) + { + uniformBuffer = graphics->createUniformBuffer(UniformBufferCreateInfo{ + .sourceData = { + .size = uniformData.size(), + }, + .dynamic = true, + } + ); + } baseMaterial = asset; } diff --git a/src/Engine/Material/ShaderExpression.cpp b/src/Engine/Material/ShaderExpression.cpp index 5153f06..f4b0d18 100644 --- a/src/Engine/Material/ShaderExpression.cpp +++ b/src/Engine/Material/ShaderExpression.cpp @@ -4,6 +4,7 @@ #include "Asset/AssetRegistry.h" #include "Graphics/Graphics.h" #include "Graphics/Descriptor.h" +#include using namespace Seele; @@ -40,6 +41,10 @@ ShaderExpression::ShaderExpression(std::string key) { } +ShaderExpression::~ShaderExpression() +{ +} + void ShaderExpression::save(ArchiveBuffer& buffer) const { Serialization::save(buffer, inputs); diff --git a/src/Engine/Material/ShaderExpression.h b/src/Engine/Material/ShaderExpression.h index 7e30a22..46b53fb 100644 --- a/src/Engine/Material/ShaderExpression.h +++ b/src/Engine/Material/ShaderExpression.h @@ -38,6 +38,7 @@ struct ShaderExpression std::string key; ShaderExpression(); ShaderExpression(std::string key); + virtual ~ShaderExpression(); virtual uint64 getIdentifier() const = 0; virtual std::string evaluate(Map& varState) const = 0; virtual void save(ArchiveBuffer& buffer) const; @@ -216,14 +217,14 @@ struct MaterialNode void load(ArchiveBuffer& buffer); }; template<> -static void Serialization::save(ArchiveBuffer& buffer, const OShaderExpression& parameter) +void Serialization::save(ArchiveBuffer& buffer, const OShaderExpression& parameter) { Serialization::save(buffer, parameter->getIdentifier()); parameter->save(buffer); } template<> -static void Serialization::load(ArchiveBuffer& buffer, OShaderExpression& parameter) +void Serialization::load(ArchiveBuffer& buffer, OShaderExpression& parameter) { uint64 identifier = 0; Serialization::load(buffer, identifier); @@ -269,14 +270,14 @@ static void Serialization::load(ArchiveBuffer& buffer, OShaderExpression& parame } template<> -static void Serialization::save(ArchiveBuffer& buffer, const OShaderParameter& parameter) +void Serialization::save(ArchiveBuffer& buffer, const OShaderParameter& parameter) { Serialization::save(buffer, parameter->getIdentifier()); parameter->save(buffer); } template<> -static void Serialization::load(ArchiveBuffer& buffer, OShaderParameter& parameter) +void Serialization::load(ArchiveBuffer& buffer, OShaderParameter& parameter) { uint64 identifier = 0; Serialization::load(buffer, identifier); diff --git a/src/Engine/MinimalEngine.h b/src/Engine/MinimalEngine.h index c84d903..4acfb7e 100644 --- a/src/Engine/MinimalEngine.h +++ b/src/Engine/MinimalEngine.h @@ -157,6 +157,10 @@ public: { if (this != &other) { + if(pointer != nullptr) + { + Deleter()(pointer); + } pointer = other.pointer; } return *this; diff --git a/src/Engine/Physics/BVH.cpp b/src/Engine/Physics/BVH.cpp index b701842..6c23392 100644 --- a/src/Engine/Physics/BVH.cpp +++ b/src/Engine/Physics/BVH.cpp @@ -109,7 +109,7 @@ void BVH::reinsertCollider(entt::entity entity, AABB aabb) void BVH::removeCollider(entt::entity entity) { int32 nodeIndex = -1; - for (int32 i = 0; i < dynamicNodes.size(); i++) + for (size_t i = 0; i < dynamicNodes.size(); i++) { if(dynamicNodes[i].isLeaf && dynamicNodes[i].owner == entity) { @@ -119,7 +119,6 @@ void BVH::removeCollider(entt::entity entity) } if(nodeIndex == -1) { - return; } int32 parentIndex = dynamicNodes[nodeIndex].parentIndex; @@ -354,7 +353,7 @@ int32 BVH::splitNode(Array aabbs) } int32 BVH::allocateNode() { - for (int32 i = 0; i < dynamicNodes.size(); i++) + for (size_t i = 0; i < dynamicNodes.size(); i++) { if(!dynamicNodes[i].isValid) { @@ -377,7 +376,7 @@ void BVH::validateBVH() const { assert(dynamicNodes[dynamicRoot].parentIndex == -1); } - for(int32 i = 0; i < dynamicNodes.size(); ++i) + for(size_t i = 0; i < dynamicNodes.size(); ++i) { int32 nodeIdx = i; size_t counter = dynamicNodes.size(); diff --git a/src/Engine/Physics/CollisionSystem.cpp b/src/Engine/Physics/CollisionSystem.cpp index 91f8f0f..06d160f 100644 --- a/src/Engine/Physics/CollisionSystem.cpp +++ b/src/Engine/Physics/CollisionSystem.cpp @@ -91,7 +91,7 @@ bool CollisionSystem::createWitness(Witness& result, const ShapeBase& source, co } for (size_t i = 0; i < source.indices.size(); i += 3) { - auto findEdgePlane = [=, &result](uint32_t point1Index, uint32_t point2Index) + auto findEdgePlane = [this, &source, &other, &result](uint32_t point1Index, uint32_t point2Index) { const glm::vec3 point1 = source.vertices[point1Index]; const glm::vec3 point2 = source.vertices[point2Index]; diff --git a/src/Engine/Physics/PhysicsSystem.cpp b/src/Engine/Physics/PhysicsSystem.cpp index 14c9369..851c537 100644 --- a/src/Engine/Physics/PhysicsSystem.cpp +++ b/src/Engine/Physics/PhysicsSystem.cpp @@ -346,19 +346,19 @@ void PhysicsSystem::calculateContacts(entt::entity id1, const ShapeBase& shape1, && tx >= 0.f && tx <= 1.f) { - Vector p = p1 + tx * (p2 - p1); - Vector ea = p2 - p1; - Vector eb = p4 - p3; - Vector n = glm::normalize(glm::cross(eb, ea)); - Contact contact = { - .a = id1, - .b = id2, - .p = p, - .n = n, - .ea = ea, - .eb = eb, - .vf = false - }; + // Vector p = p1 + tx * (p2 - p1); + // Vector ea = p2 - p1; + // Vector eb = p4 - p3; + // Vector n = glm::normalize(glm::cross(eb, ea)); + // Contact contact = { + // .a = id1, + // .b = id2, + // .p = p, + // .n = n, + // .ea = ea, + // .eb = eb, + // .vf = false + // }; } }; for(size_t j = 0; j < shape2.indices.size(); j+=3) diff --git a/src/Engine/Platform/CMakeLists.txt b/src/Engine/Platform/CMakeLists.txt index 196f640..e212857 100644 --- a/src/Engine/Platform/CMakeLists.txt +++ b/src/Engine/Platform/CMakeLists.txt @@ -1 +1,5 @@ -add_subdirectory(Windows/) \ No newline at end of file +if(WIN32) + add_subdirectory(Windows/) +else() + add_subdirectory(Linux/) +endif() \ No newline at end of file diff --git a/src/Engine/Platform/Linux/CMakeLists.txt b/src/Engine/Platform/Linux/CMakeLists.txt new file mode 100644 index 0000000..4613346 --- /dev/null +++ b/src/Engine/Platform/Linux/CMakeLists.txt @@ -0,0 +1,10 @@ +target_sources(Engine + PRIVATE + GameInterface.h + GameInterface.cpp) + + +target_sources(Engine + PUBLIC FILE_SET HEADERS + FILES + GameInterface.h) \ No newline at end of file diff --git a/src/Engine/Platform/Linux/GameInterface.cpp b/src/Engine/Platform/Linux/GameInterface.cpp new file mode 100644 index 0000000..ba8b1cb --- /dev/null +++ b/src/Engine/Platform/Linux/GameInterface.cpp @@ -0,0 +1,32 @@ +#include "GameInterface.h" + +using namespace Seele; + +GameInterface::GameInterface(std::string soPath) + : lib(NULL) + , soPath(soPath) +{ +} + +GameInterface::~GameInterface() +{ + +} + +Game* GameInterface::getGame() +{ + return game; +} + +void GameInterface::reload(AssetRegistry* registry) +{ + if(lib != NULL) + { + destroyInstance(game); + dlclose(lib); + } + lib = dlopen(soPath.c_str(), RTLD_NOW); + createInstance = (decltype(createInstance))dlsym(lib, "createInstance"); + destroyInstance = (decltype(destroyInstance))dlsym(lib, "destroyInstance"); + game = createInstance(registry); +} \ No newline at end of file diff --git a/src/Engine/Platform/Linux/GameInterface.h b/src/Engine/Platform/Linux/GameInterface.h new file mode 100644 index 0000000..fa3d4c9 --- /dev/null +++ b/src/Engine/Platform/Linux/GameInterface.h @@ -0,0 +1,21 @@ +#pragma once +#include "Game.h" +#include "dlfcn.h" + +namespace Seele +{ +class GameInterface +{ +public: + GameInterface(std::string soPath); + ~GameInterface(); + Game* getGame(); + void reload(AssetRegistry* registry); +private: + void* lib; + std::string soPath; + Game* game; + Game* (*createInstance)(AssetRegistry*) = nullptr; + void (*destroyInstance)(Game*) = nullptr; +}; +} // namespace Seele \ No newline at end of file diff --git a/src/Engine/Scene/Scene.cpp b/src/Engine/Scene/Scene.cpp index 3a0e73d..28e5c1f 100644 --- a/src/Engine/Scene/Scene.cpp +++ b/src/Engine/Scene/Scene.cpp @@ -14,8 +14,8 @@ using namespace Seele; Scene::Scene(Gfx::PGraphics graphics) : graphics(graphics) - , physics(registry) , lightEnv(new LightEnvironment(graphics)) + , physics(registry) { } diff --git a/src/Engine/Scene/Scene.h b/src/Engine/Scene/Scene.h index 9c73e80..6989cc8 100644 --- a/src/Engine/Scene/Scene.h +++ b/src/Engine/Scene/Scene.h @@ -48,9 +48,9 @@ public: Gfx::PGraphics getGraphics() const { return graphics; } entt::registry registry; private: + Gfx::PGraphics graphics; OLightEnvironment lightEnv; PhysicsSystem physics; - Gfx::PGraphics graphics; }; DEFINE_REF(Scene) } // namespace Seele \ No newline at end of file diff --git a/src/Engine/Serialization/ArchiveBuffer.cpp b/src/Engine/Serialization/ArchiveBuffer.cpp index fe2c7e9..e4f5573 100644 --- a/src/Engine/Serialization/ArchiveBuffer.cpp +++ b/src/Engine/Serialization/ArchiveBuffer.cpp @@ -59,7 +59,7 @@ void ArchiveBuffer::seek(int64 s, SeekOp op) newPos = position + s; break; } - assert(newPos >= 0 && newPos < memory.size()); + assert(newPos >= 0 && size_t(newPos) < memory.size()); newPos = position; } diff --git a/src/Engine/System/ComponentSystem.h b/src/Engine/System/ComponentSystem.h index 170b8a1..90678dc 100644 --- a/src/Engine/System/ComponentSystem.h +++ b/src/Engine/System/ComponentSystem.h @@ -27,6 +27,14 @@ public: { return (deps | ...); } + void setupView(Dependencies<>, dp::thread_pool<>&) + { + registry.view().each([&](Components&... comp){ + //pool.enqueue_detach([&](){ + update(comp...); + //}); + }); + } template void setupView(Dependencies, dp::thread_pool<>&) { @@ -37,20 +45,12 @@ public: //}); }); } - template<> - void setupView(Dependencies<>, dp::thread_pool<>&) - { - registry.view().each([&](Components&... comp){ - //pool.enqueue_detach([&](){ - update(comp...); - //}); - }); - } virtual void run(dp::thread_pool<>& pool, double delta) override { SystemBase::run(pool, delta); setupView(mergeDependencies((getDependencies(),...)), pool); } + virtual void update() {} virtual void update(Components&... components) = 0; }; } // namespace System diff --git a/src/Engine/System/MeshUpdater.cpp b/src/Engine/System/MeshUpdater.cpp index b104469..d184ad1 100644 --- a/src/Engine/System/MeshUpdater.cpp +++ b/src/Engine/System/MeshUpdater.cpp @@ -12,7 +12,10 @@ MeshUpdater::~MeshUpdater() { } -void MeshUpdater::update(Component::Transform& transform, Component::Mesh& mesh) +void MeshUpdater::update(Component::Transform& transform, Component::Mesh& meshComp) { - mesh.vertexData->updateMesh(transform, mesh); + for(const auto& mesh : meshComp.asset->meshes) + { + mesh->vertexData->updateMesh(transform, mesh); + } } diff --git a/src/Engine/System/SystemBase.h b/src/Engine/System/SystemBase.h index 5e59089..86383ac 100644 --- a/src/Engine/System/SystemBase.h +++ b/src/Engine/System/SystemBase.h @@ -12,7 +12,7 @@ class SystemBase public: SystemBase(PScene scene) : registry(scene->registry), scene(scene) {} virtual ~SystemBase() {} - virtual void run(dp::thread_pool<>& pool, double delta) + virtual void run(dp::thread_pool<>&, double delta) { deltaTime = delta; update(); diff --git a/src/Engine/UI/System.cpp b/src/Engine/UI/System.cpp index c6f5d8d..b59a8db 100644 --- a/src/Engine/UI/System.cpp +++ b/src/Engine/UI/System.cpp @@ -22,7 +22,7 @@ void System::update() } -void System::updateViewport(Gfx::PViewport viewport) +void System::updateViewport(Gfx::PViewport) { //TODO set viewport FoV to 0 } diff --git a/src/Engine/Window/GameView.cpp b/src/Engine/Window/GameView.cpp index fc04f11..57d391c 100644 --- a/src/Engine/Window/GameView.cpp +++ b/src/Engine/Window/GameView.cpp @@ -9,12 +9,13 @@ using namespace Seele; GameView::GameView(Gfx::PGraphics graphics, PWindow window, const ViewportCreateInfo &createInfo, std::string dllPath) : View(graphics, window, createInfo, "Game") + , scene(new Scene(graphics)) , gameInterface(dllPath) , renderGraph(RenderGraphBuilder::build( - std::move(DepthPrepass(graphics, scene)), - std::move(LightCullingPass(graphics, scene)), - std::move(BasePass(graphics, scene)), - std::move(SkyboxRenderPass(graphics, scene)) + DepthPrepass(graphics, scene), + LightCullingPass(graphics, scene), + BasePass(graphics, scene), + SkyboxRenderPass(graphics, scene) )) { reloadGame(); @@ -75,7 +76,7 @@ void GameView::reloadGame() void GameView::keyCallback(KeyCode code, InputAction action, KeyModifier) { - scene->view([=](Component::KeyboardInput& input) + scene->view([=, this](Component::KeyboardInput& input) { //if(code == KeyCode::KEY_R && action == InputAction::PRESS) //{ diff --git a/src/Engine/Window/GameView.h b/src/Engine/Window/GameView.h index 4afd057..ea60ef8 100644 --- a/src/Engine/Window/GameView.h +++ b/src/Engine/Window/GameView.h @@ -5,7 +5,11 @@ #include "Graphics/RenderPass/LightCullingPass.h" #include "Graphics/RenderPass/BasePass.h" #include "Graphics/RenderPass/SkyboxRenderPass.h" +#ifdef WIN32 #include "Platform/Windows/GameInterface.h" // TODO +#else +#include "Platform/Linux/GameInterface.h" +#endif namespace Seele { @@ -23,6 +27,8 @@ public: void reloadGame(); private: + OScene scene; + PEntity camera; GameInterface gameInterface; RenderGraph< DepthPrepass, @@ -31,8 +37,6 @@ private: SkyboxRenderPass > renderGraph; - PEntity camera; - OScene scene; PSystemGraph systemGraph; dp::thread_pool<> threadPool; float updateTime = 0;