From 073af40c4df1d24ea1b9172bebf461e72fd50e8c Mon Sep 17 00:00:00 2001 From: Luke Street Date: Mon, 7 Jun 2021 11:28:30 -0400 Subject: [PATCH 001/405] Use freetype for ImGui fonts if available --- .github/workflows/build.yml | 4 +-- .github/workflows/release.yml | 4 +-- README.md | 11 ++++---- Runtime/ImGuiConsole.cpp | 3 +- imgui/CMakeLists.txt | 36 ++++++++++++++---------- imgui/ImGuiEngine.cpp | 52 ++++++++++++++++++++++------------- imgui/ImGuiEngine.hpp | 2 ++ 7 files changed, 68 insertions(+), 44 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3ef5736ef..3a6b64496 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -37,7 +37,7 @@ jobs: sudo apt-get -y install build-essential curl git cmake ninja-build clang lld python3 python-is-python3 \ zlib1g-dev libglu1-mesa-dev libdbus-1-dev libvulkan-dev libxi-dev libxrandr-dev libasound2-dev \ libpulse-dev libudev-dev libpng-dev libncurses5-dev libx11-xcb-dev libcurl4-openssl-dev qt5-default \ - llvm-11-dev libclang-11-dev clang-11 + llvm-11-dev libclang-11-dev clang-11 libfreetype-dev # free up disk space # https://github.com/actions/virtual-environments/issues/2840#issuecomment-790492173 @@ -78,7 +78,7 @@ jobs: run: | brew update brew upgrade --formula - brew install ninja qt@5 graphicsmagick imagemagick + brew install ninja qt@5 graphicsmagick imagemagick freetype brew link qt@5 yarn global add create-dmg diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 12958b708..169d61609 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -39,7 +39,7 @@ jobs: sudo apt-get -y install build-essential curl git cmake ninja-build clang lld python3 python-is-python3 \ zlib1g-dev libglu1-mesa-dev libdbus-1-dev libvulkan-dev libxi-dev libxrandr-dev libasound2-dev \ libpulse-dev libudev-dev libpng-dev libncurses5-dev libx11-xcb-dev libcurl4-openssl-dev qt5-default \ - llvm-11-dev libclang-11-dev clang-11 intel-oneapi-ipp-devel + llvm-11-dev libclang-11-dev clang-11 intel-oneapi-ipp-devel libfreetype-dev yarn global add @sentry/cli echo "$(yarn global bin)" >> $GITHUB_PATH @@ -104,7 +104,7 @@ jobs: run: | brew update brew upgrade --formula - brew install ninja qt@5 graphicsmagick imagemagick getsentry/tools/sentry-cli + brew install ninja qt@5 graphicsmagick imagemagick getsentry/tools/sentry-cli freetype brew link qt@5 yarn global add create-dmg diff --git a/README.md b/README.md index 28fe49596..a6b94ace2 100644 --- a/README.md +++ b/README.md @@ -64,13 +64,14 @@ NFS files dumped from Metroid Prime Trilogy on Wii U VC can be used directly wit * **[Linux]** recent development packages of `udev`, `x11`, `xcb`, `xinput`, `glx`, `asound` * Ubuntu 20.04+ packages ``` - build-essential curl git ninja-build llvm-dev libclang-dev clang lld zlib1g-dev libcurl4-openssl-dev - libglu1-mesa-dev libdbus-1-dev libvulkan-dev libxi-dev libxrandr-dev libasound2-dev libpulse-dev - libudev-dev libpng-dev libncurses5-dev cmake libx11-xcb-dev python3 python-is-python3 qt5-default + build-essential curl git ninja-build llvm-dev libclang-dev clang lld zlib1g-dev libcurl4-openssl-dev \ + libglu1-mesa-dev libdbus-1-dev libvulkan-dev libxi-dev libxrandr-dev libasound2-dev libpulse-dev \ + libudev-dev libpng-dev libncurses5-dev cmake libx11-xcb-dev python3 python-is-python3 qt5-default \ + libfreetype-dev ``` - * Arch packages + * Arch packages ``` - base-devel cmake ninja llvm vulkan-headers python3 qt6 clang lld alsa-lib libpulse libxrandr + base-devel cmake ninja llvm vulkan-headers python3 qt6 clang lld alsa-lib libpulse libxrandr freetype2 ``` ### Prep Directions diff --git a/Runtime/ImGuiConsole.cpp b/Runtime/ImGuiConsole.cpp index d3a455349..d9898e45b 100644 --- a/Runtime/ImGuiConsole.cpp +++ b/Runtime/ImGuiConsole.cpp @@ -29,7 +29,7 @@ void ImGuiStringViewText(std::string_view text) { void ImGuiTextCenter(std::string_view text) { ImGui::NewLine(); - float fontSize = ImGui::GetFontSize() * float(text.size()) / 2; + float fontSize = ImGui::CalcTextSize(text.data(), text.data() + text.size()).x; ImGui::SameLine(ImGui::GetWindowSize().x / 2 - fontSize + fontSize / 2); ImGuiStringViewText(text); } @@ -1118,7 +1118,6 @@ void ImGuiConsole::ShowAppMainMenuBar(bool canInspect) { } } -s32 TranslateBooSpecialKey(boo::ESpecialKey key) { return 256 + static_cast(key); } void ImGuiConsole::PreUpdate() { if (!m_isInitialized) { m_isInitialized = true; diff --git a/imgui/CMakeLists.txt b/imgui/CMakeLists.txt index 8f3c0c9f4..98ca45f30 100644 --- a/imgui/CMakeLists.txt +++ b/imgui/CMakeLists.txt @@ -1,23 +1,31 @@ add_library(imgui - ../extern/imgui/imgui.cpp - ../extern/imgui/imgui_demo.cpp - ../extern/imgui/imgui_draw.cpp - ../extern/imgui/imgui_tables.cpp - ../extern/imgui/imgui_widgets.cpp - ../extern/imgui/misc/cpp/imgui_stdlib.cpp - ImGuiEngine.cpp - ImGuiEngine.hpp - NotoMono.cpp - MetaforceIcon.cpp - ) + ../extern/imgui/imgui.cpp + ../extern/imgui/imgui_demo.cpp + ../extern/imgui/imgui_draw.cpp + ../extern/imgui/imgui_tables.cpp + ../extern/imgui/imgui_widgets.cpp + ../extern/imgui/misc/cpp/imgui_stdlib.cpp + ImGuiEngine.cpp + ImGuiEngine.hpp + NotoMono.cpp + MetaforceIcon.cpp + ) target_include_directories(imgui PUBLIC ${CMAKE_SOURCE_DIR}/extern/imgui ${CMAKE_CURRENT_SOURCE_DIR}) target_compile_definitions(imgui PUBLIC IMGUI_USER_CONFIG="imconfig_user.h") if (CMAKE_COMPILER_IS_GNUCXX) - # currently explicitly ignored for clang in imgui code, but not gcc (yet) - target_compile_options(imgui PRIVATE -Wno-deprecated-enum-enum-conversion) -endif() + # currently explicitly ignored for clang in imgui code, but not gcc (yet) + target_compile_options(imgui PRIVATE -Wno-deprecated-enum-enum-conversion) +endif () target_link_libraries(imgui PRIVATE boo hecl-light RetroDataSpec) +# Optional, replaces stb_freetype if available +find_package(Freetype) +if (FREETYPE_FOUND) + target_sources(imgui PRIVATE ../extern/imgui/misc/freetype/imgui_freetype.cpp) + target_compile_definitions(imgui PUBLIC IMGUI_ENABLE_FREETYPE) + target_link_libraries(imgui PRIVATE Freetype::Freetype) +endif () + bintoc_compress(NotoMono.cpp NotoMono-Regular.ttf NOTO_MONO_FONT) bintoc(MetaforceIcon.cpp ../Runtime/platforms/freedesktop/256x256/apps/metaforce.png METAFORCE_ICON) diff --git a/imgui/ImGuiEngine.cpp b/imgui/ImGuiEngine.cpp index fde1bf3de..0f626f338 100644 --- a/imgui/ImGuiEngine.cpp +++ b/imgui/ImGuiEngine.cpp @@ -10,6 +10,10 @@ #define STBI_ONLY_PNG #include "stb_image.h" +#ifdef IMGUI_ENABLE_FREETYPE +#include "misc/freetype/imgui_freetype.h" +#endif + #include "Runtime/GameGlobalObjects.hpp" #include "Runtime/Input/CInputGenerator.hpp" #include @@ -83,21 +87,21 @@ void ImGuiEngine::Initialize(boo::IGraphicsDataFactory* factory, boo::IWindow* w io.BackendPlatformName = "Boo"; io.BackendRendererName = "Boo"; - io.KeyMap[ImGuiKey_Tab] = 256 + static_cast(boo::ESpecialKey::Tab); - io.KeyMap[ImGuiKey_LeftArrow] = 256 + static_cast(boo::ESpecialKey::Left); - io.KeyMap[ImGuiKey_RightArrow] = 256 + static_cast(boo::ESpecialKey::Right); - io.KeyMap[ImGuiKey_UpArrow] = 256 + static_cast(boo::ESpecialKey::Up); - io.KeyMap[ImGuiKey_DownArrow] = 256 + static_cast(boo::ESpecialKey::Down); - io.KeyMap[ImGuiKey_PageUp] = 256 + static_cast(boo::ESpecialKey::PgUp); - io.KeyMap[ImGuiKey_PageDown] = 256 + static_cast(boo::ESpecialKey::PgDown); - io.KeyMap[ImGuiKey_Home] = 256 + static_cast(boo::ESpecialKey::Home); - io.KeyMap[ImGuiKey_End] = 256 + static_cast(boo::ESpecialKey::End); - io.KeyMap[ImGuiKey_Insert] = 256 + static_cast(boo::ESpecialKey::Insert); - io.KeyMap[ImGuiKey_Delete] = 256 + static_cast(boo::ESpecialKey::Delete); - io.KeyMap[ImGuiKey_Backspace] = 256 + static_cast(boo::ESpecialKey::Backspace); + io.KeyMap[ImGuiKey_Tab] = TranslateBooSpecialKey(boo::ESpecialKey::Tab); + io.KeyMap[ImGuiKey_LeftArrow] = TranslateBooSpecialKey(boo::ESpecialKey::Left); + io.KeyMap[ImGuiKey_RightArrow] = TranslateBooSpecialKey(boo::ESpecialKey::Right); + io.KeyMap[ImGuiKey_UpArrow] = TranslateBooSpecialKey(boo::ESpecialKey::Up); + io.KeyMap[ImGuiKey_DownArrow] = TranslateBooSpecialKey(boo::ESpecialKey::Down); + io.KeyMap[ImGuiKey_PageUp] = TranslateBooSpecialKey(boo::ESpecialKey::PgUp); + io.KeyMap[ImGuiKey_PageDown] = TranslateBooSpecialKey(boo::ESpecialKey::PgDown); + io.KeyMap[ImGuiKey_Home] = TranslateBooSpecialKey(boo::ESpecialKey::Home); + io.KeyMap[ImGuiKey_End] = TranslateBooSpecialKey(boo::ESpecialKey::End); + io.KeyMap[ImGuiKey_Insert] = TranslateBooSpecialKey(boo::ESpecialKey::Insert); + io.KeyMap[ImGuiKey_Delete] = TranslateBooSpecialKey(boo::ESpecialKey::Delete); + io.KeyMap[ImGuiKey_Backspace] = TranslateBooSpecialKey(boo::ESpecialKey::Backspace); io.KeyMap[ImGuiKey_Space] = ' '; - io.KeyMap[ImGuiKey_Enter] = 256 + static_cast(boo::ESpecialKey::Enter); - io.KeyMap[ImGuiKey_Escape] = 256 + static_cast(boo::ESpecialKey::Esc); + io.KeyMap[ImGuiKey_Enter] = TranslateBooSpecialKey(boo::ESpecialKey::Enter); + io.KeyMap[ImGuiKey_Escape] = TranslateBooSpecialKey(boo::ESpecialKey::Esc); io.KeyMap[ImGuiKey_A] = 'a'; // for text edit CTRL+A: select all io.KeyMap[ImGuiKey_C] = 'c'; // for text edit CTRL+C: copy io.KeyMap[ImGuiKey_V] = 'v'; // for text edit CTRL+V: paste @@ -114,22 +118,32 @@ void ImGuiEngine::Initialize(boo::IGraphicsDataFactory* factory, boo::IWindow* w auto* metaforceIcon = stbi_load_from_memory(static_cast(METAFORCE_ICON), int(METAFORCE_ICON_SZ), &iconWidth, &iconHeight, nullptr, 4); - int width = 0; - int height = 0; - unsigned char* pixels = nullptr; ImFontConfig fontConfig{}; fontConfig.FontData = fontData; fontConfig.FontDataSize = int(NOTO_MONO_FONT_DECOMPRESSED_SZ); fontConfig.SizePixels = std::floor(14.f * scale); +#ifdef IMGUI_ENABLE_FREETYPE + fontConfig.FontBuilderFlags = ImGuiFreeTypeBuilderFlags_LightHinting; +#endif snprintf(static_cast(fontConfig.Name), sizeof(fontConfig.Name), "Noto Mono Regular, %dpx", static_cast(fontConfig.SizePixels)); fontNormal = io.Fonts->AddFont(&fontConfig); + fontConfig.FontDataOwnedByAtlas = false; // first one took ownership fontConfig.SizePixels = std::floor(24.f * scale); +#ifdef IMGUI_ENABLE_FREETYPE + fontConfig.FontBuilderFlags |= ImGuiFreeTypeBuilderFlags_Bold; + snprintf(static_cast(fontConfig.Name), sizeof(fontConfig.Name), "Noto Mono Bold, %dpx", + static_cast(fontConfig.SizePixels)); +#else snprintf(static_cast(fontConfig.Name), sizeof(fontConfig.Name), "Noto Mono Regular, %dpx", static_cast(fontConfig.SizePixels)); +#endif fontLarge = io.Fonts->AddFont(&fontConfig); + int width = 0; + int height = 0; + unsigned char* pixels = nullptr; io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height); factory->commitTransaction([&](boo::IGraphicsDataFactory::Context& ctx) { ShaderPipeline = hecl::conv->convert(Shader_ImGuiShader{}); @@ -419,12 +433,12 @@ void ImGuiWindowCallback::charKeyUp(unsigned long charCode, boo::EModifierKey mo } void ImGuiWindowCallback::specialKeyDown(boo::ESpecialKey key, boo::EModifierKey mods, bool isRepeat) { - ImGuiEngine::Input.m_keys[256 + static_cast(key)] = true; + ImGuiEngine::Input.m_keys[TranslateBooSpecialKey(key)] = true; ImGuiEngine::Input.m_modifiers = mods; } void ImGuiWindowCallback::specialKeyUp(boo::ESpecialKey key, boo::EModifierKey mods) { - ImGuiEngine::Input.m_keys[256 + static_cast(key)] = false; + ImGuiEngine::Input.m_keys[TranslateBooSpecialKey(key)] = false; ImGuiEngine::Input.m_modifiers = mods; } diff --git a/imgui/ImGuiEngine.hpp b/imgui/ImGuiEngine.hpp index 8eb2295a1..81dc49702 100644 --- a/imgui/ImGuiEngine.hpp +++ b/imgui/ImGuiEngine.hpp @@ -7,6 +7,8 @@ #include namespace metaforce { +constexpr inline int TranslateBooSpecialKey(boo::ESpecialKey key) { return 256 + static_cast(key); } + class ImGuiEngine { public: static struct Input { From e48435f11e9593fd076f7ad453c1b72cf8375339 Mon Sep 17 00:00:00 2001 From: Luke Street Date: Mon, 31 Jan 2022 19:06:54 -0500 Subject: [PATCH 002/405] Start wiring up wgpu+winit --- .vscode/launch.json | 36 + CMakeLists.txt | 39 +- DataSpec/CMakeLists.txt | 2 +- Graphics/.gitignore | 17 + Graphics/CMakeLists.txt | 42 + Graphics/Cargo.lock | 2076 +++++++ Graphics/Cargo.toml | 75 + Graphics/build.rs | 47 + Graphics/include/aurora.hpp | 48 + Graphics/include/lib.hpp | 9 + Graphics/lib.cpp | 9 + Graphics/rustfmt.toml | 8 + Graphics/src/gpu.rs | 194 + Graphics/src/imgui.rs | 80 + Graphics/src/imgui_backend/imgui.wgsl | 53 + Graphics/src/imgui_backend/mod.rs | 659 +++ Graphics/src/lib.rs | 345 ++ Graphics/src/shaders/aabb.rs | 203 + Graphics/src/shaders/aabb.wgsl | 16 + Graphics/src/shaders/fog_volume_filter.rs | 3 + Graphics/src/shaders/fog_volume_plane.rs | 5 + Graphics/src/shaders/mod.rs | 574 ++ Graphics/src/shaders/model.rs | 41 + Graphics/src/shaders/texture.rs | 129 + Graphics/src/zeus.rs | 171 + NESEmulator/CNESEmulator.cpp | 61 +- NESEmulator/CNESEmulator.hpp | 11 +- NESEmulator/CNESShader.cpp | 32 +- NESEmulator/CNESShader.hpp | 14 +- Runtime/AutoMapper/CMapArea.cpp | 76 +- Runtime/AutoMapper/CMapArea.hpp | 16 +- Runtime/AutoMapper/CMappableObject.cpp | 25 +- Runtime/AutoMapper/CMappableObject.hpp | 14 +- Runtime/CDvdFile.cpp | 129 +- Runtime/CDvdFile.hpp | 39 +- Runtime/CGameOptions.cpp | 2 +- Runtime/CMain.cpp | 361 +- Runtime/CMakeLists.txt | 6 +- Runtime/CPakFile.cpp | 4 +- Runtime/CResLoader.cpp | 6 +- Runtime/CStateManager.cpp | 168 +- Runtime/CTextureCache.cpp | 2 +- Runtime/CTextureCache.hpp | 2 +- Runtime/Character/CAnimData.cpp | 11 +- Runtime/Character/CAnimData.hpp | 4 +- Runtime/Character/CCharacterFactory.cpp | 24 +- Runtime/Character/CCharacterFactory.hpp | 2 +- Runtime/Character/CModelData.cpp | 14 +- Runtime/Character/CModelData.hpp | 6 +- Runtime/Character/CSkinRules.cpp | 82 +- Runtime/Character/CSkinRules.hpp | 51 +- Runtime/Graphics/CBooRenderer.cpp | 316 +- Runtime/Graphics/CBooRenderer.hpp | 81 +- Runtime/Graphics/CCubeModel.cpp | 36 + Runtime/Graphics/CCubeModel.hpp | 37 + Runtime/Graphics/CGraphics.cpp | 123 +- Runtime/Graphics/CGraphics.hpp | 232 +- Runtime/Graphics/CLineRenderer.cpp | 226 +- Runtime/Graphics/CLineRenderer.hpp | 38 +- Runtime/Graphics/CMakeLists.txt | 1 + Runtime/Graphics/CMetroidModelInstance.hpp | 4 +- Runtime/Graphics/CModel.hpp | 132 +- Runtime/Graphics/CModelBoo.cpp | 1184 ++-- Runtime/Graphics/CMoviePlayer.cpp | 158 +- Runtime/Graphics/CMoviePlayer.hpp | 27 +- Runtime/Graphics/CRainSplashGenerator.cpp | 15 +- Runtime/Graphics/CRainSplashGenerator.hpp | 4 +- Runtime/Graphics/CSkinnedModel.cpp | 51 +- Runtime/Graphics/CSkinnedModel.hpp | 12 +- Runtime/Graphics/CTexture.hpp | 48 +- Runtime/Graphics/CTextureBoo.cpp | 254 +- Runtime/Graphics/Shaders/CAABoxShader.cpp | 44 +- Runtime/Graphics/Shaders/CAABoxShader.hpp | 8 +- .../Graphics/Shaders/CCameraBlurFilter.cpp | 40 +- .../Graphics/Shaders/CCameraBlurFilter.hpp | 8 +- .../Graphics/Shaders/CColoredQuadFilter.cpp | 116 +- .../Graphics/Shaders/CColoredQuadFilter.hpp | 8 +- .../Graphics/Shaders/CColoredStripShader.cpp | 113 +- .../Graphics/Shaders/CColoredStripShader.hpp | 16 +- Runtime/Graphics/Shaders/CDecalShaders.cpp | 106 +- Runtime/Graphics/Shaders/CDecalShaders.hpp | 16 +- .../Graphics/Shaders/CElementGenShaders.cpp | 534 +- .../Graphics/Shaders/CElementGenShaders.hpp | 58 +- Runtime/Graphics/Shaders/CEnergyBarShader.cpp | 90 +- Runtime/Graphics/Shaders/CEnergyBarShader.hpp | 8 +- Runtime/Graphics/Shaders/CEnvFxShaders.cpp | 78 +- Runtime/Graphics/Shaders/CEnvFxShaders.hpp | 8 +- .../Graphics/Shaders/CFluidPlaneShader.cpp | 472 +- .../Graphics/Shaders/CFluidPlaneShader.hpp | 117 +- Runtime/Graphics/Shaders/CFogVolumeFilter.cpp | 88 +- Runtime/Graphics/Shaders/CFogVolumeFilter.hpp | 18 +- .../Shaders/CFogVolumePlaneShader.cpp | 72 +- .../Shaders/CFogVolumePlaneShader.hpp | 15 +- .../Graphics/Shaders/CLineRendererShaders.cpp | 194 +- .../Graphics/Shaders/CLineRendererShaders.hpp | 32 +- .../Graphics/Shaders/CMapSurfaceShader.cpp | 36 +- .../Graphics/Shaders/CMapSurfaceShader.hpp | 15 +- Runtime/Graphics/Shaders/CModelShaders.cpp | 292 +- Runtime/Graphics/Shaders/CModelShaders.hpp | 12 +- .../Shaders/CParticleSwooshShaders.cpp | 164 +- .../Shaders/CParticleSwooshShaders.hpp | 22 +- .../Graphics/Shaders/CPhazonSuitFilter.cpp | 196 +- .../Graphics/Shaders/CPhazonSuitFilter.hpp | 20 +- .../Graphics/Shaders/CRadarPaintShader.cpp | 50 +- .../Graphics/Shaders/CRadarPaintShader.hpp | 8 +- .../Graphics/Shaders/CRandomStaticFilter.cpp | 102 +- .../Graphics/Shaders/CRandomStaticFilter.hpp | 8 +- Runtime/Graphics/Shaders/CScanLinesFilter.cpp | 74 +- Runtime/Graphics/Shaders/CScanLinesFilter.hpp | 6 +- Runtime/Graphics/Shaders/CSpaceWarpFilter.cpp | 99 +- Runtime/Graphics/Shaders/CSpaceWarpFilter.hpp | 13 +- .../Graphics/Shaders/CTextSupportShader.cpp | 56 +- .../Graphics/Shaders/CTextSupportShader.hpp | 92 +- .../Graphics/Shaders/CTexturedQuadFilter.cpp | 420 +- .../Graphics/Shaders/CTexturedQuadFilter.hpp | 19 +- .../Graphics/Shaders/CThermalColdFilter.cpp | 68 +- .../Graphics/Shaders/CThermalColdFilter.hpp | 8 +- .../Graphics/Shaders/CThermalHotFilter.cpp | 64 +- .../Graphics/Shaders/CThermalHotFilter.hpp | 8 +- .../Graphics/Shaders/CWorldShadowShader.cpp | 70 +- .../Graphics/Shaders/CWorldShadowShader.hpp | 14 +- Runtime/Graphics/Shaders/CXRayBlurFilter.cpp | 68 +- Runtime/Graphics/Shaders/CXRayBlurFilter.hpp | 10 +- Runtime/GuiSys/CCompoundTargetReticle.cpp | 10 +- Runtime/GuiSys/CRasterFont.hpp | 2 +- Runtime/GuiSys/CTextRenderBuffer.cpp | 170 +- Runtime/GuiSys/CTextRenderBuffer.hpp | 12 +- Runtime/IMain.hpp | 12 +- Runtime/ImGuiConsole.cpp | 9 +- Runtime/MP1/CInGameGuiManager.cpp | 6 +- Runtime/MP1/CMFGame.cpp | 4 +- Runtime/MP1/CPlayerVisor.cpp | 20 +- Runtime/MP1/CPlayerVisor.hpp | 4 +- Runtime/MP1/CTweaks.cpp | 4 +- Runtime/MP1/MP1.cpp | 350 +- Runtime/MP1/MP1.hpp | 23 +- Runtime/MP1/World/CAtomicBeta.cpp | 7 +- Runtime/MP1/World/CAtomicBeta.hpp | 4 +- Runtime/MP1/World/CBabygoth.cpp | 2 +- Runtime/MP1/World/CMagdolite.cpp | 2 +- Runtime/MP1/World/COmegaPirate.cpp | 2 +- Runtime/MP1/World/CParasite.cpp | 2 +- Runtime/Particle/CDecal.cpp | 42 +- Runtime/Particle/CDecal.hpp | 8 +- Runtime/Particle/CElementGen.cpp | 123 +- Runtime/Particle/CElementGen.hpp | 22 +- Runtime/Particle/CParticleDataFactory.cpp | 14 +- Runtime/Particle/CParticleSwoosh.cpp | 54 +- Runtime/Particle/CParticleSwoosh.hpp | 6 +- Runtime/Weapon/CElectricBeamProjectile.cpp | 24 +- Runtime/Weapon/CElectricBeamProjectile.hpp | 12 +- Runtime/Weapon/CGunMotion.cpp | 2 +- Runtime/Weapon/CPlasmaProjectile.cpp | 30 +- Runtime/Weapon/CPlasmaProjectile.hpp | 4 +- Runtime/Weapon/CPlayerGun.cpp | 2 +- Runtime/Weapon/CPlayerGun.hpp | 4 +- Runtime/World/CActor.cpp | 12 +- Runtime/World/CActor.hpp | 2 +- Runtime/World/CActorModelParticles.cpp | 2 +- Runtime/World/CDamageVulnerability.cpp | 7 +- Runtime/World/CEnvFxManager.cpp | 91 +- Runtime/World/CEnvFxManager.hpp | 22 +- Runtime/World/CFluidPlane.cpp | 18 +- Runtime/World/CFluidPlaneCPU.cpp | 2 +- Runtime/World/CFluidPlaneGPU.cpp | 4 +- Runtime/World/CFluidPlaneManager.cpp | 10 +- Runtime/World/CFluidPlaneManager.hpp | 5 +- Runtime/World/CGameArea.cpp | 100 +- Runtime/World/CMorphBallShadow.cpp | 2 +- Runtime/World/CPlayer.cpp | 2 +- Runtime/World/CScriptDoor.cpp | 7 +- Runtime/World/CScriptTrigger.cpp | 5 +- Runtime/World/CScriptWater.cpp | 18 +- Runtime/World/CWorldShadow.cpp | 2 +- Runtime/World/CWorldTransManager.cpp | 102 +- Runtime/World/CWorldTransManager.hpp | 4 +- Shaders/shader_CFluidPlaneShader.hpp | 126 +- extern/boo | 2 +- extern/imgui | 2 +- hecl/include/hecl/Backend.hpp | 420 +- hecl/include/hecl/CVarManager.hpp | 4 - hecl/include/hecl/Compilers.hpp | 96 - hecl/include/hecl/Console.hpp | 107 - hecl/include/hecl/Pipeline.hpp | 506 -- hecl/include/hecl/PipelineBase.hpp | 222 - hecl/include/hecl/Runtime.hpp | 51 +- hecl/include/hecl/UniformBufferPool.hpp | 187 - hecl/include/hecl/VertexBufferPool.hpp | 195 - hecl/include/hecl/hecl.hpp | 9 +- hecl/lib/CMakeLists.txt | 19 +- hecl/lib/CVarManager.cpp | 57 - hecl/lib/Compilers.cpp | 292 - hecl/lib/Console.cpp | 410 -- hecl/lib/Pipeline.cpp | 167 - hecl/lib/Runtime/CMakeLists.txt | 3 +- hecl/lib/Runtime/HMDL_RT.cpp | 48 - imgui-sys/Cargo.toml | 19 + imgui-sys/LICENSE-APACHE | 201 + imgui-sys/LICENSE-MIT | 19 + imgui-sys/src/bindings.rs | 4359 +++++++++++++++ imgui-sys/src/lib.rs | 142 + imgui-sys/src/wasm_bindings.rs | 4954 +++++++++++++++++ imgui-sys/third-party/cimgui.cpp | 2585 +++++++++ imgui-sys/third-party/cimgui.h | 1745 ++++++ imgui-sys/third-party/cimgui_impl.h | 0 imgui/CMakeLists.txt | 9 +- imgui/ImGuiEngine.cpp | 406 +- imgui/ImGuiEngine.hpp | 242 +- imgui/imconfig_user.h | 11 +- 209 files changed, 24234 insertions(+), 8085 deletions(-) create mode 100644 .vscode/launch.json create mode 100644 Graphics/.gitignore create mode 100644 Graphics/CMakeLists.txt create mode 100644 Graphics/Cargo.lock create mode 100644 Graphics/Cargo.toml create mode 100644 Graphics/build.rs create mode 100644 Graphics/include/aurora.hpp create mode 100644 Graphics/include/lib.hpp create mode 100644 Graphics/lib.cpp create mode 100644 Graphics/rustfmt.toml create mode 100644 Graphics/src/gpu.rs create mode 100644 Graphics/src/imgui.rs create mode 100644 Graphics/src/imgui_backend/imgui.wgsl create mode 100644 Graphics/src/imgui_backend/mod.rs create mode 100644 Graphics/src/lib.rs create mode 100644 Graphics/src/shaders/aabb.rs create mode 100644 Graphics/src/shaders/aabb.wgsl create mode 100644 Graphics/src/shaders/fog_volume_filter.rs create mode 100644 Graphics/src/shaders/fog_volume_plane.rs create mode 100644 Graphics/src/shaders/mod.rs create mode 100644 Graphics/src/shaders/model.rs create mode 100644 Graphics/src/shaders/texture.rs create mode 100644 Graphics/src/zeus.rs create mode 100644 Runtime/Graphics/CCubeModel.cpp create mode 100644 Runtime/Graphics/CCubeModel.hpp delete mode 100644 hecl/include/hecl/Compilers.hpp delete mode 100644 hecl/include/hecl/Console.hpp delete mode 100644 hecl/include/hecl/Pipeline.hpp delete mode 100644 hecl/include/hecl/PipelineBase.hpp delete mode 100644 hecl/include/hecl/UniformBufferPool.hpp delete mode 100644 hecl/include/hecl/VertexBufferPool.hpp delete mode 100644 hecl/lib/Compilers.cpp delete mode 100644 hecl/lib/Console.cpp delete mode 100644 hecl/lib/Pipeline.cpp delete mode 100644 hecl/lib/Runtime/HMDL_RT.cpp create mode 100644 imgui-sys/Cargo.toml create mode 100644 imgui-sys/LICENSE-APACHE create mode 100644 imgui-sys/LICENSE-MIT create mode 100644 imgui-sys/src/bindings.rs create mode 100644 imgui-sys/src/lib.rs create mode 100644 imgui-sys/src/wasm_bindings.rs create mode 100644 imgui-sys/third-party/cimgui.cpp create mode 100644 imgui-sys/third-party/cimgui.h create mode 100644 imgui-sys/third-party/cimgui_impl.h diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 000000000..fa722d897 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,36 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "Launch", + "type": "cppdbg", + "request": "launch", + // Resolved by CMake Tools: + "program": "${command:cmake.launchTargetPath}", + "args": [], + "stopAtEntry": false, + "cwd": "${workspaceFolder}", + "environment": [ + { + // add the directory where our target was built to the PATHs + // it gets resolved by CMake Tools: + "name": "PATH", + "value": "$PATH:${command:cmake.launchTargetDirectory}" + }, + { + "name": "OTHER_VALUE", + "value": "Something something" + } + ], + "externalConsole": true, + "MIMode": "gdb", + "setupCommands": [ + { + "description": "Enable pretty-printing for gdb", + "text": "-enable-pretty-printing", + "ignoreFailures": true + } + ] + } + ] +} diff --git a/CMakeLists.txt b/CMakeLists.txt index d9e1a4f49..caec51568 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -469,7 +469,7 @@ function(shaderc out) endfunction() include(hecl/ApplicationTools.cmake) -add_subdirectory(Shaders) +#add_subdirectory(Shaders) add_subdirectory(imgui) add_subdirectory(extern/libSquish EXCLUDE_FROM_ALL) add_subdirectory(extern/libpng EXCLUDE_FROM_ALL) @@ -481,21 +481,21 @@ target_include_directories(hecl-light PRIVATE ${CMAKE_SOURCE_DIR}) target_link_libraries(hecl-full PRIVATE zeus nod) target_link_libraries(hecl-light PRIVATE zeus nod) -bintoc(CModelShaders.common.glsl.cpp Shaders/CModelShaders.common.glsl CMODELSHADERS_COMMON_GLSL) -bintoc(CModelShaders.vert.glsl.cpp Shaders/CModelShaders.vert.glsl CMODELSHADERS_VERT_GLSL) -bintoc(CModelShaders.frag.glsl.cpp Shaders/CModelShaders.frag.glsl CMODELSHADERS_FRAG_GLSL) -bintoc(CModelShaders.common.hlsl.cpp Shaders/CModelShaders.common.hlsl CMODELSHADERS_COMMON_HLSL) -bintoc(CModelShaders.vert.hlsl.cpp Shaders/CModelShaders.vert.hlsl CMODELSHADERS_VERT_HLSL) -bintoc(CModelShaders.frag.hlsl.cpp Shaders/CModelShaders.frag.hlsl CMODELSHADERS_FRAG_HLSL) -bintoc(CModelShaders.common.metal.cpp Shaders/CModelShaders.common.metal CMODELSHADERS_COMMON_METAL) -bintoc(CModelShaders.vert.metal.cpp Shaders/CModelShaders.vert.metal CMODELSHADERS_VERT_METAL) -bintoc(CModelShaders.frag.metal.cpp Shaders/CModelShaders.frag.metal CMODELSHADERS_FRAG_METAL) -add_library(CModelShaders - CModelShaders.common.glsl.cpp CModelShaders.vert.glsl.cpp CModelShaders.frag.glsl.cpp - CModelShaders.common.hlsl.cpp CModelShaders.vert.hlsl.cpp CModelShaders.frag.hlsl.cpp - CModelShaders.common.metal.cpp CModelShaders.vert.metal.cpp CModelShaders.frag.metal.cpp) -target_link_libraries(CModelShaders PUBLIC zeus) -target_link_libraries(shader_CModelShaders PUBLIC CModelShaders) +#bintoc(CModelShaders.common.glsl.cpp Shaders/CModelShaders.common.glsl CMODELSHADERS_COMMON_GLSL) +#bintoc(CModelShaders.vert.glsl.cpp Shaders/CModelShaders.vert.glsl CMODELSHADERS_VERT_GLSL) +#bintoc(CModelShaders.frag.glsl.cpp Shaders/CModelShaders.frag.glsl CMODELSHADERS_FRAG_GLSL) +#bintoc(CModelShaders.common.hlsl.cpp Shaders/CModelShaders.common.hlsl CMODELSHADERS_COMMON_HLSL) +#bintoc(CModelShaders.vert.hlsl.cpp Shaders/CModelShaders.vert.hlsl CMODELSHADERS_VERT_HLSL) +#bintoc(CModelShaders.frag.hlsl.cpp Shaders/CModelShaders.frag.hlsl CMODELSHADERS_FRAG_HLSL) +#bintoc(CModelShaders.common.metal.cpp Shaders/CModelShaders.common.metal CMODELSHADERS_COMMON_METAL) +#bintoc(CModelShaders.vert.metal.cpp Shaders/CModelShaders.vert.metal CMODELSHADERS_VERT_METAL) +#bintoc(CModelShaders.frag.metal.cpp Shaders/CModelShaders.frag.metal CMODELSHADERS_FRAG_METAL) +#add_library(CModelShaders +# CModelShaders.common.glsl.cpp CModelShaders.vert.glsl.cpp CModelShaders.frag.glsl.cpp +# CModelShaders.common.hlsl.cpp CModelShaders.vert.hlsl.cpp CModelShaders.frag.hlsl.cpp +# CModelShaders.common.metal.cpp CModelShaders.vert.metal.cpp CModelShaders.frag.metal.cpp) +#target_link_libraries(CModelShaders PUBLIC zeus) +#target_link_libraries(shader_CModelShaders PUBLIC CModelShaders) if(NOT TARGET atdna) # Import native atdna if cross-compiling @@ -517,12 +517,13 @@ add_subdirectory(extern/jbus EXCLUDE_FROM_ALL) set(JBUS_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/extern/jbus/include) add_subdirectory(NESEmulator EXCLUDE_FROM_ALL) +add_subdirectory(Graphics) add_subdirectory(Runtime) add_subdirectory(mpcksum EXCLUDE_FROM_ALL) add_subdirectory(gbalink EXCLUDE_FROM_ALL) -add_subdirectory(visigen) +#add_subdirectory(visigen) -add_dependencies(hecl visigen) +#add_dependencies(hecl visigen) if (NOT WINDOWS_STORE AND NOT NX) if (APPLE AND EXISTS /opt/local/libexec/qt5) @@ -552,7 +553,7 @@ endif() configure_file(${CMAKE_SOURCE_DIR}/version.h.in ${CMAKE_BINARY_DIR}/version.h) # Packaging logic -list(APPEND BINARY_TARGETS metaforce hecl visigen) +list(APPEND BINARY_TARGETS metaforce hecl) # visigen set(DSYM_ONLY_TARGETS "") if (TARGET crashpad_handler) list(APPEND BINARY_TARGETS crashpad_handler) diff --git a/DataSpec/CMakeLists.txt b/DataSpec/CMakeLists.txt index 0acaa2640..78fd4a7f1 100644 --- a/DataSpec/CMakeLists.txt +++ b/DataSpec/CMakeLists.txt @@ -74,7 +74,7 @@ add_library(AssetNameMapNull get_target_property(HECL_INCLUDES hecl-full INCLUDE_DIRECTORIES) target_include_directories(RetroDataSpec PUBLIC ${HECL_INCLUDES} ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_SOURCE_DIR}) -target_link_libraries(RetroDataSpec PUBLIC amuse zeus nod squish ${PNG_LIBRARIES} ${ZLIB_LIBRARIES} lzokay logvisor) +target_link_libraries(RetroDataSpec PUBLIC amuse zeus nod squish ${PNG_LIBRARIES} ${ZLIB_LIBRARIES} lzokay logvisor aurora) if (COMMAND add_sanitizers) add_sanitizers(RetroDataSpec) endif () diff --git a/Graphics/.gitignore b/Graphics/.gitignore new file mode 100644 index 000000000..269c94a59 --- /dev/null +++ b/Graphics/.gitignore @@ -0,0 +1,17 @@ +# Rust +target/ +**/*.rs.bk +generated/ + +# cargo-mobile +.cargo/ +/gen + +# macOS +.DS_Store + +# JetBrains +.idea + +# Generated SPIR-V +*.spv diff --git a/Graphics/CMakeLists.txt b/Graphics/CMakeLists.txt new file mode 100644 index 000000000..e39a2bdac --- /dev/null +++ b/Graphics/CMakeLists.txt @@ -0,0 +1,42 @@ +if (CMAKE_BUILD_TYPE STREQUAL "Debug") + set(CARGO_CMD cargo build --verbose) + set(TARGET_DIR "debug") +else () + set(CARGO_CMD cargo build --release --verbose) + set(TARGET_DIR "release") +endif () + +if(USE_LTO) + set(RUST_FLAGS "-Clinker-plugin-lto" "-Clinker=clang" "-Clink-arg=-fuse-ld=lld") +endif() + +set(AURORA_LIB "${CMAKE_CURRENT_BINARY_DIR}/${TARGET_DIR}/libaurora.a") + +set(AURORA_CXX "${CMAKE_CURRENT_BINARY_DIR}/aurora.cpp") +set(AURORA_SHADERS_CXX "${CMAKE_CURRENT_BINARY_DIR}/aurora_shaders.cpp") +set(AURORA_IMGUI_CXX "${CMAKE_CURRENT_BINARY_DIR}/aurora_imgui.cpp") +add_library(aurora STATIC ${AURORA_CXX} ${AURORA_SHADERS_CXX}) +target_include_directories(aurora PRIVATE ../Runtime) +target_include_directories(aurora PUBLIC include ${CMAKE_CURRENT_BINARY_DIR}) +add_custom_command( + OUTPUT ${AURORA_CXX} ${AURORA_SHADERS_CXX} ${AURORA_IMGUI_CXX} ${AURORA_LIB} #__no_exist + COMMAND CARGO_TARGET_DIR=${CMAKE_CURRENT_BINARY_DIR} RUSTFLAGS="${RUST_FLAGS}" ${CARGO_CMD} + COMMAND cp ${CMAKE_CURRENT_BINARY_DIR}/cxxbridge/aurora/src/lib.rs.cc ${AURORA_CXX} + COMMAND cp ${CMAKE_CURRENT_BINARY_DIR}/cxxbridge/aurora/src/lib.rs.h ${CMAKE_CURRENT_BINARY_DIR}/aurora.h + COMMAND cp ${CMAKE_CURRENT_BINARY_DIR}/cxxbridge/aurora/src/shaders/mod.rs.cc ${AURORA_SHADERS_CXX} + COMMAND cp ${CMAKE_CURRENT_BINARY_DIR}/cxxbridge/aurora/src/shaders/mod.rs.h ${CMAKE_CURRENT_BINARY_DIR}/aurora_shaders.h + COMMAND cp ${CMAKE_CURRENT_BINARY_DIR}/cxxbridge/aurora/src/imgui.rs.cc ${AURORA_IMGUI_CXX} + COMMAND cp ${CMAKE_CURRENT_BINARY_DIR}/cxxbridge/aurora/src/imgui.rs.h ${CMAKE_CURRENT_BINARY_DIR}/aurora_imgui.h + DEPENDS src/lib.rs + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} +) +add_custom_target( + always_run ALL + DEPENDS __no_exist +) + +target_link_libraries(aurora pthread dl ${AURORA_LIB} zeus) + +add_test(NAME aurora_test + COMMAND cargo test + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/Graphics/Cargo.lock b/Graphics/Cargo.lock new file mode 100644 index 000000000..a73c7bfaf --- /dev/null +++ b/Graphics/Cargo.lock @@ -0,0 +1,2076 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "ahash" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47" +dependencies = [ + "getrandom", + "once_cell", + "version_check", +] + +[[package]] +name = "aho-corasick" +version = "0.7.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e37cfd5e7657ada45f742d6e99ca5788580b5c529dc78faf11ece6dc702656f" +dependencies = [ + "memchr", +] + +[[package]] +name = "android_log-sys" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85965b6739a430150bdd138e2374a98af0c3ee0d030b3bb7fc3bddff58d0102e" + +[[package]] +name = "android_logger" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9ed09b18365ed295d722d0b5ed59c01b79a826ff2d2a8f73d5ecca8e6fb2f66" +dependencies = [ + "android_log-sys", + "env_logger 0.8.4", + "lazy_static", + "log", +] + +[[package]] +name = "ansi_term" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2" +dependencies = [ + "winapi", +] + +[[package]] +name = "approx" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f2a05fd1bd10b2527e20a2cd32d8873d115b8b39fe219ee25f42a8aca6ba278" +dependencies = [ + "num-traits", +] + +[[package]] +name = "array-init" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6945cc5422176fc5e602e590c2878d2c2acd9a4fe20a4baa7c28022521698ec6" + +[[package]] +name = "arrayvec" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6" + +[[package]] +name = "ash" +version = "0.34.0+1.2.203" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0f780da53d0063880d45554306489f09dd8d1bda47688b4a57bc579119356df" +dependencies = [ + "libloading", +] + +[[package]] +name = "atty" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" +dependencies = [ + "hermit-abi", + "libc", + "winapi", +] + +[[package]] +name = "aurora" +version = "0.0.1" +dependencies = [ + "android_logger", + "bindgen", + "binread", + "bytemuck", + "bytemuck_derive", + "cgmath", + "console_error_panic_hook", + "console_log", + "cxx", + "cxx-build", + "env_logger 0.9.0", + "imgui", + "imgui-winit-support", + "log", + "log-panics", + "mobile-entry-point", + "modular-bitfield", + "naga", + "ndk-glue", + "num-traits", + "num_enum", + "pollster", + "scopeguard", + "smallvec", + "twox-hash", + "wasm-bindgen-futures", + "web-sys", + "wgpu", + "wgpu-subscriber", + "winit", +] + +[[package]] +name = "autocfg" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" + +[[package]] +name = "bindgen" +version = "0.59.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2bd2a9a458e8f4304c52c43ebb0cfbd520289f8379a52e329a38afda99bf8eb8" +dependencies = [ + "bitflags", + "cexpr", + "clang-sys", + "clap", + "env_logger 0.9.0", + "lazy_static", + "lazycell", + "log", + "peeking_take_while", + "proc-macro2", + "quote", + "regex", + "rustc-hash", + "shlex", + "which", +] + +[[package]] +name = "binread" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16598dfc8e6578e9b597d9910ba2e73618385dc9f4b1d43dd92c349d6be6418f" +dependencies = [ + "array-init", + "binread_derive", + "rustversion", +] + +[[package]] +name = "binread_derive" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d9672209df1714ee804b1f4d4f68c8eb2a90b1f7a07acf472f88ce198ef1fed" +dependencies = [ + "either", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "bit-set" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e11e16035ea35e4e5997b393eacbf6f63983188f7a2ad25bfb13465f5ad59de" +dependencies = [ + "bit-vec", +] + +[[package]] +name = "bit-vec" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "349f9b6a179ed607305526ca489b34ad0a41aed5f7980fa90eb03160b69598fb" + +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + +[[package]] +name = "block" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d8c1fef690941d3e7788d328517591fecc684c084084702d6ff1641e993699a" + +[[package]] +name = "bumpalo" +version = "3.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f1e260c3a9040a7c19a12468758f4c16f31a81a1fe087482be9570ec864bb6c" + +[[package]] +name = "bytemuck" +version = "1.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "439989e6b8c38d1b6570a384ef1e49c8848128f5a97f3914baef02920842712f" + +[[package]] +name = "bytemuck_derive" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e215f8c2f9f79cb53c8335e687ffd07d5bfcb6fe5fc80723762d0be46e7cc54" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "byteorder" +version = "1.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" + +[[package]] +name = "calloop" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf2eec61efe56aa1e813f5126959296933cf0700030e4314786c48779a66ab82" +dependencies = [ + "log", + "nix", +] + +[[package]] +name = "cc" +version = "1.0.72" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22a9137b95ea06864e018375b72adfb7db6e6f68cfc8df5a04d00288050485ee" + +[[package]] +name = "cexpr" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766" +dependencies = [ + "nom", +] + +[[package]] +name = "cfg-if" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "cfg_aliases" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd16c4719339c4530435d38e511904438d07cce7950afa3718a84ac36c10e89e" + +[[package]] +name = "cgmath" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a98d30140e3296250832bbaaff83b27dcd6fa3cc70fb6f1f3e5c9c0023b5317" +dependencies = [ + "approx", + "num-traits", +] + +[[package]] +name = "chlorine" +version = "1.0.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75476fe966a8af7c0ceae2a3e514afa87d4451741fcdfab8bfaa07ad301842ec" + +[[package]] +name = "chrono" +version = "0.4.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "670ad68c9088c2a963aaa298cb369688cf3f9465ce5e2d4ca10e6e0098a1ce73" +dependencies = [ + "libc", + "num-integer", + "num-traits", + "winapi", +] + +[[package]] +name = "clang-sys" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa66045b9cb23c2e9c1520732030608b02ee07e5cfaa5a521ec15ded7fa24c90" +dependencies = [ + "glob", + "libc", + "libloading", +] + +[[package]] +name = "clap" +version = "2.34.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a0610544180c38b88101fecf2dd634b174a62eef6946f84dfc6a7127512b381c" +dependencies = [ + "ansi_term", + "atty", + "bitflags", + "strsim 0.8.0", + "textwrap", + "unicode-width", + "vec_map", +] + +[[package]] +name = "cocoa" +version = "0.24.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f63902e9223530efb4e26ccd0cf55ec30d592d3b42e21a28defc42a9586e832" +dependencies = [ + "bitflags", + "block", + "cocoa-foundation", + "core-foundation 0.9.2", + "core-graphics 0.22.3", + "foreign-types", + "libc", + "objc", +] + +[[package]] +name = "cocoa-foundation" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ade49b65d560ca58c403a479bb396592b155c0185eada742ee323d1d68d6318" +dependencies = [ + "bitflags", + "block", + "core-foundation 0.9.2", + "core-graphics-types", + "foreign-types", + "libc", + "objc", +] + +[[package]] +name = "codespan-reporting" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3538270d33cc669650c4b093848450d380def10c331d38c768e34cac80576e6e" +dependencies = [ + "termcolor", + "unicode-width", +] + +[[package]] +name = "console_error_panic_hook" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a06aeb73f470f66dcdbf7223caeebb85984942f22f1adb2a088cf9668146bbbc" +dependencies = [ + "cfg-if 1.0.0", + "wasm-bindgen", +] + +[[package]] +name = "console_log" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "501a375961cef1a0d44767200e66e4a559283097e91d0730b1d75dfb2f8a1494" +dependencies = [ + "log", + "web-sys", +] + +[[package]] +name = "copyless" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2df960f5d869b2dd8532793fde43eb5427cceb126c929747a26823ab0eeb536" + +[[package]] +name = "core-foundation" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57d24c7a13c43e870e37c1556b74555437870a04514f7685f5b354e090567171" +dependencies = [ + "core-foundation-sys 0.7.0", + "libc", +] + +[[package]] +name = "core-foundation" +version = "0.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6888e10551bb93e424d8df1d07f1a8b4fceb0001a3a4b048bfc47554946f47b3" +dependencies = [ + "core-foundation-sys 0.8.3", + "libc", +] + +[[package]] +name = "core-foundation-sys" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b3a71ab494c0b5b860bdc8407ae08978052417070c2ced38573a9157ad75b8ac" + +[[package]] +name = "core-foundation-sys" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc" + +[[package]] +name = "core-graphics" +version = "0.19.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b3889374e6ea6ab25dba90bb5d96202f61108058361f6dc72e8b03e6f8bbe923" +dependencies = [ + "bitflags", + "core-foundation 0.7.0", + "foreign-types", + "libc", +] + +[[package]] +name = "core-graphics" +version = "0.22.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2581bbab3b8ffc6fcbd550bf46c355135d16e9ff2a6ea032ad6b9bf1d7efe4fb" +dependencies = [ + "bitflags", + "core-foundation 0.9.2", + "core-graphics-types", + "foreign-types", + "libc", +] + +[[package]] +name = "core-graphics-types" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a68b68b3446082644c91ac778bf50cd4104bfb002b5a6a7c44cca5a2c70788b" +dependencies = [ + "bitflags", + "core-foundation 0.9.2", + "foreign-types", + "libc", +] + +[[package]] +name = "core-video-sys" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34ecad23610ad9757664d644e369246edde1803fcb43ed72876565098a5d3828" +dependencies = [ + "cfg-if 0.1.10", + "core-foundation-sys 0.7.0", + "core-graphics 0.19.2", + "libc", + "objc", +] + +[[package]] +name = "cty" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b365fabc795046672053e29c954733ec3b05e4be654ab130fe8f1f94d7051f35" + +[[package]] +name = "cxx" +version = "1.0.60" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af5f0799eb4abbd9c46cb58dfaa781386f852386ad6681e65c66a8101b8562af" +dependencies = [ + "cc", + "cxxbridge-flags", + "cxxbridge-macro", + "link-cplusplus", +] + +[[package]] +name = "cxx-build" +version = "1.0.60" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c8f82eb643890f29750b559497cd5dc8c82019e5c6ff0284a1d14e85e8c44c7" +dependencies = [ + "cc", + "codespan-reporting", + "lazy_static", + "proc-macro2", + "quote", + "scratch", + "syn", +] + +[[package]] +name = "cxxbridge-flags" +version = "1.0.60" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "394474c4844c6df346936204bda4a45e4cf524d0b7050eb70e4b81fc568ab125" + +[[package]] +name = "cxxbridge-macro" +version = "1.0.60" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05055753924c7b4ae9b038eb7823d4d9c64a045a727cb581764a4454a60d0805" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "d3d12" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2daefd788d1e96e0a9d66dee4b828b883509bc3ea9ce30665f04c3246372690c" +dependencies = [ + "bitflags", + "libloading", + "winapi", +] + +[[package]] +name = "darling" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d0d720b8683f8dd83c65155f0530560cba68cd2bf395f6513a483caee57ff7f4" +dependencies = [ + "darling_core", + "darling_macro", +] + +[[package]] +name = "darling_core" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a340f241d2ceed1deb47ae36c4144b2707ec7dd0b649f894cb39bb595986324" +dependencies = [ + "fnv", + "ident_case", + "proc-macro2", + "quote", + "strsim 0.10.0", + "syn", +] + +[[package]] +name = "darling_macro" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72c41b3b7352feb3211a0d743dc5700a4e3b60f51bd2b368892d1e0f9a95f44b" +dependencies = [ + "darling_core", + "quote", + "syn", +] + +[[package]] +name = "derivative" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fcc3dd5e9e9c0b295d6e1e4d811fb6f157d5ffd784b8d202fc62eac8035a770b" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "dispatch" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd0c93bb4b0c6d9b77f4435b0ae98c24d17f1c45b2ff844c6151a07256ca923b" + +[[package]] +name = "dlib" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac1b7517328c04c2aa68422fc60a41b92208182142ed04a25879c26c8f878794" +dependencies = [ + "libloading", +] + +[[package]] +name = "downcast-rs" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ea835d29036a4087793836fa931b08837ad5e957da9e23886b29586fb9b6650" + +[[package]] +name = "either" +version = "1.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" + +[[package]] +name = "env_logger" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a19187fea3ac7e84da7dacf48de0c45d63c6a76f9490dae389aead16c243fce3" +dependencies = [ + "log", + "regex", +] + +[[package]] +name = "env_logger" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b2cf0344971ee6c64c31be0d530793fba457d322dfec2810c453d0ef228f9c3" +dependencies = [ + "atty", + "humantime", + "log", + "regex", + "termcolor", +] + +[[package]] +name = "fixedbitset" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "398ea4fabe40b9b0d885340a2a991a44c8a645624075ad966d21f88688e2b69e" + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + +[[package]] +name = "fxhash" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c" +dependencies = [ + "byteorder", +] + +[[package]] +name = "getrandom" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fcd999463524c52659517fe2cea98493cfe485d10565e7b0fb07dbba7ad2753" +dependencies = [ + "cfg-if 1.0.0", + "libc", + "wasi", +] + +[[package]] +name = "glob" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" + +[[package]] +name = "glow" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c07210904884e8e2e6a2d7f36f39040a9cefe3b379b721969b5275e9f5b464a" +dependencies = [ + "js-sys", + "slotmap", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "gpu-alloc" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e64cbb8d36508d3e19da95e56e196a84f674fc190881f2cc010000798838aa6" +dependencies = [ + "bitflags", + "gpu-alloc-types", +] + +[[package]] +name = "gpu-alloc-types" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "54804d0d6bc9d7f26db4eaec1ad10def69b599315f487d32c334a80d1efe67a5" +dependencies = [ + "bitflags", +] + +[[package]] +name = "gpu-descriptor" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a538f217be4d405ff4719a283ca68323cc2384003eca5baaa87501e821c81dda" +dependencies = [ + "bitflags", + "gpu-descriptor-types", + "hashbrown", +] + +[[package]] +name = "gpu-descriptor-types" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "363e3677e55ad168fef68cf9de3a4a310b53124c5e784c53a1d70e92d23f2126" +dependencies = [ + "bitflags", +] + +[[package]] +name = "hashbrown" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" +dependencies = [ + "ahash", +] + +[[package]] +name = "hermit-abi" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" +dependencies = [ + "libc", +] + +[[package]] +name = "hexf-parse" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfa686283ad6dd069f105e5ab091b04c62850d3e4cf5d67debad1933f55023df" + +[[package]] +name = "humantime" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" + +[[package]] +name = "ident_case" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" + +[[package]] +name = "imgui" +version = "0.8.2" +source = "git+https://github.com/imgui-rs/imgui-rs?rev=55a76370466953d5c044afc123330d0262b50e17#55a76370466953d5c044afc123330d0262b50e17" +dependencies = [ + "bitflags", + "imgui-sys", + "parking_lot", +] + +[[package]] +name = "imgui-sys" +version = "0.8.2" +dependencies = [ + "chlorine", +] + +[[package]] +name = "imgui-winit-support" +version = "0.8.2" +source = "git+https://github.com/imgui-rs/imgui-rs?rev=55a76370466953d5c044afc123330d0262b50e17#55a76370466953d5c044afc123330d0262b50e17" +dependencies = [ + "imgui", + "winit", +] + +[[package]] +name = "indexmap" +version = "1.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc633605454125dec4b66843673f01c7df2b89479b32e0ed634e43a91cff62a5" +dependencies = [ + "autocfg", + "hashbrown", +] + +[[package]] +name = "inplace_it" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90953f308a79fe6d62a4643e51f848fbfddcd05975a38e69fdf4ab86a7baf7ca" + +[[package]] +name = "instant" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" +dependencies = [ + "cfg-if 1.0.0", + "js-sys", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "itoa" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1aab8fc367588b89dcee83ab0fd66b72b50b72fa1904d7095045ace2b0c81c35" + +[[package]] +name = "jni-sys" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8eaf4bc02d17cbdd7ff4c7438cafcdf7fb9a4613313ad11b4f8fefe7d3fa0130" + +[[package]] +name = "js-sys" +version = "0.3.55" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7cc9ffccd38c451a86bf13657df244e9c3f37493cce8e5e21e940963777acc84" +dependencies = [ + "wasm-bindgen", +] + +[[package]] +name = "khronos-egl" +version = "4.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c2352bd1d0bceb871cb9d40f24360c8133c11d7486b68b5381c1dd1a32015e3" +dependencies = [ + "libc", + "libloading", +] + +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + +[[package]] +name = "lazycell" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" + +[[package]] +name = "libc" +version = "0.2.112" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b03d17f364a3a042d5e5d46b053bbbf82c92c9430c592dd4c064dc6ee997125" + +[[package]] +name = "libloading" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "afe203d669ec979b7128619bae5a63b7b42e9203c1b29146079ee05e2f604b52" +dependencies = [ + "cfg-if 1.0.0", + "winapi", +] + +[[package]] +name = "link-cplusplus" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8cae2cd7ba2f3f63938b9c724475dfb7b9861b545a90324476324ed21dbc8c8" +dependencies = [ + "cc", +] + +[[package]] +name = "lock_api" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712a4d093c9976e24e7dbca41db895dabcbac38eb5f4045393d17a95bdfb1109" +dependencies = [ + "scopeguard", +] + +[[package]] +name = "log" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710" +dependencies = [ + "cfg-if 1.0.0", +] + +[[package]] +name = "log-panics" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae0136257df209261daa18d6c16394757c63e032e27aafd8b07788b051082bef" +dependencies = [ + "log", +] + +[[package]] +name = "malloc_buf" +version = "0.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62bb907fe88d54d8d9ce32a3cceab4218ed2f6b7d35617cafe9adf84e43919cb" +dependencies = [ + "libc", +] + +[[package]] +name = "matchers" +version = "0.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f099785f7595cc4b4553a174ce30dd7589ef93391ff414dbb67f62392b9e0ce1" +dependencies = [ + "regex-automata", +] + +[[package]] +name = "memchr" +version = "2.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a" + +[[package]] +name = "memmap2" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b6c2ebff6180198788f5db08d7ce3bc1d0b617176678831a7510825973e357" +dependencies = [ + "libc", +] + +[[package]] +name = "memoffset" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5aa361d4faea93603064a027415f07bd8e1d5c88c9fbf68bf56a285428fd79ce" +dependencies = [ + "autocfg", +] + +[[package]] +name = "metal" +version = "0.23.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e0514f491f4cc03632ab399ee01e2c1c1b12d3e1cf2d667c1ff5f87d6dcd2084" +dependencies = [ + "bitflags", + "block", + "core-graphics-types", + "foreign-types", + "log", + "objc", +] + +[[package]] +name = "minimal-lexical" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" + +[[package]] +name = "mio" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba272f85fa0b41fc91872be579b3bbe0f56b792aa361a380eb669469f68dafb2" +dependencies = [ + "libc", + "log", + "miow", + "ntapi", + "winapi", +] + +[[package]] +name = "miow" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9f1c5b025cda876f66ef43a113f91ebc9f4ccef34843000e0adf6ebbab84e21" +dependencies = [ + "winapi", +] + +[[package]] +name = "mobile-entry-point" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81bef5a90018326583471cccca10424d7b3e770397b02f03276543cbb9b6a1a6" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "modular-bitfield" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a53d79ba8304ac1c4f9eb3b9d281f21f7be9d4626f72ce7df4ad8fbde4f38a74" +dependencies = [ + "modular-bitfield-impl", + "static_assertions", +] + +[[package]] +name = "modular-bitfield-impl" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a7d5f7076603ebc68de2dc6a650ec331a062a13abaa346975be747bbfa4b789" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "naga" +version = "0.8.0" +source = "git+https://github.com/gfx-rs/naga?rev=8df5421#8df5421e2e9d33e092c19779adfdc42e7f8a74e6" +dependencies = [ + "bit-set", + "bitflags", + "codespan-reporting", + "hexf-parse", + "indexmap", + "log", + "num-traits", + "petgraph", + "rustc-hash", + "spirv", + "thiserror", +] + +[[package]] +name = "ndk" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96d868f654c72e75f8687572699cdabe755f03effbb62542768e995d5b8d699d" +dependencies = [ + "bitflags", + "jni-sys", + "ndk-sys", + "num_enum", + "thiserror", +] + +[[package]] +name = "ndk-glue" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc291b8de2095cba8dab7cf381bf582ff4c17a09acf854c32e46545b08085d28" +dependencies = [ + "lazy_static", + "libc", + "log", + "ndk", + "ndk-macro", + "ndk-sys", +] + +[[package]] +name = "ndk-macro" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0df7ac00c4672f9d5aece54ee3347520b7e20f158656c7db2e6de01902eb7a6c" +dependencies = [ + "darling", + "proc-macro-crate", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "ndk-sys" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e1bcdd74c20ad5d95aacd60ef9ba40fdf77f767051040541df557b7a9b2a2121" + +[[package]] +name = "nix" +version = "0.22.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf1e25ee6b412c2a1e3fcb6a4499a5c1bfe7f43e014bdce9a6b6666e5aa2d187" +dependencies = [ + "bitflags", + "cc", + "cfg-if 1.0.0", + "libc", + "memoffset", +] + +[[package]] +name = "nom" +version = "7.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b1d11e1ef389c76fe5b81bcaf2ea32cf88b62bc494e19f493d0b30e7a930109" +dependencies = [ + "memchr", + "minimal-lexical", + "version_check", +] + +[[package]] +name = "ntapi" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f6bb902e437b6d86e03cce10a7e2af662292c5dfef23b65899ea3ac9354ad44" +dependencies = [ + "winapi", +] + +[[package]] +name = "num-integer" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2cc698a63b549a70bc047073d2949cce27cd1c7b0a4a862d08a8031bc2801db" +dependencies = [ + "autocfg", + "num-traits", +] + +[[package]] +name = "num-traits" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290" +dependencies = [ + "autocfg", +] + +[[package]] +name = "num_enum" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "085fe377a4b2805c0fbc09484415ec261174614b7f080b0e0d520456ac421a67" +dependencies = [ + "derivative", + "num_enum_derive", +] + +[[package]] +name = "num_enum_derive" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5249369707a1e07b39f78d98c8f34e00aca7dcb053812fdbb5ad7be82c1bba38" +dependencies = [ + "proc-macro-crate", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "objc" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "915b1b472bc21c53464d6c8461c9d3af805ba1ef837e1cac254428f4a77177b1" +dependencies = [ + "malloc_buf", + "objc_exception", +] + +[[package]] +name = "objc_exception" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad970fb455818ad6cba4c122ad012fae53ae8b4795f86378bce65e4f6bab2ca4" +dependencies = [ + "cc", +] + +[[package]] +name = "once_cell" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da32515d9f6e6e489d7bc9d84c71b060db7247dc035bbe44eac88cf87486d8d5" + +[[package]] +name = "parking_lot" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d17b78036a60663b797adeaee46f5c9dfebb86948d1255007a1d6be0271ff99" +dependencies = [ + "instant", + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d76e8e1493bcac0d2766c42737f34458f1c8c50c0d23bcb24ea953affb273216" +dependencies = [ + "cfg-if 1.0.0", + "instant", + "libc", + "redox_syscall 0.2.10", + "smallvec", + "winapi", +] + +[[package]] +name = "peeking_take_while" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099" + +[[package]] +name = "percent-encoding" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" + +[[package]] +name = "petgraph" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a13a2fa9d0b63e5f22328828741e523766fff0ee9e779316902290dff3f824f" +dependencies = [ + "fixedbitset", + "indexmap", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d31d11c69a6b52a174b42bdc0c30e5e11670f90788b2c471c31c1d17d449443" + +[[package]] +name = "pkg-config" +version = "0.3.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "58893f751c9b0412871a09abd62ecd2a00298c6c83befa223ef98c52aef40cbe" + +[[package]] +name = "pollster" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb20dcc30536a1508e75d47dd0e399bb2fe7354dcf35cda9127f2bf1ed92e30e" + +[[package]] +name = "ppv-lite86" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed0cfbc8191465bed66e1718596ee0b0b35d5ee1f41c5df2189d0fe8bde535ba" + +[[package]] +name = "proc-macro-crate" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ebace6889caf889b4d3f76becee12e90353f2b8c7d875534a71e5742f8f6f83" +dependencies = [ + "thiserror", + "toml", +] + +[[package]] +name = "proc-macro2" +version = "1.0.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "392a54546fda6b7cc663379d0e6ce8b324cf88aecc5a499838e1be9781bdce2e" +dependencies = [ + "unicode-xid", +] + +[[package]] +name = "profiling" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9926767b8b8244d7b6b64546585121d193c3d0b4856ccd656b7bfa9deb91ab6a" + +[[package]] +name = "quote" +version = "1.0.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38bc8cc6a5f2e3655e0899c1b848643b2562f853f114bfec7be120678e3ace05" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e7573632e6454cf6b99d7aac4ccca54be06da05aca2ef7423d22d27d4d4bcd8" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", + "rand_hc", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d34f1408f55294453790c48b2f1ebbb1c5b4b7563eb1f418bcfcfdbb06ebb4e7" +dependencies = [ + "getrandom", +] + +[[package]] +name = "rand_hc" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d51e9f596de227fda2ea6c84607f5558e196eeaf43c986b724ba4fb8fdf497e7" +dependencies = [ + "rand_core", +] + +[[package]] +name = "range-alloc" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63e935c45e09cc6dcf00d2f0b2d630a58f4095320223d47fc68918722f0538b6" + +[[package]] +name = "raw-window-handle" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fba75eee94a9d5273a68c9e1e105d9cffe1ef700532325788389e5a83e2522b7" +dependencies = [ + "cty", +] + +[[package]] +name = "redox_syscall" +version = "0.1.57" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce" + +[[package]] +name = "redox_syscall" +version = "0.2.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8383f39639269cde97d255a32bdb68c047337295414940c68bdd30c2e13203ff" +dependencies = [ + "bitflags", +] + +[[package]] +name = "regex" +version = "1.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d07a8629359eb56f1e2fb1652bb04212c072a87ba68546a04065d525673ac461" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" +dependencies = [ + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.6.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b" + +[[package]] +name = "renderdoc-sys" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1382d1f0a252c4bf97dc20d979a2fdd05b024acd7c2ed0f7595d7817666a157" + +[[package]] +name = "rustc-hash" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" + +[[package]] +name = "rustversion" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2cc38e8fa666e2de3c4aba7edeb5ffc5246c1c2ed0e3d17e560aeeba736b23f" + +[[package]] +name = "ryu" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73b4b750c782965c211b42f022f59af1fbceabdd026623714f104152f1ec149f" + +[[package]] +name = "scoped-tls" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea6a9290e3c9cf0f18145ef7ffa62d68ee0bf5fcd651017e586dc7fd5da448c2" + +[[package]] +name = "scopeguard" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" + +[[package]] +name = "scratch" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96311ef4a16462c757bb6a39152c40f58f31cd2602a40fceb937e2bc34e6cbab" + +[[package]] +name = "serde" +version = "1.0.132" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b9875c23cf305cd1fd7eb77234cbb705f21ea6a72c637a5c6db5fe4b8e7f008" + +[[package]] +name = "serde_json" +version = "1.0.73" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bcbd0344bc6533bc7ec56df11d42fb70f1b912351c0825ccb7211b59d8af7cf5" +dependencies = [ + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "sharded-slab" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "900fba806f70c630b0a382d0d825e17a0f19fcd059a2ade1ff237bcddf446b31" +dependencies = [ + "lazy_static", +] + +[[package]] +name = "shlex" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43b2853a4d09f215c24cc5489c992ce46052d359b5109343cbafbf26bc62f8a3" + +[[package]] +name = "slotmap" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e1e08e261d0e8f5c43123b7adf3e4ca1690d655377ac93a03b2c9d3e98de1342" +dependencies = [ + "version_check", +] + +[[package]] +name = "smallvec" +version = "1.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ecab6c735a6bb4139c0caafd0cc3635748bbb3acf4550e8138122099251f309" + +[[package]] +name = "smithay-client-toolkit" +version = "0.15.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "210cf40de565aaaa085face1d860b17f6aee9f76f9d2816307ea2cc45eeb64f3" +dependencies = [ + "bitflags", + "calloop", + "dlib", + "lazy_static", + "log", + "memmap2", + "nix", + "pkg-config", + "wayland-client", + "wayland-cursor", + "wayland-protocols", +] + +[[package]] +name = "spirv" +version = "0.2.0+1.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "246bfa38fe3db3f1dfc8ca5a2cdeb7348c78be2112740cc0ec8ef18b6d94f830" +dependencies = [ + "bitflags", + "num-traits", +] + +[[package]] +name = "static_assertions" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" + +[[package]] +name = "strsim" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" + +[[package]] +name = "strsim" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" + +[[package]] +name = "syn" +version = "1.0.84" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ecb2e6da8ee5eb9a61068762a32fa9619cc591ceb055b3687f4cd4051ec2e06b" +dependencies = [ + "proc-macro2", + "quote", + "unicode-xid", +] + +[[package]] +name = "termcolor" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2dfed899f0eb03f32ee8c6a0aabdb8a7949659e3466561fc0adf54e26d88c5f4" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "textwrap" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" +dependencies = [ + "unicode-width", +] + +[[package]] +name = "thiserror" +version = "1.0.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "854babe52e4df1653706b98fcfc05843010039b406875930a70e4d9644e5c417" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa32fd3f627f367fe16f893e2597ae3c05020f8bba2666a4e6ea73d377e5714b" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "thread-id" +version = "3.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7fbf4c9d56b320106cd64fd024dadfa0be7cb4706725fc44a7d7ce952d820c1" +dependencies = [ + "libc", + "redox_syscall 0.1.57", + "winapi", +] + +[[package]] +name = "thread_local" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8018d24e04c95ac8790716a5987d0fec4f8b27249ffa0f7d33f1369bdfb88cbd" +dependencies = [ + "once_cell", +] + +[[package]] +name = "toml" +version = "0.5.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a31142970826733df8241ef35dc040ef98c679ab14d7c3e54d827099b3acecaa" +dependencies = [ + "serde", +] + +[[package]] +name = "tracing" +version = "0.1.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "375a639232caf30edfc78e8d89b2d4c375515393e7af7e16f01cd96917fb2105" +dependencies = [ + "cfg-if 1.0.0", + "pin-project-lite", + "tracing-core", +] + +[[package]] +name = "tracing-core" +version = "0.1.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f4ed65637b8390770814083d20756f87bfa2c21bf2f110babdc5438351746e4" +dependencies = [ + "lazy_static", +] + +[[package]] +name = "tracing-log" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6923477a48e41c1951f1999ef8bb5a3023eb723ceadafe78ffb65dc366761e3" +dependencies = [ + "lazy_static", + "log", + "tracing-core", +] + +[[package]] +name = "tracing-serde" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb65ea441fbb84f9f6748fd496cf7f63ec9af5bca94dd86456978d055e8eb28b" +dependencies = [ + "serde", + "tracing-core", +] + +[[package]] +name = "tracing-subscriber" +version = "0.2.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e0d2eaa99c3c2e41547cfa109e910a68ea03823cccad4a0525dcbc9b01e8c71" +dependencies = [ + "ansi_term", + "chrono", + "lazy_static", + "matchers", + "regex", + "serde", + "serde_json", + "sharded-slab", + "smallvec", + "thread_local", + "tracing", + "tracing-core", + "tracing-log", + "tracing-serde", +] + +[[package]] +name = "twox-hash" +version = "1.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ee73e6e4924fe940354b8d4d98cad5231175d615cd855b758adc658c0aac6a0" +dependencies = [ + "cfg-if 1.0.0", + "rand", + "static_assertions", +] + +[[package]] +name = "unicode-width" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973" + +[[package]] +name = "unicode-xid" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" + +[[package]] +name = "vec_map" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" + +[[package]] +name = "version_check" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5fecdca9a5291cc2b8dcf7dc02453fee791a280f3743cb0905f8822ae463b3fe" + +[[package]] +name = "wasi" +version = "0.10.2+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" + +[[package]] +name = "wasm-bindgen" +version = "0.2.78" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "632f73e236b219150ea279196e54e610f5dbafa5d61786303d4da54f84e47fce" +dependencies = [ + "cfg-if 1.0.0", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.78" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a317bf8f9fba2476b4b2c85ef4c4af8ff39c3c7f0cdfeed4f82c34a880aa837b" +dependencies = [ + "bumpalo", + "lazy_static", + "log", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e8d7523cb1f2a4c96c1317ca690031b714a51cc14e05f712446691f413f5d39" +dependencies = [ + "cfg-if 1.0.0", + "js-sys", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.78" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d56146e7c495528bf6587663bea13a8eb588d39b36b679d83972e1a2dbbdacf9" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.78" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7803e0eea25835f8abdc585cd3021b3deb11543c6fe226dcd30b228857c5c5ab" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.78" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0237232789cf037d5480773fe568aac745bfe2afbc11a863e97901780a6b47cc" + +[[package]] +name = "wayland-client" +version = "0.29.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9108ec1c37f4774d0c2937ba1a6c23d1786b2152c4a13bd9fdb20e42d16e8841" +dependencies = [ + "bitflags", + "downcast-rs", + "libc", + "nix", + "scoped-tls", + "wayland-commons", + "wayland-scanner", + "wayland-sys", +] + +[[package]] +name = "wayland-commons" +version = "0.29.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "265ef51b3b3e5c9ef098f10425c39624663f459c3821dcaacc4748be975f1beb" +dependencies = [ + "nix", + "once_cell", + "smallvec", + "wayland-sys", +] + +[[package]] +name = "wayland-cursor" +version = "0.29.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c19bb6628daf4097e58b7911481e8371e13318d5a60894779901bd3267407a7" +dependencies = [ + "nix", + "wayland-client", + "xcursor", +] + +[[package]] +name = "wayland-protocols" +version = "0.29.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b3b6f1dc0193072ef4eadcb144da30d58c1f2895516c063804d213310703c8e" +dependencies = [ + "bitflags", + "wayland-client", + "wayland-commons", + "wayland-scanner", +] + +[[package]] +name = "wayland-scanner" +version = "0.29.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eaaf2bc85e7b9143159af96bd23d954a5abe391c4376db712320643280fdc6f4" +dependencies = [ + "proc-macro2", + "quote", + "xml-rs", +] + +[[package]] +name = "wayland-sys" +version = "0.29.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba9e06acb775b3007f8d3094438306979e572d1d3b844d7a71557a84b055d959" +dependencies = [ + "dlib", + "lazy_static", + "pkg-config", +] + +[[package]] +name = "web-sys" +version = "0.3.55" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38eb105f1c59d9eaa6b5cdc92b859d85b926e82cb2e0945cd0c9259faa6fe9fb" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "wgpu" +version = "0.12.0" +source = "git+https://github.com/gfx-rs/wgpu?rev=39b7a8a202c21da43035ec8dd5570a58cf4e8ef1#39b7a8a202c21da43035ec8dd5570a58cf4e8ef1" +dependencies = [ + "arrayvec", + "js-sys", + "log", + "naga", + "parking_lot", + "raw-window-handle", + "smallvec", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "wgpu-core", + "wgpu-hal", + "wgpu-types", +] + +[[package]] +name = "wgpu-core" +version = "0.12.0" +source = "git+https://github.com/gfx-rs/wgpu?rev=39b7a8a202c21da43035ec8dd5570a58cf4e8ef1#39b7a8a202c21da43035ec8dd5570a58cf4e8ef1" +dependencies = [ + "arrayvec", + "bitflags", + "cfg_aliases", + "codespan-reporting", + "copyless", + "fxhash", + "log", + "naga", + "parking_lot", + "profiling", + "raw-window-handle", + "smallvec", + "thiserror", + "wgpu-hal", + "wgpu-types", +] + +[[package]] +name = "wgpu-hal" +version = "0.12.0" +source = "git+https://github.com/gfx-rs/wgpu?rev=39b7a8a202c21da43035ec8dd5570a58cf4e8ef1#39b7a8a202c21da43035ec8dd5570a58cf4e8ef1" +dependencies = [ + "arrayvec", + "ash", + "bit-set", + "bitflags", + "block", + "core-graphics-types", + "d3d12", + "foreign-types", + "fxhash", + "glow", + "gpu-alloc", + "gpu-descriptor", + "inplace_it", + "js-sys", + "khronos-egl", + "libloading", + "log", + "metal", + "naga", + "objc", + "parking_lot", + "profiling", + "range-alloc", + "raw-window-handle", + "renderdoc-sys", + "thiserror", + "wasm-bindgen", + "web-sys", + "wgpu-types", + "winapi", +] + +[[package]] +name = "wgpu-subscriber" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91955b0d6480d86e577bbd0b0d1dd5acd0699c054610dc8673c4c3366295ed27" +dependencies = [ + "parking_lot", + "thread-id", + "tracing", + "tracing-log", + "tracing-subscriber", +] + +[[package]] +name = "wgpu-types" +version = "0.12.0" +source = "git+https://github.com/gfx-rs/wgpu?rev=39b7a8a202c21da43035ec8dd5570a58cf4e8ef1#39b7a8a202c21da43035ec8dd5570a58cf4e8ef1" +dependencies = [ + "bitflags", +] + +[[package]] +name = "which" +version = "4.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea187a8ef279bc014ec368c27a920da2024d2a711109bfbe3440585d5cf27ad9" +dependencies = [ + "either", + "lazy_static", + "libc", +] + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-util" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" +dependencies = [ + "winapi", +] + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "winit" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70466a5f4825cc88c92963591b06dbc255420bffe19d847bfcda475e82d079c0" +dependencies = [ + "bitflags", + "block", + "cocoa", + "core-foundation 0.9.2", + "core-graphics 0.22.3", + "core-video-sys", + "dispatch", + "instant", + "lazy_static", + "libc", + "log", + "mio", + "ndk", + "ndk-glue", + "ndk-sys", + "objc", + "parking_lot", + "percent-encoding", + "raw-window-handle", + "smithay-client-toolkit", + "wasm-bindgen", + "wayland-client", + "wayland-protocols", + "web-sys", + "winapi", + "x11-dl", +] + +[[package]] +name = "x11-dl" +version = "2.19.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea26926b4ce81a6f5d9d0f3a0bc401e5a37c6ae14a1bfaa8ff6099ca80038c59" +dependencies = [ + "lazy_static", + "libc", + "pkg-config", +] + +[[package]] +name = "xcursor" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "463705a63313cd4301184381c5e8042f0a7e9b4bb63653f216311d4ae74690b7" +dependencies = [ + "nom", +] + +[[package]] +name = "xml-rs" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2d7d3948613f75c98fd9328cfdcc45acc4d360655289d0a7d4ec931392200a3" diff --git a/Graphics/Cargo.toml b/Graphics/Cargo.toml new file mode 100644 index 000000000..f38d2a7ee --- /dev/null +++ b/Graphics/Cargo.toml @@ -0,0 +1,75 @@ +[package] +name = "aurora" +version = "0.0.1" +authors = ["Luke Street "] +edition = "2021" +license = "MIT" + +[lib] +crate-type = ["staticlib"] + +#[[bin]] +#name = "metaforce" +#path = "src/main.rs" + +[dependencies] +cxx = "1.0.60" +web-sys = "0.3.55" +env_logger = "0.9.0" +mobile-entry-point = "0.1.1" +pollster = "0.2.4" +binread = { version = "2.2.0", features = ['const_generics'] } +modular-bitfield = "0.11.2" +num-traits = "0.2.14" +num_enum = "0.5.5" +bytemuck = "1.7.3" +bytemuck_derive = "1.0.1" +log = "0.4.14" +log-panics = "2.0.0" +cgmath = "0.18.0" +smallvec = "1.7.0" +scopeguard = "1.1.0" +twox-hash = "1.6.2" +winit = "0.26.0" + +[dependencies.imgui] +git = "https://github.com/imgui-rs/imgui-rs" +rev = "55a76370466953d5c044afc123330d0262b50e17" +[dependencies.imgui-winit-support] +git = "https://github.com/imgui-rs/imgui-rs" +rev = "55a76370466953d5c044afc123330d0262b50e17" +default-features = false +features = ["winit-26"] +[patch.'https://github.com/imgui-rs/imgui-rs'] +imgui-sys = { path = "../imgui-sys" } +[patch.crates-io] +imgui-sys = { path = "../imgui-sys" } + +[dependencies.wgpu] +#path = "../../wgpu/wgpu" +git = "https://github.com/gfx-rs/wgpu" +rev = "39b7a8a202c21da43035ec8dd5570a58cf4e8ef1" +features = ["spirv"] + +#[patch.'https://github.com/gfx-rs/naga'] +#naga = { path = "../../naga" } + +[build-dependencies] +#naga = { path = "../../naga", features = ['spv-out', 'wgsl-in'] } +naga = { git = "https://github.com/gfx-rs/naga", rev = "8df5421", features = ['spv-out', 'wgsl-in'] } +bytemuck = "1.7.3" +cxx-build = "1.0.60" +bindgen = "0.59.2" + +[target.'cfg(target_os = "android")'.dependencies] +android_logger = "0.10.1" +ndk-glue = "0.5.0" + +[target.'cfg(not(target_os = "android"))'.dependencies] +wgpu-subscriber = "0.1.0" + +[target.'cfg(target_family = "wasm")'.dependencies] +console_error_panic_hook = "0.1.7" +console_log = "0.2.0" +wasm-bindgen-futures = "0.4.28" +#features = ["web-sys"] diff --git a/Graphics/build.rs b/Graphics/build.rs new file mode 100644 index 000000000..da5fb6eb3 --- /dev/null +++ b/Graphics/build.rs @@ -0,0 +1,47 @@ +fn main() { + let zeus_include = std::path::PathBuf::from(format!( + "{}/../extern/zeus/include", + std::env::var("CARGO_MANIFEST_DIR").unwrap() + )) + .canonicalize() + .unwrap(); + let imgui_include = std::path::PathBuf::from(format!( + "{}/../extern/imgui", + std::env::var("CARGO_MANIFEST_DIR").unwrap() + )) + .canonicalize() + .unwrap(); + let imgui_engine_include = std::path::PathBuf::from(format!( + "{}/../imgui", + std::env::var("CARGO_MANIFEST_DIR").unwrap() + )) + .canonicalize() + .unwrap(); + // let include_dir = include_path.to_string_lossy(); + // let bindings = bindgen::Builder::default() + // .header(format!("{}/zeus/CVector3f.hpp", include_dir)) + // .clang_arg(format!("-I{}", include_dir)) + // .parse_callbacks(Box::new(bindgen::CargoCallbacks)) + // .generate() + // .expect("Unable to generate bindings"); + // let out_path = std::path::PathBuf::from(std::env::var("OUT_DIR").unwrap()); + // bindings.write_to_file(out_path.join("zeus.rs")).expect("Couldn't write bindings!"); + + cxx_build::bridge("src/lib.rs") + .include("include") + .include(zeus_include.clone()) + .compile("aurora"); + println!("cargo:rerun-if-changed=src/lib.rs"); + cxx_build::bridge("src/shaders/mod.rs") + .include("include") + .include(zeus_include.clone()) + .compile("aurora_shaders"); + println!("cargo:rerun-if-changed=src/shaders/mod.rs"); + cxx_build::bridge("src/imgui.rs") + .include("include") + .include(zeus_include.clone()) + .include(imgui_include.clone()) + .include(imgui_engine_include.clone()) + .compile("aurora_imgui"); + println!("cargo:rerun-if-changed=src/imgui.rs"); +} diff --git a/Graphics/include/aurora.hpp b/Graphics/include/aurora.hpp new file mode 100644 index 000000000..bf37d194a --- /dev/null +++ b/Graphics/include/aurora.hpp @@ -0,0 +1,48 @@ +#pragma once + +#include +#include +#include + +namespace aurora { +struct WindowSize; + +struct App; +struct AppDelegate { + AppDelegate() = default; + virtual ~AppDelegate() noexcept = default; + AppDelegate(const AppDelegate&) = delete; + AppDelegate& operator=(const AppDelegate&) = delete; + AppDelegate(AppDelegate&&) = delete; + AppDelegate& operator=(AppDelegate&&) = delete; + + virtual void onAppLaunched() noexcept = 0; + virtual bool onAppIdle(float dt) noexcept = 0; + virtual void onAppDraw() noexcept = 0; + virtual void onAppPostDraw() noexcept = 0; + virtual void onAppExiting() noexcept = 0; + +// virtual void resized([[maybe_unused]] const WindowSize& rect, [[maybe_unused]] bool sync) noexcept {} +// virtual void mouseDown([[maybe_unused]] const SWindowCoord& coord, [[maybe_unused]] EMouseButton button, +// [[maybe_unused]] EModifierKey mods) noexcept {} +// virtual void mouseUp([[maybe_unused]] const SWindowCoord& coord, [[maybe_unused]] EMouseButton button, +// [[maybe_unused]] EModifierKey mods) noexcept {} +// virtual void mouseMove([[maybe_unused]] const SWindowCoord& coord) noexcept {} +// virtual void mouseEnter([[maybe_unused]] const SWindowCoord& coord) noexcept {} +// virtual void mouseLeave([[maybe_unused]] const SWindowCoord& coord) noexcept {} +// virtual void scroll([[maybe_unused]] const SWindowCoord& coord, [[maybe_unused]] const SScrollDelta& scroll) noexcept {} +// +// virtual void touchDown([[maybe_unused]] const STouchCoord& coord, [[maybe_unused]] uintptr_t tid) noexcept {} +// virtual void touchUp([[maybe_unused]] const STouchCoord& coord, [[maybe_unused]] uintptr_t tid) noexcept {} +// virtual void touchMove([[maybe_unused]] const STouchCoord& coord, [[maybe_unused]] uintptr_t tid) noexcept {} +// +// virtual void charKeyDown([[maybe_unused]] unsigned long charCode, [[maybe_unused]] EModifierKey mods, +// [[maybe_unused]] bool isRepeat) noexcept {} +// virtual void charKeyUp([[maybe_unused]] unsigned long charCode, [[maybe_unused]] EModifierKey mods) noexcept {} +// virtual void specialKeyDown([[maybe_unused]] ESpecialKey key, [[maybe_unused]] EModifierKey mods, +// [[maybe_unused]] bool isRepeat) noexcept {} +// virtual void specialKeyUp([[maybe_unused]] ESpecialKey key, [[maybe_unused]] EModifierKey mods) noexcept {} +// virtual void modKeyDown([[maybe_unused]] EModifierKey mod, [[maybe_unused]] bool isRepeat) noexcept {} +// virtual void modKeyUp([[maybe_unused]] EModifierKey mod) noexcept {} +}; +} // namespace aurora diff --git a/Graphics/include/lib.hpp b/Graphics/include/lib.hpp new file mode 100644 index 000000000..7df8caa23 --- /dev/null +++ b/Graphics/include/lib.hpp @@ -0,0 +1,9 @@ +#include "aurora.hpp" + +namespace aurora { +void App_onAppLaunched(AppDelegate& cb) noexcept; +bool App_onAppIdle(AppDelegate& cb, float dt) noexcept; +void App_onAppDraw(AppDelegate& cb) noexcept; +void App_onAppPostDraw(AppDelegate& cb) noexcept; +void App_onAppExiting(AppDelegate& cb) noexcept; +} // namespace aurora diff --git a/Graphics/lib.cpp b/Graphics/lib.cpp new file mode 100644 index 000000000..ad2b68556 --- /dev/null +++ b/Graphics/lib.cpp @@ -0,0 +1,9 @@ +#include "include/lib.hpp" + +namespace aurora { +void App_onAppLaunched(AppDelegate& cb) noexcept { return cb.onAppLaunched(); } +bool App_onAppIdle(AppDelegate& cb, float dt) noexcept { return cb.onAppIdle(dt); } +void App_onAppDraw(AppDelegate& cb) noexcept { cb.onAppDraw(); } +void App_onAppPostDraw(AppDelegate& cb) noexcept { cb.onAppPostDraw(); } +void App_onAppExiting(AppDelegate& cb) noexcept { cb.onAppExiting(); } +} // namespace aurora diff --git a/Graphics/rustfmt.toml b/Graphics/rustfmt.toml new file mode 100644 index 000000000..0a9eda5dc --- /dev/null +++ b/Graphics/rustfmt.toml @@ -0,0 +1,8 @@ +fn_single_line = true +group_imports = "StdExternalCrate" +imports_granularity = "Crate" +overflow_delimited_expr = true +reorder_impl_items = true +use_field_init_shorthand = true +use_small_heuristics = "Max" +where_single_line = true diff --git a/Graphics/src/gpu.rs b/Graphics/src/gpu.rs new file mode 100644 index 000000000..1ad805a85 --- /dev/null +++ b/Graphics/src/gpu.rs @@ -0,0 +1,194 @@ +use std::{num::NonZeroU8, sync::Arc}; + +use pollster::block_on; + +#[derive(Clone)] +pub(crate) struct GraphicsConfig { + pub(crate) color_format: wgpu::TextureFormat, + pub(crate) depth_format: wgpu::TextureFormat, + pub(crate) texture_anistropy: Option, + pub(crate) msaa_samples: u32, +} + +pub struct DeviceHolder { + pub(crate) instance: wgpu::Instance, + pub(crate) surface: wgpu::Surface, + pub(crate) adapter: wgpu::Adapter, + pub(crate) backend: wgpu::Backend, + pub(crate) device: Arc, + pub(crate) queue: Arc, + pub(crate) config: GraphicsConfig, + pub(crate) surface_config: wgpu::SurfaceConfiguration, + pub(crate) framebuffer: TextureWithSampler, + pub(crate) depth: TextureWithSampler, +} + +pub(crate) struct TextureWithSampler { + pub(crate) texture: wgpu::Texture, + pub(crate) view: wgpu::TextureView, + pub(crate) sampler: wgpu::Sampler, +} + +pub(crate) fn create_render_texture( + device: &wgpu::Device, + config: &wgpu::SurfaceConfiguration, + graphics_config: &GraphicsConfig, +) -> TextureWithSampler { + let texture = device.create_texture(&wgpu::TextureDescriptor { + label: Some("Render texture"), + size: wgpu::Extent3d { + width: config.width, + height: config.height, + depth_or_array_layers: 1, + }, + mip_level_count: 1, + sample_count: graphics_config.msaa_samples, + dimension: wgpu::TextureDimension::D2, + format: graphics_config.color_format, + usage: wgpu::TextureUsages::RENDER_ATTACHMENT, + }); + let view = texture.create_view(&wgpu::TextureViewDescriptor::default()); + let sampler = device.create_sampler(&wgpu::SamplerDescriptor { + label: Some("Render sampler"), + address_mode_u: wgpu::AddressMode::ClampToEdge, + address_mode_v: wgpu::AddressMode::ClampToEdge, + address_mode_w: wgpu::AddressMode::ClampToEdge, + mag_filter: wgpu::FilterMode::Linear, + min_filter: wgpu::FilterMode::Linear, + mipmap_filter: wgpu::FilterMode::Linear, + lod_min_clamp: 0.0, + lod_max_clamp: f32::MAX, + compare: None, + anisotropy_clamp: None, + border_color: None, + }); + TextureWithSampler { texture, view, sampler } +} + +pub(crate) fn create_depth_texture( + device: &wgpu::Device, + config: &wgpu::SurfaceConfiguration, + graphics_config: &GraphicsConfig, +) -> TextureWithSampler { + let texture = device.create_texture(&wgpu::TextureDescriptor { + label: Some("Depth texture"), + size: wgpu::Extent3d { + width: config.width, + height: config.height, + depth_or_array_layers: 1, + }, + mip_level_count: 1, + sample_count: graphics_config.msaa_samples, + dimension: wgpu::TextureDimension::D2, + format: graphics_config.depth_format, + usage: wgpu::TextureUsages::RENDER_ATTACHMENT, + }); + let view = texture.create_view(&wgpu::TextureViewDescriptor::default()); + let sampler = device.create_sampler(&wgpu::SamplerDescriptor { + label: Some("Depth sampler"), + address_mode_u: wgpu::AddressMode::ClampToEdge, + address_mode_v: wgpu::AddressMode::ClampToEdge, + address_mode_w: wgpu::AddressMode::ClampToEdge, + mag_filter: wgpu::FilterMode::Linear, + min_filter: wgpu::FilterMode::Linear, + mipmap_filter: wgpu::FilterMode::Linear, + lod_min_clamp: 0.0, + lod_max_clamp: f32::MAX, + compare: None, + anisotropy_clamp: None, + border_color: None, + }); + TextureWithSampler { texture, view, sampler } +} + +pub(crate) fn initialize_gpu(window: &winit::window::Window) -> DeviceHolder { + log::info!("Creating wgpu instance"); + let instance = wgpu::Instance::new(wgpu::Backends::all()); + let surface = unsafe { instance.create_surface(window) }; + let adapter = block_on(instance.request_adapter(&wgpu::RequestAdapterOptions { + power_preference: wgpu::PowerPreference::HighPerformance, + compatible_surface: Some(&surface), + force_fallback_adapter: false, + })) + .expect("Failed to find an appropriate adapter"); + let best_limits = adapter.limits(); + let backend = adapter.get_info().backend; + #[cfg(any(target_os = "android", target_os = "ios"))] + let needs_denorm = true; + #[cfg(not(any(target_os = "android", target_os = "ios")))] + let _needs_denorm = backend == wgpu::Backend::Gl; + + let required_features = if backend == wgpu::Backend::Vulkan { + wgpu::Features::SPIRV_SHADER_PASSTHROUGH + } else { + wgpu::Features::empty() + }; + let optional_features = wgpu::Features::TEXTURE_COMPRESSION_BC + | wgpu::Features::ADDRESS_MODE_CLAMP_TO_BORDER + | required_features; + log::info!("Requesting device with features: {:?}", optional_features); + let limits = wgpu::Limits::downlevel_defaults() + .using_resolution(best_limits.clone()) + .using_alignment(best_limits); + let (device, queue) = block_on(adapter.request_device( + &wgpu::DeviceDescriptor { + label: Some("Device with optional features"), + features: optional_features, + limits: limits.clone(), + }, + None, + )) + .unwrap_or_else(|_| { + log::warn!("Failed... requesting device with no features"); + block_on(adapter.request_device( + &wgpu::DeviceDescriptor { + label: Some("Device without optional features"), + features: required_features, + limits, + }, + None, + )) + .expect("Failed to create device") + }); + log::info!("Successfully created device"); + + let mut swapchain_format = surface.get_preferred_format(&adapter).unwrap(); + if backend != wgpu::Backend::Gl { + swapchain_format = match swapchain_format { + wgpu::TextureFormat::Rgba8UnormSrgb => wgpu::TextureFormat::Rgba8Unorm, + wgpu::TextureFormat::Bgra8UnormSrgb => wgpu::TextureFormat::Bgra8Unorm, + _ => swapchain_format, + }; + } + let graphics_config = GraphicsConfig { + color_format: swapchain_format, + depth_format: wgpu::TextureFormat::Depth32Float, + texture_anistropy: NonZeroU8::new(16), + msaa_samples: 4, + }; + + let size = window.inner_size(); + let surface_config = wgpu::SurfaceConfiguration { + usage: wgpu::TextureUsages::RENDER_ATTACHMENT, + format: swapchain_format, + width: size.width, + height: size.height, + present_mode: wgpu::PresentMode::Fifo, + }; + surface.configure(&device, &surface_config); + let depth = create_depth_texture(&device, &surface_config, &graphics_config); + let framebuffer = create_render_texture(&device, &surface_config, &graphics_config); + + DeviceHolder { + instance, + surface, + adapter, + backend, + device: Arc::new(device), + queue: Arc::new(queue), + config: graphics_config, + surface_config, + framebuffer, + depth, + } +} diff --git a/Graphics/src/imgui.rs b/Graphics/src/imgui.rs new file mode 100644 index 000000000..992cd0b60 --- /dev/null +++ b/Graphics/src/imgui.rs @@ -0,0 +1,80 @@ +use crate::{gpu::DeviceHolder, imgui_backend}; + +#[cxx::bridge(namespace = "metaforce")] +mod ffi { + unsafe extern "C++" { + include!("ImGuiEngine.hpp"); + pub(crate) fn ImGuiEngine_Initialize(scale: f32); + pub(crate) fn ImGuiEngine_AddTextures(state: &mut ImGuiState, device: &DeviceHolder); + } + + extern "Rust" { + type ImGuiState; + type DeviceHolder; + fn ImGuiEngine_AddTexture( + state: &mut ImGuiState, + device: &DeviceHolder, + width: u32, + height: u32, + data: &[u8], + ) -> usize; + } +} + +pub struct ImGuiState { + pub(crate) context: imgui::Context, + pub(crate) platform: imgui_winit_support::WinitPlatform, + pub(crate) backend: imgui_backend::Renderer, +} + +pub(crate) fn initialize_imgui(window: &winit::window::Window, gpu: &DeviceHolder) -> ImGuiState { + let hidpi_factor = window.scale_factor(); + let mut imgui = imgui::Context::create(); + let mut platform = imgui_winit_support::WinitPlatform::init(&mut imgui); + platform.attach_window(imgui.io_mut(), &window, imgui_winit_support::HiDpiMode::Default); + imgui.set_ini_filename(None); + imgui.io_mut().font_global_scale = (1.0 / hidpi_factor) as f32; + + unsafe { + ffi::ImGuiEngine_Initialize(hidpi_factor as f32); + } + + let renderer_config = if gpu.backend == wgpu::Backend::Vulkan { + imgui_backend::RendererConfig::new_spv_srgb() + } else { + imgui_backend::RendererConfig::new_srgb() + }; + let imgui_backend = imgui_backend::Renderer::new( + &mut imgui, + &gpu.device, + &gpu.queue, + imgui_backend::RendererConfig { + texture_format: gpu.config.color_format, + depth_format: Some(gpu.config.depth_format), + sample_count: gpu.config.msaa_samples, + ..renderer_config + }, + ); + let mut state = ImGuiState { context: imgui, platform, backend: imgui_backend }; + unsafe { + ffi::ImGuiEngine_AddTextures(&mut state, &gpu); + } + state +} + +fn ImGuiEngine_AddTexture( + state: &mut ImGuiState, + gpu: &DeviceHolder, + width: u32, + height: u32, + data: &[u8], +) -> usize { + let texture = + imgui_backend::Texture::new(&gpu.device, &state.backend, imgui_backend::TextureConfig { + size: wgpu::Extent3d { width, height, depth_or_array_layers: 1 }, + format: Some(wgpu::TextureFormat::Rgba8Unorm), + ..Default::default() + }); + texture.write(&gpu.queue, data, width, height); + state.backend.textures.insert(texture).id() +} diff --git a/Graphics/src/imgui_backend/imgui.wgsl b/Graphics/src/imgui_backend/imgui.wgsl new file mode 100644 index 000000000..d00d9e1cd --- /dev/null +++ b/Graphics/src/imgui_backend/imgui.wgsl @@ -0,0 +1,53 @@ +struct Uniforms { + u_Matrix: mat4x4; +}; + +struct VertexInput { + [[location(0)]] a_Pos: vec2; + [[location(1)]] a_UV: vec2; + [[location(2)]] a_Color: vec4; +}; + +struct VertexOutput { + [[location(0)]] v_UV: vec2; + [[location(1)]] v_Color: vec4; + [[builtin(position)]] v_Position: vec4; +}; + +[[group(0), binding(0)]] +var uniforms: Uniforms; + +[[stage(vertex)]] +fn vs_main(in: VertexInput) -> VertexOutput { + var out: VertexOutput; + out.v_UV = in.a_UV; + out.v_Color = in.a_Color; + out.v_Position = uniforms.u_Matrix * vec4(in.a_Pos.xy, 0.0, 1.0); + return out; +} + +[[group(1), binding(0)]] +var u_Texture: texture_2d; +[[group(1), binding(1)]] +var u_Sampler: sampler; + +fn srgb_to_linear(srgb: vec4) -> vec4 { + let color_srgb = srgb.rgb; + let selector = ceil(color_srgb - 0.04045); // 0 if under value, 1 if over + let under = color_srgb / 12.92; + let over = pow((color_srgb + 0.055) / 1.055, vec3(2.4)); + let result = mix(under, over, selector); + return vec4(result, srgb.a); +} + +[[stage(fragment)]] +fn fs_main_linear(in: VertexOutput) -> [[location(0)]] vec4 { + let color = srgb_to_linear(in.v_Color); + return color * textureSample(u_Texture, u_Sampler, in.v_UV); +} + +[[stage(fragment)]] +fn fs_main_srgb(in: VertexOutput) -> [[location(0)]] vec4 { + let color = in.v_Color; + return color * textureSample(u_Texture, u_Sampler, in.v_UV); +} diff --git a/Graphics/src/imgui_backend/mod.rs b/Graphics/src/imgui_backend/mod.rs new file mode 100644 index 000000000..dc6b48518 --- /dev/null +++ b/Graphics/src/imgui_backend/mod.rs @@ -0,0 +1,659 @@ +use std::{borrow::BorrowMut, error::Error, fmt, mem::size_of, num::NonZeroU32}; + +use imgui::{ + Context, DrawCmd::Elements, DrawData, DrawIdx, DrawList, DrawVert, TextureId, Textures, +}; +use smallvec::SmallVec; +use wgpu::{ + util::{BufferInitDescriptor, DeviceExt}, + *, +}; + +static VS_ENTRY_POINT: &str = "vs_main"; +static FS_ENTRY_POINT_LINEAR: &str = "fs_main_linear"; +static FS_ENTRY_POINT_SRGB: &str = "fs_main_srgb"; + +pub type RendererResult = Result; + +#[repr(transparent)] +#[derive(Debug, Copy, Clone)] +struct DrawVertPod(DrawVert); + +unsafe impl bytemuck::Zeroable for DrawVertPod {} + +unsafe impl bytemuck::Pod for DrawVertPod {} + +#[derive(Clone, Debug)] +pub enum RendererError { + BadTexture(TextureId), +} + +impl fmt::Display for RendererError { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match *self { + RendererError::BadTexture(id) => { + write!(f, "imgui render error: bad texture id '{}'", id.id()) + } + } + } +} + +impl Error for RendererError {} + +#[allow(dead_code)] +enum ShaderStage { + Vertex, + Fragment, + Compute, +} + +/// Config for creating a texture. +/// +/// Uses the builder pattern. +#[derive(Clone)] +pub struct TextureConfig<'a> { + /// The size of the texture. + pub size: Extent3d, + /// An optional label for the texture used for debugging. + pub label: Option<&'a str>, + /// The format of the texture, if not set uses the format from the renderer. + pub format: Option, + /// The usage of the texture. + pub usage: TextureUsages, + /// The mip level of the texture. + pub mip_level_count: u32, + /// The sample count of the texture. + pub sample_count: u32, + /// The dimension of the texture. + pub dimension: TextureDimension, +} + +impl<'a> Default for TextureConfig<'a> { + /// Create a new texture config. + fn default() -> Self { + Self { + size: Extent3d { width: 0, height: 0, depth_or_array_layers: 1 }, + label: None, + format: None, + usage: TextureUsages::TEXTURE_BINDING | TextureUsages::COPY_DST, + mip_level_count: 1, + sample_count: 1, + dimension: TextureDimension::D2, + } + } +} + +/// A container for a bindable texture. +pub struct Texture { + texture: wgpu::Texture, + view: wgpu::TextureView, + bind_group: BindGroup, + size: Extent3d, +} + +impl Texture { + /// Create a `Texture` from its raw parts. + pub fn from_raw_parts( + texture: wgpu::Texture, + view: wgpu::TextureView, + bind_group: BindGroup, + size: Extent3d, + ) -> Self { + Self { texture, view, bind_group, size } + } + + /// Create a new GPU texture width the specified `config`. + pub fn new(device: &Device, renderer: &Renderer, config: TextureConfig) -> Self { + // Create the wgpu texture. + let texture = device.create_texture(&TextureDescriptor { + label: config.label, + size: config.size, + mip_level_count: config.mip_level_count, + sample_count: config.sample_count, + dimension: config.dimension, + format: config.format.unwrap_or(renderer.config.texture_format), + usage: config.usage, + }); + + // Extract the texture view. + let view = texture.create_view(&TextureViewDescriptor::default()); + + // Create the texture sampler. + let sampler = device.create_sampler(&SamplerDescriptor { + label: Some("imgui-wgpu sampler"), + address_mode_u: AddressMode::ClampToEdge, + address_mode_v: AddressMode::ClampToEdge, + address_mode_w: AddressMode::ClampToEdge, + mag_filter: FilterMode::Linear, + min_filter: FilterMode::Linear, + mipmap_filter: FilterMode::Linear, + lod_min_clamp: 0.0, + lod_max_clamp: f32::MAX, + compare: None, + anisotropy_clamp: None, + border_color: None, + }); + + // Create the texture bind group from the layout. + let bind_group = device.create_bind_group(&BindGroupDescriptor { + label: config.label, + layout: &renderer.texture_layout, + entries: &[ + BindGroupEntry { binding: 0, resource: BindingResource::TextureView(&view) }, + BindGroupEntry { binding: 1, resource: BindingResource::Sampler(&sampler) }, + ], + }); + + Self { texture, view, bind_group, size: config.size } + } + + /// Write `data` to the texture. + /// + /// - `data`: 32-bit RGBA bitmap data. + /// - `width`: The width of the source bitmap (`data`) in pixels. + /// - `height`: The height of the source bitmap (`data`) in pixels. + pub fn write(&self, queue: &Queue, data: &[u8], width: u32, height: u32) { + queue.write_texture( + // destination (sub)texture + ImageCopyTexture { + texture: &self.texture, + mip_level: 0, + origin: Origin3d { x: 0, y: 0, z: 0 }, + aspect: TextureAspect::All, + }, + // source bitmap data + data, + // layout of the source bitmap + ImageDataLayout { + offset: 0, + bytes_per_row: NonZeroU32::new(width * 4), + rows_per_image: NonZeroU32::new(height), + }, + // size of the source bitmap + Extent3d { width, height, depth_or_array_layers: 1 }, + ); + } + + /// The width of the texture in pixels. + pub fn width(&self) -> u32 { self.size.width } + + /// The height of the texture in pixels. + pub fn height(&self) -> u32 { self.size.height } + + /// The depth of the texture. + pub fn depth(&self) -> u32 { self.size.depth_or_array_layers } + + /// The size of the texture in pixels. + pub fn size(&self) -> Extent3d { self.size } + + /// The underlying `wgpu::Texture`. + pub fn texture(&self) -> &wgpu::Texture { &self.texture } + + /// The `wgpu::TextureView` of the underlying texture. + pub fn view(&self) -> &wgpu::TextureView { &self.view } +} + +pub struct CombinedShader<'s> { + pub shader: ShaderModuleDescriptor<'s>, +} + +pub struct SeparateShaders<'s> { + pub vertex_shader: ShaderModuleDescriptorSpirV<'s>, + pub fragment_shader: ShaderModuleDescriptorSpirV<'s>, +} + +pub enum ShaderType<'s> { + None, + Combined(CombinedShader<'s>), + Separate(SeparateShaders<'s>), +} + +/// Configuration for the renderer. +pub struct RendererConfig<'s> { + pub texture_format: TextureFormat, + pub depth_format: Option, + pub sample_count: u32, + pub shader: ShaderType<'s>, + pub vertex_shader_entry_point: String, + pub fragment_shader_entry_point: String, +} + +impl RendererConfig<'_> { + /// Create a new renderer config with custom shaders. + pub fn with_combined_shaders<'s>( + shader: ShaderModuleDescriptor<'s>, + fragment_shader_entry_point: &str, + ) -> RendererConfig<'s> { + RendererConfig { + texture_format: TextureFormat::Rgba8Unorm, + depth_format: None, + sample_count: 1, + shader: ShaderType::Combined(CombinedShader { shader }), + vertex_shader_entry_point: VS_ENTRY_POINT.to_string(), + fragment_shader_entry_point: fragment_shader_entry_point.to_string(), + } + } + + /// Create a new renderer config with custom shaders. + pub fn with_separate_shaders<'s>( + vertex_shader: ShaderModuleDescriptorSpirV<'s>, + fragment_shader: ShaderModuleDescriptorSpirV<'s>, + fragment_shader_entry_point: &str, + ) -> RendererConfig<'s> { + RendererConfig { + texture_format: TextureFormat::Rgba8Unorm, + depth_format: None, + sample_count: 1, + shader: ShaderType::Separate(SeparateShaders { vertex_shader, fragment_shader }), + vertex_shader_entry_point: VS_ENTRY_POINT.to_string(), + fragment_shader_entry_point: fragment_shader_entry_point.to_string(), + } + } +} + +impl Default for RendererConfig<'_> { + /// Create a new renderer config with precompiled default shaders outputting linear color. + /// + /// If you write to a Bgra8UnormSrgb framebuffer, this is what you want. + fn default() -> Self { Self::new() } +} + +impl RendererConfig<'_> { + /// Create a new renderer config with precompiled default shaders outputting linear color. + /// + /// If you write to a Bgra8UnormSrgb framebuffer, this is what you want. + pub fn new() -> Self { + Self::with_combined_shaders(include_wgsl!("imgui.wgsl"), FS_ENTRY_POINT_LINEAR) + } + + /// Create a new renderer config with precompiled default shaders outputting srgb color. + /// + /// If you write to a Bgra8Unorm framebuffer, this is what you want. + pub fn new_srgb() -> Self { + Self::with_combined_shaders(include_wgsl!("imgui.wgsl"), FS_ENTRY_POINT_SRGB) + } + + /// Create a new renderer config with precompiled default shaders outputting linear color. + /// + /// If you write to a Bgra8UnormSrgb framebuffer, this is what you want. + pub fn new_spv() -> Self { + Self::with_separate_shaders( + include_spirv_raw!("imgui_vs_main.spv"), + include_spirv_raw!("imgui_fs_main_linear.spv"), + FS_ENTRY_POINT_LINEAR, + ) + } + + /// Create a new renderer config with precompiled default shaders outputting srgb color. + /// + /// If you write to a Bgra8Unorm framebuffer, this is what you want. + pub fn new_spv_srgb() -> Self { + Self::with_separate_shaders( + include_spirv_raw!("imgui_vs_main.spv"), + include_spirv_raw!("imgui_fs_main_srgb.spv"), + FS_ENTRY_POINT_SRGB, + ) + } +} + +pub struct Renderer { + pipeline: RenderPipeline, + uniform_buffer: Buffer, + uniform_bind_group: BindGroup, + /// Textures of the font atlas and all images. + pub textures: Textures, + texture_layout: BindGroupLayout, + index_buffers: SmallVec<[Buffer; 4]>, + vertex_buffers: SmallVec<[Buffer; 4]>, + config: RendererConfig<'static>, +} + +impl Renderer { + /// Create an entirely new imgui wgpu renderer. + pub fn new( + imgui: &mut Context, + device: &Device, + queue: &Queue, + config: RendererConfig, + ) -> Self { + let RendererConfig { + texture_format, + depth_format, + sample_count, + shader, + vertex_shader_entry_point, + fragment_shader_entry_point, + } = config; + + // Load shaders. + let shader1: Option; + let shader2: Option; + let (vs, fs) = match shader { + ShaderType::Combined(d) => { + shader1 = Some(device.create_shader_module(&d.shader)); + let r = shader1.as_ref().unwrap(); + (r, r) + } + ShaderType::Separate(d) => unsafe { + shader1 = Some(device.create_shader_module_spirv(&d.vertex_shader)); + shader2 = Some(device.create_shader_module_spirv(&d.fragment_shader)); + (shader1.as_ref().unwrap(), shader2.as_ref().unwrap()) + }, + ShaderType::None => panic!(), + }; + + // Create the uniform matrix buffer. + let size = 64; + let uniform_buffer = device.create_buffer(&BufferDescriptor { + label: Some("imgui-wgpu uniform buffer"), + size, + usage: BufferUsages::UNIFORM | BufferUsages::COPY_DST, + mapped_at_creation: false, + }); + + // Create the uniform matrix buffer bind group layout. + let uniform_layout = device.create_bind_group_layout(&BindGroupLayoutDescriptor { + label: None, + entries: &[BindGroupLayoutEntry { + binding: 0, + visibility: wgpu::ShaderStages::VERTEX, + ty: BindingType::Buffer { + ty: BufferBindingType::Uniform, + has_dynamic_offset: false, + min_binding_size: None, + }, + count: None, + }], + }); + + // Create the uniform matrix buffer bind group. + let uniform_bind_group = device.create_bind_group(&BindGroupDescriptor { + label: Some("imgui-wgpu bind group"), + layout: &uniform_layout, + entries: &[BindGroupEntry { binding: 0, resource: uniform_buffer.as_entire_binding() }], + }); + + // Create the texture layout for further usage. + let texture_layout = device.create_bind_group_layout(&BindGroupLayoutDescriptor { + label: Some("imgui-wgpu bind group layout"), + entries: &[ + BindGroupLayoutEntry { + binding: 0, + visibility: wgpu::ShaderStages::FRAGMENT, + ty: BindingType::Texture { + multisampled: false, + sample_type: TextureSampleType::Float { filterable: true }, + view_dimension: TextureViewDimension::D2, + }, + count: None, + }, + BindGroupLayoutEntry { + binding: 1, + visibility: wgpu::ShaderStages::FRAGMENT, + ty: BindingType::Sampler(wgpu::SamplerBindingType::Filtering), + count: None, + }, + ], + }); + + // Create the render pipeline layout. + let pipeline_layout = device.create_pipeline_layout(&PipelineLayoutDescriptor { + label: Some("imgui-wgpu pipeline layout"), + bind_group_layouts: &[&uniform_layout, &texture_layout], + push_constant_ranges: &[], + }); + + // Create the render pipeline. + // Create the render pipeline. + let pipeline = device.create_render_pipeline(&RenderPipelineDescriptor { + label: Some("imgui-wgpu pipeline"), + layout: Some(&pipeline_layout), + vertex: VertexState { + module: vs, + entry_point: &vertex_shader_entry_point, + buffers: &[VertexBufferLayout { + array_stride: size_of::() as BufferAddress, + step_mode: VertexStepMode::Vertex, + attributes: &vertex_attr_array![0 => Float32x2, 1 => Float32x2, 2 => Unorm8x4], + }], + }, + primitive: PrimitiveState { + topology: PrimitiveTopology::TriangleList, + strip_index_format: None, + front_face: FrontFace::Cw, + cull_mode: None, + polygon_mode: PolygonMode::Fill, + unclipped_depth: false, + conservative: false, + }, + depth_stencil: depth_format.map(|format| wgpu::DepthStencilState { + format, + depth_write_enabled: false, + depth_compare: wgpu::CompareFunction::Always, + stencil: wgpu::StencilState::default(), + bias: DepthBiasState::default(), + }), + multisample: MultisampleState { count: sample_count, ..Default::default() }, + fragment: Some(FragmentState { + module: fs, + entry_point: &fragment_shader_entry_point, + targets: &[ColorTargetState { + format: texture_format, + blend: Some(BlendState { + color: BlendComponent { + src_factor: BlendFactor::SrcAlpha, + dst_factor: BlendFactor::OneMinusSrcAlpha, + operation: BlendOperation::Add, + }, + alpha: BlendComponent { + src_factor: BlendFactor::OneMinusDstAlpha, + dst_factor: BlendFactor::One, + operation: BlendOperation::Add, + }, + }), + write_mask: ColorWrites::ALL, + }], + }), + multiview: None, + }); + + let mut renderer = Self { + pipeline, + uniform_buffer, + uniform_bind_group, + textures: Textures::new(), + texture_layout, + vertex_buffers: SmallVec::new(), + index_buffers: SmallVec::new(), + config: RendererConfig { + texture_format, + depth_format, + sample_count, + shader: ShaderType::None, + vertex_shader_entry_point, + fragment_shader_entry_point, + }, + }; + + // Immediately load the font texture to the GPU. + renderer.reload_font_texture(imgui, device, queue); + + renderer + } + + /// Render the current imgui frame. + pub fn render<'r>( + &'r mut self, + draw_data: &DrawData, + queue: &Queue, + device: &Device, + rpass: &mut RenderPass<'r>, + ) -> RendererResult<()> { + rpass.push_debug_group("imgui-wgpu"); + let mut rpass = scopeguard::guard(rpass, |rpass| { + rpass.pop_debug_group(); + }); + + let fb_width = draw_data.display_size[0] * draw_data.framebuffer_scale[0]; + let fb_height = draw_data.display_size[1] * draw_data.framebuffer_scale[1]; + + // If the render area is <= 0, exit here and now. + if !(fb_width > 0.0 && fb_height > 0.0) { + return Ok(()); + } + + let width = draw_data.display_size[0]; + let height = draw_data.display_size[1]; + + let offset_x = draw_data.display_pos[0] / width; + let offset_y = draw_data.display_pos[1] / height; + + // Create and update the transform matrix for the current frame. + // This is required to adapt to vulkan coordinates. + // let matrix = [ + // [2.0 / width, 0.0, 0.0, 0.0], + // [0.0, 2.0 / height as f32, 0.0, 0.0], + // [0.0, 0.0, -1.0, 0.0], + // [-1.0, -1.0, 0.0, 1.0], + // ]; + let matrix = [ + [2.0 / width, 0.0, 0.0, 0.0], + [0.0, 2.0 / -height as f32, 0.0, 0.0], + [0.0, 0.0, 1.0, 0.0], + [-1.0 - offset_x * 2.0, 1.0 + offset_y * 2.0, 0.0, 1.0], + ]; + self.update_uniform_buffer(queue, &matrix); + + rpass.set_pipeline(&self.pipeline); + rpass.set_bind_group(0, &self.uniform_bind_group, &[]); + + self.vertex_buffers.clear(); + self.index_buffers.clear(); + + for draw_list in draw_data.draw_lists() { + self.vertex_buffers.push(self.upload_vertex_buffer(device, draw_list.vtx_buffer())); + self.index_buffers.push(self.upload_index_buffer(device, draw_list.idx_buffer())); + } + + // Execute all the imgui render work. + for (draw_list_buffers_index, draw_list) in draw_data.draw_lists().enumerate() { + self.render_draw_list( + rpass.borrow_mut(), + draw_list, + draw_data.display_pos, + draw_data.framebuffer_scale, + draw_list_buffers_index, + )?; + } + + Ok(()) + } + + /// Render a given `DrawList` from imgui onto a wgpu frame. + fn render_draw_list<'render>( + &'render self, + rpass: &mut RenderPass<'render>, + draw_list: &DrawList, + clip_off: [f32; 2], + clip_scale: [f32; 2], + draw_list_buffers_index: usize, + ) -> RendererResult<()> { + let mut start = 0; + + let index_buffer = &self.index_buffers[draw_list_buffers_index]; + let vertex_buffer = &self.vertex_buffers[draw_list_buffers_index]; + + // Make sure the current buffers are attached to the render pass. + rpass.set_index_buffer(index_buffer.slice(..), IndexFormat::Uint16); + rpass.set_vertex_buffer(0, vertex_buffer.slice(..)); + + for cmd in draw_list.commands() { + if let Elements { count, cmd_params } = cmd { + let clip_rect = [ + (cmd_params.clip_rect[0] - clip_off[0]) * clip_scale[0], + (cmd_params.clip_rect[1] - clip_off[1]) * clip_scale[1], + (cmd_params.clip_rect[2] - clip_off[0]) * clip_scale[0], + (cmd_params.clip_rect[3] - clip_off[1]) * clip_scale[1], + ]; + + // Set the current texture bind group on the renderpass. + let texture_id = cmd_params.texture_id; + let tex = + self.textures.get(texture_id).ok_or(RendererError::BadTexture(texture_id))?; + rpass.set_bind_group(1, &tex.bind_group, &[]); + + // Set scissors on the renderpass. + let scissors = ( + clip_rect[0].max(0.0).floor() as u32, + clip_rect[1].max(0.0).floor() as u32, + (clip_rect[2] - clip_rect[0]).abs().ceil() as u32, + (clip_rect[3] - clip_rect[1]).abs().ceil() as u32, + ); + rpass.set_scissor_rect(scissors.0, scissors.1, scissors.2, scissors.3); + + // Draw the current batch of vertices with the renderpass. + let end = start + count as u32; + rpass.draw_indexed(start..end, 0, 0..1); + start = end; + } + } + Ok(()) + } + + /// Updates the current uniform buffer containing the transform matrix. + fn update_uniform_buffer(&mut self, queue: &Queue, matrix: &[[f32; 4]; 4]) { + let data = bytemuck::bytes_of(matrix); + + queue.write_buffer(&self.uniform_buffer, 0, data); + } + + /// Upload the vertex buffer to the GPU. + fn upload_vertex_buffer(&self, device: &Device, vertices: &[DrawVert]) -> Buffer { + // Safety: DrawVertPod is #[repr(transparent)] over DrawVert and DrawVert _should_ be Pod. + let vertices = unsafe { + std::slice::from_raw_parts(vertices.as_ptr() as *mut DrawVertPod, vertices.len()) + }; + + let data = bytemuck::cast_slice(vertices); + device.create_buffer_init(&BufferInitDescriptor { + label: Some("imgui-wgpu vertex buffer"), + contents: data, + usage: BufferUsages::VERTEX, + }) + } + + /// Upload the index buffer to the GPU. + fn upload_index_buffer(&self, device: &Device, indices: &[DrawIdx]) -> Buffer { + let data = bytemuck::cast_slice(indices); + + device.create_buffer_init(&BufferInitDescriptor { + label: Some("imgui-wgpu index buffer"), + contents: data, + usage: BufferUsages::INDEX, + }) + } + + /// Updates the texture on the GPU corresponding to the current imgui font atlas. + /// + /// This has to be called after loading a font. + pub fn reload_font_texture(&mut self, imgui: &mut Context, device: &Device, queue: &Queue) { + let mut fonts = imgui.fonts(); + // Remove possible font atlas texture. + self.textures.remove(fonts.tex_id); + + // Create font texture and upload it. + let handle = fonts.build_rgba32_texture(); + let font_texture_cnfig = TextureConfig { + label: Some("imgui-wgpu font atlas"), + size: Extent3d { width: handle.width, height: handle.height, ..Default::default() }, + format: Some(wgpu::TextureFormat::Rgba8Unorm), + ..Default::default() + }; + + let font_texture = Texture::new(device, self, font_texture_cnfig); + font_texture.write(queue, handle.data, handle.width, handle.height); + fonts.tex_id = self.textures.insert(font_texture); + // Clear imgui texture data to save memory. + fonts.clear_tex_data(); + } +} diff --git a/Graphics/src/lib.rs b/Graphics/src/lib.rs new file mode 100644 index 000000000..dd9291746 --- /dev/null +++ b/Graphics/src/lib.rs @@ -0,0 +1,345 @@ +#![allow(dead_code)] +#![allow(unused_imports)] +#![allow(unused_variables)] +#![allow(unused_unsafe)] + +use std::{num::NonZeroU8, time::Instant}; + +use wgpu::Backend; +use winit::{ + event::{Event, WindowEvent}, + event_loop::ControlFlow, +}; + +use crate::{ + gpu::{create_depth_texture, create_render_texture, initialize_gpu, DeviceHolder}, + imgui::{initialize_imgui, ImGuiState}, + shaders::render_into_pass, +}; + +mod gpu; +mod imgui; +mod imgui_backend; +mod shaders; +mod zeus; + +#[cxx::bridge(namespace = "aurora")] +mod ffi { + unsafe extern "C++" { + include!("aurora.hpp"); + pub(crate) type AppDelegate; + } + + unsafe extern "C++" { + include!("lib.hpp"); + pub(crate) fn App_onAppLaunched(cb: Pin<&mut AppDelegate>); + pub(crate) fn App_onAppIdle(cb: Pin<&mut AppDelegate>, dt: f32) -> bool; + pub(crate) fn App_onAppDraw(cb: Pin<&mut AppDelegate>); + pub(crate) fn App_onAppPostDraw(cb: Pin<&mut AppDelegate>); + pub(crate) fn App_onAppExiting(cb: Pin<&mut AppDelegate>); + } + + pub struct Window { + pub(crate) inner: Box, + } + pub struct WindowSize { + pub width: u32, + pub height: u32, + } + #[derive(Debug)] + pub enum Backend { + Invalid, + Vulkan, + Metal, + D3D12, + D3D11, + OpenGL, + WebGPU, + } + + pub enum ElementState { + Pressed, + Released, + } + pub enum MouseButton { + Left, + Right, + Middle, + Other, + } + pub enum SpecialKey { + None = 0, + F1 = 1, + F2 = 2, + F3 = 3, + F4 = 4, + F5 = 5, + F6 = 6, + F7 = 7, + F8 = 8, + F9 = 9, + F10 = 10, + F11 = 11, + F12 = 12, + Esc = 13, + Enter = 14, + Backspace = 15, + Insert = 16, + Delete = 17, + Home = 18, + End = 19, + PgUp = 20, + PgDown = 21, + Left = 22, + Right = 23, + Up = 24, + Down = 25, + Tab = 26, + } + pub struct KeyboardInput { + pub scancode: u32, + pub state: ElementState, + // pub + } + + extern "Rust" { + type WindowContext; + type App; + fn app_run(mut delegate: UniquePtr); + fn get_args() -> Vec; + fn get_window_size() -> WindowSize; + fn set_window_title(title: &CxxString); + fn get_backend() -> Backend; + fn get_backend_string() -> &'static str; + fn set_fullscreen(v: bool); + } +} + +pub struct App { + window: ffi::Window, + gpu: DeviceHolder, + imgui: ImGuiState, +} + +pub struct WindowContext { + window: winit::window::Window, +} + +static mut APP: Option = None; + +fn app_run(mut delegate: cxx::UniquePtr) { + if delegate.is_null() { + return; + } + env_logger::init(); + log::info!("Running app"); + let event_loop = winit::event_loop::EventLoop::new(); + let window = winit::window::WindowBuilder::new().build(&event_loop).unwrap(); + let gpu = initialize_gpu(&window); + let imgui = initialize_imgui(&window, &gpu); + shaders::construct_state(gpu.device.clone(), gpu.queue.clone(), &gpu.config); + let app = App { window: ffi::Window { inner: Box::new(WindowContext { window }) }, gpu, imgui }; + unsafe { + APP.replace(app); + ffi::App_onAppLaunched(delegate.as_mut().unwrap()); + }; + event_loop.run(move |event, _, control_flow| { + // Have the closure take ownership of the resources. + // `event_loop.run` never returns, therefore we must do this to ensure + // the resources are properly cleaned up. + let _ = &delegate; + + let app = get_app(); + let imgui = &mut app.imgui; + let window_ctx = get_window_context(); + let gpu = &mut app.gpu; + let mut last_frame: Option = None; + + *control_flow = ControlFlow::Poll; + match event { + Event::NewEvents(_) => {} + Event::WindowEvent { event: WindowEvent::CloseRequested, .. } => { + *control_flow = ControlFlow::Exit; + return; + } + Event::WindowEvent { event: WindowEvent::Resized(size), .. } => { + // Reconfigure the surface with the new size + app.gpu.surface_config.width = size.width; + app.gpu.surface_config.height = size.height; + app.gpu.surface.configure(&app.gpu.device, &app.gpu.surface_config); + app.gpu.depth = + create_depth_texture(&app.gpu.device, &app.gpu.surface_config, &app.gpu.config); + app.gpu.framebuffer = create_render_texture( + &app.gpu.device, + &app.gpu.surface_config, + &app.gpu.config, + ); + // TODO resize callback + } + Event::WindowEvent { event: WindowEvent::KeyboardInput { .. }, .. } => {} + Event::WindowEvent { .. } => {} + Event::DeviceEvent { .. } => {} + Event::UserEvent(_) => {} + Event::Suspended => {} + Event::Resumed => {} + Event::MainEventsCleared => { + log::info!("Requesting redraw"); + window_ctx.window.request_redraw(); + } + Event::RedrawRequested(_) => { + let io = imgui.context.io_mut(); + let mut dt: f32 = 1.0 / 60.0; + if let Some(last_frame) = last_frame { + let duration = last_frame.elapsed(); + dt = duration.as_secs_f32(); + io.update_delta_time(duration); + } + last_frame = Some(Instant::now()); + + imgui + .platform + .prepare_frame(io, &window_ctx.window) + .expect("Failed to prepare frame"); + let ui = imgui.context.frame(); + + #[allow(unused_unsafe)] // rust bug? + if !unsafe { ffi::App_onAppIdle(delegate.as_mut().unwrap(), dt) } { + *control_flow = ControlFlow::Exit; + return; + } + + log::info!("Redrawing"); + let frame_result = gpu.surface.get_current_texture(); + if let Err(err) = frame_result { + log::warn!("Failed to acquire frame {}", err); + return; + } + let frame = frame_result.unwrap(); + + #[allow(unused_unsafe)] // rust bug? + unsafe { + ffi::App_onAppDraw(delegate.as_mut().unwrap()); + } + + let fb_view = + gpu.framebuffer.texture.create_view(&wgpu::TextureViewDescriptor::default()); + let view = frame.texture.create_view(&wgpu::TextureViewDescriptor::default()); + let mut encoder = + gpu.device.create_command_encoder(&wgpu::CommandEncoderDescriptor { + label: Some("Redraw Encoder"), + }); + { + let mut rpass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { + label: None, + color_attachments: &[if gpu.config.msaa_samples > 1 { + wgpu::RenderPassColorAttachment { + view: &fb_view, + resolve_target: Some(&view), + ops: wgpu::Operations { + load: wgpu::LoadOp::Clear(wgpu::Color::BLACK), + store: true, + }, + } + } else { + wgpu::RenderPassColorAttachment { + view: &view, + resolve_target: None, + ops: wgpu::Operations { + load: wgpu::LoadOp::Clear(wgpu::Color::BLACK), + store: true, + }, + } + }], + depth_stencil_attachment: Some(wgpu::RenderPassDepthStencilAttachment { + view: &gpu.depth.view, + depth_ops: Some(wgpu::Operations { + load: wgpu::LoadOp::Clear(1.0), + store: true, + }), + stencil_ops: None, + }), + }); + + render_into_pass(&mut rpass); + + imgui.platform.prepare_render(&ui, &window_ctx.window); + imgui + .backend + .render(ui.render(), &gpu.queue, &gpu.device, &mut rpass) + .expect("Rendering failed"); + } + + gpu.queue.submit(Some(encoder.finish())); + frame.present(); + + #[allow(unused_unsafe)] // rust bug? + unsafe { + ffi::App_onAppPostDraw(delegate.as_mut().unwrap()); + } + } + Event::RedrawEventsCleared => {} + Event::LoopDestroyed => unsafe { + ffi::App_onAppExiting(delegate.as_mut().unwrap()); + APP.take(); + return; + }, + } + + imgui.platform.handle_event(imgui.context.io_mut(), &window_ctx.window, &event); + }); +} + +fn get_app() -> &'static mut App { + unsafe { + if let Some(ref mut app) = APP { + app + } else { + panic!("Application not initialized"); + } + } +} + +fn get_window_context() -> &'static mut WindowContext { &mut get_app().window.inner } + +fn get_args() -> Vec { std::env::args().skip(1).collect() } + +fn get_window_size() -> ffi::WindowSize { + let size = get_window_context().window.inner_size(); + ffi::WindowSize { width: size.width, height: size.height } +} + +fn set_window_title(title: &cxx::CxxString) { + get_window_context().window.set_title(&title.to_string_lossy()); +} + +fn get_backend() -> ffi::Backend { + match get_app().gpu.backend { + Backend::Vulkan => ffi::Backend::Vulkan, + Backend::Metal => ffi::Backend::Metal, + Backend::Dx12 => ffi::Backend::D3D12, + Backend::Dx11 => ffi::Backend::D3D11, + Backend::Gl => ffi::Backend::OpenGL, + Backend::BrowserWebGpu => ffi::Backend::WebGPU, + Backend::Empty => ffi::Backend::Invalid, + } +} + +fn get_backend_string() -> &'static str { + match get_app().gpu.backend { + Backend::Vulkan => "Vulkan", + Backend::Metal => "Metal", + Backend::Dx12 => "D3D12", + Backend::Dx11 => "D3D11", + Backend::Gl => "OpenGL ES", + Backend::BrowserWebGpu => "WebGPU", + Backend::Empty => "Invalid", + } +} + +fn set_fullscreen(v: bool) { + get_window_context().window.set_fullscreen(if v { + Some(winit::window::Fullscreen::Borderless(None)) + } else { + None + }); +} diff --git a/Graphics/src/shaders/aabb.rs b/Graphics/src/shaders/aabb.rs new file mode 100644 index 000000000..75d4088db --- /dev/null +++ b/Graphics/src/shaders/aabb.rs @@ -0,0 +1,203 @@ +use std::{hash::Hash, ops::Range}; + +use bytemuck_derive::{Pod, Zeroable}; +use wgpu::{include_wgsl, vertex_attr_array}; + +use crate::{ + gpu::GraphicsConfig, + shaders::{ + bind_pipeline, get_combined_matrix, pipeline_ref, push_draw_command, push_uniform, + push_verts, BuiltBuffers, PipelineCreateCommand, PipelineHolder, PipelineRef, + ShaderDrawCommand, + }, + zeus::{CAABox, CColor, CMatrix4f, CVector3f}, +}; + +#[derive(Debug, Clone)] +pub(crate) struct DrawData { + pipeline: PipelineRef, + vert_range: Range, + uniform_range: Range, +} + +#[derive(Hash)] +pub(crate) struct PipelineConfig { + z_only: bool, +} +pub(crate) const INITIAL_PIPELINES: &[PipelineConfig] = + &[PipelineConfig { z_only: false }, PipelineConfig { z_only: true }]; + +pub(crate) struct State { + shader: wgpu::ShaderModule, + uniform_layout: wgpu::BindGroupLayout, + uniform_bind_group: wgpu::BindGroup, + pipeline_layout: wgpu::PipelineLayout, +} + +pub(crate) fn construct_state( + device: &wgpu::Device, + _queue: &wgpu::Queue, + buffers: &BuiltBuffers, +) -> State { + let shader = device.create_shader_module(&include_wgsl!("aabb.wgsl")); + let uniform_size = wgpu::BufferSize::new(std::mem::size_of::() as u64); + let uniform_layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor { + label: Some("AABB Bind Group Layout"), + entries: &[wgpu::BindGroupLayoutEntry { + binding: 0, + visibility: wgpu::ShaderStages::VERTEX_FRAGMENT, + ty: wgpu::BindingType::Buffer { + ty: wgpu::BufferBindingType::Uniform, + has_dynamic_offset: true, + min_binding_size: uniform_size, + }, + count: None, + }], + }); + let uniform_bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor { + label: Some("AABB Bind Group"), + layout: &uniform_layout, + entries: &[wgpu::BindGroupEntry { + binding: 0, + resource: wgpu::BindingResource::Buffer(wgpu::BufferBinding { + buffer: &buffers.uniform_buffer, + offset: 0, // dynamic + size: uniform_size, + }), + }], + }); + let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { + label: Some("AABB Pipeline Layout"), + bind_group_layouts: &[&uniform_layout], + push_constant_ranges: &[], + }); + State { shader, uniform_layout, uniform_bind_group, pipeline_layout } +} + +pub(crate) fn construct_pipeline( + device: &wgpu::Device, + graphics: &GraphicsConfig, + state: &State, + config: &PipelineConfig, +) -> PipelineHolder { + PipelineHolder { + pipeline: device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { + label: Some("AABB Pipeline"), + layout: Some(&state.pipeline_layout), + vertex: wgpu::VertexState { + module: &state.shader, + entry_point: "vs_main", + buffers: &[wgpu::VertexBufferLayout { + array_stride: std::mem::size_of::() as u64, + step_mode: wgpu::VertexStepMode::Vertex, + attributes: &vertex_attr_array![0 => Float32x3], + }], + }, + primitive: wgpu::PrimitiveState { + topology: wgpu::PrimitiveTopology::TriangleStrip, + ..Default::default() + }, + depth_stencil: Some(wgpu::DepthStencilState { + format: graphics.depth_format, + depth_write_enabled: true, + depth_compare: wgpu::CompareFunction::LessEqual, + stencil: Default::default(), + bias: Default::default(), + }), + multisample: wgpu::MultisampleState { + count: graphics.msaa_samples, + ..Default::default() + }, + fragment: Some(wgpu::FragmentState { + module: &state.shader, + entry_point: "fs_main", + targets: &[wgpu::ColorTargetState { + format: graphics.color_format, + blend: Some(wgpu::BlendState { + color: wgpu::BlendComponent { + src_factor: wgpu::BlendFactor::SrcAlpha, + dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha, + operation: wgpu::BlendOperation::Add, + }, + alpha: wgpu::BlendComponent { + src_factor: wgpu::BlendFactor::SrcAlpha, + dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha, + operation: wgpu::BlendOperation::Add, + }, + }), + write_mask: if config.z_only { + wgpu::ColorWrites::empty() + } else { + wgpu::ColorWrites::ALL + }, + }], + }), + multiview: None, + }), + } +} + +#[derive(Pod, Zeroable, Copy, Clone, Default, Debug)] +#[repr(C)] +struct Uniform { + xf: CMatrix4f, + color: CColor, +} + +pub(crate) fn queue_aabb(aabb: CAABox, color: CColor, z_only: bool) { + let pipeline = pipeline_ref(PipelineCreateCommand::Aabb(PipelineConfig { z_only })); + let vert_range = push_verts(&[ + CVector3f::new(aabb.max.x, aabb.max.y, aabb.min.z), + CVector3f::new(aabb.max.x, aabb.min.y, aabb.min.z), + CVector3f::new(aabb.max.x, aabb.max.y, aabb.max.z), + CVector3f::new(aabb.max.x, aabb.min.y, aabb.max.z), + CVector3f::new(aabb.max.x, aabb.min.y, aabb.max.z), + CVector3f::new(aabb.min.x, aabb.max.y, aabb.min.z), + CVector3f::new(aabb.min.x, aabb.max.y, aabb.min.z), + CVector3f::new(aabb.max.x, aabb.max.y, aabb.min.z), + CVector3f::new(aabb.min.x, aabb.max.y, aabb.max.z), + CVector3f::new(aabb.max.x, aabb.max.y, aabb.max.z), + CVector3f::new(aabb.max.x, aabb.max.y, aabb.max.z), + CVector3f::new(aabb.min.x, aabb.max.y, aabb.min.z), + CVector3f::new(aabb.min.x, aabb.max.y, aabb.min.z), + CVector3f::new(aabb.min.x, aabb.min.y, aabb.min.z), + CVector3f::new(aabb.min.x, aabb.max.y, aabb.max.z), + CVector3f::new(aabb.min.x, aabb.min.y, aabb.max.z), + CVector3f::new(aabb.min.x, aabb.min.y, aabb.max.z), + CVector3f::new(aabb.min.x, aabb.min.y, aabb.min.z), + CVector3f::new(aabb.min.x, aabb.min.y, aabb.min.z), + CVector3f::new(aabb.max.x, aabb.min.y, aabb.min.z), + CVector3f::new(aabb.min.x, aabb.min.y, aabb.max.z), + CVector3f::new(aabb.max.x, aabb.min.y, aabb.max.z), + CVector3f::new(aabb.max.x, aabb.min.y, aabb.max.z), + CVector3f::new(aabb.min.x, aabb.min.y, aabb.max.z), + CVector3f::new(aabb.min.x, aabb.min.y, aabb.max.z), + CVector3f::new(aabb.max.x, aabb.min.y, aabb.max.z), + CVector3f::new(aabb.min.x, aabb.max.y, aabb.max.z), + CVector3f::new(aabb.max.x, aabb.max.y, aabb.max.z), + CVector3f::new(aabb.max.x, aabb.max.y, aabb.max.z), + CVector3f::new(aabb.min.x, aabb.min.y, aabb.min.z), + CVector3f::new(aabb.min.x, aabb.min.y, aabb.min.z), + CVector3f::new(aabb.max.x, aabb.min.y, aabb.min.z), + CVector3f::new(aabb.min.x, aabb.max.y, aabb.min.z), + CVector3f::new(aabb.max.x, aabb.max.y, aabb.min.z), + ]); + let uniform_range = push_uniform(&Uniform { xf: get_combined_matrix(), color }); + push_draw_command(ShaderDrawCommand::Aabb(DrawData { pipeline, vert_range, uniform_range })); +} + +pub(crate) fn draw_aabb<'a>( + data: &DrawData, + state: &'a State, + pass: &mut wgpu::RenderPass<'a>, + buffers: &'a BuiltBuffers, +) { + if !bind_pipeline(data.pipeline, pass) { + return; + } + pass.set_bind_group(0, &state.uniform_bind_group, &[ + data.uniform_range.start as wgpu::DynamicOffset + ]); + pass.set_vertex_buffer(0, buffers.vertex_buffer.slice(data.vert_range.clone())); + pass.draw(0..34, 0..1); +} diff --git a/Graphics/src/shaders/aabb.wgsl b/Graphics/src/shaders/aabb.wgsl new file mode 100644 index 000000000..e105d8a99 --- /dev/null +++ b/Graphics/src/shaders/aabb.wgsl @@ -0,0 +1,16 @@ +struct Uniform { + xf: mat4x4; + color: vec4; +}; +[[group(0), binding(0)]] +var ubuf: Uniform; + +[[stage(vertex)]] +fn vs_main([[location(0)]] in_pos: vec3) -> [[builtin(position)]] vec4 { + return ubuf.xf * vec4(in_pos, 1.0); +} + +[[stage(fragment)]] +fn fs_main() -> [[location(0)]] vec4 { + return ubuf.color; +} diff --git a/Graphics/src/shaders/fog_volume_filter.rs b/Graphics/src/shaders/fog_volume_filter.rs new file mode 100644 index 000000000..d6fb5b1ac --- /dev/null +++ b/Graphics/src/shaders/fog_volume_filter.rs @@ -0,0 +1,3 @@ +use crate::zeus::CColor; + +pub(crate) fn queue_fog_volume_filter(color: CColor, two_way: bool) {} diff --git a/Graphics/src/shaders/fog_volume_plane.rs b/Graphics/src/shaders/fog_volume_plane.rs new file mode 100644 index 000000000..4cf1c09a3 --- /dev/null +++ b/Graphics/src/shaders/fog_volume_plane.rs @@ -0,0 +1,5 @@ +use cxx::CxxVector; + +use crate::zeus::CVector4f; + +pub(crate) fn queue_fog_volume_plane(verts: &CxxVector, pass: u8) {} diff --git a/Graphics/src/shaders/mod.rs b/Graphics/src/shaders/mod.rs new file mode 100644 index 000000000..40dbce178 --- /dev/null +++ b/Graphics/src/shaders/mod.rs @@ -0,0 +1,574 @@ +use std::{ + collections::{HashMap, VecDeque}, + hash::{Hash, Hasher}, + num::NonZeroU8, + ops::Range, + sync::Arc, +}; + +use aabb::queue_aabb; +use bytemuck::Pod; +use bytemuck_derive::{Pod, Zeroable}; +use cxx::{type_id, ExternType}; +use fog_volume_filter::queue_fog_volume_filter; +use fog_volume_plane::queue_fog_volume_plane; +use model::{add_material_set, add_model}; +use texture::{create_render_texture, create_static_texture_2d, drop_texture}; +use twox_hash::Xxh3Hash64; +use wgpu::RenderPipeline; + +use crate::{ + gpu::GraphicsConfig, + zeus::{CColor, CMatrix4f, CRectangle, CVector2f, CVector3f, IDENTITY_MATRIX4F}, +}; + +mod aabb; +mod fog_volume_filter; +mod fog_volume_plane; +mod model; +mod texture; + +#[cxx::bridge] +mod ffi { + unsafe extern "C++" { + include!("zeus/CVector2f.hpp"); + include!("zeus/CVector3f.hpp"); + include!("zeus/CVector4f.hpp"); + include!("zeus/CMatrix4f.hpp"); + include!("zeus/CColor.hpp"); + include!("zeus/CRectangle.hpp"); + include!("zeus/CAABox.hpp"); + #[namespace = "zeus"] + type CVector2f = crate::zeus::CVector2f; + #[namespace = "zeus"] + type CVector3f = crate::zeus::CVector3f; + #[namespace = "zeus"] + type CVector4f = crate::zeus::CVector4f; + #[namespace = "zeus"] + type CMatrix4f = crate::zeus::CMatrix4f; + #[namespace = "zeus"] + type CColor = crate::zeus::CColor; + #[namespace = "zeus"] + type CRectangle = crate::zeus::CRectangle; + #[namespace = "zeus"] + type CAABox = crate::zeus::CAABox; + } + + #[namespace = "aurora::shaders"] + #[derive(Debug, Copy, Clone)] + pub(crate) enum CameraFilterType { + Passthru, + Multiply, + Invert, + Add, + Subtract, + Blend, + Widescreen, + SceneAdd, + NoColor, + InvDstMultiply, + } + #[namespace = "aurora::shaders"] + #[derive(Debug, Copy, Clone)] + pub(crate) enum ZTest { + None, + LEqual, + GEqual, + GEqualZWrite, + } + #[namespace = "aurora::shaders"] + #[derive(Debug, Copy, Clone)] + pub(crate) enum TextureFormat { + RGBA8, + R8, + R32Float, + DXT1, + DXT3, + DXT5, + BPTC, + } + #[namespace = "aurora::shaders"] + #[derive(Debug, Copy, Clone)] + pub(crate) enum TextureClampMode { + Repeat, + ClampToEdge, + ClampToWhite, + ClampToBlack, + } + #[namespace = "aurora::shaders"] + #[derive(Debug, Copy, Clone)] + pub(crate) struct TextureRef { + pub(crate) id: u32, + } + + #[namespace = "aurora::shaders"] + #[derive(Debug, Copy, Clone)] + #[repr(u32)] + pub(crate) enum FogMode { + None = 0x00, + + PerspLin = 0x02, + PerspExp = 0x04, + PerspExp2 = 0x05, + PerspRevExp = 0x06, + PerspRevExp2 = 0x07, + + OrthoLin = 0x0A, + OrthoExp = 0x0C, + OrthoExp2 = 0x0D, + OrthoRevExp = 0x0E, + OrthoRevExp2 = 0x0F, + } + #[namespace = "aurora::shaders"] + #[derive(Debug, Copy, Clone)] + pub(crate) struct FogState { + #[cxx_name = "m_color"] + pub(crate) color: CColor, + #[cxx_name = "m_A"] + pub(crate) a: f32, + #[cxx_name = "m_B"] + pub(crate) b: f32, + #[cxx_name = "m_C"] + pub(crate) c: f32, + #[cxx_name = "m_mode"] + pub(crate) mode: FogMode, + } + #[namespace = "aurora::shaders"] + #[derive(Debug, Copy, Clone)] + pub(crate) struct ClipRect { + x: i32, + y: i32, + width: i32, + height: i32, + } + + #[namespace = "aurora::shaders"] + #[derive(Debug, Copy, Clone)] + pub(crate) struct MaterialPassInfo { + tex_idx: u32, + constant_color: CColor, + has_constant_color: bool, // would love to use Option... + uv_source: u8, + uv_anim_type: u8, + uv_anim_params: [f32; 9], + normalize: bool, // TODO might be static based on uv type? + sample_alpha: bool, + } + #[namespace = "aurora::shaders"] + #[derive(Debug, Clone)] + pub(crate) struct MaterialInfo { + pass_info: [MaterialPassInfo; 8], + texture_ids: Vec, + shader_type: u8, + blend_mode: u8, + } + + #[namespace = "aurora::shaders"] + extern "Rust" { + fn update_model_view(mv: CMatrix4f, mv_inv: CMatrix4f); + fn update_projection(proj: CMatrix4f); + fn update_fog_state(state: FogState); + fn set_viewport(rect: CRectangle, znear: f32, zfar: f32); + fn set_scissor(x: u32, y: u32, w: u32, h: u32); + + fn resolve_color(rect: ClipRect, bind: u32, clear_depth: bool); + fn resolve_depth(rect: ClipRect, bind: u32); + + fn add_material_set(materials: Vec) -> u32; + fn add_model(verts: &[u8], indices: &[u8]) -> u32; + + fn queue_aabb(aabb: CAABox, color: CColor, z_only: bool); + fn queue_fog_volume_plane(verts: &CxxVector, pass: u8); + fn queue_fog_volume_filter(color: CColor, two_way: bool); + + fn create_static_texture_2d( + width: u32, + height: u32, + mips: u32, + format: TextureFormat, + data: &[u8], + label: &str, + ) -> TextureRef; + fn create_render_texture( + width: u32, + height: u32, + // clamp_mode: TextureClampMode, + color_bind_count: u32, + depth_bind_count: u32, + label: &str, + ) -> TextureRef; + fn drop_texture(handle: TextureRef); + } +} + +unsafe impl bytemuck::Zeroable for ffi::FogMode {} +unsafe impl bytemuck::Pod for ffi::FogMode {} +unsafe impl bytemuck::Zeroable for ffi::FogState {} +unsafe impl bytemuck::Pod for ffi::FogState {} +impl Default for ffi::FogState { + fn default() -> Self { + Self { color: Default::default(), a: 0.0, b: 0.5, c: 0.0, mode: ffi::FogMode::None } + } +} + +#[derive(Debug, Copy, Clone)] +enum ColoredStripMode { + Alpha, + Additive, + FullAdditive, + Subtractive, +} +#[derive(Debug, Copy, Clone)] +struct ColoredStripVert { + position: CVector3f, + color: CColor, + uv: CVector2f, +} + +#[derive(Debug, Clone)] +enum Command { + SetViewport(CRectangle, f32, f32), + SetScissor(u32, u32, u32, u32), + Draw(ShaderDrawCommand), +} +#[derive(Debug, Clone)] +enum ShaderDrawCommand { + Aabb(aabb::DrawData), + CameraBlurFilter { + amount: f32, + clear_depth: bool, + }, + ColoredQuadFilter { + filter_type: ffi::CameraFilterType, + color: CColor, + rect: CRectangle, + }, + ColoredStripFilter { + mode: ColoredStripMode, + verts: Vec, + color: CColor, + }, + Decal {/* TODO */}, + ElementGen {/* TODO */}, + EnergyBar {/* TODO */}, + EnvFx {/* TODO */}, + FluidPlane {/* TODO */}, + FogVolumeFilter { + two_way: bool, + color: CColor, + }, + FogVolumePlane { + pass: u8, + verts: Vec, + }, + LineRenderer {/* TODO */}, + MapSurface {/* TODO */}, + Model { + pipeline_id: u32, + material_id: u32, + ambient_color: CColor, + lights: u32, + post_type: u32, + game_blend_mode: u32, + model_flags: u32, + }, + MoviePlayer {/* TODO */}, + NES {/* TODO */}, + ParticleSwoosh {/* TODO */}, + PhazonSuitFilter {/* TODO */}, + RadarPaint {/* TODO */}, + RandomStaticFilter {/* TODO */}, + ScanLinesFilter {/* TODO */}, + TextSupport {/* TODO */}, + TexturedQuad { + filter_type: ffi::CameraFilterType, + z_test: ffi::ZTest, + tex: u32, /* TODO */ + /* draw, cropped, verts, filter? */ + }, + ThermalCold, + ThermalHot, + WorldShadow { + width: u32, + height: u32, + extent: f32, + }, + XRayBlur { + palette_tex: u32, /* TODO */ + amount: f32, + }, +} + +struct RenderState { + device: Arc, + queue: Arc, + graphics_config: GraphicsConfig, + pipelines: HashMap, + current_pipeline: u64, + uniform_alignment: usize, + storage_alignment: usize, + buffers: BuiltBuffers, + commands: VecDeque, + // Shader states + aabb: aabb::State, +} +pub(crate) fn construct_state( + device: Arc, + queue: Arc, + graphics_config: &GraphicsConfig, +) { + let limits = device.limits(); + let mut buffers = BuiltBuffers { + uniform_buffer: device.create_buffer(&wgpu::BufferDescriptor { + label: Some("Shared Uniform Buffer"), + size: 134_217_728, // 128mb + usage: wgpu::BufferUsages::UNIFORM | wgpu::BufferUsages::COPY_DST, + mapped_at_creation: false, + }), + vertex_buffer: device.create_buffer(&wgpu::BufferDescriptor { + label: Some("Shared Vertex Buffer"), + size: 16_777_216, // 16mb + usage: wgpu::BufferUsages::VERTEX | wgpu::BufferUsages::COPY_DST, + mapped_at_creation: false, + }), + }; + let aabb = aabb::construct_state(&device, &queue, &buffers); + let mut state = RenderState { + device: device.clone(), + queue: queue.clone(), + graphics_config: graphics_config.clone(), + pipelines: Default::default(), + current_pipeline: u64::MAX, + uniform_alignment: limits.min_uniform_buffer_offset_alignment as usize, + storage_alignment: limits.min_storage_buffer_offset_alignment as usize, + buffers, + commands: Default::default(), + aabb, + }; + for config in aabb::INITIAL_PIPELINES { + let hash = hash_with_seed(config, 0xAABB); + let pipeline = aabb::construct_pipeline(&device, graphics_config, &state.aabb, config); + state.pipelines.insert(hash, pipeline); + } + unsafe { + STATE = Some(state); + } +} +static mut STATE: Option = None; + +#[derive(Default, Pod, Zeroable, Copy, Clone)] +#[repr(C)] +struct GlobalUniform { + mv: CMatrix4f, + mv_inv: CMatrix4f, + proj: CMatrix4f, + ambient: CColor, // TODO can this be combined with model? + lightmap_mul: CColor, + fog: ffi::FogState, +} +#[derive(Default)] +struct GlobalBuffers { + uniforms: Vec, + verts: Vec, + + global_current: GlobalUniform, + global_dirty: bool, + last_global: Option>, +} +static mut GLOBAL_BUFFERS: GlobalBuffers = GlobalBuffers { + uniforms: vec![], + verts: vec![], + global_current: GlobalUniform { + mv: IDENTITY_MATRIX4F, + mv_inv: IDENTITY_MATRIX4F, + proj: IDENTITY_MATRIX4F, + ambient: CColor::new(0.0, 0.0, 0.0, 1.0), + lightmap_mul: CColor::new(0.0, 0.0, 0.0, 1.0), + fog: ffi::FogState { + color: CColor::new(0.0, 0.0, 0.0, 0.0), + a: 0.0, + b: 0.5, + c: 0.0, + mode: ffi::FogMode::None, + }, + }, + global_dirty: false, + last_global: None, +}; + +pub(crate) struct PipelineHolder { + pipeline: wgpu::RenderPipeline, +} +pub(crate) struct BuiltBuffers { + uniform_buffer: wgpu::Buffer, + vertex_buffer: wgpu::Buffer, +} + +const EMPTY_SLICE: &[u8] = &[0u8; 256]; + +fn push_value(target: &mut Vec, buf: &T, alignment: usize) -> Range { + let size_of = std::mem::size_of::(); + let padding = if alignment == 0 { 0 } else { alignment - size_of % alignment }; + let begin = target.len() as u64; + target.extend_from_slice(bytemuck::bytes_of(buf)); + if padding > 0 { + target.extend_from_slice(&EMPTY_SLICE[..padding]); + } + begin..begin + size_of as u64 +} +fn push_slice(target: &mut Vec, buf: &[T], alignment: usize) -> Range { + let size_of = std::mem::size_of::(); + let padding = if alignment == 0 { 0 } else { alignment - size_of % alignment }; + let begin = target.len() as u64; + target.extend_from_slice(bytemuck::cast_slice(buf)); + if padding > 0 { + target.extend_from_slice(&EMPTY_SLICE[..padding]); + } + begin..begin + size_of as u64 * buf.len() as u64 +} +fn push_verts(buf: &[T]) -> Range { + let global_buffers = unsafe { &mut GLOBAL_BUFFERS }; + push_slice(&mut global_buffers.verts, buf, 0 /* TODO? */) +} +fn push_uniform(buf: &T) -> Range { + let global_buffers = unsafe { &mut GLOBAL_BUFFERS }; + push_value(&mut global_buffers.uniforms, buf, unsafe { + STATE.as_ref().unwrap().uniform_alignment + }) +} + +#[derive(Debug, Copy, Clone)] +struct PipelineRef { + id: u64, +} + +enum PipelineCreateCommand { + Aabb(aabb::PipelineConfig), +} +#[inline(always)] +fn hash_with_seed(value: &T, seed: u64) -> u64 { + let mut state = Xxh3Hash64::with_seed(seed); + value.hash(&mut state); + state.finish() +} +fn pipeline_ref(cmd: PipelineCreateCommand) -> PipelineRef { + let state = unsafe { STATE.as_mut().unwrap() }; + let id = match cmd { + PipelineCreateCommand::Aabb(ref config) => hash_with_seed(config, 0xAABB), + }; + // TODO queue for creation if not found + if !state.pipelines.contains_key(&id) { + let pipeline = match cmd { + PipelineCreateCommand::Aabb(ref config) => aabb::construct_pipeline( + state.device.as_ref(), + &state.graphics_config, + &state.aabb, + config, + ), + }; + state.pipelines.insert(id, pipeline); + } + PipelineRef { id } +} + +fn bind_pipeline(pipeline_ref: PipelineRef, pass: &mut wgpu::RenderPass) -> bool { + let state = unsafe { STATE.as_ref().unwrap() }; + if pipeline_ref.id == state.current_pipeline { + return true; + } + if let Some(PipelineHolder { pipeline }) = state.pipelines.get(&pipeline_ref.id) { + pass.set_pipeline(pipeline); + return true; + } + return false; +} + +pub(crate) fn render_into_pass(pass: &mut wgpu::RenderPass) { + let state = unsafe { STATE.as_mut().unwrap() }; + { + let global_buffers = unsafe { &mut GLOBAL_BUFFERS }; + state.queue.write_buffer(&state.buffers.vertex_buffer, 0, &global_buffers.verts); + state.queue.write_buffer(&state.buffers.uniform_buffer, 0, &global_buffers.uniforms); + global_buffers.verts.clear(); + global_buffers.uniforms.clear(); + global_buffers.global_dirty = true; + } + for cmd in &state.commands { + match cmd { + Command::SetViewport(rect, znear, zfar) => { + pass.set_viewport( + rect.position.x, + rect.position.y, + rect.size.x, + rect.size.y, + *znear, + *zfar, + ); + } + Command::SetScissor(x, y, w, h) => { + pass.set_scissor_rect(*x, *y, *w, *h); + } + Command::Draw(cmd) => match cmd { + ShaderDrawCommand::Aabb(data) => { + aabb::draw_aabb(data, &state.aabb, pass, &state.buffers); + } + _ => todo!(), + }, + } + } + state.commands.clear(); +} + +fn update_model_view(mv: CMatrix4f, mv_inv: CMatrix4f) { + let global_buffers = unsafe { &mut GLOBAL_BUFFERS }; + global_buffers.global_current.mv = mv; + global_buffers.global_current.mv_inv = mv_inv; + global_buffers.global_dirty = true; +} +fn update_projection(proj: CMatrix4f) { + let global_buffers = unsafe { &mut GLOBAL_BUFFERS }; + global_buffers.global_current.proj = proj; + global_buffers.global_dirty = true; +} +fn update_fog_state(state: ffi::FogState) { + let global_buffers = unsafe { &mut GLOBAL_BUFFERS }; + global_buffers.global_current.fog = state; + global_buffers.global_dirty = true; +} + +fn get_combined_matrix() -> CMatrix4f { + let global_buffers = unsafe { &GLOBAL_BUFFERS }; + CMatrix4f::from( + cgmath::Matrix4::from(global_buffers.global_current.mv) + * cgmath::Matrix4::from(global_buffers.global_current.proj), + ) +} + +fn finalize_global_uniform() -> Range { + let global_buffers = unsafe { &mut GLOBAL_BUFFERS }; + if global_buffers.global_dirty || global_buffers.last_global.is_none() { + global_buffers.last_global = Some(push_uniform(&global_buffers.global_current)); + global_buffers.global_dirty = false; + } + global_buffers.last_global.as_ref().unwrap().clone() +} + +fn push_draw_command(cmd: ShaderDrawCommand) { + let state = unsafe { STATE.as_mut().unwrap() }; + state.commands.push_back(Command::Draw(cmd)); +} +fn set_viewport(rect: CRectangle, znear: f32, zfar: f32) { + let state = unsafe { STATE.as_mut().unwrap() }; + state.commands.push_back(Command::SetViewport(rect, znear, zfar)); +} +fn set_scissor(x: u32, y: u32, w: u32, h: u32) { + let state = unsafe { STATE.as_mut().unwrap() }; + state.commands.push_back(Command::SetScissor(x, y, w, h)); +} + +fn resolve_color(rect: ffi::ClipRect, bind: u32, clear_depth: bool) { + // TODO +} +fn resolve_depth(rect: ffi::ClipRect, bind: u32) { + // TODO +} diff --git a/Graphics/src/shaders/model.rs b/Graphics/src/shaders/model.rs new file mode 100644 index 000000000..08dc94048 --- /dev/null +++ b/Graphics/src/shaders/model.rs @@ -0,0 +1,41 @@ +use std::hash::Hash; + +use crate::shaders::ffi::MaterialInfo; + +struct MaterialShaderData { + shader_type: u32, // 5 values (incl. Invalid) + world_shadow: u32, // bool + alpha_discard: u32, // bool + samus_reflection: u32, // bool +} +struct MaterialPassData { + constant_color: [f32; 4], + has_constant_color: u32, // bool + uv_source: i32, // 8 values + normalize: u32, // bool + sample_alpha: u32, // bool +} + +struct ModelRenderData { + // position: [f32; 3], // for UV anims + ambient_color: [f32; 4], + lights: [f32; 8], // TODO + post_type: u32, + game_blend_mode: u32, + // model_flags: u32, TODO only needed for render +} + +#[derive(Debug, Hash)] +struct ModelPipelineConfig { + material_blend_mode: u32, + material_depth_write: bool, + render_blend_mode: u32, + render_model_flags: u32, + render_cull_mode: u32, + render_dst_alpha: bool, + render_color_update: bool, + render_alpha_update: bool, +} + +pub(crate) fn add_material_set(materials: Vec) -> u32 { return u32::MAX; } +pub(crate) fn add_model(verts: &[u8], indices: &[u8]) -> u32 { return u32::MAX; } diff --git a/Graphics/src/shaders/texture.rs b/Graphics/src/shaders/texture.rs new file mode 100644 index 000000000..a4f34213d --- /dev/null +++ b/Graphics/src/shaders/texture.rs @@ -0,0 +1,129 @@ +use std::ptr::null; + +use cxx::SharedPtr; +use wgpu::util::DeviceExt; + +use crate::{ + get_app, + gpu::TextureWithSampler, + shaders::ffi::{TextureClampMode, TextureFormat, TextureRef}, +}; + +pub(crate) struct TextureWithView { + texture: wgpu::Texture, + view: wgpu::TextureView, +} +impl TextureWithView { + fn new(texture: wgpu::Texture) -> Self { + let view = texture.create_view(&wgpu::TextureViewDescriptor::default()); + Self { texture, view } + } +} + +pub(crate) struct RenderTexture { + color_texture: Option, + depth_texture: Option, +} + +pub(crate) struct Texture { + texture: wgpu::Texture, +} + +pub(crate) fn create_static_texture_2d( + width: u32, + height: u32, + mips: u32, + format: TextureFormat, + data: &[u8], + label: &str, +) -> TextureRef { + let gpu = &get_app().gpu; + let texture = gpu.device.create_texture_with_data( + &gpu.queue, + &wgpu::TextureDescriptor { + label: Some(label), + size: wgpu::Extent3d { width, height, depth_or_array_layers: 1 }, + mip_level_count: mips, + sample_count: 1, + dimension: wgpu::TextureDimension::D2, + format: match format { + TextureFormat::RGBA8 => wgpu::TextureFormat::Rgba8Unorm, + TextureFormat::R8 => wgpu::TextureFormat::R8Unorm, + TextureFormat::R32Float => wgpu::TextureFormat::R32Float, + TextureFormat::DXT1 => wgpu::TextureFormat::Bc1RgbaUnorm, + TextureFormat::DXT3 => wgpu::TextureFormat::Bc3RgbaUnorm, + TextureFormat::DXT5 => wgpu::TextureFormat::Bc5RgUnorm, + TextureFormat::BPTC => wgpu::TextureFormat::Bc7RgbaUnorm, + _ => todo!(), + }, + usage: wgpu::TextureUsages::TEXTURE_BINDING, + }, + data, + ); + TextureRef { id: u32::MAX } +} + +pub(crate) fn create_render_texture( + width: u32, + height: u32, + // clamp_mode: TextureClampMode, + color_bind_count: u32, + depth_bind_count: u32, + label: &str, +) -> TextureRef { + let gpu = &get_app().gpu; + let color_texture = if color_bind_count > 0 { + Some(TextureWithView::new(gpu.device.create_texture(&wgpu::TextureDescriptor { + label: Some(format!("{} Color", label).as_str()), + size: wgpu::Extent3d { width, height, depth_or_array_layers: color_bind_count }, + mip_level_count: 1, + sample_count: 1, + dimension: wgpu::TextureDimension::D2, + format: gpu.config.color_format, + usage: wgpu::TextureUsages::RENDER_ATTACHMENT, + }))) + } else { + None + }; + let depth_texture = if depth_bind_count > 0 { + Some(TextureWithView::new(gpu.device.create_texture(&wgpu::TextureDescriptor { + label: Some(format!("{} Depth", label).as_str()), + size: wgpu::Extent3d { width, height, depth_or_array_layers: depth_bind_count }, + mip_level_count: 1, + sample_count: 1, + dimension: wgpu::TextureDimension::D2, + format: gpu.config.depth_format, + usage: wgpu::TextureUsages::RENDER_ATTACHMENT, + }))) + } else { + None + }; + // let (clamp_mode, border_color) = match clamp_mode { + // TextureClampMode::Repeat => (wgpu::AddressMode::Repeat, None), + // TextureClampMode::ClampToWhite => { + // (wgpu::AddressMode::ClampToBorder, Some(wgpu::SamplerBorderColor::OpaqueWhite)) + // } + // TextureClampMode::ClampToBlack => { + // (wgpu::AddressMode::ClampToBorder, Some(wgpu::SamplerBorderColor::OpaqueBlack)) + // } + // TextureClampMode::ClampToEdge => (wgpu::AddressMode::ClampToEdge, None), + // }; + // let sampler = gpu.device.create_sampler(&wgpu::SamplerDescriptor { + // label: Some(format!("{} Color Sampler", label).as_str()), + // address_mode_u: clamp_mode, + // address_mode_v: clamp_mode, + // address_mode_w: clamp_mode, + // mag_filter: wgpu::FilterMode::Linear, + // min_filter: wgpu::FilterMode::Linear, + // mipmap_filter: wgpu::FilterMode::Linear, + // lod_min_clamp: 0.0, + // lod_max_clamp: f32::MAX, + // compare: None, + // anisotropy_clamp: None, + // border_color, + // }); + RenderTexture { color_texture, depth_texture }; + TextureRef { id: u32::MAX } +} + +pub(crate) fn drop_texture(handle: TextureRef) {} diff --git a/Graphics/src/zeus.rs b/Graphics/src/zeus.rs new file mode 100644 index 000000000..c7ea239e9 --- /dev/null +++ b/Graphics/src/zeus.rs @@ -0,0 +1,171 @@ +use bytemuck_derive::{Pod, Zeroable}; +use cxx::{type_id, ExternType}; + +#[derive(Debug, Copy, Clone, Pod, Zeroable, Default)] +#[repr(C)] +pub struct CVector2f { + pub x: f32, + pub y: f32, + _p1: f32, + _p2: f32, +} +impl CVector2f { + pub const fn new(x: f32, y: f32) -> Self { Self { x, y, _p1: 0.0, _p2: 0.0 } } +} +unsafe impl ExternType for CVector2f { + type Id = type_id!("zeus::CVector2f"); + type Kind = cxx::kind::Trivial; +} + +#[derive(Debug, Copy, Clone, Pod, Zeroable, Default)] +#[repr(C)] +pub struct CVector3f { + pub x: f32, + pub y: f32, + pub z: f32, + _p: f32, +} +impl CVector3f { + pub const fn new(x: f32, y: f32, z: f32) -> Self { Self { x, y, z, _p: 0.0 } } +} +unsafe impl ExternType for CVector3f { + type Id = type_id!("zeus::CVector3f"); + type Kind = cxx::kind::Trivial; +} + +#[derive(Debug, Copy, Clone, Pod, Zeroable, Default)] +#[repr(C)] +pub struct CVector4f { + pub x: f32, + pub y: f32, + pub z: f32, + pub w: f32, +} +impl CVector4f { + pub const fn new(x: f32, y: f32, z: f32, w: f32) -> Self { Self { x, y, z, w } } +} +unsafe impl ExternType for CVector4f { + type Id = type_id!("zeus::CVector4f"); + type Kind = cxx::kind::Trivial; +} + +#[derive(Debug, Copy, Clone, Pod, Zeroable, Default)] +#[repr(C)] +pub struct CColor { + pub r: f32, + pub g: f32, + pub b: f32, + pub a: f32, +} +impl CColor { + pub const fn new(r: f32, g: f32, b: f32, a: f32) -> Self { Self { r, g, b, a } } +} +unsafe impl ExternType for CColor { + type Id = type_id!("zeus::CColor"); + type Kind = cxx::kind::Trivial; +} + +#[derive(Debug, Copy, Clone, Pod, Zeroable, Default)] +#[repr(C)] +pub struct CRectangle { + pub position: CVector2f, + pub size: CVector2f, +} +impl CRectangle { + pub const fn new(x: f32, y: f32, w: f32, h: f32) -> Self { + Self { position: CVector2f::new(x, y), size: CVector2f::new(w, h) } + } +} +unsafe impl ExternType for CRectangle { + type Id = type_id!("zeus::CRectangle"); + type Kind = cxx::kind::Trivial; +} + +#[derive(Debug, Copy, Clone, Pod, Zeroable, Default)] +#[repr(C)] +pub struct CAABox { + pub min: CVector3f, + pub max: CVector3f, +} +impl CAABox { + pub const fn new(min: CVector3f, max: CVector3f) -> Self { Self { min, max } } +} +unsafe impl ExternType for CAABox { + type Id = type_id!("zeus::CAABox"); + type Kind = cxx::kind::Trivial; +} + +pub const IDENTITY_MATRIX4F: CMatrix4f = CMatrix4f { + x: CVector4f::new(1.0, 0.0, 0.0, 0.0), + y: CVector4f::new(0.0, 1.0, 0.0, 0.0), + z: CVector4f::new(0.0, 0.0, 1.0, 0.0), + w: CVector4f::new(0.0, 0.0, 0.0, 1.0), +}; +#[derive(Debug, Copy, Clone, Pod, Zeroable)] +#[repr(C)] +pub struct CMatrix4f { + pub x: CVector4f, + pub y: CVector4f, + pub z: CVector4f, + pub w: CVector4f, +} +impl CMatrix4f { + pub const fn new(x: CVector4f, y: CVector4f, z: CVector4f, w: CVector4f) -> Self { + Self { x, y, z, w } + } +} +impl Default for CMatrix4f { + fn default() -> Self { IDENTITY_MATRIX4F } +} +unsafe impl ExternType for CMatrix4f { + type Id = type_id!("zeus::CMatrix4f"); + type Kind = cxx::kind::Trivial; +} + +#[cxx::bridge(namespace = "zeus")] +mod ffi { + unsafe extern "C++" { + include!("zeus/CVector2f.hpp"); + include!("zeus/CVector3f.hpp"); + include!("zeus/CVector4f.hpp"); + include!("zeus/CMatrix4f.hpp"); + include!("zeus/CColor.hpp"); + include!("zeus/CRectangle.hpp"); + include!("zeus/CAABox.hpp"); + type CVector2f = crate::zeus::CVector2f; + type CVector3f = crate::zeus::CVector3f; + type CVector4f = crate::zeus::CVector4f; + type CMatrix4f = crate::zeus::CMatrix4f; + type CColor = crate::zeus::CColor; + type CRectangle = crate::zeus::CRectangle; + type CAABox = crate::zeus::CAABox; + } +} + +impl From> for CVector4f { + fn from(v: cgmath::Vector4) -> Self { Self { x: v.x, y: v.y, z: v.z, w: v.w } } +} +impl From for cgmath::Vector4 { + fn from(v: CVector4f) -> Self { Self { x: v.x, y: v.y, z: v.z, w: v.w } } +} + +impl From> for CMatrix4f { + fn from(m: cgmath::Matrix4) -> Self { + Self { + x: CVector4f::from(m.x), + y: CVector4f::from(m.y), + z: CVector4f::from(m.z), + w: CVector4f::from(m.w), + } + } +} +impl From for cgmath::Matrix4 { + fn from(m: CMatrix4f) -> Self { + Self { + x: cgmath::Vector4::from(m.x), + y: cgmath::Vector4::from(m.y), + z: cgmath::Vector4::from(m.z), + w: cgmath::Vector4::from(m.w), + } + } +} diff --git a/NESEmulator/CNESEmulator.cpp b/NESEmulator/CNESEmulator.cpp index cb84aee4f..2fd0909c3 100644 --- a/NESEmulator/CNESEmulator.cpp +++ b/NESEmulator/CNESEmulator.cpp @@ -260,31 +260,31 @@ void CNESEmulator::InitializeEmulator() { // mainLoopRuns = nesPAL ? DOTS*ppuCycleTimer : DOTS*ppuCycleTimer; // mainLoopPos = mainLoopRuns; - CGraphics::CommitResources([this](boo::IGraphicsDataFactory::Context& ctx) { - // Nearest-neighbor FTW! - m_texture = ctx.newDynamicTexture(VISIBLE_DOTS, linesToDraw, boo::TextureFormat::RGBA8, - boo::TextureClampMode::ClampToEdgeNearest); - if (ctx.platform() == boo::IGraphicsDataFactory::Platform::OpenGL) { - Vert verts[4] = { - {{-1.f, -1.f, 0.f}, {0.f, 1.f}}, - {{-1.f, 1.f, 0.f}, {0.f, 0.f}}, - {{1.f, -1.f, 0.f}, {1.f, 1.f}}, - {{1.f, 1.f, 0.f}, {1.f, 0.f}}, - }; - m_vbo = ctx.newStaticBuffer(boo::BufferUse::Vertex, verts, sizeof(Vert), 4); - } else { - Vert verts[4] = { - {{-1.f, 1.f, 0.f}, {0.f, 1.f}}, - {{-1.f, -1.f, 0.f}, {0.f, 0.f}}, - {{1.f, 1.f, 0.f}, {1.f, 1.f}}, - {{1.f, -1.f, 0.f}, {1.f, 0.f}}, - }; - m_vbo = ctx.newStaticBuffer(boo::BufferUse::Vertex, verts, sizeof(Vert), 4); - } - m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(Uniform), 1); - m_shadBind = CNESShader::BuildShaderDataBinding(ctx, m_vbo, m_uniBuf, m_texture); - return true; - } BooTrace); +// CGraphics::CommitResources([this](boo::IGraphicsDataFactory::Context& ctx) { +// // Nearest-neighbor FTW! +// m_texture = ctx.newDynamicTexture(VISIBLE_DOTS, linesToDraw, boo::TextureFormat::RGBA8, +// boo::TextureClampMode::ClampToEdgeNearest); +// if (ctx.platform() == boo::IGraphicsDataFactory::Platform::OpenGL) { +// Vert verts[4] = { +// {{-1.f, -1.f, 0.f}, {0.f, 1.f}}, +// {{-1.f, 1.f, 0.f}, {0.f, 0.f}}, +// {{1.f, -1.f, 0.f}, {1.f, 1.f}}, +// {{1.f, 1.f, 0.f}, {1.f, 0.f}}, +// }; +// m_vbo = ctx.newStaticBuffer(boo::BufferUse::Vertex, verts, sizeof(Vert), 4); +// } else { +// Vert verts[4] = { +// {{-1.f, 1.f, 0.f}, {0.f, 1.f}}, +// {{-1.f, -1.f, 0.f}, {0.f, 0.f}}, +// {{1.f, 1.f, 0.f}, {1.f, 1.f}}, +// {{1.f, -1.f, 0.f}, {1.f, 0.f}}, +// }; +// m_vbo = ctx.newStaticBuffer(boo::BufferUse::Vertex, verts, sizeof(Vert), 4); +// } +// m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(Uniform), 1); +// m_shadBind = CNESShader::BuildShaderDataBinding(ctx, m_vbo, m_uniBuf, m_texture); +// return true; +// } BooTrace); // double useFreq = 223740; double useFreq = apuGetFrequency(); @@ -413,7 +413,8 @@ void CNESEmulator::NesEmuMainLoop(bool forceDraw) { emuMainTimesSkipped++; #endif // printf("LC RENDER: %d\n", loopCount); - m_texture->load(textureImage, visibleImg); + // TODO TODO +// m_texture->load(textureImage, visibleImg); emuRenderFrame = false; break; } @@ -770,10 +771,10 @@ void CNESEmulator::Draw(const zeus::CColor& mulColor, bool filtering) { Uniform uniform = {zeus::CMatrix4f{}, mulColor}; uniform.m_matrix[0][0] = widthFac; - m_uniBuf->load(&uniform, sizeof(Uniform)); - - CGraphics::SetShaderDataBinding(m_shadBind); - CGraphics::DrawArray(0, 4); +// m_uniBuf->load(&uniform, sizeof(Uniform)); +// +// CGraphics::SetShaderDataBinding(m_shadBind); +// CGraphics::DrawArray(0, 4); } void CNESEmulator::LoadPassword(const u8* state) { diff --git a/NESEmulator/CNESEmulator.hpp b/NESEmulator/CNESEmulator.hpp index 0dc4dd74f..e60ffc551 100644 --- a/NESEmulator/CNESEmulator.hpp +++ b/NESEmulator/CNESEmulator.hpp @@ -2,9 +2,10 @@ #include "RetroTypes.hpp" #include "zeus/CColor.hpp" -#include "boo/graphicsdev/IGraphicsDataFactory.hpp" +//#include "boo/graphicsdev/IGraphicsDataFactory.hpp" #include "boo/audiodev/IAudioVoice.hpp" #include "zeus/CMatrix4f.hpp" +#include "Runtime/Graphics/CGraphics.hpp" namespace metaforce { struct CFinalInput; @@ -34,10 +35,10 @@ private: zeus::CColor m_color; }; - boo::ObjToken m_texture; - boo::ObjToken m_uniBuf; - boo::ObjToken m_vbo; - boo::ObjToken m_shadBind; + std::shared_ptr m_texture; +// boo::ObjToken m_uniBuf; +// boo::ObjToken m_vbo; +// boo::ObjToken m_shadBind; std::unique_ptr m_audioBufBlock; u8* m_audioBufs[NUM_AUDIO_BUFFERS]; diff --git a/NESEmulator/CNESShader.cpp b/NESEmulator/CNESShader.cpp index c7d57e2fb..b1b040ccf 100644 --- a/NESEmulator/CNESShader.cpp +++ b/NESEmulator/CNESShader.cpp @@ -1,24 +1,28 @@ #include "CNESShader.hpp" #include "Graphics/CGraphics.hpp" -#include "hecl/Pipeline.hpp" +//#include "hecl/Pipeline.hpp" namespace metaforce::MP1 { -boo::ObjToken CNESShader::g_Pipeline; +//boo::ObjToken CNESShader::g_Pipeline; -void CNESShader::Initialize() { g_Pipeline = hecl::conv->convert(Shader_CNESShader{}); } - -boo::ObjToken CNESShader::BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, - boo::ObjToken vbo, - boo::ObjToken uniBuf, - boo::ObjToken tex) { - boo::ObjToken bufs[] = {uniBuf.get()}; - boo::PipelineStage stages[] = {boo::PipelineStage::Vertex}; - boo::ObjToken texs[] = {tex.get()}; - return ctx.newShaderDataBinding(g_Pipeline, vbo.get(), nullptr, nullptr, 1, bufs, stages, nullptr, nullptr, 1, texs, - nullptr, nullptr); +void CNESShader::Initialize() { +// g_Pipeline = hecl::conv->convert(Shader_CNESShader{}); } -void CNESShader::Shutdown() { g_Pipeline.reset(); } +//boo::ObjToken CNESShader::BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, +// boo::ObjToken vbo, +// boo::ObjToken uniBuf, +// boo::ObjToken tex) { +// boo::ObjToken bufs[] = {uniBuf.get()}; +// boo::PipelineStage stages[] = {boo::PipelineStage::Vertex}; +// boo::ObjToken texs[] = {tex.get()}; +// return ctx.newShaderDataBinding(g_Pipeline, vbo.get(), nullptr, nullptr, 1, bufs, stages, nullptr, nullptr, 1, texs, +// nullptr, nullptr); +//} + +void CNESShader::Shutdown() { +// g_Pipeline.reset(); +} } // namespace metaforce::MP1 diff --git a/NESEmulator/CNESShader.hpp b/NESEmulator/CNESShader.hpp index 1fa513b63..a00014257 100644 --- a/NESEmulator/CNESShader.hpp +++ b/NESEmulator/CNESShader.hpp @@ -1,6 +1,6 @@ #pragma once -#include "boo/graphicsdev/IGraphicsDataFactory.hpp" +//#include "boo/graphicsdev/IGraphicsDataFactory.hpp" namespace metaforce::MP1 { @@ -9,12 +9,12 @@ public: static void Initialize(); static void Shutdown(); - static boo::ObjToken BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, - boo::ObjToken vbo, - boo::ObjToken uniBuf, - boo::ObjToken tex); - - static boo::ObjToken g_Pipeline; +// static boo::ObjToken BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, +// boo::ObjToken vbo, +// boo::ObjToken uniBuf, +// boo::ObjToken tex); +// +// static boo::ObjToken g_Pipeline; }; } // namespace metaforce::MP1 diff --git a/Runtime/AutoMapper/CMapArea.cpp b/Runtime/AutoMapper/CMapArea.cpp index 99362316f..f434a189d 100644 --- a/Runtime/AutoMapper/CMapArea.cpp +++ b/Runtime/AutoMapper/CMapArea.cpp @@ -3,11 +3,9 @@ #include #include -#include "Runtime/CResFactory.hpp" #include "Runtime/CToken.hpp" #include "Runtime/GameGlobalObjects.hpp" #include "Runtime/AutoMapper/CMappableObject.hpp" -#include "Runtime/World/CGameArea.hpp" #include "Runtime/World/CWorld.hpp" namespace metaforce { @@ -108,43 +106,43 @@ void CMapArea::PostConstruct() { m_surfaces.emplace_back(x40_surfaceStart + j).PostConstruct(x44_buf.get(), index); } - CGraphics::CommitResources([this, &index](boo::IGraphicsDataFactory::Context& ctx) { - m_vbo = ctx.newStaticBuffer(boo::BufferUse::Vertex, m_verts.data(), 16, m_verts.size()); - m_ibo = ctx.newStaticBuffer(boo::BufferUse::Index, index.data(), 4, index.size()); - - /* Only the map universe specifies Always; it draws a maximum of 1016 instances */ - size_t instCount = (xc_visibilityMode == EVisMode::Always) ? 1024 : 1; - - for (u32 i = 0; i < x30_surfaceCount; ++i) { - CMapAreaSurface& surf = m_surfaces[i]; - surf.m_instances.reserve(instCount); - for (u32 inst = 0; inst < instCount; ++inst) { - CMapAreaSurface::Instance& instance = surf.m_instances.emplace_back(ctx, m_vbo, m_ibo); - - athena::io::MemoryReader r(surf.x1c_outlineOffset, INT_MAX); - u32 outlineCount = r.readUint32Big(); - - std::vector& linePrims = instance.m_linePrims; - linePrims.reserve(outlineCount * 2); - for (u32 j = 0; j < 2; ++j) { - r.seek(4, athena::SeekOrigin::Begin); - for (u32 k = 0; k < outlineCount; ++k) { - const u32 count = r.readUint32Big(); - r.seek(count); - r.seekAlign4(); - linePrims.emplace_back(ctx, CLineRenderer::EPrimitiveMode::LineStrip, count, nullptr, false, false, true); - } - } - } - } - - for (u32 i = 0; i < x28_mappableObjCount; ++i) { - CMappableObject& mapObj = m_mappableObjects[i]; - if (CMappableObject::IsDoorType(mapObj.GetType())) - mapObj.CreateDoorSurface(ctx); - } - return true; - } BooTrace); +// CGraphics::CommitResources([this, &index](boo::IGraphicsDataFactory::Context& ctx) { +// m_vbo = ctx.newStaticBuffer(boo::BufferUse::Vertex, m_verts.data(), 16, m_verts.size()); +// m_ibo = ctx.newStaticBuffer(boo::BufferUse::Index, index.data(), 4, index.size()); +// +// /* Only the map universe specifies Always; it draws a maximum of 1016 instances */ +// size_t instCount = (xc_visibilityMode == EVisMode::Always) ? 1024 : 1; +// +// for (u32 i = 0; i < x30_surfaceCount; ++i) { +// CMapAreaSurface& surf = m_surfaces[i]; +// surf.m_instances.reserve(instCount); +// for (u32 inst = 0; inst < instCount; ++inst) { +// CMapAreaSurface::Instance& instance = surf.m_instances.emplace_back(ctx, m_vbo, m_ibo); +// +// athena::io::MemoryReader r(surf.x1c_outlineOffset, INT_MAX); +// u32 outlineCount = r.readUint32Big(); +// +// std::vector& linePrims = instance.m_linePrims; +// linePrims.reserve(outlineCount * 2); +// for (u32 j = 0; j < 2; ++j) { +// r.seek(4, athena::SeekOrigin::Begin); +// for (u32 k = 0; k < outlineCount; ++k) { +// const u32 count = r.readUint32Big(); +// r.seek(count); +// r.seekAlign4(); +// linePrims.emplace_back(ctx, CLineRenderer::EPrimitiveMode::LineStrip, count, nullptr, false, false, true); +// } +// } +// } +// } +// +// for (u32 i = 0; i < x28_mappableObjCount; ++i) { +// CMappableObject& mapObj = m_mappableObjects[i]; +// if (CMappableObject::IsDoorType(mapObj.GetType())) +// mapObj.CreateDoorSurface(ctx); +// } +// return true; +// } BooTrace); } bool CMapArea::GetIsVisibleToAutoMapper(bool worldVis, bool areaVis) const { diff --git a/Runtime/AutoMapper/CMapArea.hpp b/Runtime/AutoMapper/CMapArea.hpp index d426c5301..45e03bb95 100644 --- a/Runtime/AutoMapper/CMapArea.hpp +++ b/Runtime/AutoMapper/CMapArea.hpp @@ -3,13 +3,13 @@ #include #include -#include "Runtime/CResFactory.hpp" -#include "Runtime/RetroTypes.hpp" #include "Runtime/AutoMapper/CMappableObject.hpp" +#include "Runtime/CResFactory.hpp" #include "Runtime/Graphics/CLineRenderer.hpp" #include "Runtime/Graphics/Shaders/CMapSurfaceShader.hpp" +#include "Runtime/RetroTypes.hpp" -#include +//#include #include #include @@ -29,9 +29,9 @@ public: struct Instance { CMapSurfaceShader m_surfacePrims; std::vector m_linePrims; - Instance(boo::IGraphicsDataFactory::Context& ctx, const boo::ObjToken& vbo, - const boo::ObjToken& ibo) - : m_surfacePrims(ctx, vbo, ibo) {} + Instance(aurora::ArrayRef vbo, + aurora::ArrayRef ibo) + : m_surfacePrims(vbo, ibo) {} Instance(Instance&&) = default; Instance& operator=(Instance&&) = default; }; @@ -65,8 +65,8 @@ private: u8* x40_surfaceStart; std::vector m_surfaces; std::unique_ptr x44_buf; - boo::ObjToken m_vbo; - boo::ObjToken m_ibo; +// boo::ObjToken m_vbo; +// boo::ObjToken m_ibo; public: explicit CMapArea(CInputStream& in, u32 size); diff --git a/Runtime/AutoMapper/CMappableObject.cpp b/Runtime/AutoMapper/CMappableObject.cpp index 48b55b92b..e37c5e791 100644 --- a/Runtime/AutoMapper/CMappableObject.cpp +++ b/Runtime/AutoMapper/CMappableObject.cpp @@ -1,8 +1,8 @@ #include "Runtime/AutoMapper/CMappableObject.hpp" +#include "Runtime/AutoMapper/CMapWorldInfo.hpp" #include "Runtime/CSimplePool.hpp" #include "Runtime/CToken.hpp" -#include "Runtime/AutoMapper/CMapWorldInfo.hpp" #include "Runtime/Camera/CCameraFilter.hpp" #include "Runtime/GameGlobalObjects.hpp" #include "Runtime/Graphics/CTexture.hpp" @@ -10,7 +10,7 @@ namespace metaforce { std::array CMappableObject::skDoorVerts{}; -constexpr std::array DoorIndices{ +std::array CMappableObject::skDoorIndices{ 6, 4, 2, 0, 3, 1, 7, 5, 1, 0, 5, 4, 7, 6, 3, 2, 3, 2, 1, 0, 5, 4, 7, 6, }; @@ -116,7 +116,7 @@ void CMappableObject::Draw(int curArea, const CMapWorldInfo& mwInfo, float alpha DoorSurface& ds = *m_doorSurface; ds.m_surface.draw(colors.first, s * 4, 4); CLineRenderer& line = ds.m_outline; - const u32* baseIdx = &DoorIndices[s * 4]; + const u16* baseIdx = &skDoorIndices[s * 4]; line.Reset(); line.AddVertex(skDoorVerts[baseIdx[0]], colors.second, 1.f); line.AddVertex(skDoorVerts[baseIdx[1]], colors.second, 1.f); @@ -186,7 +186,7 @@ void CMappableObject::DrawDoorSurface(int curArea, const CMapWorldInfo& mwInfo, DoorSurface& ds = *m_doorSurface; ds.m_surface.draw(colors.first, surfIdx * 4, 4); CLineRenderer& line = ds.m_outline; - const u32* baseIdx = &DoorIndices[surfIdx * 4]; + const u16* baseIdx = &skDoorIndices[surfIdx * 4]; line.Reset(); line.AddVertex(skDoorVerts[baseIdx[0]], colors.second, 1.f); line.AddVertex(skDoorVerts[baseIdx[1]], colors.second, 1.f); @@ -236,9 +236,6 @@ bool CMappableObject::IsVisibleToAutoMapper(bool worldVis, const CMapWorldInfo& } } -boo::ObjToken CMappableObject::g_doorVbo; -boo::ObjToken CMappableObject::g_doorIbo; - void CMappableObject::ReadAutoMapperTweaks(const ITweakAutoMapper& tweaks) { const zeus::CVector3f& center = tweaks.GetDoorCenter(); const zeus::simd_floats centerF(center.mSimd); @@ -254,15 +251,15 @@ void CMappableObject::ReadAutoMapperTweaks(const ITweakAutoMapper& tweaks) { doorVerts[6].assign(.2f * -centerF[2], centerF[1], 0.f); doorVerts[7].assign(.2f * -centerF[2], centerF[1], 2.f * centerF[0]); - CGraphics::CommitResources([](boo::IGraphicsDataFactory::Context& ctx) { - g_doorVbo = ctx.newStaticBuffer(boo::BufferUse::Vertex, skDoorVerts.data(), 16, skDoorVerts.size()); - g_doorIbo = ctx.newStaticBuffer(boo::BufferUse::Index, DoorIndices.data(), 4, DoorIndices.size()); - return true; - } BooTrace); +// CGraphics::CommitResources([](boo::IGraphicsDataFactory::Context& ctx) { +// g_doorVbo = ctx.newStaticBuffer(boo::BufferUse::Vertex, skDoorVerts.data(), 16, skDoorVerts.size()); +// g_doorIbo = ctx.newStaticBuffer(boo::BufferUse::Index, DoorIndices.data(), 4, DoorIndices.size()); +// return true; +// } BooTrace); } void CMappableObject::Shutdown() { - g_doorVbo.reset(); - g_doorIbo.reset(); +// g_doorVbo.reset(); +// g_doorIbo.reset(); } } // namespace metaforce diff --git a/Runtime/AutoMapper/CMappableObject.hpp b/Runtime/AutoMapper/CMappableObject.hpp index fd0b2df27..0b52196c6 100644 --- a/Runtime/AutoMapper/CMappableObject.hpp +++ b/Runtime/AutoMapper/CMappableObject.hpp @@ -5,10 +5,10 @@ #include #include "Runtime/GameGlobalObjects.hpp" -#include "Runtime/RetroTypes.hpp" #include "Runtime/Graphics/CLineRenderer.hpp" #include "Runtime/Graphics/Shaders/CMapSurfaceShader.hpp" #include "Runtime/Graphics/Shaders/CTexturedQuadFilter.hpp" +#include "Runtime/RetroTypes.hpp" #include #include @@ -18,9 +18,6 @@ class CMapWorldInfo; class CStateManager; class CMappableObject { - static boo::ObjToken g_doorVbo; - static boo::ObjToken g_doorIbo; - public: enum class EMappableObjectType { BlueDoor = 0, @@ -54,6 +51,7 @@ public: private: static std::array skDoorVerts; + static std::array skDoorIndices; EMappableObjectType x0_type; EVisMode x4_visibilityMode; @@ -64,9 +62,9 @@ private: struct DoorSurface { CMapSurfaceShader m_surface; CLineRenderer m_outline; - explicit DoorSurface(boo::IGraphicsDataFactory::Context& ctx) - : m_surface(ctx, g_doorVbo, g_doorIbo) - , m_outline(ctx, CLineRenderer::EPrimitiveMode::LineLoop, 5, nullptr, false, false, true) {} + explicit DoorSurface() + : m_surface(aurora::ArrayRef{skDoorVerts}, aurora::ArrayRef{skDoorIndices}) + , m_outline(CLineRenderer::EPrimitiveMode::LineLoop, 5, nullptr, false, false, true) {} }; std::optional m_doorSurface; std::optional m_texQuadFilter; @@ -87,7 +85,7 @@ public: bool IsDoorConnectedToVisitedArea(const CStateManager&) const; bool IsVisibleToAutoMapper(bool worldVis, const CMapWorldInfo& mwInfo) const; bool GetIsSeen() const; - void CreateDoorSurface(boo::IGraphicsDataFactory::Context& ctx) { m_doorSurface.emplace(ctx); } + void CreateDoorSurface() { m_doorSurface.emplace(); } static void ReadAutoMapperTweaks(const ITweakAutoMapper&); static bool GetTweakIsMapVisibilityCheat(); diff --git a/Runtime/CDvdFile.cpp b/Runtime/CDvdFile.cpp index e874686b6..7e9ec6a65 100644 --- a/Runtime/CDvdFile.cpp +++ b/Runtime/CDvdFile.cpp @@ -7,11 +7,14 @@ namespace metaforce { -hecl::ProjectPath CDvdFile::m_DvdRoot; -std::unordered_map CDvdFile::m_caseInsensitiveMap; +std::unique_ptr CDvdFile::m_DvdRoot; +// std::unordered_map CDvdFile::m_caseInsensitiveMap; class CFileDvdRequest : public IDvdRequest { - std::shared_ptr m_reader; + std::shared_ptr m_reader; + uint64_t m_begin; + uint64_t m_size; + void* m_buf; u32 m_len; ESeekOrigin m_whence; @@ -40,18 +43,43 @@ public: [[nodiscard]] EMediaType GetMediaType() const override { return EMediaType::File; } CFileDvdRequest(CDvdFile& file, void* buf, u32 len, ESeekOrigin whence, int off, std::function&& cb) - : m_reader(file.m_reader), m_buf(buf), m_len(len), m_whence(whence), m_offset(off), m_callback(std::move(cb)) {} + : m_reader(file.m_reader) + , m_begin(file.m_begin) + , m_size(file.m_size) + , m_buf(buf) + , m_len(len) + , m_whence(whence) + , m_offset(off) + , m_callback(std::move(cb)) {} void DoRequest() { if (m_cancel.load()) { return; } - u32 readLen; + u32 readLen = 0; if (m_whence == ESeekOrigin::Cur && m_offset == 0) { - readLen = m_reader->readBytesToBuf(m_buf, m_len); + readLen = m_reader->read(m_buf, m_len); } else { - m_reader->seek(m_offset, athena::SeekOrigin(m_whence)); - readLen = m_reader->readBytesToBuf(m_buf, m_len); + int seek = 0; + int64_t offset = m_offset; + switch (m_whence) { + case ESeekOrigin::Begin: { + seek = SEEK_SET; + offset += int64_t(m_begin); + break; + } + case ESeekOrigin::End: { + seek = SEEK_SET; + offset += int64_t(m_begin) + int64_t(m_size); + break; + } + case ESeekOrigin::Cur: { + seek = SEEK_CUR; + break; + } + }; + m_reader->seek(offset, seek); + readLen = m_reader->read(m_buf, m_len); } if (m_callback) { m_callback(readLen); @@ -67,6 +95,15 @@ std::mutex CDvdFile::m_WaitMutex; std::atomic_bool CDvdFile::m_WorkerRun = {false}; std::vector> CDvdFile::m_RequestQueue; +CDvdFile::CDvdFile(std::string_view path) : x18_path(path) { + auto* node = ResolvePath(path); + if (node != nullptr && node->getKind() == nod::Node::Kind::File) { + m_reader = node->beginReadStream(); + m_begin = m_reader->position(); + m_size = node->size(); + } +} + void CDvdFile::WorkerProc() { logvisor::RegisterThreadName("CDvdFile"); OPTICK_THREAD("CDvdFile"); @@ -103,42 +140,72 @@ std::shared_ptr CDvdFile::AsyncSeekRead(void* buf, u32 len, ESeekOr return ret; } -hecl::ProjectPath CDvdFile::ResolvePath(std::string_view path) { - auto start = path.begin(); - while (*start == '/') { - ++start; +u32 CDvdFile::SyncSeekRead(void* buf, u32 len, ESeekOrigin whence, int offset) { + int seek = 0; + switch (whence) { + case ESeekOrigin::Begin: { + seek = SEEK_SET; + offset += int64_t(m_begin); + break; } - std::string lowerChStr(start, path.end()); - std::transform(lowerChStr.begin(), lowerChStr.end(), lowerChStr.begin(), ::tolower); - auto search = m_caseInsensitiveMap.find(lowerChStr); - if (search == m_caseInsensitiveMap.end()) { - return {}; + case ESeekOrigin::End: { + seek = SEEK_SET; + offset += int64_t(m_begin) + int64_t(m_size); + break; } - return hecl::ProjectPath(m_DvdRoot, search->second); + case ESeekOrigin::Cur: { + seek = SEEK_CUR; + break; + } + }; + m_reader->seek(offset, seek); + return m_reader->read(buf, len); } -void CDvdFile::RecursiveBuildCaseInsensitiveMap(const hecl::ProjectPath& path, std::string::size_type prefixLen) { - for (const auto& p : path.enumerateDir()) { - if (p.m_isDir) { - RecursiveBuildCaseInsensitiveMap(hecl::ProjectPath(path, p.m_name), prefixLen); +nod::Node* CDvdFile::ResolvePath(std::string_view path) { + if (!m_DvdRoot) { + return nullptr; + } + if (path.starts_with('/')) { + path.remove_prefix(1); + } + auto* node = &m_DvdRoot->getDataPartition()->getFSTRoot(); + while (node != nullptr && !path.empty()) { + std::string component; + auto end = path.find('/'); + if (end != std::string_view::npos) { + component = path.substr(0, end); + path.remove_prefix(component.size() + 1); } else { - hecl::ProjectPath ch(path, p.m_name); - std::string chStr(ch.getAbsolutePath().begin() + prefixLen, ch.getAbsolutePath().end()); - std::string lowerChStr(chStr); - hecl::ToLower(lowerChStr); - m_caseInsensitiveMap[lowerChStr] = chStr; + component = path; + path.remove_prefix(component.size()); + } + std::transform(component.begin(), component.end(), component.begin(), ::tolower); + auto* tmpNode = node; + node = nullptr; + for (auto& item : *tmpNode) { + const auto name = item.getName(); + if (std::equal(component.begin(), component.end(), name.begin(), name.end(), + [](char a, char b) { return a == tolower(b); })) { + node = &item; + break; + } } } + return node; } -void CDvdFile::Initialize(const hecl::ProjectPath& path) { - m_DvdRoot = path; - RecursiveBuildCaseInsensitiveMap(path, path.getAbsolutePath().length() + 1); +bool CDvdFile::Initialize(const std::string_view& path) { if (m_WorkerRun.load()) { - return; + return true; + } + m_DvdRoot = nod::OpenDiscFromImage(path); + if (!m_DvdRoot) { + return false; } m_WorkerRun.store(true); m_WorkerThread = std::thread(WorkerProc); + return true; } void CDvdFile::Shutdown() { diff --git a/Runtime/CDvdFile.hpp b/Runtime/CDvdFile.hpp index f49018566..696b5908e 100644 --- a/Runtime/CDvdFile.hpp +++ b/Runtime/CDvdFile.hpp @@ -12,6 +12,8 @@ #include "Runtime/RetroTypes.hpp" #include +#include +#include namespace metaforce { @@ -23,8 +25,8 @@ class IDvdRequest; class CDvdFile { friend class CResLoader; friend class CFileDvdRequest; - static hecl::ProjectPath m_DvdRoot; - static std::unordered_map m_caseInsensitiveMap; + static std::unique_ptr m_DvdRoot; + // static std::unordered_map m_caseInsensitiveMap; static std::thread m_WorkerThread; static std::mutex m_WorkerMutex; static std::condition_variable m_WorkerCV; @@ -34,32 +36,33 @@ class CDvdFile { static void WorkerProc(); std::string x18_path; - std::shared_ptr m_reader; + std::shared_ptr m_reader; + uint64_t m_begin; + uint64_t m_size; - static hecl::ProjectPath ResolvePath(std::string_view path); - static void RecursiveBuildCaseInsensitiveMap(const hecl::ProjectPath& path, std::string::size_type prefixLen); + static nod::Node* ResolvePath(std::string_view path); + // static void RecursiveBuildCaseInsensitiveMap(const hecl::ProjectPath& path, std::string::size_type prefixLen); public: - static void Initialize(const hecl::ProjectPath& path); + static bool Initialize(const std::string_view& path); static void Shutdown(); - CDvdFile(std::string_view path) - : x18_path(path), m_reader(std::make_shared(ResolvePath(path).getAbsolutePath())) {} - operator bool() const { return m_reader->isOpen(); } - void UpdateFilePos(int pos) { m_reader->seek(pos, athena::SeekOrigin::Begin); } - static bool FileExists(std::string_view path) { return ResolvePath(path).isFile(); } - void CloseFile() { m_reader->close(); } + CDvdFile(std::string_view path); + operator bool() const { return m_reader.operator bool(); } + void UpdateFilePos(int pos) { m_reader->seek(pos, SEEK_SET); } + static bool FileExists(std::string_view path) { + nod::Node* node = ResolvePath(path); + return node != nullptr && node->getKind() == nod::Node::Kind::File; + } + void CloseFile() { m_reader.reset(); } std::shared_ptr AsyncSeekRead(void* buf, u32 len, ESeekOrigin whence, int off, std::function&& cb = {}); - u32 SyncSeekRead(void* buf, u32 len, ESeekOrigin whence, int offset) { - m_reader->seek(offset, athena::SeekOrigin(whence)); - return m_reader->readBytesToBuf(buf, len); - } + u32 SyncSeekRead(void* buf, u32 len, ESeekOrigin whence, int offset); std::shared_ptr AsyncRead(void* buf, u32 len, std::function&& cb = {}) { return AsyncSeekRead(buf, len, ESeekOrigin::Cur, 0, std::move(cb)); } - u32 SyncRead(void* buf, u32 len) { return m_reader->readBytesToBuf(buf, len); } - u64 Length() const { return m_reader->length(); } + u32 SyncRead(void* buf, u32 len) { return m_reader->read(buf, len); } + u64 Length() const { return m_size; } std::string_view GetPath() const { return x18_path; } }; } // namespace metaforce diff --git a/Runtime/CGameOptions.cpp b/Runtime/CGameOptions.cpp index 36d9adabb..d03ef368b 100644 --- a/Runtime/CGameOptions.cpp +++ b/Runtime/CGameOptions.cpp @@ -287,7 +287,7 @@ void CGameOptions::ApplyGamma() { gammaT = gammaT * 0.5f + 0.5f; if (zeus::close_enough(gammaT, 1.f, 0.05f)) gammaT = 1.f; - CGraphics::g_BooFactory->setDisplayGamma(gammaT); +// CGraphics::g_BooFactory->setDisplayGamma(gammaT); } void CGameOptions::SetGamma(s32 value, bool apply) { diff --git a/Runtime/CMain.cpp b/Runtime/CMain.cpp index cb9f8703a..48a761dc3 100644 --- a/Runtime/CMain.cpp +++ b/Runtime/CMain.cpp @@ -1,7 +1,7 @@ #include #include #include -#include +#include #include "boo/boo.hpp" #include "logvisor/logvisor.hpp" @@ -20,6 +20,10 @@ * (used by MSVC to definitively link DataSpecs) */ #include "DataSpecRegistry.hpp" +#include "Graphics/include/aurora.hpp" +#include "aurora.h" +#include "aurora_shaders.h" + using namespace std::literals; static logvisor::Module AthenaLog("Athena"); @@ -151,21 +155,21 @@ private: boo::SWindowRect m_lastRect; bool m_rectDirty = false; bool m_windowInvalid = false; - ImGuiWindowCallback m_imguiCallback; +// ImGuiWindowCallback m_imguiCallback; void resized(const boo::SWindowRect& rect, bool sync) override { m_lastRect = rect; m_rectDirty = true; - m_imguiCallback.resized(rect, sync); +// m_imguiCallback.resized(rect, sync); } void mouseDown(const boo::SWindowCoord& coord, boo::EMouseButton button, boo::EModifierKey mods) override { - if (!ImGuiWindowCallback::m_mouseCaptured && g_mainMP1) { - if (MP1::CGameArchitectureSupport* as = g_mainMP1->GetArchSupport()) { - as->mouseDown(coord, button, mods); - } - } - m_imguiCallback.mouseDown(coord, button, mods); +// if (!ImGuiWindowCallback::m_mouseCaptured && g_mainMP1) { +// if (MP1::CGameArchitectureSupport* as = g_mainMP1->GetArchSupport()) { +// as->mouseDown(coord, button, mods); +// } +// } +// m_imguiCallback.mouseDown(coord, button, mods); } void mouseUp(const boo::SWindowCoord& coord, boo::EMouseButton button, boo::EModifierKey mods) override { @@ -174,38 +178,38 @@ private: as->mouseUp(coord, button, mods); } } - m_imguiCallback.mouseUp(coord, button, mods); +// m_imguiCallback.mouseUp(coord, button, mods); } void mouseMove(const boo::SWindowCoord& coord) override { - if (!ImGuiWindowCallback::m_mouseCaptured && g_mainMP1) { - if (MP1::CGameArchitectureSupport* as = g_mainMP1->GetArchSupport()) { - as->mouseMove(coord); - } - } - m_imguiCallback.mouseMove(coord); +// if (!ImGuiWindowCallback::m_mouseCaptured && g_mainMP1) { +// if (MP1::CGameArchitectureSupport* as = g_mainMP1->GetArchSupport()) { +// as->mouseMove(coord); +// } +// } +// m_imguiCallback.mouseMove(coord); } - void mouseEnter(const boo::SWindowCoord& coord) override { m_imguiCallback.mouseEnter(coord); } +// void mouseEnter(const boo::SWindowCoord& coord) override { m_imguiCallback.mouseEnter(coord); } - void mouseLeave(const boo::SWindowCoord& coord) override { m_imguiCallback.mouseLeave(coord); } +// void mouseLeave(const boo::SWindowCoord& coord) override { m_imguiCallback.mouseLeave(coord); } void scroll(const boo::SWindowCoord& coord, const boo::SScrollDelta& scroll) override { - if (!ImGuiWindowCallback::m_mouseCaptured && g_mainMP1) { - if (MP1::CGameArchitectureSupport* as = g_mainMP1->GetArchSupport()) { - as->scroll(coord, scroll); - } - } - m_imguiCallback.scroll(coord, scroll); +// if (!ImGuiWindowCallback::m_mouseCaptured && g_mainMP1) { +// if (MP1::CGameArchitectureSupport* as = g_mainMP1->GetArchSupport()) { +// as->scroll(coord, scroll); +// } +// } +// m_imguiCallback.scroll(coord, scroll); } void charKeyDown(unsigned long charCode, boo::EModifierKey mods, bool isRepeat) override { - if (!ImGuiWindowCallback::m_keyboardCaptured && g_mainMP1) { - if (MP1::CGameArchitectureSupport* as = g_mainMP1->GetArchSupport()) { - as->charKeyDown(charCode, mods, isRepeat); - } - } - m_imguiCallback.charKeyDown(charCode, mods, isRepeat); +// if (!ImGuiWindowCallback::m_keyboardCaptured && g_mainMP1) { +// if (MP1::CGameArchitectureSupport* as = g_mainMP1->GetArchSupport()) { +// as->charKeyDown(charCode, mods, isRepeat); +// } +// } +// m_imguiCallback.charKeyDown(charCode, mods, isRepeat); } void charKeyUp(unsigned long charCode, boo::EModifierKey mods) override { @@ -214,40 +218,39 @@ private: as->charKeyUp(charCode, mods); } } - m_imguiCallback.charKeyUp(charCode, mods); +// m_imguiCallback.charKeyUp(charCode, mods); } void specialKeyDown(boo::ESpecialKey key, boo::EModifierKey mods, bool isRepeat) override { - if (!ImGuiWindowCallback::m_keyboardCaptured && g_mainMP1) { - if (MP1::CGameArchitectureSupport* as = g_mainMP1->GetArchSupport()) { - as->specialKeyDown(key, mods, isRepeat); - } - } - if (True(mods & boo::EModifierKey::Alt)) { - if (key == boo::ESpecialKey::Enter) { - m_fullscreenToggleRequested = true; - } else if (key == boo::ESpecialKey::F4) { - m_windowInvalid = true; - } - } - m_imguiCallback.specialKeyDown(key, mods, isRepeat); +// if (!ImGuiWindowCallback::m_keyboardCaptured && g_mainMP1) { +// if (MP1::CGameArchitectureSupport* as = g_mainMP1->GetArchSupport()) { +// as->specialKeyDown(key, mods, isRepeat); +// } +// } +// if (True(mods & boo::EModifierKey::Alt)) { +// if (key == boo::ESpecialKey::Enter) { +// m_fullscreenToggleRequested = true; +// } else if (key == boo::ESpecialKey::F4) { +// m_windowInvalid = true; +// } +// } +// m_imguiCallback.specialKeyDown(key, mods, isRepeat); } void specialKeyUp(boo::ESpecialKey key, boo::EModifierKey mods) override { - if (g_mainMP1) { - if (MP1::CGameArchitectureSupport* as = g_mainMP1->GetArchSupport()) { - as->specialKeyUp(key, mods); - } - } - m_imguiCallback.specialKeyUp(key, mods); +// if (g_mainMP1) { +// if (MP1::CGameArchitectureSupport* as = g_mainMP1->GetArchSupport()) { +// as->specialKeyUp(key, mods); +// } +// } +// m_imguiCallback.specialKeyUp(key, mods); } void destroyed() override { m_windowInvalid = true; } }; -struct Application : boo::IApplicationCallback { +struct Application : aurora::AppDelegate { private: - std::shared_ptr m_window; WindowCallback m_windowCallback; hecl::Runtime::FileStoreManager& m_fileMgr; hecl::CVarManager& m_cvarManager; @@ -255,17 +258,16 @@ private: ImGuiConsole m_imGuiConsole; std::string m_errorString; - boo::ObjToken m_renderTex; +// boo::ObjToken m_renderTex; std::string m_deferredProject; - std::unique_ptr m_proj; + bool m_projectInitialized = false; +// std::unique_ptr m_proj; std::optional m_amuseAllocWrapper; std::unique_ptr m_voiceEngine; - std::unique_ptr m_pipelineConv; +// std::unique_ptr m_pipelineConv; Limiter m_limiter{}; - std::atomic_bool m_running = {true}; bool m_noShaderWarmup = false; - bool m_imGuiInitialized = false; bool m_firstFrame = true; using delta_clock = std::chrono::high_resolution_clock; @@ -275,41 +277,25 @@ public: Application(hecl::Runtime::FileStoreManager& fileMgr, hecl::CVarManager& cvarMgr, hecl::CVarCommons& cvarCmns) : m_fileMgr(fileMgr), m_cvarManager(cvarMgr), m_cvarCommons(cvarCmns), m_imGuiConsole(cvarMgr, cvarCmns) {} - int appMain(boo::IApplication* app) override { - initialize(app); + void onAppLaunched() override { + initialize(); - m_window = app->newWindow("Metaforce"sv); - if (!m_window) { - return 1; - } - m_window->setCallback(&m_windowCallback); - m_window->showWindow(); + auto backend = static_cast(aurora::get_backend_string()); + aurora::set_window_title(fmt::format(FMT_STRING("Metaforce {} [{}]"), METAFORCE_WC_DESCRIBE, backend)); - boo::IGraphicsDataFactory* gfxF = m_window->getMainContextDataFactory(); - m_window->setTitle(fmt::format(FMT_STRING("Metaforce {} [{}]"), METAFORCE_WC_DESCRIBE, gfxF->platformName())); - - boo::SWindowRect rect = m_window->getWindowFrame(); - m_windowCallback.m_lastRect = rect; - gfxF->commitTransaction([&](boo::IGraphicsDataFactory::Context& ctx) { - m_renderTex = ctx.newRenderTexture(rect.size[0], rect.size[1], boo::TextureClampMode::ClampToEdge, 3, 3); - return true; - } BooTrace); - - m_pipelineConv = hecl::NewPipelineConverter(gfxF); - hecl::conv = m_pipelineConv.get(); - - m_voiceEngine = boo::NewAudioVoiceEngine(); + m_voiceEngine = boo::NewAudioVoiceEngine("metaforce", "Metaforce"); m_voiceEngine->setVolume(0.7f); m_amuseAllocWrapper.emplace(*m_voiceEngine); - hecl::ProjectPath projectPath; - for (const auto& arg : app->getArgs()) { - hecl::Sstat theStat; - if (!hecl::Stat((arg + "/out").c_str(), &theStat) && S_ISDIR(theStat.st_mode)) { - hecl::ProjectRootPath rootPath(arg); - hecl::Database::Project tmp(rootPath); // Force project creation - } - if (m_deferredProject.empty() && hecl::SearchForProject(arg)) +// hecl::ProjectPath projectPath; + for (const auto& str : aurora::get_args()) { + auto arg = static_cast(str); +// hecl::Sstat theStat; +// if (hecl::Stat((arg + "/out").c_str(), &theStat) == 0 && S_ISDIR(theStat.st_mode)) { +// hecl::ProjectRootPath rootPath(arg); +// hecl::Database::Project tmp(rootPath); // Force project creation +// } + if (m_deferredProject.empty() && !arg.starts_with('-') && !arg.starts_with('+')) m_deferredProject = arg; if (arg == "--no-shader-warmup") m_noShaderWarmup = true; @@ -317,45 +303,23 @@ public: m_voiceEngine->setVolume(0.f); } - if (m_deferredProject.empty()) { - /* Default behavior - search upwards for packaged project containing the program */ - if (hecl::ProjectRootPath projRoot = hecl::SearchForProject(ExeDir)) { - std::string rootPath(projRoot.getAbsolutePath()); - hecl::Sstat theStat; - if (hecl::Stat((rootPath + "/out/files/MP1/Metroid1.upak").c_str(), &theStat) == 0 && S_ISREG(theStat.st_mode)) - m_deferredProject = rootPath + "/out"; - } - } - - while (m_running) { - onAppIdle(); - } - - if (m_imGuiInitialized) { - m_imGuiConsole.Shutdown(); - ImGuiEngine::Shutdown(); - } - if (g_mainMP1) { - g_mainMP1->Shutdown(); - } - g_mainMP1.reset(); - m_renderTex.reset(); - m_pipelineConv.reset(); - if (m_window) { - m_window->getCommandQueue()->stopRenderer(); - } - m_cvarManager.serialize(); - m_voiceEngine.reset(); - m_amuseAllocWrapper.reset(); - CDvdFile::Shutdown(); - return 0; +// if (m_deferredProject.empty()) { +// /* Default behavior - search upwards for packaged project containing the program */ +// if (hecl::ProjectRootPath projRoot = hecl::SearchForProject(ExeDir)) { +// std::string rootPath(projRoot.getAbsolutePath()); +// hecl::Sstat theStat; +// if (hecl::Stat((rootPath + "/out/files/MP1/Metroid1.upak").c_str(), &theStat) == 0 && S_ISREG(theStat.st_mode)) +// m_deferredProject = rootPath + "/out"; +// } +// } } - void initialize(boo::IApplication* app) { + void initialize() { zeus::detectCPU(); - for (const auto& arg : app->getArgs()) { - if (arg.find("--verbosity=") == 0 || arg.find("-v=") == 0) { + for (const auto& str : aurora::get_args()) { + auto arg = static_cast(str); + if (arg.starts_with("--verbosity=") || arg.starts_with("-v=")) { hecl::VerbosityLevel = atoi(arg.substr(arg.find_last_of('=') + 1).c_str()); hecl::LogModule.report(logvisor::Info, FMT_STRING("Set verbosity level to {}"), hecl::VerbosityLevel); } @@ -367,30 +331,20 @@ public: Log.report(logvisor::Info, FMT_STRING("CPU Features: {}"), CPUFeatureString(cpuInf)); } - void onAppIdle() noexcept { - if (!m_deferredProject.empty()) { - std::string subPath; - hecl::ProjectRootPath projPath = hecl::SearchForProject(m_deferredProject, subPath); - if (projPath) { - m_proj = std::make_unique(projPath); - m_deferredProject.clear(); - hecl::ProjectPath projectPath{m_proj->getProjectWorkingPath(), "out/files/MP1"}; - CDvdFile::Initialize(projectPath); + bool onAppIdle(float realDt) noexcept override { + if (!m_projectInitialized && !m_deferredProject.empty()) { + if (CDvdFile::Initialize(m_deferredProject)) { + m_projectInitialized = true; } else { Log.report(logvisor::Error, FMT_STRING("Project doesn't exist at '{}'"), m_deferredProject); m_errorString = fmt::format(FMT_STRING("Project not found at '{}'"), m_deferredProject); m_deferredProject.clear(); } } - if (!m_proj && m_errorString.empty()) { + if (!m_projectInitialized && m_errorString.empty()) { m_errorString = "Project directory not specified"s; } - if (m_windowCallback.m_windowInvalid) { - m_running.store(false); - return; - } - const auto targetFrameTime = getTargetFrameTime(); bool skipRetrace = false; if (g_ResFactory != nullptr) { @@ -404,10 +358,6 @@ public: m_limiter.Reset(); } else { // No more to load, and we're under frame time - { - OPTICK_EVENT("Wait for Retrace"); - m_window->waitForRetrace(); - } { OPTICK_EVENT("Sleep"); m_limiter.Sleep(targetFrameTime); @@ -415,18 +365,20 @@ public: } OPTICK_FRAME("MainThread"); - CGraphics::SetCommitResourcesAsLazy(m_cvarCommons.m_lazyCommitResources->toBoolean()); +// CGraphics::SetCommitResourcesAsLazy(m_cvarCommons.m_lazyCommitResources->toBoolean()); - boo::SWindowRect rect = m_windowCallback.m_lastRect; - rect.location = {0, 0}; - boo::IGraphicsCommandQueue* gfxQ = m_window->getCommandQueue(); - if (m_windowCallback.m_rectDirty) { - gfxQ->resizeRenderTexture(m_renderTex, rect.size[0], rect.size[1]); - CGraphics::SetViewportResolution({rect.size[0], rect.size[1]}); - m_windowCallback.m_rectDirty = false; - } else if (m_firstFrame) { - CGraphics::SetViewportResolution({rect.size[0], rect.size[1]}); - } + // TODO +// boo::SWindowRect rect = m_windowCallback.m_lastRect; +// rect.location = {0, 0}; +// boo::IGraphicsCommandQueue* gfxQ = m_window->getCommandQueue(); +// if (m_windowCallback.m_rectDirty) { +// gfxQ->resizeRenderTexture(m_renderTex, rect.size[0], rect.size[1]); +// CGraphics::SetViewportResolution({rect.size[0], rect.size[1]}); +// m_windowCallback.m_rectDirty = false; +// } else if (m_firstFrame) { + auto rect = aurora::get_window_size(); + CGraphics::SetViewportResolution({static_cast(rect.width), static_cast(rect.height)}); +// } // Check if fullscreen has been toggled, if so set the fullscreen cvar accordingly if (m_windowCallback.m_fullscreenToggleRequested) { @@ -436,88 +388,63 @@ public: // Check if the user has modified the fullscreen CVar, if so set fullscreen state accordingly if (m_cvarCommons.m_fullscreen->isModified()) { - m_window->setFullscreen(m_cvarCommons.getFullscreen()); + aurora::set_fullscreen(m_cvarCommons.getFullscreen()); } // Let CVarManager inform all CVar listeners of the CVar's state and clear all mdoified flags if necessary m_cvarManager.proc(); - boo::IGraphicsDataFactory* gfxF = m_window->getMainContextDataFactory(); - float scale = std::floor(m_window->getVirtualPixelFactor() * 4.f) / 4.f; - if (!g_mainMP1 && m_proj) { - g_mainMP1.emplace(nullptr, nullptr, gfxF, gfxQ, m_renderTex.get()); - g_mainMP1->Init(m_fileMgr, &m_cvarManager, m_window.get(), m_voiceEngine.get(), *m_amuseAllocWrapper); + // TODO +// boo::IGraphicsDataFactory* gfxF = m_window->getMainContextDataFactory(); +// float scale = std::floor(m_window->getVirtualPixelFactor() * 4.f) / 4.f; + if (!g_mainMP1 && m_projectInitialized) { + g_mainMP1.emplace(nullptr, nullptr); + g_mainMP1->Init(m_fileMgr, &m_cvarManager, m_voiceEngine.get(), *m_amuseAllocWrapper); if (!m_noShaderWarmup) { g_mainMP1->WarmupShaders(); } } - if (!m_imGuiInitialized) { - ImGuiEngine::Initialize(gfxF, m_window.get(), scale, m_fileMgr.getStoreRoot()); - m_imGuiInitialized = true; - } +// if (!m_imGuiInitialized) { +// ImGuiEngine::Initialize(gfxF, m_window.get(), scale, m_fileMgr.getStoreRoot()); +// m_imGuiInitialized = true; +// } float dt = 1 / 60.f; - float realDt = dt; - auto now = delta_clock::now(); - if (m_firstFrame) { - m_firstFrame = false; - } else { - using delta_duration = std::chrono::duration>; - realDt = std::chrono::duration_cast(now - m_prevFrameTime).count(); - if (m_cvarCommons.m_variableDt->toBoolean()) { - dt = std::min(realDt, 1 / 30.f); - } + if (m_cvarCommons.m_variableDt->toBoolean()) { + dt = std::min(realDt, 1 / 30.f); } - m_prevFrameTime = now; - - ImGuiEngine::Begin(realDt, scale); if (g_mainMP1) { m_imGuiConsole.PreUpdate(); if (g_mainMP1->Proc(dt)) { - m_running.store(false); - return; + return false; } m_imGuiConsole.PostUpdate(); } else { m_imGuiConsole.ShowAboutWindow(false, m_errorString); } - { - OPTICK_EVENT("Flush"); - CGraphics::SetCommitResourcesAsLazy(false); - } +// { +// OPTICK_EVENT("Flush"); +// CGraphics::SetCommitResourcesAsLazy(false); +// } - { - OPTICK_EVENT("Draw"); - gfxQ->setRenderTarget(m_renderTex); - gfxQ->clearTarget(); - gfxQ->setViewport(rect); - gfxQ->setScissor(rect); - if (g_Renderer != nullptr) { - g_Renderer->BeginScene(); - } + return true; + } + + void onAppDraw() noexcept override { + OPTICK_EVENT("Draw"); + if (g_Renderer != nullptr) { + g_Renderer->BeginScene(); if (g_mainMP1) { g_mainMP1->Draw(); } - if (g_Renderer != nullptr) { - g_Renderer->EndScene(); - } + g_Renderer->EndScene(); } + } - { - OPTICK_EVENT("ImGui Draw"); - ImGuiEngine::End(); - ImGuiEngine::Draw(gfxQ); - } - - { - OPTICK_EVENT("Execute"); - gfxQ->execute(); - } - - gfxQ->resolveDisplay(m_renderTex); - + void onAppPostDraw() noexcept override { + OPTICK_EVENT("PostDraw"); if (m_voiceEngine) { m_voiceEngine->pumpAndMixVoices(); } @@ -526,7 +453,19 @@ public: ++logvisor::FrameIndex; } - void appQuitting(boo::IApplication* /*unused*/) override { m_running.store(false); } + void onAppExiting() noexcept override { + m_imGuiConsole.Shutdown(); + if (g_mainMP1) { + g_mainMP1->Shutdown(); + } + g_mainMP1.reset(); +// m_renderTex.reset(); +// m_pipelineConv.reset(); + m_cvarManager.serialize(); + m_voiceEngine.reset(); + m_amuseAllocWrapper.reset(); + CDvdFile::Shutdown(); + } [[nodiscard]] std::string getGraphicsApi() const { return m_cvarCommons.getGraphicsApi(); } @@ -626,11 +565,9 @@ int main(int argc, char** argv) { /* Handle -j argument */ hecl::SetCpuCountOverride(argc, argv); - metaforce::Application appCb(fileMgr, cvarMgr, cvarCmns); - int ret = boo::ApplicationRun(boo::IApplication::EPlatformType::Auto, appCb, "metaforce", "Metaforce", argv[0], args, - appCb.getGraphicsApi(), appCb.getSamples(), appCb.getAnisotropy(), appCb.getDeepColor(), - false); - return ret; + auto app = std::make_unique(fileMgr, cvarMgr, cvarCmns); + aurora::app_run(std::move(app)); + return 0; } #endif diff --git a/Runtime/CMakeLists.txt b/Runtime/CMakeLists.txt index f7df2fb4f..18f308a6b 100644 --- a/Runtime/CMakeLists.txt +++ b/Runtime/CMakeLists.txt @@ -136,7 +136,7 @@ endfunction() set(RUNTIME_INCLUDES ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}) set(RUNTIME_LIBRARIES ${HECL_APPLICATION_REPS_TARGETS_LIST} RetroDataSpec AssetNameMapNull NESEmulator - libjpeg-turbo jbus kabufuda discord-rpc logvisor OptickCore imgui) + libjpeg-turbo jbus kabufuda discord-rpc logvisor OptickCore imgui aurora) add_runtime_common_library(RuntimeCommon ${RUNTIME_SOURCES_A}) target_include_directories(RuntimeCommon PUBLIC ${RUNTIME_INCLUDES}) @@ -205,7 +205,7 @@ elseif (UNIX) set(PLAT_LIBS rt) endif () -add_executable(metaforce CMain.cpp ${PLAT_SRCS} ImGuiConsole.hpp ImGuiConsole.cpp ImGuiEntitySupport.hpp ImGuiEntitySupport.cpp) # ImGuiPlayerLoadouts.hpp +add_executable(metaforce CMain.cpp ${PLAT_SRCS} ImGuiConsole.hpp ImGuiConsole.cpp ImGuiEntitySupport.hpp ImGuiEntitySupport.cpp ../Graphics/lib.cpp) # ImGuiPlayerLoadouts.hpp # target_atdna(metaforce atdna_ImGuiPlayerLoadouts.cpp ImGuiPlayerLoadouts.hpp) # RUNTIME_LIBRARIES repeated here for link ordering target_link_libraries(metaforce PUBLIC RuntimeCommon RuntimeCommonB ${RUNTIME_LIBRARIES} ${PLAT_LIBS}) @@ -215,7 +215,7 @@ if (COMMAND add_sanitizers) endif () if (NOT WINDOWS_STORE) - add_dependencies(metaforce visigen hecl) + add_dependencies(metaforce hecl) # visigen else () set_property(TARGET metaforce PROPERTY VS_WINRT_COMPONENT TRUE) # This should match the Package.appxmanifest diff --git a/Runtime/CPakFile.cpp b/Runtime/CPakFile.cpp index c0b91600b..3555ceffa 100644 --- a/Runtime/CPakFile.cpp +++ b/Runtime/CPakFile.cpp @@ -63,10 +63,10 @@ void CPakFile::InitialHeaderLoad() { athena::io::MemoryReader r(x38_headerData.data(), x38_headerData.size()); x30_dvdReq.reset(); u32 version = r.readUint32Big(); - if (version != 0x80030005) { + if (version != 0x00030005) { Log.report(logvisor::Fatal, FMT_STRING("{}: Incompatible pak file version -- Current version is {:08X}, you're using {:08X}"), - GetPath(), 0x80030005, version); + GetPath(), 0x00030005, version); return; } diff --git a/Runtime/CResLoader.cpp b/Runtime/CResLoader.cpp index 482becd53..3a30bee4a 100644 --- a/Runtime/CResLoader.cpp +++ b/Runtime/CResLoader.cpp @@ -8,7 +8,7 @@ static logvisor::Module Log("CResLoader"); CResLoader::CResLoader() { x48_curPak = x18_pakLoadedList.end(); } const std::vector* CResLoader::GetTagListForFile(std::string_view name) const { - const std::string namePak = std::string(name).append(".upak"); + const std::string namePak = std::string(name).append(".pak"); for (const std::unique_ptr& pak : x18_pakLoadedList) { if (CStringExtras::CompareCaseInsensitive(namePak, pak->x18_path)) { return &pak->GetDepList(); @@ -18,7 +18,7 @@ const std::vector* CResLoader::GetTagListForFile(std::string_view name } void CResLoader::AddPakFileAsync(std::string_view name, bool buildDepList, bool worldPak, bool override) { - const std::string namePak = std::string(name).append(".upak"); + const std::string namePak = std::string(name).append(".pak"); if (CDvdFile::FileExists(namePak)) { x30_pakLoadingList.emplace_back(std::make_unique(namePak, buildDepList, worldPak, override)); ++x44_pakLoadingCount; @@ -116,7 +116,7 @@ std::unique_ptr CResLoader::LoadNewResourcePartSync(const metaforce::SObje } void CResLoader::GetTagListForFile(const char* pakName, std::vector& out) const { - std::string path = std::string(pakName) + ".upak"; + std::string path = std::string(pakName) + ".pak"; for (const std::unique_ptr& file : m_overridePakList) { if (_GetTagListForFile(out, path, file)) diff --git a/Runtime/CStateManager.cpp b/Runtime/CStateManager.cpp index 8c015ab19..3fe04ea60 100644 --- a/Runtime/CStateManager.cpp +++ b/Runtime/CStateManager.cpp @@ -985,90 +985,90 @@ void CStateManager::DrawWorld() { } void CStateManager::DrawActorCubeFaces(CActor& actor, int& cubeInst) const { - if (!actor.m_reflectionCube || - (!TCastToPtr(actor) && (!actor.GetActive() || !actor.IsDrawEnabled() || actor.xe4_30_outOfFrustum))) - return; - - const TAreaId visAreaId = actor.GetAreaIdAlways(); - const SViewport backupVp = g_Viewport; - - int areaCount = 0; - std::array areaArr; - for (const CGameArea& area : *x850_world) { - if (areaCount == 10) { - break; - } - auto occState = CGameArea::EOcclusionState::Occluded; - if (area.IsPostConstructed()) { - occState = area.GetOcclusionState(); - } - if (occState == CGameArea::EOcclusionState::Visible) { - areaArr[areaCount++] = &area; - } - } - - for (int f = 0; f < 6; ++f) { - SCOPED_GRAPHICS_DEBUG_GROUP(fmt::format(FMT_STRING("CStateManager::DrawActorCubeFaces [{}] {} {} {}"), f, - actor.GetUniqueId(), actor.GetEditorId(), actor.GetName()) - .c_str(), - zeus::skOrange); - CGraphics::g_BooMainCommandQueue->setRenderTarget(actor.m_reflectionCube, f); - SetupViewForCubeFaceDraw(actor.GetRenderBounds().center(), f); - CGraphics::g_BooMainCommandQueue->clearTarget(); - - std::sort(areaArr.begin(), areaArr.begin() + areaCount, [visAreaId](const CGameArea* a, const CGameArea* b) { - if (a->x4_selfIdx == b->x4_selfIdx) { - return false; - } - if (visAreaId == a->x4_selfIdx) { - return false; - } - if (visAreaId == b->x4_selfIdx) { - return true; - } - return CGraphics::g_ViewPoint.dot(a->GetAABB().center()) > CGraphics::g_ViewPoint.dot(b->GetAABB().center()); - }); - - int pvsCount = 0; - std::array pvsArr; - for (auto area = areaArr.cbegin(); area != areaArr.cbegin() + areaCount; ++area) { - const CGameArea* areaPtr = *area; - CPVSVisSet& pvsSet = pvsArr[pvsCount++]; - pvsSet.Reset(EPVSVisSetState::OutOfBounds); - GetVisSetForArea(areaPtr->x4_selfIdx, visAreaId, pvsSet); - } - - for (int i = areaCount - 1; i >= 0; --i) { - const CGameArea& area = *areaArr[i]; - SetupFogForArea(area); - g_Renderer->EnablePVS(pvsArr[i], area.x4_selfIdx); - g_Renderer->SetWorldLightFadeLevel(area.GetPostConstructed()->x1128_worldLightingLevel); - g_Renderer->UpdateAreaUniforms(area.x4_selfIdx, EWorldShadowMode::None, true, cubeInst * 6 + f); - g_Renderer->DrawUnsortedGeometry(area.x4_selfIdx, 0x2, 0x0); - } - - if (!SetupFogForDraw()) { - g_Renderer->SetWorldFog(ERglFogMode::None, 0.f, 1.f, zeus::skBlack); - } - - x850_world->DrawSky(zeus::CTransform::Translate(CGraphics::g_ViewPoint)); - - for (int i = 0; i < areaCount; ++i) { - const CGameArea& area = *areaArr[i]; - CPVSVisSet& pvs = pvsArr[i]; - SetupFogForArea(area); - g_Renderer->SetWorldLightFadeLevel(area.GetPostConstructed()->x1128_worldLightingLevel); - g_Renderer->EnablePVS(pvs, area.x4_selfIdx); - g_Renderer->DrawSortedGeometry(area.x4_selfIdx, 0x2, 0x0); - } - } - - CGraphics::g_BooMainCommandQueue->generateMipmaps(actor.m_reflectionCube); - - CBooRenderer::BindMainDrawTarget(); - g_Renderer->SetViewport(backupVp.x0_left, backupVp.x4_top, backupVp.x8_width, backupVp.xc_height); - - ++cubeInst; +// if (!actor.m_reflectionCube || +// (!TCastToPtr(actor) && (!actor.GetActive() || !actor.IsDrawEnabled() || actor.xe4_30_outOfFrustum))) +// return; +// +// const TAreaId visAreaId = actor.GetAreaIdAlways(); +// const SViewport backupVp = g_Viewport; +// +// int areaCount = 0; +// std::array areaArr; +// for (const CGameArea& area : *x850_world) { +// if (areaCount == 10) { +// break; +// } +// auto occState = CGameArea::EOcclusionState::Occluded; +// if (area.IsPostConstructed()) { +// occState = area.GetOcclusionState(); +// } +// if (occState == CGameArea::EOcclusionState::Visible) { +// areaArr[areaCount++] = &area; +// } +// } +// +// for (int f = 0; f < 6; ++f) { +// SCOPED_GRAPHICS_DEBUG_GROUP(fmt::format(FMT_STRING("CStateManager::DrawActorCubeFaces [{}] {} {} {}"), f, +// actor.GetUniqueId(), actor.GetEditorId(), actor.GetName()) +// .c_str(), +// zeus::skOrange); +// CGraphics::g_BooMainCommandQueue->setRenderTarget(actor.m_reflectionCube, f); +// SetupViewForCubeFaceDraw(actor.GetRenderBounds().center(), f); +// CGraphics::g_BooMainCommandQueue->clearTarget(); +// +// std::sort(areaArr.begin(), areaArr.begin() + areaCount, [visAreaId](const CGameArea* a, const CGameArea* b) { +// if (a->x4_selfIdx == b->x4_selfIdx) { +// return false; +// } +// if (visAreaId == a->x4_selfIdx) { +// return false; +// } +// if (visAreaId == b->x4_selfIdx) { +// return true; +// } +// return CGraphics::g_ViewPoint.dot(a->GetAABB().center()) > CGraphics::g_ViewPoint.dot(b->GetAABB().center()); +// }); +// +// int pvsCount = 0; +// std::array pvsArr; +// for (auto area = areaArr.cbegin(); area != areaArr.cbegin() + areaCount; ++area) { +// const CGameArea* areaPtr = *area; +// CPVSVisSet& pvsSet = pvsArr[pvsCount++]; +// pvsSet.Reset(EPVSVisSetState::OutOfBounds); +// GetVisSetForArea(areaPtr->x4_selfIdx, visAreaId, pvsSet); +// } +// +// for (int i = areaCount - 1; i >= 0; --i) { +// const CGameArea& area = *areaArr[i]; +// SetupFogForArea(area); +// g_Renderer->EnablePVS(pvsArr[i], area.x4_selfIdx); +// g_Renderer->SetWorldLightFadeLevel(area.GetPostConstructed()->x1128_worldLightingLevel); +// g_Renderer->UpdateAreaUniforms(area.x4_selfIdx, EWorldShadowMode::None, true, cubeInst * 6 + f); +// g_Renderer->DrawUnsortedGeometry(area.x4_selfIdx, 0x2, 0x0); +// } +// +// if (!SetupFogForDraw()) { +// g_Renderer->SetWorldFog(ERglFogMode::None, 0.f, 1.f, zeus::skBlack); +// } +// +// x850_world->DrawSky(zeus::CTransform::Translate(CGraphics::g_ViewPoint)); +// +// for (int i = 0; i < areaCount; ++i) { +// const CGameArea& area = *areaArr[i]; +// CPVSVisSet& pvs = pvsArr[i]; +// SetupFogForArea(area); +// g_Renderer->SetWorldLightFadeLevel(area.GetPostConstructed()->x1128_worldLightingLevel); +// g_Renderer->EnablePVS(pvs, area.x4_selfIdx); +// g_Renderer->DrawSortedGeometry(area.x4_selfIdx, 0x2, 0x0); +// } +// } +// +// CGraphics::g_BooMainCommandQueue->generateMipmaps(actor.m_reflectionCube); +// +// CBooRenderer::BindMainDrawTarget(); +// g_Renderer->SetViewport(backupVp.x0_left, backupVp.x4_top, backupVp.x8_width, backupVp.xc_height); +// +// ++cubeInst; } void CStateManager::DrawWorldCubeFaces() const { diff --git a/Runtime/CTextureCache.cpp b/Runtime/CTextureCache.cpp index 77adda107..3311e857b 100644 --- a/Runtime/CTextureCache.cpp +++ b/Runtime/CTextureCache.cpp @@ -23,4 +23,4 @@ CFactoryFnReturn FTextureCacheFactory([[maybe_unused]] const SObjectTag& tag, CI [[maybe_unused]] CObjectReference* selfRef) { return TToken::GetIObjObjectFor(std::make_unique(in)); } -} // namespace metaforce \ No newline at end of file +} // namespace metaforce diff --git a/Runtime/CTextureCache.hpp b/Runtime/CTextureCache.hpp index 3f095172f..81bd4bc16 100644 --- a/Runtime/CTextureCache.hpp +++ b/Runtime/CTextureCache.hpp @@ -43,4 +43,4 @@ public: CFactoryFnReturn FTextureCacheFactory(const metaforce::SObjectTag& tag, CInputStream& in, const metaforce::CVParamTransfer& vparms, CObjectReference* selfRef); -} // namespace metaforce \ No newline at end of file +} // namespace metaforce diff --git a/Runtime/Character/CAnimData.cpp b/Runtime/Character/CAnimData.cpp index c7d6a01b5..151744995 100644 --- a/Runtime/Character/CAnimData.cpp +++ b/Runtime/Character/CAnimData.cpp @@ -43,8 +43,7 @@ CAnimData::CAnimData(CAssetId id, const CCharacterInfo& character, int defaultAn TLockedToken layout, TToken model, const std::optional>& iceModel, const std::weak_ptr& ctx, std::shared_ptr animMgr, - std::shared_ptr transMgr, TLockedToken charFactory, - int drawInstCount) + std::shared_ptr transMgr, TLockedToken charFactory) : x0_charFactory(charFactory) , xc_charInfo(character) , xcc_layoutData(layout) @@ -56,8 +55,7 @@ CAnimData::CAnimData(CAssetId id, const CCharacterInfo& character, int defaultAn , x204_charIdx(charIdx) , x208_defaultAnim(defaultAnim) , x224_pose(layout->GetSegIdList().GetList().size()) -, x2fc_poseBuilder(CLayoutDescription{layout}) -, m_drawInstCount(drawInstCount) { +, x2fc_poseBuilder(CLayoutDescription{layout}) { x220_25_loop = loop; if (iceModel) @@ -797,12 +795,11 @@ void CAnimData::AdvanceAnim(CCharAnimTime& time, zeus::CVector3f& offset, zeus:: } void CAnimData::SetXRayModel(const TLockedToken& model, const TLockedToken& skinRules) { - xf4_xrayModel = std::make_shared(model, skinRules, xd8_modelData->GetLayoutInfo(), 0, m_drawInstCount); + xf4_xrayModel = std::make_shared(model, skinRules, xd8_modelData->GetLayoutInfo(), 0); } void CAnimData::SetInfraModel(const TLockedToken& model, const TLockedToken& skinRules) { - xf8_infraModel = - std::make_shared(model, skinRules, xd8_modelData->GetLayoutInfo(), 0, m_drawInstCount); + xf8_infraModel = std::make_shared(model, skinRules, xd8_modelData->GetLayoutInfo(), 0); } void CAnimData::PoseSkinnedModel(CSkinnedModel& model, const CPoseAsTransforms& pose, const CModelFlags& drawFlags, diff --git a/Runtime/Character/CAnimData.hpp b/Runtime/Character/CAnimData.hpp index 0e7bb21ac..f9ceee8a7 100644 --- a/Runtime/Character/CAnimData.hpp +++ b/Runtime/Character/CAnimData.hpp @@ -144,14 +144,12 @@ private: static rstl::reserved_vector g_SoundPOINodes; static rstl::reserved_vector g_TransientInt32POINodes; - int m_drawInstCount; - public: CAnimData(CAssetId, const CCharacterInfo& character, int defaultAnim, int charIdx, bool loop, TLockedToken layout, TToken model, const std::optional>& iceModel, const std::weak_ptr& ctx, std::shared_ptr animMgr, std::shared_ptr transMgr, - TLockedToken charFactory, int drawInstCount); + TLockedToken charFactory); void SetParticleEffectState(std::string_view effectName, bool active, CStateManager& mgr); void InitializeEffects(CStateManager& mgr, TAreaId aId, const zeus::CVector3f& scale); diff --git a/Runtime/Character/CCharacterFactory.cpp b/Runtime/Character/CCharacterFactory.cpp index 1469a8b7e..ab2074fc9 100644 --- a/Runtime/Character/CCharacterFactory.cpp +++ b/Runtime/Character/CCharacterFactory.cpp @@ -24,13 +24,11 @@ CFactoryFnReturn CCharacterFactory::CDummyFactory::Build(const SObjectTag& tag, switch (tag.type.toUint32() & 0x1) { case 0: - return TToken::GetIObjObjectFor( - std::make_unique(*g_SimplePool, charInfo.GetModelId(), charInfo.GetSkinRulesId(), - charInfo.GetCharLayoutInfoId(), 0, tag.type.toUint32() >> 16)); + return TToken::GetIObjObjectFor(std::make_unique( + *g_SimplePool, charInfo.GetModelId(), charInfo.GetSkinRulesId(), charInfo.GetCharLayoutInfoId(), 0)); case 1: - return TToken::GetIObjObjectFor( - std::make_unique(*g_SimplePool, charInfo.GetIceModelId(), charInfo.GetIceSkinRulesId(), - charInfo.GetCharLayoutInfoId(), 0, tag.type.toUint32() >> 16)); + return TToken::GetIObjObjectFor(std::make_unique( + *g_SimplePool, charInfo.GetIceModelId(), charInfo.GetIceSkinRulesId(), charInfo.GetCharLayoutInfoId(), 0)); default: break; } @@ -78,21 +76,20 @@ std::unique_ptr CCharacterFactory::CDummyFactory::LoadNewResourcePartSync( std::unique_ptr CCharacterFactory::CreateCharacter(int charIdx, bool loop, const TLockedToken& factory, - int defaultAnim, int drawInsts) { + int defaultAnim) { const CCharacterInfo& charInfo = x4_charInfoDB[charIdx]; const CVParamTransfer charParm(new TObjOwnerParam(&charInfo)); - TToken skinnedModel = - x70_cacheResPool.GetObj({FourCC(drawInsts << 16), charInfo.GetModelId()}, charParm); + TToken skinnedModel = x70_cacheResPool.GetObj({FourCC(0u), charInfo.GetModelId()}, charParm); std::optional> iceModel; if (charInfo.GetIceModelId().IsValid() && charInfo.GetIceSkinRulesId().IsValid()) { - iceModel.emplace(x70_cacheResPool.GetObj({FourCC((drawInsts << 16) | 1), charInfo.GetIceModelId()}, charParm)); + iceModel.emplace(x70_cacheResPool.GetObj({FourCC(1u), charInfo.GetIceModelId()}, charParm)); } return std::make_unique(x68_selfId, charInfo, defaultAnim, charIdx, loop, x14_charLayoutInfoDB[charIdx], std::move(skinnedModel), iceModel, x24_sysContext, x28_animMgr, x2c_transMgr, - factory, drawInsts); + factory); } CAssetId CCharacterFactory::GetEventResourceIdForAnimResourceId(CAssetId id) const { @@ -156,8 +153,9 @@ CCharacterFactory::CCharacterFactory(CSimplePool& store, const CAnimCharacterSet std::vector primitives; x28_animMgr->GetAnimationDatabase()->GetAllUniquePrimitives(primitives); x30_animSourceDB.reserve(primitives.size()); - for (const CPrimitive& prim : primitives) - x30_animSourceDB.push_back(store.GetObj({SBIG('ANIM'), prim.GetAnimResId()})); + for (const CPrimitive& prim : primitives) { + x30_animSourceDB.emplace_back(store.GetObj({SBIG('ANIM'), prim.GetAnimResId()})); + } } } // namespace metaforce diff --git a/Runtime/Character/CCharacterFactory.hpp b/Runtime/Character/CCharacterFactory.hpp index a4ac2ba47..a082c9183 100644 --- a/Runtime/Character/CCharacterFactory.hpp +++ b/Runtime/Character/CCharacterFactory.hpp @@ -68,7 +68,7 @@ public: CCharacterFactory(CSimplePool& store, const CAnimCharacterSet& ancs, CAssetId); std::unique_ptr CreateCharacter(int charIdx, bool loop, const TLockedToken& factory, - int defaultAnim, int drawInsts); + int defaultAnim); CAssetId GetEventResourceIdForAnimResourceId(CAssetId animId) const; const CCharacterInfo& GetCharInfo(int charIdx) const { return x4_charInfoDB[charIdx]; } diff --git a/Runtime/Character/CModelData.cpp b/Runtime/Character/CModelData.cpp index 37eb1bbfa..9fc9f981d 100644 --- a/Runtime/Character/CModelData.cpp +++ b/Runtime/Character/CModelData.cpp @@ -23,17 +23,17 @@ CModelData::~CModelData() = default; CModelData::CModelData() {} CModelData CModelData::CModelDataNull() { return CModelData(); } -CModelData::CModelData(const CStaticRes& res, int instCount) : x0_scale(res.GetScale()), m_drawInstCount(instCount) { +CModelData::CModelData(const CStaticRes& res) : x0_scale(res.GetScale()) { x1c_normalModel = g_SimplePool->GetObj({SBIG('CMDL'), res.GetId()}); if (!x1c_normalModel) Log.report(logvisor::Fatal, FMT_STRING("unable to find CMDL {}"), res.GetId()); - m_normalModelInst = x1c_normalModel->MakeNewInstance(0, instCount); + m_normalModelInst = x1c_normalModel->MakeNewInstance(0); } -CModelData::CModelData(const CAnimRes& res, int instCount) : x0_scale(res.GetScale()), m_drawInstCount(instCount) { +CModelData::CModelData(const CAnimRes& res) : x0_scale(res.GetScale()) { TToken factory = g_CharFactoryBuilder->GetFactory(res); x10_animData = - factory->CreateCharacter(res.GetCharacterNodeId(), res.CanLoop(), factory, res.GetDefaultAnim(), instCount); + factory->CreateCharacter(res.GetCharacterNodeId(), res.CanLoop(), factory, res.GetDefaultAnim()); } SAdvancementDeltas CModelData::GetAdvancementDeltas(const CCharAnimTime& a, const CCharAnimTime& b) const { @@ -143,7 +143,7 @@ void CModelData::SetXRayModel(const std::pair& modelSkin) { x2c_xrayModel = g_SimplePool->GetObj({SBIG('CMDL'), modelSkin.first}); if (!x2c_xrayModel) Log.report(logvisor::Fatal, FMT_STRING("unable to find CMDL {}"), modelSkin.first); - m_xrayModelInst = x2c_xrayModel->MakeNewInstance(0, m_drawInstCount); + m_xrayModelInst = x2c_xrayModel->MakeNewInstance(0); } } } @@ -160,7 +160,7 @@ void CModelData::SetInfraModel(const std::pair& modelSkin) { x3c_infraModel = g_SimplePool->GetObj({SBIG('CMDL'), modelSkin.first}); if (!x3c_infraModel) Log.report(logvisor::Fatal, FMT_STRING("unable to find CMDL {}"), modelSkin.first); - m_infraModelInst = x3c_infraModel->MakeNewInstance(0, m_drawInstCount); + m_infraModelInst = x3c_infraModel->MakeNewInstance(0); } } } @@ -431,7 +431,7 @@ void CModelData::DisintegrateDraw(EWhichModel which, const zeus::CTransform& xf, zeus::CTransform scaledXf = xf * zeus::CTransform::Scale(x0_scale); CGraphics::SetModelMatrix(scaledXf); - CBooModel::SetDisintegrateTexture(tex.GetBooTexture()); + CBooModel::SetDisintegrateTexture(tex.GetTexture()); CModelFlags flags(5, 0, 3, zeus::skWhite); flags.m_extendedShader = EExtendedShader::Disintegrate; flags.addColor = addColor; diff --git a/Runtime/Character/CModelData.hpp b/Runtime/Character/CModelData.hpp index 19b6dadcf..304dbfe82 100644 --- a/Runtime/Character/CModelData.hpp +++ b/Runtime/Character/CModelData.hpp @@ -75,8 +75,6 @@ class CModelData { std::unique_ptr m_xrayModelInst; std::unique_ptr m_infraModelInst; - int m_drawInstCount = 0; - public: enum class EWhichModel { Normal, XRay, Thermal, ThermalHot }; @@ -84,8 +82,8 @@ public: bool GetSortThermal() const { return x14_25_sortThermal; } ~CModelData(); - explicit CModelData(const CStaticRes& res, int instCount = 1); - explicit CModelData(const CAnimRes& res, int instCount = 1); + explicit CModelData(const CStaticRes& res); + explicit CModelData(const CAnimRes& res); CModelData(CModelData&&) = default; CModelData& operator=(CModelData&&) = default; CModelData(); diff --git a/Runtime/Character/CSkinRules.cpp b/Runtime/Character/CSkinRules.cpp index 8ce0ca4c9..dce9d3b2e 100644 --- a/Runtime/Character/CSkinRules.cpp +++ b/Runtime/Character/CSkinRules.cpp @@ -6,45 +6,61 @@ namespace metaforce { -CSkinRules::CSkinRules(CInputStream& in) { - u32 bankCount = in.readUint32Big(); - x0_skinBanks.reserve(bankCount); - for (u32 i = 0; i < bankCount; ++i) - x0_skinBanks.emplace_back(in); - - u32 virtualBoneCount = in.readUint32Big(); - m_virtualBones.reserve(virtualBoneCount); - for (u32 i = 0; i < virtualBoneCount; ++i) - m_virtualBones.emplace_back(in); - - u32 poolSz = in.readUint32Big(); - m_poolToSkinIdx.reserve(poolSz); - for (u32 i = 0; i < poolSz; ++i) - m_poolToSkinIdx.push_back(in.readUint32Big()); -} - -void CSkinRules::TransformVerticesCPU(std::vector>& vnOut, - const CPoseAsTransforms& pose, const CModel& model) const { - OPTICK_EVENT(); - vnOut.resize(m_poolToSkinIdx.size()); - for (size_t i = 0; i < m_poolToSkinIdx.size(); ++i) { - const CVirtualBone& vb = m_virtualBones[m_poolToSkinIdx[i]]; - zeus::CVector3f origVertex = model.GetPoolVertex(i); - zeus::CVector3f vertex; - zeus::CVector3f origNormal = model.GetPoolNormal(i); - zeus::CVector3f normal; - for (const SSkinWeighting& w : vb.GetWeights()) { - const zeus::CTransform& xf = pose.GetRestToAccumTransform(w.m_id); - vertex += (xf * origVertex) * w.m_weight; - normal += (xf.basis.inverted().transposed() * origNormal) * w.m_weight; - } - vnOut[i] = std::make_pair(vertex, normal.normalized()); +static u32 ReadCount(CInputStream& in) { + u32 result = in.readUint32Big(); + if (result == UINT32_MAX) { + return in.readUint32Big(); } + in.seek(s64(result) * 3); + return result; } +CSkinRules::CSkinRules(CInputStream& in) { + u32 weightCount = in.readUint32Big(); + x0_bones.reserve(weightCount); + for (int i = 0; i < weightCount; ++i) { + x0_bones.emplace_back(in); + } + x10_vertexCount = ReadCount(in); + x14_normalCount = ReadCount(in); +} + +// void CSkinRules::TransformVerticesCPU(std::vector>& vnOut, +// const CPoseAsTransforms& pose, const CModel& model) const { +// OPTICK_EVENT(); +// vnOut.resize(m_poolToSkinIdx.size()); +// for (size_t i = 0; i < m_poolToSkinIdx.size(); ++i) { +// const CVirtualBone& vb = m_virtualBones[m_poolToSkinIdx[i]]; +// zeus::CVector3f origVertex = model.GetPoolVertex(i); +// zeus::CVector3f vertex; +// zeus::CVector3f origNormal = model.GetPoolNormal(i); +// zeus::CVector3f normal; +// for (const SSkinWeighting& w : vb.GetWeights()) { +// const zeus::CTransform& xf = pose.GetRestToAccumTransform(w.m_id); +// vertex += (xf * origVertex) * w.m_weight; +// normal += (xf.basis.inverted().transposed() * origNormal) * w.m_weight; +// } +// vnOut[i] = std::make_pair(vertex, normal.normalized()); +// } +// } + CFactoryFnReturn FSkinRulesFactory(const SObjectTag& tag, CInputStream& in, const CVParamTransfer& params, CObjectReference* selfRef) { return TToken::GetIObjObjectFor(std::make_unique(in)); } +auto StreamInSkinWeighting(CInputStream& in) { + rstl::reserved_vector weights; + u32 weightCount = in.readUint32Big(); + for (int i = 0; i < std::min(3u, weightCount); ++i) { + weights.emplace_back(in); + } + for (int i = 3; i < weightCount; ++i) { + SSkinWeighting{in}; + } + return weights; +} + +CVirtualBone::CVirtualBone(CInputStream& in) +: x0_weights(StreamInSkinWeighting(in)), x1c_vertexCount(in.readUint32Big()) {} } // namespace metaforce diff --git a/Runtime/Character/CSkinRules.hpp b/Runtime/Character/CSkinRules.hpp index bdca237c8..109c9a783 100644 --- a/Runtime/Character/CSkinRules.hpp +++ b/Runtime/Character/CSkinRules.hpp @@ -3,10 +3,9 @@ #include #include "Runtime/CFactoryMgr.hpp" -#include "Runtime/RetroTypes.hpp" #include "Runtime/Character/CSkinBank.hpp" +#include "Runtime/RetroTypes.hpp" -#include #include namespace metaforce { @@ -14,46 +13,42 @@ class CPoseAsTransforms; class CModel; struct SSkinWeighting { - CSegId m_id; - float m_weight; - explicit SSkinWeighting(CInputStream& in) : m_id(in), m_weight(in.readFloatBig()) {} + CSegId x0_id; + float x4_weight; + explicit SSkinWeighting(CInputStream& in) : x0_id(in), x4_weight(in.readFloatBig()) {} }; class CVirtualBone { - std::vector m_weights; + rstl::reserved_vector x0_weights; + u32 x1c_vertexCount; + zeus::CTransform x20_xf; + zeus::CMatrix3f x50_mtx; public: - explicit CVirtualBone(CInputStream& in) { - u32 weightCount = in.readUint32Big(); - m_weights.reserve(weightCount); - for (u32 i = 0; i < weightCount; ++i) - m_weights.emplace_back(in); - } + explicit CVirtualBone(CInputStream& in); - const std::vector& GetWeights() const { return m_weights; } + [[nodiscard]] const rstl::reserved_vector& GetWeights() const { return x0_weights; } }; class CSkinRules { - std::vector x0_skinBanks; - // u32 x10_vertexCount; - // u32 x14_normalCount; - std::vector m_virtualBones; - std::vector m_poolToSkinIdx; + std::vector x0_bones; + u32 x10_vertexCount; + u32 x14_normalCount; public: explicit CSkinRules(CInputStream& in); - void GetBankTransforms(std::vector& out, const CPoseAsTransforms& pose, - int skinBankIdx) const { - // FIXME: This is definitely not proper behavior, this is here to fix the phazon suit crashing - if (x0_skinBanks.size() <= skinBankIdx) { - return; - } - x0_skinBanks[skinBankIdx].GetBankTransforms(out, pose); - } +// void GetBankTransforms(std::vector& out, const CPoseAsTransforms& pose, +// int skinBankIdx) const { +// // FIXME: This is definitely not proper behavior, this is here to fix the phazon suit crashing +// if (x0_skinBanks.size() <= skinBankIdx) { +// return; +// } +// x0_skinBanks[skinBankIdx].GetBankTransforms(out, pose); +// } - void TransformVerticesCPU(std::vector>& vnOut, - const CPoseAsTransforms& pose, const CModel& model) const; +// void TransformVerticesCPU(std::vector>& vnOut, +// const CPoseAsTransforms& pose, const CModel& model) const; }; CFactoryFnReturn FSkinRulesFactory(const SObjectTag& tag, CInputStream& in, const CVParamTransfer& params, diff --git a/Runtime/Graphics/CBooRenderer.cpp b/Runtime/Graphics/CBooRenderer.cpp index a45ce32fe..755f0fedf 100644 --- a/Runtime/Graphics/CBooRenderer.cpp +++ b/Runtime/Graphics/CBooRenderer.cpp @@ -410,8 +410,7 @@ void CBooRenderer::DrawFogSlices(const zeus::CPlane* planes, size_t numPlanes, s } void CBooRenderer::RenderFogVolumeModel(const zeus::CAABox& aabb, const CModel* model, const zeus::CTransform& modelMtx, - const zeus::CTransform& viewMtx, const CSkinnedModel* sModel, int pass, - CFogVolumePlaneShader* fvs) { + const zeus::CTransform& viewMtx, const CSkinnedModel* sModel, int pass) { if (!model && !sModel) { if (pass == 0) { zeus::CAABox xfAABB = aabb.getTransformedAABox(modelMtx); @@ -432,13 +431,14 @@ void CBooRenderer::RenderFogVolumeModel(const zeus::CAABox& aabb, const CModel* xfAABB.max.z() - xfAABB.min.z()) * 2.f; - fvs->reset(7 * 6); + CFogVolumePlaneShader fvs; + fvs.reset(7 * 6); for (size_t i = 0; i < planes.size(); ++i) { - DrawFogSlices(planes.data(), planes.size(), i, xfAABB.center(), longestAxis, *fvs); + DrawFogSlices(planes.data(), planes.size(), i, xfAABB.center(), longestAxis, fvs); } - fvs->draw(0); + aurora::shaders::queue_fog_volume_plane(fvs.m_verts, 0); } else { - fvs->draw(pass); + aurora::shaders::queue_fog_volume_plane({}, pass); } } else { CModelFlags flags; @@ -547,140 +547,132 @@ void CBooRenderer::ReallyRenderFogVolume(const zeus::CColor& color, const zeus:: zeus::CAABox marginAABB((CGraphics::g_GXModelView * aabb.min) - 1.f, (CGraphics::g_GXModelView * aabb.max) + 1.f); bool camInModel = marginAABB.pointInside(CGraphics::g_ViewMatrix.origin) && (model || sModel); - CFogVolumePlaneShader* fvs; - if (!model && !sModel) { - fvs = &*((m_nextFogVolumePlaneShader == m_fogVolumePlaneShaders.end()) - ? m_fogVolumePlaneShaders.insert(m_fogVolumePlaneShaders.end(), CFogVolumePlaneShader()) - : m_nextFogVolumePlaneShader++); - } else { - fvs = nullptr; - } +// CFogVolumePlaneShader* fvs; +// if (!model && !sModel) { +// fvs = &*((m_nextFogVolumePlaneShader == m_fogVolumePlaneShaders.end()) +// ? m_fogVolumePlaneShaders.insert(m_fogVolumePlaneShaders.end(), CFogVolumePlaneShader()) +// : m_nextFogVolumePlaneShader++); +// } else { +// fvs = nullptr; +// } - RenderFogVolumeModel(aabb, model, CGraphics::g_GXModelMatrix, CGraphics::g_ViewMatrix, sModel, 0, fvs); + RenderFogVolumeModel(aabb, model, CGraphics::g_GXModelMatrix, CGraphics::g_ViewMatrix, sModel, 0); if (camInModel) - RenderFogVolumeModel(aabb, model, CGraphics::g_GXModelMatrix, CGraphics::g_ViewMatrix, sModel, 1, fvs); + RenderFogVolumeModel(aabb, model, CGraphics::g_GXModelMatrix, CGraphics::g_ViewMatrix, sModel, 1); CGraphics::ResolveSpareDepth(rect, 0); - RenderFogVolumeModel(aabb, model, CGraphics::g_GXModelMatrix, CGraphics::g_ViewMatrix, sModel, 2, fvs); + RenderFogVolumeModel(aabb, model, CGraphics::g_GXModelMatrix, CGraphics::g_ViewMatrix, sModel, 2); if (camInModel) - RenderFogVolumeModel(aabb, model, CGraphics::g_GXModelMatrix, CGraphics::g_ViewMatrix, sModel, 3, fvs); + RenderFogVolumeModel(aabb, model, CGraphics::g_GXModelMatrix, CGraphics::g_ViewMatrix, sModel, 3); CGraphics::ResolveSpareDepth(rect, 1); - auto fvf = (m_nextFogVolumeFilter == m_fogVolumeFilters.end()) - ? m_fogVolumeFilters.insert(m_fogVolumeFilters.end(), CFogVolumeFilter()) - : m_nextFogVolumeFilter++; - fvf->draw2WayPass(color); + aurora::shaders::queue_fog_volume_filter(color, true); if (camInModel) - fvf->draw1WayPass(color); + aurora::shaders::queue_fog_volume_filter(color, false); // CGraphics::SetScissor(g_Viewport.x0_left, g_Viewport.x4_top, g_Viewport.x8_width, g_Viewport.xc_height); } -void CBooRenderer::GenerateFogVolumeRampTex(boo::IGraphicsDataFactory::Context& ctx) { - std::array, FOGVOL_RAMP_RES> data{}; - for (size_t y = 0; y < data.size(); ++y) { - for (size_t x = 0; x < data[y].size(); ++x) { - const int tmp = int(y << 16 | x << 8 | 0x7f); - const double a = - zeus::clamp(0.0, - (-150.0 / (tmp / double(0xffffff) * (FOGVOL_FAR - FOGVOL_NEAR) - FOGVOL_FAR) - FOGVOL_NEAR) * - 3.0 / (FOGVOL_FAR - FOGVOL_NEAR), - 1.0); - data[y][x] = u16((a * a + a) / 2.0 * 65535); - } - } - x1b8_fogVolumeRamp = - ctx.newStaticTexture(FOGVOL_RAMP_RES, FOGVOL_RAMP_RES, 1, boo::TextureFormat::I16, boo::TextureClampMode::Repeat, - data[0].data(), FOGVOL_RAMP_RES * FOGVOL_RAMP_RES * 2); -} +//void CBooRenderer::GenerateFogVolumeRampTex() { +// std::array, FOGVOL_RAMP_RES> data{}; +// for (size_t y = 0; y < data.size(); ++y) { +// for (size_t x = 0; x < data[y].size(); ++x) { +// const int tmp = int(y << 16 | x << 8 | 0x7f); +// const double a = +// zeus::clamp(0.0, +// (-150.0 / (tmp / double(0xffffff) * (FOGVOL_FAR - FOGVOL_NEAR) - FOGVOL_FAR) - FOGVOL_NEAR) * +// 3.0 / (FOGVOL_FAR - FOGVOL_NEAR), +// 1.0); +// data[y][x] = (a * a + a) / 2.0; +// } +// } +// x1b8_fogVolumeRamp = +// aurora::new_static_texture_2d(FOGVOL_RAMP_RES, FOGVOL_RAMP_RES, 1, aurora::shaders::TextureFormat::R32Float, +// {data[0].data(), FOGVOL_RAMP_RES * FOGVOL_RAMP_RES * 2}); +//} +// +//void CBooRenderer::GenerateSphereRampTex() { +// std::array, SPHERE_RAMP_RES> data{}; +// constexpr float halfRes = SPHERE_RAMP_RES / 2.f; +// for (size_t y = 0; y < data.size(); ++y) { +// for (size_t x = 0; x < data[y].size(); ++x) { +// const zeus::CVector2f vec((float(x) - halfRes) / halfRes, (float(y) - halfRes) / halfRes); +// data[y][x] = 255 - zeus::clamp(0.f, vec.canBeNormalized() ? vec.magnitude() : 0.f, 1.f) * 255; +// } +// } +// x220_sphereRamp = +// aurora::new_static_texture_2d(SPHERE_RAMP_RES, SPHERE_RAMP_RES, 1, aurora::shaders::TextureFormat::R8, +// {data[0].data(), SPHERE_RAMP_RES * SPHERE_RAMP_RES}); +//} +// +//void CBooRenderer::GenerateScanLinesVBO() { +// std::vector verts; +// verts.reserve(670); +// +// for (int i = 0; i < 112; ++i) { +// verts.emplace_back(-1.f, (float(i) * (4.f / 448.f) + (1.f / 448.f)) * 2.f - 1.f, 0.f); +// if (i != 0) { +// verts.emplace_back(verts.back()); +// } +// verts.emplace_back(-1.f, (float(i) * (4.f / 448.f) - (1.f / 448.f)) * 2.f - 1.f, 0.f); +// verts.emplace_back(1.f, (float(i) * (4.f / 448.f) + (1.f / 448.f)) * 2.f - 1.f, 0.f); +// verts.emplace_back(1.f, (float(i) * (4.f / 448.f) - (1.f / 448.f)) * 2.f - 1.f, 0.f); +// if (i != 111) { +// verts.emplace_back(verts.back()); +// } +// } +// +// m_scanLinesEvenVBO = ctx.newStaticBuffer(boo::BufferUse::Vertex, verts.data(), sizeof(zeus::CVector3f), verts.size()); +// +// verts.clear(); +// +// for (int i = 0; i < 112; ++i) { +// verts.emplace_back(-1.f, (float(i) * (4.f / 448.f) + (3.f / 448.f)) * 2.f - 1.f, 0.f); +// if (i != 0) { +// verts.emplace_back(verts.back()); +// } +// verts.emplace_back(-1.f, (float(i) * (4.f / 448.f) + (1.f / 448.f)) * 2.f - 1.f, 0.f); +// verts.emplace_back(1.f, (float(i) * (4.f / 448.f) + (3.f / 448.f)) * 2.f - 1.f, 0.f); +// verts.emplace_back(1.f, (float(i) * (4.f / 448.f) + (1.f / 448.f)) * 2.f - 1.f, 0.f); +// if (i != 111) { +// verts.emplace_back(verts.back()); +// } +// } +// +// m_scanLinesOddVBO = ctx.newStaticBuffer(boo::BufferUse::Vertex, verts.data(), sizeof(zeus::CVector3f), verts.size()); +//} -void CBooRenderer::GenerateSphereRampTex(boo::IGraphicsDataFactory::Context& ctx) { - std::array, SPHERE_RAMP_RES> data{}; - constexpr float halfRes = SPHERE_RAMP_RES / 2.f; - for (size_t y = 0; y < data.size(); ++y) { - for (size_t x = 0; x < data[y].size(); ++x) { - const zeus::CVector2f vec((float(x) - halfRes) / halfRes, (float(y) - halfRes) / halfRes); - data[y][x] = 255 - zeus::clamp(0.f, vec.canBeNormalized() ? vec.magnitude() : 0.f, 1.f) * 255; - } - } - x220_sphereRamp = - ctx.newStaticTexture(SPHERE_RAMP_RES, SPHERE_RAMP_RES, 1, boo::TextureFormat::I8, - boo::TextureClampMode::ClampToEdge, data[0].data(), SPHERE_RAMP_RES * SPHERE_RAMP_RES); -} - -void CBooRenderer::GenerateScanLinesVBO(boo::IGraphicsDataFactory::Context& ctx) { - std::vector verts; - verts.reserve(670); - - for (int i = 0; i < 112; ++i) { - verts.emplace_back(-1.f, (float(i) * (4.f / 448.f) + (1.f / 448.f)) * 2.f - 1.f, 0.f); - if (i != 0) { - verts.emplace_back(verts.back()); - } - verts.emplace_back(-1.f, (float(i) * (4.f / 448.f) - (1.f / 448.f)) * 2.f - 1.f, 0.f); - verts.emplace_back(1.f, (float(i) * (4.f / 448.f) + (1.f / 448.f)) * 2.f - 1.f, 0.f); - verts.emplace_back(1.f, (float(i) * (4.f / 448.f) - (1.f / 448.f)) * 2.f - 1.f, 0.f); - if (i != 111) { - verts.emplace_back(verts.back()); - } - } - - m_scanLinesEvenVBO = ctx.newStaticBuffer(boo::BufferUse::Vertex, verts.data(), sizeof(zeus::CVector3f), verts.size()); - - verts.clear(); - - for (int i = 0; i < 112; ++i) { - verts.emplace_back(-1.f, (float(i) * (4.f / 448.f) + (3.f / 448.f)) * 2.f - 1.f, 0.f); - if (i != 0) { - verts.emplace_back(verts.back()); - } - verts.emplace_back(-1.f, (float(i) * (4.f / 448.f) + (1.f / 448.f)) * 2.f - 1.f, 0.f); - verts.emplace_back(1.f, (float(i) * (4.f / 448.f) + (3.f / 448.f)) * 2.f - 1.f, 0.f); - verts.emplace_back(1.f, (float(i) * (4.f / 448.f) + (1.f / 448.f)) * 2.f - 1.f, 0.f); - if (i != 111) { - verts.emplace_back(verts.back()); - } - } - - m_scanLinesOddVBO = ctx.newStaticBuffer(boo::BufferUse::Vertex, verts.data(), sizeof(zeus::CVector3f), verts.size()); -} - -boo::ObjToken CBooRenderer::GetColorTexture(const zeus::CColor& color) { +std::shared_ptr CBooRenderer::GetColorTexture(const zeus::CColor& color) { const auto search = m_colorTextures.find(color); if (search != m_colorTextures.end()) { return search->second; } - std::array pixel; + std::array pixel{}; color.toRGBA8(pixel[0], pixel[1], pixel[2], pixel[3]); - boo::ObjToken tex; - CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) { - tex = ctx.newStaticTexture(1, 1, 1, boo::TextureFormat::RGBA8, boo::TextureClampMode::Repeat, pixel.data(), - pixel.size()) - .get(); - return true; - } BooTrace); + auto tex = aurora::new_static_texture_2d(1, 1, 1, aurora::shaders::TextureFormat::RGBA8, {pixel.data(), pixel.size()}, + "Color Texture"sv); m_colorTextures.emplace(color, tex); return tex; } -void CBooRenderer::LoadThermoPalette() { - m_thermoPaletteTex = xc_store.GetObj("TXTR_ThermoPalette"); - CTexture* thermoTexObj = m_thermoPaletteTex.GetObj(); - if (thermoTexObj) - x288_thermoPalette = thermoTexObj->GetPaletteTexture(); -} - -void CBooRenderer::LoadBallFade() { - m_ballFadeTex = xc_store.GetObj("TXTR_BallFade"); - CTexture* ballFadeTexObj = m_ballFadeTex.GetObj(); - if (ballFadeTexObj) { - m_ballFade = ballFadeTexObj->GetBooTexture(); - m_ballFade->setClampMode(boo::TextureClampMode::ClampToEdge); - } -} +//void CBooRenderer::LoadThermoPalette() { +// m_thermoPaletteTex = xc_store.GetObj("TXTR_ThermoPalette"); +// CTexture* thermoTexObj = m_thermoPaletteTex.GetObj(); +// if (thermoTexObj) +// x288_thermoPalette = thermoTexObj->GetPaletteTexture(); +//} +// +//void CBooRenderer::LoadBallFade() { +// m_ballFadeTex = xc_store.GetObj("TXTR_BallFade"); +// CTexture* ballFadeTexObj = m_ballFadeTex.GetObj(); +// if (ballFadeTexObj) { +// m_ballFade = ballFadeTexObj->GetBooTexture(); +// m_ballFade->setClampMode(boo::TextureClampMode::ClampToEdge); +// } +//} CBooRenderer::CBooRenderer(IObjectStore& store, IFactory& resFac) : x8_factory(resFac), xc_store(store), x2a8_thermalRand(20) { @@ -688,36 +680,32 @@ CBooRenderer::CBooRenderer(IObjectStore& store, IFactory& resFac) m_staticEntropy = store.GetObj("RandomStaticEntropy"); - CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) { - constexpr std::array clearPixel{0, 0, 0, 0}; - m_clearTexture = ctx.newStaticTexture(1, 1, 1, boo::TextureFormat::RGBA8, boo::TextureClampMode::Repeat, - clearPixel.data(), clearPixel.size()) - .get(); - constexpr std::array blackPixel{0, 0, 0, 255}; - m_blackTexture = ctx.newStaticTexture(1, 1, 1, boo::TextureFormat::RGBA8, boo::TextureClampMode::Repeat, - blackPixel.data(), blackPixel.size()) - .get(); - constexpr std::array whitePixel{255, 255, 255, 255}; - m_whiteTexture = ctx.newStaticTexture(1, 1, 1, boo::TextureFormat::RGBA8, boo::TextureClampMode::Repeat, - whitePixel.data(), whitePixel.size()) - .get(); + constexpr std::array clearPixel{0, 0, 0, 0}; + m_clearTexture = aurora::new_static_texture_2d(1, 1, 1, aurora::shaders::TextureFormat::RGBA8, + {clearPixel.data(), clearPixel.size()}, "Clear Texture"sv); + constexpr std::array blackPixel{0, 0, 0, 255}; + m_blackTexture = aurora::new_static_texture_2d(1, 1, 1, aurora::shaders::TextureFormat::RGBA8, + {blackPixel.data(), blackPixel.size()}, "Black Texture"sv); + constexpr std::array whitePixel{255, 255, 255, 255}; + m_whiteTexture = aurora::new_static_texture_2d(1, 1, 1, aurora::shaders::TextureFormat::RGBA8, + {whitePixel.data(), whitePixel.size()}, "White Texture"sv); - GenerateFogVolumeRampTex(ctx); - GenerateSphereRampTex(ctx); - m_ballShadowId = ctx.newRenderTexture(m_ballShadowIdW, m_ballShadowIdH, boo::TextureClampMode::Repeat, 1, 0); - x14c_reflectionTex = ctx.newRenderTexture(256, 256, boo::TextureClampMode::ClampToBlack, 1, 0); - GenerateScanLinesVBO(ctx); - return true; - } BooTrace); - LoadThermoPalette(); - LoadBallFade(); +// GenerateFogVolumeRampTex(); +// GenerateSphereRampTex(); + m_ballShadowId = aurora::new_render_texture(m_ballShadowIdW, m_ballShadowIdH, 1, 0, "Ball Shadow"); +// m_ballShadowId = ctx.newRenderTexture(m_ballShadowIdW, m_ballShadowIdH, boo::TextureClampMode::Repeat, 1, 0); + x14c_reflectionTex = aurora::new_render_texture(256, 256, 1, 0, "Reflection"); +// x14c_reflectionTex = ctx.newRenderTexture(256, 256, boo::TextureClampMode::ClampToBlack, 1, 0); +// GenerateScanLinesVBO(); +// LoadThermoPalette(); +// LoadBallFade(); m_thermColdFilter.emplace(); m_thermHotFilter.emplace(); Buckets::Init(); - m_nextFogVolumePlaneShader = m_fogVolumePlaneShaders.end(); - m_nextFogVolumeFilter = m_fogVolumeFilters.end(); +// m_nextFogVolumePlaneShader = m_fogVolumePlaneShaders.end(); +// m_nextFogVolumeFilter = m_fogVolumeFilters.end(); } CBooRenderer::~CBooRenderer() { g_Renderer = nullptr; } @@ -792,23 +780,20 @@ void CBooRenderer::UpdateAreaUniforms(int areaIdx, EWorldShadowMode shadowMode, if (areaIdx != -1 && item.x18_areaIdx != areaIdx) continue; - item.m_shaderSet->m_geomLayout->Update(flags, nullptr, nullptr, &item.m_shaderSet->m_matSet, - item.m_shaderSet->m_geomLayout->GetSharedBuffer(bufIdx), nullptr); +// item.m_shaderSet->m_geomLayout->Update(flags, nullptr, nullptr, &item.m_shaderSet->m_matSet, +// item.m_shaderSet->m_geomLayout->GetSharedBuffer(bufIdx), nullptr); if (shadowMode == EWorldShadowMode::BallOnWorldShadow || shadowMode == EWorldShadowMode::BallOnWorldIds) continue; - CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) { - for (auto it = item.x10_models.begin(); it != item.x10_models.end(); ++it) { - CBooModel* model = *it; - if (model->TryLockTextures()) { - if (activateLights) - ActivateLightsForModel(&item, *model); - model->UpdateUniformData(flags, nullptr, nullptr, bufIdx, &ctx); - } + for (auto it = item.x10_models.begin(); it != item.x10_models.end(); ++it) { + CBooModel* model = *it; + if (model->TryLockTextures()) { + if (activateLights) + ActivateLightsForModel(&item, *model); +// model->UpdateUniformData(flags, nullptr, nullptr, bufIdx); } - return true; - } BooTrace); + } } } @@ -1084,8 +1069,8 @@ void CBooRenderer::BeginScene() { x318_26_requestRGBA6 = false; // GXSetPixelFmt(x318_27_currentRGBA6); CGraphics::BeginScene(); - m_nextFogVolumePlaneShader = m_fogVolumePlaneShaders.begin(); - m_nextFogVolumeFilter = m_fogVolumeFilters.begin(); +// m_nextFogVolumePlaneShader = m_fogVolumePlaneShaders.begin(); +// m_nextFogVolumeFilter = m_fogVolumeFilters.begin(); } void CBooRenderer::EndScene() { @@ -1111,15 +1096,16 @@ void CBooRenderer::CacheReflection(TReflectionCallback cb, void* ctx, bool clear x318_24_refectionDirty = false; x2dc_reflectionAge = 0; - BindReflectionDrawTarget(); - SViewport backupVp = g_Viewport; - SetViewport(0, 0, 256, 256); - CGraphics::g_BooMainCommandQueue->clearTarget(); - cb(ctx, CBooModel::g_ReflectViewPos); - boo::SWindowRect rect(0, 0, 256, 256); - CGraphics::g_BooMainCommandQueue->resolveBindTexture(x14c_reflectionTex, rect, false, 0, true, false); - BindMainDrawTarget(); - SetViewport(backupVp.x0_left, backupVp.x4_top, backupVp.x8_width, backupVp.xc_height); + // TODO + // BindReflectionDrawTarget(); + // SViewport backupVp = g_Viewport; + // SetViewport(0, 0, 256, 256); + // CGraphics::g_BooMainCommandQueue->clearTarget(); + // cb(ctx, CBooModel::g_ReflectViewPos); + // boo::SWindowRect rect(0, 0, 256, 256); + // CGraphics::g_BooMainCommandQueue->resolveBindTexture(x14c_reflectionTex, rect, false, 0, true, false); + // BindMainDrawTarget(); + // SetViewport(backupVp.x0_left, backupVp.x4_top, backupVp.x8_width, backupVp.xc_height); } void CBooRenderer::DrawSpaceWarp(const zeus::CVector3f& pt, float strength) { @@ -1152,7 +1138,7 @@ void CBooRenderer::DrawXRayOutline(const zeus::CAABox& aabb) { for (u32 b = 0; b < 32; ++b) { if ((bitmap[c] & (1U << b)) != 0) { CBooModel* model = item.x10_models[c * 32 + b]; - model->UpdateUniformData(flags, nullptr, nullptr); +// model->UpdateUniformData(flags, nullptr, nullptr); const CBooSurface* surf = model->x38_firstUnsortedSurface; while (surf) { if (surf->GetBounds().intersects(aabb)) @@ -1362,7 +1348,7 @@ int CBooRenderer::DrawOverlappingWorldModelIDs(int alphaVal, const std::vector(alphaVal) / 255.f; CBooModel& model = *item.x10_models[wordModel + j]; - model.UpdateUniformData(flags, nullptr, nullptr, 3); +// model.UpdateUniformData(flags, nullptr, nullptr, 3); model.VerifyCurrentShader(0); for (const CBooSurface* surf = model.x38_firstUnsortedSurface; surf; surf = surf->m_next) { if (surf->GetBounds().intersects(aabb)) { @@ -1409,7 +1395,7 @@ void CBooRenderer::DrawOverlappingWorldModelShadows(int alphaVal, const std::vec flags.x4_color.r() = static_cast(alphaVal) / 255.f; CBooModel& model = *item.x10_models[wordModel + j]; - model.UpdateUniformData(flags, nullptr, nullptr, 2); +// model.UpdateUniformData(flags, nullptr, nullptr, 2); model.VerifyCurrentShader(0); for (const CBooSurface* surf = model.x38_firstUnsortedSurface; surf; surf = surf->m_next) if (surf->GetBounds().intersects(aabb)) diff --git a/Runtime/Graphics/CBooRenderer.hpp b/Runtime/Graphics/CBooRenderer.hpp index 1f8bab6ee..8200876da 100644 --- a/Runtime/Graphics/CBooRenderer.hpp +++ b/Runtime/Graphics/CBooRenderer.hpp @@ -101,31 +101,31 @@ class CBooRenderer final : public IRenderer { // boo::ITextureS* xe4_blackTex = nullptr; bool xee_24_ : 1 = true; - boo::ObjToken m_clearTexture; - boo::ObjToken m_blackTexture; - boo::ObjToken m_whiteTexture; - std::unordered_map> m_colorTextures; + std::shared_ptr m_clearTexture; + std::shared_ptr m_blackTexture; + std::shared_ptr m_whiteTexture; + std::unordered_map> m_colorTextures; - boo::ObjToken x14c_reflectionTex; + std::shared_ptr x14c_reflectionTex; // boo::ITextureS* x150_mirrorRamp = nullptr; - boo::ObjToken x1b8_fogVolumeRamp; - boo::ObjToken x220_sphereRamp; - TLockedToken m_thermoPaletteTex; - boo::ObjToken x288_thermoPalette; - TLockedToken m_ballFadeTex; - boo::ObjToken m_ballFade; - boo::ObjToken m_ballShadowId; - boo::ObjToken m_scanLinesEvenVBO; - boo::ObjToken m_scanLinesOddVBO; +// std::shared_ptr x1b8_fogVolumeRamp; + std::shared_ptr x220_sphereRamp; +// TLockedToken m_thermoPaletteTex; +// std::shared_ptr x288_thermoPalette; +// TLockedToken m_ballFadeTex; + std::shared_ptr m_ballFade; + std::shared_ptr m_ballShadowId; +// boo::ObjToken m_scanLinesEvenVBO; +// boo::ObjToken m_scanLinesOddVBO; int m_ballShadowIdW = 64; int m_ballShadowIdH = 64; CRandom16 x2a8_thermalRand; std::list x2ac_fogVolumes; - std::list m_fogVolumePlaneShaders; - std::list::iterator m_nextFogVolumePlaneShader; - std::list m_fogVolumeFilters; - std::list::iterator m_nextFogVolumeFilter; +// std::list m_fogVolumePlaneShaders; +// std::list::iterator m_nextFogVolumePlaneShader; +// std::list m_fogVolumeFilters; +// std::list::iterator m_nextFogVolumeFilter; std::list> x2c4_spaceWarps; u32 x2dc_reflectionAge = 2; zeus::CColor x2e0_ = zeus::skWhite; @@ -156,11 +156,11 @@ class CBooRenderer final : public IRenderer { bool x318_31_persistRGBA6 : 1 = false; bool m_thermalHotPass : 1 = false; - void GenerateFogVolumeRampTex(boo::IGraphicsDataFactory::Context& ctx); - void GenerateSphereRampTex(boo::IGraphicsDataFactory::Context& ctx); - void GenerateScanLinesVBO(boo::IGraphicsDataFactory::Context& ctx); - void LoadThermoPalette(); - void LoadBallFade(); +// void GenerateFogVolumeRampTex(); +// void GenerateSphereRampTex(); +// void GenerateScanLinesVBO(); +// void LoadThermoPalette(); +// void LoadBallFade(); void ActivateLightsForModel(CAreaListItem* item, CBooModel& model); void RenderBucketItems(CAreaListItem* item); @@ -170,8 +170,7 @@ class CBooRenderer final : public IRenderer { static void DrawFogSlices(const zeus::CPlane* planes, size_t numPlanes, size_t iteration, const zeus::CVector3f& center, float delta, CFogVolumePlaneShader& fogVol); static void RenderFogVolumeModel(const zeus::CAABox& aabb, const CModel* model, const zeus::CTransform& modelMtx, - const zeus::CTransform& viewMtx, const CSkinnedModel* sModel, int pass, - CFogVolumePlaneShader* fvs); + const zeus::CTransform& viewMtx, const CSkinnedModel* sModel, int pass); void SetupRendererStates() const; void ReallyDrawPhazonSuitIndirectEffect(const zeus::CColor& vertColor, /*const CTexture& maskTex,*/ @@ -264,27 +263,31 @@ public: void ReallyRenderFogVolume(const zeus::CColor& color, const zeus::CAABox& aabb, const CModel* model, const CSkinnedModel* sModel); - const boo::ObjToken& GetThermoPalette() const { return x288_thermoPalette; } - const boo::ObjToken& GetFogRampTex() const { return x1b8_fogVolumeRamp; } - const boo::ObjToken& GetRandomStaticEntropyTex() const { return m_staticEntropy->GetBooTexture(); } - const boo::ObjToken& GetScanLinesEvenVBO() const { return m_scanLinesEvenVBO; } - const boo::ObjToken& GetScanLinesOddVBO() const { return m_scanLinesOddVBO; } +// const boo::ObjToken& GetThermoPalette() const { return x288_thermoPalette; } +// const boo::ObjToken& GetFogRampTex() const { return x1b8_fogVolumeRamp; } +// const boo::ObjToken& GetRandomStaticEntropyTex() const { return m_staticEntropy->GetBooTexture(); } +// const boo::ObjToken& GetScanLinesEvenVBO() const { return m_scanLinesEvenVBO; } +// const boo::ObjToken& GetScanLinesOddVBO() const { return m_scanLinesOddVBO; } - const boo::ObjToken& GetClearTexture() const { return m_clearTexture; } - const boo::ObjToken& GetBlackTexture() const { return m_blackTexture; } - const boo::ObjToken& GetWhiteTexture() const { return m_whiteTexture; } + const std::shared_ptr& GetClearTexture() const { return m_clearTexture; } + const std::shared_ptr& GetBlackTexture() const { return m_blackTexture; } + const std::shared_ptr& GetWhiteTexture() const { return m_whiteTexture; } - boo::ObjToken GetColorTexture(const zeus::CColor& color); + std::shared_ptr GetColorTexture(const zeus::CColor& color); - static void BindMainDrawTarget() { CGraphics::g_BooMainCommandQueue->setRenderTarget(CGraphics::g_SpareTexture); } - void BindReflectionDrawTarget() { CGraphics::g_BooMainCommandQueue->setRenderTarget(x14c_reflectionTex); } + static void BindMainDrawTarget() { +// CGraphics::g_BooMainCommandQueue->setRenderTarget(CGraphics::g_SpareTexture); + } + void BindReflectionDrawTarget() { +// CGraphics::g_BooMainCommandQueue->setRenderTarget(x14c_reflectionTex); + } void BindBallShadowIdTarget() { - CGraphics::g_BooMainCommandQueue->setRenderTarget(m_ballShadowId); +// CGraphics::g_BooMainCommandQueue->setRenderTarget(m_ballShadowId); SetViewport(0, 0, m_ballShadowIdW, m_ballShadowIdH); } void ResolveBallShadowIdTarget() { - CGraphics::g_BooMainCommandQueue->resolveBindTexture( - m_ballShadowId, boo::SWindowRect(0, 0, m_ballShadowIdW, m_ballShadowIdH), false, 0, true, false); +// CGraphics::g_BooMainCommandQueue->resolveBindTexture( +// m_ballShadowId, boo::SWindowRect(0, 0, m_ballShadowIdW, m_ballShadowIdH), false, 0, true, false); } void FindOverlappingWorldModels(std::vector& modelBits, const zeus::CAABox& aabb) const; diff --git a/Runtime/Graphics/CCubeModel.cpp b/Runtime/Graphics/CCubeModel.cpp new file mode 100644 index 000000000..7fcc1e56b --- /dev/null +++ b/Runtime/Graphics/CCubeModel.cpp @@ -0,0 +1,36 @@ +#include "CCubeModel.hpp" + +#include "CGraphics.hpp" + +namespace metaforce { +static const u8* MemoryFromPartData(const u8*& dataCur, const u32*& secSizeCur) { + const u8* ret = nullptr; + if (*secSizeCur != 0) { + ret = dataCur; + } + dataCur += hecl::SBig(*secSizeCur); + ++secSizeCur; + return ret; +} + +CModel::CModel(std::unique_ptr in, u32 dataLen, IObjectStore* store) +: x0_data(std::move(in)), x4_dataLen(dataLen), x38_lastFrame(CGraphics::GetFrameCounter() - 2) { + const u8* data = reinterpret_cast(x0_data.get()); + u32 uVar1 = *reinterpret_cast(data + 8); + u32 sectionSizeStart = 0x2c; + if (*reinterpret_cast(data + 4) == 1) { + sectionSizeStart = 0x28; + } + const u32* secSizeCur = reinterpret_cast(data + sectionSizeStart); + s32 numMatSets = 1; + if (*reinterpret_cast(data + 4) > 1) { + numMatSets = *reinterpret_cast(data + 0x28); + } + const auto* dataCur = data + (sectionSizeStart + *reinterpret_cast(data + 0x24) * 4 + 0x1f & 0xffffffe0); + x18_matSets.reserve(numMatSets); + for (int i = 0; i < numMatSets; i += 1) { + x18_matSets.emplace_back( + const_cast(reinterpret_cast(MemoryFromPartData(dataCur, secSizeCur)))); + } +} +} // namespace metaforce diff --git a/Runtime/Graphics/CCubeModel.hpp b/Runtime/Graphics/CCubeModel.hpp new file mode 100644 index 000000000..4ea73af3d --- /dev/null +++ b/Runtime/Graphics/CCubeModel.hpp @@ -0,0 +1,37 @@ +#pragma once + +#include +#include + +#include "GCNTypes.hpp" +#include "IObjectStore.hpp" +#include "CTexture.hpp" +#include "CToken.hpp" + +namespace metaforce { +class CCubeSurface; +class CCubeModel; + +struct SShader { + std::vector> x0_textures; + CCubeModel* x10_model; + + SShader(CCubeModel* model) : x10_model(model) {} +}; + +class CModel { + std::unique_ptr x0_data; + u32 x4_dataLen; + std::vector x8_surfaces; + std::vector x18_matSets; + CCubeModel* x28_modelInst; + u16 x2c_; + u16 x2e_; + CModel* x30_next; + CModel* x34_prev; + u32 x38_lastFrame; + +public: + CModel(std::unique_ptr in, u32 dataLen, IObjectStore* store); +}; +} // namespace metaforce diff --git a/Runtime/Graphics/CGraphics.cpp b/Runtime/Graphics/CGraphics.cpp index a591ba669..8b64a9e9e 100644 --- a/Runtime/Graphics/CGraphics.cpp +++ b/Runtime/Graphics/CGraphics.cpp @@ -37,7 +37,7 @@ u32 CGraphics::g_FrameCounter = 0; u32 CGraphics::g_Framerate = 0; u32 CGraphics::g_FramesPast = 0; frame_clock::time_point CGraphics::g_FrameStartTime = frame_clock::now(); -bool CGraphics::g_commitAsLazy = false; +//bool CGraphics::g_commitAsLazy = false; const std::array CGraphics::skCubeBasisMats{{ /* Right */ @@ -127,7 +127,7 @@ void CGraphics::EndScene() { CTextSupportShader::UpdateBuffers(); /* Same with line renderer */ - CLineRenderer::UpdateBuffers(); +// CLineRenderer::UpdateBuffers(); ++g_FrameCounter; @@ -156,6 +156,7 @@ void CGraphics::SetViewMatrix() { g_GXModelViewInvXpose.origin.zeroOut(); g_GXModelViewInvXpose.basis.transpose(); /* Load normal matrix */ + aurora::shaders::update_model_view(g_GXModelView.toMatrix4f(), g_GXModelViewInvXpose.toMatrix4f()); } void CGraphics::SetModelMatrix(const zeus::CTransform& xf) { @@ -192,24 +193,24 @@ zeus::CMatrix4f CGraphics::CalculatePerspectiveMatrix(float fovy, float aspect, 0.f, 0.f, -fpn / fmn, -2.f * st.x18_far * st.x14_near / fmn, 0.f, 0.f, -1.f, 0.f); } - switch (g_BooPlatform) { - case boo::IGraphicsDataFactory::Platform::OpenGL: - default: { - return zeus::CMatrix4f(2.f * st.x14_near / rml, 0.f, rpl / rml, 0.f, 0.f, 2.f * st.x14_near / tmb, tpb / tmb, 0.f, - 0.f, 0.f, -fpn / fmn, -2.f * st.x18_far * st.x14_near / fmn, 0.f, 0.f, -1.f, 0.f); - } - case boo::IGraphicsDataFactory::Platform::D3D11: - case boo::IGraphicsDataFactory::Platform::Metal: { +// switch (g_BooPlatform) { +// case boo::IGraphicsDataFactory::Platform::OpenGL: +// default: { +// return zeus::CMatrix4f(2.f * st.x14_near / rml, 0.f, rpl / rml, 0.f, 0.f, 2.f * st.x14_near / tmb, tpb / tmb, 0.f, +// 0.f, 0.f, -fpn / fmn, -2.f * st.x18_far * st.x14_near / fmn, 0.f, 0.f, -1.f, 0.f); +// } +// case boo::IGraphicsDataFactory::Platform::D3D11: +// case boo::IGraphicsDataFactory::Platform::Metal: { zeus::CMatrix4f mat2(2.f * st.x14_near / rml, 0.f, rpl / rml, 0.f, 0.f, 2.f * st.x14_near / tmb, tpb / tmb, 0.f, 0.f, 0.f, st.x18_far / fmn, st.x14_near * st.x18_far / fmn, 0.f, 0.f, -1.f, 0.f); return PlusOneZ * mat2; - } - case boo::IGraphicsDataFactory::Platform::Vulkan: { - zeus::CMatrix4f mat2(2.f * st.x14_near / rml, 0.f, rpl / rml, 0.f, 0.f, 2.f * st.x14_near / tmb, tpb / tmb, 0.f, - 0.f, 0.f, -fpn / fmn, -2.f * st.x18_far * st.x14_near / fmn, 0.f, 0.f, -1.f, 0.f); - return VulkanCorrect * mat2; - } - } +// } +// case boo::IGraphicsDataFactory::Platform::Vulkan: { +// zeus::CMatrix4f mat2(2.f * st.x14_near / rml, 0.f, rpl / rml, 0.f, 0.f, 2.f * st.x14_near / tmb, tpb / tmb, 0.f, +// 0.f, 0.f, -fpn / fmn, -2.f * st.x18_far * st.x14_near / fmn, 0.f, 0.f, -1.f, 0.f); +// return VulkanCorrect * mat2; +// } +// } } zeus::CMatrix4f CGraphics::GetPerspectiveProjectionMatrix(bool forRenderer) { @@ -227,27 +228,27 @@ zeus::CMatrix4f CGraphics::GetPerspectiveProjectionMatrix(bool forRenderer) { 0.f, -1.f, 0.f); } - switch (g_BooPlatform) { - case boo::IGraphicsDataFactory::Platform::OpenGL: - default: { - return zeus::CMatrix4f(2.f * g_Proj.x14_near / rml, 0.f, rpl / rml, 0.f, 0.f, 2.f * g_Proj.x14_near / tmb, - tpb / tmb, 0.f, 0.f, 0.f, -fpn / fmn, -2.f * g_Proj.x18_far * g_Proj.x14_near / fmn, 0.f, - 0.f, -1.f, 0.f); - } - case boo::IGraphicsDataFactory::Platform::D3D11: - case boo::IGraphicsDataFactory::Platform::Metal: { +// switch (g_BooPlatform) { +// case boo::IGraphicsDataFactory::Platform::OpenGL: +// default: { +// return zeus::CMatrix4f(2.f * g_Proj.x14_near / rml, 0.f, rpl / rml, 0.f, 0.f, 2.f * g_Proj.x14_near / tmb, +// tpb / tmb, 0.f, 0.f, 0.f, -fpn / fmn, -2.f * g_Proj.x18_far * g_Proj.x14_near / fmn, 0.f, +// 0.f, -1.f, 0.f); +// } +// case boo::IGraphicsDataFactory::Platform::D3D11: +// case boo::IGraphicsDataFactory::Platform::Metal: { zeus::CMatrix4f mat2(2.f * g_Proj.x14_near / rml, 0.f, rpl / rml, 0.f, 0.f, 2.f * g_Proj.x14_near / tmb, tpb / tmb, 0.f, 0.f, 0.f, g_Proj.x18_far / fmn, g_Proj.x14_near * g_Proj.x18_far / fmn, 0.f, 0.f, -1.f, 0.f); return PlusOneZ * mat2; - } - case boo::IGraphicsDataFactory::Platform::Vulkan: { - zeus::CMatrix4f mat2(2.f * g_Proj.x14_near / rml, 0.f, rpl / rml, 0.f, 0.f, 2.f * g_Proj.x14_near / tmb, - tpb / tmb, 0.f, 0.f, 0.f, -fpn / fmn, -2.f * g_Proj.x18_far * g_Proj.x14_near / fmn, 0.f, - 0.f, -1.f, 0.f); - return VulkanCorrect * mat2; - } - } +// } +// case boo::IGraphicsDataFactory::Platform::Vulkan: { +// zeus::CMatrix4f mat2(2.f * g_Proj.x14_near / rml, 0.f, rpl / rml, 0.f, 0.f, 2.f * g_Proj.x14_near / tmb, +// tpb / tmb, 0.f, 0.f, 0.f, -fpn / fmn, -2.f * g_Proj.x18_far * g_Proj.x14_near / fmn, 0.f, +// 0.f, -1.f, 0.f); +// return VulkanCorrect * mat2; +// } +// } } else { float rml = g_Proj.x8_right - g_Proj.x4_left; float rpl = g_Proj.x8_right + g_Proj.x4_left; @@ -261,24 +262,24 @@ zeus::CMatrix4f CGraphics::GetPerspectiveProjectionMatrix(bool forRenderer) { -fpn / fmn, 0.f, 0.f, 0.f, 1.f); } - switch (g_BooPlatform) { - case boo::IGraphicsDataFactory::Platform::OpenGL: - default: { - return zeus::CMatrix4f(2.f / rml, 0.f, 0.f, -rpl / rml, 0.f, 2.f / tmb, 0.f, -tpb / tmb, 0.f, 0.f, -2.f / fmn, - -fpn / fmn, 0.f, 0.f, 0.f, 1.f); - } - case boo::IGraphicsDataFactory::Platform::D3D11: - case boo::IGraphicsDataFactory::Platform::Metal: { +// switch (g_BooPlatform) { +// case boo::IGraphicsDataFactory::Platform::OpenGL: +// default: { +// return zeus::CMatrix4f(2.f / rml, 0.f, 0.f, -rpl / rml, 0.f, 2.f / tmb, 0.f, -tpb / tmb, 0.f, 0.f, -2.f / fmn, +// -fpn / fmn, 0.f, 0.f, 0.f, 1.f); +// } +// case boo::IGraphicsDataFactory::Platform::D3D11: +// case boo::IGraphicsDataFactory::Platform::Metal: { zeus::CMatrix4f mat2(2.f / rml, 0.f, 0.f, -rpl / rml, 0.f, 2.f / tmb, 0.f, -tpb / tmb, 0.f, 0.f, 1.f / fmn, g_Proj.x14_near / fmn, 0.f, 0.f, 0.f, 1.f); return PlusOneZ * mat2; - } - case boo::IGraphicsDataFactory::Platform::Vulkan: { - zeus::CMatrix4f mat2(2.f / rml, 0.f, 0.f, -rpl / rml, 0.f, 2.f / tmb, 0.f, -tpb / tmb, 0.f, 0.f, -2.f / fmn, - -fpn / fmn, 0.f, 0.f, 0.f, 1.f); - return VulkanCorrect * mat2; - } - } +// } +// case boo::IGraphicsDataFactory::Platform::Vulkan: { +// zeus::CMatrix4f mat2(2.f / rml, 0.f, 0.f, -rpl / rml, 0.f, 2.f / tmb, 0.f, -tpb / tmb, 0.f, 0.f, -2.f / fmn, +// -fpn / fmn, 0.f, 0.f, 0.f, 1.f); +// return VulkanCorrect * mat2; +// } +// } } } @@ -322,6 +323,7 @@ void CGraphics::FlushProjection() { } else { // Convert and load ortho } + aurora::shaders::update_projection(GetPerspectiveProjectionMatrix(true)); } zeus::CVector2i CGraphics::ProjectPoint(const zeus::CVector3f& point) { @@ -413,26 +415,25 @@ void CGraphics::SetViewportResolution(const zeus::CVector2i& res) { g_GuiSys->OnViewportResize(); } -static boo::SWindowRect CachedVP; +static zeus::CRectangle CachedVP; zeus::CVector2f CGraphics::g_CachedDepthRange = {0.f, 1.f}; void CGraphics::SetViewport(int leftOff, int bottomOff, int width, int height) { - CachedVP.location[0] = leftOff; - CachedVP.location[1] = bottomOff; + CachedVP.position[0] = leftOff; + CachedVP.position[1] = bottomOff; CachedVP.size[0] = width; CachedVP.size[1] = height; - g_BooMainCommandQueue->setViewport(CachedVP, g_CachedDepthRange[0], g_CachedDepthRange[1]); + aurora::shaders::set_viewport(CachedVP, g_CachedDepthRange[0], g_CachedDepthRange[1]); } void CGraphics::SetScissor(int leftOff, int bottomOff, int width, int height) { - boo::SWindowRect rect(leftOff, bottomOff, width, height); - g_BooMainCommandQueue->setScissor(rect); + aurora::shaders::set_scissor(leftOff, bottomOff, width, height); } void CGraphics::SetDepthRange(float znear, float zfar) { g_CachedDepthRange[0] = znear; g_CachedDepthRange[1] = zfar; - g_BooMainCommandQueue->setViewport(CachedVP, g_CachedDepthRange[0], g_CachedDepthRange[1]); + aurora::shaders::set_viewport(CachedVP, g_CachedDepthRange[0], g_CachedDepthRange[1]); } CTimeProvider* CGraphics::g_ExternalTimeProvider = nullptr; @@ -463,11 +464,11 @@ void CGraphics::UpdateFPSCounter() { } } -boo::IGraphicsDataFactory::Platform CGraphics::g_BooPlatform = boo::IGraphicsDataFactory::Platform::Null; -boo::IGraphicsDataFactory* CGraphics::g_BooFactory = nullptr; -boo::IGraphicsCommandQueue* CGraphics::g_BooMainCommandQueue = nullptr; -boo::ObjToken CGraphics::g_SpareTexture; -const char* CGraphics::g_BooPlatformName = nullptr; +//boo::IGraphicsDataFactory::Platform CGraphics::g_BooPlatform = boo::IGraphicsDataFactory::Platform::Null; +//boo::IGraphicsDataFactory* CGraphics::g_BooFactory = nullptr; +//boo::IGraphicsCommandQueue* CGraphics::g_BooMainCommandQueue = nullptr; +//boo::ObjToken CGraphics::g_SpareTexture; +//const char* CGraphics::g_BooPlatformName = nullptr; const CTevCombiners::CTevPass CGraphics::sTevPass805a564c({GX::TevColorArg::CC_ZERO, GX::TevColorArg::CC_ZERO, GX::TevColorArg::CC_ZERO, GX::TevColorArg::CC_RASC}, diff --git a/Runtime/Graphics/CGraphics.hpp b/Runtime/Graphics/CGraphics.hpp index bd09bd4ca..18cfd415f 100644 --- a/Runtime/Graphics/CGraphics.hpp +++ b/Runtime/Graphics/CGraphics.hpp @@ -9,8 +9,8 @@ #include "DataSpec/DNACommon/GX.hpp" -#include -#include +//#include +//#include #include #include @@ -20,8 +20,70 @@ #include #include +#include "aurora.h" +#include "aurora_shaders.h" + using frame_clock = std::chrono::high_resolution_clock; +namespace aurora { +using TextureRef = aurora::shaders::TextureRef; +template +struct RustDrop {}; +template <> +struct RustDrop { + TextureRef ref; + explicit RustDrop(TextureRef ref) : ref(ref) {} + ~RustDrop() { aurora::shaders::drop_texture(ref); } + RustDrop(const RustDrop&) = delete; + RustDrop& operator=(const RustDrop&) = delete; +}; +using TextureHandle = RustDrop; + +inline std::shared_ptr new_static_texture_2d(uint32_t width, uint32_t height, uint32_t mips, + aurora::shaders::TextureFormat format, + rust::Slice data, + std::string_view label) { + rust::Str rlabel{label.data(), label.size()}; + auto ref = aurora::shaders::create_static_texture_2d(width, height, mips, format, data, rlabel); + return std::make_shared(ref); +} +inline std::shared_ptr new_render_texture(uint32_t width, uint32_t height, + uint32_t color_bind_count, uint32_t depth_bind_count, + std::string_view label) { + rust::Str rlabel{label.data(), label.size()}; + auto ref = aurora::shaders::create_render_texture(width, height, color_bind_count, depth_bind_count, rlabel); + return std::make_shared(ref); +} + +template +class ArrayRef { +public: + using value_type = std::remove_cvref_t; + using pointer = value_type*; + using const_pointer = const value_type*; + using reference = value_type&; + using const_reference = const value_type&; + using iterator = const_pointer; + using const_iterator = const_pointer; + using size_type = std::size_t; + using difference_type = std::ptrdiff_t; + + ArrayRef() = default; + explicit ArrayRef(T& one) : data(&one), length(1) {} + ArrayRef(T* data, size_t length) : data(data), length(length) {} + ArrayRef(T* begin, T* end) : data(begin), length(end - begin) {} + template + constexpr explicit ArrayRef(T (&arr)[N]) : data(arr), length(N) {} + template + constexpr explicit ArrayRef(std::array arr) : data(arr.data()), length(arr.size()) {} + explicit ArrayRef(std::vector vec) : data(vec.data()), length(vec.size()) {} + +private: + T* data = nullptr; + size_t length = 0; +}; +} // namespace aurora + namespace metaforce { extern hecl::CVar* g_disableLighting; class CLight; @@ -91,21 +153,7 @@ enum class ERglAlphaFunc { enum class ERglAlphaOp { And = 0, Or = 1, Xor = 2, XNor = 3 }; -enum class ERglFogMode : uint32_t { - None = 0x00, - - PerspLin = 0x02, - PerspExp = 0x04, - PerspExp2 = 0x05, - PerspRevExp = 0x06, - PerspRevExp2 = 0x07, - - OrthoLin = 0x0A, - OrthoExp = 0x0C, - OrthoExp2 = 0x0D, - OrthoRevExp = 0x0E, - OrthoRevExp2 = 0x0F -}; +using ERglFogMode = aurora::shaders::FogMode; struct SViewport { u32 x0_left; @@ -145,12 +193,12 @@ struct SClipScreenRect { , x20_uvYMin(uvYMin) , x24_uvYMax(uvYMax) {} - SClipScreenRect(const boo::SWindowRect& rect) { - x4_left = rect.location[0]; - x8_top = rect.location[1]; - xc_width = rect.size[0]; - x10_height = rect.size[1]; - x14_dstWidth = rect.size[0]; + SClipScreenRect(const aurora::shaders::ClipRect& rect) { + x4_left = rect.x; + x8_top = rect.y; + xc_width = rect.width; + x10_height = rect.height; + x14_dstWidth = rect.width; } SClipScreenRect(const SViewport& vp) { @@ -243,13 +291,14 @@ public: float x18_far; }; - struct CFogState { - zeus::CColor m_color; - float m_A = 0.f; - float m_B = 0.5f; - float m_C = 0.f; - ERglFogMode m_mode; - }; + using CFogState = aurora::shaders::FogState; + // struct CFogState { + // zeus::CColor m_color; + // float m_A = 0.f; + // float m_B = 0.5f; + // float m_C = 0.f; + // ERglFogMode m_mode; + // }; static CProjectionState g_Proj; static zeus::CVector2f g_CachedDepthRange; @@ -321,73 +370,78 @@ public: static u32 GetFPS() { return g_Framerate; } static void UpdateFPSCounter(); - static boo::IGraphicsDataFactory::Platform g_BooPlatform; - static const char* g_BooPlatformName; - static boo::IGraphicsDataFactory* g_BooFactory; - static boo::IGraphicsCommandQueue* g_BooMainCommandQueue; - static boo::ObjToken g_SpareTexture; +// static boo::IGraphicsDataFactory::Platform g_BooPlatform; +// static const char* g_BooPlatformName; +// static boo::IGraphicsDataFactory* g_BooFactory; +// static boo::IGraphicsCommandQueue* g_BooMainCommandQueue; +// static boo::ObjToken g_SpareTexture; static const std::array skCubeBasisMats; - static void InitializeBoo(boo::IGraphicsDataFactory* factory, boo::IGraphicsCommandQueue* cc, - const boo::ObjToken& spareTex) { - g_BooPlatform = factory->platform(); - g_BooPlatformName = factory->platformName(); - g_BooFactory = factory; - g_BooMainCommandQueue = cc; - g_SpareTexture = spareTex; - } +// static void InitializeBoo(boo::IGraphicsDataFactory* factory, boo::IGraphicsCommandQueue* cc, +// const boo::ObjToken& spareTex) { +// g_BooPlatform = factory->platform(); +// g_BooPlatformName = factory->platformName(); +// g_BooFactory = factory; +// g_BooMainCommandQueue = cc; +// g_SpareTexture = spareTex; +// } +// +// static void ShutdownBoo() { +// g_BooFactory = nullptr; +// g_BooMainCommandQueue = nullptr; +// g_SpareTexture.reset(); +// } +// +// static const char* PlatformName() { return g_BooPlatformName; } - static void ShutdownBoo() { - g_BooFactory = nullptr; - g_BooMainCommandQueue = nullptr; - g_SpareTexture.reset(); - } +// static void CommitResources(const boo::FactoryCommitFunc& commitFunc __BooTraceArgs) { +// g_BooFactory->commitTransaction(commitFunc __BooTraceArgsUse); +// } - static const char* PlatformName() { return g_BooPlatformName; } - - - static bool g_commitAsLazy; - static void SetCommitResourcesAsLazy(bool newStatus) { - if (newStatus != g_commitAsLazy) { - g_commitAsLazy = newStatus; - if (!newStatus && g_BooFactory) { - g_BooFactory->commitPendingTransaction(); - } - } - } - - static void CommitResources(const boo::FactoryCommitFunc& commitFunc __BooTraceArgs) { - CommitResources(commitFunc __BooTraceArgsUse, g_commitAsLazy); - } - - static void CommitResources(const boo::FactoryCommitFunc& commitFunc __BooTraceArgs, bool lazy) { - if (!g_BooFactory) { - return; - } - if (lazy) { - g_BooFactory->lazyCommitTransaction(commitFunc __BooTraceArgsUse); - } else { - g_BooFactory->commitTransaction(commitFunc __BooTraceArgsUse); - } - } - - static void SetShaderDataBinding(const boo::ObjToken& binding) { - g_BooMainCommandQueue->setShaderDataBinding(binding); - } +// static bool g_commitAsLazy; +// static void SetCommitResourcesAsLazy(bool newStatus) { +// if (newStatus != g_commitAsLazy) { +// g_commitAsLazy = newStatus; +// if (!newStatus && g_BooFactory) { +// g_BooFactory->commitPendingTransaction(); +// } +// } +// } +// +// static void CommitResources(const boo::FactoryCommitFunc& commitFunc __BooTraceArgs) { +// CommitResources(commitFunc __BooTraceArgsUse, g_commitAsLazy); +// } +// +// static void CommitResources(const boo::FactoryCommitFunc& commitFunc __BooTraceArgs, bool lazy) { +// if (!g_BooFactory) { +// return; +// } +// if (lazy) { +// g_BooFactory->lazyCommitTransaction(commitFunc __BooTraceArgsUse); +// } else { +// g_BooFactory->commitTransaction(commitFunc __BooTraceArgsUse); +// } +// } +// +// static void SetShaderDataBinding(const boo::ObjToken& binding) { +// g_BooMainCommandQueue->setShaderDataBinding(binding); +// } static void ResolveSpareTexture(const SClipScreenRect& rect, int bindIdx = 0, bool clearDepth = false) { - boo::SWindowRect wrect = {rect.x4_left, rect.x8_top, rect.xc_width, rect.x10_height}; - g_BooMainCommandQueue->resolveBindTexture(g_SpareTexture, wrect, true, bindIdx, true, false, clearDepth); + aurora::shaders::resolve_color({rect.x4_left, rect.x8_top, rect.xc_width, rect.x10_height}, bindIdx, clearDepth); +// boo::SWindowRect wrect = {rect.x4_left, rect.x8_top, rect.xc_width, rect.x10_height}; +// g_BooMainCommandQueue->resolveBindTexture(g_SpareTexture, wrect, true, bindIdx, true, false, clearDepth); } static void ResolveSpareDepth(const SClipScreenRect& rect, int bindIdx = 0) { - boo::SWindowRect wrect = {rect.x4_left, rect.x8_top, rect.xc_width, rect.x10_height}; - g_BooMainCommandQueue->resolveBindTexture(g_SpareTexture, wrect, true, bindIdx, false, true); + aurora::shaders::resolve_depth({rect.x4_left, rect.x8_top, rect.xc_width, rect.x10_height}, bindIdx); +// boo::SWindowRect wrect = {rect.x4_left, rect.x8_top, rect.xc_width, rect.x10_height}; +// g_BooMainCommandQueue->resolveBindTexture(g_SpareTexture, wrect, true, bindIdx, false, true); } - static void DrawInstances(size_t start, size_t count, size_t instCount, size_t startInst = 0) { - g_BooMainCommandQueue->drawInstances(start, count, instCount, startInst); - } - static void DrawArray(size_t start, size_t count) { g_BooMainCommandQueue->draw(start, count); } - static void DrawArrayIndexed(size_t start, size_t count) { g_BooMainCommandQueue->drawIndexed(start, count); } +// static void DrawInstances(size_t start, size_t count, size_t instCount, size_t startInst = 0) { +// g_BooMainCommandQueue->drawInstances(start, count, instCount, startInst); +// } +// static void DrawArray(size_t start, size_t count) { g_BooMainCommandQueue->draw(start, count); } +// static void DrawArrayIndexed(size_t start, size_t count) { g_BooMainCommandQueue->drawIndexed(start, count); } static const CTevCombiners::CTevPass sTevPass805a564c; static const CTevCombiners::CTevPass sTevPass805a5698; @@ -441,7 +495,7 @@ public: m_vec.emplace_back(std::forward<_Args>(args)...); } - void Draw() const { CGraphics::DrawArray(m_start, m_vec.size() - m_start); } +// void Draw() const { CGraphics::DrawArray(m_start, m_vec.size() - m_start); } }; #ifdef BOO_GRAPHICS_DEBUG_GROUPS diff --git a/Runtime/Graphics/CLineRenderer.cpp b/Runtime/Graphics/CLineRenderer.cpp index 036ce7b63..1c3f6c1ef 100644 --- a/Runtime/Graphics/CLineRenderer.cpp +++ b/Runtime/Graphics/CLineRenderer.cpp @@ -11,48 +11,16 @@ void CLineRenderer::Initialize() { CLineRendererShaders::Initialize(); } void CLineRenderer::Shutdown() { CLineRendererShaders::Shutdown(); - s_vertPoolTex.doDestroy(); - s_vertPoolNoTex.doDestroy(); - s_uniformPool.doDestroy(); +// s_vertPoolTex.doDestroy(); +// s_vertPoolNoTex.doDestroy(); +// s_uniformPool.doDestroy(); } -hecl::VertexBufferPool CLineRenderer::s_vertPoolTex = {}; -hecl::VertexBufferPool CLineRenderer::s_vertPoolNoTex = {}; -hecl::UniformBufferPool CLineRenderer::s_uniformPool = {}; +//hecl::VertexBufferPool CLineRenderer::s_vertPoolTex = {}; +//hecl::VertexBufferPool CLineRenderer::s_vertPoolNoTex = {}; +//hecl::UniformBufferPool CLineRenderer::s_uniformPool = {}; -CLineRenderer::CLineRenderer(boo::IGraphicsDataFactory::Context& ctx, EPrimitiveMode mode, u32 maxVerts, - const boo::ObjToken& texture, bool additive, bool zTest, bool zGEqual) -: m_mode(mode), m_maxVerts(maxVerts) { - OPTICK_EVENT(); - if (maxVerts < 2) { - LineRendererLog.report(logvisor::Fatal, FMT_STRING("maxVerts < 2, maxVerts = {}"), maxVerts); - return; - } - m_textured = bool(texture); - - u32 maxTriVerts = 0; - switch (mode) { - case EPrimitiveMode::Lines: - case EPrimitiveMode::LineStrip: - maxTriVerts = maxVerts * 4; - break; - case EPrimitiveMode::LineLoop: - maxTriVerts = maxVerts * 4 + 4; - break; - } - - if (texture) { - m_vertBufTex = s_vertPoolTex.allocateBlock(CGraphics::g_BooFactory, maxTriVerts); - } else { - m_vertBufNoTex = s_vertPoolNoTex.allocateBlock(CGraphics::g_BooFactory, maxTriVerts); - } - - m_uniformBuf = s_uniformPool.allocateBlock(CGraphics::g_BooFactory); - - CLineRendererShaders::BuildShaderDataBinding(ctx, *this, texture, additive, zTest, zGEqual); -} - -CLineRenderer::CLineRenderer(EPrimitiveMode mode, u32 maxVerts, const boo::ObjToken& texture, +CLineRenderer::CLineRenderer(EPrimitiveMode mode, u32 maxVerts, const std::shared_ptr& texture, bool additive, bool zTest, bool zGEqual) : m_mode(mode), m_maxVerts(maxVerts) { OPTICK_EVENT(); @@ -73,22 +41,22 @@ CLineRenderer::CLineRenderer(EPrimitiveMode mode, u32 maxVerts, const boo::ObjTo break; } - if (texture) { - m_vertBufTex = s_vertPoolTex.allocateBlock(CGraphics::g_BooFactory, maxTriVerts); - } else { - m_vertBufNoTex = s_vertPoolNoTex.allocateBlock(CGraphics::g_BooFactory, maxTriVerts); - } - - m_uniformBuf = s_uniformPool.allocateBlock(CGraphics::g_BooFactory); - - CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) { - CLineRendererShaders::BuildShaderDataBinding(ctx, *this, texture, additive, zTest, zGEqual); - return true; - } BooTrace); +// if (texture) { +// m_vertBufTex = s_vertPoolTex.allocateBlock(CGraphics::g_BooFactory, maxTriVerts); +// } else { +// m_vertBufNoTex = s_vertPoolNoTex.allocateBlock(CGraphics::g_BooFactory, maxTriVerts); +// } +// +// m_uniformBuf = s_uniformPool.allocateBlock(CGraphics::g_BooFactory); +// +// CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) { +// CLineRendererShaders::BuildShaderDataBinding(ctx, *this, texture, additive, zTest, zGEqual); +// return true; +// } BooTrace); } -rstl::reserved_vector CLineRenderer::g_StaticLineVertsTex = {}; -rstl::reserved_vector CLineRenderer::g_StaticLineVertsNoTex = {}; +//rstl::reserved_vector CLineRenderer::g_StaticLineVertsTex = {}; +//rstl::reserved_vector CLineRenderer::g_StaticLineVertsNoTex = {}; static bool IntersectLines(const zeus::CVector2f& pa1, const zeus::CVector2f& pa2, const zeus::CVector2f& pb1, const zeus::CVector2f& pb2, zeus::CVector3f& intersect) { @@ -106,15 +74,15 @@ static bool IntersectLines(const zeus::CVector2f& pa1, const zeus::CVector2f& pa void CLineRenderer::Reset() { m_nextVert = 0; m_final = false; - if (m_textured) - g_StaticLineVertsTex.clear(); - else - g_StaticLineVertsNoTex.clear(); +// if (m_textured) +// g_StaticLineVertsTex.clear(); +// else +// g_StaticLineVertsNoTex.clear(); } void CLineRenderer::AddVertex(const zeus::CVector3f& position, const zeus::CColor& color, float width, const zeus::CVector2f& uv) { - if (m_final || !m_shaderBind[0] || m_nextVert >= m_maxVerts) + if (m_final /*|| !m_shaderBind[0]*/ || m_nextVert >= m_maxVerts) return; float adjWidth = width / 480.f; @@ -150,13 +118,13 @@ void CLineRenderer::AddVertex(const zeus::CVector3f& position, const zeus::CColo if (m_textured) { if (m_mode == EPrimitiveMode::Lines) { if (m_nextVert & 1) { - g_StaticLineVertsTex.push_back(g_StaticLineVertsTex.back()); - g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(m_lastPos + dvb, m_lastW), m_lastColor, m_lastUV}); - g_StaticLineVertsTex.push_back(g_StaticLineVertsTex.back()); - g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(m_lastPos - dvb, m_lastW), m_lastColor, m_lastUV}); +// g_StaticLineVertsTex.push_back(g_StaticLineVertsTex.back()); +// g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(m_lastPos + dvb, m_lastW), m_lastColor, m_lastUV}); +// g_StaticLineVertsTex.push_back(g_StaticLineVertsTex.back()); +// g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(m_lastPos - dvb, m_lastW), m_lastColor, m_lastUV}); } else { - g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(m_lastPos + dva, m_lastW), m_lastColor, m_lastUV}); - g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(m_lastPos - dva, m_lastW), m_lastColor, m_lastUV}); +// g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(m_lastPos + dva, m_lastW), m_lastColor, m_lastUV}); +// g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(m_lastPos - dva, m_lastW), m_lastColor, m_lastUV}); } } else { zeus::CVector3f intersect1; @@ -174,25 +142,25 @@ void CLineRenderer::AddVertex(const zeus::CVector3f& position, const zeus::CColo if (good1 && good2) { intersect1.z() = float(m_lastPos.z()); intersect2.z() = float(m_lastPos.z()); - g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(intersect1, m_lastW), m_lastColor, m_lastUV}); - g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(intersect2, m_lastW), m_lastColor, m_lastUV}); +// g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(intersect1, m_lastW), m_lastColor, m_lastUV}); +// g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(intersect2, m_lastW), m_lastColor, m_lastUV}); } else { - g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(m_lastPos + dva, m_lastW), m_lastColor, m_lastUV}); - g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(m_lastPos - dva, m_lastW), m_lastColor, m_lastUV}); - g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(m_lastPos + dvb, m_lastW), m_lastColor, m_lastUV}); - g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(m_lastPos - dvb, m_lastW), m_lastColor, m_lastUV}); +// g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(m_lastPos + dva, m_lastW), m_lastColor, m_lastUV}); +// g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(m_lastPos - dva, m_lastW), m_lastColor, m_lastUV}); +// g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(m_lastPos + dvb, m_lastW), m_lastColor, m_lastUV}); +// g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(m_lastPos - dvb, m_lastW), m_lastColor, m_lastUV}); } } } else { if (m_mode == EPrimitiveMode::Lines) { if (m_nextVert & 1) { - g_StaticLineVertsNoTex.push_back(g_StaticLineVertsNoTex.back()); - g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(m_lastPos + dvb, m_lastW), m_lastColor}); - g_StaticLineVertsNoTex.push_back(g_StaticLineVertsNoTex.back()); - g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(m_lastPos - dvb, m_lastW), m_lastColor}); +// g_StaticLineVertsNoTex.push_back(g_StaticLineVertsNoTex.back()); +// g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(m_lastPos + dvb, m_lastW), m_lastColor}); +// g_StaticLineVertsNoTex.push_back(g_StaticLineVertsNoTex.back()); +// g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(m_lastPos - dvb, m_lastW), m_lastColor}); } else { - g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(m_lastPos + dva, m_lastW), m_lastColor}); - g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(m_lastPos - dva, m_lastW), m_lastColor}); +// g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(m_lastPos + dva, m_lastW), m_lastColor}); +// g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(m_lastPos - dva, m_lastW), m_lastColor}); } } else { zeus::CVector3f intersect1; @@ -210,13 +178,13 @@ void CLineRenderer::AddVertex(const zeus::CVector3f& position, const zeus::CColo if (good1 && good2) { intersect1.z() = float(m_lastPos.z()); intersect2.z() = float(m_lastPos.z()); - g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(intersect1, m_lastW), m_lastColor}); - g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(intersect2, m_lastW), m_lastColor}); +// g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(intersect1, m_lastW), m_lastColor}); +// g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(intersect2, m_lastW), m_lastColor}); } else { - g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(m_lastPos + dva, m_lastW), m_lastColor}); - g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(m_lastPos - dva, m_lastW), m_lastColor}); - g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(m_lastPos + dvb, m_lastW), m_lastColor}); - g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(m_lastPos - dvb, m_lastW), m_lastColor}); +// g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(m_lastPos + dva, m_lastW), m_lastColor}); +// g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(m_lastPos - dva, m_lastW), m_lastColor}); +// g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(m_lastPos + dvb, m_lastW), m_lastColor}); +// g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(m_lastPos - dvb, m_lastW), m_lastColor}); } } } @@ -227,11 +195,11 @@ void CLineRenderer::AddVertex(const zeus::CVector3f& position, const zeus::CColo dv = dv.normalized().perpendicularVector() * m_lastWidth; dv.x() /= CGraphics::g_ProjAspect; if (m_textured) { - g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(m_lastPos + dv, m_lastW), m_lastColor, m_lastUV}); - g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(m_lastPos - dv, m_lastW), m_lastColor, m_lastUV}); +// g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(m_lastPos + dv, m_lastW), m_lastColor, m_lastUV}); +// g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(m_lastPos - dv, m_lastW), m_lastColor, m_lastUV}); } else { - g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(m_lastPos + dv, m_lastW), m_lastColor}); - g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(m_lastPos - dv, m_lastW), m_lastColor}); +// g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(m_lastPos + dv, m_lastW), m_lastColor}); +// g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(m_lastPos - dv, m_lastW), m_lastColor}); } } @@ -278,25 +246,25 @@ void CLineRenderer::Render(bool alphaWrite, const zeus::CColor& moduColor) { if (good1 && good2) { intersect1.z() = float(m_lastPos.z()); intersect2.z() = float(m_lastPos.z()); - g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(intersect1, m_lastW), m_lastColor, m_lastUV}); - g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(intersect2, m_lastW), m_lastColor, m_lastUV}); +// g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(intersect1, m_lastW), m_lastColor, m_lastUV}); +// g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(intersect2, m_lastW), m_lastColor, m_lastUV}); } else { - g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(m_lastPos + dva, m_lastW), m_lastColor, m_lastUV}); - g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(m_lastPos - dva, m_lastW), m_lastColor, m_lastUV}); - g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(m_lastPos + dvb, m_lastW), m_lastColor, m_lastUV}); - g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(m_lastPos - dvb, m_lastW), m_lastColor, m_lastUV}); +// g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(m_lastPos + dva, m_lastW), m_lastColor, m_lastUV}); +// g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(m_lastPos - dva, m_lastW), m_lastColor, m_lastUV}); +// g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(m_lastPos + dvb, m_lastW), m_lastColor, m_lastUV}); +// g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(m_lastPos - dvb, m_lastW), m_lastColor, m_lastUV}); } } else { if (good1 && good2) { intersect1.z() = float(m_lastPos.z()); intersect2.z() = float(m_lastPos.z()); - g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(intersect1, m_lastW), m_lastColor}); - g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(intersect2, m_lastW), m_lastColor}); +// g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(intersect1, m_lastW), m_lastColor}); +// g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(intersect2, m_lastW), m_lastColor}); } else { - g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(m_lastPos + dva, m_lastW), m_lastColor}); - g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(m_lastPos - dva, m_lastW), m_lastColor}); - g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(m_lastPos + dvb, m_lastW), m_lastColor}); - g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(m_lastPos - dvb, m_lastW), m_lastColor}); +// g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(m_lastPos + dva, m_lastW), m_lastColor}); +// g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(m_lastPos - dva, m_lastW), m_lastColor}); +// g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(m_lastPos + dvb, m_lastW), m_lastColor}); +// g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(m_lastPos - dvb, m_lastW), m_lastColor}); } } } @@ -329,25 +297,25 @@ void CLineRenderer::Render(bool alphaWrite, const zeus::CColor& moduColor) { if (good1 && good2) { intersect1.z() = float(m_firstPos.z()); intersect2.z() = float(m_firstPos.z()); - g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(intersect1, m_lastW), m_lastColor, m_lastUV}); - g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(intersect2, m_lastW), m_lastColor, m_lastUV}); +// g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(intersect1, m_lastW), m_lastColor, m_lastUV}); +// g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(intersect2, m_lastW), m_lastColor, m_lastUV}); } else { - g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(m_firstPos + dva, m_lastW), m_lastColor, m_lastUV}); - g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(m_firstPos - dva, m_lastW), m_lastColor, m_lastUV}); - g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(m_firstPos + dvb, m_lastW), m_lastColor, m_lastUV}); - g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(m_firstPos - dvb, m_lastW), m_lastColor, m_lastUV}); +// g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(m_firstPos + dva, m_lastW), m_lastColor, m_lastUV}); +// g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(m_firstPos - dva, m_lastW), m_lastColor, m_lastUV}); +// g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(m_firstPos + dvb, m_lastW), m_lastColor, m_lastUV}); +// g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(m_firstPos - dvb, m_lastW), m_lastColor, m_lastUV}); } } else { if (good1 && good2) { intersect1.z() = float(m_firstPos.z()); intersect2.z() = float(m_firstPos.z()); - g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(intersect1, m_lastW), m_lastColor}); - g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(intersect2, m_lastW), m_lastColor}); +// g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(intersect1, m_lastW), m_lastColor}); +// g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(intersect2, m_lastW), m_lastColor}); } else { - g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(m_firstPos + dva, m_lastW), m_lastColor}); - g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(m_firstPos - dva, m_lastW), m_lastColor}); - g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(m_firstPos + dvb, m_lastW), m_lastColor}); - g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(m_firstPos - dvb, m_lastW), m_lastColor}); +// g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(m_firstPos + dva, m_lastW), m_lastColor}); +// g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(m_firstPos - dva, m_lastW), m_lastColor}); +// g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(m_firstPos + dvb, m_lastW), m_lastColor}); +// g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(m_firstPos - dvb, m_lastW), m_lastColor}); } } } @@ -360,14 +328,14 @@ void CLineRenderer::Render(bool alphaWrite, const zeus::CColor& moduColor) { if (m_textured) { if (m_mode == EPrimitiveMode::Lines && (m_nextVert & 1)) { } else { - g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(m_lastPos + dv, m_lastW), m_lastColor, m_lastUV}); - g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(m_lastPos - dv, m_lastW), m_lastColor, m_lastUV}); +// g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(m_lastPos + dv, m_lastW), m_lastColor, m_lastUV}); +// g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(m_lastPos - dv, m_lastW), m_lastColor, m_lastUV}); } } else { if (m_mode == EPrimitiveMode::Lines && (m_nextVert & 1)) { } else { - g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(m_lastPos + dv, m_lastW), m_lastColor}); - g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(m_lastPos - dv, m_lastW), m_lastColor}); +// g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(m_lastPos + dv, m_lastW), m_lastColor}); +// g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(m_lastPos - dv, m_lastW), m_lastColor}); } } } @@ -375,21 +343,21 @@ void CLineRenderer::Render(bool alphaWrite, const zeus::CColor& moduColor) { m_final = true; } - m_uniformBuf.access() = SDrawUniform{moduColor, CGraphics::g_Fog}; - if (m_textured) { - if (!g_StaticLineVertsTex.empty()) { - memmove(m_vertBufTex.access(), g_StaticLineVertsTex.data(), sizeof(SDrawVertTex) * g_StaticLineVertsTex.size()); - CGraphics::SetShaderDataBinding(m_shaderBind[alphaWrite]); - CGraphics::DrawArray(0, g_StaticLineVertsTex.size()); - } - } else { - if (!g_StaticLineVertsNoTex.empty()) { - memmove(m_vertBufNoTex.access(), g_StaticLineVertsNoTex.data(), - sizeof(SDrawVertNoTex) * g_StaticLineVertsNoTex.size()); - CGraphics::SetShaderDataBinding(m_shaderBind[alphaWrite]); - CGraphics::DrawArray(0, g_StaticLineVertsNoTex.size()); - } - } +// m_uniformBuf.access() = SDrawUniform{moduColor, CGraphics::g_Fog}; +// if (m_textured) { +// if (!g_StaticLineVertsTex.empty()) { +// memmove(m_vertBufTex.access(), g_StaticLineVertsTex.data(), sizeof(SDrawVertTex) * g_StaticLineVertsTex.size()); +// CGraphics::SetShaderDataBinding(m_shaderBind[alphaWrite]); +// CGraphics::DrawArray(0, g_StaticLineVertsTex.size()); +// } +// } else { +// if (!g_StaticLineVertsNoTex.empty()) { +// memmove(m_vertBufNoTex.access(), g_StaticLineVertsNoTex.data(), +// sizeof(SDrawVertNoTex) * g_StaticLineVertsNoTex.size()); +// CGraphics::SetShaderDataBinding(m_shaderBind[alphaWrite]); +// CGraphics::DrawArray(0, g_StaticLineVertsNoTex.size()); +// } +// } } } // namespace metaforce diff --git a/Runtime/Graphics/CLineRenderer.hpp b/Runtime/Graphics/CLineRenderer.hpp index 924ce30d8..bc3b88f0f 100644 --- a/Runtime/Graphics/CLineRenderer.hpp +++ b/Runtime/Graphics/CLineRenderer.hpp @@ -6,10 +6,10 @@ #include "Runtime/rstl.hpp" #include "Runtime/Graphics/CGraphics.hpp" -#include +//#include -#include -#include +//#include +//#include #include #include @@ -59,22 +59,20 @@ private: float m_lastWidth; float m_lastW; - static rstl::reserved_vector g_StaticLineVertsTex; - static rstl::reserved_vector g_StaticLineVertsNoTex; +// static rstl::reserved_vector g_StaticLineVertsTex; +// static rstl::reserved_vector g_StaticLineVertsNoTex; - static hecl::VertexBufferPool s_vertPoolTex; - static hecl::VertexBufferPool s_vertPoolNoTex; - static hecl::UniformBufferPool s_uniformPool; +// static hecl::VertexBufferPool s_vertPoolTex; +// static hecl::VertexBufferPool s_vertPoolNoTex; +// static hecl::UniformBufferPool s_uniformPool; public: - hecl::VertexBufferPool::Token m_vertBufTex; - hecl::VertexBufferPool::Token m_vertBufNoTex; - hecl::UniformBufferPool::Token m_uniformBuf; - std::array, 2> m_shaderBind; +// hecl::VertexBufferPool::Token m_vertBufTex; +// hecl::VertexBufferPool::Token m_vertBufNoTex; +// hecl::UniformBufferPool::Token m_uniformBuf; +// std::array, 2> m_shaderBind; - CLineRenderer(boo::IGraphicsDataFactory::Context& ctx, EPrimitiveMode mode, u32 maxVerts, - const boo::ObjToken& texture, bool additive, bool zTest = false, bool zGEqual = false); - CLineRenderer(EPrimitiveMode mode, u32 maxVerts, const boo::ObjToken& texture, bool additive, + CLineRenderer(EPrimitiveMode mode, u32 maxVerts, const std::shared_ptr& texture, bool additive, bool zTest = false, bool zGEqual = false); CLineRenderer(CLineRenderer&&) = default; @@ -83,11 +81,11 @@ public: const zeus::CVector2f& uv = zeus::skZero2f); void Render(bool alphaWrite = false, const zeus::CColor& moduColor = zeus::skWhite); - static void UpdateBuffers() { - s_vertPoolTex.updateBuffers(); - s_vertPoolNoTex.updateBuffers(); - s_uniformPool.updateBuffers(); - } +// static void UpdateBuffers() { +// s_vertPoolTex.updateBuffers(); +// s_vertPoolNoTex.updateBuffers(); +// s_uniformPool.updateBuffers(); +// } static void Initialize(); static void Shutdown(); diff --git a/Runtime/Graphics/CMakeLists.txt b/Runtime/Graphics/CMakeLists.txt index 7938a5f3e..99e3979bf 100644 --- a/Runtime/Graphics/CMakeLists.txt +++ b/Runtime/Graphics/CMakeLists.txt @@ -1,6 +1,7 @@ set(GRAPHICS_SOURCES IRenderer.hpp IWeaponRenderer.hpp IWeaponRenderer.cpp + CCubeModel.cpp CCubeModel.hpp CBooRenderer.hpp CBooRenderer.cpp CDrawable.hpp CDrawablePlaneObject.hpp diff --git a/Runtime/Graphics/CMetroidModelInstance.hpp b/Runtime/Graphics/CMetroidModelInstance.hpp index 9bedb439d..cf0a52f30 100644 --- a/Runtime/Graphics/CMetroidModelInstance.hpp +++ b/Runtime/Graphics/CMetroidModelInstance.hpp @@ -27,7 +27,7 @@ class CMetroidModelInstance { std::vector m_surfaces; std::unique_ptr m_instance; hecl::HMDLMeta m_hmdlMeta; - std::unordered_map m_shaders; +// std::unordered_map m_shaders; public: CMetroidModelInstance() = default; @@ -39,7 +39,7 @@ public: m_surfaces.clear(); m_instance.reset(); m_hmdlMeta = {}; - m_shaders.clear(); +// m_shaders.clear(); } }; diff --git a/Runtime/Graphics/CModel.hpp b/Runtime/Graphics/CModel.hpp index 40f808ae3..71d9cfab9 100644 --- a/Runtime/Graphics/CModel.hpp +++ b/Runtime/Graphics/CModel.hpp @@ -9,11 +9,10 @@ #include "DataSpec/DNAMP1/CMDLMaterials.hpp" #include "Runtime/CFactoryMgr.hpp" #include "Runtime/CToken.hpp" -#include "Runtime/RetroTypes.hpp" #include "Runtime/Graphics/CTexture.hpp" #include "Runtime/Graphics/Shaders/CModelShaders.hpp" +#include "Runtime/RetroTypes.hpp" -#include #include #include #include @@ -80,42 +79,42 @@ struct CBooSurface { using MaterialSet = DataSpec::DNAMP1::HMDLMaterialSet; -struct GeometryUniformLayout { - mutable std::vector> m_sharedBuffer; - size_t m_geomBufferSize = 0; - size_t m_skinBankCount = 0; - size_t m_weightVecCount = 0; - - std::vector m_skinOffs; - std::vector m_skinSizes; - - std::vector m_uvOffs; - std::vector m_uvSizes; - - GeometryUniformLayout(const CModel* model, const MaterialSet* matSet); - void Update(const CModelFlags& flags, const CSkinRules* cskr, const CPoseAsTransforms* pose, - const MaterialSet* matSet, const boo::ObjToken& buf, - const CBooModel* parent) const; - - void ReserveSharedBuffers(boo::IGraphicsDataFactory::Context& ctx, int size); - boo::ObjToken GetSharedBuffer(int idx) const; -}; +//struct GeometryUniformLayout { +// mutable std::vector> m_sharedBuffer; +// size_t m_geomBufferSize = 0; +// size_t m_skinBankCount = 0; +// size_t m_weightVecCount = 0; +// +// std::vector m_skinOffs; +// std::vector m_skinSizes; +// +// std::vector m_uvOffs; +// std::vector m_uvSizes; +// +// GeometryUniformLayout(const CModel* model, const MaterialSet* matSet); +// void Update(const CModelFlags& flags, const CSkinRules* cskr, const CPoseAsTransforms* pose, +// const MaterialSet* matSet, const boo::ObjToken& buf, +// const CBooModel* parent) const; +// +// void ReserveSharedBuffers(boo::IGraphicsDataFactory::Context& ctx, int size); +// boo::ObjToken GetSharedBuffer(int idx) const; +//}; struct SShader { std::unordered_map> x0_textures; - std::unordered_map m_shaders; +// std::unordered_map m_shaders; MaterialSet m_matSet; - std::optional m_geomLayout; +// std::optional m_geomLayout; int m_matSetIdx; explicit SShader(int idx) : m_matSetIdx(idx) { x0_textures.clear(); - m_shaders.clear(); +// m_shaders.clear(); } - void InitializeLayout(const CModel* model) { m_geomLayout.emplace(model, &m_matSet); } +// void InitializeLayout(const CModel* model) { m_geomLayout.emplace(model, &m_matSet); } void UnlockTextures(); - CModelShaders::ShaderPipelines BuildShader(const hecl::HMDLMeta& meta, const MaterialSet::Material& mat); - void BuildShaders(const hecl::HMDLMeta& meta, std::unordered_map& shaders); - void BuildShaders(const hecl::HMDLMeta& meta) { BuildShaders(meta, m_shaders); } +// CModelShaders::ShaderPipelines BuildShader(const hecl::HMDLMeta& meta, const MaterialSet::Material& mat); +// void BuildShaders(const hecl::HMDLMeta& meta, std::unordered_map& shaders); +// void BuildShaders(const hecl::HMDLMeta& meta) { BuildShaders(meta, m_shaders); } }; class CBooModel { @@ -137,9 +136,9 @@ private: CModel* m_model; std::vector* x0_surfaces; const MaterialSet* x4_matSet; - const GeometryUniformLayout* m_geomLayout; +// const GeometryUniformLayout* m_geomLayout; int m_matSetIdx = -1; - const std::unordered_map* m_pipelines; +// const std::unordered_map* m_pipelines; std::unordered_map> x1c_textures; zeus::CAABox x20_aabb; CBooSurface* x38_firstUnsortedSurface = nullptr; @@ -158,26 +157,26 @@ private: CModelShaders::LightingUniform m_lightingData; /* metaforce addition: boo! */ - size_t m_uniformDataSize = 0; - struct ModelInstance { - boo::ObjToken m_geomUniformBuffer; - boo::ObjToken m_uniformBuffer; - std::vector>> m_shaderDataBindings; - boo::ObjToken m_dynamicVbo; +// size_t m_uniformDataSize = 0; +// struct ModelInstance { +// boo::ObjToken m_geomUniformBuffer; +// boo::ObjToken m_uniformBuffer; +// std::vector>> m_shaderDataBindings; +// boo::ObjToken m_dynamicVbo; +// +// boo::ObjToken GetBooVBO(const CBooModel& model, boo::IGraphicsDataFactory::Context& ctx); +// }; +// std::vector m_instances; +// ModelInstance m_ballShadowInstance; - boo::ObjToken GetBooVBO(const CBooModel& model, boo::IGraphicsDataFactory::Context& ctx); - }; - std::vector m_instances; - ModelInstance m_ballShadowInstance; +// boo::ObjToken m_staticVbo; +// boo::ObjToken m_staticIbo; +// +// boo::ObjToken m_lastDrawnShadowMap; +// boo::ObjToken m_lastDrawnOneTexture; +// boo::ObjToken m_lastDrawnReflectionCube; - boo::ObjToken m_staticVbo; - boo::ObjToken m_staticIbo; - - boo::ObjToken m_lastDrawnShadowMap; - boo::ObjToken m_lastDrawnOneTexture; - boo::ObjToken m_lastDrawnReflectionCube; - - ModelInstance* PushNewModelInstance(int sharedLayoutBuf = -1, boo::IGraphicsDataFactory::Context* ctx = nullptr); +// ModelInstance* PushNewModelInstance(int sharedLayoutBuf = -1, boo::IGraphicsDataFactory::Context* ctx = nullptr); void DrawAlphaSurfaces(const CModelFlags& flags) const; void DrawNormalSurfaces(const CModelFlags& flags) const; void DrawSurfaces(const CModelFlags& flags) const; @@ -197,8 +196,9 @@ private: public: ~CBooModel(); CBooModel(TToken& token, CModel* parent, std::vector* surfaces, SShader& shader, - const boo::ObjToken& vbo, const boo::ObjToken& ibo, - const zeus::CAABox& aabb, u8 renderMask, int numInsts); + // TODO +// boo::ObjToken vbo, boo::ObjToken ibo, + const zeus::CAABox& aabb, u8 renderMask); static void MakeTexturesFromMats(const MaterialSet& matSet, std::unordered_map>& toksOut, IObjectStore& store); @@ -209,15 +209,13 @@ public: void SetAmbientColor(const zeus::CColor& color) { m_lightingData.ambient = color; } void DisableAllLights(); void RemapMaterialData(SShader& shader); - void RemapMaterialData(SShader& shader, const std::unordered_map& pipelines); bool TryLockTextures(); void UnlockTextures(); void SyncLoadTextures(); void Touch(int shaderIdx); void VerifyCurrentShader(int shaderIdx); - boo::ObjToken UpdateUniformData(const CModelFlags& flags, const CSkinRules* cskr, - const CPoseAsTransforms* pose, int sharedLayoutBuf = -1, - boo::IGraphicsDataFactory::Context* ctx = nullptr); +// boo::ObjToken UpdateUniformData(const CModelFlags& flags, const CSkinRules* cskr, +// const CPoseAsTransforms* pose, int sharedLayoutBuf = -1); void DrawAlpha(const CModelFlags& flags, const CSkinRules* cskr, const CPoseAsTransforms* pose); void DrawNormal(const CModelFlags& flags, const CSkinRules* cskr, const CPoseAsTransforms* pose); void Draw(const CModelFlags& flags, const CSkinRules* cskr, const CPoseAsTransforms* pose); @@ -241,16 +239,16 @@ public: static void EnsureViewDepStateCached(const CBooModel& model, const CBooSurface* surf, zeus::CMatrix4f* mtxsOut, float& alphaOut); - static inline boo::ObjToken g_shadowMap; + static inline std::shared_ptr g_shadowMap; static inline zeus::CTransform g_shadowTexXf; - static void EnableShadowMaps(const boo::ObjToken& map, const zeus::CTransform& texXf); + static void EnableShadowMaps(const std::shared_ptr& map, const zeus::CTransform& texXf); static void DisableShadowMaps(); - static inline boo::ObjToken g_disintegrateTexture; - static void SetDisintegrateTexture(const boo::ObjToken& map) { g_disintegrateTexture = map; } + static inline std::shared_ptr g_disintegrateTexture; + static void SetDisintegrateTexture(const std::shared_ptr& map) { g_disintegrateTexture = map; } - static inline boo::ObjToken g_reflectionCube; - static void SetReflectionCube(const boo::ObjToken& map) { g_reflectionCube = map; } + static inline std::shared_ptr g_reflectionCube; + static void SetReflectionCube(const std::shared_ptr& map) { g_reflectionCube = map; } static void SetDummyTextures(bool b) { g_DummyTextures = b; } static void SetRenderModelBlack(bool b) { g_RenderModelBlack = b; } @@ -276,10 +274,10 @@ class CModel { int x38_lastFrame; /* metaforce addition: boo! */ - boo::ObjToken m_staticVbo; +// boo::ObjToken m_staticVbo; hecl::HMDLMeta m_hmdlMeta; std::unique_ptr m_dynamicVertexData; - boo::ObjToken m_ibo; +// boo::ObjToken m_ibo; public: using MaterialSet = DataSpec::DNAMP1::HMDLMaterialSet; @@ -294,7 +292,7 @@ public: const zeus::CAABox& GetAABB() const { return m_aabb; } CBooModel& GetInstance() { return *x28_modelInst; } const CBooModel& GetInstance() const { return *x28_modelInst; } - std::unique_ptr MakeNewInstance(int shaderIdx, int subInsts, bool lockParent = true); + std::unique_ptr MakeNewInstance(int shaderIdx, bool lockParent = true); void UpdateLastFrame() const { const_cast(*this).x38_lastFrame = CGraphics::GetFrameCounter(); } u32 GetNumMaterialSets() const { return x18_matSets.size(); } @@ -302,9 +300,9 @@ public: zeus::CVector3f GetPoolVertex(size_t idx) const; size_t GetPoolNormalOffset(size_t idx) const; zeus::CVector3f GetPoolNormal(size_t idx) const; - void ApplyVerticesCPU(const boo::ObjToken& vertBuf, - const std::vector>& vn) const; - void RestoreVerticesCPU(const boo::ObjToken& vertBuf) const; +// void ApplyVerticesCPU(const boo::ObjToken& vertBuf, +// const std::vector>& vn) const; +// void RestoreVerticesCPU(const boo::ObjToken& vertBuf) const; void _WarmupShaders(); static void WarmupShaders(const SObjectTag& cmdlTag); diff --git a/Runtime/Graphics/CModelBoo.cpp b/Runtime/Graphics/CModelBoo.cpp index 46b6039df..63f063e9d 100644 --- a/Runtime/Graphics/CModelBoo.cpp +++ b/Runtime/Graphics/CModelBoo.cpp @@ -11,11 +11,11 @@ #include -#include #include #include #include #include +#include namespace metaforce { namespace { @@ -125,17 +125,17 @@ void CBooModel::EnsureViewDepStateCached(const CBooModel& model, const CBooSurfa mtxsOut[1][3][0] = -surfPos.dot(v2) * f1 + 0.5f; mtxsOut[1][2][1] = f2; mtxsOut[1][3][1] = -modelToPlayerLocal.z() * f2; - switch (CGraphics::g_BooPlatform) { - case boo::IGraphicsDataFactory::Platform::OpenGL: - mtxsOut[1] = ReflectPostGL * mtxsOut[1]; - break; - default: - break; - } +// switch (CGraphics::g_BooPlatform) { +// case boo::IGraphicsDataFactory::Platform::OpenGL: +// mtxsOut[1] = ReflectPostGL * mtxsOut[1]; +// break; +// default: +// break; +// } } } -void CBooModel::EnableShadowMaps(const boo::ObjToken& map, const zeus::CTransform& texXf) { +void CBooModel::EnableShadowMaps(const std::shared_ptr& map, const zeus::CTransform& texXf) { g_shadowMap = map; g_shadowTexXf = texXf; } @@ -151,20 +151,21 @@ CBooModel::~CBooModel() { } CBooModel::CBooModel(TToken& token, CModel* parent, std::vector* surfaces, SShader& shader, - const boo::ObjToken& vbo, const boo::ObjToken& ibo, - const zeus::CAABox& aabb, u8 renderMask, int numInsts) +// boo::ObjToken vbo, boo::ObjToken ibo, + const zeus::CAABox& aabb, u8 renderMask) : m_modelTok(token) , m_model(parent) , x0_surfaces(surfaces) , x4_matSet(&shader.m_matSet) -, m_geomLayout(&*shader.m_geomLayout) +//, m_geomLayout(&*shader.m_geomLayout) , m_matSetIdx(shader.m_matSetIdx) -, m_pipelines(&shader.m_shaders) +//, m_pipelines(&shader.m_shaders) , x1c_textures(shader.x0_textures) , x20_aabb(aabb) , x41_mask(renderMask) -, m_staticVbo(vbo) -, m_staticIbo(ibo) { +//, m_staticVbo(std::move(vbo)) +//, m_staticIbo(std::move(ibo)) +{ if (!g_FirstModel) g_FirstModel = this; else { @@ -188,229 +189,221 @@ CBooModel::CBooModel(TToken& token, CModel* parent, std::vector CBooModel::ModelInstance::GetBooVBO(const CBooModel& model, - boo::IGraphicsDataFactory::Context& ctx) { - if (model.m_staticVbo) - return model.m_staticVbo.get(); - if (!m_dynamicVbo && model.m_model) { - const CModel& parent = *model.m_model; - m_dynamicVbo = - ctx.newDynamicBuffer(boo::BufferUse::Vertex, parent.m_hmdlMeta.vertStride, parent.m_hmdlMeta.vertCount); - m_dynamicVbo->load(parent.m_dynamicVertexData.get(), parent.m_hmdlMeta.vertStride * parent.m_hmdlMeta.vertCount); - } - return m_dynamicVbo.get(); -} +//boo::ObjToken CBooModel::ModelInstance::GetBooVBO(const CBooModel& model, +// boo::IGraphicsDataFactory::Context& ctx) { +// if (model.m_staticVbo) +// return model.m_staticVbo.get(); +// if (!m_dynamicVbo && model.m_model) { +// const CModel& parent = *model.m_model; +// m_dynamicVbo = +// ctx.newDynamicBuffer(boo::BufferUse::Vertex, parent.m_hmdlMeta.vertStride, parent.m_hmdlMeta.vertCount); +// m_dynamicVbo->load(parent.m_dynamicVertexData.get(), parent.m_hmdlMeta.vertStride * parent.m_hmdlMeta.vertCount); +// } +// return m_dynamicVbo.get(); +//} -GeometryUniformLayout::GeometryUniformLayout(const CModel* model, const MaterialSet* matSet) { - if (model) { - m_skinBankCount = model->m_hmdlMeta.bankCount; - m_weightVecCount = model->m_hmdlMeta.weightCount; - } +//GeometryUniformLayout::GeometryUniformLayout(const CModel* model, const MaterialSet* matSet) { +// if (model) { +// m_skinBankCount = model->m_hmdlMeta.bankCount; +// m_weightVecCount = model->m_hmdlMeta.weightCount; +// } +// +// m_skinOffs.reserve(std::max(size_t(1), m_skinBankCount)); +// m_skinSizes.reserve(std::max(size_t(1), m_skinBankCount)); +// +// m_uvOffs.reserve(matSet->materials.size()); +// m_uvSizes.reserve(matSet->materials.size()); +// +// if (m_skinBankCount) { +// /* Skinned */ +// for (size_t i = 0; i < m_skinBankCount; ++i) { +// size_t thisSz = ROUND_UP_256(sizeof(zeus::CMatrix4f) * (2 * m_weightVecCount * 4 + 3)); +// m_skinOffs.push_back(m_geomBufferSize); +// m_skinSizes.push_back(thisSz); +// m_geomBufferSize += thisSz; +// } +// } else { +// /* Non-Skinned */ +// size_t thisSz = ROUND_UP_256(sizeof(zeus::CMatrix4f) * 3); +// m_skinOffs.push_back(m_geomBufferSize); +// m_skinSizes.push_back(thisSz); +// m_geomBufferSize += thisSz; +// } +// +// /* Animated UV transform matrices */ +// for (const MaterialSet::Material& mat : matSet->materials) { +// (void)mat; +// size_t thisSz = ROUND_UP_256(/*mat.uvAnims.size()*/ 8 * (sizeof(zeus::CMatrix4f) * 2)); +// m_uvOffs.push_back(m_geomBufferSize); +// m_uvSizes.push_back(thisSz); +// m_geomBufferSize += thisSz; +// } +//} - m_skinOffs.reserve(std::max(size_t(1), m_skinBankCount)); - m_skinSizes.reserve(std::max(size_t(1), m_skinBankCount)); - - m_uvOffs.reserve(matSet->materials.size()); - m_uvSizes.reserve(matSet->materials.size()); - - if (m_skinBankCount) { - /* Skinned */ - for (size_t i = 0; i < m_skinBankCount; ++i) { - size_t thisSz = ROUND_UP_256(sizeof(zeus::CMatrix4f) * (2 * m_weightVecCount * 4 + 3)); - m_skinOffs.push_back(m_geomBufferSize); - m_skinSizes.push_back(thisSz); - m_geomBufferSize += thisSz; - } - } else { - /* Non-Skinned */ - size_t thisSz = ROUND_UP_256(sizeof(zeus::CMatrix4f) * 3); - m_skinOffs.push_back(m_geomBufferSize); - m_skinSizes.push_back(thisSz); - m_geomBufferSize += thisSz; - } - - /* Animated UV transform matrices */ - for (const MaterialSet::Material& mat : matSet->materials) { - (void)mat; - size_t thisSz = ROUND_UP_256(/*mat.uvAnims.size()*/ 8 * (sizeof(zeus::CMatrix4f) * 2)); - m_uvOffs.push_back(m_geomBufferSize); - m_uvSizes.push_back(thisSz); - m_geomBufferSize += thisSz; - } -} - -CBooModel::ModelInstance* CBooModel::PushNewModelInstance(int sharedLayoutBuf, - boo::IGraphicsDataFactory::Context* ctx) { - OPTICK_EVENT(); - if (!x40_24_texturesLoaded && !g_DummyTextures) { - return nullptr; - } - - if (m_instances.size() >= 512) { - Log.report(logvisor::Fatal, FMT_STRING("Model buffer overflow")); - } - - ModelInstance& newInst = m_instances.emplace_back(); - - auto withContext = [&](boo::IGraphicsDataFactory::Context& ctx) { - /* Build geometry uniform buffer if shared not available */ - boo::ObjToken geomUniformBuf; - if (sharedLayoutBuf >= 0) { - geomUniformBuf = m_geomLayout->GetSharedBuffer(sharedLayoutBuf); - } else { - geomUniformBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, m_geomLayout->m_geomBufferSize, 1); - newInst.m_geomUniformBuffer = geomUniformBuf; - } - - /* Lighting and reflection uniforms */ - size_t uniBufSize = 0; - - /* Lighting uniform */ - size_t lightOff = 0; - size_t lightSz = 0; - { - size_t thisSz = ROUND_UP_256(sizeof(CModelShaders::LightingUniform)); - lightOff = uniBufSize; - lightSz = thisSz; - uniBufSize += thisSz; - } - - /* Surface reflection texmatrix uniform with first identity slot */ - size_t reflectOff = uniBufSize; - uniBufSize += 256; - for (const CBooSurface& surf : *x0_surfaces) { - const MaterialSet::Material& mat = x4_matSet->materials.at(surf.m_data.matIdx); - if (mat.flags.samusReflection() || mat.flags.samusReflectionSurfaceEye()) - uniBufSize += 256; - } - - /* Allocate resident buffer */ - m_uniformDataSize = uniBufSize; - newInst.m_uniformBuffer = ctx.newDynamicBuffer(boo::BufferUse::Uniform, uniBufSize, 1); - - const std::array, 4> bufs{ - geomUniformBuf.get(), - geomUniformBuf.get(), - newInst.m_uniformBuffer.get(), - newInst.m_uniformBuffer.get(), - }; - - /* Binding for each surface */ - newInst.m_shaderDataBindings.reserve(x0_surfaces->size()); - - std::array thisOffs; - std::array thisSizes; - - static constexpr std::array stages{ - boo::PipelineStage::Vertex, - boo::PipelineStage::Vertex, - boo::PipelineStage::Fragment, - boo::PipelineStage::Vertex, - }; - - /* Enumerate surfaces and build data bindings */ - size_t curReflect = reflectOff + 256; - for (const CBooSurface& surf : *x0_surfaces) { - const MaterialSet::Material& mat = x4_matSet->materials.at(surf.m_data.matIdx); - - std::array, 12> texs{ - g_Renderer->m_clearTexture.get(), g_Renderer->m_clearTexture.get(), g_Renderer->m_clearTexture.get(), - g_Renderer->m_clearTexture.get(), g_Renderer->m_clearTexture.get(), g_Renderer->m_clearTexture.get(), - g_Renderer->m_whiteTexture.get(), g_Renderer->m_clearTexture.get(), g_Renderer->x220_sphereRamp.get(), - g_Renderer->x220_sphereRamp.get(), g_Renderer->x220_sphereRamp.get(), g_Renderer->x220_sphereRamp.get(), - }; - if (!g_DummyTextures) { - for (const auto& ch : mat.chunks) { - if (const auto* const pass = ch.get_if()) { - auto search = x1c_textures.find(pass->texId.toUint32()); - boo::ObjToken btex; - if (search != x1c_textures.cend() && (btex = search->second.GetObj()->GetBooTexture())) { - texs[MaterialSet::Material::TexMapIdx(pass->type)] = btex; - } - } else if (const auto* const pass = ch.get_if()) { - boo::ObjToken btex = g_Renderer->GetColorTexture(zeus::CColor(pass->color)); - texs[MaterialSet::Material::TexMapIdx(pass->type)] = btex; - } - } - } - - if (m_geomLayout->m_skinBankCount) { - thisOffs[0] = m_geomLayout->m_skinOffs[surf.m_data.skinMtxBankIdx]; - thisSizes[0] = m_geomLayout->m_skinSizes[surf.m_data.skinMtxBankIdx]; - } else { - thisOffs[0] = 0; - thisSizes[0] = 256; - } - - thisOffs[1] = m_geomLayout->m_uvOffs[surf.m_data.matIdx]; - thisSizes[1] = m_geomLayout->m_uvSizes[surf.m_data.matIdx]; - - thisOffs[2] = lightOff; - thisSizes[2] = lightSz; - - bool useReflection = mat.flags.samusReflection() || mat.flags.samusReflectionSurfaceEye(); - if (useReflection) { - if (g_Renderer->x14c_reflectionTex) - texs[11] = g_Renderer->x14c_reflectionTex.get(); - thisOffs[3] = curReflect; - curReflect += 256; - } else { - thisOffs[3] = reflectOff; - } - thisSizes[3] = 256; - - const CModelShaders::ShaderPipelines& pipelines = m_pipelines->at(surf.m_data.matIdx); - - std::vector>& extendeds = newInst.m_shaderDataBindings.emplace_back(); - extendeds.reserve(pipelines->size()); - - EExtendedShader idx{}; - for (const auto& pipeline : *pipelines) { - if (idx == EExtendedShader::ThermalModel || idx == EExtendedShader::ThermalModelNoZTestNoZWrite || - idx == EExtendedShader::ThermalStatic || idx == EExtendedShader::ThermalStaticNoZWrite) { - texs[8] = g_Renderer->x220_sphereRamp.get(); - } else if (idx == EExtendedShader::MorphBallShadow) { - texs[8] = g_Renderer->m_ballShadowId.get(); - texs[9] = g_Renderer->x220_sphereRamp.get(); - texs[10] = g_Renderer->m_ballFade.get(); - } else if (idx == EExtendedShader::WorldShadow || idx == EExtendedShader::LightingCubeReflectionWorldShadow) { - if (g_shadowMap) - texs[8] = g_shadowMap; - else - texs[8] = g_Renderer->x220_sphereRamp.get(); - } else if (idx == EExtendedShader::Disintegrate) { - if (g_disintegrateTexture) - texs[8] = g_disintegrateTexture; - else - texs[8] = g_Renderer->x220_sphereRamp.get(); - } else if (hecl::com_cubemaps->toBoolean() && (idx == EExtendedShader::LightingCubeReflection || - idx == EExtendedShader::LightingCubeReflectionWorldShadow)) { - if (m_lastDrawnReflectionCube) - texs[11] = m_lastDrawnReflectionCube.get(); - else - texs[11] = g_Renderer->x220_sphereRamp.get(); - } - extendeds.push_back(ctx.newShaderDataBinding( - pipeline, newInst.GetBooVBO(*this, ctx), nullptr, m_staticIbo.get(), bufs.size(), bufs.data(), - stages.data(), thisOffs.data(), thisSizes.data(), texs.size(), texs.data(), nullptr, nullptr)); - idx = EExtendedShader(size_t(idx) + 1); - } - } - return true; - }; - - if (ctx) { - withContext(*ctx); - } else { - CGraphics::CommitResources(withContext BooTrace); - } - return &newInst; -} +//CBooModel::ModelInstance* CBooModel::PushNewModelInstance(int sharedLayoutBuf, +// boo::IGraphicsDataFactory::Context* ctx) { +// OPTICK_EVENT(); +// if (!x40_24_texturesLoaded && !g_DummyTextures) { +// return nullptr; +// } +// +// if (m_instances.size() >= 512) { +// Log.report(logvisor::Fatal, FMT_STRING("Model buffer overflow")); +// } +// +// ModelInstance& newInst = m_instances.emplace_back(); +// +// /* Build geometry uniform buffer if shared not available */ +// boo::ObjToken geomUniformBuf; +// if (sharedLayoutBuf >= 0) { +// geomUniformBuf = m_geomLayout->GetSharedBuffer(sharedLayoutBuf); +// } else { +// geomUniformBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, m_geomLayout->m_geomBufferSize, 1); +// newInst.m_geomUniformBuffer = geomUniformBuf; +// } +// +// /* Lighting and reflection uniforms */ +// size_t uniBufSize = 0; +// +// /* Lighting uniform */ +// size_t lightOff = 0; +// size_t lightSz = 0; +// { +// size_t thisSz = ROUND_UP_256(sizeof(CModelShaders::LightingUniform)); +// lightOff = uniBufSize; +// lightSz = thisSz; +// uniBufSize += thisSz; +// } +// +// /* Surface reflection texmatrix uniform with first identity slot */ +// size_t reflectOff = uniBufSize; +// uniBufSize += 256; +// for (const CBooSurface& surf : *x0_surfaces) { +// const MaterialSet::Material& mat = x4_matSet->materials.at(surf.m_data.matIdx); +// if (mat.flags.samusReflection() || mat.flags.samusReflectionSurfaceEye()) +// uniBufSize += 256; +// } +// +// /* Allocate resident buffer */ +// m_uniformDataSize = uniBufSize; +// newInst.m_uniformBuffer = ctx.newDynamicBuffer(boo::BufferUse::Uniform, uniBufSize, 1); +// +// const std::array, 4> bufs{ +// geomUniformBuf.get(), +// geomUniformBuf.get(), +// newInst.m_uniformBuffer.get(), +// newInst.m_uniformBuffer.get(), +// }; +// +// /* Binding for each surface */ +// newInst.m_shaderDataBindings.reserve(x0_surfaces->size()); +// +// std::array thisOffs; +// std::array thisSizes; +// +// static constexpr std::array stages{ +// boo::PipelineStage::Vertex, +// boo::PipelineStage::Vertex, +// boo::PipelineStage::Fragment, +// boo::PipelineStage::Vertex, +// }; +// +// /* Enumerate surfaces and build data bindings */ +// size_t curReflect = reflectOff + 256; +// for (const CBooSurface& surf : *x0_surfaces) { +// const MaterialSet::Material& mat = x4_matSet->materials.at(surf.m_data.matIdx); +// +// std::array, 12> texs{ +// g_Renderer->m_clearTexture.get(), g_Renderer->m_clearTexture.get(), g_Renderer->m_clearTexture.get(), +// g_Renderer->m_clearTexture.get(), g_Renderer->m_clearTexture.get(), g_Renderer->m_clearTexture.get(), +// g_Renderer->m_whiteTexture.get(), g_Renderer->m_clearTexture.get(), g_Renderer->x220_sphereRamp.get(), +// g_Renderer->x220_sphereRamp.get(), g_Renderer->x220_sphereRamp.get(), g_Renderer->x220_sphereRamp.get(), +// }; +// if (!g_DummyTextures) { +// for (const auto& ch : mat.chunks) { +// if (const auto* const pass = ch.get_if()) { +// auto search = x1c_textures.find(pass->texId.toUint32()); +// boo::ObjToken btex; +// if (search != x1c_textures.cend() && (btex = search->second.GetObj()->GetBooTexture())) { +// texs[MaterialSet::Material::TexMapIdx(pass->type)] = btex; +// } +// } else if (const auto* const pass = ch.get_if()) { +// boo::ObjToken btex = g_Renderer->GetColorTexture(zeus::CColor(pass->color)); +// texs[MaterialSet::Material::TexMapIdx(pass->type)] = btex; +// } +// } +// } +// +// if (m_geomLayout->m_skinBankCount) { +// thisOffs[0] = m_geomLayout->m_skinOffs[surf.m_data.skinMtxBankIdx]; +// thisSizes[0] = m_geomLayout->m_skinSizes[surf.m_data.skinMtxBankIdx]; +// } else { +// thisOffs[0] = 0; +// thisSizes[0] = 256; +// } +// +// thisOffs[1] = m_geomLayout->m_uvOffs[surf.m_data.matIdx]; +// thisSizes[1] = m_geomLayout->m_uvSizes[surf.m_data.matIdx]; +// +// thisOffs[2] = lightOff; +// thisSizes[2] = lightSz; +// +// bool useReflection = mat.flags.samusReflection() || mat.flags.samusReflectionSurfaceEye(); +// if (useReflection) { +// if (g_Renderer->x14c_reflectionTex) +// texs[11] = g_Renderer->x14c_reflectionTex.get(); +// thisOffs[3] = curReflect; +// curReflect += 256; +// } else { +// thisOffs[3] = reflectOff; +// } +// thisSizes[3] = 256; +// +// const CModelShaders::ShaderPipelines& pipelines = m_pipelines->at(surf.m_data.matIdx); +// +// std::vector>& extendeds = newInst.m_shaderDataBindings.emplace_back(); +// extendeds.reserve(pipelines->size()); +// +// EExtendedShader idx{}; +// for (const auto& pipeline : *pipelines) { +// if (idx == EExtendedShader::ThermalModel || idx == EExtendedShader::ThermalModelNoZTestNoZWrite || +// idx == EExtendedShader::ThermalStatic || idx == EExtendedShader::ThermalStaticNoZWrite) { +// texs[8] = g_Renderer->x220_sphereRamp.get(); +// } else if (idx == EExtendedShader::MorphBallShadow) { +// texs[8] = g_Renderer->m_ballShadowId.get(); +// texs[9] = g_Renderer->x220_sphereRamp.get(); +// texs[10] = g_Renderer->m_ballFade.get(); +// } else if (idx == EExtendedShader::WorldShadow || idx == EExtendedShader::LightingCubeReflectionWorldShadow) { +// if (g_shadowMap) +// texs[8] = g_shadowMap; +// else +// texs[8] = g_Renderer->x220_sphereRamp.get(); +// } else if (idx == EExtendedShader::Disintegrate) { +// if (g_disintegrateTexture) +// texs[8] = g_disintegrateTexture; +// else +// texs[8] = g_Renderer->x220_sphereRamp.get(); +// } else if (hecl::com_cubemaps->toBoolean() && (idx == EExtendedShader::LightingCubeReflection || +// idx == EExtendedShader::LightingCubeReflectionWorldShadow)) { +// if (m_lastDrawnReflectionCube) +// texs[11] = m_lastDrawnReflectionCube.get(); +// else +// texs[11] = g_Renderer->x220_sphereRamp.get(); +// } +// extendeds.push_back(ctx.newShaderDataBinding( +// pipeline, newInst.GetBooVBO(*this, ctx), nullptr, m_staticIbo.get(), bufs.size(), bufs.data(), +// stages.data(), thisOffs.data(), thisSizes.data(), texs.size(), texs.data(), nullptr, nullptr)); +// idx = EExtendedShader(size_t(idx) + 1); +// } +// } +// +// return &newInst; +//} void CBooModel::MakeTexturesFromMats(const MaterialSet& matSet, std::unordered_map>& toksOut, @@ -443,28 +436,12 @@ void CBooModel::DisableAllLights() { } void CBooModel::RemapMaterialData(SShader& shader) { - if (!shader.m_geomLayout) - return; + // TODO what is this checking? +// if (!shader.m_geomLayout) +// return; x4_matSet = &shader.m_matSet; - m_geomLayout = &*shader.m_geomLayout; - m_matSetIdx = shader.m_matSetIdx; x1c_textures = shader.x0_textures; - m_pipelines = &shader.m_shaders; x40_24_texturesLoaded = false; - m_instances.clear(); -} - -void CBooModel::RemapMaterialData(SShader& shader, - const std::unordered_map& pipelines) { - if (!shader.m_geomLayout) - return; - x4_matSet = &shader.m_matSet; - m_geomLayout = &*shader.m_geomLayout; - m_matSetIdx = shader.m_matSetIdx; - x1c_textures = shader.x0_textures; - m_pipelines = &pipelines; - x40_24_texturesLoaded = false; - m_instances.clear(); } bool CBooModel::TryLockTextures() { @@ -477,19 +454,20 @@ bool CBooModel::TryLockTextures() { } } - if (allLoad) { - for (const auto& pipeline : *m_pipelines) { - for (const auto& subpipeline : *pipeline.second) { - if (!subpipeline->isReady()) { - allLoad = false; - break; - } - } - if (!allLoad) { - break; - } - } - } + // TODO +// if (allLoad) { +// for (const auto& pipeline : *m_pipelines) { +// for (const auto& subpipeline : *pipeline.second) { +// if (!subpipeline->isReady()) { +// allLoad = false; +// break; +// } +// } +// if (!allLoad) { +// break; +// } +// } +// } x40_24_texturesLoaded = allLoad; } @@ -498,7 +476,7 @@ bool CBooModel::TryLockTextures() { } void CBooModel::UnlockTextures() { - m_instances.clear(); +// m_instances.clear(); for (auto& tex : x1c_textures) { tex.second.Unlock(); @@ -641,22 +619,20 @@ static EExtendedShader ResolveExtendedShader(const MaterialSet::Material& data, } void CBooModel::DrawSurface(const CBooSurface& surf, const CModelFlags& flags) const { - // if (m_uniUpdateCount == 0) - // Log.report(logvisor::Fatal, FMT_STRING("UpdateUniformData() not called")); - if (m_uniUpdateCount == 0 || m_uniUpdateCount > m_instances.size()) - return; - const ModelInstance& inst = m_instances[m_uniUpdateCount - 1]; - - const MaterialSet::Material& data = GetMaterialByIndex(surf.m_data.matIdx); - if (data.flags.shadowOccluderMesh() && !g_DrawingOccluders) - return; - - const std::vector>& extendeds = inst.m_shaderDataBindings[surf.selfIdx]; - EExtendedShader extended = ResolveExtendedShader(data, flags); - - boo::ObjToken binding = extendeds[size_t(extended)]; - CGraphics::SetShaderDataBinding(binding); - CGraphics::DrawArrayIndexed(surf.m_data.idxStart, surf.m_data.idxCount); +// if (m_uniUpdateCount == 0 || m_uniUpdateCount > m_instances.size()) +// return; +// const ModelInstance& inst = m_instances[m_uniUpdateCount - 1]; +// +// const MaterialSet::Material& data = GetMaterialByIndex(surf.m_data.matIdx); +// if (data.flags.shadowOccluderMesh() && !g_DrawingOccluders) +// return; +// +// const std::vector>& extendeds = inst.m_shaderDataBindings[surf.selfIdx]; +// EExtendedShader extended = ResolveExtendedShader(data, flags); +// +// boo::ObjToken binding = extendeds[size_t(extended)]; +// CGraphics::SetShaderDataBinding(binding); +// CGraphics::DrawArrayIndexed(surf.m_data.idxStart, surf.m_data.idxCount); } void CBooModel::WarmupDrawSurfaces() const { @@ -674,14 +650,14 @@ void CBooModel::WarmupDrawSurfaces() const { } void CBooModel::WarmupDrawSurface(const CBooSurface& surf) const { - if (m_uniUpdateCount > m_instances.size()) - return; - const ModelInstance& inst = m_instances[m_uniUpdateCount - 1]; - - for (const auto& binding : inst.m_shaderDataBindings[surf.selfIdx]) { - CGraphics::SetShaderDataBinding(binding); - CGraphics::DrawArrayIndexed(surf.m_data.idxStart, std::min(u32(3), surf.m_data.idxCount)); - } +// if (m_uniUpdateCount > m_instances.size()) +// return; +// const ModelInstance& inst = m_instances[m_uniUpdateCount - 1]; +// +// for (const auto& binding : inst.m_shaderDataBindings[surf.selfIdx]) { +// CGraphics::SetShaderDataBinding(binding); +// CGraphics::DrawArrayIndexed(surf.m_data.idxStart, std::min(u32(3), surf.m_data.idxCount)); +// } } void CBooModel::UVAnimationBuffer::ProcessAnimation(u8*& bufOut, const MaterialSet::Material::PASS& anim) { @@ -873,224 +849,223 @@ void CBooModel::UVAnimationBuffer::Update(u8*& bufOut, const MaterialSet* matSet } } -void GeometryUniformLayout::Update(const CModelFlags& flags, const CSkinRules* cskr, const CPoseAsTransforms* pose, - const MaterialSet* matSet, const boo::ObjToken& buf, - const CBooModel* parent) const { - u8* dataOut = reinterpret_cast(buf->map(m_geomBufferSize)); - u8* dataCur = dataOut; +//void GeometryUniformLayout::Update(const CModelFlags& flags, const CSkinRules* cskr, const CPoseAsTransforms* pose, +// const MaterialSet* matSet, const boo::ObjToken& buf, +// const CBooModel* parent) const { +// u8* dataOut = reinterpret_cast(buf->map(m_geomBufferSize)); +// u8* dataCur = dataOut; +// +// if (m_skinBankCount) { +// /* Skinned */ +// std::vector bankTransforms; +// size_t weightCount = m_weightVecCount * 4; +// bankTransforms.reserve(weightCount); +// for (size_t i = 0; i < m_skinBankCount; ++i) { +// if (cskr && pose) { +// cskr->GetBankTransforms(bankTransforms, *pose, i); +// +// for (size_t w = 0; w < weightCount; ++w) { +// zeus::CMatrix4f& obj = reinterpret_cast(*dataCur); +// if (w >= bankTransforms.size()) +// obj = zeus::CMatrix4f(); +// else +// obj = bankTransforms[w]->toMatrix4f(); +// dataCur += sizeof(zeus::CMatrix4f); +// } +// for (size_t w = 0; w < weightCount; ++w) { +// zeus::CMatrix4f& objInv = reinterpret_cast(*dataCur); +// if (w >= bankTransforms.size()) +// objInv = zeus::CMatrix4f(); +// else +// objInv = bankTransforms[w]->basis; +// dataCur += sizeof(zeus::CMatrix4f); +// } +// +// bankTransforms.clear(); +// } else { +// for (size_t w = 0; w < weightCount; ++w) { +// zeus::CMatrix4f& mv = reinterpret_cast(*dataCur); +// mv = zeus::CMatrix4f(); +// dataCur += sizeof(zeus::CMatrix4f); +// } +// for (size_t w = 0; w < weightCount; ++w) { +// zeus::CMatrix4f& mvinv = reinterpret_cast(*dataCur); +// mvinv = zeus::CMatrix4f(); +// dataCur += sizeof(zeus::CMatrix4f); +// } +// } +// zeus::CMatrix4f& mv = reinterpret_cast(*dataCur); +// mv = CGraphics::g_GXModelView.toMatrix4f(); +// dataCur += sizeof(zeus::CMatrix4f); +// +// zeus::CMatrix4f& mvinv = reinterpret_cast(*dataCur); +// mvinv = CGraphics::g_GXModelViewInvXpose.toMatrix4f(); +// dataCur += sizeof(zeus::CMatrix4f); +// +// zeus::CMatrix4f& proj = reinterpret_cast(*dataCur); +// proj = CGraphics::GetPerspectiveProjectionMatrix(true); +// dataCur += sizeof(zeus::CMatrix4f); +// +// dataCur = dataOut + ROUND_UP_256(dataCur - dataOut); +// } +// } else { +// /* Non-Skinned */ +// zeus::CMatrix4f& mv = reinterpret_cast(*dataCur); +// mv = CGraphics::g_GXModelView.toMatrix4f(); +// dataCur += sizeof(zeus::CMatrix4f); +// +// zeus::CMatrix4f& mvinv = reinterpret_cast(*dataCur); +// mvinv = CGraphics::g_GXModelViewInvXpose.toMatrix4f(); +// dataCur += sizeof(zeus::CMatrix4f); +// +// zeus::CMatrix4f& proj = reinterpret_cast(*dataCur); +// proj = CGraphics::GetPerspectiveProjectionMatrix(true); +// dataCur += sizeof(zeus::CMatrix4f); +// +// dataCur = dataOut + ROUND_UP_256(dataCur - dataOut); +// } +// +// CBooModel::UVAnimationBuffer::Update(dataCur, matSet, flags, parent); +// buf->unmap(); +//} - if (m_skinBankCount) { - /* Skinned */ - std::vector bankTransforms; - size_t weightCount = m_weightVecCount * 4; - bankTransforms.reserve(weightCount); - for (size_t i = 0; i < m_skinBankCount; ++i) { - if (cskr && pose) { - cskr->GetBankTransforms(bankTransforms, *pose, i); +//void GeometryUniformLayout::ReserveSharedBuffers(boo::IGraphicsDataFactory::Context& ctx, int size) { +// if (m_sharedBuffer.size() < size) +// m_sharedBuffer.resize(size); +// for (int i = 0; i < size; ++i) { +// auto& buf = m_sharedBuffer[i]; +// if (!buf) +// buf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, m_geomBufferSize, 1); +// } +//} +// +//boo::ObjToken GeometryUniformLayout::GetSharedBuffer(int idx) const { +// if (idx >= m_sharedBuffer.size()) +// m_sharedBuffer.resize(idx + 1); +// +// auto& buf = m_sharedBuffer[idx]; +// if (!buf) { +// CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) { +// buf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, m_geomBufferSize, 1); +// return true; +// } BooTrace); +// } +// +// return buf; +//} - for (size_t w = 0; w < weightCount; ++w) { - zeus::CMatrix4f& obj = reinterpret_cast(*dataCur); - if (w >= bankTransforms.size()) - obj = zeus::CMatrix4f(); - else - obj = bankTransforms[w]->toMatrix4f(); - dataCur += sizeof(zeus::CMatrix4f); - } - for (size_t w = 0; w < weightCount; ++w) { - zeus::CMatrix4f& objInv = reinterpret_cast(*dataCur); - if (w >= bankTransforms.size()) - objInv = zeus::CMatrix4f(); - else - objInv = bankTransforms[w]->basis; - dataCur += sizeof(zeus::CMatrix4f); - } - - bankTransforms.clear(); - } else { - for (size_t w = 0; w < weightCount; ++w) { - zeus::CMatrix4f& mv = reinterpret_cast(*dataCur); - mv = zeus::CMatrix4f(); - dataCur += sizeof(zeus::CMatrix4f); - } - for (size_t w = 0; w < weightCount; ++w) { - zeus::CMatrix4f& mvinv = reinterpret_cast(*dataCur); - mvinv = zeus::CMatrix4f(); - dataCur += sizeof(zeus::CMatrix4f); - } - } - zeus::CMatrix4f& mv = reinterpret_cast(*dataCur); - mv = CGraphics::g_GXModelView.toMatrix4f(); - dataCur += sizeof(zeus::CMatrix4f); - - zeus::CMatrix4f& mvinv = reinterpret_cast(*dataCur); - mvinv = CGraphics::g_GXModelViewInvXpose.toMatrix4f(); - dataCur += sizeof(zeus::CMatrix4f); - - zeus::CMatrix4f& proj = reinterpret_cast(*dataCur); - proj = CGraphics::GetPerspectiveProjectionMatrix(true); - dataCur += sizeof(zeus::CMatrix4f); - - dataCur = dataOut + ROUND_UP_256(dataCur - dataOut); - } - } else { - /* Non-Skinned */ - zeus::CMatrix4f& mv = reinterpret_cast(*dataCur); - mv = CGraphics::g_GXModelView.toMatrix4f(); - dataCur += sizeof(zeus::CMatrix4f); - - zeus::CMatrix4f& mvinv = reinterpret_cast(*dataCur); - mvinv = CGraphics::g_GXModelViewInvXpose.toMatrix4f(); - dataCur += sizeof(zeus::CMatrix4f); - - zeus::CMatrix4f& proj = reinterpret_cast(*dataCur); - proj = CGraphics::GetPerspectiveProjectionMatrix(true); - dataCur += sizeof(zeus::CMatrix4f); - - dataCur = dataOut + ROUND_UP_256(dataCur - dataOut); - } - - CBooModel::UVAnimationBuffer::Update(dataCur, matSet, flags, parent); - buf->unmap(); -} - -void GeometryUniformLayout::ReserveSharedBuffers(boo::IGraphicsDataFactory::Context& ctx, int size) { - if (m_sharedBuffer.size() < size) - m_sharedBuffer.resize(size); - for (int i = 0; i < size; ++i) { - auto& buf = m_sharedBuffer[i]; - if (!buf) - buf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, m_geomBufferSize, 1); - } -} - -boo::ObjToken GeometryUniformLayout::GetSharedBuffer(int idx) const { - if (idx >= m_sharedBuffer.size()) - m_sharedBuffer.resize(idx + 1); - - auto& buf = m_sharedBuffer[idx]; - if (!buf) { - CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) { - buf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, m_geomBufferSize, 1); - return true; - } BooTrace); - } - - return buf; -} - -boo::ObjToken CBooModel::UpdateUniformData(const CModelFlags& flags, const CSkinRules* cskr, - const CPoseAsTransforms* pose, int sharedLayoutBuf, - boo::IGraphicsDataFactory::Context* ctx) { - OPTICK_EVENT(); - if (!g_DummyTextures && !TryLockTextures()) - return {}; - - /* Invalidate instances if new shadow being drawn */ - if ((flags.m_extendedShader == EExtendedShader::WorldShadow || - flags.m_extendedShader == EExtendedShader::LightingCubeReflectionWorldShadow) && - m_lastDrawnShadowMap != g_shadowMap) { - m_lastDrawnShadowMap = g_shadowMap; - m_instances.clear(); - } - - /* Invalidate instances if new one-texture being drawn */ - if (flags.m_extendedShader == EExtendedShader::Disintegrate && m_lastDrawnOneTexture != g_disintegrateTexture) { - m_lastDrawnOneTexture = g_disintegrateTexture; - m_instances.clear(); - } - - /* Invalidate instances if new reflection cube being drawn */ - if (hecl::com_cubemaps->toBoolean() && - (flags.m_extendedShader == EExtendedShader::LightingCubeReflection || - flags.m_extendedShader == EExtendedShader::LightingCubeReflectionWorldShadow) && - m_lastDrawnReflectionCube != g_reflectionCube) { - m_lastDrawnReflectionCube = g_reflectionCube; - m_instances.clear(); - } - - const ModelInstance* inst; - if (sharedLayoutBuf >= 0) { - if (m_instances.size() <= sharedLayoutBuf) { - do { - inst = PushNewModelInstance(m_instances.size(), ctx); - if (!inst) { - return {}; - } - } while (m_instances.size() <= sharedLayoutBuf); - } else { - inst = &m_instances[sharedLayoutBuf]; - } - m_uniUpdateCount = sharedLayoutBuf + 1; - } else { - if (m_instances.size() <= m_uniUpdateCount) { - inst = PushNewModelInstance(sharedLayoutBuf, ctx); - if (!inst) { - return {}; - } - } else { - inst = &m_instances[m_uniUpdateCount]; - } - ++m_uniUpdateCount; - } - - if (inst->m_geomUniformBuffer) { - m_geomLayout->Update(flags, cskr, pose, x4_matSet, inst->m_geomUniformBuffer, this); - } - - u8* dataOut = reinterpret_cast(inst->m_uniformBuffer->map(m_uniformDataSize)); - u8* dataCur = dataOut; - - if (flags.m_extendedShader == EExtendedShader::ThermalModel || - flags.m_extendedShader == EExtendedShader::ThermalModelNoZTestNoZWrite) /* Thermal Model (same as UV Mode 0) */ - { - CModelShaders::ThermalUniform& thermalOut = *reinterpret_cast(dataCur); - thermalOut.mulColor = flags.x4_color; - thermalOut.addColor = flags.addColor; - } else if (flags.m_extendedShader >= EExtendedShader::SolidColor && - flags.m_extendedShader <= EExtendedShader::SolidColorBackfaceCullGreaterAlphaOnly) /* Solid color render */ - { - CModelShaders::SolidUniform& solidOut = *reinterpret_cast(dataCur); - solidOut.solidColor = flags.x4_color; - } else if (flags.m_extendedShader == EExtendedShader::MorphBallShadow) /* MorphBall shadow render */ - { - CModelShaders::MBShadowUniform& shadowOut = *reinterpret_cast(dataCur); - shadowOut.shadowUp = CGraphics::g_GXModelView.rotate(zeus::skUp); - shadowOut.shadowUp.w() = flags.x4_color.a(); - shadowOut.shadowId = flags.x4_color.r(); - } else if (flags.m_extendedShader == EExtendedShader::Disintegrate) { - CModelShaders::OneTextureUniform& oneTexOut = *reinterpret_cast(dataCur); - oneTexOut.addColor = flags.addColor; - oneTexOut.fog = CGraphics::g_Fog; - } else { - CModelShaders::LightingUniform& lightingOut = *reinterpret_cast(dataCur); - lightingOut = m_lightingData; - lightingOut.colorRegs = CGraphics::g_ColorRegs; - lightingOut.mulColor = flags.x4_color; - lightingOut.addColor = flags.addColor; - lightingOut.fog = CGraphics::g_Fog; - } - - dataCur += sizeof(CModelShaders::LightingUniform); - dataCur = dataOut + ROUND_UP_256(dataCur - dataOut); - - /* Reflection texmtx uniform */ - zeus::CMatrix4f* identMtxs = reinterpret_cast(dataCur); - identMtxs[0] = zeus::CMatrix4f(); - identMtxs[1] = zeus::CMatrix4f(); - u8* curReflect = dataCur + 256; - for (const CBooSurface& surf : *x0_surfaces) { - const MaterialSet::Material& mat = x4_matSet->materials.at(surf.m_data.matIdx); - if (mat.flags.samusReflection() || mat.flags.samusReflectionSurfaceEye()) { - zeus::CMatrix4f* mtxs = reinterpret_cast(curReflect); - float& alpha = reinterpret_cast(mtxs[2]); - curReflect += 256; - EnsureViewDepStateCached(*this, mat.flags.samusReflectionSurfaceEye() ? &surf : nullptr, mtxs, alpha); - } - } - - inst->m_uniformBuffer->unmap(); - return inst->m_dynamicVbo; -} +//boo::ObjToken CBooModel::UpdateUniformData(const CModelFlags& flags, const CSkinRules* cskr, +// const CPoseAsTransforms* pose, int sharedLayoutBuf) { +// OPTICK_EVENT(); +//// if (!g_DummyTextures && !TryLockTextures()) +// return {}; +// +//// /* Invalidate instances if new shadow being drawn */ +//// if ((flags.m_extendedShader == EExtendedShader::WorldShadow || +//// flags.m_extendedShader == EExtendedShader::LightingCubeReflectionWorldShadow) && +//// m_lastDrawnShadowMap != g_shadowMap) { +//// m_lastDrawnShadowMap = g_shadowMap; +//// m_instances.clear(); +//// } +//// +//// /* Invalidate instances if new one-texture being drawn */ +//// if (flags.m_extendedShader == EExtendedShader::Disintegrate && m_lastDrawnOneTexture != g_disintegrateTexture) { +//// m_lastDrawnOneTexture = g_disintegrateTexture; +//// m_instances.clear(); +//// } +//// +//// /* Invalidate instances if new reflection cube being drawn */ +//// if (hecl::com_cubemaps->toBoolean() && +//// (flags.m_extendedShader == EExtendedShader::LightingCubeReflection || +//// flags.m_extendedShader == EExtendedShader::LightingCubeReflectionWorldShadow) && +//// m_lastDrawnReflectionCube != g_reflectionCube) { +//// m_lastDrawnReflectionCube = g_reflectionCube; +//// m_instances.clear(); +//// } +// +//// const ModelInstance* inst; +//// if (sharedLayoutBuf >= 0) { +//// if (m_instances.size() <= sharedLayoutBuf) { +//// do { +//// inst = PushNewModelInstance(m_instances.size(), ctx); +//// if (!inst) { +//// return {}; +//// } +//// } while (m_instances.size() <= sharedLayoutBuf); +//// } else { +//// inst = &m_instances[sharedLayoutBuf]; +//// } +//// m_uniUpdateCount = sharedLayoutBuf + 1; +//// } else { +//// if (m_instances.size() <= m_uniUpdateCount) { +//// inst = PushNewModelInstance(sharedLayoutBuf, ctx); +//// if (!inst) { +//// return {}; +//// } +//// } else { +//// inst = &m_instances[m_uniUpdateCount]; +//// } +//// ++m_uniUpdateCount; +//// } +//// +//// if (inst->m_geomUniformBuffer) { +//// m_geomLayout->Update(flags, cskr, pose, x4_matSet, inst->m_geomUniformBuffer, this); +//// } +//// +//// u8* dataOut = reinterpret_cast(inst->m_uniformBuffer->map(m_uniformDataSize)); +//// u8* dataCur = dataOut; +//// +//// if (flags.m_extendedShader == EExtendedShader::ThermalModel || +//// flags.m_extendedShader == EExtendedShader::ThermalModelNoZTestNoZWrite) /* Thermal Model (same as UV Mode 0) */ +//// { +//// CModelShaders::ThermalUniform& thermalOut = *reinterpret_cast(dataCur); +//// thermalOut.mulColor = flags.x4_color; +//// thermalOut.addColor = flags.addColor; +//// } else if (flags.m_extendedShader >= EExtendedShader::SolidColor && +//// flags.m_extendedShader <= EExtendedShader::SolidColorBackfaceCullGreaterAlphaOnly) /* Solid color render */ +//// { +//// CModelShaders::SolidUniform& solidOut = *reinterpret_cast(dataCur); +//// solidOut.solidColor = flags.x4_color; +//// } else if (flags.m_extendedShader == EExtendedShader::MorphBallShadow) /* MorphBall shadow render */ +//// { +//// CModelShaders::MBShadowUniform& shadowOut = *reinterpret_cast(dataCur); +//// shadowOut.shadowUp = CGraphics::g_GXModelView.rotate(zeus::skUp); +//// shadowOut.shadowUp.w() = flags.x4_color.a(); +//// shadowOut.shadowId = flags.x4_color.r(); +//// } else if (flags.m_extendedShader == EExtendedShader::Disintegrate) { +//// CModelShaders::OneTextureUniform& oneTexOut = *reinterpret_cast(dataCur); +//// oneTexOut.addColor = flags.addColor; +//// oneTexOut.fog = CGraphics::g_Fog; +//// } else { +//// CModelShaders::LightingUniform& lightingOut = *reinterpret_cast(dataCur); +//// lightingOut = m_lightingData; +//// lightingOut.colorRegs = CGraphics::g_ColorRegs; +//// lightingOut.mulColor = flags.x4_color; +//// lightingOut.addColor = flags.addColor; +//// lightingOut.fog = CGraphics::g_Fog; +//// } +//// +//// dataCur += sizeof(CModelShaders::LightingUniform); +//// dataCur = dataOut + ROUND_UP_256(dataCur - dataOut); +//// +//// /* Reflection texmtx uniform */ +//// zeus::CMatrix4f* identMtxs = reinterpret_cast(dataCur); +//// identMtxs[0] = zeus::CMatrix4f(); +//// identMtxs[1] = zeus::CMatrix4f(); +//// u8* curReflect = dataCur + 256; +//// for (const CBooSurface& surf : *x0_surfaces) { +//// const MaterialSet::Material& mat = x4_matSet->materials.at(surf.m_data.matIdx); +//// if (mat.flags.samusReflection() || mat.flags.samusReflectionSurfaceEye()) { +//// zeus::CMatrix4f* mtxs = reinterpret_cast(curReflect); +//// float& alpha = reinterpret_cast(mtxs[2]); +//// curReflect += 256; +//// EnsureViewDepStateCached(*this, mat.flags.samusReflectionSurfaceEye() ? &surf : nullptr, mtxs, alpha); +//// } +//// } +//// +//// inst->m_uniformBuffer->unmap(); +//// return inst->m_dynamicVbo; +//} void CBooModel::DrawAlpha(const CModelFlags& flags, const CSkinRules* cskr, const CPoseAsTransforms* pose) { CModelFlags rFlags = flags; @@ -1101,7 +1076,8 @@ void CBooModel::DrawAlpha(const CModelFlags& flags, const CSkinRules* cskr, cons } if (TryLockTextures()) { - UpdateUniformData(rFlags, cskr, pose); + // TODO? +// UpdateUniformData(rFlags, cskr, pose); DrawAlphaSurfaces(rFlags); } } @@ -1114,7 +1090,8 @@ void CBooModel::DrawNormal(const CModelFlags& flags, const CSkinRules* cskr, con rFlags.x4_color = zeus::skBlack; } if (TryLockTextures()) { - UpdateUniformData(rFlags, cskr, pose); + // TODO? +// UpdateUniformData(rFlags, cskr, pose); DrawNormalSurfaces(rFlags); } } @@ -1128,7 +1105,8 @@ void CBooModel::Draw(const CModelFlags& flags, const CSkinRules* cskr, const CPo } if (TryLockTextures()) { - UpdateUniformData(rFlags, cskr, pose); + // TODO? +// UpdateUniformData(rFlags, cskr, pose); DrawSurfaces(rFlags); } } @@ -1145,37 +1123,37 @@ static const u8* MemoryFromPartData(const u8*& dataCur, const u32*& secSizeCur) return ret; } -std::unique_ptr CModel::MakeNewInstance(int shaderIdx, int subInsts, bool lockParent) { +std::unique_ptr CModel::MakeNewInstance(int shaderIdx, bool lockParent) { if (shaderIdx >= x18_matSets.size()) shaderIdx = 0; - auto ret = std::make_unique(m_selfToken, this, &x8_surfaces, x18_matSets[shaderIdx], m_staticVbo, m_ibo, - m_aabb, (m_flags & 0x2) != 0, subInsts); + auto ret = std::make_unique(m_selfToken, this, &x8_surfaces, x18_matSets[shaderIdx], //m_staticVbo, m_ibo, + m_aabb, (m_flags & 0x2) != 0); if (lockParent) ret->LockParent(); return ret; } -CModelShaders::ShaderPipelines SShader::BuildShader(const hecl::HMDLMeta& meta, const MaterialSet::Material& mat) { - OPTICK_EVENT(); - hecl::Backend::ReflectionType reflectionType; - if (mat.flags.samusReflectionIndirectTexture()) - reflectionType = hecl::Backend::ReflectionType::Indirect; - else if (mat.flags.samusReflection() || mat.flags.samusReflectionSurfaceEye()) - reflectionType = hecl::Backend::ReflectionType::Simple; - else - reflectionType = hecl::Backend::ReflectionType::None; - hecl::Backend::ShaderTag tag(mat.hash, meta.colorCount, meta.uvCount, meta.weightCount, meta.weightCount * 4, - boo::Primitive(meta.topology), reflectionType, true, true, true, mat.flags.alphaTest()); - return CModelShaders::BuildExtendedShader(tag, mat); -} - -void SShader::BuildShaders(const hecl::HMDLMeta& meta, - std::unordered_map& shaders) { - shaders.reserve(m_matSet.materials.size()); - int idx = 0; - for (const MaterialSet::Material& mat : m_matSet.materials) - shaders[idx++] = BuildShader(meta, mat); -} +//CModelShaders::ShaderPipelines SShader::BuildShader(const hecl::HMDLMeta& meta, const MaterialSet::Material& mat) { +// OPTICK_EVENT(); +// hecl::Backend::ReflectionType reflectionType; +// if (mat.flags.samusReflectionIndirectTexture()) +// reflectionType = hecl::Backend::ReflectionType::Indirect; +// else if (mat.flags.samusReflection() || mat.flags.samusReflectionSurfaceEye()) +// reflectionType = hecl::Backend::ReflectionType::Simple; +// else +// reflectionType = hecl::Backend::ReflectionType::None; +// hecl::Backend::ShaderTag tag(mat.hash, meta.colorCount, meta.uvCount, meta.weightCount, meta.weightCount * 4, +// boo::Primitive(meta.topology), reflectionType, true, true, true, mat.flags.alphaTest()); +// return CModelShaders::BuildExtendedShader(tag, mat); +//} +// +//void SShader::BuildShaders(const hecl::HMDLMeta& meta, +// std::unordered_map& shaders) { +// shaders.reserve(m_matSet.materials.size()); +// int idx = 0; +// for (const MaterialSet::Material& mat : m_matSet.materials) +// shaders[idx++] = BuildShader(meta, mat); +//} CModel::CModel(std::unique_ptr&& in, u32 /* dataLen */, IObjectStore* store, CObjectReference* selfRef) : m_selfToken(selfRef) { @@ -1184,8 +1162,10 @@ CModel::CModel(std::unique_ptr&& in, u32 /* dataLen */, IObjectStore* stor u32 version = hecl::SBig(*reinterpret_cast(data.get() + 0x4)); m_flags = hecl::SBig(*reinterpret_cast(data.get() + 0x8)); - if (version != 0x10002) - Log.report(logvisor::Fatal, FMT_STRING("invalid CMDL for loading with boo")); + if (version != 0x10002) { + Log.report(logvisor::Error, FMT_STRING("invalid CMDL for loading with boo")); + return; + } u32 secCount = hecl::SBig(*reinterpret_cast(data.get() + 0x24)); u32 matSetCount = hecl::SBig(*reinterpret_cast(data.get() + 0x28)); @@ -1212,31 +1192,31 @@ CModel::CModel(std::unique_ptr&& in, u32 /* dataLen */, IObjectStore* stor const u8* iboData = MemoryFromPartData(dataCur, secSizeCur); const u8* surfInfo = MemoryFromPartData(dataCur, secSizeCur); - for (SShader& matSet : x18_matSets) { - matSet.InitializeLayout(this); - matSet.BuildShaders(m_hmdlMeta); - } +// for (SShader& matSet : x18_matSets) { +// matSet.InitializeLayout(this); +// matSet.BuildShaders(m_hmdlMeta); +// } - CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) { - /* Index buffer is always static */ - if (m_hmdlMeta.indexCount) - m_ibo = ctx.newStaticBuffer(boo::BufferUse::Index, iboData, 4, m_hmdlMeta.indexCount); - - if (!m_hmdlMeta.bankCount) { - /* Non-skinned models use static vertex buffers shared with CBooModel instances */ - if (m_hmdlMeta.vertCount) - m_staticVbo = ctx.newStaticBuffer(boo::BufferUse::Vertex, vboData, m_hmdlMeta.vertStride, m_hmdlMeta.vertCount); - } else { - /* Skinned models use per-instance dynamic buffers for vertex manipulation effects */ - size_t vboSz = m_hmdlMeta.vertStride * m_hmdlMeta.vertCount; - if (vboSz) { - m_dynamicVertexData.reset(new uint8_t[vboSz]); - memmove(m_dynamicVertexData.get(), vboData, vboSz); - } - } - - return true; - } BooTrace); +// CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) { +// /* Index buffer is always static */ +// if (m_hmdlMeta.indexCount) +// m_ibo = ctx.newStaticBuffer(boo::BufferUse::Index, iboData, 4, m_hmdlMeta.indexCount); +// +// if (!m_hmdlMeta.bankCount) { +// /* Non-skinned models use static vertex buffers shared with CBooModel instances */ +// if (m_hmdlMeta.vertCount) +// m_staticVbo = ctx.newStaticBuffer(boo::BufferUse::Vertex, vboData, m_hmdlMeta.vertStride, m_hmdlMeta.vertCount); +// } else { +// /* Skinned models use per-instance dynamic buffers for vertex manipulation effects */ +// size_t vboSz = m_hmdlMeta.vertStride * m_hmdlMeta.vertCount; +// if (vboSz) { +// m_dynamicVertexData.reset(new uint8_t[vboSz]); +// memmove(m_dynamicVertexData.get(), vboData, vboSz); +// } +// } +// +// return true; +// } BooTrace); const u32 surfCount = hecl::SBig(*reinterpret_cast(surfInfo)); x8_surfaces.reserve(surfCount); @@ -1252,7 +1232,7 @@ CModel::CModel(std::unique_ptr&& in, u32 /* dataLen */, IObjectStore* stor const float* aabbPtr = reinterpret_cast(data.get() + 0xc); m_aabb = zeus::CAABox(hecl::SBig(aabbPtr[0]), hecl::SBig(aabbPtr[1]), hecl::SBig(aabbPtr[2]), hecl::SBig(aabbPtr[3]), hecl::SBig(aabbPtr[4]), hecl::SBig(aabbPtr[5])); - x28_modelInst = MakeNewInstance(0, 1, false); + x28_modelInst = MakeNewInstance(0, false); } void SShader::UnlockTextures() { @@ -1304,49 +1284,49 @@ zeus::CVector3f CModel::GetPoolNormal(size_t idx) const { return {floats}; } -void CModel::ApplyVerticesCPU(const boo::ObjToken& vertBuf, - const std::vector>& vn) const { - u8* data = reinterpret_cast(vertBuf->map(m_hmdlMeta.vertStride * m_hmdlMeta.vertCount)); - for (u32 i = 0; i < std::min(u32(vn.size()), m_hmdlMeta.vertCount); ++i) { - const std::pair& avn = vn[i]; - float* floats = reinterpret_cast(data + GetPoolVertexOffset(i)); - floats[0] = avn.first.x(); - floats[1] = avn.first.y(); - floats[2] = avn.first.z(); - floats[3] = avn.second.x(); - floats[4] = avn.second.y(); - floats[5] = avn.second.z(); - } - vertBuf->unmap(); -} - -void CModel::RestoreVerticesCPU(const boo::ObjToken& vertBuf) const { - size_t size = m_hmdlMeta.vertStride * m_hmdlMeta.vertCount; - u8* data = reinterpret_cast(vertBuf->map(size)); - memcpy(data, m_dynamicVertexData.get(), size); - vertBuf->unmap(); -} +//void CModel::ApplyVerticesCPU(const boo::ObjToken& vertBuf, +// const std::vector>& vn) const { +// u8* data = reinterpret_cast(vertBuf->map(m_hmdlMeta.vertStride * m_hmdlMeta.vertCount)); +// for (u32 i = 0; i < std::min(u32(vn.size()), m_hmdlMeta.vertCount); ++i) { +// const std::pair& avn = vn[i]; +// float* floats = reinterpret_cast(data + GetPoolVertexOffset(i)); +// floats[0] = avn.first.x(); +// floats[1] = avn.first.y(); +// floats[2] = avn.first.z(); +// floats[3] = avn.second.x(); +// floats[4] = avn.second.y(); +// floats[5] = avn.second.z(); +// } +// vertBuf->unmap(); +//} +// +//void CModel::RestoreVerticesCPU(const boo::ObjToken& vertBuf) const { +// size_t size = m_hmdlMeta.vertStride * m_hmdlMeta.vertCount; +// u8* data = reinterpret_cast(vertBuf->map(size)); +// memcpy(data, m_dynamicVertexData.get(), size); +// vertBuf->unmap(); +//} void CModel::_WarmupShaders() { - CBooModel::SetDummyTextures(true); - CBooModel::EnableShadowMaps(g_Renderer->x220_sphereRamp.get(), zeus::CTransform()); - CGraphics::CProjectionState backupProj = CGraphics::GetProjectionState(); - zeus::CTransform backupViewPoint = CGraphics::g_ViewMatrix; - zeus::CTransform backupModel = CGraphics::g_GXModelMatrix; - CGraphics::SetModelMatrix(zeus::CTransform::Translate(-m_aabb.center())); - CGraphics::SetViewPointMatrix(zeus::CTransform::Translate(0.f, -2048.f, 0.f)); - CGraphics::SetOrtho(-2048.f, 2048.f, 2048.f, -2048.f, 0.f, 4096.f); - CModelFlags defaultFlags; - for (SShader& shader : x18_matSets) { - GetInstance().RemapMaterialData(shader); - GetInstance().UpdateUniformData(defaultFlags, nullptr, nullptr); - GetInstance().WarmupDrawSurfaces(); - } - CGraphics::SetProjectionState(backupProj); - CGraphics::SetViewPointMatrix(backupViewPoint); - CGraphics::SetModelMatrix(backupModel); - CBooModel::DisableShadowMaps(); - CBooModel::SetDummyTextures(false); +// CBooModel::SetDummyTextures(true); +// CBooModel::EnableShadowMaps(g_Renderer->x220_sphereRamp.get(), zeus::CTransform()); +// CGraphics::CProjectionState backupProj = CGraphics::GetProjectionState(); +// zeus::CTransform backupViewPoint = CGraphics::g_ViewMatrix; +// zeus::CTransform backupModel = CGraphics::g_GXModelMatrix; +// CGraphics::SetModelMatrix(zeus::CTransform::Translate(-m_aabb.center())); +// CGraphics::SetViewPointMatrix(zeus::CTransform::Translate(0.f, -2048.f, 0.f)); +// CGraphics::SetOrtho(-2048.f, 2048.f, 2048.f, -2048.f, 0.f, 4096.f); +// CModelFlags defaultFlags; +// for (SShader& shader : x18_matSets) { +// GetInstance().RemapMaterialData(shader); +// GetInstance().UpdateUniformData(defaultFlags, nullptr, nullptr); +// GetInstance().WarmupDrawSurfaces(); +// } +// CGraphics::SetProjectionState(backupProj); +// CGraphics::SetViewPointMatrix(backupViewPoint); +// CGraphics::SetModelMatrix(backupModel); +// CBooModel::DisableShadowMaps(); +// CBooModel::SetDummyTextures(false); } void CModel::WarmupShaders(const SObjectTag& cmdlTag) { diff --git a/Runtime/Graphics/CMoviePlayer.cpp b/Runtime/Graphics/CMoviePlayer.cpp index 37aab6c64..7e6b4dcfb 100644 --- a/Runtime/Graphics/CMoviePlayer.cpp +++ b/Runtime/Graphics/CMoviePlayer.cpp @@ -5,7 +5,7 @@ #include "Runtime/Graphics/CGraphics.hpp" #include -#include +//#include #include namespace metaforce { @@ -27,7 +27,7 @@ static const u16 StaticVolumeLookup[] = { 0x6CA2, 0x6E80, 0x7061, 0x7247, 0x7430, 0x761E, 0x7810, 0x7A06, 0x7C00, 0x7DFE, 0x8000}; /* shared boo resources */ -static boo::ObjToken YUVShaderPipeline; +//static boo::ObjToken YUVShaderPipeline; static tjhandle TjHandle = nullptr; /* RSF audio state */ @@ -46,20 +46,20 @@ static float SfxVolume = 1.f; static const char* BlockNames[] = {"SpecterViewBlock"}; static const char* TexNames[] = {"texY", "texU", "texV"}; -void CMoviePlayer::Initialize(boo::IGraphicsDataFactory* factory) { - switch (factory->platform()) { - case boo::IGraphicsDataFactory::Platform::Vulkan: - g_PlatformMatrix.m[1][1] = -1.f; - break; - default: - break; - } - YUVShaderPipeline = hecl::conv->convert(Shader_CMoviePlayerShader{}); +void CMoviePlayer::Initialize() { +// switch (factory->platform()) { +// case boo::IGraphicsDataFactory::Platform::Vulkan: +// g_PlatformMatrix.m[1][1] = -1.f; +// break; +// default: +// break; +// } +// YUVShaderPipeline = hecl::conv->convert(Shader_CMoviePlayerShader{}); TjHandle = tjInitDecompress(); } void CMoviePlayer::Shutdown() { - YUVShaderPipeline.reset(); +// YUVShaderPipeline.reset(); tjDestroy(TjHandle); } @@ -202,50 +202,50 @@ CMoviePlayer::CMoviePlayer(const char* path, float preLoadSeconds, bool loop, bo xa0_bufferQueue.reserve(xf0_preLoadFrames); /* All set for GPU resources */ - CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) { - m_blockBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(m_viewVertBlock), 1); - m_vertBuf = ctx.newDynamicBuffer(boo::BufferUse::Vertex, sizeof(TexShaderVert), 4); - - /* Allocate textures here (rather than at decode time) */ - x80_textures.reserve(3); - for (int i = 0; i < 3; ++i) { - CTHPTextureSet& set = x80_textures.emplace_back(); - if (deinterlace) { - /* metaforce addition: this way interlaced THPs don't look horrible */ - set.Y[0] = ctx.newDynamicTexture(x6c_videoInfo.width, x6c_videoInfo.height / 2, boo::TextureFormat::I8, - boo::TextureClampMode::Repeat); - set.Y[1] = ctx.newDynamicTexture(x6c_videoInfo.width, x6c_videoInfo.height / 2, boo::TextureFormat::I8, - boo::TextureClampMode::Repeat); - set.U = ctx.newDynamicTexture(x6c_videoInfo.width / 2, x6c_videoInfo.height / 2, boo::TextureFormat::I8, - boo::TextureClampMode::Repeat); - set.V = ctx.newDynamicTexture(x6c_videoInfo.width / 2, x6c_videoInfo.height / 2, boo::TextureFormat::I8, - boo::TextureClampMode::Repeat); - - boo::ObjToken bufs[] = {m_blockBuf.get()}; - for (int j = 0; j < 2; ++j) { - boo::ObjToken texs[] = {set.Y[j].get(), set.U.get(), set.V.get()}; - set.binding[j] = ctx.newShaderDataBinding(YUVShaderPipeline, m_vertBuf.get(), nullptr, nullptr, 1, bufs, - nullptr, 3, texs, nullptr, nullptr); - } - } else { - /* normal progressive presentation */ - set.Y[0] = ctx.newDynamicTexture(x6c_videoInfo.width, x6c_videoInfo.height, boo::TextureFormat::I8, - boo::TextureClampMode::Repeat); - set.U = ctx.newDynamicTexture(x6c_videoInfo.width / 2, x6c_videoInfo.height / 2, boo::TextureFormat::I8, - boo::TextureClampMode::Repeat); - set.V = ctx.newDynamicTexture(x6c_videoInfo.width / 2, x6c_videoInfo.height / 2, boo::TextureFormat::I8, - boo::TextureClampMode::Repeat); - - boo::ObjToken bufs[] = {m_blockBuf.get()}; - boo::ObjToken texs[] = {set.Y[0].get(), set.U.get(), set.V.get()}; - set.binding[0] = ctx.newShaderDataBinding(YUVShaderPipeline, m_vertBuf.get(), nullptr, nullptr, 1, bufs, - nullptr, 3, texs, nullptr, nullptr); - } - if (xf4_25_hasAudio) - set.audioBuf.reset(new s16[x28_thpHead.maxAudioSamples * 2]); - } - return true; - } BooTrace); +// CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) { +// m_blockBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(m_viewVertBlock), 1); +// m_vertBuf = ctx.newDynamicBuffer(boo::BufferUse::Vertex, sizeof(TexShaderVert), 4); +// +// /* Allocate textures here (rather than at decode time) */ +// x80_textures.reserve(3); +// for (int i = 0; i < 3; ++i) { +// CTHPTextureSet& set = x80_textures.emplace_back(); +// if (deinterlace) { +// /* metaforce addition: this way interlaced THPs don't look horrible */ +// set.Y[0] = ctx.newDynamicTexture(x6c_videoInfo.width, x6c_videoInfo.height / 2, boo::TextureFormat::I8, +// boo::TextureClampMode::Repeat); +// set.Y[1] = ctx.newDynamicTexture(x6c_videoInfo.width, x6c_videoInfo.height / 2, boo::TextureFormat::I8, +// boo::TextureClampMode::Repeat); +// set.U = ctx.newDynamicTexture(x6c_videoInfo.width / 2, x6c_videoInfo.height / 2, boo::TextureFormat::I8, +// boo::TextureClampMode::Repeat); +// set.V = ctx.newDynamicTexture(x6c_videoInfo.width / 2, x6c_videoInfo.height / 2, boo::TextureFormat::I8, +// boo::TextureClampMode::Repeat); +// +// boo::ObjToken bufs[] = {m_blockBuf.get()}; +// for (int j = 0; j < 2; ++j) { +// boo::ObjToken texs[] = {set.Y[j].get(), set.U.get(), set.V.get()}; +// set.binding[j] = ctx.newShaderDataBinding(YUVShaderPipeline, m_vertBuf.get(), nullptr, nullptr, 1, bufs, +// nullptr, 3, texs, nullptr, nullptr); +// } +// } else { +// /* normal progressive presentation */ +// set.Y[0] = ctx.newDynamicTexture(x6c_videoInfo.width, x6c_videoInfo.height, boo::TextureFormat::I8, +// boo::TextureClampMode::Repeat); +// set.U = ctx.newDynamicTexture(x6c_videoInfo.width / 2, x6c_videoInfo.height / 2, boo::TextureFormat::I8, +// boo::TextureClampMode::Repeat); +// set.V = ctx.newDynamicTexture(x6c_videoInfo.width / 2, x6c_videoInfo.height / 2, boo::TextureFormat::I8, +// boo::TextureClampMode::Repeat); +// +// boo::ObjToken bufs[] = {m_blockBuf.get()}; +// boo::ObjToken texs[] = {set.Y[0].get(), set.U.get(), set.V.get()}; +// set.binding[0] = ctx.newShaderDataBinding(YUVShaderPipeline, m_vertBuf.get(), nullptr, nullptr, 1, bufs, +// nullptr, 3, texs, nullptr, nullptr); +// } +// if (xf4_25_hasAudio) +// set.audioBuf.reset(new s16[x28_thpHead.maxAudioSamples * 2]); +// } +// return true; +// } BooTrace); /* Temporary planar YUV decode buffer, resulting planes copied to Boo */ m_yuvBuf.reset(new uint8_t[tjBufSizeYUV(x6c_videoInfo.width, x6c_videoInfo.height, TJ_420)]); @@ -260,7 +260,7 @@ CMoviePlayer::CMoviePlayer(const char* path, float preLoadSeconds, bool loop, bo SetFrame({-0.5f, 0.5f, 0.f}, {-0.5f, -0.5f, 0.f}, {0.5f, -0.5f, 0.f}, {0.5f, 0.5f, 0.f}); m_viewVertBlock.finalAssign(m_viewVertBlock); - m_blockBuf->load(&m_viewVertBlock, sizeof(m_viewVertBlock)); +// m_blockBuf->load(&m_viewVertBlock, sizeof(m_viewVertBlock)); } void CMoviePlayer::SetStaticAudioVolume(int vol) { @@ -405,7 +405,7 @@ void CMoviePlayer::SetFrame(const zeus::CVector3f& a, const zeus::CVector3f& b, m_frame[1].m_pos = b; m_frame[2].m_pos = d; m_frame[3].m_pos = c; - m_vertBuf->load(m_frame, sizeof(m_frame)); +// m_vertBuf->load(m_frame, sizeof(m_frame)); } void CMoviePlayer::DrawFrame() { @@ -415,8 +415,8 @@ void CMoviePlayer::DrawFrame() { /* draw appropriate field */ CTHPTextureSet& tex = x80_textures[xd0_drawTexSlot]; - CGraphics::SetShaderDataBinding(tex.binding[m_deinterlace ? (xfc_fieldIndex != 0) : 0]); - CGraphics::DrawArray(0, 4); +// CGraphics::SetShaderDataBinding(tex.binding[m_deinterlace ? (xfc_fieldIndex != 0) : 0]); +// CGraphics::DrawArray(0, 4); /* ensure second field is being displayed by VI to signal advance * (faked in metaforce with continuous xor) */ @@ -532,27 +532,27 @@ void CMoviePlayer::DecodeFromRead(const void* data) { if (m_deinterlace) { /* Deinterlace into 2 discrete 60-fps half-res textures */ - u8* mappedData = (u8*)tex.Y[0]->map(planeSizeHalf); - for (unsigned y = 0; y < x6c_videoInfo.height / 2; ++y) { - memmove(mappedData + x6c_videoInfo.width * y, m_yuvBuf.get() + x6c_videoInfo.width * (y * 2), - x6c_videoInfo.width); - } - tex.Y[0]->unmap(); - - mappedData = (u8*)tex.Y[1]->map(planeSizeHalf); - for (unsigned y = 0; y < x6c_videoInfo.height / 2; ++y) { - memmove(mappedData + x6c_videoInfo.width * y, m_yuvBuf.get() + x6c_videoInfo.width * (y * 2 + 1), - x6c_videoInfo.width); - } - tex.Y[1]->unmap(); - - tex.U->load(m_yuvBuf.get() + planeSize, planeSizeQuarter); - tex.V->load(m_yuvBuf.get() + planeSize + planeSizeQuarter, planeSizeQuarter); +// u8* mappedData = (u8*)tex.Y[0]->map(planeSizeHalf); +// for (unsigned y = 0; y < x6c_videoInfo.height / 2; ++y) { +// memmove(mappedData + x6c_videoInfo.width * y, m_yuvBuf.get() + x6c_videoInfo.width * (y * 2), +// x6c_videoInfo.width); +// } +// tex.Y[0]->unmap(); +// +// mappedData = (u8*)tex.Y[1]->map(planeSizeHalf); +// for (unsigned y = 0; y < x6c_videoInfo.height / 2; ++y) { +// memmove(mappedData + x6c_videoInfo.width * y, m_yuvBuf.get() + x6c_videoInfo.width * (y * 2 + 1), +// x6c_videoInfo.width); +// } +// tex.Y[1]->unmap(); +// +// tex.U->load(m_yuvBuf.get() + planeSize, planeSizeQuarter); +// tex.V->load(m_yuvBuf.get() + planeSize + planeSizeQuarter, planeSizeQuarter); } else { /* Direct planar load */ - tex.Y[0]->load(m_yuvBuf.get(), planeSize); - tex.U->load(m_yuvBuf.get() + planeSize, planeSizeQuarter); - tex.V->load(m_yuvBuf.get() + planeSize + planeSizeQuarter, planeSizeQuarter); +// tex.Y[0]->load(m_yuvBuf.get(), planeSize); +// tex.U->load(m_yuvBuf.get() + planeSize, planeSizeQuarter); +// tex.V->load(m_yuvBuf.get() + planeSize + planeSizeQuarter, planeSizeQuarter); } break; diff --git a/Runtime/Graphics/CMoviePlayer.hpp b/Runtime/Graphics/CMoviePlayer.hpp index 606d9ee11..4d7b8a6e6 100644 --- a/Runtime/Graphics/CMoviePlayer.hpp +++ b/Runtime/Graphics/CMoviePlayer.hpp @@ -5,9 +5,8 @@ #include "Runtime/CDvdFile.hpp" #include "Runtime/RetroTypes.hpp" +#include "Runtime/Graphics/CGraphics.hpp" -#include -#include #include #include @@ -72,13 +71,13 @@ private: }; struct CTHPTextureSet { - boo::ObjToken Y[2]; - boo::ObjToken U; - boo::ObjToken V; + std::shared_ptr Y[2]; + std::shared_ptr U; + std::shared_ptr V; u32 playedSamples = 0; u32 audioSamples = 0; std::unique_ptr audioBuf; - boo::ObjToken binding[2]; +// boo::ObjToken binding[2]; }; std::vector x80_textures; std::unique_ptr x90_requestBuf; @@ -118,11 +117,11 @@ private: struct ViewBlock { zeus::CMatrix4f m_mv; zeus::CColor m_color = zeus::skWhite; - void setViewRect(const boo::SWindowRect& root, const boo::SWindowRect& sub) { - m_mv[0][0] = 2.0f / root.size[0]; - m_mv[1][1] = 2.0f / root.size[1]; - m_mv[3][0] = sub.location[0] * m_mv[0][0] - 1.0f; - m_mv[3][1] = sub.location[1] * m_mv[1][1] - 1.0f; + void setViewRect(const aurora::shaders::ClipRect& root, const aurora::shaders::ClipRect& sub) { + m_mv[0][0] = 2.0f / root.width; + m_mv[1][1] = 2.0f / root.height; + m_mv[3][0] = sub.x * m_mv[0][0] - 1.0f; + m_mv[3][1] = sub.y * m_mv[1][1] - 1.0f; } void finalAssign(const ViewBlock& other) { m_mv = g_PlatformMatrix * other.m_mv; @@ -131,8 +130,8 @@ private: }; ViewBlock m_viewVertBlock; - boo::ObjToken m_blockBuf; - boo::ObjToken m_vertBuf; +// boo::ObjToken m_blockBuf; +// boo::ObjToken m_vertBuf; TexShaderVert m_frame[4]; @@ -167,7 +166,7 @@ public: void Update(float dt); std::pair GetVideoDimensions() const { return {x6c_videoInfo.width, x6c_videoInfo.height}; } - static void Initialize(boo::IGraphicsDataFactory* factory); + static void Initialize(); static void Shutdown(); }; diff --git a/Runtime/Graphics/CRainSplashGenerator.cpp b/Runtime/Graphics/CRainSplashGenerator.cpp index 0dc3895c7..0b6d51ebc 100644 --- a/Runtime/Graphics/CRainSplashGenerator.cpp +++ b/Runtime/Graphics/CRainSplashGenerator.cpp @@ -13,11 +13,8 @@ CRainSplashGenerator::CRainSplashGenerator(const zeus::CVector3f& scale, u32 max x30_alpha = std::min(1.f, alpha); x44_genRate = std::min(maxSplashes, genRate); x0_rainSplashes.reserve(maxSplashes); - CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) { - for (u32 i = 0; i < maxSplashes; ++i) - x0_rainSplashes.emplace_back(ctx); - return true; - } BooTrace); + for (u32 i = 0; i < maxSplashes; ++i) + x0_rainSplashes.emplace_back(); } void CRainSplashGenerator::SSplashLine::Draw(float alpha, float dt, const zeus::CVector3f& pos) { @@ -73,12 +70,12 @@ void CRainSplashGenerator::Draw(const zeus::CTransform& xf) { DoDraw(xf); } -CRainSplashGenerator::SSplashLine::SSplashLine(boo::IGraphicsDataFactory::Context& ctx) -: m_renderer(ctx, CLineRenderer::EPrimitiveMode::LineStrip, 3, nullptr, false) {} +CRainSplashGenerator::SSplashLine::SSplashLine() +: m_renderer(CLineRenderer::EPrimitiveMode::LineStrip, 3, nullptr, false) {} -CRainSplashGenerator::SRainSplash::SRainSplash(boo::IGraphicsDataFactory::Context& ctx) { +CRainSplashGenerator::SRainSplash::SRainSplash() { for (size_t i = 0; i < x0_lines.capacity(); ++i) { - x0_lines.emplace_back(ctx); + x0_lines.emplace_back(); } } diff --git a/Runtime/Graphics/CRainSplashGenerator.hpp b/Runtime/Graphics/CRainSplashGenerator.hpp index 37e9fe1f7..de7147fba 100644 --- a/Runtime/Graphics/CRainSplashGenerator.hpp +++ b/Runtime/Graphics/CRainSplashGenerator.hpp @@ -24,7 +24,7 @@ class CRainSplashGenerator { u8 x15_length = 1; bool x16_active = true; // used to be one-bit bitfield CLineRenderer m_renderer; - explicit SSplashLine(boo::IGraphicsDataFactory::Context& ctx); + explicit SSplashLine(); void Update(float dt, CStateManager& mgr); void Draw(float alpha, float dt, const zeus::CVector3f& pos); void SetActive() { x16_active = true; } @@ -33,7 +33,7 @@ class CRainSplashGenerator { rstl::reserved_vector x0_lines; zeus::CVector3f x64_pos; float x70_ = 0.f; - explicit SRainSplash(boo::IGraphicsDataFactory::Context& ctx); + explicit SRainSplash(); SRainSplash(const SRainSplash&) = delete; SRainSplash& operator=(const SRainSplash&) = delete; SRainSplash(SRainSplash&&) = default; diff --git a/Runtime/Graphics/CSkinnedModel.cpp b/Runtime/Graphics/CSkinnedModel.cpp index 65eba6f43..914b94aee 100644 --- a/Runtime/Graphics/CSkinnedModel.cpp +++ b/Runtime/Graphics/CSkinnedModel.cpp @@ -9,7 +9,7 @@ namespace metaforce { static logvisor::Module Log("metaforce::CSkinnedModel"); CSkinnedModel::CSkinnedModel(TLockedToken model, TLockedToken skinRules, - TLockedToken layoutInfo, int shaderIdx, int drawInsts) + TLockedToken layoutInfo, int shaderIdx) : x4_model(std::move(model)), x10_skinRules(std::move(skinRules)), x1c_layoutInfo(std::move(layoutInfo)) { if (!x4_model) { Log.report(logvisor::Fatal, FMT_STRING("bad model token provided to CSkinnedModel")); @@ -20,35 +20,36 @@ CSkinnedModel::CSkinnedModel(TLockedToken model, TLockedTokenMakeNewInstance(shaderIdx, drawInsts); + m_modelInst = x4_model->MakeNewInstance(shaderIdx); } CSkinnedModel::CSkinnedModel(IObjectStore& store, CAssetId model, CAssetId skinRules, CAssetId layoutInfo, - int shaderIdx, int drawInsts) + int shaderIdx) : CSkinnedModel(store.GetObj(SObjectTag{FOURCC('CMDL'), model}), store.GetObj(SObjectTag{FOURCC('CSKR'), skinRules}), - store.GetObj(SObjectTag{FOURCC('CINF'), layoutInfo}), shaderIdx, drawInsts) {} + store.GetObj(SObjectTag{FOURCC('CINF'), layoutInfo}), shaderIdx) {} void CSkinnedModel::Calculate(const CPoseAsTransforms& pose, const CModelFlags& drawFlags, const std::optional& morphEffect, const float* morphMagnitudes) { - if (morphEffect || g_PointGenFunc) { - if (boo::ObjToken vertBuf = m_modelInst->UpdateUniformData(drawFlags, nullptr, nullptr)) { - x10_skinRules->TransformVerticesCPU(m_vertWorkspace, pose, *x4_model); - if (morphEffect) - morphEffect->MorphVertices(m_vertWorkspace, morphMagnitudes, x10_skinRules, pose); - if (g_PointGenFunc) - g_PointGenFunc(g_PointGenCtx, m_vertWorkspace); - x4_model->ApplyVerticesCPU(vertBuf, m_vertWorkspace); - m_modifiedVBO = true; - } - } else { - if (boo::ObjToken vertBuf = - m_modelInst->UpdateUniformData(drawFlags, x10_skinRules.GetObj(), &pose)) { - if (m_modifiedVBO) { - x4_model->RestoreVerticesCPU(vertBuf); - m_modifiedVBO = false; - } - } - } + // TODO +// if (morphEffect || g_PointGenFunc) { +// if (boo::ObjToken vertBuf = m_modelInst->UpdateUniformData(drawFlags, nullptr, nullptr)) { +// x10_skinRules->TransformVerticesCPU(m_vertWorkspace, pose, *x4_model); +// if (morphEffect) +// morphEffect->MorphVertices(m_vertWorkspace, morphMagnitudes, x10_skinRules, pose); +// if (g_PointGenFunc) +// g_PointGenFunc(g_PointGenCtx, m_vertWorkspace); +// x4_model->ApplyVerticesCPU(vertBuf, m_vertWorkspace); +// m_modifiedVBO = true; +// } +// } else { +// if (boo::ObjToken vertBuf = +// m_modelInst->UpdateUniformData(drawFlags, x10_skinRules.GetObj(), &pose)) { +// if (m_modifiedVBO) { +// x4_model->RestoreVerticesCPU(vertBuf); +// m_modifiedVBO = false; +// } +// } +// } } void CSkinnedModel::Draw(const CModelFlags& drawFlags) const { @@ -58,8 +59,8 @@ void CSkinnedModel::Draw(const CModelFlags& drawFlags) const { } CMorphableSkinnedModel::CMorphableSkinnedModel(IObjectStore& store, CAssetId model, CAssetId skinRules, - CAssetId layoutInfo, int shaderIdx, int drawInsts) -: CSkinnedModel(store, model, skinRules, layoutInfo, shaderIdx, drawInsts) {} + CAssetId layoutInfo, int shaderIdx) +: CSkinnedModel(store, model, skinRules, layoutInfo, shaderIdx) {} CSkinnedModel::FPointGenerator CSkinnedModel::g_PointGenFunc = nullptr; void* CSkinnedModel::g_PointGenCtx = nullptr; diff --git a/Runtime/Graphics/CSkinnedModel.hpp b/Runtime/Graphics/CSkinnedModel.hpp index e977c1078..8985d7537 100644 --- a/Runtime/Graphics/CSkinnedModel.hpp +++ b/Runtime/Graphics/CSkinnedModel.hpp @@ -30,11 +30,10 @@ class CSkinnedModel { public: enum class EDataOwnership { Zero, One }; CSkinnedModel(TLockedToken model, TLockedToken skinRules, - TLockedToken layoutInfo, int shaderIdx, int drawInsts); - CSkinnedModel(IObjectStore& store, CAssetId model, CAssetId skinRules, CAssetId layoutInfo, int shaderIdx, - int drawInsts); - std::unique_ptr Clone(int shaderIdx = 0, int drawInsts = 1) const { - return std::make_unique(x4_model, x10_skinRules, x1c_layoutInfo, shaderIdx, drawInsts); + TLockedToken layoutInfo, int shaderIdx); + CSkinnedModel(IObjectStore& store, CAssetId model, CAssetId skinRules, CAssetId layoutInfo, int shaderIdx); + std::unique_ptr Clone(int shaderIdx = 0) const { + return std::make_unique(x4_model, x10_skinRules, x1c_layoutInfo, shaderIdx); } const TLockedToken& GetModel() const { return x4_model; } @@ -61,8 +60,7 @@ class CMorphableSkinnedModel : public CSkinnedModel { std::unique_ptr x40_morphMagnitudes; public: - CMorphableSkinnedModel(IObjectStore& store, CAssetId model, CAssetId skinRules, CAssetId layoutInfo, int shaderIdx, - int drawInsts); + CMorphableSkinnedModel(IObjectStore& store, CAssetId model, CAssetId skinRules, CAssetId layoutInfo, int shaderIdx); const float* GetMorphMagnitudes() const { return x40_morphMagnitudes.get(); } }; diff --git a/Runtime/Graphics/CTexture.hpp b/Runtime/Graphics/CTexture.hpp index 272dac108..de1f237b1 100644 --- a/Runtime/Graphics/CTexture.hpp +++ b/Runtime/Graphics/CTexture.hpp @@ -9,7 +9,7 @@ #include "Runtime/IOStreams.hpp" #include "Runtime/Graphics/CGraphics.hpp" -#include +//#include namespace metaforce { class CVParamTransfer; @@ -32,34 +32,35 @@ private: u16 x4_w; u16 x6_h; u32 x8_mips; - boo::ObjToken m_booTex; - boo::ObjToken m_paletteTex; +// boo::ObjToken m_booTex; + std::shared_ptr m_tex; + std::shared_ptr m_paletteTex; std::unique_ptr m_otex; EFontType m_ftype = EFontType::None; const CTextureInfo* m_textureInfo; size_t ComputeMippedTexelCount() const; size_t ComputeMippedBlockCountDXT1() const; - void BuildI4FromGCN(CInputStream& in); - void BuildI8FromGCN(CInputStream& in); - void BuildIA4FromGCN(CInputStream& in); - void BuildIA8FromGCN(CInputStream& in); - void BuildC4FromGCN(CInputStream& in); - void BuildC8FromGCN(CInputStream& in); - void BuildC14X2FromGCN(CInputStream& in); - void BuildRGB565FromGCN(CInputStream& in); - void BuildRGB5A3FromGCN(CInputStream& in); - void BuildRGBA8FromGCN(CInputStream& in); - void BuildDXT1FromGCN(CInputStream& in); - void BuildRGBA8(const void* data, size_t length); - void BuildC8(const void* data, size_t length); - void BuildC8Font(const void* data, EFontType ftype); - void BuildDXT1(const void* data, size_t length); - void BuildDXT3(const void* data, size_t length); + void BuildI4FromGCN(CInputStream& in, std::string_view label); + void BuildI8FromGCN(CInputStream& in, std::string_view label); + void BuildIA4FromGCN(CInputStream& in, std::string_view label); + void BuildIA8FromGCN(CInputStream& in, std::string_view label); + void BuildC4FromGCN(CInputStream& in, std::string_view label); + void BuildC8FromGCN(CInputStream& in, std::string_view label); + void BuildC14X2FromGCN(CInputStream& in, std::string_view label); + void BuildRGB565FromGCN(CInputStream& in, std::string_view label); + void BuildRGB5A3FromGCN(CInputStream& in, std::string_view label); + void BuildRGBA8FromGCN(CInputStream& in, std::string_view label); + void BuildDXT1FromGCN(CInputStream& in, std::string_view label); + void BuildRGBA8(const void* data, size_t length, std::string_view label); + void BuildC8(const void* data, size_t length, std::string_view label); + void BuildC8Font(const void* data, EFontType ftype, std::string_view label); + void BuildDXT1(const void* data, size_t length, std::string_view label); + void BuildDXT3(const void* data, size_t length, std::string_view label); public: CTexture(ETexelFormat, s16, s16, s32); - CTexture(std::unique_ptr&& in, u32 length, bool otex, const CTextureInfo* inf); + CTexture(std::unique_ptr&& in, u32 length, bool otex, const CTextureInfo* inf, CAssetId id); enum class EClampMode { None, One }; ETexelFormat GetTexelFormat() const { return x0_fmt; } ETexelFormat GetMemoryCardTexelFormat() const { @@ -69,10 +70,11 @@ public: u16 GetHeight() const { return x6_h; } u32 GetNumMips() const { return x8_mips; } void Load(int slot, EClampMode clamp) const; - const boo::ObjToken& GetBooTexture() const { return m_booTex; } - const boo::ObjToken& GetPaletteTexture() const { return m_paletteTex; } + const std::shared_ptr& GetTexture() const { return m_tex; } +// const boo::ObjToken& GetBooTexture() const { return m_booTex; } + const std::shared_ptr& GetPaletteTexture() const { return m_paletteTex; } std::unique_ptr BuildMemoryCardTex(u32& sizeOut, ETexelFormat& fmtOut, std::unique_ptr& paletteOut) const; - const boo::ObjToken& GetFontTexture(EFontType tp); + const std::shared_ptr& GetFontTexture(EFontType tp); const CTextureInfo* GetTextureInfo() const { return m_textureInfo; } }; diff --git a/Runtime/Graphics/CTextureBoo.cpp b/Runtime/Graphics/CTextureBoo.cpp index 2bfc78089..8f8c5a335 100644 --- a/Runtime/Graphics/CTextureBoo.cpp +++ b/Runtime/Graphics/CTextureBoo.cpp @@ -75,7 +75,7 @@ size_t CTexture::ComputeMippedBlockCountDXT1() const { return ret; } -void CTexture::BuildI4FromGCN(CInputStream& in) { +void CTexture::BuildI4FromGCN(CInputStream& in, std::string_view label) { const size_t texelCount = ComputeMippedTexelCount(); std::unique_ptr buf(new RGBA8[texelCount]); @@ -89,11 +89,11 @@ void CTexture::BuildI4FromGCN(CInputStream& in) { const int baseY = by * 8; for (int bx = 0; bx < bwidth; ++bx) { const int baseX = bx * 8; - for (int y = 0; y < 8; ++y) { + for (int y = 0; y < std::min(h, 8); ++y) { RGBA8* target = targetMip + (baseY + y) * w + baseX; std::array source; - in.readBytesToBuf(source.data(), source.size()); - for (size_t x = 0; x < 8; ++x) { + in.readBytesToBuf(source.data(), std::min(size_t(w) / 4, source.size())); + for (size_t x = 0; x < std::min(w, 8); ++x) { target[x].r = Convert4To8(source[x / 2] >> ((x & 1) ? 0 : 4) & 0xf); target[x].g = target[x].r; target[x].b = target[x].r; @@ -111,15 +111,11 @@ void CTexture::BuildI4FromGCN(CInputStream& in) { } } - CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) { - m_booTex = ctx.newStaticTexture(x4_w, x6_h, x8_mips, boo::TextureFormat::RGBA8, boo::TextureClampMode::Repeat, - buf.get(), texelCount * 4) - .get(); - return true; - } BooTrace); + m_tex = aurora::new_static_texture_2d(x4_w, x6_h, x8_mips, aurora::shaders::TextureFormat::RGBA8, + {reinterpret_cast(buf.get()), texelCount * 4}, label); } -void CTexture::BuildI8FromGCN(CInputStream& in) { +void CTexture::BuildI8FromGCN(CInputStream& in, std::string_view label) { const size_t texelCount = ComputeMippedTexelCount(); std::unique_ptr buf(new RGBA8[texelCount]); @@ -155,15 +151,11 @@ void CTexture::BuildI8FromGCN(CInputStream& in) { } } - CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) { - m_booTex = ctx.newStaticTexture(x4_w, x6_h, x8_mips, boo::TextureFormat::RGBA8, boo::TextureClampMode::Repeat, - buf.get(), texelCount * 4) - .get(); - return true; - } BooTrace); + m_tex = aurora::new_static_texture_2d(x4_w, x6_h, x8_mips, aurora::shaders::TextureFormat::RGBA8, + {reinterpret_cast(buf.get()), texelCount * 4}, label); } -void CTexture::BuildIA4FromGCN(CInputStream& in) { +void CTexture::BuildIA4FromGCN(CInputStream& in, std::string_view label) { const size_t texelCount = ComputeMippedTexelCount(); std::unique_ptr buf(new RGBA8[texelCount]); @@ -200,15 +192,11 @@ void CTexture::BuildIA4FromGCN(CInputStream& in) { } } - CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) { - m_booTex = ctx.newStaticTexture(x4_w, x6_h, x8_mips, boo::TextureFormat::RGBA8, boo::TextureClampMode::Repeat, - buf.get(), texelCount * 4) - .get(); - return true; - } BooTrace); + m_tex = aurora::new_static_texture_2d(x4_w, x6_h, x8_mips, aurora::shaders::TextureFormat::RGBA8, + {reinterpret_cast(buf.get()), texelCount * 4}, label); } -void CTexture::BuildIA8FromGCN(CInputStream& in) { +void CTexture::BuildIA8FromGCN(CInputStream& in, std::string_view label) { const size_t texelCount = ComputeMippedTexelCount(); std::unique_ptr buf(new RGBA8[texelCount]); @@ -245,12 +233,8 @@ void CTexture::BuildIA8FromGCN(CInputStream& in) { } } - CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) { - m_booTex = ctx.newStaticTexture(x4_w, x6_h, x8_mips, boo::TextureFormat::RGBA8, boo::TextureClampMode::Repeat, - buf.get(), texelCount * 4) - .get(); - return true; - } BooTrace); + m_tex = aurora::new_static_texture_2d(x4_w, x6_h, x8_mips, aurora::shaders::TextureFormat::RGBA8, + {reinterpret_cast(buf.get()), texelCount * 4}, label); } static std::vector DecodePalette(int numEntries, CInputStream& in) { @@ -294,7 +278,7 @@ static std::vector DecodePalette(int numEntries, CInputStream& in) { return ret; } -void CTexture::BuildC4FromGCN(CInputStream& in) { +void CTexture::BuildC4FromGCN(CInputStream& in, std::string_view label) { const size_t texelCount = ComputeMippedTexelCount(); std::unique_ptr buf(new RGBA8[texelCount]); std::vector palette = DecodePalette(16, in); @@ -328,15 +312,11 @@ void CTexture::BuildC4FromGCN(CInputStream& in) { } } - CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) { - m_booTex = ctx.newStaticTexture(x4_w, x6_h, x8_mips, boo::TextureFormat::RGBA8, boo::TextureClampMode::Repeat, - buf.get(), texelCount * 4) - .get(); - return true; - } BooTrace); + m_tex = aurora::new_static_texture_2d(x4_w, x6_h, x8_mips, aurora::shaders::TextureFormat::RGBA8, + {reinterpret_cast(buf.get()), texelCount * 4}, label); } -void CTexture::BuildC8FromGCN(CInputStream& in) { +void CTexture::BuildC8FromGCN(CInputStream& in, std::string_view label) { const size_t texelCount = ComputeMippedTexelCount(); std::unique_ptr buf(new RGBA8[texelCount]); std::vector palette = DecodePalette(256, in); @@ -370,17 +350,15 @@ void CTexture::BuildC8FromGCN(CInputStream& in) { } } - CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) { - m_booTex = ctx.newStaticTexture(x4_w, x6_h, x8_mips, boo::TextureFormat::RGBA8, boo::TextureClampMode::Repeat, - buf.get(), texelCount * 4) - .get(); - return true; - } BooTrace); + m_tex = aurora::new_static_texture_2d(x4_w, x6_h, x8_mips, aurora::shaders::TextureFormat::RGBA8, + {reinterpret_cast(buf.get()), texelCount * 4}, label); } -void CTexture::BuildC14X2FromGCN(CInputStream& in) {} +void CTexture::BuildC14X2FromGCN(CInputStream& in, std::string_view label) { + Log.report(logvisor::Fatal, FMT_STRING("C14X2 not implemented")); +} -void CTexture::BuildRGB565FromGCN(CInputStream& in) { +void CTexture::BuildRGB565FromGCN(CInputStream& in, std::string_view label) { const size_t texelCount = ComputeMippedTexelCount(); std::unique_ptr buf(new RGBA8[texelCount]); @@ -415,15 +393,11 @@ void CTexture::BuildRGB565FromGCN(CInputStream& in) { } } - CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) { - m_booTex = ctx.newStaticTexture(x4_w, x6_h, x8_mips, boo::TextureFormat::RGBA8, boo::TextureClampMode::Repeat, - buf.get(), texelCount * 4) - .get(); - return true; - } BooTrace); + m_tex = aurora::new_static_texture_2d(x4_w, x6_h, x8_mips, aurora::shaders::TextureFormat::RGBA8, + {reinterpret_cast(buf.get()), texelCount * 4}, label); } -void CTexture::BuildRGB5A3FromGCN(CInputStream& in) { +void CTexture::BuildRGB5A3FromGCN(CInputStream& in, std::string_view label) { size_t texelCount = ComputeMippedTexelCount(); std::unique_ptr buf(new RGBA8[texelCount]); @@ -465,15 +439,11 @@ void CTexture::BuildRGB5A3FromGCN(CInputStream& in) { } } - CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) { - m_booTex = ctx.newStaticTexture(x4_w, x6_h, x8_mips, boo::TextureFormat::RGBA8, boo::TextureClampMode::Repeat, - buf.get(), texelCount * 4) - .get(); - return true; - } BooTrace); + m_tex = aurora::new_static_texture_2d(x4_w, x6_h, x8_mips, aurora::shaders::TextureFormat::RGBA8, + {reinterpret_cast(buf.get()), texelCount * 4}, label); } -void CTexture::BuildRGBA8FromGCN(CInputStream& in) { +void CTexture::BuildRGBA8FromGCN(CInputStream& in, std::string_view label) { const size_t texelCount = ComputeMippedTexelCount(); std::unique_ptr buf(new RGBA8[texelCount]); @@ -514,15 +484,11 @@ void CTexture::BuildRGBA8FromGCN(CInputStream& in) { } } - CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) { - m_booTex = ctx.newStaticTexture(x4_w, x6_h, x8_mips, boo::TextureFormat::RGBA8, boo::TextureClampMode::Repeat, - buf.get(), texelCount * 4) - .get(); - return true; - } BooTrace); + m_tex = aurora::new_static_texture_2d(x4_w, x6_h, x8_mips, aurora::shaders::TextureFormat::RGBA8, + {reinterpret_cast(buf.get()), texelCount * 4}, label); } -void CTexture::BuildDXT1FromGCN(CInputStream& in) { +void CTexture::BuildDXT1FromGCN(CInputStream& in, std::string_view label) { const size_t blockCount = ComputeMippedBlockCountDXT1(); std::unique_ptr buf(new DXT1Block[blockCount]); @@ -566,48 +532,35 @@ void CTexture::BuildDXT1FromGCN(CInputStream& in) { } } - CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) { - m_booTex = ctx.newStaticTexture(x4_w, x6_h, x8_mips, boo::TextureFormat::DXT1, boo::TextureClampMode::Repeat, - buf.get(), blockCount * 8) - .get(); - return true; - } BooTrace); + m_tex = aurora::new_static_texture_2d(x4_w, x6_h, x8_mips, aurora::shaders::TextureFormat::DXT1, + {reinterpret_cast(buf.get()), blockCount * 8}, label); } -void CTexture::BuildRGBA8(const void* data, size_t length) { +void CTexture::BuildRGBA8(const void* data, size_t length, std::string_view label) { size_t texelCount = ComputeMippedTexelCount(); size_t expectedSize = texelCount * 4; if (expectedSize > length) Log.report(logvisor::Fatal, FMT_STRING("insufficient TXTR length ({}/{})"), length, expectedSize); - CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) { - m_booTex = ctx.newStaticTexture(x4_w, x6_h, x8_mips, boo::TextureFormat::RGBA8, boo::TextureClampMode::Repeat, data, - expectedSize) - .get(); - return true; - } BooTrace); + m_tex = aurora::new_static_texture_2d(x4_w, x6_h, x8_mips, aurora::shaders::TextureFormat::RGBA8, + {reinterpret_cast(data), expectedSize}, label); } -void CTexture::BuildC8(const void* data, size_t length) { +void CTexture::BuildC8(const void* data, size_t length, std::string_view label) { size_t texelCount = ComputeMippedTexelCount(); if (texelCount > length) Log.report(logvisor::Fatal, FMT_STRING("insufficient TXTR length ({}/{})"), length, texelCount); - CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) { - uint32_t nentries = hecl::SBig(*reinterpret_cast(data)); - const u8* paletteTexels = reinterpret_cast(data) + 4; - const u8* texels = reinterpret_cast(data) + 4 + nentries * 4; - m_paletteTex = ctx.newStaticTexture(nentries, 1, 1, boo::TextureFormat::RGBA8, boo::TextureClampMode::Repeat, - paletteTexels, nentries * 4) - .get(); - m_booTex = ctx.newStaticTexture(x4_w, x6_h, x8_mips, boo::TextureFormat::I8, boo::TextureClampMode::Repeat, texels, - texelCount) - .get(); - return true; - } BooTrace); + uint32_t nentries = hecl::SBig(*reinterpret_cast(data)); + const u8* paletteTexels = reinterpret_cast(data) + 4; + const u8* texels = reinterpret_cast(data) + 4 + nentries * 4; + m_paletteTex = aurora::new_static_texture_2d(nentries, 1, 1, aurora::shaders::TextureFormat::RGBA8, + {paletteTexels, nentries * 4}, label); + m_tex = aurora::new_static_texture_2d(x4_w, x6_h, x8_mips, aurora::shaders::TextureFormat::R8, {texels, texelCount}, + label); } -void CTexture::BuildC8Font(const void* data, EFontType ftype) { +void CTexture::BuildC8Font(const void* data, EFontType ftype, std::string_view label) { size_t texelCount = ComputeMippedTexelCount(); size_t layerCount = 1; @@ -697,30 +650,58 @@ void CTexture::BuildC8Font(const void* data, EFontType ftype) { h /= 2; } - CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) { - m_booTex = ctx.newStaticArrayTexture(x4_w, x6_h, layerCount, x8_mips, boo::TextureFormat::RGBA8, - boo::TextureClampMode::Repeat, buf.get(), texelCount * layerCount * 4) - .get(); - return true; - } BooTrace); + // TODO array tex + // CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) { + // m_booTex = ctx.newStaticArrayTexture(x4_w, x6_h, layerCount, x8_mips, boo::TextureFormat::RGBA8, + // boo::TextureClampMode::Repeat, buf.get(), texelCount * layerCount * 4) + // .get(); + // return true; + // } BooTrace); } -void CTexture::BuildDXT1(const void* data, size_t length) { - CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) { - m_booTex = - ctx.newStaticTexture(x4_w, x6_h, x8_mips, boo::TextureFormat::DXT1, boo::TextureClampMode::Repeat, data, length) - .get(); - return true; - } BooTrace); +void CTexture::BuildDXT1(const void* data, size_t length, std::string_view label) { + m_tex = aurora::new_static_texture_2d(x4_w, x6_h, x8_mips, aurora::shaders::TextureFormat::DXT1, + {reinterpret_cast(data), length}, label); } -void CTexture::BuildDXT3(const void* data, size_t length) { - CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) { - m_booTex = - ctx.newStaticTexture(x4_w, x6_h, x8_mips, boo::TextureFormat::DXT3, boo::TextureClampMode::Repeat, data, length) - .get(); - return true; - } BooTrace); +void CTexture::BuildDXT3(const void* data, size_t length, std::string_view label) { + m_tex = aurora::new_static_texture_2d(x4_w, x6_h, x8_mips, aurora::shaders::TextureFormat::DXT3, + {reinterpret_cast(data), length}, label); +} + +static std::string_view TextureFormatString(ETexelFormat format) { + switch (format) { + case ETexelFormat::I4: + return "I4"sv; + case ETexelFormat::I8: + return "I8"sv; + case ETexelFormat::IA4: + return "IA4"sv; + case ETexelFormat::IA8: + return "IA8"sv; + case ETexelFormat::C4: + return "C4"sv; + case ETexelFormat::C8: + return "C8"sv; + case ETexelFormat::C14X2: + return "C14X2"sv; + case ETexelFormat::RGB565: + return "RGB565"sv; + case ETexelFormat::RGB5A3: + return "RGB5A3"sv; + case ETexelFormat::RGBA8: + return "RGBA8"sv; + case ETexelFormat::CMPR: + return "CMPR"sv; + case ETexelFormat::RGBA8PC: + return "RGBA8PC"sv; + case ETexelFormat::C8PC: + return "C8PC"sv; + case ETexelFormat::CMPRPC: + return "CMPRPC"sv; + case ETexelFormat::CMPRPCA: + return "CMPRPCA"sv; + } } CTexture::CTexture(ETexelFormat fmt, s16 w, s16 h, s32 mips) : x0_fmt(fmt), x4_w(w), x6_h(h), x8_mips(mips) { @@ -731,8 +712,8 @@ CTexture::CTexture(ETexelFormat fmt, s16 w, s16 h, s32 mips) : x0_fmt(fmt), x4_w */ } -CTexture::CTexture(std::unique_ptr&& in, u32 length, bool otex, const CTextureInfo* inf) { - m_textureInfo = inf; +CTexture::CTexture(std::unique_ptr&& in, u32 length, bool otex, const CTextureInfo* inf, CAssetId id) +: m_textureInfo(inf) { std::unique_ptr owned = std::move(in); athena::io::MemoryReader r(owned.get(), length); x0_fmt = ETexelFormat(r.readUint32Big()); @@ -740,52 +721,53 @@ CTexture::CTexture(std::unique_ptr&& in, u32 length, bool otex, const CTex x6_h = r.readUint16Big(); x8_mips = r.readUint32Big(); + auto label = fmt::format(FMT_STRING("TXTR {:08X} ({})"), id.Value(), TextureFormatString(x0_fmt)); switch (x0_fmt) { case ETexelFormat::I4: - BuildI4FromGCN(r); + BuildI4FromGCN(r, label); break; case ETexelFormat::I8: - BuildI8FromGCN(r); + BuildI8FromGCN(r, label); break; case ETexelFormat::IA4: - BuildIA4FromGCN(r); + BuildIA4FromGCN(r, label); break; case ETexelFormat::IA8: - BuildIA8FromGCN(r); + BuildIA8FromGCN(r, label); break; case ETexelFormat::C4: - BuildC4FromGCN(r); + BuildC4FromGCN(r, label); break; case ETexelFormat::C8: - BuildC8FromGCN(r); + BuildC8FromGCN(r, label); break; case ETexelFormat::C14X2: - BuildC14X2FromGCN(r); + BuildC14X2FromGCN(r, label); break; case ETexelFormat::RGB565: - BuildRGB565FromGCN(r); + BuildRGB565FromGCN(r, label); break; case ETexelFormat::RGB5A3: - BuildRGB5A3FromGCN(r); + BuildRGB5A3FromGCN(r, label); break; case ETexelFormat::RGBA8: - BuildRGBA8FromGCN(r); + BuildRGBA8FromGCN(r, label); break; case ETexelFormat::CMPR: - BuildDXT1FromGCN(r); + BuildDXT1FromGCN(r, label); break; case ETexelFormat::RGBA8PC: - BuildRGBA8(owned.get() + 12, length - 12); + BuildRGBA8(owned.get() + 12, length - 12, label); break; case ETexelFormat::C8PC: - BuildC8(owned.get() + 12, length - 12); + BuildC8(owned.get() + 12, length - 12, label); otex = true; break; case ETexelFormat::CMPRPC: - BuildDXT1(owned.get() + 12, length - 12); + BuildDXT1(owned.get() + 12, length - 12, label); break; case ETexelFormat::CMPRPCA: - BuildDXT3(owned.get() + 12, length - 12); + BuildDXT3(owned.get() + 12, length - 12, label); break; default: Log.report(logvisor::Fatal, FMT_STRING("invalid texture type {} for boo"), int(x0_fmt)); @@ -881,12 +863,12 @@ std::unique_ptr CTexture::BuildMemoryCardTex(u32& sizeOut, ETexelFormat& f return ret; } -const boo::ObjToken& CTexture::GetFontTexture(EFontType tp) { +const std::shared_ptr& CTexture::GetFontTexture(EFontType tp) { if (m_ftype != tp && x0_fmt == ETexelFormat::C8PC) { m_ftype = tp; - BuildC8Font(m_otex.get() + 12, m_ftype); + BuildC8Font(m_otex.get() + 12, m_ftype, "Font (TODO)"sv); } - return m_booTex; + return m_tex; } CFactoryFnReturn FTextureFactory(const metaforce::SObjectTag& tag, std::unique_ptr&& in, u32 len, @@ -896,7 +878,7 @@ CFactoryFnReturn FTextureFactory(const metaforce::SObjectTag& tag, std::unique_p if (g_TextureCache) inf = g_TextureCache->GetTextureInfo(tag.id); return TToken::GetIObjObjectFor( - std::make_unique(std::move(in), len, u32Owned == SBIG('OTEX'), inf)); + std::make_unique(std::move(in), len, u32Owned == SBIG('OTEX'), inf, tag.id)); } } // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CAABoxShader.cpp b/Runtime/Graphics/Shaders/CAABoxShader.cpp index 6303478bc..c5720df1a 100644 --- a/Runtime/Graphics/Shaders/CAABoxShader.cpp +++ b/Runtime/Graphics/Shaders/CAABoxShader.cpp @@ -4,35 +4,35 @@ #include "Runtime/Graphics/CGraphics.hpp" -#include +//#include #include namespace metaforce { -static boo::ObjToken s_Pipeline; -static boo::ObjToken s_zOnlyPipeline; +//static boo::ObjToken s_Pipeline; +//static boo::ObjToken s_zOnlyPipeline; void CAABoxShader::Initialize() { - s_Pipeline = hecl::conv->convert(Shader_CAABoxShader{}); - s_zOnlyPipeline = hecl::conv->convert(Shader_CAABoxShaderZOnly{}); +// s_Pipeline = hecl::conv->convert(Shader_CAABoxShader{}); +// s_zOnlyPipeline = hecl::conv->convert(Shader_CAABoxShaderZOnly{}); } void CAABoxShader::Shutdown() { - s_Pipeline.reset(); - s_zOnlyPipeline.reset(); +// s_Pipeline.reset(); +// s_zOnlyPipeline.reset(); } CAABoxShader::CAABoxShader(bool zOnly) { - CGraphics::CommitResources([this, zOnly](boo::IGraphicsDataFactory::Context& ctx) { - m_vbo = ctx.newDynamicBuffer(boo::BufferUse::Vertex, sizeof(zeus::CVector3f), 34); - m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(Uniform), 1); - const std::array, 1> bufs{m_uniBuf.get()}; - constexpr std::array stages{boo::PipelineStage::Vertex}; - m_dataBind = - ctx.newShaderDataBinding(zOnly ? s_zOnlyPipeline : s_Pipeline, m_vbo.get(), nullptr, nullptr, bufs.size(), - bufs.data(), stages.data(), nullptr, nullptr, 0, nullptr, nullptr, nullptr); - return true; - } BooTrace); +// CGraphics::CommitResources([this, zOnly](boo::IGraphicsDataFactory::Context& ctx) { +// m_vbo = ctx.newDynamicBuffer(boo::BufferUse::Vertex, sizeof(zeus::CVector3f), 34); +// m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(Uniform), 1); +// const std::array, 1> bufs{m_uniBuf.get()}; +// constexpr std::array stages{boo::PipelineStage::Vertex}; +// m_dataBind = +// ctx.newShaderDataBinding(zOnly ? s_zOnlyPipeline : s_Pipeline, m_vbo.get(), nullptr, nullptr, bufs.size(), +// bufs.data(), stages.data(), nullptr, nullptr, 0, nullptr, nullptr, nullptr); +// return true; +// } BooTrace); } void CAABoxShader::setAABB(const zeus::CAABox& aabb) { @@ -62,7 +62,7 @@ void CAABoxShader::setAABB(const zeus::CAABox& aabb) { {aabb.max.x(), aabb.max.y(), aabb.min.z()}, }}; - m_vbo->load(vboData.data(), sizeof(vboData)); +// m_vbo->load(vboData.data(), sizeof(vboData)); } void CAABoxShader::draw(const zeus::CColor& color) { @@ -70,10 +70,10 @@ void CAABoxShader::draw(const zeus::CColor& color) { m_uniform.m_xf = CGraphics::GetPerspectiveProjectionMatrix(true) * CGraphics::g_GXModelView.toMatrix4f(); m_uniform.m_color = color; - m_uniBuf->load(&m_uniform, sizeof(Uniform)); - - CGraphics::SetShaderDataBinding(m_dataBind); - CGraphics::DrawArray(0, 34); +// m_uniBuf->load(&m_uniform, sizeof(Uniform)); +// +// CGraphics::SetShaderDataBinding(m_dataBind); +// CGraphics::DrawArray(0, 34); } } // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CAABoxShader.hpp b/Runtime/Graphics/Shaders/CAABoxShader.hpp index 831a58234..ec201302c 100644 --- a/Runtime/Graphics/Shaders/CAABoxShader.hpp +++ b/Runtime/Graphics/Shaders/CAABoxShader.hpp @@ -1,6 +1,6 @@ #pragma once -#include +//#include #include #include @@ -16,9 +16,9 @@ class CAABoxShader { zeus::CMatrix4f m_xf; zeus::CColor m_color; }; - boo::ObjToken m_vbo; - boo::ObjToken m_uniBuf; - boo::ObjToken m_dataBind; +// boo::ObjToken m_vbo; +// boo::ObjToken m_uniBuf; +// boo::ObjToken m_dataBind; Uniform m_uniform; public: diff --git a/Runtime/Graphics/Shaders/CCameraBlurFilter.cpp b/Runtime/Graphics/Shaders/CCameraBlurFilter.cpp index 341ac9afe..d92eb8c18 100644 --- a/Runtime/Graphics/Shaders/CCameraBlurFilter.cpp +++ b/Runtime/Graphics/Shaders/CCameraBlurFilter.cpp @@ -6,7 +6,7 @@ #include "Runtime/Graphics/CGraphics.hpp" -#include +//#include #include namespace metaforce { @@ -16,24 +16,28 @@ struct Vert { zeus::CVector2f m_uv; }; -boo::ObjToken s_Pipeline; +//boo::ObjToken s_Pipeline; } // Anonymous namespace -void CCameraBlurFilter::Initialize() { s_Pipeline = hecl::conv->convert(Shader_CCameraBlurFilter{}); } +void CCameraBlurFilter::Initialize() { +// s_Pipeline = hecl::conv->convert(Shader_CCameraBlurFilter{}); +} -void CCameraBlurFilter::Shutdown() { s_Pipeline.reset(); } +void CCameraBlurFilter::Shutdown() { +// s_Pipeline.reset(); +} CCameraBlurFilter::CCameraBlurFilter() { - CGraphics::CommitResources([this](boo::IGraphicsDataFactory::Context& ctx) { - m_vbo = ctx.newDynamicBuffer(boo::BufferUse::Vertex, 32, 4); - m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(Uniform), 1); - const std::array, 1> bufs{m_uniBuf.get()}; - constexpr std::array stages{boo::PipelineStage::Vertex}; - const std::array, 1> texs{CGraphics::g_SpareTexture.get()}; - m_dataBind = ctx.newShaderDataBinding(s_Pipeline, m_vbo.get(), nullptr, nullptr, bufs.size(), bufs.data(), - stages.data(), nullptr, nullptr, texs.size(), texs.data(), nullptr, nullptr); - return true; - } BooTrace); +// CGraphics::CommitResources([this](boo::IGraphicsDataFactory::Context& ctx) { +// m_vbo = ctx.newDynamicBuffer(boo::BufferUse::Vertex, 32, 4); +// m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(Uniform), 1); +// const std::array, 1> bufs{m_uniBuf.get()}; +// constexpr std::array stages{boo::PipelineStage::Vertex}; +// const std::array, 1> texs{CGraphics::g_SpareTexture.get()}; +// m_dataBind = ctx.newShaderDataBinding(s_Pipeline, m_vbo.get(), nullptr, nullptr, bufs.size(), bufs.data(), +// stages.data(), nullptr, nullptr, texs.size(), texs.data(), nullptr, nullptr); +// return true; +// } BooTrace); } void CCameraBlurFilter::draw(float amount, bool clearDepth) { @@ -58,7 +62,7 @@ void CCameraBlurFilter::draw(float amount, bool clearDepth) { {{1.0, -1.0}, {xBias + xFac, yBias}}, {{1.0, 1.0}, {xBias + xFac, yBias + yFac}}, }}; - m_vbo->load(verts.data(), sizeof(verts)); +// m_vbo->load(verts.data(), sizeof(verts)); for (size_t i = 0; i < m_uniform.m_uv.size(); ++i) { auto tmp = static_cast(i); @@ -75,10 +79,10 @@ void CCameraBlurFilter::draw(float amount, bool clearDepth) { m_uniform.m_uv[i][1] = amtY * yFac; } m_uniform.m_opacity = std::min(amount / 2.f, 1.f); - m_uniBuf->load(&m_uniform, sizeof(m_uniform)); +// m_uniBuf->load(&m_uniform, sizeof(m_uniform)); - CGraphics::SetShaderDataBinding(m_dataBind); - CGraphics::DrawArray(0, 4); +// CGraphics::SetShaderDataBinding(m_dataBind); +// CGraphics::DrawArray(0, 4); } } // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CCameraBlurFilter.hpp b/Runtime/Graphics/Shaders/CCameraBlurFilter.hpp index 0c1235b43..46fe2dc03 100644 --- a/Runtime/Graphics/Shaders/CCameraBlurFilter.hpp +++ b/Runtime/Graphics/Shaders/CCameraBlurFilter.hpp @@ -1,7 +1,7 @@ #pragma once #include -#include +//#include #include namespace metaforce { @@ -12,9 +12,9 @@ class CCameraBlurFilter { float m_opacity = 1.f; }; - boo::ObjToken m_vbo; - boo::ObjToken m_uniBuf; - boo::ObjToken m_dataBind; +// boo::ObjToken m_vbo; +// boo::ObjToken m_uniBuf; +// boo::ObjToken m_dataBind; Uniform m_uniform; public: diff --git a/Runtime/Graphics/Shaders/CColoredQuadFilter.cpp b/Runtime/Graphics/Shaders/CColoredQuadFilter.cpp index da9b3c921..161e58da6 100644 --- a/Runtime/Graphics/Shaders/CColoredQuadFilter.cpp +++ b/Runtime/Graphics/Shaders/CColoredQuadFilter.cpp @@ -5,61 +5,61 @@ #include "Runtime/Camera/CCameraFilter.hpp" #include "Runtime/Graphics/CGraphics.hpp" -#include +//#include namespace metaforce { -static boo::ObjToken s_AlphaPipeline; -static boo::ObjToken s_AddPipeline; -static boo::ObjToken s_MultPipeline; +//static boo::ObjToken s_AlphaPipeline; +//static boo::ObjToken s_AddPipeline; +//static boo::ObjToken s_MultPipeline; void CColoredQuadFilter::Initialize() { - s_AlphaPipeline = hecl::conv->convert(Shader_CColoredQuadFilter{}); - s_AddPipeline = hecl::conv->convert(Shader_CColoredQuadFilterAdd{}); - s_MultPipeline = hecl::conv->convert(Shader_CColoredQuadFilterMul{}); +// s_AlphaPipeline = hecl::conv->convert(Shader_CColoredQuadFilter{}); +// s_AddPipeline = hecl::conv->convert(Shader_CColoredQuadFilterAdd{}); +// s_MultPipeline = hecl::conv->convert(Shader_CColoredQuadFilterMul{}); } void CColoredQuadFilter::Shutdown() { - s_AlphaPipeline.reset(); - s_AddPipeline.reset(); - s_MultPipeline.reset(); +// s_AlphaPipeline.reset(); +// s_AddPipeline.reset(); +// s_MultPipeline.reset(); } -static boo::ObjToken SelectPipeline(EFilterType type) { - switch (type) { - case EFilterType::Blend: - return s_AlphaPipeline; - case EFilterType::Add: - return s_AddPipeline; - case EFilterType::Multiply: - return s_MultPipeline; - default: - return s_AlphaPipeline; - } -} +//static boo::ObjToken SelectPipeline(EFilterType type) { +// switch (type) { +// case EFilterType::Blend: +// return s_AlphaPipeline; +// case EFilterType::Add: +// return s_AddPipeline; +// case EFilterType::Multiply: +// return s_MultPipeline; +// default: +// return s_AlphaPipeline; +// } +//} CColoredQuadFilter::CColoredQuadFilter(EFilterType type) { - CGraphics::CommitResources([this, type](boo::IGraphicsDataFactory::Context& ctx) { - struct Vert { - zeus::CVector2f m_pos; - }; - - const std::array verts{{ - {{0.0, 0.0}}, - {{0.0, 1.0}}, - {{1.0, 0.0}}, - {{1.0, 1.0}}, - }}; - - m_vbo = ctx.newStaticBuffer(boo::BufferUse::Vertex, verts.data(), 16, verts.size()); - m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(Uniform), 1); - - const std::array, 1> bufs{m_uniBuf.get()}; - constexpr std::array stages{boo::PipelineStage::Vertex}; - m_dataBind = ctx.newShaderDataBinding(SelectPipeline(type), m_vbo.get(), nullptr, nullptr, bufs.size(), bufs.data(), - stages.data(), nullptr, nullptr, 0, nullptr, nullptr, nullptr); - return true; - } BooTrace); +// CGraphics::CommitResources([this, type](boo::IGraphicsDataFactory::Context& ctx) { +// struct Vert { +// zeus::CVector2f m_pos; +// }; +// +// const std::array verts{{ +// {{0.0, 0.0}}, +// {{0.0, 1.0}}, +// {{1.0, 0.0}}, +// {{1.0, 1.0}}, +// }}; +// +// m_vbo = ctx.newStaticBuffer(boo::BufferUse::Vertex, verts.data(), 16, verts.size()); +// m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(Uniform), 1); +// +// const std::array, 1> bufs{m_uniBuf.get()}; +// constexpr std::array stages{boo::PipelineStage::Vertex}; +// m_dataBind = ctx.newShaderDataBinding(SelectPipeline(type), m_vbo.get(), nullptr, nullptr, bufs.size(), bufs.data(), +// stages.data(), nullptr, nullptr, 0, nullptr, nullptr, nullptr); +// return true; +// } BooTrace); } void CColoredQuadFilter::draw(const zeus::CColor& color, const zeus::CRectangle& rect) { @@ -70,10 +70,10 @@ void CColoredQuadFilter::draw(const zeus::CColor& color, const zeus::CRectangle& m_uniform.m_matrix[3][0] = rect.position.x() * 2.f - 1.f; m_uniform.m_matrix[3][1] = rect.position.y() * 2.f - 1.f; m_uniform.m_color = color; - m_uniBuf->load(&m_uniform, sizeof(m_uniform)); - - CGraphics::SetShaderDataBinding(m_dataBind); - CGraphics::DrawArray(0, 4); +// m_uniBuf->load(&m_uniform, sizeof(m_uniform)); +// +// CGraphics::SetShaderDataBinding(m_dataBind); +// CGraphics::DrawArray(0, 4); } void CWideScreenFilter::draw(const zeus::CColor& color, float t) { @@ -92,12 +92,12 @@ float CWideScreenFilter::SetViewportToMatch(float t) { if (g_Viewport.aspect < 1.7777f) { float targetHeight = g_Viewport.x8_width / 1.7777f; float delta = (g_Viewport.xc_height - targetHeight) * t / 2.f; - boo::SWindowRect rect = {}; - rect.size[0] = g_Viewport.x8_width; - rect.size[1] = g_Viewport.xc_height - delta * 2.f; - rect.location[1] = delta; - CGraphics::g_CroppedViewport = rect; - CGraphics::g_BooMainCommandQueue->setViewport(rect); +// boo::SWindowRect rect = {}; +// rect.size[0] = g_Viewport.x8_width; +// rect.size[1] = g_Viewport.xc_height - delta * 2.f; +// rect.location[1] = delta; +// CGraphics::g_CroppedViewport = rect; +// CGraphics::g_BooMainCommandQueue->setViewport(rect); return 1.7777f; } else { SetViewportToFull(); @@ -106,11 +106,11 @@ float CWideScreenFilter::SetViewportToMatch(float t) { } void CWideScreenFilter::SetViewportToFull() { - boo::SWindowRect rect = {}; - rect.size[0] = g_Viewport.x8_width; - rect.size[1] = g_Viewport.xc_height; - CGraphics::g_CroppedViewport = rect; - CGraphics::g_BooMainCommandQueue->setViewport(rect); +// boo::SWindowRect rect = {}; +// rect.size[0] = g_Viewport.x8_width; +// rect.size[1] = g_Viewport.xc_height; +// CGraphics::g_CroppedViewport = rect; +// CGraphics::g_BooMainCommandQueue->setViewport(rect); } } // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CColoredQuadFilter.hpp b/Runtime/Graphics/Shaders/CColoredQuadFilter.hpp index 388be7ce6..76d30f20c 100644 --- a/Runtime/Graphics/Shaders/CColoredQuadFilter.hpp +++ b/Runtime/Graphics/Shaders/CColoredQuadFilter.hpp @@ -2,7 +2,7 @@ #include "Runtime/CToken.hpp" -#include +//#include #include #include @@ -19,9 +19,9 @@ class CColoredQuadFilter { zeus::CMatrix4f m_matrix; zeus::CColor m_color; }; - boo::ObjToken m_vbo; - boo::ObjToken m_uniBuf; - boo::ObjToken m_dataBind; +// boo::ObjToken m_vbo; +// boo::ObjToken m_uniBuf; +// boo::ObjToken m_dataBind; Uniform m_uniform; public: diff --git a/Runtime/Graphics/Shaders/CColoredStripShader.cpp b/Runtime/Graphics/Shaders/CColoredStripShader.cpp index 1c2c8f716..5413cd540 100644 --- a/Runtime/Graphics/Shaders/CColoredStripShader.cpp +++ b/Runtime/Graphics/Shaders/CColoredStripShader.cpp @@ -6,84 +6,79 @@ #include "Runtime/Graphics/CBooRenderer.hpp" #include "Runtime/Graphics/CGraphics.hpp" -#include +//#include namespace metaforce { -static boo::ObjToken s_Pipeline; -static boo::ObjToken s_AdditivePipeline; -static boo::ObjToken s_FullAdditivePipeline; -static boo::ObjToken s_SubtractivePipeline; +//static boo::ObjToken s_Pipeline; +//static boo::ObjToken s_AdditivePipeline; +//static boo::ObjToken s_FullAdditivePipeline; +//static boo::ObjToken s_SubtractivePipeline; void CColoredStripShader::Initialize() { - s_Pipeline = hecl::conv->convert(Shader_CColoredStripShader{}); - s_AdditivePipeline = hecl::conv->convert(Shader_CColoredStripShaderAdditive{}); - s_FullAdditivePipeline = hecl::conv->convert(Shader_CColoredStripShaderFullAdditive{}); - s_SubtractivePipeline = hecl::conv->convert(Shader_CColoredStripShaderSubtractive{}); +// s_Pipeline = hecl::conv->convert(Shader_CColoredStripShader{}); +// s_AdditivePipeline = hecl::conv->convert(Shader_CColoredStripShaderAdditive{}); +// s_FullAdditivePipeline = hecl::conv->convert(Shader_CColoredStripShaderFullAdditive{}); +// s_SubtractivePipeline = hecl::conv->convert(Shader_CColoredStripShaderSubtractive{}); } void CColoredStripShader::Shutdown() { - s_Pipeline.reset(); - s_AdditivePipeline.reset(); - s_FullAdditivePipeline.reset(); - s_SubtractivePipeline.reset(); +// s_Pipeline.reset(); +// s_AdditivePipeline.reset(); +// s_FullAdditivePipeline.reset(); +// s_SubtractivePipeline.reset(); } -static const boo::ObjToken& SelectPipeline(CColoredStripShader::Mode mode) { - switch (mode) { - case CColoredStripShader::Mode::Alpha: - default: - return s_Pipeline; - case CColoredStripShader::Mode::Additive: - return s_AdditivePipeline; - case CColoredStripShader::Mode::FullAdditive: - return s_FullAdditivePipeline; - case CColoredStripShader::Mode::Subtractive: - return s_SubtractivePipeline; - } -} +//static const boo::ObjToken& SelectPipeline(CColoredStripShader::Mode mode) { +// switch (mode) { +// case CColoredStripShader::Mode::Alpha: +// default: +// return s_Pipeline; +// case CColoredStripShader::Mode::Additive: +// return s_AdditivePipeline; +// case CColoredStripShader::Mode::FullAdditive: +// return s_FullAdditivePipeline; +// case CColoredStripShader::Mode::Subtractive: +// return s_SubtractivePipeline; +// } +//} +// +//void CColoredStripShader::BuildResources(boo::IGraphicsDataFactory::Context& ctx, size_t maxVerts, Mode mode, +// boo::ObjToken tex) { +// m_vbo = ctx.newDynamicBuffer(boo::BufferUse::Vertex, sizeof(Vert), maxVerts); +// m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(Uniform), 1); +// +// const std::array, 1> bufs{m_uniBuf.get()}; +// constexpr std::array stages{boo::PipelineStage::Vertex}; +// std::array, 1> texs; +// if (tex) { +// texs[0] = tex; +// } else { +// texs[0] = g_Renderer->GetWhiteTexture(); +// } +// +// m_dataBind = ctx.newShaderDataBinding(SelectPipeline(mode), m_vbo.get(), nullptr, nullptr, bufs.size(), bufs.data(), +// stages.data(), nullptr, nullptr, texs.size(), texs.data(), nullptr, nullptr); +//} -void CColoredStripShader::BuildResources(boo::IGraphicsDataFactory::Context& ctx, size_t maxVerts, Mode mode, - boo::ObjToken tex) { - m_vbo = ctx.newDynamicBuffer(boo::BufferUse::Vertex, sizeof(Vert), maxVerts); - m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(Uniform), 1); - - const std::array, 1> bufs{m_uniBuf.get()}; - constexpr std::array stages{boo::PipelineStage::Vertex}; - std::array, 1> texs; - if (tex) { - texs[0] = tex; - } else { - texs[0] = g_Renderer->GetWhiteTexture(); - } - - m_dataBind = ctx.newShaderDataBinding(SelectPipeline(mode), m_vbo.get(), nullptr, nullptr, bufs.size(), bufs.data(), - stages.data(), nullptr, nullptr, texs.size(), texs.data(), nullptr, nullptr); -} - -CColoredStripShader::CColoredStripShader(size_t maxVerts, Mode mode, boo::ObjToken tex) { - CGraphics::CommitResources([this, maxVerts, mode, tex](boo::IGraphicsDataFactory::Context& ctx) { - BuildResources(ctx, maxVerts, mode, tex); - return true; - } BooTrace); -} - -CColoredStripShader::CColoredStripShader(boo::IGraphicsDataFactory::Context& ctx, size_t maxVerts, Mode mode, - boo::ObjToken tex) { - BuildResources(ctx, maxVerts, mode, tex); +CColoredStripShader::CColoredStripShader(size_t maxVerts, Mode mode, std::shared_ptr tex) { +// CGraphics::CommitResources([this, maxVerts, mode, tex](boo::IGraphicsDataFactory::Context& ctx) { +// BuildResources(ctx, maxVerts, mode, tex); +// return true; +// } BooTrace); } void CColoredStripShader::draw(const zeus::CColor& color, size_t numVerts, const Vert* verts) { SCOPED_GRAPHICS_DEBUG_GROUP("CColoredStripShader::draw", zeus::skMagenta); - m_vbo->load(verts, sizeof(Vert) * numVerts); +// m_vbo->load(verts, sizeof(Vert) * numVerts); m_uniform.m_matrix = CGraphics::GetPerspectiveProjectionMatrix(true) * CGraphics::g_GXModelView.toMatrix4f(); m_uniform.m_color = color; - m_uniBuf->load(&m_uniform, sizeof(m_uniform)); - - CGraphics::SetShaderDataBinding(m_dataBind); - CGraphics::DrawArray(0, numVerts); +// m_uniBuf->load(&m_uniform, sizeof(m_uniform)); +// +// CGraphics::SetShaderDataBinding(m_dataBind); +// CGraphics::DrawArray(0, numVerts); } } // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CColoredStripShader.hpp b/Runtime/Graphics/Shaders/CColoredStripShader.hpp index 620f7fdc6..62f7bafed 100644 --- a/Runtime/Graphics/Shaders/CColoredStripShader.hpp +++ b/Runtime/Graphics/Shaders/CColoredStripShader.hpp @@ -1,6 +1,6 @@ #pragma once -#include +#include "Runtime/Graphics/CGraphics.hpp" #include #include @@ -16,13 +16,13 @@ private: zeus::CMatrix4f m_matrix; zeus::CColor m_color; }; - boo::ObjToken m_vbo; - boo::ObjToken m_uniBuf; - boo::ObjToken m_dataBind; +// boo::ObjToken m_vbo; +// boo::ObjToken m_uniBuf; +// boo::ObjToken m_dataBind; Uniform m_uniform; - void BuildResources(boo::IGraphicsDataFactory::Context& ctx, size_t maxVerts, Mode mode, - boo::ObjToken tex); +// void BuildResources(boo::IGraphicsDataFactory::Context& ctx, size_t maxVerts, Mode mode, +// boo::ObjToken tex); public: struct Vert { @@ -32,9 +32,7 @@ public: }; static void Initialize(); static void Shutdown(); - CColoredStripShader(size_t maxVerts, Mode mode, boo::ObjToken tex); - CColoredStripShader(boo::IGraphicsDataFactory::Context& ctx, size_t maxVerts, Mode mode, - boo::ObjToken tex); + CColoredStripShader(size_t maxVerts, Mode mode, std::shared_ptr tex); void draw(const zeus::CColor& color, size_t numVerts, const Vert* verts); }; diff --git a/Runtime/Graphics/Shaders/CDecalShaders.cpp b/Runtime/Graphics/Shaders/CDecalShaders.cpp index 28c0d45db..47c8d62a2 100644 --- a/Runtime/Graphics/Shaders/CDecalShaders.cpp +++ b/Runtime/Graphics/Shaders/CDecalShaders.cpp @@ -4,69 +4,69 @@ #include "Runtime/Particle/CDecal.hpp" -#include +//#include namespace metaforce { void CDecalShaders::Initialize() { - m_texZTestNoZWrite = hecl::conv->convert(Shader_CDecalShaderTexZTest{}); - m_texAdditiveZTest = hecl::conv->convert(Shader_CDecalShaderTexAdditiveZTest{}); - m_texRedToAlphaZTest = hecl::conv->convert(Shader_CDecalShaderTexRedToAlphaZTest{}); - m_noTexZTestNoZWrite = hecl::conv->convert(Shader_CDecalShaderNoTexZTest{}); - m_noTexAdditiveZTest = hecl::conv->convert(Shader_CDecalShaderNoTexAdditiveZTest{}); +// m_texZTestNoZWrite = hecl::conv->convert(Shader_CDecalShaderTexZTest{}); +// m_texAdditiveZTest = hecl::conv->convert(Shader_CDecalShaderTexAdditiveZTest{}); +// m_texRedToAlphaZTest = hecl::conv->convert(Shader_CDecalShaderTexRedToAlphaZTest{}); +// m_noTexZTestNoZWrite = hecl::conv->convert(Shader_CDecalShaderNoTexZTest{}); +// m_noTexAdditiveZTest = hecl::conv->convert(Shader_CDecalShaderNoTexAdditiveZTest{}); } void CDecalShaders::Shutdown() { - m_texZTestNoZWrite.reset(); - m_texAdditiveZTest.reset(); - m_texRedToAlphaZTest.reset(); - m_noTexZTestNoZWrite.reset(); - m_noTexAdditiveZTest.reset(); +// m_texZTestNoZWrite.reset(); +// m_texAdditiveZTest.reset(); +// m_texRedToAlphaZTest.reset(); +// m_noTexZTestNoZWrite.reset(); +// m_noTexAdditiveZTest.reset(); } -void CDecalShaders::BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, CQuadDecal& decal) { - boo::ObjToken regPipeline; - boo::ObjToken redToAlphaPipeline; +void CDecalShaders::BuildShaderDataBinding(CQuadDecal& decal) { +// boo::ObjToken regPipeline; +// boo::ObjToken redToAlphaPipeline; - if (decal.m_desc->x14_TEX) { - if (decal.m_desc->x18_ADD) - regPipeline = m_texAdditiveZTest; - else - regPipeline = m_texZTestNoZWrite; - redToAlphaPipeline = m_texRedToAlphaZTest; - } else { - if (decal.m_desc->x18_ADD) - regPipeline = m_noTexAdditiveZTest; - else - regPipeline = m_noTexZTestNoZWrite; - } - - const SQuadDescr* const desc = decal.m_desc; - const CUVElement* const texr = desc->x14_TEX.get(); - size_t texCount = 0; - std::array, 1> textures; - - if (texr != nullptr) { - textures[0] = texr->GetValueTexture(0).GetObj()->GetBooTexture(); - texCount = 1; - } - - if (!decal.m_instBuf) { - return; - } - - std::array, 1> uniforms{decal.m_uniformBuf.get()}; - - if (regPipeline) { - decal.m_normalDataBind = - ctx.newShaderDataBinding(regPipeline, nullptr, decal.m_instBuf.get(), nullptr, uniforms.size(), uniforms.data(), - nullptr, texCount, textures.data(), nullptr, nullptr); - } - if (redToAlphaPipeline) { - decal.m_redToAlphaDataBind = - ctx.newShaderDataBinding(redToAlphaPipeline, nullptr, decal.m_instBuf.get(), nullptr, uniforms.size(), - uniforms.data(), nullptr, texCount, textures.data(), nullptr, nullptr); - } +// if (decal.m_desc->x14_TEX) { +// if (decal.m_desc->x18_ADD) +// regPipeline = m_texAdditiveZTest; +// else +// regPipeline = m_texZTestNoZWrite; +// redToAlphaPipeline = m_texRedToAlphaZTest; +// } else { +// if (decal.m_desc->x18_ADD) +// regPipeline = m_noTexAdditiveZTest; +// else +// regPipeline = m_noTexZTestNoZWrite; +// } +// +// const SQuadDescr* const desc = decal.m_desc; +// const CUVElement* const texr = desc->x14_TEX.get(); +// size_t texCount = 0; +// std::array, 1> textures; +// +// if (texr != nullptr) { +// textures[0] = texr->GetValueTexture(0).GetObj()->GetBooTexture(); +// texCount = 1; +// } +// +// if (!decal.m_instBuf) { +// return; +// } +// +// std::array, 1> uniforms{decal.m_uniformBuf.get()}; +// +// if (regPipeline) { +// decal.m_normalDataBind = +// ctx.newShaderDataBinding(regPipeline, nullptr, decal.m_instBuf.get(), nullptr, uniforms.size(), uniforms.data(), +// nullptr, texCount, textures.data(), nullptr, nullptr); +// } +// if (redToAlphaPipeline) { +// decal.m_redToAlphaDataBind = +// ctx.newShaderDataBinding(redToAlphaPipeline, nullptr, decal.m_instBuf.get(), nullptr, uniforms.size(), +// uniforms.data(), nullptr, texCount, textures.data(), nullptr, nullptr); +// } } } // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CDecalShaders.hpp b/Runtime/Graphics/Shaders/CDecalShaders.hpp index 32a402961..53cde90f4 100644 --- a/Runtime/Graphics/Shaders/CDecalShaders.hpp +++ b/Runtime/Graphics/Shaders/CDecalShaders.hpp @@ -1,23 +1,23 @@ #pragma once -#include +//#include namespace metaforce { struct CQuadDecal; class CDecalShaders { private: - static inline boo::ObjToken m_texZTestNoZWrite; - static inline boo::ObjToken m_texAdditiveZTest; - static inline boo::ObjToken m_texRedToAlphaZTest; - - static inline boo::ObjToken m_noTexZTestNoZWrite; - static inline boo::ObjToken m_noTexAdditiveZTest; +// static inline boo::ObjToken m_texZTestNoZWrite; +// static inline boo::ObjToken m_texAdditiveZTest; +// static inline boo::ObjToken m_texRedToAlphaZTest; +// +// static inline boo::ObjToken m_noTexZTestNoZWrite; +// static inline boo::ObjToken m_noTexAdditiveZTest; public: static void Initialize(); static void Shutdown(); - static void BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, CQuadDecal& decal); + static void BuildShaderDataBinding(CQuadDecal& decal); }; } // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CElementGenShaders.cpp b/Runtime/Graphics/Shaders/CElementGenShaders.cpp index 1648b88bb..90f39c69e 100644 --- a/Runtime/Graphics/Shaders/CElementGenShaders.cpp +++ b/Runtime/Graphics/Shaders/CElementGenShaders.cpp @@ -4,116 +4,116 @@ #include "Runtime/Particle/CElementGen.hpp" -#include +//#include namespace metaforce { void CElementGenShaders::Initialize() { - m_texZTestZWrite = {hecl::conv->convert(Shader_CElementGenShaderTexZTestZWrite{}), - hecl::conv->convert(Shader_CElementGenShaderTexZTestZWrite{})}; - m_texNoZTestZWrite = {hecl::conv->convert(Shader_CElementGenShaderTexNoZTestZWrite{}), - hecl::conv->convert(Shader_CElementGenShaderTexNoZTestZWriteAWrite{})}; - m_texZTestNoZWrite = {hecl::conv->convert(Shader_CElementGenShaderTexZTestNoZWrite{}), - hecl::conv->convert(Shader_CElementGenShaderTexZTestNoZWriteAWrite{})}; - m_texNoZTestNoZWrite = {hecl::conv->convert(Shader_CElementGenShaderTexNoZTestNoZWrite{}), - hecl::conv->convert(Shader_CElementGenShaderTexNoZTestNoZWriteAWrite{})}; - m_texAdditiveZTest = {hecl::conv->convert(Shader_CElementGenShaderTexAdditiveZTest{}), - hecl::conv->convert(Shader_CElementGenShaderTexAdditiveZTestAWrite{})}; - m_texAdditiveNoZTest = {hecl::conv->convert(Shader_CElementGenShaderTexAdditiveNoZTest{}), - hecl::conv->convert(Shader_CElementGenShaderTexAdditiveNoZTestAWrite{})}; - m_texRedToAlphaZTest = {hecl::conv->convert(Shader_CElementGenShaderTexRedToAlphaZTest{}), - hecl::conv->convert(Shader_CElementGenShaderTexRedToAlphaZTestAWrite{})}; - m_texRedToAlphaNoZTest = {hecl::conv->convert(Shader_CElementGenShaderTexRedToAlphaNoZTest{}), - hecl::conv->convert(Shader_CElementGenShaderTexRedToAlphaNoZTestAWrite{})}; - m_texZTestNoZWriteSub = {hecl::conv->convert(Shader_CElementGenShaderTexZTestNoZWriteSub{}), - hecl::conv->convert(Shader_CElementGenShaderTexZTestNoZWriteSubAWrite{})}; - m_texNoZTestNoZWriteSub = {hecl::conv->convert(Shader_CElementGenShaderTexNoZTestNoZWriteSub{}), - hecl::conv->convert(Shader_CElementGenShaderTexNoZTestNoZWriteSubAWrite{})}; - m_texRedToAlphaZTestSub = {hecl::conv->convert(Shader_CElementGenShaderTexRedToAlphaZTestSub{}), - hecl::conv->convert(Shader_CElementGenShaderTexRedToAlphaZTestSubAWrite{})}; - m_texRedToAlphaNoZTestSub = {hecl::conv->convert(Shader_CElementGenShaderTexRedToAlphaNoZTestSub{}), - hecl::conv->convert(Shader_CElementGenShaderTexRedToAlphaNoZTestSubAWrite{})}; - - m_indTexZWrite = {hecl::conv->convert(Shader_CElementGenShaderIndTexZWrite{}), - hecl::conv->convert(Shader_CElementGenShaderIndTexZWriteAWrite{})}; - m_indTexNoZWrite = {hecl::conv->convert(Shader_CElementGenShaderIndTexNoZWrite{}), - hecl::conv->convert(Shader_CElementGenShaderIndTexNoZWriteAWrite{})}; - m_indTexAdditive = {hecl::conv->convert(Shader_CElementGenShaderIndTexAdditive{}), - hecl::conv->convert(Shader_CElementGenShaderIndTexAdditiveAWrite{})}; - - m_cindTexZWrite = {hecl::conv->convert(Shader_CElementGenShaderCindTexZWrite{}), - hecl::conv->convert(Shader_CElementGenShaderCindTexZWriteAWrite{})}; - m_cindTexNoZWrite = {hecl::conv->convert(Shader_CElementGenShaderCindTexNoZWrite{}), - hecl::conv->convert(Shader_CElementGenShaderCindTexNoZWriteAWrite{})}; - m_cindTexAdditive = {hecl::conv->convert(Shader_CElementGenShaderCindTexAdditive{}), - hecl::conv->convert(Shader_CElementGenShaderCindTexAdditiveAWrite{})}; - - m_noTexZTestZWrite = {hecl::conv->convert(Shader_CElementGenShaderNoTexZTestZWrite{}), - hecl::conv->convert(Shader_CElementGenShaderNoTexZTestZWriteAWrite{})}; - m_noTexNoZTestZWrite = {hecl::conv->convert(Shader_CElementGenShaderNoTexNoZTestZWrite{}), - hecl::conv->convert(Shader_CElementGenShaderNoTexNoZTestZWriteAWrite{})}; - m_noTexZTestNoZWrite = {hecl::conv->convert(Shader_CElementGenShaderNoTexZTestNoZWrite{}), - hecl::conv->convert(Shader_CElementGenShaderNoTexZTestNoZWriteAWrite{})}; - m_noTexNoZTestNoZWrite = {hecl::conv->convert(Shader_CElementGenShaderNoTexNoZTestNoZWrite{}), - hecl::conv->convert(Shader_CElementGenShaderNoTexNoZTestNoZWriteAWrite{})}; - m_noTexAdditiveZTest = {hecl::conv->convert(Shader_CElementGenShaderNoTexAdditiveZTest{}), - hecl::conv->convert(Shader_CElementGenShaderNoTexAdditiveZTestAWrite{})}; - m_noTexAdditiveNoZTest = {hecl::conv->convert(Shader_CElementGenShaderNoTexAdditiveNoZTest{}), - hecl::conv->convert(Shader_CElementGenShaderNoTexAdditiveNoZTestAWrite{})}; +// m_texZTestZWrite = {hecl::conv->convert(Shader_CElementGenShaderTexZTestZWrite{}), +// hecl::conv->convert(Shader_CElementGenShaderTexZTestZWrite{})}; +// m_texNoZTestZWrite = {hecl::conv->convert(Shader_CElementGenShaderTexNoZTestZWrite{}), +// hecl::conv->convert(Shader_CElementGenShaderTexNoZTestZWriteAWrite{})}; +// m_texZTestNoZWrite = {hecl::conv->convert(Shader_CElementGenShaderTexZTestNoZWrite{}), +// hecl::conv->convert(Shader_CElementGenShaderTexZTestNoZWriteAWrite{})}; +// m_texNoZTestNoZWrite = {hecl::conv->convert(Shader_CElementGenShaderTexNoZTestNoZWrite{}), +// hecl::conv->convert(Shader_CElementGenShaderTexNoZTestNoZWriteAWrite{})}; +// m_texAdditiveZTest = {hecl::conv->convert(Shader_CElementGenShaderTexAdditiveZTest{}), +// hecl::conv->convert(Shader_CElementGenShaderTexAdditiveZTestAWrite{})}; +// m_texAdditiveNoZTest = {hecl::conv->convert(Shader_CElementGenShaderTexAdditiveNoZTest{}), +// hecl::conv->convert(Shader_CElementGenShaderTexAdditiveNoZTestAWrite{})}; +// m_texRedToAlphaZTest = {hecl::conv->convert(Shader_CElementGenShaderTexRedToAlphaZTest{}), +// hecl::conv->convert(Shader_CElementGenShaderTexRedToAlphaZTestAWrite{})}; +// m_texRedToAlphaNoZTest = {hecl::conv->convert(Shader_CElementGenShaderTexRedToAlphaNoZTest{}), +// hecl::conv->convert(Shader_CElementGenShaderTexRedToAlphaNoZTestAWrite{})}; +// m_texZTestNoZWriteSub = {hecl::conv->convert(Shader_CElementGenShaderTexZTestNoZWriteSub{}), +// hecl::conv->convert(Shader_CElementGenShaderTexZTestNoZWriteSubAWrite{})}; +// m_texNoZTestNoZWriteSub = {hecl::conv->convert(Shader_CElementGenShaderTexNoZTestNoZWriteSub{}), +// hecl::conv->convert(Shader_CElementGenShaderTexNoZTestNoZWriteSubAWrite{})}; +// m_texRedToAlphaZTestSub = {hecl::conv->convert(Shader_CElementGenShaderTexRedToAlphaZTestSub{}), +// hecl::conv->convert(Shader_CElementGenShaderTexRedToAlphaZTestSubAWrite{})}; +// m_texRedToAlphaNoZTestSub = {hecl::conv->convert(Shader_CElementGenShaderTexRedToAlphaNoZTestSub{}), +// hecl::conv->convert(Shader_CElementGenShaderTexRedToAlphaNoZTestSubAWrite{})}; +// +// m_indTexZWrite = {hecl::conv->convert(Shader_CElementGenShaderIndTexZWrite{}), +// hecl::conv->convert(Shader_CElementGenShaderIndTexZWriteAWrite{})}; +// m_indTexNoZWrite = {hecl::conv->convert(Shader_CElementGenShaderIndTexNoZWrite{}), +// hecl::conv->convert(Shader_CElementGenShaderIndTexNoZWriteAWrite{})}; +// m_indTexAdditive = {hecl::conv->convert(Shader_CElementGenShaderIndTexAdditive{}), +// hecl::conv->convert(Shader_CElementGenShaderIndTexAdditiveAWrite{})}; +// +// m_cindTexZWrite = {hecl::conv->convert(Shader_CElementGenShaderCindTexZWrite{}), +// hecl::conv->convert(Shader_CElementGenShaderCindTexZWriteAWrite{})}; +// m_cindTexNoZWrite = {hecl::conv->convert(Shader_CElementGenShaderCindTexNoZWrite{}), +// hecl::conv->convert(Shader_CElementGenShaderCindTexNoZWriteAWrite{})}; +// m_cindTexAdditive = {hecl::conv->convert(Shader_CElementGenShaderCindTexAdditive{}), +// hecl::conv->convert(Shader_CElementGenShaderCindTexAdditiveAWrite{})}; +// +// m_noTexZTestZWrite = {hecl::conv->convert(Shader_CElementGenShaderNoTexZTestZWrite{}), +// hecl::conv->convert(Shader_CElementGenShaderNoTexZTestZWriteAWrite{})}; +// m_noTexNoZTestZWrite = {hecl::conv->convert(Shader_CElementGenShaderNoTexNoZTestZWrite{}), +// hecl::conv->convert(Shader_CElementGenShaderNoTexNoZTestZWriteAWrite{})}; +// m_noTexZTestNoZWrite = {hecl::conv->convert(Shader_CElementGenShaderNoTexZTestNoZWrite{}), +// hecl::conv->convert(Shader_CElementGenShaderNoTexZTestNoZWriteAWrite{})}; +// m_noTexNoZTestNoZWrite = {hecl::conv->convert(Shader_CElementGenShaderNoTexNoZTestNoZWrite{}), +// hecl::conv->convert(Shader_CElementGenShaderNoTexNoZTestNoZWriteAWrite{})}; +// m_noTexAdditiveZTest = {hecl::conv->convert(Shader_CElementGenShaderNoTexAdditiveZTest{}), +// hecl::conv->convert(Shader_CElementGenShaderNoTexAdditiveZTestAWrite{})}; +// m_noTexAdditiveNoZTest = {hecl::conv->convert(Shader_CElementGenShaderNoTexAdditiveNoZTest{}), +// hecl::conv->convert(Shader_CElementGenShaderNoTexAdditiveNoZTestAWrite{})}; } void CElementGenShaders::Shutdown() { - for (auto& s : m_texZTestZWrite) - s.reset(); - for (auto& s : m_texNoZTestZWrite) - s.reset(); - for (auto& s : m_texZTestNoZWrite) - s.reset(); - for (auto& s : m_texNoZTestNoZWrite) - s.reset(); - for (auto& s : m_texAdditiveZTest) - s.reset(); - for (auto& s : m_texAdditiveNoZTest) - s.reset(); - for (auto& s : m_texRedToAlphaZTest) - s.reset(); - for (auto& s : m_texRedToAlphaNoZTest) - s.reset(); - for (auto& s : m_texZTestNoZWriteSub) - s.reset(); - for (auto& s : m_texNoZTestNoZWriteSub) - s.reset(); - for (auto& s : m_texRedToAlphaZTestSub) - s.reset(); - for (auto& s : m_texRedToAlphaNoZTestSub) - s.reset(); - - for (auto& s : m_indTexZWrite) - s.reset(); - for (auto& s : m_indTexNoZWrite) - s.reset(); - for (auto& s : m_indTexAdditive) - s.reset(); - - for (auto& s : m_cindTexZWrite) - s.reset(); - for (auto& s : m_cindTexNoZWrite) - s.reset(); - for (auto& s : m_cindTexAdditive) - s.reset(); - - for (auto& s : m_noTexZTestZWrite) - s.reset(); - for (auto& s : m_noTexNoZTestZWrite) - s.reset(); - for (auto& s : m_noTexZTestNoZWrite) - s.reset(); - for (auto& s : m_noTexNoZTestNoZWrite) - s.reset(); - for (auto& s : m_noTexAdditiveZTest) - s.reset(); - for (auto& s : m_noTexAdditiveNoZTest) - s.reset(); +// for (auto& s : m_texZTestZWrite) +// s.reset(); +// for (auto& s : m_texNoZTestZWrite) +// s.reset(); +// for (auto& s : m_texZTestNoZWrite) +// s.reset(); +// for (auto& s : m_texNoZTestNoZWrite) +// s.reset(); +// for (auto& s : m_texAdditiveZTest) +// s.reset(); +// for (auto& s : m_texAdditiveNoZTest) +// s.reset(); +// for (auto& s : m_texRedToAlphaZTest) +// s.reset(); +// for (auto& s : m_texRedToAlphaNoZTest) +// s.reset(); +// for (auto& s : m_texZTestNoZWriteSub) +// s.reset(); +// for (auto& s : m_texNoZTestNoZWriteSub) +// s.reset(); +// for (auto& s : m_texRedToAlphaZTestSub) +// s.reset(); +// for (auto& s : m_texRedToAlphaNoZTestSub) +// s.reset(); +// +// for (auto& s : m_indTexZWrite) +// s.reset(); +// for (auto& s : m_indTexNoZWrite) +// s.reset(); +// for (auto& s : m_indTexAdditive) +// s.reset(); +// +// for (auto& s : m_cindTexZWrite) +// s.reset(); +// for (auto& s : m_cindTexNoZWrite) +// s.reset(); +// for (auto& s : m_cindTexAdditive) +// s.reset(); +// +// for (auto& s : m_noTexZTestZWrite) +// s.reset(); +// for (auto& s : m_noTexNoZTestZWrite) +// s.reset(); +// for (auto& s : m_noTexZTestNoZWrite) +// s.reset(); +// for (auto& s : m_noTexNoZTestNoZWrite) +// s.reset(); +// for (auto& s : m_noTexAdditiveZTest) +// s.reset(); +// for (auto& s : m_noTexAdditiveNoZTest) +// s.reset(); } CElementGenShaders::EShaderClass CElementGenShaders::GetShaderClass(CElementGen& gen) { @@ -128,171 +128,171 @@ CElementGenShaders::EShaderClass CElementGenShaders::GetShaderClass(CElementGen& return EShaderClass::NoTex; } -void CElementGenShaders::BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, CElementGen& gen) { +void CElementGenShaders::BuildShaderDataBinding(CElementGen& gen) { CGenDescription* desc = gen.x1c_genDesc.GetObj(); - std::array, 2>* regPipeline = nullptr; - std::array, 2>* regPipelineSub = nullptr; - std::array, 2>* redToAlphaPipeline = nullptr; - std::array, 2>* redToAlphaPipelineSub = nullptr; - std::array, 2>* regPipelinePmus = nullptr; - std::array, 2>* redToAlphaPipelinePmus = nullptr; - - if (gen.x26c_28_zTest) { - redToAlphaPipeline = &m_texRedToAlphaZTest; - regPipelineSub = &m_texZTestNoZWriteSub; - redToAlphaPipelineSub = &m_texRedToAlphaZTestSub; - } else { - redToAlphaPipeline = &m_texRedToAlphaNoZTest; - regPipelineSub = &m_texNoZTestNoZWriteSub; - redToAlphaPipelineSub = &m_texRedToAlphaNoZTestSub; - } - - if (desc->x54_x40_TEXR) { - if (desc->x58_x44_TIND) { - if (desc->x45_30_x32_24_CIND) { - if (gen.x26c_26_AAPH) - regPipeline = &m_cindTexAdditive; - else { - if (gen.x26c_27_ZBUF) - regPipeline = &m_cindTexZWrite; - else - regPipeline = &m_cindTexNoZWrite; - } - } else { - if (gen.x26c_26_AAPH) - regPipeline = &m_indTexAdditive; - else { - if (gen.x26c_27_ZBUF) - regPipeline = &m_indTexZWrite; - else - regPipeline = &m_indTexNoZWrite; - } - } - } else { - if (gen.x26c_26_AAPH) { - if (gen.x26c_28_zTest) - regPipeline = &m_texAdditiveZTest; - else - regPipeline = &m_texAdditiveNoZTest; - } else { - if (gen.x26c_28_zTest) { - if (gen.x26c_27_ZBUF) - regPipeline = &m_texZTestZWrite; - else - regPipeline = &m_texZTestNoZWrite; - } else { - if (gen.x26c_27_ZBUF) - regPipeline = &m_texNoZTestZWrite; - else - regPipeline = &m_texNoZTestNoZWrite; - } - } - } - } else { - if (gen.x26c_26_AAPH) { - if (gen.x26c_28_zTest) - regPipeline = &m_noTexAdditiveZTest; - else - regPipeline = &m_noTexAdditiveNoZTest; - } else { - if (gen.x26c_28_zTest) { - if (gen.x26c_27_ZBUF) - regPipeline = &m_noTexZTestZWrite; - else - regPipeline = &m_noTexZTestNoZWrite; - } else { - if (gen.x26c_27_ZBUF) - regPipeline = &m_noTexNoZTestZWrite; - else - regPipeline = &m_noTexNoZTestNoZWrite; - } - } - } - - if (desc->x45_24_x31_26_PMUS) { - if (desc->x54_x40_TEXR) { - redToAlphaPipelinePmus = &m_texRedToAlphaZTest; - if (desc->x44_31_x31_25_PMAB) - regPipelinePmus = &m_texAdditiveZTest; - else - regPipelinePmus = &m_texZTestZWrite; - } else { - if (desc->x44_31_x31_25_PMAB) - regPipelinePmus = &m_noTexAdditiveZTest; - else - regPipelinePmus = &m_noTexZTestZWrite; - } - } - - const CUVElement* const texr = desc->x54_x40_TEXR.get(); - const CUVElement* const tind = desc->x58_x44_TIND.get(); - int texCount = 0; - std::array, 3> textures; - - if (texr) { - textures[0] = texr->GetValueTexture(0).GetObj()->GetBooTexture(); - texCount = 1; - if (gen.m_instBuf) { - if (tind) { - textures[1] = CGraphics::g_SpareTexture.get(); - textures[2] = tind->GetValueTexture(0).GetObj()->GetBooTexture(); - texCount = 3; - } - } - } - - if (gen.m_instBuf) { - const std::array, 1> uniforms{gen.m_uniformBuf.get()}; - - if (regPipeline != nullptr) { - for (size_t i = 0; i < gen.m_normalDataBind.size(); ++i) { - gen.m_normalDataBind[i] = - ctx.newShaderDataBinding((*regPipeline)[i], nullptr, gen.m_instBuf.get(), nullptr, uniforms.size(), - uniforms.data(), nullptr, texCount, textures.data(), nullptr, nullptr); - } - } - if (regPipelineSub != nullptr) { - for (size_t i = 0; i < gen.m_normalSubDataBind.size(); ++i) { - gen.m_normalSubDataBind[i] = - ctx.newShaderDataBinding((*regPipelineSub)[i], nullptr, gen.m_instBuf.get(), nullptr, uniforms.size(), - uniforms.data(), nullptr, texCount, textures.data(), nullptr, nullptr); - } - } - if (redToAlphaPipeline != nullptr) { - for (size_t i = 0; i < gen.m_redToAlphaDataBind.size(); ++i) { - gen.m_redToAlphaDataBind[i] = - ctx.newShaderDataBinding((*redToAlphaPipeline)[i], nullptr, gen.m_instBuf.get(), nullptr, uniforms.size(), - uniforms.data(), nullptr, texCount, textures.data(), nullptr, nullptr); - } - } - if (redToAlphaPipelineSub != nullptr) { - for (size_t i = 0; i < gen.m_redToAlphaSubDataBind.size(); ++i) { - gen.m_redToAlphaSubDataBind[i] = ctx.newShaderDataBinding( - (*redToAlphaPipelineSub)[i], nullptr, gen.m_instBuf.get(), nullptr, uniforms.size(), uniforms.data(), - nullptr, texCount, textures.data(), nullptr, nullptr); - } - } - } - - if (gen.m_instBufPmus) { - const std::array, 1> uniforms{gen.m_uniformBufPmus.get()}; - texCount = std::min(texCount, 1); - - if (regPipelinePmus != nullptr) { - for (size_t i = 0; i < gen.m_normalDataBindPmus.size(); ++i) { - gen.m_normalDataBindPmus[i] = - ctx.newShaderDataBinding((*regPipelinePmus)[i], nullptr, gen.m_instBufPmus.get(), nullptr, uniforms.size(), - uniforms.data(), nullptr, texCount, textures.data(), nullptr, nullptr); - } - } - if (redToAlphaPipelinePmus != nullptr) { - for (size_t i = 0; i < gen.m_redToAlphaDataBindPmus.size(); ++i) { - gen.m_redToAlphaDataBindPmus[i] = ctx.newShaderDataBinding( - (*redToAlphaPipelinePmus)[i], nullptr, gen.m_instBufPmus.get(), nullptr, uniforms.size(), uniforms.data(), - nullptr, texCount, textures.data(), nullptr, nullptr); - } - } - } +// std::array, 2>* regPipeline = nullptr; +// std::array, 2>* regPipelineSub = nullptr; +// std::array, 2>* redToAlphaPipeline = nullptr; +// std::array, 2>* redToAlphaPipelineSub = nullptr; +// std::array, 2>* regPipelinePmus = nullptr; +// std::array, 2>* redToAlphaPipelinePmus = nullptr; +// +// if (gen.x26c_28_zTest) { +// redToAlphaPipeline = &m_texRedToAlphaZTest; +// regPipelineSub = &m_texZTestNoZWriteSub; +// redToAlphaPipelineSub = &m_texRedToAlphaZTestSub; +// } else { +// redToAlphaPipeline = &m_texRedToAlphaNoZTest; +// regPipelineSub = &m_texNoZTestNoZWriteSub; +// redToAlphaPipelineSub = &m_texRedToAlphaNoZTestSub; +// } +// +// if (desc->x54_x40_TEXR) { +// if (desc->x58_x44_TIND) { +// if (desc->x45_30_x32_24_CIND) { +// if (gen.x26c_26_AAPH) +// regPipeline = &m_cindTexAdditive; +// else { +// if (gen.x26c_27_ZBUF) +// regPipeline = &m_cindTexZWrite; +// else +// regPipeline = &m_cindTexNoZWrite; +// } +// } else { +// if (gen.x26c_26_AAPH) +// regPipeline = &m_indTexAdditive; +// else { +// if (gen.x26c_27_ZBUF) +// regPipeline = &m_indTexZWrite; +// else +// regPipeline = &m_indTexNoZWrite; +// } +// } +// } else { +// if (gen.x26c_26_AAPH) { +// if (gen.x26c_28_zTest) +// regPipeline = &m_texAdditiveZTest; +// else +// regPipeline = &m_texAdditiveNoZTest; +// } else { +// if (gen.x26c_28_zTest) { +// if (gen.x26c_27_ZBUF) +// regPipeline = &m_texZTestZWrite; +// else +// regPipeline = &m_texZTestNoZWrite; +// } else { +// if (gen.x26c_27_ZBUF) +// regPipeline = &m_texNoZTestZWrite; +// else +// regPipeline = &m_texNoZTestNoZWrite; +// } +// } +// } +// } else { +// if (gen.x26c_26_AAPH) { +// if (gen.x26c_28_zTest) +// regPipeline = &m_noTexAdditiveZTest; +// else +// regPipeline = &m_noTexAdditiveNoZTest; +// } else { +// if (gen.x26c_28_zTest) { +// if (gen.x26c_27_ZBUF) +// regPipeline = &m_noTexZTestZWrite; +// else +// regPipeline = &m_noTexZTestNoZWrite; +// } else { +// if (gen.x26c_27_ZBUF) +// regPipeline = &m_noTexNoZTestZWrite; +// else +// regPipeline = &m_noTexNoZTestNoZWrite; +// } +// } +// } +// +// if (desc->x45_24_x31_26_PMUS) { +// if (desc->x54_x40_TEXR) { +// redToAlphaPipelinePmus = &m_texRedToAlphaZTest; +// if (desc->x44_31_x31_25_PMAB) +// regPipelinePmus = &m_texAdditiveZTest; +// else +// regPipelinePmus = &m_texZTestZWrite; +// } else { +// if (desc->x44_31_x31_25_PMAB) +// regPipelinePmus = &m_noTexAdditiveZTest; +// else +// regPipelinePmus = &m_noTexZTestZWrite; +// } +// } +// +// const CUVElement* const texr = desc->x54_x40_TEXR.get(); +// const CUVElement* const tind = desc->x58_x44_TIND.get(); +// int texCount = 0; +// std::array, 3> textures; +// +// if (texr) { +// textures[0] = texr->GetValueTexture(0).GetObj()->GetBooTexture(); +// texCount = 1; +// if (gen.m_instBuf) { +// if (tind) { +// textures[1] = CGraphics::g_SpareTexture.get(); +// textures[2] = tind->GetValueTexture(0).GetObj()->GetBooTexture(); +// texCount = 3; +// } +// } +// } +// +// if (gen.m_instBuf) { +// const std::array, 1> uniforms{gen.m_uniformBuf.get()}; +// +// if (regPipeline != nullptr) { +// for (size_t i = 0; i < gen.m_normalDataBind.size(); ++i) { +// gen.m_normalDataBind[i] = +// ctx.newShaderDataBinding((*regPipeline)[i], nullptr, gen.m_instBuf.get(), nullptr, uniforms.size(), +// uniforms.data(), nullptr, texCount, textures.data(), nullptr, nullptr); +// } +// } +// if (regPipelineSub != nullptr) { +// for (size_t i = 0; i < gen.m_normalSubDataBind.size(); ++i) { +// gen.m_normalSubDataBind[i] = +// ctx.newShaderDataBinding((*regPipelineSub)[i], nullptr, gen.m_instBuf.get(), nullptr, uniforms.size(), +// uniforms.data(), nullptr, texCount, textures.data(), nullptr, nullptr); +// } +// } +// if (redToAlphaPipeline != nullptr) { +// for (size_t i = 0; i < gen.m_redToAlphaDataBind.size(); ++i) { +// gen.m_redToAlphaDataBind[i] = +// ctx.newShaderDataBinding((*redToAlphaPipeline)[i], nullptr, gen.m_instBuf.get(), nullptr, uniforms.size(), +// uniforms.data(), nullptr, texCount, textures.data(), nullptr, nullptr); +// } +// } +// if (redToAlphaPipelineSub != nullptr) { +// for (size_t i = 0; i < gen.m_redToAlphaSubDataBind.size(); ++i) { +// gen.m_redToAlphaSubDataBind[i] = ctx.newShaderDataBinding( +// (*redToAlphaPipelineSub)[i], nullptr, gen.m_instBuf.get(), nullptr, uniforms.size(), uniforms.data(), +// nullptr, texCount, textures.data(), nullptr, nullptr); +// } +// } +// } +// +// if (gen.m_instBufPmus) { +// const std::array, 1> uniforms{gen.m_uniformBufPmus.get()}; +// texCount = std::min(texCount, 1); +// +// if (regPipelinePmus != nullptr) { +// for (size_t i = 0; i < gen.m_normalDataBindPmus.size(); ++i) { +// gen.m_normalDataBindPmus[i] = +// ctx.newShaderDataBinding((*regPipelinePmus)[i], nullptr, gen.m_instBufPmus.get(), nullptr, uniforms.size(), +// uniforms.data(), nullptr, texCount, textures.data(), nullptr, nullptr); +// } +// } +// if (redToAlphaPipelinePmus != nullptr) { +// for (size_t i = 0; i < gen.m_redToAlphaDataBindPmus.size(); ++i) { +// gen.m_redToAlphaDataBindPmus[i] = ctx.newShaderDataBinding( +// (*redToAlphaPipelinePmus)[i], nullptr, gen.m_instBufPmus.get(), nullptr, uniforms.size(), uniforms.data(), +// nullptr, texCount, textures.data(), nullptr, nullptr); +// } +// } +// } } } // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CElementGenShaders.hpp b/Runtime/Graphics/Shaders/CElementGenShaders.hpp index 386e943d9..c5171a6c7 100644 --- a/Runtime/Graphics/Shaders/CElementGenShaders.hpp +++ b/Runtime/Graphics/Shaders/CElementGenShaders.hpp @@ -2,7 +2,7 @@ #include -#include +//#include namespace metaforce { class CElementGen; @@ -12,39 +12,39 @@ public: enum class EShaderClass { Tex, IndTex, NoTex }; private: - static inline std::array, 2> m_texZTestZWrite; - static inline std::array, 2> m_texNoZTestZWrite; - static inline std::array, 2> m_texZTestNoZWrite; - static inline std::array, 2> m_texNoZTestNoZWrite; - static inline std::array, 2> m_texAdditiveZTest; - static inline std::array, 2> m_texAdditiveNoZTest; - static inline std::array, 2> m_texRedToAlphaZTest; - static inline std::array, 2> m_texRedToAlphaNoZTest; - static inline std::array, 2> m_texZTestNoZWriteSub; - static inline std::array, 2> m_texNoZTestNoZWriteSub; - static inline std::array, 2> m_texRedToAlphaZTestSub; - static inline std::array, 2> m_texRedToAlphaNoZTestSub; - - static inline std::array, 2> m_indTexZWrite; - static inline std::array, 2> m_indTexNoZWrite; - static inline std::array, 2> m_indTexAdditive; - - static inline std::array, 2> m_cindTexZWrite; - static inline std::array, 2> m_cindTexNoZWrite; - static inline std::array, 2> m_cindTexAdditive; - - static inline std::array, 2> m_noTexZTestZWrite; - static inline std::array, 2> m_noTexNoZTestZWrite; - static inline std::array, 2> m_noTexZTestNoZWrite; - static inline std::array, 2> m_noTexNoZTestNoZWrite; - static inline std::array, 2> m_noTexAdditiveZTest; - static inline std::array, 2> m_noTexAdditiveNoZTest; +// static inline std::array, 2> m_texZTestZWrite; +// static inline std::array, 2> m_texNoZTestZWrite; +// static inline std::array, 2> m_texZTestNoZWrite; +// static inline std::array, 2> m_texNoZTestNoZWrite; +// static inline std::array, 2> m_texAdditiveZTest; +// static inline std::array, 2> m_texAdditiveNoZTest; +// static inline std::array, 2> m_texRedToAlphaZTest; +// static inline std::array, 2> m_texRedToAlphaNoZTest; +// static inline std::array, 2> m_texZTestNoZWriteSub; +// static inline std::array, 2> m_texNoZTestNoZWriteSub; +// static inline std::array, 2> m_texRedToAlphaZTestSub; +// static inline std::array, 2> m_texRedToAlphaNoZTestSub; +// +// static inline std::array, 2> m_indTexZWrite; +// static inline std::array, 2> m_indTexNoZWrite; +// static inline std::array, 2> m_indTexAdditive; +// +// static inline std::array, 2> m_cindTexZWrite; +// static inline std::array, 2> m_cindTexNoZWrite; +// static inline std::array, 2> m_cindTexAdditive; +// +// static inline std::array, 2> m_noTexZTestZWrite; +// static inline std::array, 2> m_noTexNoZTestZWrite; +// static inline std::array, 2> m_noTexZTestNoZWrite; +// static inline std::array, 2> m_noTexNoZTestNoZWrite; +// static inline std::array, 2> m_noTexAdditiveZTest; +// static inline std::array, 2> m_noTexAdditiveNoZTest; public: static void Initialize(); static void Shutdown(); static EShaderClass GetShaderClass(CElementGen& gen); - static void BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, CElementGen& gen); + static void BuildShaderDataBinding(CElementGen& gen); }; } // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CEnergyBarShader.cpp b/Runtime/Graphics/Shaders/CEnergyBarShader.cpp index 82810bdb4..835740f94 100644 --- a/Runtime/Graphics/Shaders/CEnergyBarShader.cpp +++ b/Runtime/Graphics/Shaders/CEnergyBarShader.cpp @@ -5,15 +5,19 @@ #include "Runtime/Graphics/CGraphics.hpp" #include "Runtime/Graphics/CTexture.hpp" -#include +//#include namespace metaforce { -static boo::ObjToken s_Pipeline; +//static boo::ObjToken s_Pipeline; -void CEnergyBarShader::Initialize() { s_Pipeline = hecl::conv->convert(Shader_CEnergyBarShader{}); } +void CEnergyBarShader::Initialize() { +// s_Pipeline = hecl::conv->convert(Shader_CEnergyBarShader{}); +} -void CEnergyBarShader::Shutdown() { s_Pipeline.reset(); } +void CEnergyBarShader::Shutdown() { +// s_Pipeline.reset(); +} void CEnergyBarShader::updateModelMatrix() { m_uniform.m_matrix = CGraphics::GetPerspectiveProjectionMatrix(true) * CGraphics::g_GXModelView.toMatrix4f(); @@ -31,60 +35,60 @@ void CEnergyBarShader::draw(const zeus::CColor& color0, const std::vector m_maxVerts) { m_maxVerts = totalVerts; m_tex = tex; - CGraphics::CommitResources([this](boo::IGraphicsDataFactory::Context& ctx) { - m_vbo = ctx.newDynamicBuffer(boo::BufferUse::Vertex, sizeof(Vertex), m_maxVerts); - - std::array, 1> bufs; - constexpr std::array stages{boo::PipelineStage::Vertex}; - const std::array, 1> texs{m_tex->GetBooTexture()}; - - for (size_t i = 0; i < m_uniBuf.size(); ++i) { - m_uniBuf[i] = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(Uniform), 1); - bufs[0] = m_uniBuf[i].get(); - m_dataBind[i] = - ctx.newShaderDataBinding(s_Pipeline, m_vbo.get(), nullptr, nullptr, bufs.size(), bufs.data(), stages.data(), - nullptr, nullptr, texs.size(), texs.data(), nullptr, nullptr); - } - - return true; - } BooTrace); +// CGraphics::CommitResources([this](boo::IGraphicsDataFactory::Context& ctx) { +// m_vbo = ctx.newDynamicBuffer(boo::BufferUse::Vertex, sizeof(Vertex), m_maxVerts); +// +// std::array, 1> bufs; +// constexpr std::array stages{boo::PipelineStage::Vertex}; +// const std::array, 1> texs{m_tex->GetBooTexture()}; +// +// for (size_t i = 0; i < m_uniBuf.size(); ++i) { +// m_uniBuf[i] = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(Uniform), 1); +// bufs[0] = m_uniBuf[i].get(); +// m_dataBind[i] = +// ctx.newShaderDataBinding(s_Pipeline, m_vbo.get(), nullptr, nullptr, bufs.size(), bufs.data(), stages.data(), +// nullptr, nullptr, texs.size(), texs.data(), nullptr, nullptr); +// } +// +// return true; +// } BooTrace); } size_t vertIter = 0; - Vertex* verts = reinterpret_cast(m_vbo->map(sizeof(Vertex) * totalVerts)); - if (verts0.size()) { - memmove(verts, verts0.data(), sizeof(Vertex) * verts0.size()); - vertIter += verts0.size(); - } - if (verts1.size()) { - memmove(verts + vertIter, verts1.data(), sizeof(Vertex) * verts1.size()); - vertIter += verts1.size(); - } - if (verts2.size()) { - memmove(verts + vertIter, verts2.data(), sizeof(Vertex) * verts2.size()); - } - m_vbo->unmap(); +// Vertex* verts = reinterpret_cast(m_vbo->map(sizeof(Vertex) * totalVerts)); +// if (verts0.size()) { +// memmove(verts, verts0.data(), sizeof(Vertex) * verts0.size()); +// vertIter += verts0.size(); +// } +// if (verts1.size()) { +// memmove(verts + vertIter, verts1.data(), sizeof(Vertex) * verts1.size()); +// vertIter += verts1.size(); +// } +// if (verts2.size()) { +// memmove(verts + vertIter, verts2.data(), sizeof(Vertex) * verts2.size()); +// } +// m_vbo->unmap(); vertIter = 0; if (verts0.size()) { m_uniform.m_color = color0; - m_uniBuf[0]->load(&m_uniform, sizeof(Uniform)); - CGraphics::SetShaderDataBinding(m_dataBind[0]); - CGraphics::DrawArray(0, verts0.size()); +// m_uniBuf[0]->load(&m_uniform, sizeof(Uniform)); +// CGraphics::SetShaderDataBinding(m_dataBind[0]); +// CGraphics::DrawArray(0, verts0.size()); vertIter += verts0.size(); } if (verts1.size()) { m_uniform.m_color = color1; - m_uniBuf[1]->load(&m_uniform, sizeof(Uniform)); - CGraphics::SetShaderDataBinding(m_dataBind[1]); - CGraphics::DrawArray(vertIter, verts1.size()); +// m_uniBuf[1]->load(&m_uniform, sizeof(Uniform)); +// CGraphics::SetShaderDataBinding(m_dataBind[1]); +// CGraphics::DrawArray(vertIter, verts1.size()); vertIter += verts1.size(); } if (verts2.size()) { m_uniform.m_color = color2; - m_uniBuf[2]->load(&m_uniform, sizeof(Uniform)); - CGraphics::SetShaderDataBinding(m_dataBind[2]); - CGraphics::DrawArray(vertIter, verts2.size()); +// m_uniBuf[2]->load(&m_uniform, sizeof(Uniform)); +// CGraphics::SetShaderDataBinding(m_dataBind[2]); +// CGraphics::DrawArray(vertIter, verts2.size()); } } diff --git a/Runtime/Graphics/Shaders/CEnergyBarShader.hpp b/Runtime/Graphics/Shaders/CEnergyBarShader.hpp index f04fa4330..6cb6b47a7 100644 --- a/Runtime/Graphics/Shaders/CEnergyBarShader.hpp +++ b/Runtime/Graphics/Shaders/CEnergyBarShader.hpp @@ -3,7 +3,7 @@ #include #include -#include +//#include #include #include @@ -25,9 +25,9 @@ private: zeus::CMatrix4f m_matrix; zeus::CColor m_color; }; - boo::ObjToken m_vbo; - std::array, 3> m_uniBuf; - std::array, 3> m_dataBind; +// boo::ObjToken m_vbo; +// std::array, 3> m_uniBuf; +// std::array, 3> m_dataBind; Uniform m_uniform; const CTexture* m_tex = nullptr; size_t m_maxVerts = 0; diff --git a/Runtime/Graphics/Shaders/CEnvFxShaders.cpp b/Runtime/Graphics/Shaders/CEnvFxShaders.cpp index 0a1d48fc5..7302486ea 100644 --- a/Runtime/Graphics/Shaders/CEnvFxShaders.cpp +++ b/Runtime/Graphics/Shaders/CEnvFxShaders.cpp @@ -2,56 +2,56 @@ #include "Runtime/World/CEnvFxManager.hpp" -#include +//#include namespace metaforce { -boo::ObjToken CEnvFxShaders::m_snowPipeline; -boo::ObjToken CEnvFxShaders::m_underwaterPipeline; +//boo::ObjToken CEnvFxShaders::m_snowPipeline; +//boo::ObjToken CEnvFxShaders::m_underwaterPipeline; void CEnvFxShaders::Initialize() { - m_snowPipeline = hecl::conv->convert(Shader_CEnvFxSnowShader{}); - m_underwaterPipeline = hecl::conv->convert(Shader_CEnvFxUnderwaterShader{}); +// m_snowPipeline = hecl::conv->convert(Shader_CEnvFxSnowShader{}); +// m_underwaterPipeline = hecl::conv->convert(Shader_CEnvFxUnderwaterShader{}); } void CEnvFxShaders::Shutdown() { - m_snowPipeline.reset(); - m_underwaterPipeline.reset(); +// m_snowPipeline.reset(); +// m_underwaterPipeline.reset(); } -void CEnvFxShaders::BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, CEnvFxManager& fxMgr, +void CEnvFxShaders::BuildShaderDataBinding(CEnvFxManager& fxMgr, CEnvFxManagerGrid& grid) { - const auto uBufInfo = grid.m_uniformBuf.getBufferInfo(); - const auto iBufInfo = grid.m_instBuf.getBufferInfo(); +// const auto uBufInfo = grid.m_uniformBuf.getBufferInfo(); +// const auto iBufInfo = grid.m_instBuf.getBufferInfo(); - const std::array, 2> uniforms{{ - uBufInfo.first.get(), - fxMgr.m_fogUniformBuf.get(), - }}; - const std::array ubufOffsets{ - size_t(uBufInfo.second), - 0, - }; - constexpr std::array ubufSizes{ - sizeof(CEnvFxShaders::Uniform), - sizeof(CGraphics::g_Fog), - }; - constexpr std::array uniformStages{ - boo::PipelineStage::Vertex, - boo::PipelineStage::Fragment, - }; - std::array, 2> textures{ - fxMgr.xb74_txtrSnowFlake->GetBooTexture(), - fxMgr.x40_txtrEnvGradient->GetBooTexture(), - }; - - grid.m_snowBinding = ctx.newShaderDataBinding( - m_snowPipeline, nullptr, iBufInfo.first.get(), nullptr, uniforms.size(), uniforms.data(), uniformStages.data(), - ubufOffsets.data(), ubufSizes.data(), textures.size(), textures.data(), nullptr, nullptr, 0, iBufInfo.second); - textures[0] = fxMgr.xc48_underwaterFlake->GetBooTexture(); - grid.m_underwaterBinding = - ctx.newShaderDataBinding(m_underwaterPipeline, nullptr, iBufInfo.first.get(), nullptr, uniforms.size(), - uniforms.data(), uniformStages.data(), ubufOffsets.data(), ubufSizes.data(), - textures.size(), textures.data(), nullptr, nullptr, 0, iBufInfo.second); +// const std::array, 2> uniforms{{ +// uBufInfo.first.get(), +// fxMgr.m_fogUniformBuf.get(), +// }}; +// const std::array ubufOffsets{ +// size_t(uBufInfo.second), +// 0, +// }; +// constexpr std::array ubufSizes{ +// sizeof(CEnvFxShaders::Uniform), +// sizeof(CGraphics::g_Fog), +// }; +// constexpr std::array uniformStages{ +// boo::PipelineStage::Vertex, +// boo::PipelineStage::Fragment, +// }; +// std::array, 2> textures{ +// fxMgr.xb74_txtrSnowFlake->GetBooTexture(), +// fxMgr.x40_txtrEnvGradient->GetBooTexture(), +// }; +// +// grid.m_snowBinding = ctx.newShaderDataBinding( +// m_snowPipeline, nullptr, iBufInfo.first.get(), nullptr, uniforms.size(), uniforms.data(), uniformStages.data(), +// ubufOffsets.data(), ubufSizes.data(), textures.size(), textures.data(), nullptr, nullptr, 0, iBufInfo.second); +// textures[0] = fxMgr.xc48_underwaterFlake->GetBooTexture(); +// grid.m_underwaterBinding = +// ctx.newShaderDataBinding(m_underwaterPipeline, nullptr, iBufInfo.first.get(), nullptr, uniforms.size(), +// uniforms.data(), uniformStages.data(), ubufOffsets.data(), ubufSizes.data(), +// textures.size(), textures.data(), nullptr, nullptr, 0, iBufInfo.second); } } // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CEnvFxShaders.hpp b/Runtime/Graphics/Shaders/CEnvFxShaders.hpp index 2425264b6..69fbbf5f5 100644 --- a/Runtime/Graphics/Shaders/CEnvFxShaders.hpp +++ b/Runtime/Graphics/Shaders/CEnvFxShaders.hpp @@ -2,7 +2,7 @@ #include -#include +//#include #include #include @@ -28,13 +28,13 @@ public: }; private: - static boo::ObjToken m_snowPipeline; - static boo::ObjToken m_underwaterPipeline; +// static boo::ObjToken m_snowPipeline; +// static boo::ObjToken m_underwaterPipeline; public: static void Initialize(); static void Shutdown(); - static void BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, CEnvFxManager& fxMgr, + static void BuildShaderDataBinding(CEnvFxManager& fxMgr, CEnvFxManagerGrid& grid); }; diff --git a/Runtime/Graphics/Shaders/CFluidPlaneShader.cpp b/Runtime/Graphics/Shaders/CFluidPlaneShader.cpp index f11ffdc44..6acebef40 100644 --- a/Runtime/Graphics/Shaders/CFluidPlaneShader.cpp +++ b/Runtime/Graphics/Shaders/CFluidPlaneShader.cpp @@ -3,200 +3,202 @@ #include "Runtime/World/CRipple.hpp" #include "Runtime/World/CRippleManager.hpp" -#include +//#include namespace metaforce { -CFluidPlaneShader::Cache CFluidPlaneShader::_cache = {}; - -u16 CFluidPlaneShader::Cache::MakeCacheKey(const SFluidPlaneShaderInfo& info) { - u16 ret = 0; - - switch (info.m_type) { - case EFluidType::NormalWater: - case EFluidType::PhazonFluid: - case EFluidType::Four: - if (info.m_hasLightmap) { - ret |= 1 << 2; - if (info.m_doubleLightmapBlend) - ret |= 1 << 3; - } - - if (!info.m_hasEnvMap && info.m_hasEnvBumpMap) - ret |= 1 << 4; - - if (info.m_hasEnvMap) - ret |= 1 << 5; - - break; - - case EFluidType::PoisonWater: - ret |= 1; - - if (info.m_hasLightmap) { - ret |= 1 << 2; - if (info.m_doubleLightmapBlend) - ret |= 1 << 3; - } - - if (info.m_hasEnvBumpMap) - ret |= 1 << 4; - - break; - - case EFluidType::Lava: - ret |= 2; - - if (info.m_hasBumpMap) - ret |= 1 << 2; - - break; - - case EFluidType::ThickLava: - ret |= 3; - - if (info.m_hasBumpMap) - ret |= 1 << 2; - - break; - } - - if (info.m_hasPatternTex1) - ret |= 1 << 6; - if (info.m_hasPatternTex2) - ret |= 1 << 7; - if (info.m_hasColorTex) - ret |= 1 << 8; - - if (info.m_additive) - ret |= 1 << 9; - - return ret; -} - -u16 CFluidPlaneShader::Cache::MakeCacheKey(const SFluidPlaneDoorShaderInfo& info) { - u16 ret = 0; - - if (info.m_hasPatternTex1) - ret |= 1 << 0; - if (info.m_hasPatternTex2) - ret |= 1 << 1; - if (info.m_hasColorTex) - ret |= 1 << 2; - - return ret; -} - -template <> -CFluidPlaneShader::ShaderPair -CFluidPlaneShader::Cache::GetOrBuildShader(const SFluidPlaneShaderInfo& info) { - OPTICK_EVENT(); - u16 key = MakeCacheKey(info); - auto& slot = CacheSlot(info, key); - if (slot.m_regular) - return slot; - - slot.m_regular = hecl::conv->convert(Shader_CFluidPlaneShader{info, false}); - if (info.m_tessellation) - slot.m_tessellation = hecl::conv->convert(Shader_CFluidPlaneShader{info, true}); - - return slot; -} -template <> -CFluidPlaneShader::ShaderPair -CFluidPlaneShader::Cache::GetOrBuildShader(const SFluidPlaneDoorShaderInfo& info) { - OPTICK_EVENT(); - u16 key = MakeCacheKey(info); - auto& slot = CacheSlot(info, key); - if (slot.m_regular) - return slot; - - slot.m_regular = hecl::conv->convert(Shader_CFluidPlaneDoorShader{info}); - - return slot; -} - -void CFluidPlaneShader::Cache::Clear() { - for (auto& p : m_cache) - p.reset(); - for (auto& p : m_doorCache) - p.reset(); -} +//CFluidPlaneShader::Cache CFluidPlaneShader::_cache = {}; +// +//u16 CFluidPlaneShader::Cache::MakeCacheKey(const SFluidPlaneShaderInfo& info) { +// u16 ret = 0; +// +// switch (info.m_type) { +// case EFluidType::NormalWater: +// case EFluidType::PhazonFluid: +// case EFluidType::Four: +// if (info.m_hasLightmap) { +// ret |= 1 << 2; +// if (info.m_doubleLightmapBlend) +// ret |= 1 << 3; +// } +// +// if (!info.m_hasEnvMap && info.m_hasEnvBumpMap) +// ret |= 1 << 4; +// +// if (info.m_hasEnvMap) +// ret |= 1 << 5; +// +// break; +// +// case EFluidType::PoisonWater: +// ret |= 1; +// +// if (info.m_hasLightmap) { +// ret |= 1 << 2; +// if (info.m_doubleLightmapBlend) +// ret |= 1 << 3; +// } +// +// if (info.m_hasEnvBumpMap) +// ret |= 1 << 4; +// +// break; +// +// case EFluidType::Lava: +// ret |= 2; +// +// if (info.m_hasBumpMap) +// ret |= 1 << 2; +// +// break; +// +// case EFluidType::ThickLava: +// ret |= 3; +// +// if (info.m_hasBumpMap) +// ret |= 1 << 2; +// +// break; +// } +// +// if (info.m_hasPatternTex1) +// ret |= 1 << 6; +// if (info.m_hasPatternTex2) +// ret |= 1 << 7; +// if (info.m_hasColorTex) +// ret |= 1 << 8; +// +// if (info.m_additive) +// ret |= 1 << 9; +// +// return ret; +//} +// +//u16 CFluidPlaneShader::Cache::MakeCacheKey(const SFluidPlaneDoorShaderInfo& info) { +// u16 ret = 0; +// +// if (info.m_hasPatternTex1) +// ret |= 1 << 0; +// if (info.m_hasPatternTex2) +// ret |= 1 << 1; +// if (info.m_hasColorTex) +// ret |= 1 << 2; +// +// return ret; +//} +// +//template <> +//CFluidPlaneShader::ShaderPair +//CFluidPlaneShader::Cache::GetOrBuildShader(const SFluidPlaneShaderInfo& info) { +// OPTICK_EVENT(); +// u16 key = MakeCacheKey(info); +// auto& slot = CacheSlot(info, key); +// if (slot.m_regular) +// return slot; +// +// slot.m_regular = hecl::conv->convert(Shader_CFluidPlaneShader{info, false}); +// if (info.m_tessellation) +// slot.m_tessellation = hecl::conv->convert(Shader_CFluidPlaneShader{info, true}); +// +// return slot; +//} +//template <> +//CFluidPlaneShader::ShaderPair +//CFluidPlaneShader::Cache::GetOrBuildShader(const SFluidPlaneDoorShaderInfo& info) { +// OPTICK_EVENT(); +// u16 key = MakeCacheKey(info); +// auto& slot = CacheSlot(info, key); +// if (slot.m_regular) +// return slot; +// +// slot.m_regular = hecl::conv->convert(Shader_CFluidPlaneDoorShader{info}); +// +// return slot; +//} +// +//void CFluidPlaneShader::Cache::Clear() { +// for (auto& p : m_cache) +// p.reset(); +// for (auto& p : m_doorCache) +// p.reset(); +//} void CFluidPlaneShader::PrepareBinding(u32 maxVertCount) { - CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) { - m_vbo = ctx.newDynamicBuffer(boo::BufferUse::Vertex, sizeof(Vertex), maxVertCount); - if (m_pipelines.m_tessellation) { - m_pvbo = ctx.newDynamicBuffer(boo::BufferUse::Vertex, sizeof(PatchVertex), maxVertCount); - } - m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(Uniform), 1); - - const std::array, 3> ubufs{{ - m_uniBuf.get(), - m_uniBuf.get(), - m_uniBuf.get(), - }}; - constexpr std::array ubufStages{ - boo::PipelineStage::Vertex, - boo::PipelineStage::Vertex, - boo::PipelineStage::Fragment, - }; - constexpr std::array ubufOffs{ - 0, - 0, - 1280, - }; - constexpr std::array ubufSizes{ - 1280, - 1280, - sizeof(CModelShaders::LightingUniform), - }; - - size_t texCount = 0; - std::array, 8> texs; - if (m_patternTex1) { - texs[texCount++] = m_patternTex1->GetBooTexture(); - } - if (m_patternTex2) { - texs[texCount++] = m_patternTex2->GetBooTexture(); - } - if (m_colorTex) { - texs[texCount++] = m_colorTex->GetBooTexture(); - } - if (m_bumpMap) { - texs[texCount++] = m_bumpMap->GetBooTexture(); - } - if (m_envMap) { - texs[texCount++] = m_envMap->GetBooTexture(); - } - if (m_envBumpMap) { - texs[texCount++] = m_envBumpMap->GetBooTexture(); - } - if (m_lightmap) { - texs[texCount++] = m_lightmap->GetBooTexture(); - } - auto regular = ctx.newShaderDataBinding(m_pipelines.m_regular, m_vbo.get(), nullptr, nullptr, ubufs.size(), - ubufs.data(), ubufStages.data(), ubufOffs.data(), ubufSizes.data(), - texCount, texs.data(), nullptr, nullptr); - boo::ObjToken tessellation; - if (m_pipelines.m_tessellation) { - texs[texCount++] = m_rippleMap.get(); - tessellation = ctx.newShaderDataBinding(m_pipelines.m_tessellation, m_pvbo.get(), nullptr, nullptr, ubufs.size(), - ubufs.data(), ubufStages.data(), ubufOffs.data(), ubufSizes.data(), - texCount, texs.data(), nullptr, nullptr); - } - m_dataBind = {regular, tessellation}; - return true; - } BooTrace); +// CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) { +// m_vbo = ctx.newDynamicBuffer(boo::BufferUse::Vertex, sizeof(Vertex), maxVertCount); +// if (m_pipelines.m_tessellation) { +// m_pvbo = ctx.newDynamicBuffer(boo::BufferUse::Vertex, sizeof(PatchVertex), maxVertCount); +// } +// m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(Uniform), 1); +// +// const std::array, 3> ubufs{{ +// m_uniBuf.get(), +// m_uniBuf.get(), +// m_uniBuf.get(), +// }}; +// constexpr std::array ubufStages{ +// boo::PipelineStage::Vertex, +// boo::PipelineStage::Vertex, +// boo::PipelineStage::Fragment, +// }; +// constexpr std::array ubufOffs{ +// 0, +// 0, +// 1280, +// }; +// constexpr std::array ubufSizes{ +// 1280, +// 1280, +// sizeof(CModelShaders::LightingUniform), +// }; +// +// size_t texCount = 0; +// std::array, 8> texs; +// if (m_patternTex1) { +// texs[texCount++] = m_patternTex1->GetBooTexture(); +// } +// if (m_patternTex2) { +// texs[texCount++] = m_patternTex2->GetBooTexture(); +// } +// if (m_colorTex) { +// texs[texCount++] = m_colorTex->GetBooTexture(); +// } +// if (m_bumpMap) { +// texs[texCount++] = m_bumpMap->GetBooTexture(); +// } +// if (m_envMap) { +// texs[texCount++] = m_envMap->GetBooTexture(); +// } +// if (m_envBumpMap) { +// texs[texCount++] = m_envBumpMap->GetBooTexture(); +// } +// if (m_lightmap) { +// texs[texCount++] = m_lightmap->GetBooTexture(); +// } +// auto regular = ctx.newShaderDataBinding(m_pipelines.m_regular, m_vbo.get(), nullptr, nullptr, ubufs.size(), +// ubufs.data(), ubufStages.data(), ubufOffs.data(), ubufSizes.data(), +// texCount, texs.data(), nullptr, nullptr); +// boo::ObjToken tessellation; +// if (m_pipelines.m_tessellation) { +// texs[texCount++] = m_rippleMap.get(); +// tessellation = ctx.newShaderDataBinding(m_pipelines.m_tessellation, m_pvbo.get(), nullptr, nullptr, ubufs.size(), +// ubufs.data(), ubufStages.data(), ubufOffs.data(), ubufSizes.data(), +// texCount, texs.data(), nullptr, nullptr); +// } +// m_dataBind = {regular, tessellation}; +// return true; +// } BooTrace); } -void CFluidPlaneShader::Shutdown() { _cache.Clear(); } +void CFluidPlaneShader::Shutdown() { +// _cache.Clear(); +} CFluidPlaneShader::CFluidPlaneShader(EFluidType type, const TLockedToken& patternTex1, const TLockedToken& patternTex2, const TLockedToken& colorTex, const TLockedToken& bumpMap, const TLockedToken& envMap, const TLockedToken& envBumpMap, const TLockedToken& lightmap, - const boo::ObjToken& rippleMap, bool doubleLightmapBlend, + const std::shared_ptr& rippleMap, bool doubleLightmapBlend, bool additive, u32 maxVertCount) : m_patternTex1(patternTex1) , m_patternTex2(patternTex2) @@ -210,7 +212,7 @@ CFluidPlaneShader::CFluidPlaneShader(EFluidType type, const TLockedToken& patternTex1, : m_patternTex1(patternTex1), m_patternTex2(patternTex2), m_colorTex(colorTex) { SFluidPlaneDoorShaderInfo shaderInfo(m_patternTex1.HasReference(), m_patternTex2.HasReference(), m_colorTex.HasReference()); - m_pipelines = _cache.GetOrBuildShader(shaderInfo); +// m_pipelines = _cache.GetOrBuildShader(shaderInfo); PrepareBinding(maxVertCount); } void CFluidPlaneShader::prepareDraw(const RenderSetupInfo& info) { - Uniform& uni = *reinterpret_cast(m_uniBuf->map(sizeof(Uniform))); - uni.m_mv = CGraphics::g_GXModelView.toMatrix4f(); - uni.m_mvNorm = info.normMtx; - uni.m_proj = CGraphics::GetPerspectiveProjectionMatrix(true); - uni.m_texMtxs = info.texMtxs; - uni.m_lighting.ActivateLights(info.lights); - for (size_t i = 0; i < uni.m_lighting.colorRegs.size(); ++i) { - uni.m_lighting.colorRegs[i] = info.kColors[i]; - } - uni.m_lighting.mulColor = info.kColors[3]; - uni.m_lighting.fog = CGraphics::g_Fog; - uni.m_pad2.x() = info.indScale; - m_uniBuf->unmap(); +// Uniform& uni = *reinterpret_cast(m_uniBuf->map(sizeof(Uniform))); +// uni.m_mv = CGraphics::g_GXModelView.toMatrix4f(); +// uni.m_mvNorm = info.normMtx; +// uni.m_proj = CGraphics::GetPerspectiveProjectionMatrix(true); +// uni.m_texMtxs = info.texMtxs; +// uni.m_lighting.ActivateLights(info.lights); +// for (size_t i = 0; i < uni.m_lighting.colorRegs.size(); ++i) { +// uni.m_lighting.colorRegs[i] = info.kColors[i]; +// } +// uni.m_lighting.mulColor = info.kColors[3]; +// uni.m_lighting.fog = CGraphics::g_Fog; +// uni.m_pad2.x() = info.indScale; +// m_uniBuf->unmap(); } void CFluidPlaneShader::prepareDraw(const RenderSetupInfo& info, const zeus::CVector3f& waterCenter, const CRippleManager& rippleManager, const zeus::CColor& colorMul, float rippleNormResolution) { - Uniform& uni = *reinterpret_cast(m_uniBuf->map(sizeof(Uniform))); - uni.m_mv = CGraphics::g_GXModelView.toMatrix4f(); - uni.m_mvNorm = info.normMtx; - uni.m_proj = CGraphics::GetPerspectiveProjectionMatrix(true); - uni.m_texMtxs = info.texMtxs; - - size_t i = 0; - for (const CRipple& ripple : rippleManager.GetRipples()) { - assert(i < uni.m_ripple.size() && "Too many ripples"); - Ripple& rOut = uni.m_ripple[i++]; - if (ripple.GetTime() >= ripple.GetTimeFalloff()) { - rOut.center.zeroOut(); - rOut.params.zeroOut(); - continue; - } - zeus::CVector3f localPos = ripple.GetCenter() - waterCenter; - rOut.center.x() = float(localPos.x()); - rOut.center.y() = float(localPos.y()); - rOut.center.z() = ripple.GetTime() * ripple.GetOOTimeFalloff(); - rOut.center.w() = ripple.GetOODistanceFalloff(); - rOut.params.x() = ripple.GetAmplitude(); - rOut.params.y() = ripple.GetPhase(); - rOut.params.z() = - (1.f - ripple.GetTime() * ripple.GetOOTimeFalloff() * ripple.GetOOTimeFalloff()) * ripple.GetFrequency(); - } - uni.m_colorMul = colorMul; - uni.m_pad[0].x() = rippleNormResolution; - uni.m_lighting.ActivateLights(info.lights); - for (i = 0; i < uni.m_lighting.colorRegs.size(); ++i) { - uni.m_lighting.colorRegs[i] = info.kColors[i]; - } - uni.m_lighting.mulColor = info.kColors[3]; - uni.m_lighting.fog = CGraphics::g_Fog; - uni.m_pad2.x() = info.indScale; - m_uniBuf->unmap(); +// Uniform& uni = *reinterpret_cast(m_uniBuf->map(sizeof(Uniform))); +// uni.m_mv = CGraphics::g_GXModelView.toMatrix4f(); +// uni.m_mvNorm = info.normMtx; +// uni.m_proj = CGraphics::GetPerspectiveProjectionMatrix(true); +// uni.m_texMtxs = info.texMtxs; +// +// size_t i = 0; +// for (const CRipple& ripple : rippleManager.GetRipples()) { +// assert(i < uni.m_ripple.size() && "Too many ripples"); +// Ripple& rOut = uni.m_ripple[i++]; +// if (ripple.GetTime() >= ripple.GetTimeFalloff()) { +// rOut.center.zeroOut(); +// rOut.params.zeroOut(); +// continue; +// } +// zeus::CVector3f localPos = ripple.GetCenter() - waterCenter; +// rOut.center.x() = float(localPos.x()); +// rOut.center.y() = float(localPos.y()); +// rOut.center.z() = ripple.GetTime() * ripple.GetOOTimeFalloff(); +// rOut.center.w() = ripple.GetOODistanceFalloff(); +// rOut.params.x() = ripple.GetAmplitude(); +// rOut.params.y() = ripple.GetPhase(); +// rOut.params.z() = +// (1.f - ripple.GetTime() * ripple.GetOOTimeFalloff() * ripple.GetOOTimeFalloff()) * ripple.GetFrequency(); +// } +// uni.m_colorMul = colorMul; +// uni.m_pad[0].x() = rippleNormResolution; +// uni.m_lighting.ActivateLights(info.lights); +// for (i = 0; i < uni.m_lighting.colorRegs.size(); ++i) { +// uni.m_lighting.colorRegs[i] = info.kColors[i]; +// } +// uni.m_lighting.mulColor = info.kColors[3]; +// uni.m_lighting.fog = CGraphics::g_Fog; +// uni.m_pad2.x() = info.indScale; +// m_uniBuf->unmap(); } void CFluidPlaneShader::loadVerts(const std::vector& verts, const std::vector& pVerts) { - m_vbo->load(verts.data(), verts.size() * sizeof(Vertex)); - if (m_pvbo) - m_pvbo->load(pVerts.data(), pVerts.size() * sizeof(PatchVertex)); +// m_vbo->load(verts.data(), verts.size() * sizeof(Vertex)); +// if (m_pvbo) +// m_pvbo->load(pVerts.data(), pVerts.size() * sizeof(PatchVertex)); } } // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CFluidPlaneShader.hpp b/Runtime/Graphics/Shaders/CFluidPlaneShader.hpp index 2b78d4cb8..c672f85db 100644 --- a/Runtime/Graphics/Shaders/CFluidPlaneShader.hpp +++ b/Runtime/Graphics/Shaders/CFluidPlaneShader.hpp @@ -10,7 +10,7 @@ #include "Shaders/shader_CFluidPlaneShader.hpp" -#include +//#include #include #include @@ -53,34 +53,34 @@ public: }; private: - struct ShaderPair { - boo::ObjToken m_regular; - boo::ObjToken m_tessellation; - void reset() { - m_regular.reset(); - m_tessellation.reset(); - } - }; +// struct ShaderPair { +// boo::ObjToken m_regular; +// boo::ObjToken m_tessellation; +// void reset() { +// m_regular.reset(); +// m_tessellation.reset(); +// } +// }; +// +// struct BindingPair { +// boo::ObjToken m_regular; +// boo::ObjToken m_tessellation; +// }; - struct BindingPair { - boo::ObjToken m_regular; - boo::ObjToken m_tessellation; - }; - - class Cache { - std::array m_cache{}; - std::array m_doorCache{}; - ShaderPair& CacheSlot(const SFluidPlaneShaderInfo& info, int i) { return m_cache[i]; } - ShaderPair& CacheSlot(const SFluidPlaneDoorShaderInfo& info, int i) { return m_doorCache[i]; } - static u16 MakeCacheKey(const SFluidPlaneShaderInfo& info); - static u16 MakeCacheKey(const SFluidPlaneDoorShaderInfo& info); - - public: - template - ShaderPair GetOrBuildShader(const T& info); - void Clear(); - }; - static Cache _cache; +// class Cache { +// std::array m_cache{}; +// std::array m_doorCache{}; +// ShaderPair& CacheSlot(const SFluidPlaneShaderInfo& info, int i) { return m_cache[i]; } +// ShaderPair& CacheSlot(const SFluidPlaneDoorShaderInfo& info, int i) { return m_doorCache[i]; } +// static u16 MakeCacheKey(const SFluidPlaneShaderInfo& info); +// static u16 MakeCacheKey(const SFluidPlaneDoorShaderInfo& info); +// +// public: +// template +// ShaderPair GetOrBuildShader(const T& info); +// void Clear(); +// }; +// static Cache _cache; struct Ripple { zeus::CVector4f center; // time, distFalloff @@ -106,34 +106,34 @@ private: TLockedToken m_envMap; TLockedToken m_envBumpMap; TLockedToken m_lightmap; - boo::ObjToken m_rippleMap; - boo::ObjToken m_vbo; - boo::ObjToken m_pvbo; - boo::ObjToken m_uniBuf; - ShaderPair m_pipelines; - BindingPair m_dataBind; + std::shared_ptr m_rippleMap; +// boo::ObjToken m_vbo; +// boo::ObjToken m_pvbo; +// boo::ObjToken m_uniBuf; +// ShaderPair m_pipelines; +// BindingPair m_dataBind; int m_lastBind = -1; -#if BOO_HAS_GL - static ShaderPair BuildShader(boo::GLDataFactory::Context& ctx, const SFluidPlaneShaderInfo& info); - static ShaderPair BuildShader(boo::GLDataFactory::Context& ctx, const SFluidPlaneDoorShaderInfo& info); - BindingPair BuildBinding(boo::GLDataFactory::Context& ctx, const ShaderPair& pipeline); -#endif -#if _WIN32 - static ShaderPair BuildShader(boo::D3D11DataFactory::Context& ctx, const SFluidPlaneShaderInfo& info); - static ShaderPair BuildShader(boo::D3D11DataFactory::Context& ctx, const SFluidPlaneDoorShaderInfo& info); - BindingPair BuildBinding(boo::D3D11DataFactory::Context& ctx, const ShaderPair& pipeline); -#endif -#if BOO_HAS_METAL - static ShaderPair BuildShader(boo::MetalDataFactory::Context& ctx, const SFluidPlaneShaderInfo& info); - static ShaderPair BuildShader(boo::MetalDataFactory::Context& ctx, const SFluidPlaneDoorShaderInfo& info); - BindingPair BuildBinding(boo::MetalDataFactory::Context& ctx, const ShaderPair& pipeline); -#endif -#if BOO_HAS_VULKAN - static ShaderPair BuildShader(boo::VulkanDataFactory::Context& ctx, const SFluidPlaneShaderInfo& info); - static ShaderPair BuildShader(boo::VulkanDataFactory::Context& ctx, const SFluidPlaneDoorShaderInfo& info); - BindingPair BuildBinding(boo::VulkanDataFactory::Context& ctx, const ShaderPair& pipeline); -#endif +//#if BOO_HAS_GL +// static ShaderPair BuildShader(boo::GLDataFactory::Context& ctx, const SFluidPlaneShaderInfo& info); +// static ShaderPair BuildShader(boo::GLDataFactory::Context& ctx, const SFluidPlaneDoorShaderInfo& info); +// BindingPair BuildBinding(boo::GLDataFactory::Context& ctx, const ShaderPair& pipeline); +//#endif +//#if _WIN32 +// static ShaderPair BuildShader(boo::D3D11DataFactory::Context& ctx, const SFluidPlaneShaderInfo& info); +// static ShaderPair BuildShader(boo::D3D11DataFactory::Context& ctx, const SFluidPlaneDoorShaderInfo& info); +// BindingPair BuildBinding(boo::D3D11DataFactory::Context& ctx, const ShaderPair& pipeline); +//#endif +//#if BOO_HAS_METAL +// static ShaderPair BuildShader(boo::MetalDataFactory::Context& ctx, const SFluidPlaneShaderInfo& info); +// static ShaderPair BuildShader(boo::MetalDataFactory::Context& ctx, const SFluidPlaneDoorShaderInfo& info); +// BindingPair BuildBinding(boo::MetalDataFactory::Context& ctx, const ShaderPair& pipeline); +//#endif +//#if BOO_HAS_VULKAN +// static ShaderPair BuildShader(boo::VulkanDataFactory::Context& ctx, const SFluidPlaneShaderInfo& info); +// static ShaderPair BuildShader(boo::VulkanDataFactory::Context& ctx, const SFluidPlaneDoorShaderInfo& info); +// BindingPair BuildBinding(boo::VulkanDataFactory::Context& ctx, const ShaderPair& pipeline); +//#endif template static void _Shutdown(); @@ -145,7 +145,7 @@ public: const TLockedToken& patternTex2, const TLockedToken& colorTex, const TLockedToken& bumpMap, const TLockedToken& envMap, const TLockedToken& envBumpMap, const TLockedToken& lightmap, - const boo::ObjToken& rippleMap, bool doubleLightmapBlend, bool additive, + const std::shared_ptr& rippleMap, bool doubleLightmapBlend, bool additive, u32 maxVertCount); CFluidPlaneShader(const TLockedToken& patternTex1, const TLockedToken& patternTex2, const TLockedToken& colorTex, u32 maxVertCount); @@ -154,13 +154,13 @@ public: const zeus::CColor& colorMul, float rippleNormResolution); void bindRegular() { if (m_lastBind != 0) { - CGraphics::SetShaderDataBinding(m_dataBind.m_regular); +// CGraphics::SetShaderDataBinding(m_dataBind.m_regular); m_lastBind = 0; } } bool bindTessellation() { if (m_lastBind != 1) { - CGraphics::SetShaderDataBinding(m_dataBind.m_tessellation); +// CGraphics::SetShaderDataBinding(m_dataBind.m_tessellation); m_lastBind = 1; } return true; @@ -168,7 +168,8 @@ public: void doneDrawing() { m_lastBind = -1; } void loadVerts(const std::vector& verts, const std::vector& pVerts); bool isReady() const { - return m_pipelines.m_regular->isReady() && (!m_pipelines.m_tessellation || m_pipelines.m_tessellation->isReady()); +// return m_pipelines.m_regular->isReady() && (!m_pipelines.m_tessellation || m_pipelines.m_tessellation->isReady()); + return false; } static void Shutdown(); diff --git a/Runtime/Graphics/Shaders/CFogVolumeFilter.cpp b/Runtime/Graphics/Shaders/CFogVolumeFilter.cpp index 80e3033fe..8cb018988 100644 --- a/Runtime/Graphics/Shaders/CFogVolumeFilter.cpp +++ b/Runtime/Graphics/Shaders/CFogVolumeFilter.cpp @@ -6,72 +6,72 @@ #include "Runtime/Graphics/CBooRenderer.hpp" #include "Runtime/Graphics/CGraphics.hpp" -#include -#include +//#include +//#include #include namespace metaforce { -static boo::ObjToken s_1WayPipeline; -static boo::ObjToken s_2WayPipeline; +//static boo::ObjToken s_1WayPipeline; +//static boo::ObjToken s_2WayPipeline; void CFogVolumeFilter::Initialize() { - s_1WayPipeline = hecl::conv->convert(Shader_CFogVolumeFilter1Way{}); - s_2WayPipeline = hecl::conv->convert(Shader_CFogVolumeFilter2Way{}); +// s_1WayPipeline = hecl::conv->convert(Shader_CFogVolumeFilter1Way{}); +// s_2WayPipeline = hecl::conv->convert(Shader_CFogVolumeFilter2Way{}); } void CFogVolumeFilter::Shutdown() { - s_1WayPipeline.reset(); - s_2WayPipeline.reset(); +// s_1WayPipeline.reset(); +// s_2WayPipeline.reset(); } CFogVolumeFilter::CFogVolumeFilter() { - CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) { - struct Vert { - zeus::CVector2f m_pos; - zeus::CVector2f m_uv; - }; - constexpr std::array verts{{ - {{-1.0, -1.0}, {0.0, 0.0}}, - {{-1.0, 1.0}, {0.0, 1.0}}, - {{1.0, -1.0}, {1.0, 0.0}}, - {{1.0, 1.0}, {1.0, 1.0}}, - }}; - m_vbo = ctx.newStaticBuffer(boo::BufferUse::Vertex, verts.data(), sizeof(Vert), verts.size()); - m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(zeus::CColor), 1); - const std::array, 3> texs{ - CGraphics::g_SpareTexture.get(), - CGraphics::g_SpareTexture.get(), - g_Renderer->GetFogRampTex().get(), - }; - constexpr std::array bindIdxs{0, 1, 0}; - constexpr std::array bindDepth{true, true, false}; - const std::array, 1> ubufs{m_uniBuf.get()}; - - m_dataBind1Way = - ctx.newShaderDataBinding(s_1WayPipeline, m_vbo.get(), nullptr, nullptr, ubufs.size(), ubufs.data(), nullptr, - nullptr, nullptr, texs.size(), texs.data(), bindIdxs.data(), bindDepth.data()); - m_dataBind2Way = - ctx.newShaderDataBinding(s_2WayPipeline, m_vbo.get(), nullptr, nullptr, ubufs.size(), ubufs.data(), nullptr, - nullptr, nullptr, texs.size(), texs.data(), bindIdxs.data(), bindDepth.data()); - return true; - } BooTrace); +// CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) { +// struct Vert { +// zeus::CVector2f m_pos; +// zeus::CVector2f m_uv; +// }; +// constexpr std::array verts{{ +// {{-1.0, -1.0}, {0.0, 0.0}}, +// {{-1.0, 1.0}, {0.0, 1.0}}, +// {{1.0, -1.0}, {1.0, 0.0}}, +// {{1.0, 1.0}, {1.0, 1.0}}, +// }}; +// m_vbo = ctx.newStaticBuffer(boo::BufferUse::Vertex, verts.data(), sizeof(Vert), verts.size()); +// m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(zeus::CColor), 1); +// const std::array, 3> texs{ +// CGraphics::g_SpareTexture.get(), +// CGraphics::g_SpareTexture.get(), +// g_Renderer->GetFogRampTex().get(), +// }; +// constexpr std::array bindIdxs{0, 1, 0}; +// constexpr std::array bindDepth{true, true, false}; +// const std::array, 1> ubufs{m_uniBuf.get()}; +// +// m_dataBind1Way = +// ctx.newShaderDataBinding(s_1WayPipeline, m_vbo.get(), nullptr, nullptr, ubufs.size(), ubufs.data(), nullptr, +// nullptr, nullptr, texs.size(), texs.data(), bindIdxs.data(), bindDepth.data()); +// m_dataBind2Way = +// ctx.newShaderDataBinding(s_2WayPipeline, m_vbo.get(), nullptr, nullptr, ubufs.size(), ubufs.data(), nullptr, +// nullptr, nullptr, texs.size(), texs.data(), bindIdxs.data(), bindDepth.data()); +// return true; +// } BooTrace); } void CFogVolumeFilter::draw2WayPass(const zeus::CColor& color) { SCOPED_GRAPHICS_DEBUG_GROUP("CFogVolumeFilter::draw2WayPass", zeus::skMagenta); - m_uniBuf->load(&color, sizeof(zeus::CColor)); - CGraphics::SetShaderDataBinding(m_dataBind2Way); - CGraphics::DrawArray(0, 4); +// m_uniBuf->load(&color, sizeof(zeus::CColor)); +// CGraphics::SetShaderDataBinding(m_dataBind2Way); +// CGraphics::DrawArray(0, 4); } void CFogVolumeFilter::draw1WayPass(const zeus::CColor& color) { SCOPED_GRAPHICS_DEBUG_GROUP("CFogVolumeFilter::draw1WayPass", zeus::skMagenta); - m_uniBuf->load(&color, sizeof(zeus::CColor)); - CGraphics::SetShaderDataBinding(m_dataBind1Way); - CGraphics::DrawArray(0, 4); +// m_uniBuf->load(&color, sizeof(zeus::CColor)); +// CGraphics::SetShaderDataBinding(m_dataBind1Way); +// CGraphics::DrawArray(0, 4); } } // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CFogVolumeFilter.hpp b/Runtime/Graphics/Shaders/CFogVolumeFilter.hpp index bff2340db..ced382d90 100644 --- a/Runtime/Graphics/Shaders/CFogVolumeFilter.hpp +++ b/Runtime/Graphics/Shaders/CFogVolumeFilter.hpp @@ -1,24 +1,16 @@ #pragma once -#include - -namespace boo { -struct IGraphicsBufferD; -struct IGraphicsBufferS; -struct IShaderDataBinding; -} // namespace boo - namespace zeus { class CColor; -} +} // namespace zeus namespace metaforce { class CFogVolumeFilter { - boo::ObjToken m_vbo; - boo::ObjToken m_uniBuf; - boo::ObjToken m_dataBind1Way; - boo::ObjToken m_dataBind2Way; +// boo::ObjToken m_vbo; +// boo::ObjToken m_uniBuf; +// boo::ObjToken m_dataBind1Way; +// boo::ObjToken m_dataBind2Way; public: static void Initialize(); diff --git a/Runtime/Graphics/Shaders/CFogVolumePlaneShader.cpp b/Runtime/Graphics/Shaders/CFogVolumePlaneShader.cpp index 29f44ff7e..dabe4c05a 100644 --- a/Runtime/Graphics/Shaders/CFogVolumePlaneShader.cpp +++ b/Runtime/Graphics/Shaders/CFogVolumePlaneShader.cpp @@ -2,42 +2,42 @@ #include "Runtime/Graphics/CGraphics.hpp" -#include +//#include namespace metaforce { -static std::array, 4> s_Pipelines; - -void CFogVolumePlaneShader::Initialize() { - s_Pipelines[0] = hecl::conv->convert(Shader_CFogVolumePlaneShader0{}); - s_Pipelines[1] = hecl::conv->convert(Shader_CFogVolumePlaneShader1{}); - s_Pipelines[2] = hecl::conv->convert(Shader_CFogVolumePlaneShader2{}); - s_Pipelines[3] = hecl::conv->convert(Shader_CFogVolumePlaneShader3{}); -} - -void CFogVolumePlaneShader::Shutdown() { - s_Pipelines[0].reset(); - s_Pipelines[1].reset(); - s_Pipelines[2].reset(); - s_Pipelines[3].reset(); -} - -void CFogVolumePlaneShader::CommitResources(size_t capacity) { - m_vertCapacity = capacity; - CGraphics::CommitResources([this, capacity](boo::IGraphicsDataFactory::Context& ctx) { - m_vbo = ctx.newDynamicBuffer(boo::BufferUse::Vertex, sizeof(zeus::CVector4f), capacity); - for (size_t i = 0; i < m_dataBinds.size(); ++i) { - m_dataBinds[i] = ctx.newShaderDataBinding(s_Pipelines[i], m_vbo.get(), nullptr, nullptr, 0, nullptr, nullptr, - nullptr, nullptr, 0, nullptr, nullptr, nullptr); - } - return true; - } BooTrace); -} +//static std::array, 4> s_Pipelines; +// +//void CFogVolumePlaneShader::Initialize() { +// s_Pipelines[0] = hecl::conv->convert(Shader_CFogVolumePlaneShader0{}); +// s_Pipelines[1] = hecl::conv->convert(Shader_CFogVolumePlaneShader1{}); +// s_Pipelines[2] = hecl::conv->convert(Shader_CFogVolumePlaneShader2{}); +// s_Pipelines[3] = hecl::conv->convert(Shader_CFogVolumePlaneShader3{}); +//} +// +//void CFogVolumePlaneShader::Shutdown() { +// s_Pipelines[0].reset(); +// s_Pipelines[1].reset(); +// s_Pipelines[2].reset(); +// s_Pipelines[3].reset(); +//} +// +//void CFogVolumePlaneShader::CommitResources(size_t capacity) { +// m_vertCapacity = capacity; +// CGraphics::CommitResources([this, capacity](boo::IGraphicsDataFactory::Context& ctx) { +// m_vbo = ctx.newDynamicBuffer(boo::BufferUse::Vertex, sizeof(zeus::CVector4f), capacity); +// for (size_t i = 0; i < m_dataBinds.size(); ++i) { +// m_dataBinds[i] = ctx.newShaderDataBinding(s_Pipelines[i], m_vbo.get(), nullptr, nullptr, 0, nullptr, nullptr, +// nullptr, nullptr, 0, nullptr, nullptr, nullptr); +// } +// return true; +// } BooTrace); +//} void CFogVolumePlaneShader::addFan(const zeus::CVector3f* verts, int numVerts) { zeus::CMatrix4f proj = CGraphics::GetPerspectiveProjectionMatrix(true); zeus::CVector4f vert0 = proj * zeus::CVector4f(CGraphics::g_GXModelView * verts[0]); - if (m_verts.size()) { + if (!m_verts.empty()) { m_verts.push_back(m_verts.back()); m_verts.push_back(vert0); if (m_verts.size() & 1) @@ -53,13 +53,13 @@ void CFogVolumePlaneShader::draw(int pass) { if (m_verts.empty()) return; SCOPED_GRAPHICS_DEBUG_GROUP("CFogVolumePlaneShader::draw", zeus::skMagenta); - if (pass == 0) { - if (m_vertCapacity < m_verts.size()) - CommitResources(m_verts.size()); - m_vbo->load(m_verts.data(), m_verts.size() * sizeof(zeus::CVector4f)); - } - CGraphics::SetShaderDataBinding(m_dataBinds[pass]); - CGraphics::DrawArray(0, m_verts.size()); +// if (pass == 0) { +// if (m_vertCapacity < m_verts.size()) +// CommitResources(m_verts.size()); +// m_vbo->load(m_verts.data(), m_verts.size() * sizeof(zeus::CVector4f)); +// } +// CGraphics::SetShaderDataBinding(m_dataBinds[pass]); +// CGraphics::DrawArray(0, m_verts.size()); } } // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CFogVolumePlaneShader.hpp b/Runtime/Graphics/Shaders/CFogVolumePlaneShader.hpp index 10f7473b4..25376341b 100644 --- a/Runtime/Graphics/Shaders/CFogVolumePlaneShader.hpp +++ b/Runtime/Graphics/Shaders/CFogVolumePlaneShader.hpp @@ -4,28 +4,25 @@ #include #include -#include +//#include #include #include namespace zeus { class CVector3f; -} +} // namespace zeus namespace metaforce { class CFogVolumePlaneShader { - boo::ObjToken m_vbo; - std::array, 4> m_dataBinds; - std::vector m_verts; +// boo::ObjToken m_vbo; +// std::array, 4> m_dataBinds; size_t m_vertCapacity = 0; - - void CommitResources(size_t capacity); +public: + std::vector m_verts; public: - static void Initialize(); - static void Shutdown(); static const zeus::CRectangle DefaultRect; void reset(int numVerts) { m_verts.clear(); diff --git a/Runtime/Graphics/Shaders/CLineRendererShaders.cpp b/Runtime/Graphics/Shaders/CLineRendererShaders.cpp index 05b4c3dc8..eeee0976a 100644 --- a/Runtime/Graphics/Shaders/CLineRendererShaders.cpp +++ b/Runtime/Graphics/Shaders/CLineRendererShaders.cpp @@ -4,113 +4,113 @@ #include "Runtime/Graphics/CLineRenderer.hpp" -#include +//#include namespace metaforce { void CLineRendererShaders::Initialize() { - CGraphics::CommitResources([](boo::IGraphicsDataFactory::Context& ctx) { - m_texAlpha = {hecl::conv->convert(ctx, Shader_CLineRendererShaderTexAlpha{}), - hecl::conv->convert(ctx, Shader_CLineRendererShaderTexAlphaAWrite{})}; - m_texAdditive = {hecl::conv->convert(ctx, Shader_CLineRendererShaderTexAdditive{}), - hecl::conv->convert(ctx, Shader_CLineRendererShaderTexAdditiveAWrite{})}; - m_noTexAlpha = {hecl::conv->convert(ctx, Shader_CLineRendererShaderNoTexAlpha{}), - hecl::conv->convert(ctx, Shader_CLineRendererShaderNoTexAlphaAWrite{})}; - m_noTexAdditive = {hecl::conv->convert(ctx, Shader_CLineRendererShaderNoTexAdditive{}), - hecl::conv->convert(ctx, Shader_CLineRendererShaderNoTexAdditiveAWrite{})}; - m_texAlphaZ = {hecl::conv->convert(ctx, Shader_CLineRendererShaderTexAlphaZ{}), - hecl::conv->convert(ctx, Shader_CLineRendererShaderTexAlphaZAWrite{})}; - m_texAdditiveZ = {hecl::conv->convert(ctx, Shader_CLineRendererShaderTexAdditiveZ{}), - hecl::conv->convert(ctx, Shader_CLineRendererShaderTexAdditiveZAWrite{})}; - m_noTexAlphaZ = {hecl::conv->convert(ctx, Shader_CLineRendererShaderNoTexAlphaZ{}), - hecl::conv->convert(ctx, Shader_CLineRendererShaderNoTexAlphaZAWrite{})}; - m_noTexAdditiveZ = {hecl::conv->convert(ctx, Shader_CLineRendererShaderNoTexAdditiveZ{}), - hecl::conv->convert(ctx, Shader_CLineRendererShaderNoTexAdditiveZAWrite{})}; - m_noTexAlphaZGEqual = {hecl::conv->convert(ctx, Shader_CLineRendererShaderNoTexAlphaZGEqual{}), - hecl::conv->convert(ctx, Shader_CLineRendererShaderNoTexAlphaZGEqualAWrite{})}; - return true; - } BooTrace); +// CGraphics::CommitResources([](boo::IGraphicsDataFactory::Context& ctx) { +// m_texAlpha = {hecl::conv->convert(ctx, Shader_CLineRendererShaderTexAlpha{}), +// hecl::conv->convert(ctx, Shader_CLineRendererShaderTexAlphaAWrite{})}; +// m_texAdditive = {hecl::conv->convert(ctx, Shader_CLineRendererShaderTexAdditive{}), +// hecl::conv->convert(ctx, Shader_CLineRendererShaderTexAdditiveAWrite{})}; +// m_noTexAlpha = {hecl::conv->convert(ctx, Shader_CLineRendererShaderNoTexAlpha{}), +// hecl::conv->convert(ctx, Shader_CLineRendererShaderNoTexAlphaAWrite{})}; +// m_noTexAdditive = {hecl::conv->convert(ctx, Shader_CLineRendererShaderNoTexAdditive{}), +// hecl::conv->convert(ctx, Shader_CLineRendererShaderNoTexAdditiveAWrite{})}; +// m_texAlphaZ = {hecl::conv->convert(ctx, Shader_CLineRendererShaderTexAlphaZ{}), +// hecl::conv->convert(ctx, Shader_CLineRendererShaderTexAlphaZAWrite{})}; +// m_texAdditiveZ = {hecl::conv->convert(ctx, Shader_CLineRendererShaderTexAdditiveZ{}), +// hecl::conv->convert(ctx, Shader_CLineRendererShaderTexAdditiveZAWrite{})}; +// m_noTexAlphaZ = {hecl::conv->convert(ctx, Shader_CLineRendererShaderNoTexAlphaZ{}), +// hecl::conv->convert(ctx, Shader_CLineRendererShaderNoTexAlphaZAWrite{})}; +// m_noTexAdditiveZ = {hecl::conv->convert(ctx, Shader_CLineRendererShaderNoTexAdditiveZ{}), +// hecl::conv->convert(ctx, Shader_CLineRendererShaderNoTexAdditiveZAWrite{})}; +// m_noTexAlphaZGEqual = {hecl::conv->convert(ctx, Shader_CLineRendererShaderNoTexAlphaZGEqual{}), +// hecl::conv->convert(ctx, Shader_CLineRendererShaderNoTexAlphaZGEqualAWrite{})}; +// return true; +// } BooTrace); } void CLineRendererShaders::Shutdown() { - for (auto& s : m_texAlpha) - s.reset(); - for (auto& s : m_texAdditive) - s.reset(); - for (auto& s : m_noTexAlpha) - s.reset(); - for (auto& s : m_noTexAdditive) - s.reset(); - for (auto& s : m_texAlphaZ) - s.reset(); - for (auto& s : m_texAdditiveZ) - s.reset(); - for (auto& s : m_noTexAlphaZ) - s.reset(); - for (auto& s : m_noTexAdditiveZ) - s.reset(); - for (auto& s : m_noTexAlphaZGEqual) - s.reset(); +// for (auto& s : m_texAlpha) +// s.reset(); +// for (auto& s : m_texAdditive) +// s.reset(); +// for (auto& s : m_noTexAlpha) +// s.reset(); +// for (auto& s : m_noTexAdditive) +// s.reset(); +// for (auto& s : m_texAlphaZ) +// s.reset(); +// for (auto& s : m_texAdditiveZ) +// s.reset(); +// for (auto& s : m_noTexAlphaZ) +// s.reset(); +// for (auto& s : m_noTexAdditiveZ) +// s.reset(); +// for (auto& s : m_noTexAlphaZGEqual) +// s.reset(); } -void CLineRendererShaders::BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, CLineRenderer& renderer, - const boo::ObjToken& texture, bool additive, +void CLineRendererShaders::BuildShaderDataBinding(CLineRenderer& renderer, + const std::shared_ptr& texture, bool additive, bool zTest, bool zGEqual) { - std::array, 2>* pipeline = nullptr; - - if (zGEqual) { - pipeline = &m_noTexAlphaZGEqual; - } else if (zTest) { - if (texture) { - if (additive) - pipeline = &m_texAdditiveZ; - else - pipeline = &m_texAlphaZ; - } else { - if (additive) - pipeline = &m_noTexAdditiveZ; - else - pipeline = &m_noTexAlphaZ; - } - } else { - if (texture) { - if (additive) - pipeline = &m_texAdditive; - else - pipeline = &m_texAlpha; - } else { - if (additive) - pipeline = &m_noTexAdditive; - else - pipeline = &m_noTexAlpha; - } - } - - size_t texCount = 0; - std::array, 1> textures; - - std::pair, hecl::VertexBufferPool::IndexTp> - vbufInfo; - std::pair, hecl::UniformBufferPool::IndexTp> - ubufInfo = renderer.m_uniformBuf.getBufferInfo(); - if (texture) { - vbufInfo = renderer.m_vertBufTex.getBufferInfo(); - textures[0] = texture; - texCount = 1; - } else { - vbufInfo = renderer.m_vertBufNoTex.getBufferInfo(); - } - - const std::array, 1> uniforms{ubufInfo.first.get()}; - constexpr std::array stages{boo::PipelineStage::Fragment}; - const std::array ubufOffs{size_t(ubufInfo.second)}; - const std::array ubufSizes{sizeof(CLineRenderer::SDrawUniform)}; - - for (size_t i = 0; i < renderer.m_shaderBind.size(); ++i) { - renderer.m_shaderBind[i] = ctx.newShaderDataBinding( - (*pipeline)[i], vbufInfo.first.get(), nullptr, nullptr, uniforms.size(), uniforms.data(), stages.data(), - ubufOffs.data(), ubufSizes.data(), texCount, textures.data(), nullptr, nullptr, vbufInfo.second); - } +// std::array, 2>* pipeline = nullptr; +// +// if (zGEqual) { +// pipeline = &m_noTexAlphaZGEqual; +// } else if (zTest) { +// if (texture) { +// if (additive) +// pipeline = &m_texAdditiveZ; +// else +// pipeline = &m_texAlphaZ; +// } else { +// if (additive) +// pipeline = &m_noTexAdditiveZ; +// else +// pipeline = &m_noTexAlphaZ; +// } +// } else { +// if (texture) { +// if (additive) +// pipeline = &m_texAdditive; +// else +// pipeline = &m_texAlpha; +// } else { +// if (additive) +// pipeline = &m_noTexAdditive; +// else +// pipeline = &m_noTexAlpha; +// } +// } +// +// size_t texCount = 0; +// std::array, 1> textures; +// +// std::pair, hecl::VertexBufferPool::IndexTp> +// vbufInfo; +// std::pair, hecl::UniformBufferPool::IndexTp> +// ubufInfo = renderer.m_uniformBuf.getBufferInfo(); +// if (texture) { +// vbufInfo = renderer.m_vertBufTex.getBufferInfo(); +// textures[0] = texture; +// texCount = 1; +// } else { +// vbufInfo = renderer.m_vertBufNoTex.getBufferInfo(); +// } +// +// const std::array, 1> uniforms{ubufInfo.first.get()}; +// constexpr std::array stages{boo::PipelineStage::Fragment}; +// const std::array ubufOffs{size_t(ubufInfo.second)}; +// const std::array ubufSizes{sizeof(CLineRenderer::SDrawUniform)}; +// +// for (size_t i = 0; i < renderer.m_shaderBind.size(); ++i) { +// renderer.m_shaderBind[i] = ctx.newShaderDataBinding( +// (*pipeline)[i], vbufInfo.first.get(), nullptr, nullptr, uniforms.size(), uniforms.data(), stages.data(), +// ubufOffs.data(), ubufSizes.data(), texCount, textures.data(), nullptr, nullptr, vbufInfo.second); +// } } } // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CLineRendererShaders.hpp b/Runtime/Graphics/Shaders/CLineRendererShaders.hpp index e0d44169d..132bae2dd 100644 --- a/Runtime/Graphics/Shaders/CLineRendererShaders.hpp +++ b/Runtime/Graphics/Shaders/CLineRendererShaders.hpp @@ -2,31 +2,31 @@ #include -#include +#include "Runtime/Graphics/CGraphics.hpp" namespace metaforce { class CLineRenderer; class CLineRendererShaders { - static inline std::array, 2> m_texAlpha; - static inline std::array, 2> m_texAdditive; - - static inline std::array, 2> m_noTexAlpha; - static inline std::array, 2> m_noTexAdditive; - - static inline std::array, 2> m_texAlphaZ; - static inline std::array, 2> m_texAdditiveZ; - - static inline std::array, 2> m_noTexAlphaZ; - static inline std::array, 2> m_noTexAdditiveZ; - - static inline std::array, 2> m_noTexAlphaZGEqual; +// static inline std::array, 2> m_texAlpha; +// static inline std::array, 2> m_texAdditive; +// +// static inline std::array, 2> m_noTexAlpha; +// static inline std::array, 2> m_noTexAdditive; +// +// static inline std::array, 2> m_texAlphaZ; +// static inline std::array, 2> m_texAdditiveZ; +// +// static inline std::array, 2> m_noTexAlphaZ; +// static inline std::array, 2> m_noTexAdditiveZ; +// +// static inline std::array, 2> m_noTexAlphaZGEqual; public: static void Initialize(); static void Shutdown(); - static void BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, CLineRenderer& renderer, - const boo::ObjToken& texture, bool additive, bool zTest, + static void BuildShaderDataBinding(CLineRenderer& renderer, + const std::shared_ptr& texture, bool additive, bool zTest, bool zGEqual); }; diff --git a/Runtime/Graphics/Shaders/CMapSurfaceShader.cpp b/Runtime/Graphics/Shaders/CMapSurfaceShader.cpp index 5ad827ba4..af2c337b8 100644 --- a/Runtime/Graphics/Shaders/CMapSurfaceShader.cpp +++ b/Runtime/Graphics/Shaders/CMapSurfaceShader.cpp @@ -4,33 +4,37 @@ #include "Runtime/Graphics/CGraphics.hpp" -#include +//#include namespace metaforce { -static boo::ObjToken s_Pipeline; +//static boo::ObjToken s_Pipeline; -void CMapSurfaceShader::Initialize() { s_Pipeline = hecl::conv->convert(Shader_CMapSurfaceShader{}); } +void CMapSurfaceShader::Initialize() { +// s_Pipeline = hecl::conv->convert(Shader_CMapSurfaceShader{}); +} -void CMapSurfaceShader::Shutdown() { s_Pipeline.reset(); } +void CMapSurfaceShader::Shutdown() { +// s_Pipeline.reset(); +} -CMapSurfaceShader::CMapSurfaceShader(boo::IGraphicsDataFactory::Context& ctx, - const boo::ObjToken& vbo, - const boo::ObjToken& ibo) -: m_vbo(vbo), m_ibo(ibo) { - m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(Uniform), 1); - const std::array, 1> bufs{m_uniBuf.get()}; - constexpr std::array stages{boo::PipelineStage::Vertex}; - m_dataBind = ctx.newShaderDataBinding(s_Pipeline, m_vbo.get(), nullptr, m_ibo.get(), bufs.size(), bufs.data(), - stages.data(), nullptr, nullptr, 0, nullptr, nullptr, nullptr); +CMapSurfaceShader::CMapSurfaceShader(aurora::ArrayRef vbo, + aurora::ArrayRef ibo) +//: m_vbo(vbo), m_ibo(ibo) +{ +// m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(Uniform), 1); +// const std::array, 1> bufs{m_uniBuf.get()}; +// constexpr std::array stages{boo::PipelineStage::Vertex}; +// m_dataBind = ctx.newShaderDataBinding(s_Pipeline, m_vbo.get(), nullptr, m_ibo.get(), bufs.size(), bufs.data(), +// stages.data(), nullptr, nullptr, 0, nullptr, nullptr, nullptr); } void CMapSurfaceShader::draw(const zeus::CColor& color, u32 start, u32 count) { SCOPED_GRAPHICS_DEBUG_GROUP("CMapSurfaceShader::draw", zeus::skMagenta); Uniform uniform = {CGraphics::GetPerspectiveProjectionMatrix(true) * CGraphics::g_GXModelView.toMatrix4f(), color}; - m_uniBuf->load(&uniform, sizeof(Uniform)); - CGraphics::SetShaderDataBinding(m_dataBind); - CGraphics::DrawArrayIndexed(start, count); +// m_uniBuf->load(&uniform, sizeof(Uniform)); +// CGraphics::SetShaderDataBinding(m_dataBind); +// CGraphics::DrawArrayIndexed(start, count); } } // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CMapSurfaceShader.hpp b/Runtime/Graphics/Shaders/CMapSurfaceShader.hpp index b3504c15d..46d8fab3b 100644 --- a/Runtime/Graphics/Shaders/CMapSurfaceShader.hpp +++ b/Runtime/Graphics/Shaders/CMapSurfaceShader.hpp @@ -1,8 +1,7 @@ #pragma once #include "Runtime/GCNTypes.hpp" - -#include +#include "Runtime/Graphics/CGraphics.hpp" #include #include @@ -15,16 +14,16 @@ class CMapSurfaceShader { zeus::CColor color; }; - boo::ObjToken m_uniBuf; - boo::ObjToken m_vbo; - boo::ObjToken m_ibo; - boo::ObjToken m_dataBind; +// boo::ObjToken m_uniBuf; +// boo::ObjToken m_vbo; +// boo::ObjToken m_ibo; +// boo::ObjToken m_dataBind; public: static void Initialize(); static void Shutdown(); - CMapSurfaceShader(boo::IGraphicsDataFactory::Context& ctx, const boo::ObjToken& vbo, - const boo::ObjToken& ibo); + CMapSurfaceShader(aurora::ArrayRef vbo, + aurora::ArrayRef ibo); void draw(const zeus::CColor& color, u32 start, u32 count); }; diff --git a/Runtime/Graphics/Shaders/CModelShaders.cpp b/Runtime/Graphics/Shaders/CModelShaders.cpp index f2dd04f2f..2fc2e2a16 100644 --- a/Runtime/Graphics/Shaders/CModelShaders.cpp +++ b/Runtime/Graphics/Shaders/CModelShaders.cpp @@ -4,11 +4,11 @@ #include "Runtime/Graphics/CLight.hpp" #include -#include +//#include namespace metaforce { -std::unordered_map CModelShaders::g_ShaderPipelines; +//std::unordered_map CModelShaders::g_ShaderPipelines; void CModelShaders::LightingUniform::ActivateLights(const std::vector& lts) { ambient = zeus::skClear; @@ -80,154 +80,156 @@ constexpr std::array DisintegrateTextures{{ {TexCoordSource::Position, 1, false}, // Ashy tex }}; -static std::array g_ExtensionSlots{{ - /* Default solid shading */ - {}, - /* Normal lit shading */ - {0, nullptr, hecl::Backend::BlendFactor::Original, hecl::Backend::BlendFactor::Original, - hecl::Backend::ZTest::Original, hecl::Backend::CullMode::Backface, false, false, true}, - /* Thermal model shading */ - {1, ThermalTextures.data(), hecl::Backend::BlendFactor::One, hecl::Backend::BlendFactor::One, - hecl::Backend::ZTest::Original, hecl::Backend::CullMode::Backface, false, false, false, true}, - /* Thermal model shading without Z-test or Z-write */ - {1, ThermalTextures.data(), hecl::Backend::BlendFactor::One, hecl::Backend::BlendFactor::One, - hecl::Backend::ZTest::None, hecl::Backend::CullMode::Backface, true, false, false, true}, - /* Thermal static shading */ - {0, nullptr, hecl::Backend::BlendFactor::SrcAlpha, hecl::Backend::BlendFactor::One, hecl::Backend::ZTest::Original, - hecl::Backend::CullMode::Backface, false, false, false, true, false, false, true}, - /* Thermal static shading without Z-write */ - {0, nullptr, hecl::Backend::BlendFactor::SrcAlpha, hecl::Backend::BlendFactor::One, hecl::Backend::ZTest::Original, - hecl::Backend::CullMode::Backface, true, false, false, true, false, false, false}, - /* Forced alpha shading */ - {0, nullptr, hecl::Backend::BlendFactor::SrcAlpha, hecl::Backend::BlendFactor::InvSrcAlpha, - hecl::Backend::ZTest::Original, hecl::Backend::CullMode::Backface, false, false, true}, - /* Forced additive shading */ - {0, nullptr, hecl::Backend::BlendFactor::SrcAlpha, hecl::Backend::BlendFactor::One, hecl::Backend::ZTest::Original, - hecl::Backend::CullMode::Backface, false, false, true}, - /* Solid color */ - {0, nullptr, hecl::Backend::BlendFactor::One, hecl::Backend::BlendFactor::Zero, hecl::Backend::ZTest::LEqual, - hecl::Backend::CullMode::Backface, false, false, false}, - /* Solid color additive */ - {0, nullptr, hecl::Backend::BlendFactor::SrcAlpha, hecl::Backend::BlendFactor::One, hecl::Backend::ZTest::LEqual, - hecl::Backend::CullMode::Backface, true, false, true}, - /* Alpha-only Solid color frontface cull, LEqual */ - {0, nullptr, hecl::Backend::BlendFactor::Zero, hecl::Backend::BlendFactor::One, hecl::Backend::ZTest::LEqual, - hecl::Backend::CullMode::Frontface, false, true, false}, - /* Alpha-only Solid color frontface cull, Always, No Z-write */ - {0, nullptr, hecl::Backend::BlendFactor::Zero, hecl::Backend::BlendFactor::One, hecl::Backend::ZTest::None, - hecl::Backend::CullMode::Frontface, true, true, false}, - /* Alpha-only Solid color backface cull, LEqual */ - {0, nullptr, hecl::Backend::BlendFactor::Zero, hecl::Backend::BlendFactor::One, hecl::Backend::ZTest::LEqual, - hecl::Backend::CullMode::Backface, false, true, false}, - /* Alpha-only Solid color backface cull, Greater, No Z-write */ - {0, nullptr, hecl::Backend::BlendFactor::Zero, hecl::Backend::BlendFactor::One, hecl::Backend::ZTest::Greater, - hecl::Backend::CullMode::Backface, true, true, false}, - /* MorphBall shadow shading */ - {3, BallFadeTextures.data(), hecl::Backend::BlendFactor::SrcAlpha, hecl::Backend::BlendFactor::InvSrcAlpha, - hecl::Backend::ZTest::Equal, hecl::Backend::CullMode::Backface, false, false, true, false, true}, - /* World shadow shading (modified lighting) */ - {1, WorldShadowTextures.data(), hecl::Backend::BlendFactor::Original, hecl::Backend::BlendFactor::Original, - hecl::Backend::ZTest::Original, hecl::Backend::CullMode::Backface, false, false, true}, - /* Forced alpha shading without culling */ - {0, nullptr, hecl::Backend::BlendFactor::SrcAlpha, hecl::Backend::BlendFactor::InvSrcAlpha, - hecl::Backend::ZTest::Original, hecl::Backend::CullMode::None, false, false, true}, - /* Forced additive shading without culling */ - {0, nullptr, hecl::Backend::BlendFactor::SrcAlpha, hecl::Backend::BlendFactor::One, hecl::Backend::ZTest::Original, - hecl::Backend::CullMode::None, false, false, true}, - /* Forced alpha shading without Z-write */ - {0, nullptr, hecl::Backend::BlendFactor::SrcAlpha, hecl::Backend::BlendFactor::InvSrcAlpha, - hecl::Backend::ZTest::Original, hecl::Backend::CullMode::Original, true, false, true}, - /* Forced additive shading without Z-write */ - {0, nullptr, hecl::Backend::BlendFactor::SrcAlpha, hecl::Backend::BlendFactor::One, hecl::Backend::ZTest::Original, - hecl::Backend::CullMode::Original, true, false, true}, - /* Forced alpha shading without culling or Z-write */ - {0, nullptr, hecl::Backend::BlendFactor::SrcAlpha, hecl::Backend::BlendFactor::InvSrcAlpha, - hecl::Backend::ZTest::Original, hecl::Backend::CullMode::None, true, false, true}, - /* Forced additive shading without culling or Z-write */ - {0, nullptr, hecl::Backend::BlendFactor::SrcAlpha, hecl::Backend::BlendFactor::One, hecl::Backend::ZTest::Original, - hecl::Backend::CullMode::None, true, false, true}, - /* Depth GEqual no Z-write */ - {0, nullptr, hecl::Backend::BlendFactor::SrcAlpha, hecl::Backend::BlendFactor::InvSrcAlpha, - hecl::Backend::ZTest::GEqual, hecl::Backend::CullMode::Backface, true, false, true}, - /* Disintegration */ - {2, DisintegrateTextures.data(), hecl::Backend::BlendFactor::SrcAlpha, hecl::Backend::BlendFactor::InvSrcAlpha, - hecl::Backend::ZTest::LEqual, hecl::Backend::CullMode::Original, false, false, true, false, false, true}, - /* Forced additive shading without culling or Z-write and greater depth test */ - {0, nullptr, hecl::Backend::BlendFactor::SrcAlpha, hecl::Backend::BlendFactor::One, hecl::Backend::ZTest::Greater, - hecl::Backend::CullMode::None, true, false, true}, - /* Thermal cold shading */ - {0, nullptr, hecl::Backend::BlendFactor::Original, hecl::Backend::BlendFactor::Original, - hecl::Backend::ZTest::Original, hecl::Backend::CullMode::Original, false, false, true, false, false, false, true}, - /* Normal lit shading with alpha */ - {0, nullptr, hecl::Backend::BlendFactor::Original, hecl::Backend::BlendFactor::Original, - hecl::Backend::ZTest::Original, hecl::Backend::CullMode::Backface}, - /* Normal lit shading with alpha without Z-write or depth test */ - {0, nullptr, hecl::Backend::BlendFactor::Original, hecl::Backend::BlendFactor::Original, hecl::Backend::ZTest::None, - hecl::Backend::CullMode::Backface, true}, - /* Normal lit shading with cube reflection */ - {0, nullptr, hecl::Backend::BlendFactor::Original, hecl::Backend::BlendFactor::Original, - hecl::Backend::ZTest::Original, hecl::Backend::CullMode::Backface, false, false, true}, - /* Normal lit shading with cube reflection and world shadow */ - {1, WorldShadowTextures.data(), hecl::Backend::BlendFactor::Original, hecl::Backend::BlendFactor::Original, - hecl::Backend::ZTest::Original, hecl::Backend::CullMode::Backface, false, false, true}, -}}; +//static std::array g_ExtensionSlots{{ +// /* Default solid shading */ +// {}, +// /* Normal lit shading */ +// {0, nullptr, hecl::Backend::BlendFactor::Original, hecl::Backend::BlendFactor::Original, +// hecl::Backend::ZTest::Original, hecl::Backend::CullMode::Backface, false, false, true}, +// /* Thermal model shading */ +// {1, ThermalTextures.data(), hecl::Backend::BlendFactor::One, hecl::Backend::BlendFactor::One, +// hecl::Backend::ZTest::Original, hecl::Backend::CullMode::Backface, false, false, false, true}, +// /* Thermal model shading without Z-test or Z-write */ +// {1, ThermalTextures.data(), hecl::Backend::BlendFactor::One, hecl::Backend::BlendFactor::One, +// hecl::Backend::ZTest::None, hecl::Backend::CullMode::Backface, true, false, false, true}, +// /* Thermal static shading */ +// {0, nullptr, hecl::Backend::BlendFactor::SrcAlpha, hecl::Backend::BlendFactor::One, hecl::Backend::ZTest::Original, +// hecl::Backend::CullMode::Backface, false, false, false, true, false, false, true}, +// /* Thermal static shading without Z-write */ +// {0, nullptr, hecl::Backend::BlendFactor::SrcAlpha, hecl::Backend::BlendFactor::One, hecl::Backend::ZTest::Original, +// hecl::Backend::CullMode::Backface, true, false, false, true, false, false, false}, +// /* Forced alpha shading */ +// {0, nullptr, hecl::Backend::BlendFactor::SrcAlpha, hecl::Backend::BlendFactor::InvSrcAlpha, +// hecl::Backend::ZTest::Original, hecl::Backend::CullMode::Backface, false, false, true}, +// /* Forced additive shading */ +// {0, nullptr, hecl::Backend::BlendFactor::SrcAlpha, hecl::Backend::BlendFactor::One, hecl::Backend::ZTest::Original, +// hecl::Backend::CullMode::Backface, false, false, true}, +// /* Solid color */ +// {0, nullptr, hecl::Backend::BlendFactor::One, hecl::Backend::BlendFactor::Zero, hecl::Backend::ZTest::LEqual, +// hecl::Backend::CullMode::Backface, false, false, false}, +// /* Solid color additive */ +// {0, nullptr, hecl::Backend::BlendFactor::SrcAlpha, hecl::Backend::BlendFactor::One, hecl::Backend::ZTest::LEqual, +// hecl::Backend::CullMode::Backface, true, false, true}, +// /* Alpha-only Solid color frontface cull, LEqual */ +// {0, nullptr, hecl::Backend::BlendFactor::Zero, hecl::Backend::BlendFactor::One, hecl::Backend::ZTest::LEqual, +// hecl::Backend::CullMode::Frontface, false, true, false}, +// /* Alpha-only Solid color frontface cull, Always, No Z-write */ +// {0, nullptr, hecl::Backend::BlendFactor::Zero, hecl::Backend::BlendFactor::One, hecl::Backend::ZTest::None, +// hecl::Backend::CullMode::Frontface, true, true, false}, +// /* Alpha-only Solid color backface cull, LEqual */ +// {0, nullptr, hecl::Backend::BlendFactor::Zero, hecl::Backend::BlendFactor::One, hecl::Backend::ZTest::LEqual, +// hecl::Backend::CullMode::Backface, false, true, false}, +// /* Alpha-only Solid color backface cull, Greater, No Z-write */ +// {0, nullptr, hecl::Backend::BlendFactor::Zero, hecl::Backend::BlendFactor::One, hecl::Backend::ZTest::Greater, +// hecl::Backend::CullMode::Backface, true, true, false}, +// /* MorphBall shadow shading */ +// {3, BallFadeTextures.data(), hecl::Backend::BlendFactor::SrcAlpha, hecl::Backend::BlendFactor::InvSrcAlpha, +// hecl::Backend::ZTest::Equal, hecl::Backend::CullMode::Backface, false, false, true, false, true}, +// /* World shadow shading (modified lighting) */ +// {1, WorldShadowTextures.data(), hecl::Backend::BlendFactor::Original, hecl::Backend::BlendFactor::Original, +// hecl::Backend::ZTest::Original, hecl::Backend::CullMode::Backface, false, false, true}, +// /* Forced alpha shading without culling */ +// {0, nullptr, hecl::Backend::BlendFactor::SrcAlpha, hecl::Backend::BlendFactor::InvSrcAlpha, +// hecl::Backend::ZTest::Original, hecl::Backend::CullMode::None, false, false, true}, +// /* Forced additive shading without culling */ +// {0, nullptr, hecl::Backend::BlendFactor::SrcAlpha, hecl::Backend::BlendFactor::One, hecl::Backend::ZTest::Original, +// hecl::Backend::CullMode::None, false, false, true}, +// /* Forced alpha shading without Z-write */ +// {0, nullptr, hecl::Backend::BlendFactor::SrcAlpha, hecl::Backend::BlendFactor::InvSrcAlpha, +// hecl::Backend::ZTest::Original, hecl::Backend::CullMode::Original, true, false, true}, +// /* Forced additive shading without Z-write */ +// {0, nullptr, hecl::Backend::BlendFactor::SrcAlpha, hecl::Backend::BlendFactor::One, hecl::Backend::ZTest::Original, +// hecl::Backend::CullMode::Original, true, false, true}, +// /* Forced alpha shading without culling or Z-write */ +// {0, nullptr, hecl::Backend::BlendFactor::SrcAlpha, hecl::Backend::BlendFactor::InvSrcAlpha, +// hecl::Backend::ZTest::Original, hecl::Backend::CullMode::None, true, false, true}, +// /* Forced additive shading without culling or Z-write */ +// {0, nullptr, hecl::Backend::BlendFactor::SrcAlpha, hecl::Backend::BlendFactor::One, hecl::Backend::ZTest::Original, +// hecl::Backend::CullMode::None, true, false, true}, +// /* Depth GEqual no Z-write */ +// {0, nullptr, hecl::Backend::BlendFactor::SrcAlpha, hecl::Backend::BlendFactor::InvSrcAlpha, +// hecl::Backend::ZTest::GEqual, hecl::Backend::CullMode::Backface, true, false, true}, +// /* Disintegration */ +// {2, DisintegrateTextures.data(), hecl::Backend::BlendFactor::SrcAlpha, hecl::Backend::BlendFactor::InvSrcAlpha, +// hecl::Backend::ZTest::LEqual, hecl::Backend::CullMode::Original, false, false, true, false, false, true}, +// /* Forced additive shading without culling or Z-write and greater depth test */ +// {0, nullptr, hecl::Backend::BlendFactor::SrcAlpha, hecl::Backend::BlendFactor::One, hecl::Backend::ZTest::Greater, +// hecl::Backend::CullMode::None, true, false, true}, +// /* Thermal cold shading */ +// {0, nullptr, hecl::Backend::BlendFactor::Original, hecl::Backend::BlendFactor::Original, +// hecl::Backend::ZTest::Original, hecl::Backend::CullMode::Original, false, false, true, false, false, false, true}, +// /* Normal lit shading with alpha */ +// {0, nullptr, hecl::Backend::BlendFactor::Original, hecl::Backend::BlendFactor::Original, +// hecl::Backend::ZTest::Original, hecl::Backend::CullMode::Backface}, +// /* Normal lit shading with alpha without Z-write or depth test */ +// {0, nullptr, hecl::Backend::BlendFactor::Original, hecl::Backend::BlendFactor::Original, hecl::Backend::ZTest::None, +// hecl::Backend::CullMode::Backface, true}, +// /* Normal lit shading with cube reflection */ +// {0, nullptr, hecl::Backend::BlendFactor::Original, hecl::Backend::BlendFactor::Original, +// hecl::Backend::ZTest::Original, hecl::Backend::CullMode::Backface, false, false, true}, +// /* Normal lit shading with cube reflection and world shadow */ +// {1, WorldShadowTextures.data(), hecl::Backend::BlendFactor::Original, hecl::Backend::BlendFactor::Original, +// hecl::Backend::ZTest::Original, hecl::Backend::CullMode::Backface, false, false, true}, +//}}; -constexpr std::array ShaderMacros{ - "URDE_LIGHTING", - "URDE_LIGHTING", - "URDE_THERMAL_MODEL", - "URDE_THERMAL_MODEL", - "URDE_THERMAL_STATIC", - "URDE_THERMAL_STATIC", - "URDE_LIGHTING", - "URDE_LIGHTING", - "URDE_SOLID", - "URDE_SOLID", - "URDE_SOLID", - "URDE_SOLID", - "URDE_SOLID", - "URDE_SOLID", - "URDE_MB_SHADOW", - "URDE_LIGHTING_SHADOW", - "URDE_LIGHTING", - "URDE_LIGHTING", - "URDE_LIGHTING", - "URDE_LIGHTING", - "URDE_LIGHTING", - "URDE_LIGHTING", - "URDE_LIGHTING", - "URDE_DISINTEGRATE", - "URDE_LIGHTING", - "URDE_THERMAL_COLD", - "URDE_LIGHTING", - "URDE_LIGHTING", - "URDE_LIGHTING_CUBE_REFLECTION", - "URDE_LIGHTING_CUBE_REFLECTION_SHADOW", -}; +//constexpr std::array ShaderMacros{ +// "URDE_LIGHTING", +// "URDE_LIGHTING", +// "URDE_THERMAL_MODEL", +// "URDE_THERMAL_MODEL", +// "URDE_THERMAL_STATIC", +// "URDE_THERMAL_STATIC", +// "URDE_LIGHTING", +// "URDE_LIGHTING", +// "URDE_SOLID", +// "URDE_SOLID", +// "URDE_SOLID", +// "URDE_SOLID", +// "URDE_SOLID", +// "URDE_SOLID", +// "URDE_MB_SHADOW", +// "URDE_LIGHTING_SHADOW", +// "URDE_LIGHTING", +// "URDE_LIGHTING", +// "URDE_LIGHTING", +// "URDE_LIGHTING", +// "URDE_LIGHTING", +// "URDE_LIGHTING", +// "URDE_LIGHTING", +// "URDE_DISINTEGRATE", +// "URDE_LIGHTING", +// "URDE_THERMAL_COLD", +// "URDE_LIGHTING", +// "URDE_LIGHTING", +// "URDE_LIGHTING_CUBE_REFLECTION", +// "URDE_LIGHTING_CUBE_REFLECTION_SHADOW", +//}; void CModelShaders::Initialize() { - for (size_t i = 0; i < g_ExtensionSlots.size(); i++) { - g_ExtensionSlots[i].shaderMacro = ShaderMacros[i]; - } +// for (size_t i = 0; i < g_ExtensionSlots.size(); i++) { +// g_ExtensionSlots[i].shaderMacro = ShaderMacros[i]; +// } } -void CModelShaders::Shutdown() { g_ShaderPipelines.clear(); } - -CModelShaders::ShaderPipelines CModelShaders::BuildExtendedShader(const hecl::Backend::ShaderTag& tag, - const Material& material) { - auto search = g_ShaderPipelines.find(tag.val64()); - if (search != g_ShaderPipelines.cend()) - return search->second; - - ShaderPipelines& newPipelines = g_ShaderPipelines[tag.val64()]; - newPipelines = std::make_shared(); - CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) { - size_t idx = 0; - for (const auto& ext : g_ExtensionSlots) - (*newPipelines)[idx++] = hecl::conv->convert(ctx, Shader_CModelShaders(SModelShadersInfo(material, tag, ext))); - return true; - } BooTrace); - return newPipelines; +void CModelShaders::Shutdown() { +// g_ShaderPipelines.clear(); } +//CModelShaders::ShaderPipelines CModelShaders::BuildExtendedShader(const hecl::Backend::ShaderTag& tag, +// const Material& material) { +// auto search = g_ShaderPipelines.find(tag.val64()); +// if (search != g_ShaderPipelines.cend()) +// return search->second; +// +// ShaderPipelines& newPipelines = g_ShaderPipelines[tag.val64()]; +// newPipelines = std::make_shared(); +// CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) { +// size_t idx = 0; +// for (const auto& ext : g_ExtensionSlots) +// (*newPipelines)[idx++] = hecl::conv->convert(ctx, Shader_CModelShaders(SModelShadersInfo(material, tag, ext))); +// return true; +// } BooTrace); +// return newPipelines; +//} + } // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CModelShaders.hpp b/Runtime/Graphics/Shaders/CModelShaders.hpp index 34f447b5f..961f59bf3 100644 --- a/Runtime/Graphics/Shaders/CModelShaders.hpp +++ b/Runtime/Graphics/Shaders/CModelShaders.hpp @@ -4,7 +4,7 @@ #include #include -#include "DataSpec/DNAMP1/CMDLMaterials.hpp" +//#include "DataSpec/DNAMP1/CMDLMaterials.hpp" #include "Runtime/Graphics/CGraphics.hpp" @@ -100,14 +100,14 @@ public: static void Initialize(); static void Shutdown(); - using ShaderPipelinesData = std::array, size_t(EExtendedShader::MAX)>; - using ShaderPipelines = std::shared_ptr; +// using ShaderPipelinesData = std::array, size_t(EExtendedShader::MAX)>; +// using ShaderPipelines = std::shared_ptr; - using Material = DataSpec::DNAMP1::HMDLMaterialSet::Material; - static ShaderPipelines BuildExtendedShader(const hecl::Backend::ShaderTag& tag, const Material& material); +// using Material = DataSpec::DNAMP1::HMDLMaterialSet::Material; +// static ShaderPipelines BuildExtendedShader(const hecl::Backend::ShaderTag& tag, const Material& material); private: - static std::unordered_map g_ShaderPipelines; +// static std::unordered_map g_ShaderPipelines; }; } // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CParticleSwooshShaders.cpp b/Runtime/Graphics/Shaders/CParticleSwooshShaders.cpp index e33e3d7a1..ebc3fc54b 100644 --- a/Runtime/Graphics/Shaders/CParticleSwooshShaders.cpp +++ b/Runtime/Graphics/Shaders/CParticleSwooshShaders.cpp @@ -5,56 +5,56 @@ #include "Runtime/Particle/CParticleSwoosh.hpp" #include "Runtime/Particle/CSwooshDescription.hpp" -#include +//#include namespace metaforce { -std::array, 2> CParticleSwooshShaders::m_texZWrite; -std::array, 2> CParticleSwooshShaders::m_texNoZWrite; -std::array, 2> CParticleSwooshShaders::m_texAdditiveZWrite; -std::array, 2> CParticleSwooshShaders::m_texAdditiveNoZWrite; - -std::array, 2> CParticleSwooshShaders::m_noTexZWrite; -std::array, 2> CParticleSwooshShaders::m_noTexNoZWrite; -std::array, 2> CParticleSwooshShaders::m_noTexAdditiveZWrite; -std::array, 2> CParticleSwooshShaders::m_noTexAdditiveNoZWrite; +//std::array, 2> CParticleSwooshShaders::m_texZWrite; +//std::array, 2> CParticleSwooshShaders::m_texNoZWrite; +//std::array, 2> CParticleSwooshShaders::m_texAdditiveZWrite; +//std::array, 2> CParticleSwooshShaders::m_texAdditiveNoZWrite; +// +//std::array, 2> CParticleSwooshShaders::m_noTexZWrite; +//std::array, 2> CParticleSwooshShaders::m_noTexNoZWrite; +//std::array, 2> CParticleSwooshShaders::m_noTexAdditiveZWrite; +//std::array, 2> CParticleSwooshShaders::m_noTexAdditiveNoZWrite; void CParticleSwooshShaders::Initialize() { - m_texZWrite = {hecl::conv->convert(Shader_CParticleSwooshShaderTexZWrite{}), - hecl::conv->convert(Shader_CParticleSwooshShaderTexZWriteAWrite{})}; - m_texNoZWrite = {hecl::conv->convert(Shader_CParticleSwooshShaderTexNoZWrite{}), - hecl::conv->convert(Shader_CParticleSwooshShaderTexNoZWriteAWrite{})}; - m_texAdditiveZWrite = {hecl::conv->convert(Shader_CParticleSwooshShaderTexAdditiveZWrite{}), - hecl::conv->convert(Shader_CParticleSwooshShaderTexAdditiveZWriteAWrite{})}; - m_texAdditiveNoZWrite = {hecl::conv->convert(Shader_CParticleSwooshShaderTexAdditiveNoZWrite{}), - hecl::conv->convert(Shader_CParticleSwooshShaderTexAdditiveNoZWriteAWrite{})}; - m_noTexZWrite = {hecl::conv->convert(Shader_CParticleSwooshShaderNoTexZWrite{}), - hecl::conv->convert(Shader_CParticleSwooshShaderNoTexZWriteAWrite{})}; - m_noTexNoZWrite = {hecl::conv->convert(Shader_CParticleSwooshShaderNoTexNoZWrite{}), - hecl::conv->convert(Shader_CParticleSwooshShaderNoTexNoZWriteAWrite{})}; - m_noTexAdditiveZWrite = {hecl::conv->convert(Shader_CParticleSwooshShaderNoTexAdditiveZWrite{}), - hecl::conv->convert(Shader_CParticleSwooshShaderNoTexAdditiveZWriteAWrite{})}; - m_noTexAdditiveNoZWrite = {hecl::conv->convert(Shader_CParticleSwooshShaderNoTexAdditiveNoZWrite{}), - hecl::conv->convert(Shader_CParticleSwooshShaderNoTexAdditiveNoZWriteAWrite{})}; +// m_texZWrite = {hecl::conv->convert(Shader_CParticleSwooshShaderTexZWrite{}), +// hecl::conv->convert(Shader_CParticleSwooshShaderTexZWriteAWrite{})}; +// m_texNoZWrite = {hecl::conv->convert(Shader_CParticleSwooshShaderTexNoZWrite{}), +// hecl::conv->convert(Shader_CParticleSwooshShaderTexNoZWriteAWrite{})}; +// m_texAdditiveZWrite = {hecl::conv->convert(Shader_CParticleSwooshShaderTexAdditiveZWrite{}), +// hecl::conv->convert(Shader_CParticleSwooshShaderTexAdditiveZWriteAWrite{})}; +// m_texAdditiveNoZWrite = {hecl::conv->convert(Shader_CParticleSwooshShaderTexAdditiveNoZWrite{}), +// hecl::conv->convert(Shader_CParticleSwooshShaderTexAdditiveNoZWriteAWrite{})}; +// m_noTexZWrite = {hecl::conv->convert(Shader_CParticleSwooshShaderNoTexZWrite{}), +// hecl::conv->convert(Shader_CParticleSwooshShaderNoTexZWriteAWrite{})}; +// m_noTexNoZWrite = {hecl::conv->convert(Shader_CParticleSwooshShaderNoTexNoZWrite{}), +// hecl::conv->convert(Shader_CParticleSwooshShaderNoTexNoZWriteAWrite{})}; +// m_noTexAdditiveZWrite = {hecl::conv->convert(Shader_CParticleSwooshShaderNoTexAdditiveZWrite{}), +// hecl::conv->convert(Shader_CParticleSwooshShaderNoTexAdditiveZWriteAWrite{})}; +// m_noTexAdditiveNoZWrite = {hecl::conv->convert(Shader_CParticleSwooshShaderNoTexAdditiveNoZWrite{}), +// hecl::conv->convert(Shader_CParticleSwooshShaderNoTexAdditiveNoZWriteAWrite{})}; } void CParticleSwooshShaders::Shutdown() { - for (auto& s : m_texZWrite) - s.reset(); - for (auto& s : m_texNoZWrite) - s.reset(); - for (auto& s : m_texAdditiveZWrite) - s.reset(); - for (auto& s : m_texAdditiveNoZWrite) - s.reset(); - for (auto& s : m_noTexZWrite) - s.reset(); - for (auto& s : m_noTexNoZWrite) - s.reset(); - for (auto& s : m_noTexAdditiveZWrite) - s.reset(); - for (auto& s : m_noTexAdditiveNoZWrite) - s.reset(); +// for (auto& s : m_texZWrite) +// s.reset(); +// for (auto& s : m_texNoZWrite) +// s.reset(); +// for (auto& s : m_texAdditiveZWrite) +// s.reset(); +// for (auto& s : m_texAdditiveNoZWrite) +// s.reset(); +// for (auto& s : m_noTexZWrite) +// s.reset(); +// for (auto& s : m_noTexNoZWrite) +// s.reset(); +// for (auto& s : m_noTexAdditiveZWrite) +// s.reset(); +// for (auto& s : m_noTexAdditiveNoZWrite) +// s.reset(); } CParticleSwooshShaders::EShaderClass CParticleSwooshShaders::GetShaderClass(CParticleSwoosh& gen) { @@ -66,47 +66,47 @@ CParticleSwooshShaders::EShaderClass CParticleSwooshShaders::GetShaderClass(CPar return EShaderClass::NoTex; } -void CParticleSwooshShaders::BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, CParticleSwoosh& gen) { +void CParticleSwooshShaders::BuildShaderDataBinding(CParticleSwoosh& gen) { CSwooshDescription* desc = gen.GetDesc(); - std::array, 2>* pipeline = nullptr; - - if (desc->x3c_TEXR) { - if (desc->x44_31_AALP) { - if (desc->x45_24_ZBUF) - pipeline = &m_texAdditiveZWrite; - else - pipeline = &m_texAdditiveNoZWrite; - } else { - if (desc->x45_24_ZBUF) - pipeline = &m_texZWrite; - else - pipeline = &m_texNoZWrite; - } - } else { - if (desc->x44_31_AALP) { - if (desc->x45_24_ZBUF) - pipeline = &m_noTexAdditiveZWrite; - else - pipeline = &m_noTexAdditiveNoZWrite; - } else { - if (desc->x45_24_ZBUF) - pipeline = &m_noTexZWrite; - else - pipeline = &m_noTexNoZWrite; - } - } - - const CUVElement* const texr = desc->x3c_TEXR.get(); - const std::array, 1> textures{ - texr ? texr->GetValueTexture(0).GetObj()->GetBooTexture() : nullptr, - }; - - const std::array, 1> uniforms{gen.m_uniformBuf.get()}; - for (size_t i = 0; i < gen.m_dataBind.size(); ++i) { - gen.m_dataBind[i] = - ctx.newShaderDataBinding((*pipeline)[i], gen.m_vertBuf.get(), nullptr, nullptr, uniforms.size(), - uniforms.data(), nullptr, texr ? 1 : 0, textures.data(), nullptr, nullptr); - } +// std::array, 2>* pipeline = nullptr; +// +// if (desc->x3c_TEXR) { +// if (desc->x44_31_AALP) { +// if (desc->x45_24_ZBUF) +// pipeline = &m_texAdditiveZWrite; +// else +// pipeline = &m_texAdditiveNoZWrite; +// } else { +// if (desc->x45_24_ZBUF) +// pipeline = &m_texZWrite; +// else +// pipeline = &m_texNoZWrite; +// } +// } else { +// if (desc->x44_31_AALP) { +// if (desc->x45_24_ZBUF) +// pipeline = &m_noTexAdditiveZWrite; +// else +// pipeline = &m_noTexAdditiveNoZWrite; +// } else { +// if (desc->x45_24_ZBUF) +// pipeline = &m_noTexZWrite; +// else +// pipeline = &m_noTexNoZWrite; +// } +// } +// +// const CUVElement* const texr = desc->x3c_TEXR.get(); +// const std::array, 1> textures{ +// texr ? texr->GetValueTexture(0).GetObj()->GetBooTexture() : nullptr, +// }; +// +// const std::array, 1> uniforms{gen.m_uniformBuf.get()}; +// for (size_t i = 0; i < gen.m_dataBind.size(); ++i) { +// gen.m_dataBind[i] = +// ctx.newShaderDataBinding((*pipeline)[i], gen.m_vertBuf.get(), nullptr, nullptr, uniforms.size(), +// uniforms.data(), nullptr, texr ? 1 : 0, textures.data(), nullptr, nullptr); +// } } } // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CParticleSwooshShaders.hpp b/Runtime/Graphics/Shaders/CParticleSwooshShaders.hpp index bcdd8aae4..5b4211a12 100644 --- a/Runtime/Graphics/Shaders/CParticleSwooshShaders.hpp +++ b/Runtime/Graphics/Shaders/CParticleSwooshShaders.hpp @@ -2,7 +2,7 @@ #include -#include +//#include #include #include @@ -22,21 +22,21 @@ public: }; private: - static std::array, 2> m_texZWrite; - static std::array, 2> m_texNoZWrite; - static std::array, 2> m_texAdditiveZWrite; - static std::array, 2> m_texAdditiveNoZWrite; - - static std::array, 2> m_noTexZWrite; - static std::array, 2> m_noTexNoZWrite; - static std::array, 2> m_noTexAdditiveZWrite; - static std::array, 2> m_noTexAdditiveNoZWrite; +// static std::array, 2> m_texZWrite; +// static std::array, 2> m_texNoZWrite; +// static std::array, 2> m_texAdditiveZWrite; +// static std::array, 2> m_texAdditiveNoZWrite; +// +// static std::array, 2> m_noTexZWrite; +// static std::array, 2> m_noTexNoZWrite; +// static std::array, 2> m_noTexAdditiveZWrite; +// static std::array, 2> m_noTexAdditiveNoZWrite; public: static void Initialize(); static void Shutdown(); static EShaderClass GetShaderClass(CParticleSwoosh& gen); - static void BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, CParticleSwoosh& gen); + static void BuildShaderDataBinding(CParticleSwoosh& gen); }; } // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CPhazonSuitFilter.cpp b/Runtime/Graphics/Shaders/CPhazonSuitFilter.cpp index 7316e32e3..3c0ee0d68 100644 --- a/Runtime/Graphics/Shaders/CPhazonSuitFilter.cpp +++ b/Runtime/Graphics/Shaders/CPhazonSuitFilter.cpp @@ -6,7 +6,7 @@ #include "Runtime/Graphics/CGraphics.hpp" #include "Runtime/Graphics/CTexture.hpp" -#include +//#include #include #include @@ -15,103 +15,103 @@ namespace metaforce { -static boo::ObjToken s_IndPipeline; -static boo::ObjToken s_Pipeline; -static boo::ObjToken s_BlurPipeline; +//static boo::ObjToken s_IndPipeline; +//static boo::ObjToken s_Pipeline; +//static boo::ObjToken s_BlurPipeline; void CPhazonSuitFilter::Initialize() { - s_IndPipeline = hecl::conv->convert(Shader_CPhazonSuitFilterInd{}); - s_Pipeline = hecl::conv->convert(Shader_CPhazonSuitFilterNoInd{}); - s_BlurPipeline = hecl::conv->convert(Shader_CPhazonSuitFilterBlur{}); +// s_IndPipeline = hecl::conv->convert(Shader_CPhazonSuitFilterInd{}); +// s_Pipeline = hecl::conv->convert(Shader_CPhazonSuitFilterNoInd{}); +// s_BlurPipeline = hecl::conv->convert(Shader_CPhazonSuitFilterBlur{}); } void CPhazonSuitFilter::Shutdown() { - s_IndPipeline.reset(); - s_Pipeline.reset(); - s_BlurPipeline.reset(); +// s_IndPipeline.reset(); +// s_Pipeline.reset(); +// s_BlurPipeline.reset(); } void CPhazonSuitFilter::drawBlurPasses(float radius, const CTexture* indTex) { SCOPED_GRAPHICS_DEBUG_GROUP("CPhazonSuitFilter::drawBlurPasses", zeus::skMagenta); - if (!m_dataBind || indTex != m_indTex) { - m_indTex = indTex; - CGraphics::CommitResources([this](boo::IGraphicsDataFactory::Context& ctx) { - m_uniBufBlurX = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(zeus::CVector4f), 1); - m_uniBufBlurY = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(zeus::CVector4f), 1); - m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(zeus::CVector4f) * 2, 1); - - struct BlurVert { - zeus::CVector3f pos; - zeus::CVector2f uv; - }; - const std::array blurVerts{{ - {{-1.f, 1.f, 0.f}, {0.f, 1.f}}, - {{-1.f, -1.f, 0.f}, {0.f, 0.f}}, - {{1.f, 1.f, 0.f}, {1.f, 1.f}}, - {{1.f, -1.f, 0.f}, {1.f, 0.f}}, - }}; - m_blurVbo = ctx.newStaticBuffer(boo::BufferUse::Vertex, blurVerts.data(), sizeof(BlurVert), blurVerts.size()); - - struct Vert { - zeus::CVector3f pos; - zeus::CVector2f screenUv; - zeus::CVector2f indUv; - zeus::CVector2f maskUv; - }; - const std::array verts{{ - {{-1.f, 1.f, 0.f}, {0.01f, 0.99f}, {0.f, 4.f}, {0.f, 1.f}}, - {{-1.f, -1.f, 0.f}, {0.01f, 0.01f}, {0.f, 0.f}, {0.f, 0.f}}, - {{1.f, 1.f, 0.f}, {0.99f, 0.99f}, {g_Viewport.aspect * 4.f, 4.f}, {1.f, 1.f}}, - {{1.f, -1.f, 0.f}, {0.99f, 0.01f}, {g_Viewport.aspect * 4.f, 0.f}, {1.f, 0.f}}, - }}; - m_vbo = ctx.newStaticBuffer(boo::BufferUse::Vertex, verts.data(), sizeof(Vert), verts.size()); - - std::array, 1> bufs{m_uniBufBlurX.get()}; - constexpr std::array stages{boo::PipelineStage::Vertex}; - std::array, 4> texs; - std::array texBindIdxs; - - texs[0] = CGraphics::g_SpareTexture.get(); - texBindIdxs[0] = 1; - m_dataBindBlurX = - ctx.newShaderDataBinding(s_BlurPipeline, m_blurVbo.get(), nullptr, nullptr, bufs.size(), bufs.data(), - stages.data(), nullptr, nullptr, 1, texs.data(), texBindIdxs.data(), nullptr); - - bufs[0] = m_uniBufBlurY.get(); - texs[0] = CGraphics::g_SpareTexture.get(); - texBindIdxs[0] = 2; - m_dataBindBlurY = - ctx.newShaderDataBinding(s_BlurPipeline, m_blurVbo.get(), nullptr, nullptr, bufs.size(), bufs.data(), - stages.data(), nullptr, nullptr, 1, texs.data(), texBindIdxs.data(), nullptr); - - bufs[0] = m_uniBuf.get(); - size_t texCount; - if (m_indTex) { - texs[0] = CGraphics::g_SpareTexture.get(); - texBindIdxs[0] = 0; - texs[1] = m_indTex->GetBooTexture(); - texBindIdxs[1] = 0; - texs[2] = CGraphics::g_SpareTexture.get(); - texBindIdxs[2] = 1; - texs[3] = CGraphics::g_SpareTexture.get(); - texBindIdxs[3] = 2; - texCount = 4; - } else { - texs[0] = CGraphics::g_SpareTexture.get(); - texBindIdxs[0] = 0; - texs[1] = CGraphics::g_SpareTexture.get(); - texBindIdxs[1] = 1; - texs[2] = CGraphics::g_SpareTexture.get(); - texBindIdxs[2] = 2; - texCount = 3; - } - - m_dataBind = ctx.newShaderDataBinding(m_indTex ? s_IndPipeline : s_Pipeline, m_vbo.get(), nullptr, nullptr, - bufs.size(), bufs.data(), stages.data(), nullptr, nullptr, texCount, - texs.data(), texBindIdxs.data(), nullptr); - return true; - } BooTrace); - } +// if (!m_dataBind || indTex != m_indTex) { +// m_indTex = indTex; +// CGraphics::CommitResources([this](boo::IGraphicsDataFactory::Context& ctx) { +// m_uniBufBlurX = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(zeus::CVector4f), 1); +// m_uniBufBlurY = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(zeus::CVector4f), 1); +// m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(zeus::CVector4f) * 2, 1); +// +// struct BlurVert { +// zeus::CVector3f pos; +// zeus::CVector2f uv; +// }; +// const std::array blurVerts{{ +// {{-1.f, 1.f, 0.f}, {0.f, 1.f}}, +// {{-1.f, -1.f, 0.f}, {0.f, 0.f}}, +// {{1.f, 1.f, 0.f}, {1.f, 1.f}}, +// {{1.f, -1.f, 0.f}, {1.f, 0.f}}, +// }}; +// m_blurVbo = ctx.newStaticBuffer(boo::BufferUse::Vertex, blurVerts.data(), sizeof(BlurVert), blurVerts.size()); +// +// struct Vert { +// zeus::CVector3f pos; +// zeus::CVector2f screenUv; +// zeus::CVector2f indUv; +// zeus::CVector2f maskUv; +// }; +// const std::array verts{{ +// {{-1.f, 1.f, 0.f}, {0.01f, 0.99f}, {0.f, 4.f}, {0.f, 1.f}}, +// {{-1.f, -1.f, 0.f}, {0.01f, 0.01f}, {0.f, 0.f}, {0.f, 0.f}}, +// {{1.f, 1.f, 0.f}, {0.99f, 0.99f}, {g_Viewport.aspect * 4.f, 4.f}, {1.f, 1.f}}, +// {{1.f, -1.f, 0.f}, {0.99f, 0.01f}, {g_Viewport.aspect * 4.f, 0.f}, {1.f, 0.f}}, +// }}; +// m_vbo = ctx.newStaticBuffer(boo::BufferUse::Vertex, verts.data(), sizeof(Vert), verts.size()); +// +// std::array, 1> bufs{m_uniBufBlurX.get()}; +// constexpr std::array stages{boo::PipelineStage::Vertex}; +// std::array, 4> texs; +// std::array texBindIdxs; +// +// texs[0] = CGraphics::g_SpareTexture.get(); +// texBindIdxs[0] = 1; +// m_dataBindBlurX = +// ctx.newShaderDataBinding(s_BlurPipeline, m_blurVbo.get(), nullptr, nullptr, bufs.size(), bufs.data(), +// stages.data(), nullptr, nullptr, 1, texs.data(), texBindIdxs.data(), nullptr); +// +// bufs[0] = m_uniBufBlurY.get(); +// texs[0] = CGraphics::g_SpareTexture.get(); +// texBindIdxs[0] = 2; +// m_dataBindBlurY = +// ctx.newShaderDataBinding(s_BlurPipeline, m_blurVbo.get(), nullptr, nullptr, bufs.size(), bufs.data(), +// stages.data(), nullptr, nullptr, 1, texs.data(), texBindIdxs.data(), nullptr); +// +// bufs[0] = m_uniBuf.get(); +// size_t texCount; +// if (m_indTex) { +// texs[0] = CGraphics::g_SpareTexture.get(); +// texBindIdxs[0] = 0; +// texs[1] = m_indTex->GetBooTexture(); +// texBindIdxs[1] = 0; +// texs[2] = CGraphics::g_SpareTexture.get(); +// texBindIdxs[2] = 1; +// texs[3] = CGraphics::g_SpareTexture.get(); +// texBindIdxs[3] = 2; +// texCount = 4; +// } else { +// texs[0] = CGraphics::g_SpareTexture.get(); +// texBindIdxs[0] = 0; +// texs[1] = CGraphics::g_SpareTexture.get(); +// texBindIdxs[1] = 1; +// texs[2] = CGraphics::g_SpareTexture.get(); +// texBindIdxs[2] = 2; +// texCount = 3; +// } +// +// m_dataBind = ctx.newShaderDataBinding(m_indTex ? s_IndPipeline : s_Pipeline, m_vbo.get(), nullptr, nullptr, +// bufs.size(), bufs.data(), stages.data(), nullptr, nullptr, texCount, +// texs.data(), texBindIdxs.data(), nullptr); +// return true; +// } BooTrace); +// } SClipScreenRect rect; rect.x4_left = g_Viewport.x0_left; @@ -123,18 +123,18 @@ void CPhazonSuitFilter::drawBlurPasses(float radius, const CTexture* indTex) { /* X Pass */ auto blurDir = zeus::CVector4f{g_Viewport.xc_height / float(g_Viewport.x8_width) * radius * blurScale, 0.f, 0.f, 0.f}; - m_uniBufBlurX->load(&blurDir, sizeof(zeus::CVector4f)); +// m_uniBufBlurX->load(&blurDir, sizeof(zeus::CVector4f)); - CGraphics::SetShaderDataBinding(m_dataBindBlurX); - CGraphics::DrawArray(0, 4); +// CGraphics::SetShaderDataBinding(m_dataBindBlurX); +// CGraphics::DrawArray(0, 4); CGraphics::ResolveSpareTexture(rect, 2); /* Y Pass */ blurDir = zeus::CVector4f{0.f, radius * blurScale, 0.f, 0.f}; - m_uniBufBlurY->load(&blurDir, sizeof(zeus::CVector4f)); +// m_uniBufBlurY->load(&blurDir, sizeof(zeus::CVector4f)); - CGraphics::SetShaderDataBinding(m_dataBindBlurY); - CGraphics::DrawArray(0, 4); +// CGraphics::SetShaderDataBinding(m_dataBindBlurY); +// CGraphics::DrawArray(0, 4); CGraphics::ResolveSpareTexture(rect, 2); } @@ -145,9 +145,9 @@ void CPhazonSuitFilter::draw(const zeus::CColor& color, float indScale, float in zeus::CVector4f indScaleOff; } uniform = {color, zeus::CVector4f(indScale, indScale, indOffX, indOffY)}; - m_uniBuf->load(&uniform, sizeof(Uniform)); - CGraphics::SetShaderDataBinding(m_dataBind); - CGraphics::DrawArray(0, 4); +// m_uniBuf->load(&uniform, sizeof(Uniform)); +// CGraphics::SetShaderDataBinding(m_dataBind); +// CGraphics::DrawArray(0, 4); } } // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CPhazonSuitFilter.hpp b/Runtime/Graphics/Shaders/CPhazonSuitFilter.hpp index d966356c4..c3e39a3d1 100644 --- a/Runtime/Graphics/Shaders/CPhazonSuitFilter.hpp +++ b/Runtime/Graphics/Shaders/CPhazonSuitFilter.hpp @@ -1,24 +1,24 @@ #pragma once -#include +//#include namespace zeus { class CColor; -} +} // namespace zeus namespace metaforce { class CTexture; class CPhazonSuitFilter { - boo::ObjToken m_uniBufBlurX; - boo::ObjToken m_uniBufBlurY; - boo::ObjToken m_uniBuf; - boo::ObjToken m_blurVbo; - boo::ObjToken m_vbo; +// boo::ObjToken m_uniBufBlurX; +// boo::ObjToken m_uniBufBlurY; +// boo::ObjToken m_uniBuf; +// boo::ObjToken m_blurVbo; +// boo::ObjToken m_vbo; const CTexture* m_indTex = nullptr; - boo::ObjToken m_dataBindBlurX; - boo::ObjToken m_dataBindBlurY; - boo::ObjToken m_dataBind; +// boo::ObjToken m_dataBindBlurX; +// boo::ObjToken m_dataBindBlurY; +// boo::ObjToken m_dataBind; public: static void Initialize(); diff --git a/Runtime/Graphics/Shaders/CRadarPaintShader.cpp b/Runtime/Graphics/Shaders/CRadarPaintShader.cpp index 2b153f55d..eaf1b444a 100644 --- a/Runtime/Graphics/Shaders/CRadarPaintShader.cpp +++ b/Runtime/Graphics/Shaders/CRadarPaintShader.cpp @@ -5,15 +5,19 @@ #include "Runtime/Graphics/CGraphics.hpp" #include "Runtime/Graphics/CTexture.hpp" -#include +//#include namespace metaforce { -static boo::ObjToken s_Pipeline; +//static boo::ObjToken s_Pipeline; -void CRadarPaintShader::Initialize() { s_Pipeline = hecl::conv->convert(Shader_CRadarPaintShader{}); } +void CRadarPaintShader::Initialize() { +// s_Pipeline = hecl::conv->convert(Shader_CRadarPaintShader{}); +} -void CRadarPaintShader::Shutdown() { s_Pipeline.reset(); } +void CRadarPaintShader::Shutdown() { +// s_Pipeline.reset(); +} void CRadarPaintShader::draw(const std::vector& instances, const CTexture* tex) { if (!instances.size()) @@ -23,31 +27,31 @@ void CRadarPaintShader::draw(const std::vector& instances, const CText if (instances.size() > m_maxInsts) { m_maxInsts = instances.size(); m_tex = tex; - CGraphics::CommitResources([this](boo::IGraphicsDataFactory::Context& ctx) { - m_vbo = ctx.newDynamicBuffer(boo::BufferUse::Vertex, sizeof(Instance), m_maxInsts); - m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(zeus::CMatrix4f), 1); - - const std::array, 1> bufs{m_uniBuf.get()}; - constexpr std::array stages{boo::PipelineStage::Vertex}; - const std::array, 1> texs{m_tex->GetBooTexture()}; - - m_dataBind = - ctx.newShaderDataBinding(s_Pipeline, nullptr, m_vbo.get(), nullptr, bufs.size(), bufs.data(), stages.data(), - nullptr, nullptr, texs.size(), texs.data(), nullptr, nullptr); - return true; - } BooTrace); +// CGraphics::CommitResources([this](boo::IGraphicsDataFactory::Context& ctx) { +// m_vbo = ctx.newDynamicBuffer(boo::BufferUse::Vertex, sizeof(Instance), m_maxInsts); +// m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(zeus::CMatrix4f), 1); +// +// const std::array, 1> bufs{m_uniBuf.get()}; +// constexpr std::array stages{boo::PipelineStage::Vertex}; +// const std::array, 1> texs{m_tex->GetBooTexture()}; +// +// m_dataBind = +// ctx.newShaderDataBinding(s_Pipeline, nullptr, m_vbo.get(), nullptr, bufs.size(), bufs.data(), stages.data(), +// nullptr, nullptr, texs.size(), texs.data(), nullptr, nullptr); +// return true; +// } BooTrace); } zeus::CMatrix4f uniMtx = CGraphics::GetPerspectiveProjectionMatrix(true) * CGraphics::g_GXModelView.toMatrix4f(); - m_uniBuf->load(&uniMtx, sizeof(zeus::CMatrix4f)); +// m_uniBuf->load(&uniMtx, sizeof(zeus::CMatrix4f)); size_t mapSz = sizeof(Instance) * instances.size(); - Instance* insts = reinterpret_cast(m_vbo->map(mapSz)); - memmove(insts, instances.data(), mapSz); - m_vbo->unmap(); +// Instance* insts = reinterpret_cast(m_vbo->map(mapSz)); +// memmove(insts, instances.data(), mapSz); +// m_vbo->unmap(); - CGraphics::SetShaderDataBinding(m_dataBind); - CGraphics::DrawInstances(0, 4, instances.size()); +// CGraphics::SetShaderDataBinding(m_dataBind); +// CGraphics::DrawInstances(0, 4, instances.size()); } } // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CRadarPaintShader.hpp b/Runtime/Graphics/Shaders/CRadarPaintShader.hpp index fbf4e2335..eb8acbbef 100644 --- a/Runtime/Graphics/Shaders/CRadarPaintShader.hpp +++ b/Runtime/Graphics/Shaders/CRadarPaintShader.hpp @@ -3,7 +3,7 @@ #include #include -#include +//#include #include #include @@ -21,9 +21,9 @@ public: }; private: - boo::ObjToken m_vbo; - boo::ObjToken m_uniBuf; - boo::ObjToken m_dataBind; +// boo::ObjToken m_vbo; +// boo::ObjToken m_uniBuf; +// boo::ObjToken m_dataBind; const CTexture* m_tex = nullptr; size_t m_maxInsts = 0; diff --git a/Runtime/Graphics/Shaders/CRandomStaticFilter.cpp b/Runtime/Graphics/Shaders/CRandomStaticFilter.cpp index cc1e857ee..e45ae3d33 100644 --- a/Runtime/Graphics/Shaders/CRandomStaticFilter.cpp +++ b/Runtime/Graphics/Shaders/CRandomStaticFilter.cpp @@ -6,65 +6,65 @@ #include "Runtime/Camera/CCameraFilter.hpp" #include "Runtime/Graphics/CBooRenderer.hpp" -#include +//#include namespace metaforce { -static boo::ObjToken s_AlphaPipeline; -static boo::ObjToken s_AddPipeline; -static boo::ObjToken s_MultPipeline; -static boo::ObjToken s_CookieCutterPipeline; +//static boo::ObjToken s_AlphaPipeline; +//static boo::ObjToken s_AddPipeline; +//static boo::ObjToken s_MultPipeline; +//static boo::ObjToken s_CookieCutterPipeline; void CRandomStaticFilter::Initialize() { - s_AlphaPipeline = hecl::conv->convert(Shader_CRandomStaticFilterAlpha{}); - s_AddPipeline = hecl::conv->convert(Shader_CRandomStaticFilterAdd{}); - s_MultPipeline = hecl::conv->convert(Shader_CRandomStaticFilterMult{}); - s_CookieCutterPipeline = hecl::conv->convert(Shader_CRandomStaticFilterCookieCutter{}); +// s_AlphaPipeline = hecl::conv->convert(Shader_CRandomStaticFilterAlpha{}); +// s_AddPipeline = hecl::conv->convert(Shader_CRandomStaticFilterAdd{}); +// s_MultPipeline = hecl::conv->convert(Shader_CRandomStaticFilterMult{}); +// s_CookieCutterPipeline = hecl::conv->convert(Shader_CRandomStaticFilterCookieCutter{}); } void CRandomStaticFilter::Shutdown() { - s_AlphaPipeline.reset(); - s_AddPipeline.reset(); - s_MultPipeline.reset(); - s_CookieCutterPipeline.reset(); +// s_AlphaPipeline.reset(); +// s_AddPipeline.reset(); +// s_MultPipeline.reset(); +// s_CookieCutterPipeline.reset(); } -static boo::ObjToken SelectPipeline(EFilterType type) { - switch (type) { - case EFilterType::Blend: - return s_AlphaPipeline; - case EFilterType::Add: - return s_AddPipeline; - case EFilterType::Multiply: - return s_MultPipeline; - default: - return {}; - } -} +//static boo::ObjToken SelectPipeline(EFilterType type) { +// switch (type) { +// case EFilterType::Blend: +// return s_AlphaPipeline; +// case EFilterType::Add: +// return s_AddPipeline; +// case EFilterType::Multiply: +// return s_MultPipeline; +// default: +// return {}; +// } +//} CRandomStaticFilter::CRandomStaticFilter(EFilterType type, bool cookieCutter) : m_cookieCutter(cookieCutter) { - CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) { - struct Vert { - zeus::CVector2f m_pos; - zeus::CVector2f m_uv; - }; - const std::array verts{{ - {{-1.f, -1.f}, {0.f, 0.f}}, - {{-1.f, 1.f}, {0.f, 448.f}}, - {{1.f, -1.f}, {640.f, 0.f}}, - {{1.f, 1.f}, {640.f, 448.f}}, - }}; - m_vbo = ctx.newStaticBuffer(boo::BufferUse::Vertex, verts.data(), sizeof(Vert), verts.size()); - m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(Uniform), 1); - - const std::array, 1> bufs{m_uniBuf.get()}; - constexpr std::array stages{boo::PipelineStage::Vertex}; - const std::array, 1> texs{g_Renderer->GetRandomStaticEntropyTex()}; - m_dataBind = ctx.newShaderDataBinding(m_cookieCutter ? s_CookieCutterPipeline : SelectPipeline(type), m_vbo.get(), - nullptr, nullptr, bufs.size(), bufs.data(), stages.data(), nullptr, nullptr, - texs.size(), texs.data(), nullptr, nullptr); - return true; - } BooTrace); +// CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) { +// struct Vert { +// zeus::CVector2f m_pos; +// zeus::CVector2f m_uv; +// }; +// const std::array verts{{ +// {{-1.f, -1.f}, {0.f, 0.f}}, +// {{-1.f, 1.f}, {0.f, 448.f}}, +// {{1.f, -1.f}, {640.f, 0.f}}, +// {{1.f, 1.f}, {640.f, 448.f}}, +// }}; +// m_vbo = ctx.newStaticBuffer(boo::BufferUse::Vertex, verts.data(), sizeof(Vert), verts.size()); +// m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(Uniform), 1); +// +// const std::array, 1> bufs{m_uniBuf.get()}; +// constexpr std::array stages{boo::PipelineStage::Vertex}; +// const std::array, 1> texs{g_Renderer->GetRandomStaticEntropyTex()}; +// m_dataBind = ctx.newShaderDataBinding(m_cookieCutter ? s_CookieCutterPipeline : SelectPipeline(type), m_vbo.get(), +// nullptr, nullptr, bufs.size(), bufs.data(), stages.data(), nullptr, nullptr, +// texs.size(), texs.data(), nullptr, nullptr); +// return true; +// } BooTrace); } void CRandomStaticFilter::draw(const zeus::CColor& color, float t) { @@ -74,10 +74,10 @@ void CRandomStaticFilter::draw(const zeus::CColor& color, float t) { m_uniform.randOff = ROUND_UP_32(int64_t(rand()) * 32767 / RAND_MAX); m_uniform.discardThres = 1.f - t; - m_uniBuf->load(&m_uniform, sizeof(Uniform)); - - CGraphics::SetShaderDataBinding(m_dataBind); - CGraphics::DrawArray(0, 4); +// m_uniBuf->load(&m_uniform, sizeof(Uniform)); +// +// CGraphics::SetShaderDataBinding(m_dataBind); +// CGraphics::DrawArray(0, 4); } } // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CRandomStaticFilter.hpp b/Runtime/Graphics/Shaders/CRandomStaticFilter.hpp index 8cf10f9a6..64a78a131 100644 --- a/Runtime/Graphics/Shaders/CRandomStaticFilter.hpp +++ b/Runtime/Graphics/Shaders/CRandomStaticFilter.hpp @@ -2,7 +2,7 @@ #include "Runtime/CToken.hpp" -#include +//#include #include namespace metaforce { @@ -17,9 +17,9 @@ class CRandomStaticFilter { float randOff; float discardThres; }; - boo::ObjToken m_vbo; - boo::ObjToken m_uniBuf; - boo::ObjToken m_dataBind; +// boo::ObjToken m_vbo; +// boo::ObjToken m_uniBuf; +// boo::ObjToken m_dataBind; Uniform m_uniform; bool m_cookieCutter; diff --git a/Runtime/Graphics/Shaders/CScanLinesFilter.cpp b/Runtime/Graphics/Shaders/CScanLinesFilter.cpp index 6dc980e44..f44ae89b1 100644 --- a/Runtime/Graphics/Shaders/CScanLinesFilter.cpp +++ b/Runtime/Graphics/Shaders/CScanLinesFilter.cpp @@ -7,61 +7,61 @@ #include "Runtime/Graphics/CBooRenderer.hpp" #include "Runtime/Graphics/CGraphics.hpp" -#include +//#include namespace metaforce { -static boo::ObjToken s_AlphaPipeline; -static boo::ObjToken s_AddPipeline; -static boo::ObjToken s_MultPipeline; +//static boo::ObjToken s_AlphaPipeline; +//static boo::ObjToken s_AddPipeline; +//static boo::ObjToken s_MultPipeline; void CScanLinesFilter::Initialize() { - s_AlphaPipeline = hecl::conv->convert(Shader_CScanLinesFilterAlpha{}); - s_AddPipeline = hecl::conv->convert(Shader_CScanLinesFilterAdd{}); - s_MultPipeline = hecl::conv->convert(Shader_CScanLinesFilterMult{}); +// s_AlphaPipeline = hecl::conv->convert(Shader_CScanLinesFilterAlpha{}); +// s_AddPipeline = hecl::conv->convert(Shader_CScanLinesFilterAdd{}); +// s_MultPipeline = hecl::conv->convert(Shader_CScanLinesFilterMult{}); } void CScanLinesFilter::Shutdown() { - s_AlphaPipeline.reset(); - s_AddPipeline.reset(); - s_MultPipeline.reset(); +// s_AlphaPipeline.reset(); +// s_AddPipeline.reset(); +// s_MultPipeline.reset(); } -static boo::ObjToken SelectPipeline(EFilterType type) { - switch (type) { - case EFilterType::Blend: - return s_AlphaPipeline; - case EFilterType::Add: - return s_AddPipeline; - case EFilterType::Multiply: - return s_MultPipeline; - default: - return {}; - } -} +//static boo::ObjToken SelectPipeline(EFilterType type) { +// switch (type) { +// case EFilterType::Blend: +// return s_AlphaPipeline; +// case EFilterType::Add: +// return s_AddPipeline; +// case EFilterType::Multiply: +// return s_MultPipeline; +// default: +// return {}; +// } +//} CScanLinesFilter::CScanLinesFilter(EFilterType type, bool even) : m_even(even) { - CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) { - m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(Uniform), 1); - boo::ObjToken vbo = - m_even ? g_Renderer->GetScanLinesEvenVBO().get() : g_Renderer->GetScanLinesOddVBO().get(); - const std::array, 1> bufs{m_uniBuf.get()}; - constexpr std::array stages{boo::PipelineStage::Vertex}; - - m_dataBind = ctx.newShaderDataBinding(SelectPipeline(type), vbo, nullptr, nullptr, bufs.size(), bufs.data(), - stages.data(), nullptr, nullptr, 0, nullptr, nullptr, nullptr); - return true; - } BooTrace); +// CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) { +// m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(Uniform), 1); +// boo::ObjToken vbo = +// m_even ? g_Renderer->GetScanLinesEvenVBO().get() : g_Renderer->GetScanLinesOddVBO().get(); +// const std::array, 1> bufs{m_uniBuf.get()}; +// constexpr std::array stages{boo::PipelineStage::Vertex}; +// +// m_dataBind = ctx.newShaderDataBinding(SelectPipeline(type), vbo, nullptr, nullptr, bufs.size(), bufs.data(), +// stages.data(), nullptr, nullptr, 0, nullptr, nullptr, nullptr); +// return true; +// } BooTrace); } void CScanLinesFilter::draw(const zeus::CColor& color) { SCOPED_GRAPHICS_DEBUG_GROUP("CScanLinesFilter::draw", zeus::skMagenta); m_uniform.color = color; - m_uniBuf->load(&m_uniform, sizeof(Uniform)); - - CGraphics::SetShaderDataBinding(m_dataBind); - CGraphics::DrawArray(0, 670); +// m_uniBuf->load(&m_uniform, sizeof(Uniform)); +// +// CGraphics::SetShaderDataBinding(m_dataBind); +// CGraphics::DrawArray(0, 670); } } // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CScanLinesFilter.hpp b/Runtime/Graphics/Shaders/CScanLinesFilter.hpp index cdd048fd3..3b2b28f28 100644 --- a/Runtime/Graphics/Shaders/CScanLinesFilter.hpp +++ b/Runtime/Graphics/Shaders/CScanLinesFilter.hpp @@ -2,7 +2,7 @@ #include "Runtime/CToken.hpp" -#include +//#include #include namespace metaforce { @@ -15,8 +15,8 @@ class CScanLinesFilter { struct Uniform { zeus::CColor color; }; - boo::ObjToken m_uniBuf; - boo::ObjToken m_dataBind; +// boo::ObjToken m_uniBuf; +// boo::ObjToken m_dataBind; Uniform m_uniform; bool m_even; diff --git a/Runtime/Graphics/Shaders/CSpaceWarpFilter.cpp b/Runtime/Graphics/Shaders/CSpaceWarpFilter.cpp index ec9478e41..5b9618a4a 100644 --- a/Runtime/Graphics/Shaders/CSpaceWarpFilter.cpp +++ b/Runtime/Graphics/Shaders/CSpaceWarpFilter.cpp @@ -3,19 +3,23 @@ #include "Runtime/Graphics/CBooRenderer.hpp" #include "Runtime/Graphics/CGraphics.hpp" -#include +//#include #define WARP_RAMP_RES 32 namespace metaforce { -static boo::ObjToken s_Pipeline; +// static boo::ObjToken s_Pipeline; -void CSpaceWarpFilter::Initialize() { s_Pipeline = hecl::conv->convert(Shader_CSpaceWarpFilter{}); } +void CSpaceWarpFilter::Initialize() { + // s_Pipeline = hecl::conv->convert(Shader_CSpaceWarpFilter{}); +} -void CSpaceWarpFilter::Shutdown() { s_Pipeline.reset(); } +void CSpaceWarpFilter::Shutdown() { + // s_Pipeline.reset(); +} -void CSpaceWarpFilter::GenerateWarpRampTex(boo::IGraphicsDataFactory::Context& ctx) { +void CSpaceWarpFilter::GenerateWarpRampTex() { std::array, WARP_RAMP_RES + 1>, WARP_RAMP_RES + 1> data{}; const float halfRes = WARP_RAMP_RES / 2.f; for (int y = 0; y < WARP_RAMP_RES + 1; ++y) { @@ -31,40 +35,39 @@ void CSpaceWarpFilter::GenerateWarpRampTex(boo::IGraphicsDataFactory::Context& c data[y][x][0] = data[y][x][1] = data[y][x][2]; } } - m_warpTex = - ctx.newStaticTexture(WARP_RAMP_RES + 1, WARP_RAMP_RES + 1, 1, boo::TextureFormat::RGBA8, - boo::TextureClampMode::Repeat, data.data(), (WARP_RAMP_RES + 1) * (WARP_RAMP_RES + 1) * 4) - .get(); + m_warpTex = aurora::new_static_texture_2d( + WARP_RAMP_RES + 1, WARP_RAMP_RES + 1, 1, aurora::shaders::TextureFormat::R8, + {reinterpret_cast(data.data()), (WARP_RAMP_RES + 1) * (WARP_RAMP_RES + 1) * 4}, "Warp Ramp"); } CSpaceWarpFilter::CSpaceWarpFilter() { - CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) { - GenerateWarpRampTex(ctx); - - struct Vert { - zeus::CVector2f m_pos; - zeus::CVector2f m_uv; - }; - const std::array verts{{ - {{-1.f, -1.f}, {0.f, 0.f}}, - {{-1.f, 1.f}, {0.f, 1.f}}, - {{1.f, -1.f}, {1.f, 0.f}}, - {{1.f, 1.f}, {1.f, 1.f}}, - }}; - - m_vbo = ctx.newStaticBuffer(boo::BufferUse::Vertex, verts.data(), 32, verts.size()); - m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(Uniform), 1); - - const std::array, 1> bufs{m_uniBuf.get()}; - constexpr std::array stages{boo::PipelineStage::Vertex}; - const std::array, 2> texs{ - CGraphics::g_SpareTexture.get(), - m_warpTex.get(), - }; - m_dataBind = ctx.newShaderDataBinding(s_Pipeline, m_vbo.get(), nullptr, nullptr, bufs.size(), bufs.data(), - stages.data(), nullptr, nullptr, texs.size(), texs.data(), nullptr, nullptr); - return true; - } BooTrace); +// CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) { +// GenerateWarpRampTex(ctx); +// +// struct Vert { +// zeus::CVector2f m_pos; +// zeus::CVector2f m_uv; +// }; +// const std::array verts{{ +// {{-1.f, -1.f}, {0.f, 0.f}}, +// {{-1.f, 1.f}, {0.f, 1.f}}, +// {{1.f, -1.f}, {1.f, 0.f}}, +// {{1.f, 1.f}, {1.f, 1.f}}, +// }}; +// +// m_vbo = ctx.newStaticBuffer(boo::BufferUse::Vertex, verts.data(), 32, verts.size()); +// m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(Uniform), 1); +// +// const std::array, 1> bufs{m_uniBuf.get()}; +// constexpr std::array stages{boo::PipelineStage::Vertex}; +// const std::array, 2> texs{ +// CGraphics::g_SpareTexture.get(), +// m_warpTex.get(), +// }; +// m_dataBind = ctx.newShaderDataBinding(s_Pipeline, m_vbo.get(), nullptr, nullptr, bufs.size(), bufs.data(), +// stages.data(), nullptr, nullptr, texs.size(), texs.data(), nullptr, nullptr); +// return true; +// } BooTrace); } void CSpaceWarpFilter::draw(const zeus::CVector3f& pt) { @@ -129,15 +132,15 @@ void CSpaceWarpFilter::draw(const zeus::CVector3f& pt) { m_uniform.m_matrix[1][1] = clipRect.x10_height / vp.y(); m_uniform.m_matrix[3][0] = pt.x() + (1.f / vp.x()); m_uniform.m_matrix[3][1] = pt.y() + (1.f / vp.y()); - if (CGraphics::g_BooPlatform == boo::IGraphicsDataFactory::Platform::OpenGL) { - m_uniform.m_matrix[3][2] = pt.z() * 2.f - 1.f; - } else if (CGraphics::g_BooPlatform == boo::IGraphicsDataFactory::Platform::Vulkan) { - m_uniform.m_matrix[1][1] *= -1.f; - m_uniform.m_matrix[3][1] *= -1.f; - m_uniform.m_matrix[3][2] = pt.z(); - } else { - m_uniform.m_matrix[3][2] = pt.z(); - } +// if (CGraphics::g_BooPlatform == boo::IGraphicsDataFactory::Platform::OpenGL) { +// m_uniform.m_matrix[3][2] = pt.z() * 2.f - 1.f; +// } else if (CGraphics::g_BooPlatform == boo::IGraphicsDataFactory::Platform::Vulkan) { +// m_uniform.m_matrix[1][1] *= -1.f; +// m_uniform.m_matrix[3][1] *= -1.f; +// m_uniform.m_matrix[3][2] = pt.z(); +// } else { +// m_uniform.m_matrix[3][2] = pt.z(); +// } if (clipRect.x4_left) { clipRect.x4_left -= 1; @@ -160,10 +163,10 @@ void CSpaceWarpFilter::draw(const zeus::CVector3f& pt) { m_uniform.m_strength.x() = m_uniform.m_matrix[0][0] * m_strength * 0.5f * (clipRect.x10_height / float(clipRect.xc_width)); m_uniform.m_strength.y() = m_uniform.m_matrix[1][1] * m_strength * 0.5f; - m_uniBuf->load(&m_uniform, sizeof(m_uniform)); +// m_uniBuf->load(&m_uniform, sizeof(m_uniform)); - CGraphics::SetShaderDataBinding(m_dataBind); - CGraphics::DrawArray(0, 4); +// CGraphics::SetShaderDataBinding(m_dataBind); +// CGraphics::DrawArray(0, 4); } } // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CSpaceWarpFilter.hpp b/Runtime/Graphics/Shaders/CSpaceWarpFilter.hpp index ac5963b7c..8c85fd5be 100644 --- a/Runtime/Graphics/Shaders/CSpaceWarpFilter.hpp +++ b/Runtime/Graphics/Shaders/CSpaceWarpFilter.hpp @@ -3,8 +3,7 @@ #include #include "Runtime/GCNTypes.hpp" - -#include +#include "Runtime/Graphics/CGraphics.hpp" #include #include @@ -18,14 +17,14 @@ class CSpaceWarpFilter { zeus::CVector3f m_strength; }; std::array, 8>, 4> m_shiftTexture{}; - boo::ObjToken m_warpTex; - boo::ObjToken m_vbo; - boo::ObjToken m_uniBuf; - boo::ObjToken m_dataBind; + std::shared_ptr m_warpTex; +// boo::ObjToken m_vbo; +// boo::ObjToken m_uniBuf; +// boo::ObjToken m_dataBind; Uniform m_uniform; float m_strength = 1.f; - void GenerateWarpRampTex(boo::IGraphicsDataFactory::Context& ctx); + void GenerateWarpRampTex(); public: static void Initialize(); diff --git a/Runtime/Graphics/Shaders/CTextSupportShader.cpp b/Runtime/Graphics/Shaders/CTextSupportShader.cpp index 9a0525c14..a00604956 100644 --- a/Runtime/Graphics/Shaders/CTextSupportShader.cpp +++ b/Runtime/Graphics/Shaders/CTextSupportShader.cpp @@ -3,42 +3,42 @@ #include "Runtime/GuiSys/CFontImageDef.hpp" #include "Runtime/GuiSys/CRasterFont.hpp" -#include +//#include namespace metaforce { -boo::ObjToken CTextSupportShader::s_TextAlphaPipeline; -boo::ObjToken CTextSupportShader::s_TextAddPipeline; -boo::ObjToken CTextSupportShader::s_TextAddOverdrawPipeline; - -boo::ObjToken CTextSupportShader::s_ImageAlphaPipeline; -boo::ObjToken CTextSupportShader::s_ImageAddPipeline; -boo::ObjToken CTextSupportShader::s_ImageAddOverdrawPipeline; - -hecl::VertexBufferPool CTextSupportShader::s_CharInsts; -hecl::VertexBufferPool CTextSupportShader::s_ImgInsts; -hecl::UniformBufferPool CTextSupportShader::s_Uniforms; +//boo::ObjToken CTextSupportShader::s_TextAlphaPipeline; +//boo::ObjToken CTextSupportShader::s_TextAddPipeline; +//boo::ObjToken CTextSupportShader::s_TextAddOverdrawPipeline; +// +//boo::ObjToken CTextSupportShader::s_ImageAlphaPipeline; +//boo::ObjToken CTextSupportShader::s_ImageAddPipeline; +//boo::ObjToken CTextSupportShader::s_ImageAddOverdrawPipeline; +// +//hecl::VertexBufferPool CTextSupportShader::s_CharInsts; +//hecl::VertexBufferPool CTextSupportShader::s_ImgInsts; +//hecl::UniformBufferPool CTextSupportShader::s_Uniforms; void CTextSupportShader::Initialize() { - s_TextAlphaPipeline = hecl::conv->convert(Shader_CTextSupportShaderAlpha{}); - s_TextAddPipeline = hecl::conv->convert(Shader_CTextSupportShaderAdd{}); - s_TextAddOverdrawPipeline = hecl::conv->convert(Shader_CTextSupportShaderAddOverdraw{}); - s_ImageAlphaPipeline = hecl::conv->convert(Shader_CTextSupportShaderImageAlpha{}); - s_ImageAddPipeline = hecl::conv->convert(Shader_CTextSupportShaderImageAdd{}); - s_ImageAddOverdrawPipeline = hecl::conv->convert(Shader_CTextSupportShaderImageAddOverdraw{}); +// s_TextAlphaPipeline = hecl::conv->convert(Shader_CTextSupportShaderAlpha{}); +// s_TextAddPipeline = hecl::conv->convert(Shader_CTextSupportShaderAdd{}); +// s_TextAddOverdrawPipeline = hecl::conv->convert(Shader_CTextSupportShaderAddOverdraw{}); +// s_ImageAlphaPipeline = hecl::conv->convert(Shader_CTextSupportShaderImageAlpha{}); +// s_ImageAddPipeline = hecl::conv->convert(Shader_CTextSupportShaderImageAdd{}); +// s_ImageAddOverdrawPipeline = hecl::conv->convert(Shader_CTextSupportShaderImageAddOverdraw{}); } void CTextSupportShader::Shutdown() { - s_TextAlphaPipeline.reset(); - s_TextAddPipeline.reset(); - s_TextAddOverdrawPipeline.reset(); - s_ImageAlphaPipeline.reset(); - s_ImageAddPipeline.reset(); - s_ImageAddOverdrawPipeline.reset(); - - s_CharInsts.doDestroy(); - s_ImgInsts.doDestroy(); - s_Uniforms.doDestroy(); +// s_TextAlphaPipeline.reset(); +// s_TextAddPipeline.reset(); +// s_TextAddOverdrawPipeline.reset(); +// s_ImageAlphaPipeline.reset(); +// s_ImageAddPipeline.reset(); +// s_ImageAddOverdrawPipeline.reset(); +// +// s_CharInsts.doDestroy(); +// s_ImgInsts.doDestroy(); +// s_Uniforms.doDestroy(); } void CTextSupportShader::CharacterInstance::SetMetrics(const CGlyph& glyph, const zeus::CVector2i& offset) { diff --git a/Runtime/Graphics/Shaders/CTextSupportShader.hpp b/Runtime/Graphics/Shaders/CTextSupportShader.hpp index 37ab564b1..580b29d73 100644 --- a/Runtime/Graphics/Shaders/CTextSupportShader.hpp +++ b/Runtime/Graphics/Shaders/CTextSupportShader.hpp @@ -4,8 +4,8 @@ #include "Runtime/GuiSys/CGuiWidget.hpp" -#include -#include +//#include +//#include #include #include @@ -21,13 +21,13 @@ class CTextRenderBuffer; class CTextSupportShader { friend class CTextRenderBuffer; - static boo::ObjToken s_TextAlphaPipeline; - static boo::ObjToken s_TextAddPipeline; - static boo::ObjToken s_TextAddOverdrawPipeline; - - static boo::ObjToken s_ImageAlphaPipeline; - static boo::ObjToken s_ImageAddPipeline; - static boo::ObjToken s_ImageAddOverdrawPipeline; +// static boo::ObjToken s_TextAlphaPipeline; +// static boo::ObjToken s_TextAddPipeline; +// static boo::ObjToken s_TextAddOverdrawPipeline; +// +// static boo::ObjToken s_ImageAlphaPipeline; +// static boo::ObjToken s_ImageAddPipeline; +// static boo::ObjToken s_ImageAddOverdrawPipeline; struct Uniform { zeus::CMatrix4f m_mvp; @@ -50,47 +50,47 @@ class CTextSupportShader { void SetMetrics(const CFontImageDef& imgDef, const zeus::CVector2i& offset); }; - static hecl::VertexBufferPool s_CharInsts; - static hecl::VertexBufferPool s_ImgInsts; - static hecl::UniformBufferPool s_Uniforms; +// static hecl::VertexBufferPool s_CharInsts; +// static hecl::VertexBufferPool s_ImgInsts; +// static hecl::UniformBufferPool s_Uniforms; public: - static boo::ObjToken SelectTextPipeline(CGuiWidget::EGuiModelDrawFlags df) { - switch (df) { - case CGuiWidget::EGuiModelDrawFlags::Shadeless: - case CGuiWidget::EGuiModelDrawFlags::Opaque: - case CGuiWidget::EGuiModelDrawFlags::Alpha: - case CGuiWidget::EGuiModelDrawFlags::AlphaAdditiveOverdraw: - return s_TextAlphaPipeline; - case CGuiWidget::EGuiModelDrawFlags::Additive: - return s_TextAddPipeline; - default: - return {}; - } - } - - static boo::ObjToken SelectImagePipeline(CGuiWidget::EGuiModelDrawFlags df) { - switch (df) { - case CGuiWidget::EGuiModelDrawFlags::Shadeless: - case CGuiWidget::EGuiModelDrawFlags::Opaque: - case CGuiWidget::EGuiModelDrawFlags::Alpha: - case CGuiWidget::EGuiModelDrawFlags::AlphaAdditiveOverdraw: - return s_ImageAlphaPipeline; - case CGuiWidget::EGuiModelDrawFlags::Additive: - return s_ImageAddPipeline; - default: - return {}; - } - } - - static boo::ObjToken GetTextAdditiveOverdrawPipeline() { return s_TextAddOverdrawPipeline; } - - static boo::ObjToken GetImageAdditiveOverdrawPipeline() { return s_ImageAddOverdrawPipeline; } +// static boo::ObjToken SelectTextPipeline(CGuiWidget::EGuiModelDrawFlags df) { +// switch (df) { +// case CGuiWidget::EGuiModelDrawFlags::Shadeless: +// case CGuiWidget::EGuiModelDrawFlags::Opaque: +// case CGuiWidget::EGuiModelDrawFlags::Alpha: +// case CGuiWidget::EGuiModelDrawFlags::AlphaAdditiveOverdraw: +// return s_TextAlphaPipeline; +// case CGuiWidget::EGuiModelDrawFlags::Additive: +// return s_TextAddPipeline; +// default: +// return {}; +// } +// } +// +// static boo::ObjToken SelectImagePipeline(CGuiWidget::EGuiModelDrawFlags df) { +// switch (df) { +// case CGuiWidget::EGuiModelDrawFlags::Shadeless: +// case CGuiWidget::EGuiModelDrawFlags::Opaque: +// case CGuiWidget::EGuiModelDrawFlags::Alpha: +// case CGuiWidget::EGuiModelDrawFlags::AlphaAdditiveOverdraw: +// return s_ImageAlphaPipeline; +// case CGuiWidget::EGuiModelDrawFlags::Additive: +// return s_ImageAddPipeline; +// default: +// return {}; +// } +// } +// +// static boo::ObjToken GetTextAdditiveOverdrawPipeline() { return s_TextAddOverdrawPipeline; } +// +// static boo::ObjToken GetImageAdditiveOverdrawPipeline() { return s_ImageAddOverdrawPipeline; } static void UpdateBuffers() { - s_CharInsts.updateBuffers(); - s_ImgInsts.updateBuffers(); - s_Uniforms.updateBuffers(); +// s_CharInsts.updateBuffers(); +// s_ImgInsts.updateBuffers(); +// s_Uniforms.updateBuffers(); } static void Initialize(); diff --git a/Runtime/Graphics/Shaders/CTexturedQuadFilter.cpp b/Runtime/Graphics/Shaders/CTexturedQuadFilter.cpp index 7bbc857d1..fe207bab3 100644 --- a/Runtime/Graphics/Shaders/CTexturedQuadFilter.cpp +++ b/Runtime/Graphics/Shaders/CTexturedQuadFilter.cpp @@ -5,204 +5,204 @@ #include "Runtime/Camera/CCameraFilter.hpp" #include "Runtime/Graphics/CTexture.hpp" -#include +//#include namespace metaforce { -static boo::ObjToken s_AlphaPipeline; -static boo::ObjToken s_AlphaGEqualPipeline; -static boo::ObjToken s_AlphaGEqualZWritePipeline; -static boo::ObjToken s_AlphaLEqualPipeline; -static boo::ObjToken s_AddPipeline; -static boo::ObjToken s_AddGEqualPipeline; -static boo::ObjToken s_AddGEqualZWritePipeline; -static boo::ObjToken s_AddLEqualPipeline; -static boo::ObjToken s_SubtractPipeline; -static boo::ObjToken s_SubtractGEqualPipeline; -static boo::ObjToken s_SubtractGEqualZWritePipeline; -static boo::ObjToken s_SubtractLEqualPipeline; -static boo::ObjToken s_MultPipeline; -static boo::ObjToken s_MultGEqualPipeline; -static boo::ObjToken s_MultGEqualZWritePipeline; -static boo::ObjToken s_MultLEqualPipeline; -static boo::ObjToken s_InvDstMultPipeline; -static boo::ObjToken s_InvDstMultGEqualPipeline; -static boo::ObjToken s_InvDstMultLEqualPipeline; - -static boo::ObjToken s_AAlphaPipeline; -static boo::ObjToken s_AAddPipeline; -static boo::ObjToken s_ASubtractPipeline; -static boo::ObjToken s_AMultPipeline; -static boo::ObjToken s_AInvDstMultPipeline; +//static boo::ObjToken s_AlphaPipeline; +//static boo::ObjToken s_AlphaGEqualPipeline; +//static boo::ObjToken s_AlphaGEqualZWritePipeline; +//static boo::ObjToken s_AlphaLEqualPipeline; +//static boo::ObjToken s_AddPipeline; +//static boo::ObjToken s_AddGEqualPipeline; +//static boo::ObjToken s_AddGEqualZWritePipeline; +//static boo::ObjToken s_AddLEqualPipeline; +//static boo::ObjToken s_SubtractPipeline; +//static boo::ObjToken s_SubtractGEqualPipeline; +//static boo::ObjToken s_SubtractGEqualZWritePipeline; +//static boo::ObjToken s_SubtractLEqualPipeline; +//static boo::ObjToken s_MultPipeline; +//static boo::ObjToken s_MultGEqualPipeline; +//static boo::ObjToken s_MultGEqualZWritePipeline; +//static boo::ObjToken s_MultLEqualPipeline; +//static boo::ObjToken s_InvDstMultPipeline; +//static boo::ObjToken s_InvDstMultGEqualPipeline; +//static boo::ObjToken s_InvDstMultLEqualPipeline; +// +//static boo::ObjToken s_AAlphaPipeline; +//static boo::ObjToken s_AAddPipeline; +//static boo::ObjToken s_ASubtractPipeline; +//static boo::ObjToken s_AMultPipeline; +//static boo::ObjToken s_AInvDstMultPipeline; void CTexturedQuadFilter::Initialize() { - s_AlphaPipeline = hecl::conv->convert(Shader_CTexturedQuadFilterAlpha{}); - s_AlphaGEqualPipeline = hecl::conv->convert(Shader_CTexturedQuadFilterAlphaGEqual{}); - s_AlphaGEqualZWritePipeline = hecl::conv->convert(Shader_CTexturedQuadFilterAlphaGEqualZWrite{}); - s_AlphaLEqualPipeline = hecl::conv->convert(Shader_CTexturedQuadFilterAlphaLEqual{}); - s_AddPipeline = hecl::conv->convert(Shader_CTexturedQuadFilterAdd{}); - s_AddGEqualPipeline = hecl::conv->convert(Shader_CTexturedQuadFilterAddGEqual{}); - s_AddGEqualZWritePipeline = hecl::conv->convert(Shader_CTexturedQuadFilterAddGEqualZWrite{}); - s_AddLEqualPipeline = hecl::conv->convert(Shader_CTexturedQuadFilterAddLEqual{}); - s_SubtractPipeline = hecl::conv->convert(Shader_CTexturedQuadFilterSubtract{}); - s_SubtractGEqualPipeline = hecl::conv->convert(Shader_CTexturedQuadFilterSubtractGEqual{}); - s_SubtractGEqualZWritePipeline = hecl::conv->convert(Shader_CTexturedQuadFilterSubtractGEqualZWrite{}); - s_SubtractLEqualPipeline = hecl::conv->convert(Shader_CTexturedQuadFilterSubtractLEqual{}); - s_MultPipeline = hecl::conv->convert(Shader_CTexturedQuadFilterMult{}); - s_MultGEqualPipeline = hecl::conv->convert(Shader_CTexturedQuadFilterMultGEqual{}); - s_MultGEqualZWritePipeline = hecl::conv->convert(Shader_CTexturedQuadFilterMultGEqualZWrite{}); - s_MultLEqualPipeline = hecl::conv->convert(Shader_CTexturedQuadFilterMultLEqual{}); - s_InvDstMultPipeline = hecl::conv->convert(Shader_CTexturedQuadFilterInvDstMult{}); - s_InvDstMultGEqualPipeline = hecl::conv->convert(Shader_CTexturedQuadFilterInvDstMultGEqual{}); - s_InvDstMultLEqualPipeline = hecl::conv->convert(Shader_CTexturedQuadFilterInvDstMultLEqual{}); +// s_AlphaPipeline = hecl::conv->convert(Shader_CTexturedQuadFilterAlpha{}); +// s_AlphaGEqualPipeline = hecl::conv->convert(Shader_CTexturedQuadFilterAlphaGEqual{}); +// s_AlphaGEqualZWritePipeline = hecl::conv->convert(Shader_CTexturedQuadFilterAlphaGEqualZWrite{}); +// s_AlphaLEqualPipeline = hecl::conv->convert(Shader_CTexturedQuadFilterAlphaLEqual{}); +// s_AddPipeline = hecl::conv->convert(Shader_CTexturedQuadFilterAdd{}); +// s_AddGEqualPipeline = hecl::conv->convert(Shader_CTexturedQuadFilterAddGEqual{}); +// s_AddGEqualZWritePipeline = hecl::conv->convert(Shader_CTexturedQuadFilterAddGEqualZWrite{}); +// s_AddLEqualPipeline = hecl::conv->convert(Shader_CTexturedQuadFilterAddLEqual{}); +// s_SubtractPipeline = hecl::conv->convert(Shader_CTexturedQuadFilterSubtract{}); +// s_SubtractGEqualPipeline = hecl::conv->convert(Shader_CTexturedQuadFilterSubtractGEqual{}); +// s_SubtractGEqualZWritePipeline = hecl::conv->convert(Shader_CTexturedQuadFilterSubtractGEqualZWrite{}); +// s_SubtractLEqualPipeline = hecl::conv->convert(Shader_CTexturedQuadFilterSubtractLEqual{}); +// s_MultPipeline = hecl::conv->convert(Shader_CTexturedQuadFilterMult{}); +// s_MultGEqualPipeline = hecl::conv->convert(Shader_CTexturedQuadFilterMultGEqual{}); +// s_MultGEqualZWritePipeline = hecl::conv->convert(Shader_CTexturedQuadFilterMultGEqualZWrite{}); +// s_MultLEqualPipeline = hecl::conv->convert(Shader_CTexturedQuadFilterMultLEqual{}); +// s_InvDstMultPipeline = hecl::conv->convert(Shader_CTexturedQuadFilterInvDstMult{}); +// s_InvDstMultGEqualPipeline = hecl::conv->convert(Shader_CTexturedQuadFilterInvDstMultGEqual{}); +// s_InvDstMultLEqualPipeline = hecl::conv->convert(Shader_CTexturedQuadFilterInvDstMultLEqual{}); } void CTexturedQuadFilter::Shutdown() { - s_AlphaPipeline.reset(); - s_AlphaGEqualPipeline.reset(); - s_AlphaGEqualZWritePipeline.reset(); - s_AlphaLEqualPipeline.reset(); - s_AddPipeline.reset(); - s_AddGEqualPipeline.reset(); - s_AddGEqualZWritePipeline.reset(); - s_AddLEqualPipeline.reset(); - s_SubtractPipeline.reset(); - s_SubtractGEqualPipeline.reset(); - s_SubtractGEqualZWritePipeline.reset(); - s_SubtractLEqualPipeline.reset(); - s_MultPipeline.reset(); - s_MultGEqualPipeline.reset(); - s_MultGEqualZWritePipeline.reset(); - s_MultLEqualPipeline.reset(); - s_InvDstMultPipeline.reset(); - s_InvDstMultGEqualPipeline.reset(); - s_InvDstMultLEqualPipeline.reset(); +// s_AlphaPipeline.reset(); +// s_AlphaGEqualPipeline.reset(); +// s_AlphaGEqualZWritePipeline.reset(); +// s_AlphaLEqualPipeline.reset(); +// s_AddPipeline.reset(); +// s_AddGEqualPipeline.reset(); +// s_AddGEqualZWritePipeline.reset(); +// s_AddLEqualPipeline.reset(); +// s_SubtractPipeline.reset(); +// s_SubtractGEqualPipeline.reset(); +// s_SubtractGEqualZWritePipeline.reset(); +// s_SubtractLEqualPipeline.reset(); +// s_MultPipeline.reset(); +// s_MultGEqualPipeline.reset(); +// s_MultGEqualZWritePipeline.reset(); +// s_MultLEqualPipeline.reset(); +// s_InvDstMultPipeline.reset(); +// s_InvDstMultGEqualPipeline.reset(); +// s_InvDstMultLEqualPipeline.reset(); } void CTexturedQuadFilterAlpha::Initialize() { - s_AAlphaPipeline = hecl::conv->convert(Shader_CTexturedQuadFilterAlphaTexAlpha{}); - s_AAddPipeline = hecl::conv->convert(Shader_CTexturedQuadFilterAlphaTexAdd{}); - s_ASubtractPipeline = hecl::conv->convert(Shader_CTexturedQuadFilterAlphaTexSubtract{}); - s_AMultPipeline = hecl::conv->convert(Shader_CTexturedQuadFilterAlphaTexMult{}); - s_AInvDstMultPipeline = hecl::conv->convert(Shader_CTexturedQuadFilterAlphaTexInvDstMult{}); +// s_AAlphaPipeline = hecl::conv->convert(Shader_CTexturedQuadFilterAlphaTexAlpha{}); +// s_AAddPipeline = hecl::conv->convert(Shader_CTexturedQuadFilterAlphaTexAdd{}); +// s_ASubtractPipeline = hecl::conv->convert(Shader_CTexturedQuadFilterAlphaTexSubtract{}); +// s_AMultPipeline = hecl::conv->convert(Shader_CTexturedQuadFilterAlphaTexMult{}); +// s_AInvDstMultPipeline = hecl::conv->convert(Shader_CTexturedQuadFilterAlphaTexInvDstMult{}); } void CTexturedQuadFilterAlpha::Shutdown() { - s_AAlphaPipeline.reset(); - s_AAddPipeline.reset(); - s_ASubtractPipeline.reset(); - s_AMultPipeline.reset(); - s_AInvDstMultPipeline.reset(); +// s_AAlphaPipeline.reset(); +// s_AAddPipeline.reset(); +// s_ASubtractPipeline.reset(); +// s_AMultPipeline.reset(); +// s_AInvDstMultPipeline.reset(); } -static boo::ObjToken SelectPipeline(EFilterType type, CTexturedQuadFilter::ZTest zTest) { - switch (zTest) { - case CTexturedQuadFilter::ZTest::GEqual: - switch (type) { - case EFilterType::Blend: - return s_AlphaGEqualPipeline; - case EFilterType::Add: - return s_AddGEqualPipeline; - case EFilterType::Subtract: - return s_SubtractGEqualPipeline; - case EFilterType::Multiply: - return s_MultGEqualPipeline; - default: - break; - } - break; - case CTexturedQuadFilter::ZTest::GEqualZWrite: - switch (type) { - case EFilterType::Blend: - return s_AlphaGEqualZWritePipeline; - case EFilterType::Add: - return s_AddGEqualZWritePipeline; - case EFilterType::Subtract: - return s_SubtractGEqualZWritePipeline; - case EFilterType::Multiply: - return s_MultGEqualZWritePipeline; - default: - break; - } - break; - case CTexturedQuadFilter::ZTest::LEqual: - switch (type) { - case EFilterType::Blend: - return s_AlphaLEqualPipeline; - case EFilterType::Add: - return s_AddLEqualPipeline; - case EFilterType::Subtract: - return s_SubtractLEqualPipeline; - case EFilterType::Multiply: - return s_MultLEqualPipeline; - case EFilterType::InvDstMultiply: - return s_InvDstMultLEqualPipeline; - default: - break; - } - break; - default: - break; - } +//static boo::ObjToken SelectPipeline(EFilterType type, CTexturedQuadFilter::ZTest zTest) { +// switch (zTest) { +// case CTexturedQuadFilter::ZTest::GEqual: +// switch (type) { +// case EFilterType::Blend: +// return s_AlphaGEqualPipeline; +// case EFilterType::Add: +// return s_AddGEqualPipeline; +// case EFilterType::Subtract: +// return s_SubtractGEqualPipeline; +// case EFilterType::Multiply: +// return s_MultGEqualPipeline; +// default: +// break; +// } +// break; +// case CTexturedQuadFilter::ZTest::GEqualZWrite: +// switch (type) { +// case EFilterType::Blend: +// return s_AlphaGEqualZWritePipeline; +// case EFilterType::Add: +// return s_AddGEqualZWritePipeline; +// case EFilterType::Subtract: +// return s_SubtractGEqualZWritePipeline; +// case EFilterType::Multiply: +// return s_MultGEqualZWritePipeline; +// default: +// break; +// } +// break; +// case CTexturedQuadFilter::ZTest::LEqual: +// switch (type) { +// case EFilterType::Blend: +// return s_AlphaLEqualPipeline; +// case EFilterType::Add: +// return s_AddLEqualPipeline; +// case EFilterType::Subtract: +// return s_SubtractLEqualPipeline; +// case EFilterType::Multiply: +// return s_MultLEqualPipeline; +// case EFilterType::InvDstMultiply: +// return s_InvDstMultLEqualPipeline; +// default: +// break; +// } +// break; +// default: +// break; +// } +// +// switch (type) { +// case EFilterType::Blend: +// return s_AlphaPipeline; +// case EFilterType::Add: +// return s_AddPipeline; +// case EFilterType::Subtract: +// return s_SubtractPipeline; +// case EFilterType::Multiply: +// return s_MultPipeline; +// case EFilterType::InvDstMultiply: +// return s_InvDstMultPipeline; +// default: +// return {}; +// } +//} - switch (type) { - case EFilterType::Blend: - return s_AlphaPipeline; - case EFilterType::Add: - return s_AddPipeline; - case EFilterType::Subtract: - return s_SubtractPipeline; - case EFilterType::Multiply: - return s_MultPipeline; - case EFilterType::InvDstMultiply: - return s_InvDstMultPipeline; - default: - return {}; - } +//static boo::ObjToken SelectAlphaPipeline(EFilterType type) { +// switch (type) { +// case EFilterType::Blend: +// return s_AAlphaPipeline; +// case EFilterType::Add: +// return s_AAddPipeline; +// case EFilterType::Subtract: +// return s_ASubtractPipeline; +// case EFilterType::Multiply: +// return s_AMultPipeline; +// case EFilterType::InvDstMultiply: +// return s_AInvDstMultPipeline; +// default: +// return {}; +// } +//} + +CTexturedQuadFilter::CTexturedQuadFilter(const std::shared_ptr& tex) : m_booTex(tex) { + m_flipRect = true; // TODO? } -static boo::ObjToken SelectAlphaPipeline(EFilterType type) { - switch (type) { - case EFilterType::Blend: - return s_AAlphaPipeline; - case EFilterType::Add: - return s_AAddPipeline; - case EFilterType::Subtract: - return s_ASubtractPipeline; - case EFilterType::Multiply: - return s_AMultPipeline; - case EFilterType::InvDstMultiply: - return s_AInvDstMultPipeline; - default: - return {}; - } -} - -CTexturedQuadFilter::CTexturedQuadFilter(const boo::ObjToken& tex) : m_booTex(tex) { - m_flipRect = CGraphics::g_BooFactory->platform() == boo::IGraphicsDataFactory::Platform::Vulkan; -} - -CTexturedQuadFilter::CTexturedQuadFilter(EFilterType type, const boo::ObjToken& tex, ZTest ztest) +CTexturedQuadFilter::CTexturedQuadFilter(EFilterType type, const std::shared_ptr& tex, ZTest ztest) : m_booTex(tex), m_zTest(ztest) { - m_flipRect = CGraphics::g_BooFactory->platform() == boo::IGraphicsDataFactory::Platform::Vulkan; - tex->setClampMode(boo::TextureClampMode::ClampToEdge); - CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) { - m_vbo = ctx.newDynamicBuffer(boo::BufferUse::Vertex, 32, 16); - m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(Uniform), 1); - - const std::array, 1> bufs{m_uniBuf.get()}; - const std::array stages{boo::PipelineStage::Vertex}; - const std::array, 1> texs{m_booTex.get()}; - m_dataBind = - ctx.newShaderDataBinding(SelectPipeline(type, m_zTest), m_vbo.get(), nullptr, nullptr, bufs.size(), bufs.data(), - stages.data(), nullptr, nullptr, texs.size(), texs.data(), nullptr, nullptr); - return true; - } BooTrace); + m_flipRect = true; // TODO? +// tex->setClampMode(boo::TextureClampMode::ClampToEdge); +// CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) { +// m_vbo = ctx.newDynamicBuffer(boo::BufferUse::Vertex, 32, 16); +// m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(Uniform), 1); +// +// const std::array, 1> bufs{m_uniBuf.get()}; +// const std::array stages{boo::PipelineStage::Vertex}; +// const std::array, 1> texs{m_booTex.get()}; +// m_dataBind = +// ctx.newShaderDataBinding(SelectPipeline(type, m_zTest), m_vbo.get(), nullptr, nullptr, bufs.size(), bufs.data(), +// stages.data(), nullptr, nullptr, texs.size(), texs.data(), nullptr, nullptr); +// return true; +// } BooTrace); } CTexturedQuadFilter::CTexturedQuadFilter(EFilterType type, TLockedToken tex, ZTest ztest) -: CTexturedQuadFilter(type, (tex ? tex->GetBooTexture() : nullptr), ztest) { - m_flipRect = CGraphics::g_BooFactory->platform() == boo::IGraphicsDataFactory::Platform::Vulkan; +: CTexturedQuadFilter(type, (tex ? tex->GetTexture() : nullptr), ztest) { + m_flipRect = true; // TODO? m_tex = tex; } @@ -215,7 +215,7 @@ void CTexturedQuadFilter::draw(const zeus::CColor& color, float uvScale, const z {{1.f, 0.f, z}, {uvScale, 0.f}}, {{1.f, 1.f, z}, {uvScale, uvScale}}, }}; - m_vbo->load(verts.data(), sizeof(verts)); +// m_vbo->load(verts.data(), sizeof(verts)); if (!m_flipRect) { m_uniform.m_matrix[0][0] = rect.size.x() * 2.f; @@ -229,10 +229,10 @@ void CTexturedQuadFilter::draw(const zeus::CColor& color, float uvScale, const z m_uniform.m_matrix[3][1] = rect.position.y() * -2.f + 1.f; } m_uniform.m_color = color; - m_uniBuf->load(&m_uniform, sizeof(m_uniform)); +// m_uniBuf->load(&m_uniform, sizeof(m_uniform)); - CGraphics::SetShaderDataBinding(m_dataBind); - CGraphics::DrawArray(0, 4); +// CGraphics::SetShaderDataBinding(m_dataBind); +// CGraphics::DrawArray(0, 4); } void CTexturedQuadFilter::drawCropped(const zeus::CColor& color, float uvScale) { @@ -249,27 +249,27 @@ void CTexturedQuadFilter::drawCropped(const zeus::CColor& color, float uvScale) {{1.f, -1.f, 0.f}, {(xBias + xFac) * uvScale, yBias * uvScale}}, {{1.f, 1.f, 0.f}, {(xBias + xFac) * uvScale, (yBias + yFac) * uvScale}}, }}; - m_vbo->load(verts.data(), sizeof(verts)); +// m_vbo->load(verts.data(), sizeof(verts)); m_uniform.m_color = color; - m_uniBuf->load(&m_uniform, sizeof(m_uniform)); +// m_uniBuf->load(&m_uniform, sizeof(m_uniform)); - CGraphics::SetShaderDataBinding(m_dataBind); - CGraphics::DrawArray(0, 4); +// CGraphics::SetShaderDataBinding(m_dataBind); +// CGraphics::DrawArray(0, 4); } void CTexturedQuadFilter::drawVerts(const zeus::CColor& color, std::array verts, float lod) { SCOPED_GRAPHICS_DEBUG_GROUP("CTexturedQuadFilter::drawVerts", zeus::skMagenta); - m_vbo->load(verts.data(), sizeof(Vert) * verts.size()); +// m_vbo->load(verts.data(), sizeof(Vert) * verts.size()); m_uniform.m_matrix = CGraphics::GetPerspectiveProjectionMatrix(true) * CGraphics::g_GXModelView.toMatrix4f(); m_uniform.m_color = color; m_uniform.m_lod = lod; - m_uniBuf->load(&m_uniform, sizeof(m_uniform)); +// m_uniBuf->load(&m_uniform, sizeof(m_uniform)); - CGraphics::SetShaderDataBinding(m_dataBind); - CGraphics::DrawArray(0, verts.size()); +// CGraphics::SetShaderDataBinding(m_dataBind); +// CGraphics::DrawArray(0, verts.size()); } void CTexturedQuadFilter::DrawFilter(EFilterShape shape, const zeus::CColor& color, float t) { @@ -278,9 +278,9 @@ void CTexturedQuadFilter::DrawFilter(EFilterShape shape, const zeus::CColor& col m_uniform.m_matrix = zeus::CMatrix4f(); m_uniform.m_lod = 0.f; m_uniform.m_color = color; - m_uniBuf->load(&m_uniform, sizeof(m_uniform)); +// m_uniBuf->load(&m_uniform, sizeof(m_uniform)); - CGraphics::SetShaderDataBinding(m_dataBind); +// CGraphics::SetShaderDataBinding(m_dataBind); if (shape == EFilterShape::FullscreenQuarters) { const std::array QuadVerts{{ @@ -305,11 +305,11 @@ void CTexturedQuadFilter::DrawFilter(EFilterShape shape, const zeus::CColor& col {{0.f, 1.f, 0.f}, {0.f, t}}, {{0.f, 0.f, 0.f}, {0.f, 0.f}}, }}; - m_vbo->load(QuadVerts.data(), sizeof(QuadVerts)); - CGraphics::DrawArray(0, 4); - CGraphics::DrawArray(4, 4); - CGraphics::DrawArray(8, 4); - CGraphics::DrawArray(12, 4); +// m_vbo->load(QuadVerts.data(), sizeof(QuadVerts)); +// CGraphics::DrawArray(0, 4); +// CGraphics::DrawArray(4, 4); +// CGraphics::DrawArray(8, 4); +// CGraphics::DrawArray(12, 4); } else { const std::array FullscreenVerts{{ {{-1.f, -1.f, 0.f}, {0.f, 0.f}}, @@ -317,29 +317,29 @@ void CTexturedQuadFilter::DrawFilter(EFilterShape shape, const zeus::CColor& col {{1.f, -1.f, 0.f}, {t, 0.f}}, {{1.f, 1.f, 0.f}, {t, t}}, }}; - m_vbo->load(FullscreenVerts.data(), sizeof(FullscreenVerts)); - CGraphics::DrawArray(0, FullscreenVerts.size()); +// m_vbo->load(FullscreenVerts.data(), sizeof(FullscreenVerts)); +// CGraphics::DrawArray(0, FullscreenVerts.size()); } } -CTexturedQuadFilterAlpha::CTexturedQuadFilterAlpha(EFilterType type, const boo::ObjToken& tex) +CTexturedQuadFilterAlpha::CTexturedQuadFilterAlpha(EFilterType type, const std::shared_ptr& tex) : CTexturedQuadFilter(tex) { - CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) { - m_vbo = ctx.newDynamicBuffer(boo::BufferUse::Vertex, 32, 4); - m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(Uniform), 1); - - const std::array, 1> bufs{m_uniBuf.get()}; - constexpr std::array stages{boo::PipelineStage::Vertex}; - const std::array, 1> texs{m_booTex.get()}; - m_dataBind = - ctx.newShaderDataBinding(SelectAlphaPipeline(type), m_vbo.get(), nullptr, nullptr, bufs.size(), bufs.data(), - stages.data(), nullptr, nullptr, texs.size(), texs.data(), nullptr, nullptr); - return true; - } BooTrace); +// CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) { +// m_vbo = ctx.newDynamicBuffer(boo::BufferUse::Vertex, 32, 4); +// m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(Uniform), 1); +// +// const std::array, 1> bufs{m_uniBuf.get()}; +// constexpr std::array stages{boo::PipelineStage::Vertex}; +// const std::array, 1> texs{m_booTex.get()}; +// m_dataBind = +// ctx.newShaderDataBinding(SelectAlphaPipeline(type), m_vbo.get(), nullptr, nullptr, bufs.size(), bufs.data(), +// stages.data(), nullptr, nullptr, texs.size(), texs.data(), nullptr, nullptr); +// return true; +// } BooTrace); } CTexturedQuadFilterAlpha::CTexturedQuadFilterAlpha(EFilterType type, TLockedToken tex) -: CTexturedQuadFilterAlpha(type, (tex ? tex->GetBooTexture() : nullptr)) { +: CTexturedQuadFilterAlpha(type, (tex ? tex->GetTexture() : nullptr)) { m_tex = tex; } diff --git a/Runtime/Graphics/Shaders/CTexturedQuadFilter.hpp b/Runtime/Graphics/Shaders/CTexturedQuadFilter.hpp index 7bae3c3ce..187fa7a28 100644 --- a/Runtime/Graphics/Shaders/CTexturedQuadFilter.hpp +++ b/Runtime/Graphics/Shaders/CTexturedQuadFilter.hpp @@ -1,8 +1,7 @@ #pragma once #include "Runtime/CToken.hpp" - -#include +#include "Runtime/Graphics/CGraphics.hpp" #include #include @@ -27,15 +26,15 @@ protected: float m_lod = 0.f; }; TLockedToken m_tex; - boo::ObjToken m_booTex; - boo::ObjToken m_vbo; - boo::ObjToken m_uniBuf; - boo::ObjToken m_dataBind; + std::shared_ptr m_booTex; +// boo::ObjToken m_vbo; +// boo::ObjToken m_uniBuf; +// boo::ObjToken m_dataBind; Uniform m_uniform; ZTest m_zTest; bool m_flipRect = false; - explicit CTexturedQuadFilter(const boo::ObjToken& tex); + explicit CTexturedQuadFilter(const std::shared_ptr& tex); public: struct Vert { @@ -46,7 +45,7 @@ public: static void Shutdown(); static constexpr zeus::CRectangle DefaultRect{0.f, 0.f, 1.f, 1.f}; explicit CTexturedQuadFilter(EFilterType type, TLockedToken tex, ZTest zTest = ZTest::None); - explicit CTexturedQuadFilter(EFilterType type, const boo::ObjToken& tex, ZTest zTest = ZTest::None); + explicit CTexturedQuadFilter(EFilterType type, const std::shared_ptr& tex, ZTest zTest = ZTest::None); CTexturedQuadFilter(const CTexturedQuadFilter&) = delete; CTexturedQuadFilter& operator=(const CTexturedQuadFilter&) = delete; CTexturedQuadFilter(CTexturedQuadFilter&&) = default; @@ -56,7 +55,7 @@ public: void drawVerts(const zeus::CColor& color, std::array verts, float lod = 0.f); void DrawFilter(EFilterShape shape, const zeus::CColor& color, float t); const TLockedToken& GetTex() const { return m_tex; } - const boo::ObjToken& GetBooTex() const { return m_booTex; } + const std::shared_ptr& GetBooTex() const { return m_booTex; } }; class CTexturedQuadFilterAlpha : public CTexturedQuadFilter { @@ -64,7 +63,7 @@ public: static void Initialize(); static void Shutdown(); explicit CTexturedQuadFilterAlpha(EFilterType type, TLockedToken tex); - explicit CTexturedQuadFilterAlpha(EFilterType type, const boo::ObjToken& tex); + explicit CTexturedQuadFilterAlpha(EFilterType type, const std::shared_ptr& tex); }; } // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CThermalColdFilter.cpp b/Runtime/Graphics/Shaders/CThermalColdFilter.cpp index 6aea09d9f..1b9cec9b6 100644 --- a/Runtime/Graphics/Shaders/CThermalColdFilter.cpp +++ b/Runtime/Graphics/Shaders/CThermalColdFilter.cpp @@ -4,43 +4,47 @@ #include "Runtime/Graphics/CBooRenderer.hpp" #include "Runtime/Graphics/CGraphics.hpp" -#include +//#include #include namespace metaforce { -static boo::ObjToken s_Pipeline; +//static boo::ObjToken s_Pipeline; -void CThermalColdFilter::Initialize() { s_Pipeline = hecl::conv->convert(Shader_CThermalColdFilter{}); } +void CThermalColdFilter::Initialize() { +// s_Pipeline = hecl::conv->convert(Shader_CThermalColdFilter{}); +} -void CThermalColdFilter::Shutdown() { s_Pipeline.reset(); } +void CThermalColdFilter::Shutdown() { +// s_Pipeline.reset(); +} CThermalColdFilter::CThermalColdFilter() { - CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) { - struct Vert { - zeus::CVector2f m_pos; - zeus::CVector2f m_uv; - zeus::CVector2f m_uvNoise; - }; - const std::array verts{{ - {{-1.f, -1.f}, {0.f, 0.f}, {0.f, 0.f}}, - {{-1.f, 1.f}, {0.f, 1.f}, {0.f, 448.f}}, - {{1.f, -1.f}, {1.f, 0.f}, {640.f, 0.f}}, - {{1.f, 1.f}, {1.f, 1.f}, {640.f, 448.f}}, - }}; - m_vbo = ctx.newStaticBuffer(boo::BufferUse::Vertex, verts.data(), 48, verts.size()); - m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(Uniform), 1); - - const std::array, 1> bufs{m_uniBuf.get()}; - constexpr std::array stages{boo::PipelineStage::Vertex}; - const std::array, 2> texs{ - CGraphics::g_SpareTexture.get(), - g_Renderer->GetRandomStaticEntropyTex(), - }; - m_dataBind = ctx.newShaderDataBinding(s_Pipeline, m_vbo.get(), nullptr, nullptr, bufs.size(), bufs.data(), - stages.data(), nullptr, nullptr, texs.size(), texs.data(), nullptr, nullptr); - return true; - } BooTrace); +// CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) { +// struct Vert { +// zeus::CVector2f m_pos; +// zeus::CVector2f m_uv; +// zeus::CVector2f m_uvNoise; +// }; +// const std::array verts{{ +// {{-1.f, -1.f}, {0.f, 0.f}, {0.f, 0.f}}, +// {{-1.f, 1.f}, {0.f, 1.f}, {0.f, 448.f}}, +// {{1.f, -1.f}, {1.f, 0.f}, {640.f, 0.f}}, +// {{1.f, 1.f}, {1.f, 1.f}, {640.f, 448.f}}, +// }}; +// m_vbo = ctx.newStaticBuffer(boo::BufferUse::Vertex, verts.data(), 48, verts.size()); +// m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(Uniform), 1); +// +// const std::array, 1> bufs{m_uniBuf.get()}; +// constexpr std::array stages{boo::PipelineStage::Vertex}; +// const std::array, 2> texs{ +// CGraphics::g_SpareTexture.get(), +// g_Renderer->GetRandomStaticEntropyTex(), +// }; +// m_dataBind = ctx.newShaderDataBinding(s_Pipeline, m_vbo.get(), nullptr, nullptr, bufs.size(), bufs.data(), +// stages.data(), nullptr, nullptr, texs.size(), texs.data(), nullptr, nullptr); +// return true; +// } BooTrace); setNoiseOffset(0); setScale(0.f); @@ -50,9 +54,9 @@ void CThermalColdFilter::draw() { SCOPED_GRAPHICS_DEBUG_GROUP("CThermalColdFilter::draw", zeus::skMagenta); CGraphics::ResolveSpareTexture(CGraphics::g_CroppedViewport); - m_uniBuf->load(&m_uniform, sizeof(m_uniform)); - CGraphics::SetShaderDataBinding(m_dataBind); - CGraphics::DrawArray(0, 4); +// m_uniBuf->load(&m_uniform, sizeof(m_uniform)); +// CGraphics::SetShaderDataBinding(m_dataBind); +// CGraphics::DrawArray(0, 4); } } // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CThermalColdFilter.hpp b/Runtime/Graphics/Shaders/CThermalColdFilter.hpp index 122f60bc7..19c53dfaf 100644 --- a/Runtime/Graphics/Shaders/CThermalColdFilter.hpp +++ b/Runtime/Graphics/Shaders/CThermalColdFilter.hpp @@ -2,7 +2,7 @@ #include -#include +//#include #include #include @@ -15,9 +15,9 @@ class CThermalColdFilter { std::array m_colorRegs; float m_randOff = 0.f; }; - boo::ObjToken m_vbo; - boo::ObjToken m_uniBuf; - boo::ObjToken m_dataBind; +// boo::ObjToken m_vbo; +// boo::ObjToken m_uniBuf; +// boo::ObjToken m_dataBind; Uniform m_uniform; public: diff --git a/Runtime/Graphics/Shaders/CThermalHotFilter.cpp b/Runtime/Graphics/Shaders/CThermalHotFilter.cpp index 02022b9cc..8cc116f7e 100644 --- a/Runtime/Graphics/Shaders/CThermalHotFilter.cpp +++ b/Runtime/Graphics/Shaders/CThermalHotFilter.cpp @@ -4,42 +4,46 @@ #include "Runtime/Graphics/CBooRenderer.hpp" #include "Runtime/Graphics/CGraphics.hpp" -#include +//#include #include namespace metaforce { -static boo::ObjToken s_Pipeline; +//static boo::ObjToken s_Pipeline; -void CThermalHotFilter::Initialize() { s_Pipeline = hecl::conv->convert(Shader_CThermalHotFilter{}); } +void CThermalHotFilter::Initialize() { +// s_Pipeline = hecl::conv->convert(Shader_CThermalHotFilter{}); +} -void CThermalHotFilter::Shutdown() { s_Pipeline.reset(); } +void CThermalHotFilter::Shutdown() { +// s_Pipeline.reset(); +} CThermalHotFilter::CThermalHotFilter() { - CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) { - struct Vert { - zeus::CVector2f m_pos; - zeus::CVector2f m_uv; - }; - const std::array verts{{ - {{-1.0, -1.0}, {0.0, 0.0}}, - {{-1.0, 1.0}, {0.0, 1.0}}, - {{1.0, -1.0}, {1.0, 0.0}}, - {{1.0, 1.0}, {1.0, 1.0}}, - }}; - m_vbo = ctx.newStaticBuffer(boo::BufferUse::Vertex, verts.data(), 32, verts.size()); - m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(Uniform), 1); - - const std::array, 1> bufs{m_uniBuf.get()}; - constexpr std::array stages{boo::PipelineStage::Vertex}; - const std::array, 2> texs{ - CGraphics::g_SpareTexture.get(), - g_Renderer->GetThermoPalette(), - }; - m_dataBind = ctx.newShaderDataBinding(s_Pipeline, m_vbo.get(), nullptr, nullptr, bufs.size(), bufs.data(), - stages.data(), nullptr, nullptr, texs.size(), texs.data(), nullptr, nullptr); - return true; - } BooTrace); +// CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) { +// struct Vert { +// zeus::CVector2f m_pos; +// zeus::CVector2f m_uv; +// }; +// const std::array verts{{ +// {{-1.0, -1.0}, {0.0, 0.0}}, +// {{-1.0, 1.0}, {0.0, 1.0}}, +// {{1.0, -1.0}, {1.0, 0.0}}, +// {{1.0, 1.0}, {1.0, 1.0}}, +// }}; +// m_vbo = ctx.newStaticBuffer(boo::BufferUse::Vertex, verts.data(), 32, verts.size()); +// m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(Uniform), 1); +// +// const std::array, 1> bufs{m_uniBuf.get()}; +// constexpr std::array stages{boo::PipelineStage::Vertex}; +// const std::array, 2> texs{ +// CGraphics::g_SpareTexture.get(), +// g_Renderer->GetThermoPalette(), +// }; +// m_dataBind = ctx.newShaderDataBinding(s_Pipeline, m_vbo.get(), nullptr, nullptr, bufs.size(), bufs.data(), +// stages.data(), nullptr, nullptr, texs.size(), texs.data(), nullptr, nullptr); +// return true; +// } BooTrace); } void CThermalHotFilter::draw() { @@ -49,8 +53,8 @@ void CThermalHotFilter::draw() { // m_uniBuf->load(&m_uniform, sizeof(m_uniform)); - CGraphics::SetShaderDataBinding(m_dataBind); - CGraphics::DrawArray(0, 4); +// CGraphics::SetShaderDataBinding(m_dataBind); +// CGraphics::DrawArray(0, 4); } } // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CThermalHotFilter.hpp b/Runtime/Graphics/Shaders/CThermalHotFilter.hpp index 2eb0d735b..74ba9416e 100644 --- a/Runtime/Graphics/Shaders/CThermalHotFilter.hpp +++ b/Runtime/Graphics/Shaders/CThermalHotFilter.hpp @@ -2,7 +2,7 @@ #include -#include +//#include #include @@ -12,9 +12,9 @@ class CThermalHotFilter { struct Uniform { std::array m_colorRegs; }; - boo::ObjToken m_vbo; - boo::ObjToken m_uniBuf; - boo::ObjToken m_dataBind; +// boo::ObjToken m_vbo; +// boo::ObjToken m_uniBuf; +// boo::ObjToken m_dataBind; Uniform m_uniform; public: diff --git a/Runtime/Graphics/Shaders/CWorldShadowShader.cpp b/Runtime/Graphics/Shaders/CWorldShadowShader.cpp index 2004896ef..83e5f5814 100644 --- a/Runtime/Graphics/Shaders/CWorldShadowShader.cpp +++ b/Runtime/Graphics/Shaders/CWorldShadowShader.cpp @@ -5,42 +5,44 @@ #include "Runtime/Camera/CCameraFilter.hpp" #include "Runtime/Graphics/CGraphics.hpp" -#include +//#include #include namespace metaforce { -static boo::ObjToken s_Pipeline; -static boo::ObjToken s_ZPipeline; +//static boo::ObjToken s_Pipeline; +//static boo::ObjToken s_ZPipeline; void CWorldShadowShader::Initialize() { - s_Pipeline = hecl::conv->convert(Shader_CWorldShadowShader{}); - s_ZPipeline = hecl::conv->convert(Shader_CWorldShadowShaderZ{}); +// s_Pipeline = hecl::conv->convert(Shader_CWorldShadowShader{}); +// s_ZPipeline = hecl::conv->convert(Shader_CWorldShadowShaderZ{}); } void CWorldShadowShader::Shutdown() { - s_Pipeline.reset(); - s_ZPipeline.reset(); +// s_Pipeline.reset(); +// s_ZPipeline.reset(); } CWorldShadowShader::CWorldShadowShader(u32 w, u32 h) : m_w(w), m_h(h) { - CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) { - m_vbo = ctx.newDynamicBuffer(boo::BufferUse::Vertex, 16, 4); - m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(Uniform), 1); - - const std::array, 1> bufs{m_uniBuf.get()}; - constexpr std::array stages{boo::PipelineStage::Vertex}; - m_dataBind = ctx.newShaderDataBinding(s_Pipeline, m_vbo.get(), nullptr, nullptr, bufs.size(), bufs.data(), - stages.data(), nullptr, nullptr, 0, nullptr, nullptr, nullptr); - m_zDataBind = ctx.newShaderDataBinding(s_ZPipeline, m_vbo.get(), nullptr, nullptr, bufs.size(), bufs.data(), - stages.data(), nullptr, nullptr, 0, nullptr, nullptr, nullptr); - - m_tex = ctx.newRenderTexture(m_w, m_h, boo::TextureClampMode::ClampToWhite, 1, 0); - return true; - } BooTrace); +// CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) { +// m_vbo = ctx.newDynamicBuffer(boo::BufferUse::Vertex, 16, 4); +// m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(Uniform), 1); +// +// const std::array, 1> bufs{m_uniBuf.get()}; +// constexpr std::array stages{boo::PipelineStage::Vertex}; +// m_dataBind = ctx.newShaderDataBinding(s_Pipeline, m_vbo.get(), nullptr, nullptr, bufs.size(), bufs.data(), +// stages.data(), nullptr, nullptr, 0, nullptr, nullptr, nullptr); +// m_zDataBind = ctx.newShaderDataBinding(s_ZPipeline, m_vbo.get(), nullptr, nullptr, bufs.size(), bufs.data(), +// stages.data(), nullptr, nullptr, 0, nullptr, nullptr, nullptr); +// +// m_tex = ctx.newRenderTexture(m_w, m_h, boo::TextureClampMode::ClampToWhite, 1, 0); +// return true; +// } BooTrace); } -void CWorldShadowShader::bindRenderTarget() { CGraphics::g_BooMainCommandQueue->setRenderTarget(m_tex); } +void CWorldShadowShader::bindRenderTarget() { +// CGraphics::g_BooMainCommandQueue->setRenderTarget(m_tex); +} void CWorldShadowShader::drawBase(float extent) { SCOPED_GRAPHICS_DEBUG_GROUP("CWorldShadowShader::drawBase", zeus::skMagenta); @@ -51,38 +53,38 @@ void CWorldShadowShader::drawBase(float extent) { {-extent, 0.f, -extent}, {extent, 0.f, -extent}, }}; - m_vbo->load(verts.data(), sizeof(verts)); +// m_vbo->load(verts.data(), sizeof(verts)); m_uniform.m_matrix = CGraphics::GetPerspectiveProjectionMatrix(true) * CGraphics::g_GXModelView.toMatrix4f(); m_uniform.m_color = zeus::skWhite; - m_uniBuf->load(&m_uniform, sizeof(m_uniform)); - - CGraphics::SetShaderDataBinding(m_zDataBind); - CGraphics::DrawArray(0, 4); +// m_uniBuf->load(&m_uniform, sizeof(m_uniform)); +// +// CGraphics::SetShaderDataBinding(m_zDataBind); +// CGraphics::DrawArray(0, 4); } void CWorldShadowShader::lightenShadow() { SCOPED_GRAPHICS_DEBUG_GROUP("CWorldShadowShader::lightenShadow", zeus::skMagenta); m_uniform.m_color = zeus::CColor(1.f, 0.25f); - m_uniBuf->load(&m_uniform, sizeof(m_uniform)); - - CGraphics::SetShaderDataBinding(m_dataBind); - CGraphics::DrawArray(0, 4); +// m_uniBuf->load(&m_uniform, sizeof(m_uniform)); +// +// CGraphics::SetShaderDataBinding(m_dataBind); +// CGraphics::DrawArray(0, 4); } void CWorldShadowShader::blendPreviousShadow() { SCOPED_GRAPHICS_DEBUG_GROUP("CWorldShadowShader::blendPreviousShadow", zeus::skMagenta); if (!m_prevQuad) - m_prevQuad.emplace(EFilterType::Blend, m_tex.get()); + m_prevQuad.emplace(EFilterType::Blend, m_tex); zeus::CRectangle rect(0.f, 1.f, 1.f, -1.f); m_prevQuad->draw({1.f, 0.85f}, 1.f, rect); } void CWorldShadowShader::resolveTexture() { - boo::SWindowRect rect = {0, 0, int(m_w), int(m_h)}; - CGraphics::g_BooMainCommandQueue->resolveBindTexture(m_tex, rect, false, 0, true, false, true); +// boo::SWindowRect rect = {0, 0, int(m_w), int(m_h)}; +// CGraphics::g_BooMainCommandQueue->resolveBindTexture(m_tex, rect, false, 0, true, false, true); } } // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CWorldShadowShader.hpp b/Runtime/Graphics/Shaders/CWorldShadowShader.hpp index 98af3477c..ef3473516 100644 --- a/Runtime/Graphics/Shaders/CWorldShadowShader.hpp +++ b/Runtime/Graphics/Shaders/CWorldShadowShader.hpp @@ -5,7 +5,7 @@ #include "Runtime/GCNTypes.hpp" #include "Runtime/Graphics/Shaders/CTexturedQuadFilter.hpp" -#include +//#include #include #include @@ -13,7 +13,7 @@ namespace metaforce { class CWorldShadowShader { - boo::ObjToken m_tex; + std::shared_ptr m_tex; std::optional m_prevQuad; u32 m_w, m_h; @@ -21,10 +21,10 @@ class CWorldShadowShader { zeus::CMatrix4f m_matrix; zeus::CColor m_color; }; - boo::ObjToken m_vbo; - boo::ObjToken m_uniBuf; - boo::ObjToken m_dataBind; - boo::ObjToken m_zDataBind; +// boo::ObjToken m_vbo; +// boo::ObjToken m_uniBuf; +// boo::ObjToken m_dataBind; +// boo::ObjToken m_zDataBind; Uniform m_uniform; public: @@ -40,7 +40,7 @@ public: u32 GetWidth() const { return m_w; } u32 GetHeight() const { return m_h; } - const boo::ObjToken& GetTexture() const { return m_tex; } + const std::shared_ptr& GetTexture() const { return m_tex; } }; } // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CXRayBlurFilter.cpp b/Runtime/Graphics/Shaders/CXRayBlurFilter.cpp index bf39e9160..614bd2d76 100644 --- a/Runtime/Graphics/Shaders/CXRayBlurFilter.cpp +++ b/Runtime/Graphics/Shaders/CXRayBlurFilter.cpp @@ -4,42 +4,46 @@ #include "Runtime/Graphics/CGraphics.hpp" #include "Runtime/Graphics/CTexture.hpp" -#include +//#include #include namespace metaforce { -static boo::ObjToken s_Pipeline; +//static boo::ObjToken s_Pipeline; -void CXRayBlurFilter::Initialize() { s_Pipeline = hecl::conv->convert(Shader_CXRayBlurFilter{}); } +void CXRayBlurFilter::Initialize() { +// s_Pipeline = hecl::conv->convert(Shader_CXRayBlurFilter{}); +} -void CXRayBlurFilter::Shutdown() { s_Pipeline.reset(); } +void CXRayBlurFilter::Shutdown() { +// s_Pipeline.reset(); +} CXRayBlurFilter::CXRayBlurFilter(TLockedToken& tex) : m_paletteTex(tex), m_booTex(tex->GetPaletteTexture()) { - CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) { - struct Vert { - zeus::CVector2f m_pos; - zeus::CVector2f m_uv; - }; - const std::array verts{{ - {{-1.f, -1.f}, {0.f, 0.f}}, - {{-1.f, 1.f}, {0.f, 1.f}}, - {{1.f, -1.f}, {1.f, 0.f}}, - {{1.f, 1.f}, {1.f, 1.f}}, - }}; - m_vbo = ctx.newStaticBuffer(boo::BufferUse::Vertex, verts.data(), 32, verts.size()); - m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(Uniform), 1); - - const std::array, 1> bufs{m_uniBuf.get()}; - constexpr std::array stages{boo::PipelineStage::Vertex}; - const std::array, 2> texs{ - CGraphics::g_SpareTexture.get(), - m_booTex, - }; - m_dataBind = ctx.newShaderDataBinding(s_Pipeline, m_vbo.get(), nullptr, nullptr, bufs.size(), bufs.data(), - stages.data(), nullptr, nullptr, texs.size(), texs.data(), nullptr, nullptr); - return true; - } BooTrace); +// CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) { +// struct Vert { +// zeus::CVector2f m_pos; +// zeus::CVector2f m_uv; +// }; +// const std::array verts{{ +// {{-1.f, -1.f}, {0.f, 0.f}}, +// {{-1.f, 1.f}, {0.f, 1.f}}, +// {{1.f, -1.f}, {1.f, 0.f}}, +// {{1.f, 1.f}, {1.f, 1.f}}, +// }}; +// m_vbo = ctx.newStaticBuffer(boo::BufferUse::Vertex, verts.data(), 32, verts.size()); +// m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(Uniform), 1); +// +// const std::array, 1> bufs{m_uniBuf.get()}; +// constexpr std::array stages{boo::PipelineStage::Vertex}; +// const std::array, 2> texs{ +// CGraphics::g_SpareTexture.get(), +// m_booTex, +// }; +// m_dataBind = ctx.newShaderDataBinding(s_Pipeline, m_vbo.get(), nullptr, nullptr, bufs.size(), bufs.data(), +// stages.data(), nullptr, nullptr, texs.size(), texs.data(), nullptr, nullptr); +// return true; +// } BooTrace); } void CXRayBlurFilter::draw(float amount) { @@ -59,10 +63,10 @@ void CXRayBlurFilter::draw(float amount) { m_uniform.m_uv[i][3][0] = uvOffset; m_uniform.m_uv[i][3][1] = uvOffset; } - m_uniBuf->load(&m_uniform, sizeof(m_uniform)); - - CGraphics::SetShaderDataBinding(m_dataBind); - CGraphics::DrawArray(0, 4); +// m_uniBuf->load(&m_uniform, sizeof(m_uniform)); +// +// CGraphics::SetShaderDataBinding(m_dataBind); +// CGraphics::DrawArray(0, 4); } } // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CXRayBlurFilter.hpp b/Runtime/Graphics/Shaders/CXRayBlurFilter.hpp index 35104fa7b..2d82a353c 100644 --- a/Runtime/Graphics/Shaders/CXRayBlurFilter.hpp +++ b/Runtime/Graphics/Shaders/CXRayBlurFilter.hpp @@ -3,8 +3,8 @@ #include #include "Runtime/CToken.hpp" +#include "Runtime/Graphics/CGraphics.hpp" -#include #include namespace metaforce { @@ -15,10 +15,10 @@ class CXRayBlurFilter { std::array m_uv; }; TLockedToken m_paletteTex; - boo::ObjToken m_booTex; - boo::ObjToken m_vbo; - boo::ObjToken m_uniBuf; - boo::ObjToken m_dataBind; + std::shared_ptr m_booTex; +// boo::ObjToken m_vbo; +// boo::ObjToken m_uniBuf; +// boo::ObjToken m_dataBind; Uniform m_uniform; public: diff --git a/Runtime/GuiSys/CCompoundTargetReticle.cpp b/Runtime/GuiSys/CCompoundTargetReticle.cpp index fb3c972f7..02fcd3749 100644 --- a/Runtime/GuiSys/CCompoundTargetReticle.cpp +++ b/Runtime/GuiSys/CCompoundTargetReticle.cpp @@ -70,15 +70,15 @@ CCompoundTargetReticle::CCompoundTargetReticle(const CStateManager& mgr) } CCompoundTargetReticle::SScanReticuleRenderer::SScanReticuleRenderer() { - CGraphics::CommitResources([this](boo::IGraphicsDataFactory::Context& ctx) { +// CGraphics::CommitResources([this](boo::IGraphicsDataFactory::Context& ctx) { for (size_t i = 0; i < m_lineRenderers.size(); ++i) { - m_lineRenderers[i].emplace(ctx, CLineRenderer::EPrimitiveMode::Lines, 8, nullptr, true, true); + m_lineRenderers[i].emplace(CLineRenderer::EPrimitiveMode::Lines, 8, nullptr, true, true); for (auto& stripRenderer : m_stripRenderers[i]) { - stripRenderer.emplace(ctx, CLineRenderer::EPrimitiveMode::LineStrip, 4, nullptr, true, true); + stripRenderer.emplace(CLineRenderer::EPrimitiveMode::LineStrip, 4, nullptr, true, true); } } - return true; - } BooTrace); +// return true; +// } BooTrace); } CCompoundTargetReticle::EReticleState CCompoundTargetReticle::GetDesiredReticleState(const CStateManager& mgr) const { diff --git a/Runtime/GuiSys/CRasterFont.hpp b/Runtime/GuiSys/CRasterFont.hpp index 45b0dcf04..5b0b68945 100644 --- a/Runtime/GuiSys/CRasterFont.hpp +++ b/Runtime/GuiSys/CRasterFont.hpp @@ -148,7 +148,7 @@ public: const char16_t* str, int len) const; const CGlyph* GetGlyph(char16_t chr) const { return InternalGetGlyph(chr); } void GetSize(const CDrawStringOptions& opts, int& width, int& height, const char16_t* str, int len) const; - const boo::ObjToken& GetTexture() { return x80_texture->GetFontTexture(x2c_mode); } + const std::shared_ptr& GetTexture() { return x80_texture->GetFontTexture(x2c_mode); } bool IsFinishedLoading() const; }; diff --git a/Runtime/GuiSys/CTextRenderBuffer.cpp b/Runtime/GuiSys/CTextRenderBuffer.cpp index 385cf38d5..3afe4bc24 100644 --- a/Runtime/GuiSys/CTextRenderBuffer.cpp +++ b/Runtime/GuiSys/CTextRenderBuffer.cpp @@ -14,9 +14,9 @@ namespace metaforce { struct CTextRenderBuffer::BooFontCharacters { TLockedToken m_font; - hecl::VertexBufferPool::Token m_instBuf; - boo::ObjToken m_dataBinding; - boo::ObjToken m_dataBinding2; +// hecl::VertexBufferPool::Token m_instBuf; +// boo::ObjToken m_dataBinding; +// boo::ObjToken m_dataBinding2; std::vector m_charData; u32 m_charCount = 0; bool m_dirty = true; @@ -26,9 +26,9 @@ struct CTextRenderBuffer::BooFontCharacters { struct CTextRenderBuffer::BooImage { CFontImageDef m_imageDef; - hecl::VertexBufferPool::Token m_instBuf; - std::vector> m_dataBinding; - std::vector> m_dataBinding2; +// hecl::VertexBufferPool::Token m_instBuf; +// std::vector> m_dataBinding; +// std::vector> m_dataBinding2; CTextSupportShader::ImageInstance m_imageData; bool m_dirty = true; @@ -80,68 +80,68 @@ void CTextRenderBuffer::CommitResources() { for (BooFontCharacters& chs : m_fontCharacters) chs.m_font->GetTexture(); - CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) { - m_uniBuf = CTextSupportShader::s_Uniforms.allocateBlock(CGraphics::g_BooFactory); - auto uBufInfo = m_uniBuf.getBufferInfo(); - decltype(uBufInfo) uBufInfo2; - if (m_drawFlags == CGuiWidget::EGuiModelDrawFlags::AlphaAdditiveOverdraw) { - m_uniBuf2 = CTextSupportShader::s_Uniforms.allocateBlock(CGraphics::g_BooFactory); - uBufInfo2 = m_uniBuf2.getBufferInfo(); - } - - for (BooFontCharacters& chs : m_fontCharacters) { - chs.m_instBuf = CTextSupportShader::s_CharInsts.allocateBlock(CGraphics::g_BooFactory, chs.m_charCount); - auto iBufInfo = chs.m_instBuf.getBufferInfo(); - - boo::ObjToken uniforms[] = {uBufInfo.first.get()}; - boo::PipelineStage unistages[] = {boo::PipelineStage::Vertex}; - size_t unioffs[] = {size_t(uBufInfo.second)}; - size_t unisizes[] = {sizeof(CTextSupportShader::Uniform)}; - boo::ObjToken texs[] = {chs.m_font->GetTexture()}; - chs.m_dataBinding = ctx.newShaderDataBinding(CTextSupportShader::SelectTextPipeline(m_drawFlags), nullptr, - iBufInfo.first.get(), nullptr, 1, uniforms, unistages, unioffs, - unisizes, 1, texs, nullptr, nullptr, 0, iBufInfo.second); - - if (m_drawFlags == CGuiWidget::EGuiModelDrawFlags::AlphaAdditiveOverdraw) { - uniforms[0] = uBufInfo2.first.get(); - unioffs[0] = size_t(uBufInfo2.second); - chs.m_dataBinding2 = ctx.newShaderDataBinding(CTextSupportShader::GetTextAdditiveOverdrawPipeline(), nullptr, - iBufInfo.first.get(), nullptr, 1, uniforms, unistages, unioffs, - unisizes, 1, texs, nullptr, nullptr, 0, iBufInfo.second); - } - } - - for (BooImage& img : m_images) { - img.m_instBuf = CTextSupportShader::s_ImgInsts.allocateBlock(CGraphics::g_BooFactory, 1); - auto iBufInfo = img.m_instBuf.getBufferInfo(); - - boo::ObjToken uniforms[] = {uBufInfo.first.get()}; - boo::PipelineStage unistages[] = {boo::PipelineStage::Vertex}; - size_t unioffs[] = {size_t(uBufInfo.second)}; - size_t unisizes[] = {sizeof(CTextSupportShader::Uniform)}; - img.m_dataBinding.reserve(img.m_imageDef.x4_texs.size()); - for (TToken& tex : img.m_imageDef.x4_texs) { - boo::ObjToken texs[] = {tex->GetBooTexture()}; - texs[0]->setClampMode(boo::TextureClampMode::ClampToEdge); - img.m_dataBinding.push_back(ctx.newShaderDataBinding( - CTextSupportShader::SelectImagePipeline(m_drawFlags), nullptr, iBufInfo.first.get(), nullptr, 1, uniforms, - unistages, unioffs, unisizes, 1, texs, nullptr, nullptr, 0, iBufInfo.second)); - } - - if (m_drawFlags == CGuiWidget::EGuiModelDrawFlags::AlphaAdditiveOverdraw) { - uniforms[0] = uBufInfo2.first.get(); - unioffs[0] = size_t(uBufInfo2.second); - img.m_dataBinding2.reserve(img.m_imageDef.x4_texs.size()); - for (TToken& tex : img.m_imageDef.x4_texs) { - boo::ObjToken texs[] = {tex->GetBooTexture()}; - img.m_dataBinding2.push_back(ctx.newShaderDataBinding( - CTextSupportShader::GetImageAdditiveOverdrawPipeline(), nullptr, iBufInfo.first.get(), nullptr, 1, - uniforms, unistages, unioffs, unisizes, 1, texs, nullptr, nullptr, 0, iBufInfo.second)); - } - } - } - return true; - } BooTrace); +// CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) { +// m_uniBuf = CTextSupportShader::s_Uniforms.allocateBlock(CGraphics::g_BooFactory); +// auto uBufInfo = m_uniBuf.getBufferInfo(); +// decltype(uBufInfo) uBufInfo2; +// if (m_drawFlags == CGuiWidget::EGuiModelDrawFlags::AlphaAdditiveOverdraw) { +// m_uniBuf2 = CTextSupportShader::s_Uniforms.allocateBlock(CGraphics::g_BooFactory); +// uBufInfo2 = m_uniBuf2.getBufferInfo(); +// } +// +// for (BooFontCharacters& chs : m_fontCharacters) { +// chs.m_instBuf = CTextSupportShader::s_CharInsts.allocateBlock(CGraphics::g_BooFactory, chs.m_charCount); +// auto iBufInfo = chs.m_instBuf.getBufferInfo(); +// +// boo::ObjToken uniforms[] = {uBufInfo.first.get()}; +// boo::PipelineStage unistages[] = {boo::PipelineStage::Vertex}; +// size_t unioffs[] = {size_t(uBufInfo.second)}; +// size_t unisizes[] = {sizeof(CTextSupportShader::Uniform)}; +// boo::ObjToken texs[] = {chs.m_font->GetTexture()}; +// chs.m_dataBinding = ctx.newShaderDataBinding(CTextSupportShader::SelectTextPipeline(m_drawFlags), nullptr, +// iBufInfo.first.get(), nullptr, 1, uniforms, unistages, unioffs, +// unisizes, 1, texs, nullptr, nullptr, 0, iBufInfo.second); +// +// if (m_drawFlags == CGuiWidget::EGuiModelDrawFlags::AlphaAdditiveOverdraw) { +// uniforms[0] = uBufInfo2.first.get(); +// unioffs[0] = size_t(uBufInfo2.second); +// chs.m_dataBinding2 = ctx.newShaderDataBinding(CTextSupportShader::GetTextAdditiveOverdrawPipeline(), nullptr, +// iBufInfo.first.get(), nullptr, 1, uniforms, unistages, unioffs, +// unisizes, 1, texs, nullptr, nullptr, 0, iBufInfo.second); +// } +// } +// +// for (BooImage& img : m_images) { +// img.m_instBuf = CTextSupportShader::s_ImgInsts.allocateBlock(CGraphics::g_BooFactory, 1); +// auto iBufInfo = img.m_instBuf.getBufferInfo(); +// +// boo::ObjToken uniforms[] = {uBufInfo.first.get()}; +// boo::PipelineStage unistages[] = {boo::PipelineStage::Vertex}; +// size_t unioffs[] = {size_t(uBufInfo.second)}; +// size_t unisizes[] = {sizeof(CTextSupportShader::Uniform)}; +// img.m_dataBinding.reserve(img.m_imageDef.x4_texs.size()); +// for (TToken& tex : img.m_imageDef.x4_texs) { +// boo::ObjToken texs[] = {tex->GetBooTexture()}; +// texs[0]->setClampMode(boo::TextureClampMode::ClampToEdge); +// img.m_dataBinding.push_back(ctx.newShaderDataBinding( +// CTextSupportShader::SelectImagePipeline(m_drawFlags), nullptr, iBufInfo.first.get(), nullptr, 1, uniforms, +// unistages, unioffs, unisizes, 1, texs, nullptr, nullptr, 0, iBufInfo.second)); +// } +// +// if (m_drawFlags == CGuiWidget::EGuiModelDrawFlags::AlphaAdditiveOverdraw) { +// uniforms[0] = uBufInfo2.first.get(); +// unioffs[0] = size_t(uBufInfo2.second); +// img.m_dataBinding2.reserve(img.m_imageDef.x4_texs.size()); +// for (TToken& tex : img.m_imageDef.x4_texs) { +// boo::ObjToken texs[] = {tex->GetBooTexture()}; +// img.m_dataBinding2.push_back(ctx.newShaderDataBinding( +// CTextSupportShader::GetImageAdditiveOverdrawPipeline(), nullptr, iBufInfo.first.get(), nullptr, 1, +// uniforms, unistages, unioffs, unisizes, 1, texs, nullptr, nullptr, 0, iBufInfo.second)); +// } +// } +// } +// return true; +// } BooTrace); } void CTextRenderBuffer::SetMode(EMode mode) { @@ -163,44 +163,44 @@ u32 CTextRenderBuffer::GetPrimitiveCount() const { return m_primitiveMarks.size( void CTextRenderBuffer::Render(const zeus::CColor& col, float time) { CommitResources(); - const zeus::CMatrix4f mv = CGraphics::g_GXModelView.toMatrix4f(); - const zeus::CMatrix4f proj = CGraphics::GetPerspectiveProjectionMatrix(true); - const zeus::CMatrix4f mat = proj * mv; +// const zeus::CMatrix4f mv = CGraphics::g_GXModelView.toMatrix4f(); +// const zeus::CMatrix4f proj = CGraphics::GetPerspectiveProjectionMatrix(true); +// const zeus::CMatrix4f mat = proj * mv; - m_uniBuf.access() = CTextSupportShader::Uniform{mat, col}; +// m_uniBuf.access() = CTextSupportShader::Uniform{mat, col}; if (m_drawFlags == CGuiWidget::EGuiModelDrawFlags::AlphaAdditiveOverdraw) { zeus::CColor colPremul = col * col.a(); colPremul.a() = col.a(); - m_uniBuf2.access() = CTextSupportShader::Uniform{mat, colPremul}; +// m_uniBuf2.access() = CTextSupportShader::Uniform{mat, colPremul}; } for (BooFontCharacters& chs : m_fontCharacters) { if (chs.m_charData.size()) { if (chs.m_dirty) { - std::memmove(chs.m_instBuf.access(), chs.m_charData.data(), - sizeof(CTextSupportShader::CharacterInstance) * chs.m_charData.size()); +// std::memmove(chs.m_instBuf.access(), chs.m_charData.data(), +// sizeof(CTextSupportShader::CharacterInstance) * chs.m_charData.size()); chs.m_dirty = false; } - CGraphics::SetShaderDataBinding(chs.m_dataBinding); - CGraphics::DrawInstances(0, 4, chs.m_charData.size()); +// CGraphics::SetShaderDataBinding(chs.m_dataBinding); +// CGraphics::DrawInstances(0, 4, chs.m_charData.size()); if (m_drawFlags == CGuiWidget::EGuiModelDrawFlags::AlphaAdditiveOverdraw) { - CGraphics::SetShaderDataBinding(chs.m_dataBinding2); - CGraphics::DrawInstances(0, 4, chs.m_charData.size()); +// CGraphics::SetShaderDataBinding(chs.m_dataBinding2); +// CGraphics::DrawInstances(0, 4, chs.m_charData.size()); } } } for (BooImage& img : m_images) { if (img.m_dirty) { - *img.m_instBuf.access() = img.m_imageData; +// *img.m_instBuf.access() = img.m_imageData; img.m_dirty = false; } - const int idx = int(img.m_imageDef.x0_fps * time) % img.m_dataBinding.size(); - CGraphics::SetShaderDataBinding(img.m_dataBinding[idx]); - CGraphics::DrawInstances(0, 4, 1); +// const int idx = int(img.m_imageDef.x0_fps * time) % img.m_dataBinding.size(); +// CGraphics::SetShaderDataBinding(img.m_dataBinding[idx]); +// CGraphics::DrawInstances(0, 4, 1); if (m_drawFlags == CGuiWidget::EGuiModelDrawFlags::AlphaAdditiveOverdraw) { - CGraphics::SetShaderDataBinding(img.m_dataBinding2[idx]); - CGraphics::DrawInstances(0, 4, 1); +// CGraphics::SetShaderDataBinding(img.m_dataBinding2[idx]); +// CGraphics::DrawInstances(0, 4, 1); } } } diff --git a/Runtime/GuiSys/CTextRenderBuffer.hpp b/Runtime/GuiSys/CTextRenderBuffer.hpp index c73290dab..8d24f6a3f 100644 --- a/Runtime/GuiSys/CTextRenderBuffer.hpp +++ b/Runtime/GuiSys/CTextRenderBuffer.hpp @@ -9,10 +9,10 @@ #include "Runtime/GuiSys/CFontImageDef.hpp" #include "Runtime/GuiSys/CGuiWidget.hpp" -#include - -#include -#include +//#include +// +//#include +//#include #include #include @@ -62,8 +62,8 @@ private: #else /* Boo-specific text-rendering functionality */ - hecl::UniformBufferPool::Token m_uniBuf; - hecl::UniformBufferPool::Token m_uniBuf2; +// hecl::UniformBufferPool::Token m_uniBuf; +// hecl::UniformBufferPool::Token m_uniBuf2; struct BooFontCharacters; std::vector m_fontCharacters; diff --git a/Runtime/IMain.hpp b/Runtime/IMain.hpp index a4e5a2feb..3f99762b4 100644 --- a/Runtime/IMain.hpp +++ b/Runtime/IMain.hpp @@ -2,12 +2,12 @@ #include "Runtime/RetroTypes.hpp" -#include -#include -#include -#include #include "DataSpec/DNACommon/MetaforceVersionInfo.hpp" #include "Runtime/CMainFlowBase.hpp" +#include +#include +#include +#include namespace hecl { class Console; @@ -24,17 +24,15 @@ enum class EGameplayResult { None, Win, Lose, Playing }; class IMain { public: virtual ~IMain() = default; - virtual void Init(const hecl::Runtime::FileStoreManager& storeMgr, hecl::CVarManager* cvarMgr, boo::IWindow* window, + virtual void Init(const hecl::Runtime::FileStoreManager& storeMgr, hecl::CVarManager* cvarMgr, boo::IAudioVoiceEngine* voiceEngine, amuse::IBackendVoiceAllocator& backend) = 0; virtual void Draw() = 0; virtual bool Proc(float dt) = 0; virtual void Shutdown() = 0; - virtual boo::IWindow* GetMainWindow() const = 0; virtual EClientFlowStates GetFlowState() const = 0; virtual void SetFlowState(EClientFlowStates) = 0; virtual size_t GetExpectedIdSize() const = 0; virtual void WarmupShaders() = 0; - virtual hecl::Console* Console() const = 0; virtual EGame GetGame() const = 0; virtual ERegion GetRegion() const = 0; virtual bool IsPAL() const = 0; diff --git a/Runtime/ImGuiConsole.cpp b/Runtime/ImGuiConsole.cpp index c6c660b27..9b5d21378 100644 --- a/Runtime/ImGuiConsole.cpp +++ b/Runtime/ImGuiConsole.cpp @@ -614,7 +614,7 @@ void ImGuiConsole::ShowAboutWindow(bool canClose, std::string_view errorString) if (ImGui::Begin("About", open, flags)) { float iconSize = 128.f * ImGui::GetIO().DisplayFramebufferScale.x; ImGui::SameLine(ImGui::GetWindowSize().x / 2 - iconSize + (iconSize / 2)); - ImGui::Image(ImGuiUserTextureID_MetaforceIcon, ImVec2{iconSize, iconSize}); + ImGui::Image(ImGuiEngine::metaforceIcon, ImVec2{iconSize, iconSize}); ImGui::PushFont(ImGuiEngine::fontLarge); ImGuiTextCenter("Metaforce"); ImGui::PopFont(); @@ -1122,7 +1122,6 @@ void ImGuiConsole::ShowAppMainMenuBar(bool canInspect) { } } -s32 TranslateBooSpecialKey(boo::ESpecialKey key) { return 256 + static_cast(key); } void ImGuiConsole::PreUpdate() { OPTICK_EVENT(); if (!m_isInitialized) { @@ -1148,18 +1147,18 @@ void ImGuiConsole::PreUpdate() { g_StateManager->SetActiveRandomToDefault(); } - if (ImGui::IsKeyReleased('`')) { + if (ImGui::IsKeyReleased(int(KeyCode::Grave))) { m_isVisible ^= 1; } if (m_stepFrame) { g_Main->SetPaused(true); m_stepFrame = false; } - if (m_paused && !m_stepFrame && ImGui::IsKeyPressed(TranslateBooSpecialKey(boo::ESpecialKey::F6))) { + if (m_paused && !m_stepFrame && ImGui::IsKeyPressed(int(KeyCode::F6))) { g_Main->SetPaused(false); m_stepFrame = true; } - if (ImGui::IsKeyReleased(TranslateBooSpecialKey(boo::ESpecialKey::F5))) { + if (ImGui::IsKeyReleased(int(KeyCode::F5))) { m_paused ^= 1; g_Main->SetPaused(m_paused); } diff --git a/Runtime/MP1/CInGameGuiManager.cpp b/Runtime/MP1/CInGameGuiManager.cpp index da552322c..546c1934e 100644 --- a/Runtime/MP1/CInGameGuiManager.cpp +++ b/Runtime/MP1/CInGameGuiManager.cpp @@ -607,9 +607,9 @@ void CInGameGuiManager::Draw(CStateManager& stateMgr) { {{x, 0.f, -z}, {1.f, 1.f}}, }}; - if (!m_deathRenderTexQuad) - m_deathRenderTexQuad.emplace(EFilterType::Blend, CGraphics::g_SpareTexture.get()); - m_deathRenderTexQuad->drawVerts(zeus::CColor(1.f, colT), verts); +// if (!m_deathRenderTexQuad) +// m_deathRenderTexQuad.emplace(EFilterType::Blend, CGraphics::g_SpareTexture.get()); +// m_deathRenderTexQuad->drawVerts(zeus::CColor(1.f, colT), verts); if (!m_deathDotQuad) m_deathDotQuad.emplace(EFilterType::Multiply, x50_deathDot); diff --git a/Runtime/MP1/CMFGame.cpp b/Runtime/MP1/CMFGame.cpp index 2d73d2ada..7fe8de7b0 100644 --- a/Runtime/MP1/CMFGame.cpp +++ b/Runtime/MP1/CMFGame.cpp @@ -346,8 +346,8 @@ CIOWin::EMessageReturn CMFGameLoader::OnMessage(const CArchitectureMessage& msg, x1c_loadList.clear(); - if (!CGraphics::g_BooFactory->areShadersReady()) - return EMessageReturn::Exit; +// if (!CGraphics::g_BooFactory->areShadersReady()) +// return EMessageReturn::Exit; wtMgr->StartTextFadeOut(); x2c_25_transitionFinished = wtMgr->IsTransitionFinished(); diff --git a/Runtime/MP1/CPlayerVisor.cpp b/Runtime/MP1/CPlayerVisor.cpp index 8e6a4f501..97d43b57f 100644 --- a/Runtime/MP1/CPlayerVisor.cpp +++ b/Runtime/MP1/CPlayerVisor.cpp @@ -14,13 +14,15 @@ namespace metaforce::MP1 { -CPlayerVisor::CPlayerVisor(CStateManager&) : x108_newScanPane(EFilterType::Blend, CGraphics::g_SpareTexture.get()) { +CPlayerVisor::CPlayerVisor(CStateManager&) { + // TODO + // : x108_newScanPane(EFilterType::Blend, CGraphics::g_SpareTexture.get()) xcc_scanFrameCorner = g_SimplePool->GetObj("CMDL_ScanFrameCorner"); xd8_scanFrameCenterSide = g_SimplePool->GetObj("CMDL_ScanFrameCenterSide"); xe4_scanFrameCenterTop = g_SimplePool->GetObj("CMDL_ScanFrameCenterTop"); xf0_scanFrameStretchSide = g_SimplePool->GetObj("CMDL_ScanFrameStretchSide"); xfc_scanFrameStretchTop = g_SimplePool->GetObj("CMDL_ScanFrameStretchTop"); - // x108_newScanPane = g_SimplePool->GetObj("CMDL_NewScanPane"); + x108_newScanPane = g_SimplePool->GetObj("CMDL_NewScanPane"); x114_scanShield = g_SimplePool->GetObj("CMDL_ScanShield"); x124_scanIconNoncritical = g_SimplePool->GetObj("CMDL_ScanIconNoncritical"); x130_scanIconCritical = g_SimplePool->GetObj("CMDL_ScanIconCritical"); @@ -376,13 +378,13 @@ void CPlayerVisor::DrawScanEffect(const CStateManager& mgr, CTargetingManager* t {{-5.f, 0.f, -4.45f}, {uvX0, uvY1}}, {{5.f, 0.f, -4.45f}, {uvX1, uvY1}}, }}; - if (CGraphics::g_BooPlatform == boo::IGraphicsDataFactory::Platform::OpenGL) { - rttVerts[0].m_uv.y() = uvY1; - rttVerts[1].m_uv.y() = uvY1; - rttVerts[2].m_uv.y() = uvY0; - rttVerts[3].m_uv.y() = uvY0; - } - x108_newScanPane.drawVerts(zeus::CColor(1.f, transFactor), rttVerts); +// if (CGraphics::g_BooPlatform == boo::IGraphicsDataFactory::Platform::OpenGL) { +// rttVerts[0].m_uv.y() = uvY1; +// rttVerts[1].m_uv.y() = uvY1; +// rttVerts[2].m_uv.y() = uvY0; +// rttVerts[3].m_uv.y() = uvY0; +// } +// x108_newScanPane.drawVerts(zeus::CColor(1.f, transFactor), rttVerts); // No cull faces diff --git a/Runtime/MP1/CPlayerVisor.hpp b/Runtime/MP1/CPlayerVisor.hpp index 6d3f14258..f8004521b 100644 --- a/Runtime/MP1/CPlayerVisor.hpp +++ b/Runtime/MP1/CPlayerVisor.hpp @@ -54,8 +54,8 @@ class CPlayerVisor { TLockedToken xe4_scanFrameCenterTop; TLockedToken xf0_scanFrameStretchSide; TLockedToken xfc_scanFrameStretchTop; - // TCachedToken x108_newScanPane; - CTexturedQuadFilter x108_newScanPane; + TCachedToken x108_newScanPane; +// CTexturedQuadFilter x108_newScanPane; TLockedToken x114_scanShield; int x120_assetLockCountdown = 0; TLockedToken x124_scanIconNoncritical; diff --git a/Runtime/MP1/CTweaks.cpp b/Runtime/MP1/CTweaks.cpp index b835ad376..d7767c3be 100644 --- a/Runtime/MP1/CTweaks.cpp +++ b/Runtime/MP1/CTweaks.cpp @@ -60,7 +60,9 @@ void CTweaks::RegisterTweaks(hecl::CVarManager* cvarMgr) { /* Targeting */ tag = g_ResFactory->GetResourceIdByName("Targeting"); - strm.emplace(g_ResFactory->LoadResourceSync(*tag).release(), g_ResFactory->ResourceSize(*tag), true); + u8* Args = g_ResFactory->LoadResourceSync(*tag).release(); + u32 size = g_ResFactory->ResourceSize(*tag); + strm.emplace(Args, size, true); if (g_Main->IsTrilogy() || g_Main->IsPAL() || g_Main->IsJapanese()) { g_tweakTargeting = new DataSpec::DNAMP1::CTweakTargeting(*strm); g_tweakTargeting->initCVars(cvarMgr); diff --git a/Runtime/MP1/MP1.cpp b/Runtime/MP1/MP1.cpp index 769afbc10..336332bf5 100644 --- a/Runtime/MP1/MP1.cpp +++ b/Runtime/MP1/MP1.cpp @@ -72,7 +72,9 @@ #include "Runtime/MP1/CCredits.hpp" +#ifdef ENABLE_DISCORD #include +#endif namespace metaforce::MP1 { namespace { @@ -224,37 +226,35 @@ CGameArchitectureSupport::~CGameArchitectureSupport() { void CGameArchitectureSupport::charKeyDown(unsigned long charCode, boo::EModifierKey mods, bool isRepeat) { x30_inputGenerator.charKeyDown(charCode, mods, isRepeat); - m_parent.m_console->handleCharCode(charCode, mods, isRepeat); +// m_parent.m_console->handleCharCode(charCode, mods, isRepeat); } void CGameArchitectureSupport::specialKeyDown(boo::ESpecialKey key, boo::EModifierKey mods, bool isRepeat) { x30_inputGenerator.specialKeyDown(key, mods, isRepeat); - m_parent.m_console->handleSpecialKeyDown(key, mods, isRepeat); +// m_parent.m_console->handleSpecialKeyDown(key, mods, isRepeat); } void CGameArchitectureSupport::specialKeyUp(boo::ESpecialKey key, boo::EModifierKey mods) { x30_inputGenerator.specialKeyUp(key, mods); - m_parent.m_console->handleSpecialKeyUp(key, mods); +// m_parent.m_console->handleSpecialKeyUp(key, mods); } -CMain::CMain(IFactory* resFactory, CSimplePool* resStore, boo::IGraphicsDataFactory* gfxFactory, - boo::IGraphicsCommandQueue* cmdQ, const boo::ObjToken& spareTex) -: m_booSetter(gfxFactory, cmdQ, spareTex) +CMain::CMain(IFactory* resFactory, CSimplePool* resStore) +: m_booSetter() , xe4_gameplayResult(EGameplayResult::Playing) , x128_globalObjects(std::make_unique(resFactory, resStore)) { g_Main = this; } -CMain::BooSetter::BooSetter(boo::IGraphicsDataFactory* factory, boo::IGraphicsCommandQueue* cmdQ, - const boo::ObjToken& spareTex) { - CGraphics::InitializeBoo(factory, cmdQ, spareTex); +CMain::BooSetter::BooSetter() { +// CGraphics::InitializeBoo(); CParticleSwooshShaders::Initialize(); CThermalColdFilter::Initialize(); CThermalHotFilter::Initialize(); CSpaceWarpFilter::Initialize(); CCameraBlurFilter::Initialize(); CXRayBlurFilter::Initialize(); - CFogVolumePlaneShader::Initialize(); +// CFogVolumePlaneShader::Initialize(); CFogVolumeFilter::Initialize(); CEnergyBarShader::Initialize(); CRadarPaintShader::Initialize(); @@ -271,7 +271,7 @@ CMain::BooSetter::BooSetter(boo::IGraphicsDataFactory* factory, boo::IGraphicsCo CRandomStaticFilter::Initialize(); CEnvFxShaders::Initialize(); CNESShader::Initialize(); - CMoviePlayer::Initialize(factory); + CMoviePlayer::Initialize(); } void CMain::RegisterResourceTweaks() {} @@ -357,7 +357,7 @@ void CMain::AddWorldPaks() { path += '0' + char(i); } - if (CDvdFile::FileExists(path + ".upak")) { + if (CDvdFile::FileExists(path + ".pak")) { loader->AddPakFileAsync(path, false, true); } } @@ -373,27 +373,27 @@ void CMain::AddOverridePaks() { /* Inversely load each pak starting at 999, to ensure proper priority order * the higher the number the higer the priority, e.g: Override0 has less priority than Override1 etc. */ - for (size_t i = 999; i > 0; --i) { + for (size_t i = 9; i > 0; --i) { const std::string path = fmt::format(FMT_STRING("Override{}"), i); - if (CDvdFile::FileExists(path + ".upak")) { + if (CDvdFile::FileExists(path + ".pak")) { loader->AddPakFileAsync(path, false, false, true); } } - /* Make sure all Override paks are ready before attempting to load URDE.upak */ + /* Make sure all Override paks are ready before attempting to load URDE.pak */ loader->WaitForPakFileLoadingComplete(); /* Load Trilogy PAKs */ - if (CDvdFile::FileExists("RS5.upak")) { + if (CDvdFile::FileExists("RS5.pak")) { loader->AddPakFile("RS5", false, false, true); } - if (CDvdFile::FileExists("Strings.upak")) { + if (CDvdFile::FileExists("Strings.pak")) { loader->AddPakFile("Strings", false, false, true); } - /* Attempt to load URDE.upak + /* Attempt to load URDE.pak * NOTE(phil): Should we fatal here if it's not found? */ - if (CDvdFile::FileExists("URDE.upak")) { + if (CDvdFile::FileExists("URDE.pak")) { loader->AddPakFile("URDE", false, false, true); } } @@ -416,7 +416,7 @@ void CMain::InitializeSubsystems() { CDecalManager::Initialize(); CGBASupport::Initialize(); CPatterned::Initialize(); - CGraphics::g_BooFactory->waitUntilShadersReady(); +// CGraphics::g_BooFactory->waitUntilShadersReady(); } void CMain::MemoryCardInitializePump() { @@ -452,197 +452,6 @@ void CMain::EnsureWorldPaksReady() {} void CMain::EnsureWorldPakReady(CAssetId mlvl) { /* TODO: Schedule resource list load for World Pak containing mlvl */ } -void CMain::Give(hecl::Console* console, const std::vector& args) { - if (args.empty() || (g_GameState == nullptr || !g_GameState->GetPlayerState())) { - return; - } - - std::string type = args[0]; - athena::utility::tolower(type); - std::shared_ptr pState = g_GameState->GetPlayerState(); - if (type == "all") { - for (u32 item = 0; item < u32(CPlayerState::EItemType::Max); ++item) { - pState->ReInitializePowerUp(CPlayerState::EItemType(item), - CPlayerState::GetPowerUpMaxValue(CPlayerState::EItemType(item))); - pState->IncrPickup(CPlayerState::EItemType(item), - CPlayerState::GetPowerUpMaxValue(CPlayerState::EItemType(item))); - } - pState->IncrPickup(CPlayerState::EItemType::HealthRefill, 99999); - } else if (type == "map") { - g_GameState->CurrentWorldState().MapWorldInfo()->SetMapStationUsed(true); - } else { - CPlayerState::EItemType eType = CPlayerState::ItemNameToType(type); - if (eType == CPlayerState::EItemType::Invalid) { - console->report(hecl::Console::Level::Info, FMT_STRING("Invalid item {}"), type); - return; - } - if (eType == CPlayerState::EItemType::HealthRefill) { - pState->IncrPickup(eType, 9999); - console->report(hecl::Console::Level::Info, - FMT_STRING("Cheater....., Greatly increasing Metroid encounters, have fun!")); - if (g_StateManager != nullptr) { - g_StateManager->Player()->AsyncLoadSuit(*g_StateManager); - } - return; - } - - s32 itemAmt = CPlayerState::GetPowerUpMaxValue(eType); - if (args.size() == 2) { - s32 itemMax = CPlayerState::GetPowerUpMaxValue(eType); - itemAmt = s32(strtol(args[1].c_str(), nullptr, 10)); - itemAmt = zeus::clamp(-itemMax, itemAmt, itemMax); - } - - u32 curCap = pState->GetItemCapacity(eType); - if (itemAmt > 0 && curCap < u32(itemAmt)) { - /* Handle special case with Missiles */ - if (eType == CPlayerState::EItemType::Missiles) { - u32 tmp = ((u32(itemAmt) / 5) + (itemAmt % 5)) * 5; - pState->ReInitializePowerUp(eType, tmp); - } else { - pState->ReInitializePowerUp(eType, itemAmt); - } - } - - if (itemAmt > 0) { - pState->IncrPickup(eType, u32(itemAmt)); - } else { - pState->DecrPickup(eType, zeus::clamp(0u, u32(abs(itemAmt)), pState->GetItemAmount(eType))); - } - } - if (g_StateManager != nullptr) { - g_StateManager->Player()->AsyncLoadSuit(*g_StateManager); - } - console->report(hecl::Console::Level::Info, - FMT_STRING("Cheater....., Greatly increasing Metroid encounters, have fun!")); -} // namespace MP1 - -void CMain::Remove(hecl::Console*, const std::vector& args) { - if (args.empty() || (g_GameState == nullptr || !g_GameState->GetPlayerState())) { - return; - } - - std::string type = args[0]; - athena::utility::tolower(type); - std::shared_ptr pState = g_GameState->GetPlayerState(); - if (type == "all") { - - } else if (type == "map") { - g_GameState->CurrentWorldState().MapWorldInfo()->SetMapStationUsed(false); - } else { - CPlayerState::EItemType eType = CPlayerState::ItemNameToType(type); - if (eType != CPlayerState::EItemType::Invalid) { - pState->ReInitializePowerUp(eType, 0); - if (g_StateManager != nullptr) { - g_StateManager->Player()->AsyncLoadSuit(*g_StateManager); - } - } - } -} - -void CMain::God(hecl::Console* con, const std::vector&) { - if (g_GameState != nullptr && g_GameState->GetPlayerState()) { - g_GameState->GetPlayerState()->SetCanTakeDamage(!g_GameState->GetPlayerState()->CanTakeDamage()); - if (!g_GameState->GetPlayerState()->CanTakeDamage()) { - con->report(hecl::Console::Level::Info, FMT_STRING("God Mode Enabled")); - } else { - con->report(hecl::Console::Level::Info, FMT_STRING("God Mode Disabled")); - } - } -} - -void CMain::Teleport(hecl::Console*, const std::vector& args) { - if (g_StateManager == nullptr || args.size() < 3) { - return; - } - - zeus::CVector3f loc; - for (u32 i = 0; i < 3; ++i) { - loc[i] = strtof(args[i].c_str(), nullptr); - } - - zeus::CTransform xf = g_StateManager->Player()->GetTransform(); - xf.origin = loc; - - if (args.size() >= 6) { - zeus::CVector3f angle; - for (u32 i = 0; i < 3; ++i) { - angle[i] = zeus::degToRad(strtof(args[i + 3].c_str(), nullptr)); - } - xf.setRotation(zeus::CMatrix3f(zeus::CQuaternion(angle))); - } - g_StateManager->Player()->Teleport(xf, *g_StateManager, false); -} - -void CMain::ListWorlds(hecl::Console* con, const std::vector&) { - - if (g_ResFactory != nullptr && g_ResFactory->GetResLoader() != nullptr) { - for (const auto& pak : g_ResFactory->GetResLoader()->GetPaks()) { - if (pak->IsWorldPak()) { - for (const auto& named : pak->GetNameList()) { - if (named.second.type == SBIG('MLVL')) { - con->report(hecl::Console::Level::Info, FMT_STRING("{} '{}'"), named.first, named.second.id); - } - } - } - } - } -} - -void CMain::Warp(hecl::Console* con, const std::vector& args) { - if (g_StateManager == nullptr) { - return; - } - - if (args.empty()) { - return; - } - - TAreaId aId = 0; - std::string worldName; - if (args.size() == 2) { - worldName = args[0]; - athena::utility::tolower(worldName); - aId = strtol(args[1].c_str(), nullptr, 10); - } else { - aId = strtol(args[0].c_str(), nullptr, 10); - } - - if (!worldName.empty() && g_ResFactory != nullptr && g_ResFactory->GetResLoader() != nullptr) { - bool found = false; - - for (const auto& pak : g_ResFactory->GetResLoader()->GetPaks()) { - if (found) { - break; - } - if (pak->IsWorldPak()) { - for (const auto& named : pak->GetNameList()) { - if (named.second.type == SBIG('MLVL')) { - std::string name = named.first; - athena::utility::tolower(name); - if (name.find(worldName) != std::string::npos) { - g_GameState->SetCurrentWorldId(named.second.id); - found = true; - break; - } - } - } - } - } - } - - g_GameState->GetWorldTransitionManager()->DisableTransition(); - - if (aId >= g_GameState->CurrentWorldState().GetLayerState()->GetAreaCount()) { - aId = 0; - } - - g_GameState->CurrentWorldState().SetAreaId(aId); - g_Main->SetFlowState(EClientFlowStates::None); - g_StateManager->SetWarping(true); - g_StateManager->SetShouldQuitGame(true); -} - void CMain::StreamNewGameState(CBitStreamReader& r, u32 idx) { bool fusionBackup = g_GameState->SystemOptions().GetPlayerFusionSuitActive(); x128_globalObjects->x134_gameState = std::make_unique(r, idx); @@ -677,20 +486,25 @@ static u32 DiscordItemPercent = 0xffffffff; static std::string DiscordState; void CMain::InitializeDiscord() { +#ifdef ENABLE_DISCORD DiscordStartTime = std::time(nullptr); DiscordEventHandlers handlers = {}; handlers.ready = HandleDiscordReady; handlers.disconnected = HandleDiscordDisconnected; handlers.errored = HandleDiscordErrored; Discord_Initialize(DISCORD_APPLICATION_ID, &handlers, 1, nullptr); +#endif } void CMain::ShutdownDiscord() { +#ifdef ENABLE_DISCORD DiscordWorldSTRGObj = TLockedToken(); Discord_Shutdown(); +#endif } void CMain::UpdateDiscordPresence(CAssetId worldSTRG) { +#ifdef ENABLE_DISCORD bool updated = false; if (worldSTRG != DiscordWorldSTRG) { @@ -722,6 +536,7 @@ void CMain::UpdateDiscordPresence(CAssetId worldSTRG) { discordPresence.startTimestamp = DiscordStartTime; Discord_UpdatePresence(&discordPresence); } +#endif } void CMain::HandleDiscordReady(const DiscordUser* request) { @@ -736,41 +551,11 @@ void CMain::HandleDiscordErrored(int errorCode, const char* message) { DiscordLog.report(logvisor::Error, FMT_STRING("Discord Error: {}"), message); } -void CMain::Init(const hecl::Runtime::FileStoreManager& storeMgr, hecl::CVarManager* cvarMgr, boo::IWindow* window, +void CMain::Init(const hecl::Runtime::FileStoreManager& storeMgr, hecl::CVarManager* cvarMgr, boo::IAudioVoiceEngine* voiceEngine, amuse::IBackendVoiceAllocator& backend) { InitializeDiscord(); - m_mainWindow = window; m_cvarMgr = cvarMgr; m_cvarCommons = std::make_unique(*m_cvarMgr); - m_console = std::make_unique(m_cvarMgr); - m_console->init(window); - m_console->registerCommand( - "Quit"sv, "Quits the game immediately"sv, ""sv, - [this](hecl::Console* console, const std::vector& args) { quit(console, args); }); - m_console->registerCommand( - "Give"sv, "Gives the player the specified item, maxing it out"sv, ""sv, - [this](hecl::Console* console, const std::vector& args) { Give(console, args); }, - hecl::SConsoleCommand::ECommandFlags::Cheat); - m_console->registerCommand( - "Remove"sv, "Removes the specified item from the player"sv, ""sv, - [this](hecl::Console* console, const std::vector& args) { Remove(console, args); }, - hecl::SConsoleCommand::ECommandFlags::Cheat); - m_console->registerCommand( - "Teleport"sv, "Teleports the player to the specified coordinates in worldspace"sv, "x y z [dX dY dZ]"sv, - [this](hecl::Console* console, const std::vector& args) { Teleport(console, args); }, - (hecl::SConsoleCommand::ECommandFlags::Cheat | hecl::SConsoleCommand::ECommandFlags::Developer)); - m_console->registerCommand( - "God"sv, "Disables damage given by enemies and objects"sv, ""sv, - [this](hecl::Console* console, const std::vector& args) { God(console, args); }, - hecl::SConsoleCommand::ECommandFlags::Cheat); - m_console->registerCommand( - "ListWorlds"sv, "Lists loaded worlds"sv, ""sv, - [this](hecl::Console* console, const std::vector& args) { ListWorlds(console, args); }, - hecl::SConsoleCommand::ECommandFlags::Normal); - m_console->registerCommand( - "Warp"sv, "Warps to a given area and world"sv, "[worldname] areaId"sv, - [this](hecl::Console* console, const std::vector& args) { Warp(console, args); }, - hecl::SConsoleCommand::ECommandFlags::Normal); bool loadedVersion = false; if (CDvdFile::FileExists("version.yaml")) { @@ -785,6 +570,25 @@ void CMain::Init(const hecl::Runtime::FileStoreManager& storeMgr, hecl::CVarMana MainLog.report(logvisor::Level::Info, FMT_STRING("Loaded version info")); } } + } else if (CDvdFile::FileExists("default.dol")) { + CDvdFile file("default.dol"); + if (file) { + std::unique_ptr buf = std::make_unique(file.Length()); + u32 readLen = file.SyncRead(buf.get(), file.Length()); + const char* buildInfo = + static_cast(memmem(buf.get(), readLen, "MetroidBuildInfo", 16)) + 19; + if (buildInfo != nullptr) { + // TODO + m_version = DataSpec::MetaforceVersionInfo{ + .version = std::string(buildInfo), + .region = DataSpec::ERegion::NTSC_U, + .game = DataSpec::EGame::MetroidPrime1, + .isTrilogy = false, + }; + loadedVersion = true; + MainLog.report(logvisor::Level::Info, FMT_STRING("Loaded version info")); + } + } } InitializeSubsystems(); @@ -805,7 +609,7 @@ void CMain::Init(const hecl::Runtime::FileStoreManager& storeMgr, hecl::CVarMana MainLog.report(logvisor::Level::Fatal, FMT_STRING("Unable to load version info")); } - const auto& args = boo::APP->getArgs(); + auto args = aurora::get_args(); for (auto it = args.begin(); it != args.end(); ++it) { if (*it == "--warp" && args.end() - it >= 3) { const char* worldIdxStr = (*(it + 1)).c_str(); @@ -923,7 +727,9 @@ bool CMain::Proc(float dt) { x160_24_finished = true; } +#ifdef ENABLE_DISCORD Discord_RunCallbacks(); +#endif return x160_24_finished; } @@ -932,7 +738,7 @@ void CMain::Draw() { // Warmup cycle overrides draw if (m_warmupTags.size()) { if (m_needsWarmupClear) { - CGraphics::g_BooMainCommandQueue->clearTarget(true, true); +// CGraphics::g_BooMainCommandQueue->clearTarget(true, true); m_needsWarmupClear = false; } auto startTime = std::chrono::steady_clock::now(); @@ -959,7 +765,7 @@ void CMain::Draw() { } x164_archSupport->Draw(); - m_console->draw(CGraphics::g_BooMainCommandQueue); +// m_console->draw(CGraphics::g_BooMainCommandQueue); } void CMain::ShutdownSubsystems() { @@ -974,7 +780,7 @@ void CMain::ShutdownSubsystems() { } void CMain::Shutdown() { - m_console->unregisterCommand("Give"); +// m_console->unregisterCommand("Give"); x128_globalObjects->m_gameResFactory->UnloadPersistentResources(); x164_archSupport.reset(); ShutdownSubsystems(); @@ -984,7 +790,7 @@ void CMain::Shutdown() { CSpaceWarpFilter::Shutdown(); CCameraBlurFilter::Shutdown(); CXRayBlurFilter::Shutdown(); - CFogVolumePlaneShader::Shutdown(); +// CFogVolumePlaneShader::Shutdown(); CFogVolumeFilter::Shutdown(); CEnergyBarShader::Shutdown(); CRadarPaintShader::Shutdown(); @@ -1004,12 +810,10 @@ void CMain::Shutdown() { CFluidPlaneManager::RippleMapTex.reset(); CNESShader::Shutdown(); CBooModel::Shutdown(); - CGraphics::ShutdownBoo(); +// CGraphics::ShutdownBoo(); ShutdownDiscord(); } -boo::IWindow* CMain::GetMainWindow() const { return m_mainWindow; } - #if 0 int CMain::RsMain(int argc, char** argv, boo::IAudioVoiceEngine* voiceEngine, amuse::IBackendVoiceAllocator& backend) { @@ -1041,50 +845,4 @@ int CMain::RsMain(int argc, char** argv, boo::IAudioVoiceEngine* voiceEngine, } #endif -#if MP1_USE_BOO - -int CMain::appMain(boo::IApplication* app) { - zeus::detectCPU(); - mainWindow = app->newWindow("Metroid Prime 1 Reimplementation vZygote", 1); - mainWindow->showWindow(); - TOneStatic globalObjs; - InitializeSubsystems(); - globalObjs->PostInitialize(); - x70_tweaks.RegisterTweaks(); - AddWorldPaks(); - g_TweakManager->ReadFromMemoryCard("AudioTweaks"); - FillInAssetIDs(); - TOneStatic archSupport; - mainWindow->setCallback(archSupport.GetAllocSpace()); - - boo::IGraphicsCommandQueue* gfxQ = mainWindow->getCommandQueue(); - boo::SWindowRect windowRect = mainWindow->getWindowFrame(); - boo::ITextureR* renderTex; - boo::GraphicsDataToken data = - mainWindow->getMainContextDataFactory()->commitTransaction([&](boo::IGraphicsDataFactory::Context& ctx) -> bool { - renderTex = ctx.newRenderTexture(windowRect.size[0], windowRect.size[1], true, true); - return true; - }); - float rgba[4] = {0.2f, 0.2f, 0.2f, 1.0f}; - gfxQ->setClearColor(rgba); - - while (!xe8_b24_finished) { - xe8_b24_finished = archSupport->Update(); - - if (archSupport->isRectDirty()) { - const boo::SWindowRect& windowRect = archSupport->getWindowRect(); - gfxQ->resizeRenderTexture(renderTex, windowRect.size[0], windowRect.size[1]); - } - - gfxQ->setRenderTarget(renderTex); - gfxQ->clearTarget(); - gfxQ->resolveDisplay(renderTex); - gfxQ->execute(); - mainWindow->waitForRetrace(); - } - return 0; -} - -#endif - } // namespace metaforce::MP1 diff --git a/Runtime/MP1/MP1.hpp b/Runtime/MP1/MP1.hpp index 4af468c75..49e8f7c56 100644 --- a/Runtime/MP1/MP1.hpp +++ b/Runtime/MP1/MP1.hpp @@ -38,7 +38,6 @@ #include "Runtime/GuiSys/CTextExecuteBuffer.hpp" #include "DataSpec/DNAMP1/Tweaks/CTweakPlayer.hpp" #include "DataSpec/DNAMP1/Tweaks/CTweakGame.hpp" -#include "hecl/Console.hpp" #include "hecl/CVarCommons.hpp" struct DiscordUser; @@ -203,8 +202,7 @@ class CMain : public IMain #endif private: struct BooSetter { - BooSetter(boo::IGraphicsDataFactory* factory, boo::IGraphicsCommandQueue* cmdQ, - const boo::ObjToken& spareTex); + BooSetter(); } m_booSetter; // COsContext x0_osContext; @@ -244,10 +242,10 @@ private: bool x161_24_gameFrameDrawn : 1 = false; std::unique_ptr x164_archSupport; - boo::IWindow* m_mainWindow = nullptr; +// boo::IWindow* m_mainWindow = nullptr; hecl::CVarManager* m_cvarMgr = nullptr; std::unique_ptr m_cvarCommons; - std::unique_ptr m_console; +// std::unique_ptr m_console; // Warmup state std::vector m_warmupTags; std::vector::iterator m_warmupIt; @@ -265,8 +263,7 @@ private: static void HandleDiscordErrored(int errorCode, const char* message); public: - CMain(IFactory* resFactory, CSimplePool* resStore, boo::IGraphicsDataFactory* gfxFactory, - boo::IGraphicsCommandQueue* cmdQ, const boo::ObjToken& spareTex); + CMain(IFactory* resFactory, CSimplePool* resStore); void RegisterResourceTweaks(); void AddWorldPaks(); void AddOverridePaks(); @@ -282,13 +279,13 @@ public: // int RsMain(int argc, char** argv, boo::IAudioVoiceEngine* voiceEngine, amuse::IBackendVoiceAllocator& // backend); - void Init(const hecl::Runtime::FileStoreManager& storeMgr, hecl::CVarManager* cvarManager, boo::IWindow* window, + void Init(const hecl::Runtime::FileStoreManager& storeMgr, hecl::CVarManager* cvarManager, boo::IAudioVoiceEngine* voiceEngine, amuse::IBackendVoiceAllocator& backend) override; void WarmupShaders() override; bool Proc(float dt) override; void Draw() override; void Shutdown() override; - boo::IWindow* GetMainWindow() const override; +// boo::IWindow* GetMainWindow() const override; void MemoryCardInitializePump(); @@ -316,14 +313,6 @@ public: CGameArchitectureSupport* GetArchSupport() const { return x164_archSupport.get(); } size_t GetExpectedIdSize() const override { return sizeof(u32); } - void quit(hecl::Console*, const std::vector&) { m_doQuit = true; } - void Give(hecl::Console*, const std::vector&); - void Remove(hecl::Console*, const std::vector&); - void God(hecl::Console*, const std::vector&); - void Teleport(hecl::Console*, const std::vector&); - void ListWorlds(hecl::Console*, const std::vector&); - void Warp(hecl::Console*, const std::vector&); - hecl::Console* Console() const override { return m_console.get(); } bool IsPAL() const override { return m_version.region == ERegion::PAL; } bool IsJapanese() const override { return m_version.region == ERegion::NTSC_J; } bool IsUSA() const override { return m_version.region == ERegion::NTSC_U; } diff --git a/Runtime/MP1/World/CAtomicBeta.cpp b/Runtime/MP1/World/CAtomicBeta.cpp index c614f5178..4a66b1f67 100644 --- a/Runtime/MP1/World/CAtomicBeta.cpp +++ b/Runtime/MP1/World/CAtomicBeta.cpp @@ -35,9 +35,9 @@ CAtomicBeta::CAtomicBeta(TUniqueId uid, std::string_view name, const CEntityInfo , x608_(g_SimplePool->GetObj({SBIG('WPSC'), weaponId})) , x610_projectileDamage(dInfo) , x62c_beamParticle(particleId) -, x630_(f1) +, x630_beamFadeSpeed(f1) , x634_beamRadius(beamRadius) -, x638_(f3) +, x638_beamDamageInterval(f3) , x644_(CSfxManager::TranslateSFXID(sId1)) , x646_(CSfxManager::TranslateSFXID(sId2)) , x648_(CSfxManager::TranslateSFXID(sId3)) { @@ -47,7 +47,8 @@ CAtomicBeta::CAtomicBeta(TUniqueId uid, std::string_view name, const CEntityInfo } void CAtomicBeta::CreateBeams(CStateManager& mgr) { - const SElectricBeamInfo beamInfo{x600_electricWeapon, 50.f, x634_beamRadius, 10.f, x62c_beamParticle, x630_, x638_}; + const SElectricBeamInfo beamInfo{x600_electricWeapon, 50.f, x634_beamRadius, 10.f, x62c_beamParticle, + x630_beamFadeSpeed, x638_beamDamageInterval}; for (size_t i = 0; i < kBombCount; ++i) { const TUniqueId id = mgr.AllocateUniqueId(); diff --git a/Runtime/MP1/World/CAtomicBeta.hpp b/Runtime/MP1/World/CAtomicBeta.hpp index 5e7e87540..1ea027b52 100644 --- a/Runtime/MP1/World/CAtomicBeta.hpp +++ b/Runtime/MP1/World/CAtomicBeta.hpp @@ -27,9 +27,9 @@ class CAtomicBeta final : public CPatterned { TToken x608_; CDamageInfo x610_projectileDamage; CAssetId x62c_beamParticle; - float x630_; + float x630_beamFadeSpeed; float x634_beamRadius; - float x638_; + float x638_beamDamageInterval; float x63c_ = 1.f; float x640_ = 10.f; u16 x644_; diff --git a/Runtime/MP1/World/CBabygoth.cpp b/Runtime/MP1/World/CBabygoth.cpp index 1e5aff853..f8a8edef1 100644 --- a/Runtime/MP1/World/CBabygoth.cpp +++ b/Runtime/MP1/World/CBabygoth.cpp @@ -84,7 +84,7 @@ CBabygoth::CBabygoth(TUniqueId uid, std::string_view name, const CEntityInfo& in TLockedToken skin = g_SimplePool->GetObj({SBIG('CSKR'), babyData.x13c_noShellSkin}); xa08_noShellModel = CToken(TObjOwnerDerivedFromIObj::GetNewDerivedObject(std::make_unique( - model, skin, x64_modelData->GetAnimationData()->GetModelData()->GetLayoutInfo(), 1, 1))); + model, skin, x64_modelData->GetAnimationData()->GetModelData()->GetLayoutInfo(), 1))); xa14_crackOneParticle = g_SimplePool->GetObj({SBIG('PART'), babyData.x14c_crackOneParticle}); xa20_crackTwoParticle = g_SimplePool->GetObj({SBIG('PART'), babyData.x150_crackTwoParticle}); xa2c_destroyShellParticle = g_SimplePool->GetObj({SBIG('PART'), babyData.x154_destroyShellParticle}); diff --git a/Runtime/MP1/World/CMagdolite.cpp b/Runtime/MP1/World/CMagdolite.cpp index bebf5aee5..e9850e677 100644 --- a/Runtime/MP1/World/CMagdolite.cpp +++ b/Runtime/MP1/World/CMagdolite.cpp @@ -53,7 +53,7 @@ CMagdolite::CMagdolite(TUniqueId uid, std::string_view name, const CEntityInfo& , x690_headlessModel( CToken(TObjOwnerDerivedFromIObj::GetNewDerivedObject(std::make_unique( g_SimplePool->GetObj({SBIG('CMDL'), modelId}), g_SimplePool->GetObj({SBIG('CSKR'), skinId}), - x64_modelData->GetAnimationData()->GetModelData()->GetLayoutInfo(), 1, 1)))) + x64_modelData->GetAnimationData()->GetModelData()->GetLayoutInfo(), 1)))) , x6a8_flameInfo(magData) , x6cc_flameThrowerDesc(g_SimplePool->GetObj("FlameThrower"sv)) , x6d4_flameThrowerDamage(dInfo1) diff --git a/Runtime/MP1/World/COmegaPirate.cpp b/Runtime/MP1/World/COmegaPirate.cpp index de3e47acc..7874a1556 100644 --- a/Runtime/MP1/World/COmegaPirate.cpp +++ b/Runtime/MP1/World/COmegaPirate.cpp @@ -124,7 +124,7 @@ COmegaPirate::COmegaPirate(TUniqueId uid, std::string_view name, const CEntityIn CAssetId skeletonLayoutInfoId) : CElitePirate(uid, name, info, xf, std::move(mData), pInfo, actParms, data) , x9d0_initialScale(GetModelData()->GetScale()) -, x9f0_skeletonModel(*g_SimplePool, skeletonModelId, skeletonSkinRulesId, skeletonLayoutInfoId, 0, 0) +, x9f0_skeletonModel(*g_SimplePool, skeletonModelId, skeletonSkinRulesId, skeletonLayoutInfoId, 0) , xb70_thermalSpot(g_SimplePool->GetObj("Thermal_Spot_2"sv)) { x9a4_scriptWaypointPlatforms.reserve(3); x9b8_scriptEffects.reserve(24); diff --git a/Runtime/MP1/World/CParasite.cpp b/Runtime/MP1/World/CParasite.cpp index 2d025691b..d9890d9ab 100644 --- a/Runtime/MP1/World/CParasite.cpp +++ b/Runtime/MP1/World/CParasite.cpp @@ -71,7 +71,7 @@ CParasite::CParasite(TUniqueId uid, std::string_view name, EFlavorType flavor, c TLockedToken skin = g_SimplePool->GetObj({FOURCC('CSKR'), skinRes}); x624_extraModel = CToken(TObjOwnerDerivedFromIObj::GetNewDerivedObject(std::make_unique( - model, skin, x64_modelData->GetAnimationData()->GetModelData()->GetLayoutInfo(), 1, 1))); + model, skin, x64_modelData->GetAnimationData()->GetModelData()->GetLayoutInfo(), 1))); break; } default: diff --git a/Runtime/Particle/CDecal.cpp b/Runtime/Particle/CDecal.cpp index 33a3be6ff..74e4acbf0 100644 --- a/Runtime/Particle/CDecal.cpp +++ b/Runtime/Particle/CDecal.cpp @@ -29,18 +29,18 @@ CDecal::CDecal(const TToken& desc, const zeus::CTransform& xf x5c_29_modelInvalid = true; } - CGraphics::CommitResources([this](boo::IGraphicsDataFactory::Context& ctx) { - for (auto& decal : x3c_decalQuads) { - if (decal.m_desc->x14_TEX) { - decal.m_instBuf = ctx.newDynamicBuffer(boo::BufferUse::Vertex, sizeof(SParticleInstanceTex), 1); - } else { - decal.m_instBuf = ctx.newDynamicBuffer(boo::BufferUse::Vertex, sizeof(SParticleInstanceNoTex), 1); - } - decal.m_uniformBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(SParticleUniforms), 1); - CDecalShaders::BuildShaderDataBinding(ctx, decal); - } - return true; - } BooTrace); +// CGraphics::CommitResources([this](boo::IGraphicsDataFactory::Context& ctx) { +// for (auto& decal : x3c_decalQuads) { +// if (decal.m_desc->x14_TEX) { +// decal.m_instBuf = ctx.newDynamicBuffer(boo::BufferUse::Vertex, sizeof(SParticleInstanceTex), 1); +// } else { +// decal.m_instBuf = ctx.newDynamicBuffer(boo::BufferUse::Vertex, sizeof(SParticleInstanceNoTex), 1); +// } +// decal.m_uniformBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(SParticleUniforms), 1); +// CDecalShaders::BuildShaderDataBinding(ctx, decal); +// } +// return true; +// } BooTrace); } bool CDecal::InitQuad(CQuadDecal& quad, const SQuadDescr& desc) { @@ -97,7 +97,7 @@ void CDecal::RenderQuad(CQuadDecal& decal, const SQuadDescr& desc) const { SParticleUniforms uniformData = { CGraphics::GetPerspectiveProjectionMatrix(true) * CGraphics::g_GXModelView.toMatrix4f(), {1.f, 1.f, 1.f, 1.f}}; - decal.m_uniformBuf->load(&uniformData, sizeof(SParticleUniforms)); +// decal.m_uniformBuf->load(&uniformData, sizeof(SParticleUniforms)); bool redToAlpha = sMoveRedToAlphaBuffer && desc.x18_ADD && desc.x14_TEX; @@ -107,10 +107,10 @@ void CDecal::RenderQuad(CQuadDecal& decal, const SQuadDescr& desc) const { if (!texObj.IsLoaded()) return; tex->GetValueUV(x58_frameIdx, uvSet); - if (redToAlpha) - CGraphics::SetShaderDataBinding(decal.m_redToAlphaDataBind); - else - CGraphics::SetShaderDataBinding(decal.m_normalDataBind); +// if (redToAlpha) +// CGraphics::SetShaderDataBinding(decal.m_redToAlphaDataBind); +// else +// CGraphics::SetShaderDataBinding(decal.m_normalDataBind); g_instTexData.clear(); g_instTexData.reserve(1); @@ -136,8 +136,8 @@ void CDecal::RenderQuad(CQuadDecal& decal, const SQuadDescr& desc) const { inst.uvs[2] = zeus::CVector2f(uvSet.xMin, uvSet.yMax); inst.uvs[3] = zeus::CVector2f(uvSet.xMax, uvSet.yMax); - decal.m_instBuf->load(g_instTexData.data(), g_instTexData.size() * sizeof(SParticleInstanceTex)); - CGraphics::DrawInstances(0, 4, g_instTexData.size()); +// decal.m_instBuf->load(g_instTexData.data(), g_instTexData.size() * sizeof(SParticleInstanceTex)); +// CGraphics::DrawInstances(0, 4, g_instTexData.size()); } else { g_instNoTexData.clear(); g_instNoTexData.reserve(1); @@ -159,8 +159,8 @@ void CDecal::RenderQuad(CQuadDecal& decal, const SQuadDescr& desc) const { } inst.color = color; - decal.m_instBuf->load(g_instNoTexData.data(), g_instNoTexData.size() * sizeof(SParticleInstanceNoTex)); - CGraphics::DrawInstances(0, 4, g_instNoTexData.size()); +// decal.m_instBuf->load(g_instNoTexData.data(), g_instNoTexData.size() * sizeof(SParticleInstanceNoTex)); +// CGraphics::DrawInstances(0, 4, g_instNoTexData.size()); } } diff --git a/Runtime/Particle/CDecal.hpp b/Runtime/Particle/CDecal.hpp index 2dd7b0bf3..3e32547d0 100644 --- a/Runtime/Particle/CDecal.hpp +++ b/Runtime/Particle/CDecal.hpp @@ -20,10 +20,10 @@ struct CQuadDecal { CQuadDecal() = default; CQuadDecal(s32 i, float f) : x4_lifetime(i), x8_rotation(f) {} - boo::ObjToken m_instBuf; - boo::ObjToken m_uniformBuf; - boo::ObjToken m_normalDataBind; - boo::ObjToken m_redToAlphaDataBind; +// boo::ObjToken m_instBuf; +// boo::ObjToken m_uniformBuf; +// boo::ObjToken m_normalDataBind; +// boo::ObjToken m_redToAlphaDataBind; }; class CDecal { diff --git a/Runtime/Particle/CElementGen.cpp b/Runtime/Particle/CElementGen.cpp index bce806230..0a2115d88 100644 --- a/Runtime/Particle/CElementGen.cpp +++ b/Runtime/Particle/CElementGen.cpp @@ -209,9 +209,9 @@ CElementGen::CElementGen(TToken gen, EModelOrientationType orie if (x26c_31_LINE) { CUVElement* texr = desc->x54_x40_TEXR.get(); - boo::ObjToken tex; + std::shared_ptr tex; if (texr) - tex = texr->GetValueTexture(0).GetObj()->GetBooTexture(); + tex = texr->GetValueTexture(0).GetObj()->GetTexture(); int maxVerts = x90_MAXP; m_lineRenderer.reset( new CLineRenderer(CLineRenderer::EPrimitiveMode::Lines, maxVerts * 2, tex, x26c_26_AAPH, x26c_28_zTest)); @@ -220,10 +220,10 @@ CElementGen::CElementGen(TToken gen, EModelOrientationType orie } _RecreatePipelines(); - CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) { - CElementGenShaders::BuildShaderDataBinding(ctx, *this); - return true; - } BooTrace); +// CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) { +// CElementGenShaders::BuildShaderDataBinding(ctx, *this); +// return true; +// } BooTrace); } CElementGen::~CElementGen() { @@ -259,17 +259,17 @@ void CElementGen::_RecreatePipelines() { size_t maxInsts = x26c_30_MBLR ? 2560 * 2 : 2560; // x26c_30_MBLR ? (x270_MBSP * x90_MAXP) : x90_MAXP; maxInsts = (maxInsts == 0 ? 256 : maxInsts); - CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) { - if (!x26c_31_LINE) { - m_instBuf = ctx.newDynamicBuffer(boo::BufferUse::Vertex, ShadClsSizes[size_t(m_shaderClass)], maxInsts); - m_uniformBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(SParticleUniforms), 1); - } - if (x28_loadedGenDesc->x45_24_x31_26_PMUS) { - m_instBufPmus = ctx.newDynamicBuffer(boo::BufferUse::Vertex, ShadClsSizes[size_t(m_shaderClass)], maxInsts); - m_uniformBufPmus = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(SParticleUniforms), 1); - } - return true; - } BooTrace); +// CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) { +// if (!x26c_31_LINE) { +// m_instBuf = ctx.newDynamicBuffer(boo::BufferUse::Vertex, ShadClsSizes[size_t(m_shaderClass)], maxInsts); +// m_uniformBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(SParticleUniforms), 1); +// } +// if (x28_loadedGenDesc->x45_24_x31_26_PMUS) { +// m_instBufPmus = ctx.newDynamicBuffer(boo::BufferUse::Vertex, ShadClsSizes[size_t(m_shaderClass)], maxInsts); +// m_uniformBufPmus = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(SParticleUniforms), 1); +// } +// return true; +// } BooTrace); } bool CElementGen::InternalUpdate(double dt) { @@ -837,10 +837,10 @@ u32 CElementGen::GetSystemCount() const { void CElementGen::Render(const CActorLights* actorLights) { // Check to make sure our buffers are ready to render - if (!x26c_31_LINE && (!m_instBuf || !m_uniformBuf)) { + if (!x26c_31_LINE) { // && (!m_instBuf || !m_uniformBuf) return; } - if (x28_loadedGenDesc->x45_24_x31_26_PMUS && (!m_instBufPmus || !m_uniformBufPmus)) { + if (x28_loadedGenDesc->x45_24_x31_26_PMUS) { // && (!m_instBufPmus || !m_uniformBufPmus) return; } @@ -875,10 +875,10 @@ void CElementGen::Render(const CActorLights* actorLights) { void CElementGen::RenderModels(const CActorLights* actorLights) { // Check to make sure our buffers are ready to render - if (!x26c_31_LINE && (!m_instBuf || !m_uniformBuf)) { + if (!x26c_31_LINE) { // && (!m_instBuf || !m_uniformBuf) return; } - if (x28_loadedGenDesc->x45_24_x31_26_PMUS && (!m_instBufPmus || !m_uniformBufPmus)) { + if (x28_loadedGenDesc->x45_24_x31_26_PMUS) { // && (!m_instBufPmus || !m_uniformBufPmus) return; } @@ -944,12 +944,12 @@ void CElementGen::RenderModels(const CActorLights* actorLights) { SParticleUniforms uniformData = {CGraphics::GetPerspectiveProjectionMatrix(true), {1.f, 1.f, 1.f, 1.f}}; - m_uniformBufPmus->load(&uniformData, sizeof(SParticleUniforms)); - - if (moveRedToAlphaBuffer) - CGraphics::SetShaderDataBinding(m_redToAlphaDataBindPmus[g_Renderer->IsThermalVisorHotPass()]); - else - CGraphics::SetShaderDataBinding(m_normalDataBindPmus[g_Renderer->IsThermalVisorHotPass()]); +// m_uniformBufPmus->load(&uniformData, sizeof(SParticleUniforms)); +// +// if (moveRedToAlphaBuffer) +// CGraphics::SetShaderDataBinding(m_redToAlphaDataBindPmus[g_Renderer->IsThermalVisorHotPass()]); +// else +// CGraphics::SetShaderDataBinding(m_normalDataBindPmus[g_Renderer->IsThermalVisorHotPass()]); } zeus::CTransform orient = zeus::CTransform(); @@ -1098,12 +1098,12 @@ void CElementGen::RenderModels(const CActorLights* actorLights) { if (desc->x45_24_x31_26_PMUS) { switch (m_shaderClass) { case CElementGenShaders::EShaderClass::Tex: - m_instBufPmus->load(g_instTexData.data(), g_instTexData.size() * sizeof(SParticleInstanceTex)); - CGraphics::DrawInstances(0, 4, g_instTexData.size()); +// m_instBufPmus->load(g_instTexData.data(), g_instTexData.size() * sizeof(SParticleInstanceTex)); +// CGraphics::DrawInstances(0, 4, g_instTexData.size()); break; case CElementGenShaders::EShaderClass::NoTex: - m_instBufPmus->load(g_instNoTexData.data(), g_instNoTexData.size() * sizeof(SParticleInstanceNoTex)); - CGraphics::DrawInstances(0, 4, g_instNoTexData.size()); +// m_instBufPmus->load(g_instNoTexData.data(), g_instNoTexData.size() * sizeof(SParticleInstanceNoTex)); +// CGraphics::DrawInstances(0, 4, g_instNoTexData.size()); break; default: break; @@ -1275,7 +1275,7 @@ void CElementGen::RenderParticles() { constUVs = texr->HasConstantUV(); } - m_uniformBuf->load(&uniformData, sizeof(SParticleUniforms)); +// m_uniformBuf->load(&uniformData, sizeof(SParticleUniforms)); std::vector sortItems; if (desc->x44_28_x30_28_SORT) { @@ -1300,15 +1300,15 @@ void CElementGen::RenderParticles() { if (g_subtractBlend) { // FIXME should there be NoTex specializations for RedToAlpha? - if (moveRedToAlphaBuffer && desc->x54_x40_TEXR) - CGraphics::SetShaderDataBinding(m_redToAlphaSubDataBind[g_Renderer->IsThermalVisorHotPass()]); - else - CGraphics::SetShaderDataBinding(m_normalSubDataBind[g_Renderer->IsThermalVisorHotPass()]); +// if (moveRedToAlphaBuffer && desc->x54_x40_TEXR) +// CGraphics::SetShaderDataBinding(m_redToAlphaSubDataBind[g_Renderer->IsThermalVisorHotPass()]); +// else +// CGraphics::SetShaderDataBinding(m_normalSubDataBind[g_Renderer->IsThermalVisorHotPass()]); } else { - if (moveRedToAlphaBuffer && desc->x54_x40_TEXR) - CGraphics::SetShaderDataBinding(m_redToAlphaDataBind[g_Renderer->IsThermalVisorHotPass()]); - else - CGraphics::SetShaderDataBinding(m_normalDataBind[g_Renderer->IsThermalVisorHotPass()]); +// if (moveRedToAlphaBuffer && desc->x54_x40_TEXR) +// CGraphics::SetShaderDataBinding(m_redToAlphaDataBind[g_Renderer->IsThermalVisorHotPass()]); +// else +// CGraphics::SetShaderDataBinding(m_normalDataBind[g_Renderer->IsThermalVisorHotPass()]); } int mbspVal = std::max(1, x270_MBSP); @@ -1521,12 +1521,12 @@ void CElementGen::RenderParticles() { switch (m_shaderClass) { case CElementGenShaders::EShaderClass::Tex: - m_instBuf->load(g_instTexData.data(), g_instTexData.size() * sizeof(SParticleInstanceTex)); - CGraphics::DrawInstances(0, 4, g_instTexData.size()); +// m_instBuf->load(g_instTexData.data(), g_instTexData.size() * sizeof(SParticleInstanceTex)); +// CGraphics::DrawInstances(0, 4, g_instTexData.size()); break; case CElementGenShaders::EShaderClass::NoTex: - m_instBuf->load(g_instNoTexData.data(), g_instNoTexData.size() * sizeof(SParticleInstanceNoTex)); - CGraphics::DrawInstances(0, 4, g_instNoTexData.size()); +// m_instBuf->load(g_instNoTexData.data(), g_instNoTexData.size() * sizeof(SParticleInstanceNoTex)); +// CGraphics::DrawInstances(0, 4, g_instNoTexData.size()); break; default: break; @@ -1635,12 +1635,12 @@ void CElementGen::RenderParticles() { } switch (m_shaderClass) { case CElementGenShaders::EShaderClass::Tex: - m_instBuf->load(g_instTexData.data(), g_instTexData.size() * sizeof(SParticleInstanceTex)); - CGraphics::DrawInstances(0, 4, g_instTexData.size()); +// m_instBuf->load(g_instTexData.data(), g_instTexData.size() * sizeof(SParticleInstanceTex)); +// CGraphics::DrawInstances(0, 4, g_instTexData.size()); break; case CElementGenShaders::EShaderClass::NoTex: - m_instBuf->load(g_instNoTexData.data(), g_instNoTexData.size() * sizeof(SParticleInstanceNoTex)); - CGraphics::DrawInstances(0, 4, g_instNoTexData.size()); +// m_instBuf->load(g_instNoTexData.data(), g_instNoTexData.size() * sizeof(SParticleInstanceNoTex)); +// CGraphics::DrawInstances(0, 4, g_instNoTexData.size()); break; default: break; @@ -1661,7 +1661,7 @@ void CElementGen::RenderParticlesIndirectTexture() { SParticleUniforms uniformData = { CGraphics::GetPerspectiveProjectionMatrix(true) * CGraphics::g_GXModelView.toMatrix4f(), {1.f, 1.f, 1.f, 1.f}}; - m_uniformBuf->load(&uniformData, sizeof(SParticleUniforms)); +// m_uniformBuf->load(&uniformData, sizeof(SParticleUniforms)); CGraphics::SetAlphaCompare(ERglAlphaFunc::Always, 0, ERglAlphaOp::And, ERglAlphaFunc::Always, 0); @@ -1714,8 +1714,8 @@ void CElementGen::RenderParticlesIndirectTexture() { g_instIndTexData.clear(); g_instIndTexData.reserve(x30_particles.size()); - if (!x30_particles.empty()) - CGraphics::SetShaderDataBinding(m_normalDataBind[g_Renderer->IsThermalVisorHotPass()]); +// if (!x30_particles.empty()) +// CGraphics::SetShaderDataBinding(m_normalDataBind[g_Renderer->IsThermalVisorHotPass()]); for (size_t i = 0; i < x30_particles.size(); ++i) { const int partIdx = desc->x44_28_x30_28_SORT ? sortItems[i].x0_partIdx : int(i); @@ -1773,21 +1773,22 @@ void CElementGen::RenderParticlesIndirectTexture() { inst.texrTindUVs[1] = zeus::CVector4f{uvs.xMin, uvs.yMax, uvsInd.xMin, uvsInd.yMax}; inst.texrTindUVs[2] = zeus::CVector4f{uvs.xMax, uvs.yMin, uvsInd.xMax, uvsInd.yMin}; inst.texrTindUVs[3] = zeus::CVector4f{uvs.xMin, uvs.yMin, uvsInd.xMin, uvsInd.yMin}; - switch (CGraphics::g_BooPlatform) { - case boo::IGraphicsDataFactory::Platform::OpenGL: - inst.sceneUVs = - zeus::CVector4f{clipRect.x18_uvXMin, clipRect.x24_uvYMax, clipRect.x1c_uvXMax, clipRect.x20_uvYMin}; - break; - default: +// switch (CGraphics::g_BooPlatform) { +// case boo::IGraphicsDataFactory::Platform::OpenGL: +// inst.sceneUVs = +// zeus::CVector4f{clipRect.x18_uvXMin, clipRect.x24_uvYMax, clipRect.x1c_uvXMax, clipRect.x20_uvYMin}; +// break; +// default: inst.sceneUVs = zeus::CVector4f{clipRect.x18_uvXMin, 1.f - clipRect.x24_uvYMax, clipRect.x1c_uvXMax, 1.f - clipRect.x20_uvYMin}; - break; - } - CGraphics::DrawInstances(0, 4, 1, g_instIndTexData.size() - 1); +// break; +// } +// CGraphics::DrawInstances(0, 4, 1, g_instIndTexData.size() - 1); } if (g_instIndTexData.size()) { - m_instBuf->load(g_instIndTexData.data(), g_instIndTexData.size() * sizeof(SParticleInstanceIndTex)); +// m_instBuf->load(g_instIndTexData.data(), g_instIndTexData.size() * sizeof(SParticleInstanceIndTex)); +// TODO! this looks like a bug // CGraphics::SetShaderDataBinding(m_normalDataBind); // CGraphics::DrawInstances(0, 4, g_instIndTexData.size()); } diff --git a/Runtime/Particle/CElementGen.hpp b/Runtime/Particle/CElementGen.hpp index 7b00e7aa8..12c008f52 100644 --- a/Runtime/Particle/CElementGen.hpp +++ b/Runtime/Particle/CElementGen.hpp @@ -141,17 +141,17 @@ public: EOptionalSystemFlags flags = EOptionalSystemFlags::One); ~CElementGen() override; - std::array, 2> m_normalDataBind; - std::array, 2> m_normalSubDataBind; - std::array, 2> m_redToAlphaDataBind; - std::array, 2> m_redToAlphaSubDataBind; - boo::ObjToken m_instBuf; - boo::ObjToken m_uniformBuf; - - std::array, 2> m_normalDataBindPmus; - std::array, 2> m_redToAlphaDataBindPmus; - boo::ObjToken m_instBufPmus; - boo::ObjToken m_uniformBufPmus; +// std::array, 2> m_normalDataBind; +// std::array, 2> m_normalSubDataBind; +// std::array, 2> m_redToAlphaDataBind; +// std::array, 2> m_redToAlphaSubDataBind; +// boo::ObjToken m_instBuf; +// boo::ObjToken m_uniformBuf; +// +// std::array, 2> m_normalDataBindPmus; +// std::array, 2> m_redToAlphaDataBindPmus; +// boo::ObjToken m_instBufPmus; +// boo::ObjToken m_uniformBufPmus; CGenDescription* GetDesc() { return x1c_genDesc.GetObj(); } const SObjectTag* GetDescTag() const { return x1c_genDesc.GetObjectTag(); } diff --git a/Runtime/Particle/CParticleDataFactory.cpp b/Runtime/Particle/CParticleDataFactory.cpp index 95125c537..2613d4464 100644 --- a/Runtime/Particle/CParticleDataFactory.cpp +++ b/Runtime/Particle/CParticleDataFactory.cpp @@ -907,21 +907,15 @@ bool CParticleDataFactory::CreateGPSM(CGenDescription* fillDesc, CInputStream& i case SBIG('SSPO'): fillDesc->xe8_xd4_SSPO = GetVectorElement(in); break; - case SBIG('TEXR'): { - std::unique_ptr tex(GetTextureElement(in, resPool)); - if (tex->GetValueTexture(0)) - fillDesc->x54_x40_TEXR = std::move(tex); + case SBIG('TEXR'): + fillDesc->x54_x40_TEXR = GetTextureElement(in, resPool); break; - } case SBIG('SSWH'): fillDesc->xd4_xc0_SSWH = GetSwooshGeneratorDesc(in, resPool); break; - case SBIG('TIND'): { - std::unique_ptr tex(GetTextureElement(in, resPool)); - if (tex->GetValueTexture(0)) - fillDesc->x58_x44_TIND = std::move(tex); + case SBIG('TIND'): + fillDesc->x58_x44_TIND = GetTextureElement(in, resPool); break; - } case SBIG('VMD4'): fillDesc->x45_29_x31_31_VMD4 = GetBool(in); break; diff --git a/Runtime/Particle/CParticleSwoosh.cpp b/Runtime/Particle/CParticleSwoosh.cpp index c4fbc5e7f..36753466e 100644 --- a/Runtime/Particle/CParticleSwoosh.cpp +++ b/Runtime/Particle/CParticleSwoosh.cpp @@ -71,12 +71,12 @@ CParticleSwoosh::CParticleSwoosh(const TToken& desc, int len } else { const auto maxVerts = size_t(x1b4_LENG * (x1b0_SPLN + 1) * x1b8_SIDE * 4); m_cachedVerts.reserve(maxVerts); - CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) { - m_vertBuf = ctx.newDynamicBuffer(boo::BufferUse::Vertex, sizeof(CParticleSwooshShaders::Vert), maxVerts); - m_uniformBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(zeus::CMatrix4f), 1); - CParticleSwooshShaders::BuildShaderDataBinding(ctx, *this); - return true; - } BooTrace); +// CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) { +// m_vertBuf = ctx.newDynamicBuffer(boo::BufferUse::Vertex, sizeof(CParticleSwooshShaders::Vert), maxVerts); +// m_uniformBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(zeus::CMatrix4f), 1); +// CParticleSwooshShaders::BuildShaderDataBinding(ctx, *this); +// return true; +// } BooTrace); } } } @@ -437,7 +437,7 @@ void CParticleSwoosh::RenderNSidedSpline() { m_cachedVerts.push_back({v1, {x1d4_uvs.xMin, x1d4_uvs.yMax}, color}); m_cachedVerts.push_back({v2, {x1d4_uvs.xMax, x1d4_uvs.yMin}, color}); m_cachedVerts.push_back({v3, {x1d4_uvs.xMax, x1d4_uvs.yMax}, color}); - CGraphics::DrawArray(m_cachedVerts.size() - 4, 4); +// CGraphics::DrawArray(m_cachedVerts.size() - 4, 4); } else { const auto v0 = GetSplinePoint(x16c_p0[k], x17c_p1[k], x18c_p2[k], x19c_p3[k], t0); const auto v1 = GetSplinePoint(x16c_p0[otherK], x17c_p1[otherK], x18c_p2[otherK], x19c_p3[otherK], t0); @@ -462,7 +462,7 @@ void CParticleSwoosh::RenderNSidedSpline() { m_cachedVerts.push_back({v1, {x1d4_uvs.xMin, x1d4_uvs.yMax}, color}); m_cachedVerts.push_back({v2, {x1d4_uvs.xMax, x1d4_uvs.yMin}, color}); m_cachedVerts.push_back({v3, {x1d4_uvs.xMax, x1d4_uvs.yMax}, color}); - CGraphics::DrawArray(m_cachedVerts.size() - 4, 4); +// CGraphics::DrawArray(m_cachedVerts.size() - 4, 4); } } } @@ -593,19 +593,19 @@ void CParticleSwoosh::Render3SidedSolidSpline() { m_cachedVerts.push_back({v10, {uv0, x1d4_uvs.yMax}, c0}); m_cachedVerts.push_back({v01, {uv1, x1d4_uvs.yMin}, c1}); m_cachedVerts.push_back({v11, {uv1, x1d4_uvs.yMax}, c1}); - CGraphics::DrawArray(m_cachedVerts.size() - 4, 4); +// CGraphics::DrawArray(m_cachedVerts.size() - 4, 4); m_cachedVerts.push_back({v10, {uv0, x1d4_uvs.yMin}, c0}); m_cachedVerts.push_back({v20, {uv0, x1d4_uvs.yMax}, c0}); m_cachedVerts.push_back({v11, {uv1, x1d4_uvs.yMin}, c1}); m_cachedVerts.push_back({v21, {uv1, x1d4_uvs.yMax}, c1}); - CGraphics::DrawArray(m_cachedVerts.size() - 4, 4); +// CGraphics::DrawArray(m_cachedVerts.size() - 4, 4); m_cachedVerts.push_back({v20, {uv0, x1d4_uvs.yMin}, c0}); m_cachedVerts.push_back({v00, {uv0, x1d4_uvs.yMax}, c0}); m_cachedVerts.push_back({v21, {uv1, x1d4_uvs.yMin}, c1}); m_cachedVerts.push_back({v01, {uv1, x1d4_uvs.yMax}, c1}); - CGraphics::DrawArray(m_cachedVerts.size() - 4, 4); +// CGraphics::DrawArray(m_cachedVerts.size() - 4, 4); } } } @@ -685,19 +685,19 @@ void CParticleSwoosh::Render3SidedSolidNoSplineNoGaps() { m_cachedVerts.push_back({p1[i & 1], {uv0, x1d4_uvs.yMax}, c0}); m_cachedVerts.push_back({p0[!(i & 1)], {uv1, x1d4_uvs.yMin}, c1}); m_cachedVerts.push_back({p1[!(i & 1)], {uv1, x1d4_uvs.yMax}, c1}); - CGraphics::DrawArray(m_cachedVerts.size() - 4, 4); +// CGraphics::DrawArray(m_cachedVerts.size() - 4, 4); m_cachedVerts.push_back({p1[i & 1], {uv0, x1d4_uvs.yMin}, c0}); m_cachedVerts.push_back({p2[i & 1], {uv0, x1d4_uvs.yMax}, c0}); m_cachedVerts.push_back({p1[!(i & 1)], {uv1, x1d4_uvs.yMin}, c1}); m_cachedVerts.push_back({p2[!(i & 1)], {uv1, x1d4_uvs.yMax}, c1}); - CGraphics::DrawArray(m_cachedVerts.size() - 4, 4); +// CGraphics::DrawArray(m_cachedVerts.size() - 4, 4); m_cachedVerts.push_back({p2[i & 1], {uv0, x1d4_uvs.yMin}, c0}); m_cachedVerts.push_back({p0[i & 1], {uv0, x1d4_uvs.yMax}, c0}); m_cachedVerts.push_back({p2[!(i & 1)], {uv1, x1d4_uvs.yMin}, c1}); m_cachedVerts.push_back({p0[!(i & 1)], {uv1, x1d4_uvs.yMax}, c1}); - CGraphics::DrawArray(m_cachedVerts.size() - 4, 4); +// CGraphics::DrawArray(m_cachedVerts.size() - 4, 4); } } @@ -719,7 +719,7 @@ void CParticleSwoosh::Render2SidedNoSplineGaps() { if (!swoosh.x0_active) { if (streaming) { streaming = false; - CGraphics::DrawArray(drawStart, m_cachedVerts.size() - drawStart); +// CGraphics::DrawArray(drawStart, m_cachedVerts.size() - drawStart); } continue; } @@ -764,8 +764,8 @@ void CParticleSwoosh::Render2SidedNoSplineGaps() { m_cachedVerts.push_back({v1, {0.f, x1d4_uvs.yMax}, color}); } - if (streaming) - CGraphics::DrawArray(drawStart, m_cachedVerts.size() - drawStart); +// if (streaming) +// CGraphics::DrawArray(drawStart, m_cachedVerts.size() - drawStart); } void CParticleSwoosh::Render2SidedNoSplineNoGaps() { @@ -818,7 +818,7 @@ void CParticleSwoosh::Render2SidedNoSplineNoGaps() { m_cachedVerts.push_back({v0, {uvOffset, x1d4_uvs.yMin}, color}); m_cachedVerts.push_back({v1, {uvOffset, x1d4_uvs.yMax}, color}); if (uvOffset >= 1.f && particleCount) { - CGraphics::DrawArray(drawStart, m_cachedVerts.size() - drawStart); +// CGraphics::DrawArray(drawStart, m_cachedVerts.size() - drawStart); drawStart = m_cachedVerts.size(); uvOffset -= 1.f; m_cachedVerts.push_back({v0, {uvOffset, x1d4_uvs.yMin}, color}); @@ -872,7 +872,7 @@ void CParticleSwoosh::Render2SidedNoSplineNoGaps() { m_cachedVerts.push_back({v0, {uvOffset, x1d4_uvs.yMin}, color}); m_cachedVerts.push_back({v1, {uvOffset, x1d4_uvs.yMax}, color}); if (uvOffset >= 1.f && particleCount) { - CGraphics::DrawArray(drawStart, m_cachedVerts.size() - drawStart); +// CGraphics::DrawArray(drawStart, m_cachedVerts.size() - drawStart); drawStart = m_cachedVerts.size(); uvOffset -= 1.f; m_cachedVerts.push_back({v0, {uvOffset, x1d4_uvs.yMin}, color}); @@ -925,7 +925,7 @@ void CParticleSwoosh::Render2SidedNoSplineNoGaps() { } } - CGraphics::DrawArray(drawStart, m_cachedVerts.size() - drawStart); +// CGraphics::DrawArray(drawStart, m_cachedVerts.size() - drawStart); } void CParticleSwoosh::Render(const CActorLights*) { @@ -937,9 +937,9 @@ void CParticleSwoosh::Render(const CActorLights*) { zeus::skYellow); m_cachedVerts.clear(); - if (m_dataBind[0]) { - CGraphics::SetShaderDataBinding(m_dataBind[g_Renderer->IsThermalVisorHotPass()]); - } +// if (m_dataBind[0]) { +// CGraphics::SetShaderDataBinding(m_dataBind[g_Renderer->IsThermalVisorHotPass()]); +// } CParticleGlobals::instance()->SetParticleLifetime(x1b4_LENG); CGlobalRandom gr(x1c0_rand); @@ -1007,10 +1007,10 @@ void CParticleSwoosh::Render(const CActorLights*) { } zeus::CMatrix4f mvp = CGraphics::GetPerspectiveProjectionMatrix(true) * CGraphics::g_GXModelView.toMatrix4f(); - m_uniformBuf->load(&mvp, sizeof(zeus::CMatrix4f)); - if (m_cachedVerts.size()) { - m_vertBuf->load(m_cachedVerts.data(), m_cachedVerts.size() * sizeof(CParticleSwooshShaders::Vert)); - } +// m_uniformBuf->load(&mvp, sizeof(zeus::CMatrix4f)); +// if (m_cachedVerts.size()) { +// m_vertBuf->load(m_cachedVerts.data(), m_cachedVerts.size() * sizeof(CParticleSwooshShaders::Vert)); +// } } void CParticleSwoosh::SetOrientation(const zeus::CTransform& xf) { diff --git a/Runtime/Particle/CParticleSwoosh.hpp b/Runtime/Particle/CParticleSwoosh.hpp index a76c00a99..2b77e4498 100644 --- a/Runtime/Particle/CParticleSwoosh.hpp +++ b/Runtime/Particle/CParticleSwoosh.hpp @@ -104,9 +104,9 @@ private: float x208_maxRadius = 0.f; zeus::CColor x20c_moduColor = zeus::skWhite; - std::array, 2> m_dataBind; - boo::ObjToken m_vertBuf; - boo::ObjToken m_uniformBuf; +// std::array, 2> m_dataBind; +// boo::ObjToken m_vertBuf; +// boo::ObjToken m_uniformBuf; std::unique_ptr m_lineRenderer; std::vector m_cachedVerts; diff --git a/Runtime/Weapon/CElectricBeamProjectile.cpp b/Runtime/Weapon/CElectricBeamProjectile.cpp index 9328e7b82..43e6165dd 100644 --- a/Runtime/Weapon/CElectricBeamProjectile.cpp +++ b/Runtime/Weapon/CElectricBeamProjectile.cpp @@ -20,8 +20,8 @@ CElectricBeamProjectile::CElectricBeamProjectile(const TToken(elec.x0_electricDescription)) , x46c_genDescription(g_SimplePool->GetObj({SBIG('PART'), elec.x14_particleId})) , x478_elementGen(std::make_unique(x46c_genDescription)) -, x47c_(elec.x18_) -, x488_(elec.x1c_) { +, x47c_fadeSpeed(elec.x18_fadeSpeed) +, x488_damageInterval(elec.x1c_damageInterval) { x478_elementGen->SetParticleEmission(false); x468_electric->SetParticleEmission(false); } @@ -50,28 +50,28 @@ void CElectricBeamProjectile::UpdateFx(const zeus::CTransform& xf, float dt, CSt if (!GetActive()) return; - if (x484_ <= 0.f) + if (x484_damageTimer <= 0.f) CauseDamage(true); if (GetDamageType() == EDamageType::Actor) { - x484_ = x488_; + x484_damageTimer = x488_damageInterval; CauseDamage(false); } - x484_ -= dt; - if (zeus::close_enough(x47c_, 0.f)) { - x480_ = 1.f; + x484_damageTimer -= dt; + if (zeus::close_enough(x47c_fadeSpeed, 0.f)) { + x480_intensity = 1.f; } else { float fVar1 = x48c_ ? 1.f : -1.f; - x480_ = std::min(1.f, dt * (fVar1 / x47c_) + x480_); - if (x480_ < 0.f) { + x480_intensity = std::min(1.f, dt * (fVar1 / x47c_fadeSpeed) + x480_intensity); + if (x480_intensity < 0.f) { ResetBeam(mgr, true); } } CBeamProjectile::UpdateFx(xf, dt, mgr); - x478_elementGen->SetModulationColor(zeus::CColor::lerp(zeus::skBlack, zeus::skWhite, x480_)); + x478_elementGen->SetModulationColor(zeus::CColor::lerp(zeus::skBlack, zeus::skWhite, x480_intensity)); bool hasDamage = GetDamageType() != EDamageType::None; if (hasDamage) { x478_elementGen->SetGlobalOrientation(zeus::lookAt(zeus::skZero3f, GetSurfaceNormal(), zeus::skUp)); @@ -80,7 +80,7 @@ void CElectricBeamProjectile::UpdateFx(const zeus::CTransform& xf, float dt, CSt x478_elementGen->SetParticleEmission(hasDamage); x478_elementGen->Update(dt); - x468_electric->SetModulationColor(zeus::CColor::lerp(zeus::skBlack, zeus::skWhite, x480_)); + x468_electric->SetModulationColor(zeus::CColor::lerp(zeus::skBlack, zeus::skWhite, x480_intensity)); x468_electric->SetParticleEmission(true); zeus::CVector3f dist = GetCurrentPos() - GetBeamTransform().origin; if (dist.canBeNormalized()) { @@ -107,6 +107,6 @@ void CElectricBeamProjectile::ResetBeam(CStateManager& mgr, bool b) { void CElectricBeamProjectile::Fire(const zeus::CTransform&, CStateManager&, bool) { x48c_ = true; SetActive(true); - x480_ = 0.f; + x480_intensity = 0.f; } } // namespace metaforce diff --git a/Runtime/Weapon/CElectricBeamProjectile.hpp b/Runtime/Weapon/CElectricBeamProjectile.hpp index 6ca613969..14aa3d6ea 100644 --- a/Runtime/Weapon/CElectricBeamProjectile.hpp +++ b/Runtime/Weapon/CElectricBeamProjectile.hpp @@ -11,18 +11,18 @@ struct SElectricBeamInfo { float xc_radius; float x10_travelSpeed; CAssetId x14_particleId; - float x18_; - float x1c_; + float x18_fadeSpeed; + float x1c_damageInterval; }; class CElectricBeamProjectile : public CBeamProjectile { std::unique_ptr x468_electric; TCachedToken x46c_genDescription; std::unique_ptr x478_elementGen; - float x47c_; - float x480_; - float x484_ = 0.f; - float x488_; + float x47c_fadeSpeed; + float x480_intensity; + float x484_damageTimer = 0.f; + float x488_damageInterval; bool x48c_ = false; public: diff --git a/Runtime/Weapon/CGunMotion.cpp b/Runtime/Weapon/CGunMotion.cpp index e4d205930..c77aed751 100644 --- a/Runtime/Weapon/CGunMotion.cpp +++ b/Runtime/Weapon/CGunMotion.cpp @@ -7,7 +7,7 @@ namespace metaforce { CGunMotion::CGunMotion(CAssetId ancsId, const zeus::CVector3f& scale) -: x0_modelData(CAnimRes(ancsId, 0, scale, 0, false), 1), x4c_gunController(x0_modelData) { +: x0_modelData(CAnimRes(ancsId, 0, scale, 0, false))/*, 1*/, x4c_gunController(x0_modelData) { LoadAnimations(); } diff --git a/Runtime/Weapon/CPlasmaProjectile.cpp b/Runtime/Weapon/CPlasmaProjectile.cpp index 60f11b5d1..6082ca672 100644 --- a/Runtime/Weapon/CPlasmaProjectile.cpp +++ b/Runtime/Weapon/CPlasmaProjectile.cpp @@ -12,17 +12,17 @@ namespace metaforce { -CPlasmaProjectile::RenderObjects::RenderObjects(boo::IGraphicsDataFactory::Context& ctx, - boo::ObjToken tex, boo::ObjToken glowTex) -: m_beamStrip1(ctx, 8, CColoredStripShader::Mode::Additive, {}) -, m_beamStrip2(ctx, 10, CColoredStripShader::Mode::FullAdditive, tex) -, m_beamStrip3(ctx, 18, CColoredStripShader::Mode::FullAdditive, tex) -, m_beamStrip4(ctx, 14, CColoredStripShader::Mode::Additive, glowTex) -, m_beamStrip1Sub(ctx, 8, CColoredStripShader::Mode::Subtractive, {}) -, m_beamStrip2Sub(ctx, 10, CColoredStripShader::Mode::Subtractive, tex) -, m_beamStrip3Sub(ctx, 18, CColoredStripShader::Mode::Subtractive, tex) -, m_beamStrip4Sub(ctx, 14, CColoredStripShader::Mode::Subtractive, glowTex) -, m_motionBlurStrip(ctx, 16, CColoredStripShader::Mode::Alpha, {}) {} +CPlasmaProjectile::RenderObjects::RenderObjects(std::shared_ptr tex, + std::shared_ptr glowTex) +: m_beamStrip1(8, CColoredStripShader::Mode::Additive, {}) +, m_beamStrip2( 10, CColoredStripShader::Mode::FullAdditive, tex) +, m_beamStrip3( 18, CColoredStripShader::Mode::FullAdditive, tex) +, m_beamStrip4( 14, CColoredStripShader::Mode::Additive, glowTex) +, m_beamStrip1Sub( 8, CColoredStripShader::Mode::Subtractive, {}) +, m_beamStrip2Sub( 10, CColoredStripShader::Mode::Subtractive, tex) +, m_beamStrip3Sub( 18, CColoredStripShader::Mode::Subtractive, tex) +, m_beamStrip4Sub( 14, CColoredStripShader::Mode::Subtractive, glowTex) +, m_motionBlurStrip( 16, CColoredStripShader::Mode::Alpha, {}) {} CPlasmaProjectile::CPlasmaProjectile(const TToken& wDesc, std::string_view name, EWeaponType wType, const CBeamInfo& bInfo, const zeus::CTransform& xf, EMaterialTypes matType, @@ -60,10 +60,10 @@ CPlasmaProjectile::CPlasmaProjectile(const TToken& wDesc, st x518_contactGen->SetParticleEmission(false); x51c_pulseGen->SetParticleEmission(false); - CGraphics::CommitResources([this](boo::IGraphicsDataFactory::Context& ctx) { - m_renderObjs.emplace(ctx, x4e8_texture->GetBooTexture(), x4f4_glowTexture->GetBooTexture()); - return true; - } BooTrace); +// CGraphics::CommitResources([this](boo::IGraphicsDataFactory::Context& ctx) { + m_renderObjs.emplace(x4e8_texture->GetTexture(), x4f4_glowTexture->GetTexture()); +// return true; +// } BooTrace); } void CPlasmaProjectile::Accept(IVisitor& visitor) { visitor.Visit(this); } diff --git a/Runtime/Weapon/CPlasmaProjectile.hpp b/Runtime/Weapon/CPlasmaProjectile.hpp index f964a5ae2..11635a4ff 100644 --- a/Runtime/Weapon/CPlasmaProjectile.hpp +++ b/Runtime/Weapon/CPlasmaProjectile.hpp @@ -91,8 +91,8 @@ private: CColoredStripShader m_beamStrip3Sub; CColoredStripShader m_beamStrip4Sub; CColoredStripShader m_motionBlurStrip; - RenderObjects(boo::IGraphicsDataFactory::Context& ctx, boo::ObjToken tex, - boo::ObjToken glowTex); + RenderObjects(std::shared_ptr tex, + std::shared_ptr glowTex); }; std::optional m_renderObjs; diff --git a/Runtime/Weapon/CPlayerGun.cpp b/Runtime/Weapon/CPlayerGun.cpp index e67ffe1b4..60d5eb6c5 100644 --- a/Runtime/Weapon/CPlayerGun.cpp +++ b/Runtime/Weapon/CPlayerGun.cpp @@ -2140,7 +2140,7 @@ void CPlayerGun::DrawScreenTex(float z) { // Use CopyScreenTex rendering to draw over framebuffer pixels in front of `z` // This is accomplished using orthographic projection quad with sweeping `y` coordinates // Depth is set to GEQUAL to obscure pixels in front rather than behind - m_screenQuad.draw(zeus::skWhite, 1.f, CTexturedQuadFilter::DefaultRect, z); +// m_screenQuad.draw(zeus::skWhite, 1.f, CTexturedQuadFilter::DefaultRect, z); } void CPlayerGun::DrawClipCube(const zeus::CAABox& aabb) { diff --git a/Runtime/Weapon/CPlayerGun.hpp b/Runtime/Weapon/CPlayerGun.hpp index 5999aba2f..607027825 100644 --- a/Runtime/Weapon/CPlayerGun.hpp +++ b/Runtime/Weapon/CPlayerGun.hpp @@ -255,8 +255,8 @@ private: bool x835_30_inPhazonPool : 1 = false; bool x835_31_actorAttached : 1 = false; - CTexturedQuadFilter m_screenQuad{EFilterType::Blend, CGraphics::g_SpareTexture.get(), - CTexturedQuadFilter::ZTest::GEqualZWrite}; +// CTexturedQuadFilter m_screenQuad{EFilterType::Blend, CGraphics::g_SpareTexture.get(), +// CTexturedQuadFilter::ZTest::GEqualZWrite}; CAABoxShader m_aaboxShader{true}; void InitBeamData(); diff --git a/Runtime/World/CActor.cpp b/Runtime/World/CActor.cpp index 88b0a33a3..0ed646434 100644 --- a/Runtime/World/CActor.cpp +++ b/Runtime/World/CActor.cpp @@ -456,12 +456,12 @@ void CActor::_CreateShadow() { } void CActor::_CreateReflectionCube() { - if (hecl::com_cubemaps->toBoolean()) { - CGraphics::CommitResources([this](boo::IGraphicsDataFactory::Context& ctx) { - m_reflectionCube = ctx.newCubeRenderTexture(CUBEMAP_RES, CUBEMAP_MIPS); - return true; - } BooTrace); - } +// if (hecl::com_cubemaps->toBoolean()) { +// CGraphics::CommitResources([this](boo::IGraphicsDataFactory::Context& ctx) { +// m_reflectionCube = ctx.newCubeRenderTexture(CUBEMAP_RES, CUBEMAP_MIPS); +// return true; +// } BooTrace); +// } } void CActor::SetCallTouch(bool callTouch) { xe5_28_callTouch = callTouch; } diff --git a/Runtime/World/CActor.hpp b/Runtime/World/CActor.hpp index 4da11a0ba..5b197ae56 100644 --- a/Runtime/World/CActor.hpp +++ b/Runtime/World/CActor.hpp @@ -75,7 +75,7 @@ protected: bool xe7_30_doTargetDistanceTest : 1 = true; bool xe7_31_targetable : 1 = true; - boo::ObjToken m_reflectionCube; + std::shared_ptr m_reflectionCube; zeus::CColor m_debugAddColor = zeus::skClear; float m_debugAddColorTime = 0.f; diff --git a/Runtime/World/CActorModelParticles.cpp b/Runtime/World/CActorModelParticles.cpp index cabfefb19..f73e83eef 100644 --- a/Runtime/World/CActorModelParticles.cpp +++ b/Runtime/World/CActorModelParticles.cpp @@ -622,7 +622,7 @@ void CActorModelParticles::LightDudeOnFire(CActor& act) { const CTexture* CActorModelParticles::GetAshyTexture(const CActor& act) { auto iter = FindSystem(act.GetUniqueId()); if (iter != x0_items.cend() && iter->xdc_ashy && iter->xdc_ashy.IsLoaded()) { - iter->xdc_ashy->GetBooTexture()->setClampMode(boo::TextureClampMode::ClampToEdge); +// iter->xdc_ashy->GetBooTexture()->setClampMode(boo::TextureClampMode::ClampToEdge); return iter->xdc_ashy.GetObj(); } return nullptr; diff --git a/Runtime/World/CDamageVulnerability.cpp b/Runtime/World/CDamageVulnerability.cpp index dcf5ffe48..857012117 100644 --- a/Runtime/World/CDamageVulnerability.cpp +++ b/Runtime/World/CDamageVulnerability.cpp @@ -83,12 +83,7 @@ CDamageVulnerability::CDamageVulnerability(CInputStream& in) { x0_normal[i] = EVulnerability(in.readUint32Big()); } - if (propCount == 15) { - x5c_deflected = EDeflectType::None; - } else { - x5c_deflected = EDeflectType(in.readUint32Big()); - } - + x5c_deflected = EDeflectType(in.readUint32Big()); x3c_charged[0] = x0_normal[0]; x4c_combo[0] = x0_normal[0]; x3c_charged[1] = x0_normal[1]; diff --git a/Runtime/World/CEnvFxManager.cpp b/Runtime/World/CEnvFxManager.cpp index 66bc6b9db..53a9e1dce 100644 --- a/Runtime/World/CEnvFxManager.cpp +++ b/Runtime/World/CEnvFxManager.cpp @@ -22,34 +22,33 @@ namespace metaforce { static rstl::reserved_vector g_SnowForces; CEnvFxManagerGrid::CEnvFxManagerGrid(const zeus::CVector2i& position, const zeus::CVector2i& extent, - std::vector initialParticles, int reserve, CEnvFxManager& parent, - boo::IGraphicsDataFactory::Context& ctx) + std::vector initialParticles, int reserve, CEnvFxManager& parent) : x4_position(position) , xc_extent(extent) , x1c_particles(std::move(initialParticles)) -, m_instBuf(parent.m_instPool.allocateBlock(CGraphics::g_BooFactory, reserve)) -, m_uniformBuf(parent.m_uniformPool.allocateBlock(CGraphics::g_BooFactory)) -, m_lineRenderer(ctx, CLineRenderer::EPrimitiveMode::Lines, reserve * 2, parent.x40_txtrEnvGradient->GetBooTexture(), +//, m_instBuf(parent.m_instPool.allocateBlock(CGraphics::g_BooFactory, reserve)) +//, m_uniformBuf(parent.m_uniformPool.allocateBlock(CGraphics::g_BooFactory)) +, m_lineRenderer(CLineRenderer::EPrimitiveMode::Lines, reserve * 2, parent.x40_txtrEnvGradient->GetTexture(), true, true) { x1c_particles.reserve(reserve); - CEnvFxShaders::BuildShaderDataBinding(ctx, parent, *this); + CEnvFxShaders::BuildShaderDataBinding(parent, *this); } CEnvFxManager::CEnvFxManager() { x40_txtrEnvGradient = g_SimplePool->GetObj("TXTR_EnvGradient"); - x40_txtrEnvGradient->GetBooTexture()->setClampMode(boo::TextureClampMode::ClampToEdge); +// x40_txtrEnvGradient->GetBooTexture()->setClampMode(boo::TextureClampMode::ClampToEdge); xb58_envRainSplash = g_SimplePool->GetObj("PART_EnvRainSplash"); xb74_txtrSnowFlake = g_SimplePool->GetObj("TXTR_SnowFlake"); xc48_underwaterFlake = g_SimplePool->GetObj("TXTR_UnderwaterFlake"); CRandom16 random(0); - CGraphics::CommitResources([this](boo::IGraphicsDataFactory::Context& ctx) { - m_fogUniformBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(CGraphics::g_Fog), 1); +// CGraphics::CommitResources([this](boo::IGraphicsDataFactory::Context& ctx) { +// m_fogUniformBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(CGraphics::g_Fog), 1); for (int i = 0; i < 8; ++i) for (int j = 0; j < 8; ++j) x50_grids.emplace_back(zeus::CVector2i{j * 2048, i * 2048}, zeus::CVector2i{2048, 2048}, - std::vector{}, 171, *this, ctx); - return true; - } BooTrace); + std::vector{}, 171, *this); +// return true; +// } BooTrace); for (int i = 0; i < 16; ++i) xb84_snowZDeltas.emplace_back(0.f, 0.f, random.Range(-2.f, -4.f)); } @@ -377,21 +376,21 @@ void CEnvFxManagerGrid::RenderSnowParticles(const zeus::CTransform& camXf) { const zeus::CVector3f xVec = 0.2f * camXf.basis[0]; const zeus::CVector3f zVec = 0.2f * camXf.basis[2]; const zeus::CMatrix4f mvp = CGraphics::GetPerspectiveProjectionMatrix(false) * CGraphics::g_GXModelView.toMatrix4f(); - auto* bufOut = m_instBuf.access(); - for (const auto& particle : x1c_particles) { - bufOut->positions[0] = particle.toVec3f(); - bufOut->uvs[0] = zeus::CVector2f(0.f, 0.f); - bufOut->positions[1] = bufOut->positions[0] + zVec; - bufOut->uvs[1] = zeus::CVector2f(0.f, 1.f); - bufOut->positions[3] = bufOut->positions[1] + xVec; - bufOut->uvs[3] = zeus::CVector2f(1.f, 1.f); - bufOut->positions[2] = bufOut->positions[3] - zVec; - bufOut->uvs[2] = zeus::CVector2f(1.f, 0.f); - bufOut->color = GetFlakeColor(mvp, *bufOut); - ++bufOut; - } - CGraphics::SetShaderDataBinding(m_snowBinding); - CGraphics::DrawInstances(0, 4, x1c_particles.size()); +// auto* bufOut = m_instBuf.access(); +// for (const auto& particle : x1c_particles) { +// bufOut->positions[0] = particle.toVec3f(); +// bufOut->uvs[0] = zeus::CVector2f(0.f, 0.f); +// bufOut->positions[1] = bufOut->positions[0] + zVec; +// bufOut->uvs[1] = zeus::CVector2f(0.f, 1.f); +// bufOut->positions[3] = bufOut->positions[1] + xVec; +// bufOut->uvs[3] = zeus::CVector2f(1.f, 1.f); +// bufOut->positions[2] = bufOut->positions[3] - zVec; +// bufOut->uvs[2] = zeus::CVector2f(1.f, 0.f); +// bufOut->color = GetFlakeColor(mvp, *bufOut); +// ++bufOut; +// } +// CGraphics::SetShaderDataBinding(m_snowBinding); +// CGraphics::DrawInstances(0, 4, x1c_particles.size()); } void CEnvFxManagerGrid::RenderRainParticles(const zeus::CTransform& camXf) { @@ -414,21 +413,21 @@ void CEnvFxManagerGrid::RenderUnderwaterParticles(const zeus::CTransform& camXf) const zeus::CVector3f xVec = 0.5f * camXf.basis[0]; const zeus::CVector3f zVec = 0.5f * camXf.basis[2]; const zeus::CMatrix4f mvp = CGraphics::GetPerspectiveProjectionMatrix(false) * CGraphics::g_GXModelView.toMatrix4f(); - auto* bufOut = m_instBuf.access(); - for (const auto& particle : x1c_particles) { - bufOut->positions[0] = particle.toVec3f(); - bufOut->uvs[0] = zeus::CVector2f(0.f, 0.f); - bufOut->positions[1] = bufOut->positions[0] + zVec; - bufOut->uvs[1] = zeus::CVector2f(0.f, 1.f); - bufOut->positions[3] = bufOut->positions[1] + xVec; - bufOut->uvs[3] = zeus::CVector2f(1.f, 1.f); - bufOut->positions[2] = bufOut->positions[3] - zVec; - bufOut->uvs[2] = zeus::CVector2f(1.f, 0.f); - bufOut->color = GetFlakeColor(mvp, *bufOut); - ++bufOut; - } - CGraphics::SetShaderDataBinding(m_underwaterBinding); - CGraphics::DrawInstances(0, 4, x1c_particles.size()); +// auto* bufOut = m_instBuf.access(); +// for (const auto& particle : x1c_particles) { +// bufOut->positions[0] = particle.toVec3f(); +// bufOut->uvs[0] = zeus::CVector2f(0.f, 0.f); +// bufOut->positions[1] = bufOut->positions[0] + zVec; +// bufOut->uvs[1] = zeus::CVector2f(0.f, 1.f); +// bufOut->positions[3] = bufOut->positions[1] + xVec; +// bufOut->uvs[3] = zeus::CVector2f(1.f, 1.f); +// bufOut->positions[2] = bufOut->positions[3] - zVec; +// bufOut->uvs[2] = zeus::CVector2f(1.f, 0.f); +// bufOut->color = GetFlakeColor(mvp, *bufOut); +// ++bufOut; +// } +// CGraphics::SetShaderDataBinding(m_underwaterBinding); +// CGraphics::DrawInstances(0, 4, x1c_particles.size()); } void CEnvFxManagerGrid::Render(const zeus::CTransform& xf, const zeus::CTransform& invXf, const zeus::CTransform& camXf, @@ -450,7 +449,7 @@ void CEnvFxManagerGrid::Render(const zeus::CTransform& xf, const zeus::CTransfor default: break; } - m_uniformBuf.access() = parent.m_uniformData; +// m_uniformBuf.access() = parent.m_uniformData; switch (fxType) { case EEnvFxType::Snow: RenderSnowParticles(camXf); @@ -559,13 +558,13 @@ void CEnvFxManager::Render(const CStateManager& mgr) { default: break; } - m_fogUniformBuf->load(&CGraphics::g_Fog, sizeof(CGraphics::g_Fog)); +// m_fogUniformBuf->load(&CGraphics::g_Fog, sizeof(CGraphics::g_Fog)); for (auto& grid : x50_grids) grid.Render(xf, invXf, camXf, x30_fxDensity, fxType, *this); // Backface cull - m_uniformPool.updateBuffers(); - m_instPool.updateBuffers(); +// m_uniformPool.updateBuffers(); +// m_instPool.updateBuffers(); } } } diff --git a/Runtime/World/CEnvFxManager.hpp b/Runtime/World/CEnvFxManager.hpp index 05f50d2f7..5f15e4a60 100644 --- a/Runtime/World/CEnvFxManager.hpp +++ b/Runtime/World/CEnvFxManager.hpp @@ -11,9 +11,6 @@ #include "Runtime/Graphics/CLineRenderer.hpp" #include "Runtime/Graphics/Shaders/CEnvFxShaders.hpp" -#include -#include - #include #include #include @@ -61,12 +58,12 @@ class CEnvFxManagerGrid { std::pair x14_block = {false, FLT_MAX}; /* Blocked-bool, Z-coordinate */ std::vector x1c_particles; - hecl::VertexBufferPool::Token m_instBuf; - hecl::UniformBufferPool::Token m_uniformBuf; +// hecl::VertexBufferPool::Token m_instBuf; +// hecl::UniformBufferPool::Token m_uniformBuf; CLineRenderer m_lineRenderer; - - boo::ObjToken m_snowBinding; - boo::ObjToken m_underwaterBinding; +// +// boo::ObjToken m_snowBinding; +// boo::ObjToken m_underwaterBinding; float m_uvyOffset = 0.f; @@ -76,8 +73,7 @@ class CEnvFxManagerGrid { public: CEnvFxManagerGrid(const zeus::CVector2i& position, const zeus::CVector2i& extent, - std::vector initialParticles, int reserve, CEnvFxManager& parent, - boo::IGraphicsDataFactory::Context& ctx); + std::vector initialParticles, int reserve, CEnvFxManager& parent); void Render(const zeus::CTransform& xf, const zeus::CTransform& invXf, const zeus::CTransform& camXf, float fxDensity, EEnvFxType fxType, CEnvFxManager& parent); }; @@ -86,10 +82,10 @@ class CEnvFxManager { friend class CEnvFxManagerGrid; friend class CEnvFxShaders; - hecl::VertexBufferPool m_instPool; - hecl::UniformBufferPool m_uniformPool; +// hecl::VertexBufferPool m_instPool; +// hecl::UniformBufferPool m_uniformPool; CEnvFxShaders::Uniform m_uniformData; - boo::ObjToken m_fogUniformBuf; +// boo::ObjToken m_fogUniformBuf; zeus::CAABox x0_particleBounds = zeus::CAABox(-63.5f, 63.5f); zeus::CVector3f x18_focusCellPosition = zeus::skZero3f; diff --git a/Runtime/World/CFluidPlane.cpp b/Runtime/World/CFluidPlane.cpp index 1cc5ad4ad..37a7eff8f 100644 --- a/Runtime/World/CFluidPlane.cpp +++ b/Runtime/World/CFluidPlane.cpp @@ -154,7 +154,7 @@ void CFluidPlane::RenderStripWithRipples(float curY, const Heights& heights, con func(curTileX, curTileY + info.x18_rippleResolution, heights[curYDiv + 1][i + v]); curTileX += info.x18_rippleResolution; } - CGraphics::DrawArray(start, vOut.size() - start); +// CGraphics::DrawArray(start, vOut.size() - start); } } else { bool r19 = (flags[yTile + 1][xTile] & 0x2) != 0; // North @@ -219,7 +219,7 @@ void CFluidPlane::RenderStripWithRipples(float curY, const Heights& heights, con default: break; } - CGraphics::DrawArray(start, vOut.size() - start); +// CGraphics::DrawArray(start, vOut.size() - start); } else { TriFanToStrip toStrip(vOut); std::function func; @@ -303,7 +303,7 @@ void CFluidPlane::RenderStripWithRipples(float curY, const Heights& heights, con } } - toStrip.Draw(); +// toStrip.Draw(); } } } @@ -328,7 +328,7 @@ void CFluidPlane::RenderPatch(const CFluidPlaneRender::SPatchInfo& info, const H vOut.emplace_back(zeus::CVector3f(xMin, yMax, 0.f)); vOut.emplace_back(zeus::CVector3f(xMax, yMin, 0.f)); vOut.emplace_back(zeus::CVector3f(xMax, yMax, 0.f)); - CGraphics::DrawArray(start, 4); +// CGraphics::DrawArray(start, 4); break; } case CFluidPlaneRender::NormalMode::NoNormals: { @@ -337,7 +337,7 @@ void CFluidPlane::RenderPatch(const CFluidPlaneRender::SPatchInfo& info, const H vOut.emplace_back(zeus::CVector3f(xMin, yMax, 0.f), zeus::skBlack); vOut.emplace_back(zeus::CVector3f(xMax, yMin, 0.f), zeus::skBlack); vOut.emplace_back(zeus::CVector3f(xMax, yMax, 0.f), zeus::skBlack); - CGraphics::DrawArray(start, 4); +// CGraphics::DrawArray(start, 4); break; } case CFluidPlaneRender::NormalMode::Normals: { @@ -384,7 +384,7 @@ void CFluidPlane::RenderPatch(const CFluidPlaneRender::SPatchInfo& info, const H toStrip.EmplaceVert(zeus::CVector3f(xMax, yMax + info.x14_tileSize, 0.f), zeus::skUp, zeus::skBlack); - toStrip.Draw(); +// toStrip.Draw(); nextXTile = curXTile + 1; xMax += info.x14_tileSize; @@ -399,7 +399,7 @@ void CFluidPlane::RenderPatch(const CFluidPlaneRender::SPatchInfo& info, const H vOut.emplace_back(zeus::CVector3f(xMax, yMax + info.x14_tileSize, 0.f), zeus::skUp, zeus::skBlack); xMax += info.x14_tileSize; } - CGraphics::DrawArray(start, vOut.size() - start); +// CGraphics::DrawArray(start, vOut.size() - start); ++nextXTile; if (nextXTile == xTiles) { @@ -426,7 +426,7 @@ void CFluidPlane::RenderPatch(const CFluidPlaneRender::SPatchInfo& info, const H vOut.emplace_back(zeus::CVector3f(xMin, yMax, 0.f), zeus::skUp, zeus::skForward, zeus::skRight, zeus::skBlack); vOut.emplace_back(zeus::CVector3f(xMax, yMin, 0.f), zeus::skUp, zeus::skForward, zeus::skRight, zeus::skBlack); vOut.emplace_back(zeus::CVector3f(xMax, yMax, 0.f), zeus::skUp, zeus::skForward, zeus::skRight, zeus::skBlack); - CGraphics::DrawArray(start, 4); +// CGraphics::DrawArray(start, 4); } else { int xTiles = (info.x0_xSubdivs - 3) / CFluidPlaneRender::numSubdivisionsInTile + 1; int yTiles = (info.x1_ySubdivs - 3) / CFluidPlaneRender::numSubdivisionsInTile + 1; @@ -451,7 +451,7 @@ void CFluidPlane::RenderPatch(const CFluidPlaneRender::SPatchInfo& info, const H zeus::skRight, zeus::skBlack); xMax += info.x14_tileSize; } - CGraphics::DrawArray(start, vOut.size() - start); +// CGraphics::DrawArray(start, vOut.size() - start); } else { nextXTile = curXTile + 1; xMax += info.x14_tileSize; diff --git a/Runtime/World/CFluidPlaneCPU.cpp b/Runtime/World/CFluidPlaneCPU.cpp index 3c48d0e4e..474e1bfe8 100644 --- a/Runtime/World/CFluidPlaneCPU.cpp +++ b/Runtime/World/CFluidPlaneCPU.cpp @@ -271,7 +271,7 @@ CFluidPlaneShader::RenderSetupInfo CFluidPlaneCPU::RenderSetup(const CStateManag m_cachedAdditive = mgr.GetThermalDrawFlag() == EThermalDrawFlag::Hot; m_shader.emplace(x44_fluidType, x10_texPattern1, x20_texPattern2, x30_texColor, xb0_bumpMap, xc0_envMap, xd0_envBumpMap, xe0_lightmap, - m_tessellation ? CFluidPlaneManager::RippleMapTex : boo::ObjToken{}, + m_tessellation ? CFluidPlaneManager::RippleMapTex : std::shared_ptr{}, m_cachedDoubleLightmapBlend, m_cachedAdditive, m_maxVertCount); } diff --git a/Runtime/World/CFluidPlaneGPU.cpp b/Runtime/World/CFluidPlaneGPU.cpp index 5d53aa0c1..4991eb794 100644 --- a/Runtime/World/CFluidPlaneGPU.cpp +++ b/Runtime/World/CFluidPlaneGPU.cpp @@ -74,8 +74,8 @@ void CFluidPlaneGPU::RenderStripWithRipples(float curY, const Heights& heights, curTileX += info.x14_tileSize; } - CGraphics::DrawArray(start, pvOut.size() - start); +// CGraphics::DrawArray(start, pvOut.size() - start); } } -} // namespace metaforce \ No newline at end of file +} // namespace metaforce diff --git a/Runtime/World/CFluidPlaneManager.cpp b/Runtime/World/CFluidPlaneManager.cpp index 3ffbaa8e8..bfd6b4d4b 100644 --- a/Runtime/World/CFluidPlaneManager.cpp +++ b/Runtime/World/CFluidPlaneManager.cpp @@ -81,7 +81,7 @@ static bool g_RippleMapSetup = false; std::array, 64> CFluidPlaneManager::RippleValues{}; std::array CFluidPlaneManager::RippleMins{}; std::array CFluidPlaneManager::RippleMaxs{}; -boo::ObjToken CFluidPlaneManager::RippleMapTex; +std::shared_ptr CFluidPlaneManager::RippleMapTex; void CFluidPlaneManager::SetupRippleMap() { if (g_RippleMapSetup) { @@ -135,11 +135,9 @@ void CFluidPlaneManager::SetupRippleMap() { curX += (1.f / 63.f); } - CGraphics::CommitResources([](boo::IGraphicsDataFactory::Context& ctx) { - RippleMapTex = ctx.newStaticTexture(64, 64, 1, boo::TextureFormat::I8, boo::TextureClampMode::ClampToBlack, - RippleValues.data(), 64 * 64); - return true; - } BooTrace); + RippleMapTex = + aurora::new_static_texture_2d(64, 64, 1, aurora::shaders::TextureFormat::R8, + {reinterpret_cast(RippleValues.data()), 64 * 64}, "Ripple Map"); } } // namespace metaforce diff --git a/Runtime/World/CFluidPlaneManager.hpp b/Runtime/World/CFluidPlaneManager.hpp index 903cb4675..a550ee5e6 100644 --- a/Runtime/World/CFluidPlaneManager.hpp +++ b/Runtime/World/CFluidPlaneManager.hpp @@ -1,11 +1,10 @@ #pragma once +#include "Runtime/Graphics/CGraphics.hpp" #include "Runtime/RetroTypes.hpp" #include "Runtime/rstl.hpp" #include "Runtime/World/CRippleManager.hpp" -#include - namespace metaforce { class CStateManager; @@ -47,7 +46,7 @@ public: static std::array, 64> RippleValues; static std::array RippleMins; static std::array RippleMaxs; - static boo::ObjToken RippleMapTex; + static std::shared_ptr RippleMapTex; CFluidPlaneManager(); void StartFrame(bool); diff --git a/Runtime/World/CGameArea.cpp b/Runtime/World/CGameArea.cpp index cbb18985a..b3ebbf0c4 100644 --- a/Runtime/World/CGameArea.cpp +++ b/Runtime/World/CGameArea.cpp @@ -406,7 +406,7 @@ CGameArea::CGameArea(CAssetId mreaId) : x84_mrea(mreaId), xf0_25_active{false} { FillInStaticGeometry(false); CBooModel::SetDummyTextures(true); - CBooModel::EnableShadowMaps(g_Renderer->x220_sphereRamp.get(), zeus::CTransform()); + CBooModel::EnableShadowMaps(g_Renderer->x220_sphereRamp, zeus::CTransform()); CGraphics::CProjectionState backupProj = CGraphics::GetProjectionState(); zeus::CTransform backupViewPoint = CGraphics::g_ViewMatrix; zeus::CTransform backupModel = CGraphics::g_GXModelMatrix; @@ -415,7 +415,7 @@ CGameArea::CGameArea(CAssetId mreaId) : x84_mrea(mreaId), xf0_25_active{false} { CModelFlags defaultFlags; for (CMetroidModelInstance& inst : x12c_postConstructed->x4c_insts) { CGraphics::SetModelMatrix(zeus::CTransform::Translate(-inst.x34_aabb.center())); - inst.m_instance->UpdateUniformData(defaultFlags, nullptr, nullptr); +// inst.m_instance->UpdateUniformData(defaultFlags, nullptr, nullptr); inst.m_instance->WarmupDrawSurfaces(); } CGraphics::SetProjectionState(backupProj); @@ -1048,67 +1048,63 @@ void CGameArea::FillInStaticGeometry(bool textures) { matSet.m_matSet.read(r); if (textures) CBooModel::MakeTexturesFromMats(matSet.m_matSet, matSet.x0_textures, *g_SimplePool); - matSet.InitializeLayout(nullptr); +// matSet.InitializeLayout(nullptr); ++secIt; } - CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) { - /* Reserve extra buffers for 16 cubemaps and shadow rendering */ - matSet.m_geomLayout->ReserveSharedBuffers(ctx, 96 + int(EWorldShadowMode::MAX)); + /* Reserve extra buffers for 16 cubemaps and shadow rendering */ +// matSet.m_geomLayout->ReserveSharedBuffers(ctx, 96 + int(EWorldShadowMode::MAX)); - /* Models */ - for (CMetroidModelInstance& inst : x12c_postConstructed->x4c_insts) { - { - DataSpec::DNAMP1::MREA::MeshHeader header; - athena::io::MemoryReader r(secIt->first, secIt->second); - header.read(r); - inst.x0_visorFlags = header.visorFlags.flags; - inst.x4_xf = header.xfMtx; - inst.x34_aabb = zeus::CAABox(header.aabb[0], header.aabb[1]); - ++secIt; - } - - { - athena::io::MemoryReader r(secIt->first, secIt->second); - inst.m_hmdlMeta.read(r); - } + /* Models */ + for (CMetroidModelInstance& inst : x12c_postConstructed->x4c_insts) { + { + DataSpec::DNAMP1::MREA::MeshHeader header; + athena::io::MemoryReader r(secIt->first, secIt->second); + header.read(r); + inst.x0_visorFlags = header.visorFlags.flags; + inst.x4_xf = header.xfMtx; + inst.x34_aabb = zeus::CAABox(header.aabb[0], header.aabb[1]); ++secIt; - - boo::ObjToken vbo; - boo::ObjToken ibo; - vbo = ctx.newStaticBuffer(boo::BufferUse::Vertex, secIt->first, inst.m_hmdlMeta.vertStride, - inst.m_hmdlMeta.vertCount); - ++secIt; - ibo = ctx.newStaticBuffer(boo::BufferUse::Index, secIt->first, 4, inst.m_hmdlMeta.indexCount); - ++secIt; - - const u32 surfCount = hecl::SBig(*reinterpret_cast(secIt->first)); - inst.m_surfaces.reserve(surfCount); - inst.m_shaders.reserve(surfCount); - ++secIt; - for (u32 j = 0; j < surfCount; ++j) { - CBooSurface& surf = inst.m_surfaces.emplace_back(); - surf.selfIdx = j; - athena::io::MemoryReader r(secIt->first, secIt->second); - surf.m_data.read(r); - ++secIt; - } - - TToken nullModel; - inst.m_instance = std::make_unique(nullModel, nullptr, &inst.m_surfaces, matSet, vbo, ibo, - inst.x34_aabb, static_cast(inst.x0_visorFlags), 0); } - return true; - } BooTrace); + { + athena::io::MemoryReader r(secIt->first, secIt->second); + inst.m_hmdlMeta.read(r); + } + ++secIt; + +// boo::ObjToken vbo; +// boo::ObjToken ibo; +// vbo = ctx.newStaticBuffer(boo::BufferUse::Vertex, secIt->first, inst.m_hmdlMeta.vertStride, +// inst.m_hmdlMeta.vertCount); + ++secIt; +// ibo = ctx.newStaticBuffer(boo::BufferUse::Index, secIt->first, 4, inst.m_hmdlMeta.indexCount); + ++secIt; + + const u32 surfCount = hecl::SBig(*reinterpret_cast(secIt->first)); + inst.m_surfaces.reserve(surfCount); +// inst.m_shaders.reserve(surfCount); + ++secIt; + for (u32 j = 0; j < surfCount; ++j) { + CBooSurface& surf = inst.m_surfaces.emplace_back(); + surf.selfIdx = j; + athena::io::MemoryReader r(secIt->first, secIt->second); + surf.m_data.read(r); + ++secIt; + } + + TToken nullModel; + inst.m_instance = std::make_unique(nullModel, nullptr, &inst.m_surfaces, matSet, //vbo, ibo, + inst.x34_aabb, static_cast(inst.x0_visorFlags)); + } for (CMetroidModelInstance& inst : x12c_postConstructed->x4c_insts) { for (CBooSurface& surf : inst.m_surfaces) { - auto& shad = inst.m_shaders[surf.m_data.matIdx]; - if (!shad) - shad = matSet.BuildShader(inst.m_hmdlMeta, matSet.m_matSet.materials[surf.m_data.matIdx]); +// auto& shad = inst.m_shaders[surf.m_data.matIdx]; +// if (!shad) +// shad = matSet.BuildShader(inst.m_hmdlMeta, matSet.m_matSet.materials[surf.m_data.matIdx]); } - inst.m_instance->RemapMaterialData(matSet, inst.m_shaders); + inst.m_instance->RemapMaterialData(matSet); } x12c_postConstructed->x1108_25_modelsConstructed = true; diff --git a/Runtime/World/CMorphBallShadow.cpp b/Runtime/World/CMorphBallShadow.cpp index 837cd9ebd..e50ed3fb6 100644 --- a/Runtime/World/CMorphBallShadow.cpp +++ b/Runtime/World/CMorphBallShadow.cpp @@ -36,7 +36,7 @@ void CMorphBallShadow::RenderIdBuffer(const zeus::CAABox& aabb, const CStateMana SViewport backupVp = g_Viewport; g_Renderer->BindBallShadowIdTarget(); - CGraphics::g_BooMainCommandQueue->clearTarget(); +// CGraphics::g_BooMainCommandQueue->clearTarget(); zeus::CTransform backupViewMtx = CGraphics::g_ViewMatrix; CGraphics::CProjectionState backupProjection = CGraphics::g_Proj; diff --git a/Runtime/World/CPlayer.cpp b/Runtime/World/CPlayer.cpp index a8cb1b36c..774347a07 100644 --- a/Runtime/World/CPlayer.cpp +++ b/Runtime/World/CPlayer.cpp @@ -187,7 +187,7 @@ constexpr std::arrayareShadersReady()) { - return EDoorOpenCondition::Loading; - } + // TODO +// if (!CGraphics::g_BooFactory->areShadersReady()) { +// return EDoorOpenCondition::Loading; +// } return EDoorOpenCondition::Ready; } diff --git a/Runtime/World/CScriptTrigger.cpp b/Runtime/World/CScriptTrigger.cpp index a1c9ce45e..5fe743afa 100644 --- a/Runtime/World/CScriptTrigger.cpp +++ b/Runtime/World/CScriptTrigger.cpp @@ -9,9 +9,8 @@ #include "TCastTo.hpp" // Generated file, do not modify include path namespace metaforce { -namespace { -logvisor::Module Log("CScriptTrigger"); -} +static logvisor::Module Log("CScriptTrigger"); + CScriptTrigger::CScriptTrigger(TUniqueId uid, std::string_view name, const CEntityInfo& info, const zeus::CVector3f& pos, const zeus::CAABox& bounds, const CDamageInfo& dInfo, const zeus::CVector3f& forceField, ETriggerFlags triggerFlags, bool active, diff --git a/Runtime/World/CScriptWater.cpp b/Runtime/World/CScriptWater.cpp index 7cfabff5b..dd6c368ad 100644 --- a/Runtime/World/CScriptWater.cpp +++ b/Runtime/World/CScriptWater.cpp @@ -70,21 +70,21 @@ CScriptWater::CScriptWater( x2cc_gridCellCount = (x2c4_gridDimX + 1) * (x2c8_gridDimY + 1); uint32_t maxPatchSize; - if (CGraphics::g_BooFactory->isTessellationSupported(maxPatchSize)) { - x1b4_fluidPlane = std::make_unique( - patternMap1, patternMap2, colorMap, bumpMap, envMap, envBumpMap, lightmapId, unitsPerLightmapTexel, tileSize, - tileSubdivisions * 2, fluidType, x2bc_alpha, bumpLightDir, bumpScale, uvMot, turbSpeed, turbDistance, - turbFreqMax, turbFreqMin, turbPhaseMax, turbPhaseMin, turbAmplitudeMax, turbAmplitudeMin, specularMin, - specularMax, reflectionBlend, reflectionSize, rippleIntensity, - x2cc_gridCellCount * ((std::max(u32(2), tileSubdivisions * 2) * 4 + 2) * 4)); - } else { +// if (CGraphics::g_BooFactory->isTessellationSupported(maxPatchSize)) { +// x1b4_fluidPlane = std::make_unique( +// patternMap1, patternMap2, colorMap, bumpMap, envMap, envBumpMap, lightmapId, unitsPerLightmapTexel, tileSize, +// tileSubdivisions * 2, fluidType, x2bc_alpha, bumpLightDir, bumpScale, uvMot, turbSpeed, turbDistance, +// turbFreqMax, turbFreqMin, turbPhaseMax, turbPhaseMin, turbAmplitudeMax, turbAmplitudeMin, specularMin, +// specularMax, reflectionBlend, reflectionSize, rippleIntensity, +// x2cc_gridCellCount * ((std::max(u32(2), tileSubdivisions * 2) * 4 + 2) * 4)); +// } else { x1b4_fluidPlane = std::make_unique( patternMap1, patternMap2, colorMap, bumpMap, envMap, envBumpMap, lightmapId, unitsPerLightmapTexel, tileSize, tileSubdivisions, fluidType, x2bc_alpha, bumpLightDir, bumpScale, uvMot, turbSpeed, turbDistance, turbFreqMax, turbFreqMin, turbPhaseMax, turbPhaseMin, turbAmplitudeMax, turbAmplitudeMin, specularMin, specularMax, reflectionBlend, reflectionSize, rippleIntensity, x2cc_gridCellCount * ((std::max(u32(2), tileSubdivisions) * 4 + 2) * 4)); - } +// } u32Arr.reset(); x264_splashEffects.resize(3); if (x22c_splashParticle1Id.IsValid()) { diff --git a/Runtime/World/CWorldShadow.cpp b/Runtime/World/CWorldShadow.cpp index 6d6660bf0..d497e8bac 100644 --- a/Runtime/World/CWorldShadow.cpp +++ b/Runtime/World/CWorldShadow.cpp @@ -15,7 +15,7 @@ void CWorldShadow::EnableModelProjectedShadow(const zeus::CTransform& pos, s32 l texTransform = posXf.inverse() * texTransform; texTransform = (texTransform * zeus::CTransform::Scale(float(M_SQRT2) * x64_objHalfExtent * f1)).inverse(); texTransform = zeus::CTransform::Translate(0.5f, 0.f, 0.5f) * texTransform; - CBooModel::EnableShadowMaps(m_shader.GetTexture().get(), texTransform); + CBooModel::EnableShadowMaps(m_shader.GetTexture(), texTransform); #if CWORLDSHADOW_FEEDBACK if (!m_feedback) diff --git a/Runtime/World/CWorldTransManager.cpp b/Runtime/World/CWorldTransManager.cpp index 0fc402dfe..da2557424 100644 --- a/Runtime/World/CWorldTransManager.cpp +++ b/Runtime/World/CWorldTransManager.cpp @@ -210,7 +210,7 @@ void CWorldTransManager::DrawAllModels(CActorLights* lights) { } void CWorldTransManager::DrawFirstPass(CActorLights* lights) { - CBooModel::SetReflectionCube(m_reflectionCube[0]); +// CBooModel::SetReflectionCube(m_reflectionCube[0]); zeus::CTransform translateXf = zeus::CTransform::Translate( x4_modelData->x1b4_shakeResult.x(), -3.5f * (1.f - zeus::clamp(0.f, x0_curTime / 10.f, 1.f)) - 3.5f, x4_modelData->x1b4_shakeResult.y() + 2.f); @@ -222,7 +222,7 @@ void CWorldTransManager::DrawFirstPass(CActorLights* lights) { } void CWorldTransManager::DrawSecondPass(CActorLights* lights) { - CBooModel::SetReflectionCube(m_reflectionCube[1]); +// CBooModel::SetReflectionCube(m_reflectionCube[1]); const zeus::CVector3f& samusScale = x4_modelData->x0_samusRes.GetScale(); zeus::CTransform translateXf = zeus::CTransform::Translate(-0.1f * samusScale.x(), -0.5f * samusScale.y(), 1.5f * samusScale.z()); @@ -237,44 +237,44 @@ void CWorldTransManager::DrawEnabled() { CActorLights lights(0, zeus::skZero3f, 4, 4, 0, 0, 0, 0.1f); lights.BuildFakeLightList(x4_modelData->x1a0_lights, zeus::CColor{0.1f, 0.1f, 0.1f, 1.0f}); - if (m_reflectionCube[0]) { - SViewport backupVp = g_Viewport; - constexpr float width = CUBEMAP_RES; - CGraphics::g_BooMainCommandQueue->setRenderTarget(m_reflectionCube[0], 0); - g_Renderer->SetViewport(0, 0, width, width); - g_Renderer->SetPerspective(90.f, width, width, 0.2f, 750.f); - - if (x0_curTime < x4_modelData->x1d4_dissolveEndTime) { - zeus::CTransform mainCamXf = - zeus::CTransform::RotateZ(zeus::degToRad(zeus::clamp(0.f, x0_curTime / 25.f, 100.f) * 360.f + 180.f - 90.f)); - for (int face = 0; face < 6; ++face) { - CGraphics::g_BooMainCommandQueue->setRenderTarget(m_reflectionCube[0], face); - CGraphics::g_BooMainCommandQueue->clearTarget(); - zeus::CTransform camXf = - zeus::CTransform(mainCamXf.basis * CGraphics::skCubeBasisMats[face], zeus::CVector3f(0.f, 0.f, 1.5f)); - g_Renderer->SetWorldViewpoint(camXf); - DrawPlatformModels(&lights); - } - CGraphics::g_BooMainCommandQueue->generateMipmaps(m_reflectionCube[0]); - } - if (x0_curTime > x4_modelData->x1d0_dissolveStartTime) { - zeus::CTransform mainCamXf = zeus::CTransform::RotateZ( - zeus::degToRad(48.f * zeus::clamp(0.f, (x0_curTime - x4_modelData->x1d0_dissolveStartTime + 2.f) / 5.f, 1.f) + - 180.f - 24.f)); - for (int face = 0; face < 6; ++face) { - CGraphics::g_BooMainCommandQueue->setRenderTarget(m_reflectionCube[1], face); - CGraphics::g_BooMainCommandQueue->clearTarget(); - zeus::CTransform camXf = - zeus::CTransform(mainCamXf.basis * CGraphics::skCubeBasisMats[face], zeus::CVector3f(0.f, 0.f, 1.5f)); - g_Renderer->SetWorldViewpoint(camXf); - DrawPlatformModels(&lights); - } - CGraphics::g_BooMainCommandQueue->generateMipmaps(m_reflectionCube[1]); - } - - CBooRenderer::BindMainDrawTarget(); - g_Renderer->SetViewport(backupVp.x0_left, backupVp.x4_top, backupVp.x8_width, backupVp.xc_height); - } +// if (m_reflectionCube[0]) { +// SViewport backupVp = g_Viewport; +// constexpr float width = CUBEMAP_RES; +// CGraphics::g_BooMainCommandQueue->setRenderTarget(m_reflectionCube[0], 0); +// g_Renderer->SetViewport(0, 0, width, width); +// g_Renderer->SetPerspective(90.f, width, width, 0.2f, 750.f); +// +// if (x0_curTime < x4_modelData->x1d4_dissolveEndTime) { +// zeus::CTransform mainCamXf = +// zeus::CTransform::RotateZ(zeus::degToRad(zeus::clamp(0.f, x0_curTime / 25.f, 100.f) * 360.f + 180.f - 90.f)); +// for (int face = 0; face < 6; ++face) { +// CGraphics::g_BooMainCommandQueue->setRenderTarget(m_reflectionCube[0], face); +// CGraphics::g_BooMainCommandQueue->clearTarget(); +// zeus::CTransform camXf = +// zeus::CTransform(mainCamXf.basis * CGraphics::skCubeBasisMats[face], zeus::CVector3f(0.f, 0.f, 1.5f)); +// g_Renderer->SetWorldViewpoint(camXf); +// DrawPlatformModels(&lights); +// } +// CGraphics::g_BooMainCommandQueue->generateMipmaps(m_reflectionCube[0]); +// } +// if (x0_curTime > x4_modelData->x1d0_dissolveStartTime) { +// zeus::CTransform mainCamXf = zeus::CTransform::RotateZ( +// zeus::degToRad(48.f * zeus::clamp(0.f, (x0_curTime - x4_modelData->x1d0_dissolveStartTime + 2.f) / 5.f, 1.f) + +// 180.f - 24.f)); +// for (int face = 0; face < 6; ++face) { +// CGraphics::g_BooMainCommandQueue->setRenderTarget(m_reflectionCube[1], face); +// CGraphics::g_BooMainCommandQueue->clearTarget(); +// zeus::CTransform camXf = +// zeus::CTransform(mainCamXf.basis * CGraphics::skCubeBasisMats[face], zeus::CVector3f(0.f, 0.f, 1.5f)); +// g_Renderer->SetWorldViewpoint(camXf); +// DrawPlatformModels(&lights); +// } +// CGraphics::g_BooMainCommandQueue->generateMipmaps(m_reflectionCube[1]); +// } +// +// CBooRenderer::BindMainDrawTarget(); +// g_Renderer->SetViewport(backupVp.x0_left, backupVp.x4_top, backupVp.x8_width, backupVp.xc_height); +// } float wsAspect = CWideScreenFilter::SetViewportToMatch(1.f); @@ -291,9 +291,9 @@ void CWorldTransManager::DrawEnabled() { DrawFirstPass(&lights); SClipScreenRect rect(g_Viewport); CGraphics::ResolveSpareTexture(rect); - CGraphics::g_BooMainCommandQueue->clearTarget(true, true); +// CGraphics::g_BooMainCommandQueue->clearTarget(true, true); DrawSecondPass(&lights); - m_dissolve.drawCropped(zeus::CColor{1.f, 1.f, 1.f, 1.f - t}, 1.f); +// m_dissolve.drawCropped(zeus::CColor{1.f, 1.f, 1.f, 1.f - t}, 1.f); } CWideScreenFilter::SetViewportToFull(); @@ -352,7 +352,7 @@ void CWorldTransManager::TouchModels() { if (x4_modelData->x68_beamModelData.IsNull() && x4_modelData->x14c_beamModel.IsLoaded() && x4_modelData->x14c_beamModel.GetObj()) { x4_modelData->x68_beamModelData = CModelData{ - CStaticRes(x4_modelData->x14c_beamModel.GetObjectTag()->id, x4_modelData->x0_samusRes.GetScale()), 2}; + CStaticRes(x4_modelData->x14c_beamModel.GetObjectTag()->id, x4_modelData->x0_samusRes.GetScale())}; // , 2 } if (x4_modelData->x1c_samusModelData.IsNull() && x4_modelData->x158_suitModel.IsLoaded() && @@ -360,7 +360,7 @@ void CWorldTransManager::TouchModels() { x4_modelData->x164_suitSkin.GetObj()) { CAnimRes animRes(x4_modelData->x0_samusRes.GetId(), GetSuitCharIdx(), x4_modelData->x0_samusRes.GetScale(), x4_modelData->x0_samusRes.GetDefaultAnim(), true); - x4_modelData->x1c_samusModelData = CModelData{animRes, 2}; + x4_modelData->x1c_samusModelData = CModelData{animRes}; // , 2 CAnimPlaybackParms aData(animRes.GetDefaultAnim(), -1, 1.f, true); x4_modelData->x1c_samusModelData.GetAnimationData()->SetAnimation(aData, false); @@ -390,12 +390,12 @@ void CWorldTransManager::EnableTransition(const CAnimRes& samusRes, CAssetId pla x30_type = ETransType::Enabled; x4_modelData = std::make_unique(samusRes); - if (!m_reflectionCube[0] && hecl::com_cubemaps->toBoolean()) - CGraphics::CommitResources([this](boo::IGraphicsDataFactory::Context& ctx) { - m_reflectionCube[0] = ctx.newCubeRenderTexture(CUBEMAP_RES, CUBEMAP_MIPS); - m_reflectionCube[1] = ctx.newCubeRenderTexture(CUBEMAP_RES, CUBEMAP_MIPS); - return true; - } BooTrace); +// if (!m_reflectionCube[0] && hecl::com_cubemaps->toBoolean()) +// CGraphics::CommitResources([this](boo::IGraphicsDataFactory::Context& ctx) { +// m_reflectionCube[0] = ctx.newCubeRenderTexture(CUBEMAP_RES, CUBEMAP_MIPS); +// m_reflectionCube[1] = ctx.newCubeRenderTexture(CUBEMAP_RES, CUBEMAP_MIPS); +// return true; +// } BooTrace); x8_textData.reset(); x20_random.SetSeed(99); @@ -410,7 +410,7 @@ void CWorldTransManager::EnableTransition(const CAnimRes& samusRes, CAssetId pla x4_modelData->x164_suitSkin = g_SimplePool->GetObj(SObjectTag{FOURCC('CSKR'), info.GetSkinRulesId()}); if (platRes.IsValid()) { - x4_modelData->xb4_platformModelData = CModelData{CStaticRes(platRes, platScale), 2}; + x4_modelData->xb4_platformModelData = CModelData{CStaticRes(platRes, platScale)}; // , 2 x4_modelData->xb4_platformModelData.Touch(CModelData::EWhichModel::Normal, 0); } diff --git a/Runtime/World/CWorldTransManager.hpp b/Runtime/World/CWorldTransManager.hpp index eb9d2c6e2..9a0816af5 100644 --- a/Runtime/World/CWorldTransManager.hpp +++ b/Runtime/World/CWorldTransManager.hpp @@ -77,11 +77,11 @@ private: bool x44_28_textDirty : 1 = false; CColoredQuadFilter m_fadeToBlack{EFilterType::Blend}; - CTexturedQuadFilter m_dissolve{EFilterType::Blend, CGraphics::g_SpareTexture.get()}; +// CTexturedQuadFilter m_dissolve{EFilterType::Blend, CGraphics::g_SpareTexture.get()}; CWideScreenFilter m_widescreen{EFilterType::Blend}; CCameraBlurFilter m_camblur; - std::array, 2> m_reflectionCube; +// std::array, 2> m_reflectionCube; static int GetSuitCharIdx(); void DrawFirstPass(CActorLights* lights); diff --git a/Shaders/shader_CFluidPlaneShader.hpp b/Shaders/shader_CFluidPlaneShader.hpp index e63ce0f7d..4ce19d61f 100644 --- a/Shaders/shader_CFluidPlaneShader.hpp +++ b/Shaders/shader_CFluidPlaneShader.hpp @@ -1,5 +1,5 @@ #pragma once -#include "hecl/PipelineBase.hpp" +//#include "hecl/PipelineBase.hpp" #include "athena/Global.hpp" #include "hecl/hecl.hpp" @@ -47,66 +47,66 @@ struct SFluidPlaneDoorShaderInfo { : m_hasPatternTex1(hasPatternTex1), m_hasPatternTex2(hasPatternTex2), m_hasColorTex(hasColorTex) {} }; -class Shader_CFluidPlaneShader : public hecl::TessellationShader { - friend class Shader_CFluidPlaneDoorShader; - static const boo::VertexElementDescriptor VtxFmtElems[5]; - static const boo::VertexElementDescriptor TessVtxFmtElems[3]; - const SFluidPlaneShaderInfo& m_info; +//class Shader_CFluidPlaneShader : public hecl::TessellationShader { +// friend class Shader_CFluidPlaneDoorShader; +// static const boo::VertexElementDescriptor VtxFmtElems[5]; +// static const boo::VertexElementDescriptor TessVtxFmtElems[3]; +// const SFluidPlaneShaderInfo& m_info; +// +//public: +// Shader_CFluidPlaneShader(const SFluidPlaneShaderInfo& in, bool tessellation) +// : m_info(in) +// , VtxFmt(tessellation ? boo::VertexFormatInfo(TessVtxFmtElems) : boo::VertexFormatInfo(VtxFmtElems)) +// , PipelineInfo({in.m_additive ? boo::BlendFactor::One : boo::BlendFactor::SrcAlpha, +// in.m_additive ? boo::BlendFactor::One : boo::BlendFactor::InvSrcAlpha, boo::Primitive::TriStrips, +// boo::ZTest::LEqual, false, true, false, boo::CullMode::None, tessellation ? 1u : 0u}) +// , HasTessellation(tessellation) {} +// +// const boo::VertexFormatInfo VtxFmt; +// const boo::AdditionalPipelineInfo PipelineInfo; +// bool HasTessellation; +// static constexpr bool HasHash = false; +// static constexpr bool HasStageHash = false; +// const SFluidPlaneShaderInfo& info() const { return m_info; } +//}; +// +//template +//class StageObject_CFluidPlaneShader : public hecl::StageBinary { +// static std::string BuildShader(const SFluidPlaneShaderInfo& in, bool tessellation); +// +//public: +// StageObject_CFluidPlaneShader(hecl::StageConverter& conv, hecl::FactoryCtx& ctx, +// const Shader_CFluidPlaneShader& in) +// : hecl::StageBinary(conv, ctx, hecl::StageSourceText(BuildShader(in.info(), in.HasTessellation))) {} +//}; +// +//class Shader_CFluidPlaneDoorShader : public hecl::GeneralShader { +// const SFluidPlaneDoorShaderInfo& m_info; +// +//public: +// explicit Shader_CFluidPlaneDoorShader(const SFluidPlaneDoorShaderInfo& in) +// : m_info(in) +// , VtxFmt(boo::VertexFormatInfo(Shader_CFluidPlaneShader::VtxFmtElems)) +// , PipelineInfo({boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, boo::Primitive::TriStrips, +// boo::ZTest::LEqual, false, true, false, boo::CullMode::None}) {} +// +// const boo::VertexFormatInfo VtxFmt; +// const boo::AdditionalPipelineInfo PipelineInfo; +// static constexpr bool HasHash = false; +// static constexpr bool HasStageHash = false; +// const SFluidPlaneDoorShaderInfo& info() const { return m_info; } +//}; -public: - Shader_CFluidPlaneShader(const SFluidPlaneShaderInfo& in, bool tessellation) - : m_info(in) - , VtxFmt(tessellation ? boo::VertexFormatInfo(TessVtxFmtElems) : boo::VertexFormatInfo(VtxFmtElems)) - , PipelineInfo({in.m_additive ? boo::BlendFactor::One : boo::BlendFactor::SrcAlpha, - in.m_additive ? boo::BlendFactor::One : boo::BlendFactor::InvSrcAlpha, boo::Primitive::TriStrips, - boo::ZTest::LEqual, false, true, false, boo::CullMode::None, tessellation ? 1u : 0u}) - , HasTessellation(tessellation) {} - - const boo::VertexFormatInfo VtxFmt; - const boo::AdditionalPipelineInfo PipelineInfo; - bool HasTessellation; - static constexpr bool HasHash = false; - static constexpr bool HasStageHash = false; - const SFluidPlaneShaderInfo& info() const { return m_info; } -}; - -template -class StageObject_CFluidPlaneShader : public hecl::StageBinary { - static std::string BuildShader(const SFluidPlaneShaderInfo& in, bool tessellation); - -public: - StageObject_CFluidPlaneShader(hecl::StageConverter& conv, hecl::FactoryCtx& ctx, - const Shader_CFluidPlaneShader& in) - : hecl::StageBinary(conv, ctx, hecl::StageSourceText(BuildShader(in.info(), in.HasTessellation))) {} -}; - -class Shader_CFluidPlaneDoorShader : public hecl::GeneralShader { - const SFluidPlaneDoorShaderInfo& m_info; - -public: - explicit Shader_CFluidPlaneDoorShader(const SFluidPlaneDoorShaderInfo& in) - : m_info(in) - , VtxFmt(boo::VertexFormatInfo(Shader_CFluidPlaneShader::VtxFmtElems)) - , PipelineInfo({boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, boo::Primitive::TriStrips, - boo::ZTest::LEqual, false, true, false, boo::CullMode::None}) {} - - const boo::VertexFormatInfo VtxFmt; - const boo::AdditionalPipelineInfo PipelineInfo; - static constexpr bool HasHash = false; - static constexpr bool HasStageHash = false; - const SFluidPlaneDoorShaderInfo& info() const { return m_info; } -}; - -template -class StageObject_CFluidPlaneDoorShader : public hecl::StageBinary { - static std::string BuildShader(const SFluidPlaneDoorShaderInfo& in); - -public: - StageObject_CFluidPlaneDoorShader(hecl::StageConverter& conv, hecl::FactoryCtx& ctx, - const Shader_CFluidPlaneDoorShader& in) - : hecl::StageBinary(conv, ctx, hecl::StageSourceText(BuildShader(in.info()))) {} -}; - -#define UNIVERSAL_PIPELINES_shader_CFluidPlaneShader ::Shader_CFluidPlaneShader ::Shader_CFluidPlaneDoorShader -#define STAGES_shader_CFluidPlaneShader(P, S) \ - ::StageObject_CFluidPlaneShader, ::StageObject_CFluidPlaneDoorShader, +//template +//class StageObject_CFluidPlaneDoorShader : public hecl::StageBinary { +// static std::string BuildShader(const SFluidPlaneDoorShaderInfo& in); +// +//public: +// StageObject_CFluidPlaneDoorShader(hecl::StageConverter& conv, hecl::FactoryCtx& ctx, +// const Shader_CFluidPlaneDoorShader& in) +// : hecl::StageBinary(conv, ctx, hecl::StageSourceText(BuildShader(in.info()))) {} +//}; +// +//#define UNIVERSAL_PIPELINES_shader_CFluidPlaneShader ::Shader_CFluidPlaneShader ::Shader_CFluidPlaneDoorShader +//#define STAGES_shader_CFluidPlaneShader(P, S) +// ::StageObject_CFluidPlaneShader, ::StageObject_CFluidPlaneDoorShader, diff --git a/extern/boo b/extern/boo index 49cfab476..9f8035dbd 160000 --- a/extern/boo +++ b/extern/boo @@ -1 +1 @@ -Subproject commit 49cfab476fa53aeedd783b28b644c90a9218f8ff +Subproject commit 9f8035dbd86193c2a3505637a2269ffc0abe25fa diff --git a/extern/imgui b/extern/imgui index 55d35d838..e3e1fbcf0 160000 --- a/extern/imgui +++ b/extern/imgui @@ -1 +1 @@ -Subproject commit 55d35d8387c15bf0cfd71861df67af8cfbda7456 +Subproject commit e3e1fbcf025cf83413815751f7c33500e1314d57 diff --git a/hecl/include/hecl/Backend.hpp b/hecl/include/hecl/Backend.hpp index 0b3a67631..aff7bae77 100644 --- a/hecl/include/hecl/Backend.hpp +++ b/hecl/include/hecl/Backend.hpp @@ -5,7 +5,7 @@ #include #include -#include +//#include #include #include "hecl.hpp" @@ -87,213 +87,213 @@ struct TextureInfo { enum class ReflectionType { None, Simple, Indirect }; -/** - * @brief Hash subclass for identifying shaders and their metadata - */ -class ShaderTag : public Hash { - union { - uint64_t m_meta = 0; - struct { - uint8_t m_colorCount; - uint8_t m_uvCount; - uint8_t m_weightCount; - uint8_t m_skinSlotCount; - uint8_t m_primitiveType; - uint8_t m_reflectionType; - bool m_depthTest : 1; - bool m_depthWrite : 1; - bool m_backfaceCulling : 1; - bool m_alphaTest : 1; - }; - }; - -public: - ShaderTag() = default; - ShaderTag(std::string_view source, uint8_t c, uint8_t u, uint8_t w, uint8_t s, boo::Primitive pt, - Backend::ReflectionType reflectionType, bool depthTest, bool depthWrite, bool backfaceCulling, - bool alphaTest) - : Hash(source) { - m_colorCount = c; - m_uvCount = u; - m_weightCount = w; - m_skinSlotCount = s; - m_primitiveType = uint8_t(pt); - m_reflectionType = uint8_t(reflectionType); - m_depthTest = depthTest; - m_depthWrite = depthWrite; - m_backfaceCulling = backfaceCulling; - m_alphaTest = alphaTest; - hash ^= m_meta; - } - ShaderTag(uint64_t hashin, uint8_t c, uint8_t u, uint8_t w, uint8_t s, boo::Primitive pt, - Backend::ReflectionType reflectionType, bool depthTest, bool depthWrite, bool backfaceCulling, - bool alphaTest) - : Hash(hashin) { - m_colorCount = c; - m_uvCount = u; - m_weightCount = w; - m_skinSlotCount = s; - m_primitiveType = uint8_t(pt); - m_reflectionType = uint8_t(reflectionType); - m_depthTest = depthTest; - m_depthWrite = depthWrite; - m_backfaceCulling = backfaceCulling; - m_alphaTest = alphaTest; - hash ^= m_meta; - } - ShaderTag(uint64_t comphashin, uint64_t meta) : Hash(comphashin), m_meta(meta) {} - ShaderTag(const ShaderTag& other) : Hash(other), m_meta(other.m_meta) {} - uint8_t getColorCount() const { return m_colorCount; } - uint8_t getUvCount() const { return m_uvCount; } - uint8_t getWeightCount() const { return m_weightCount; } - uint8_t getSkinSlotCount() const { return m_skinSlotCount; } - boo::Primitive getPrimType() const { return boo::Primitive(m_primitiveType); } - Backend::ReflectionType getReflectionType() const { return Backend::ReflectionType(m_reflectionType); } - bool getDepthTest() const { return m_depthTest; } - bool getDepthWrite() const { return m_depthWrite; } - bool getBackfaceCulling() const { return m_backfaceCulling; } - bool getAlphaTest() const { return m_alphaTest; } - uint64_t getMetaData() const { return m_meta; } - - std::vector vertexFormat() const { - std::vector ret; - size_t elemCount = 2 + m_colorCount + m_uvCount + m_weightCount; - ret.resize(elemCount); - - ret[0].semantic = boo::VertexSemantic::Position3; - ret[1].semantic = boo::VertexSemantic::Normal3; - size_t e = 2; - - for (size_t i = 0; i < m_colorCount; ++i, ++e) { - ret[e].semantic = boo::VertexSemantic::ColorUNorm; - ret[e].semanticIdx = i; - } - - for (size_t i = 0; i < m_uvCount; ++i, ++e) { - ret[e].semantic = boo::VertexSemantic::UV2; - ret[e].semanticIdx = i; - } - - for (size_t i = 0; i < m_weightCount; ++i, ++e) { - ret[e].semantic = boo::VertexSemantic::Weight; - ret[e].semanticIdx = i; - } - - return ret; - } - - boo::AdditionalPipelineInfo additionalInfo(const ExtensionSlot& ext, - std::pair blendFactors) const; -}; - -struct Function { - std::string_view m_source; - std::string_view m_entry; - Function() = default; - Function(std::string_view source, std::string_view entry) : m_source(source), m_entry(entry) {} -}; - -struct ExtensionSlot { - const char* shaderMacro = nullptr; - size_t texCount = 0; - const Backend::TextureInfo* texs = nullptr; - Backend::BlendFactor srcFactor = Backend::BlendFactor::Original; - Backend::BlendFactor dstFactor = Backend::BlendFactor::Original; - Backend::ZTest depthTest = Backend::ZTest::Original; - Backend::CullMode cullMode = Backend::CullMode::Backface; - bool noDepthWrite = false; - bool noColorWrite = false; - bool noAlphaWrite = false; - bool noAlphaOverwrite = false; - bool noReflection = false; - bool forceAlphaTest = false; - bool diffuseOnly = false; - - constexpr ExtensionSlot(size_t texCount = 0, const Backend::TextureInfo* texs = nullptr, - Backend::BlendFactor srcFactor = Backend::BlendFactor::Original, - Backend::BlendFactor dstFactor = Backend::BlendFactor::Original, - Backend::ZTest depthTest = Backend::ZTest::Original, - Backend::CullMode cullMode = Backend::CullMode::Backface, bool noDepthWrite = false, - bool noColorWrite = false, bool noAlphaWrite = false, bool noAlphaOverwrite = false, - bool noReflection = false, bool forceAlphaTest = false, bool diffuseOnly = false) noexcept - : texCount(texCount) - , texs(texs) - , srcFactor(srcFactor) - , dstFactor(dstFactor) - , depthTest(depthTest) - , cullMode(cullMode) - , noDepthWrite(noDepthWrite) - , noColorWrite(noColorWrite) - , noAlphaWrite(noAlphaWrite) - , noAlphaOverwrite(noAlphaOverwrite) - , noReflection(noReflection) - , forceAlphaTest(forceAlphaTest) - , diffuseOnly(diffuseOnly) {} - - mutable uint64_t m_hash = 0; - void calculateHash() const { - XXH64_state_t st; - XXH64_reset(&st, 0); - XXH64_update(&st, shaderMacro, strlen(shaderMacro)); - for (size_t i = 0; i < texCount; ++i) { - const Backend::TextureInfo& tinfo = texs[i]; - XXH64_update(&st, &tinfo, sizeof(tinfo)); - } - XXH64_update(&st, &srcFactor, offsetof(ExtensionSlot, m_hash) - offsetof(ExtensionSlot, srcFactor)); - m_hash = XXH64_digest(&st); - } - uint64_t hash() const { - if (m_hash == 0) - calculateHash(); - return m_hash; - } -}; - -inline boo::AdditionalPipelineInfo ShaderTag::additionalInfo(const ExtensionSlot& ext, - std::pair blendFactors) const { - boo::ZTest zTest; - switch (ext.depthTest) { - case hecl::Backend::ZTest::Original: - default: - zTest = getDepthTest() ? boo::ZTest::LEqual : boo::ZTest::None; - break; - case hecl::Backend::ZTest::None: - zTest = boo::ZTest::None; - break; - case hecl::Backend::ZTest::LEqual: - zTest = boo::ZTest::LEqual; - break; - case hecl::Backend::ZTest::Greater: - zTest = boo::ZTest::Greater; - break; - case hecl::Backend::ZTest::Equal: - zTest = boo::ZTest::Equal; - break; - case hecl::Backend::ZTest::GEqual: - zTest = boo::ZTest::GEqual; - break; - } - - BlendFactor srcFactor = m_alphaTest ? BlendFactor::One : blendFactors.first; - BlendFactor dstFactor = m_alphaTest ? BlendFactor::Zero : blendFactors.second; - return {boo::BlendFactor((ext.srcFactor == BlendFactor::Original) ? srcFactor : ext.srcFactor), - boo::BlendFactor((ext.dstFactor == BlendFactor::Original) ? dstFactor : ext.dstFactor), - getPrimType(), - zTest, - ext.noDepthWrite ? false : getDepthWrite(), - !ext.noColorWrite, - !ext.noAlphaWrite, - (ext.cullMode == hecl::Backend::CullMode::Original) - ? (getBackfaceCulling() ? boo::CullMode::Backface : boo::CullMode::None) - : boo::CullMode(ext.cullMode), - !ext.noAlphaOverwrite}; -} - +///** +// * @brief Hash subclass for identifying shaders and their metadata +// */ +//class ShaderTag : public Hash { +// union { +// uint64_t m_meta = 0; +// struct { +// uint8_t m_colorCount; +// uint8_t m_uvCount; +// uint8_t m_weightCount; +// uint8_t m_skinSlotCount; +// uint8_t m_primitiveType; +// uint8_t m_reflectionType; +// bool m_depthTest : 1; +// bool m_depthWrite : 1; +// bool m_backfaceCulling : 1; +// bool m_alphaTest : 1; +// }; +// }; +// +//public: +// ShaderTag() = default; +// ShaderTag(std::string_view source, uint8_t c, uint8_t u, uint8_t w, uint8_t s, boo::Primitive pt, +// Backend::ReflectionType reflectionType, bool depthTest, bool depthWrite, bool backfaceCulling, +// bool alphaTest) +// : Hash(source) { +// m_colorCount = c; +// m_uvCount = u; +// m_weightCount = w; +// m_skinSlotCount = s; +// m_primitiveType = uint8_t(pt); +// m_reflectionType = uint8_t(reflectionType); +// m_depthTest = depthTest; +// m_depthWrite = depthWrite; +// m_backfaceCulling = backfaceCulling; +// m_alphaTest = alphaTest; +// hash ^= m_meta; +// } +// ShaderTag(uint64_t hashin, uint8_t c, uint8_t u, uint8_t w, uint8_t s, boo::Primitive pt, +// Backend::ReflectionType reflectionType, bool depthTest, bool depthWrite, bool backfaceCulling, +// bool alphaTest) +// : Hash(hashin) { +// m_colorCount = c; +// m_uvCount = u; +// m_weightCount = w; +// m_skinSlotCount = s; +// m_primitiveType = uint8_t(pt); +// m_reflectionType = uint8_t(reflectionType); +// m_depthTest = depthTest; +// m_depthWrite = depthWrite; +// m_backfaceCulling = backfaceCulling; +// m_alphaTest = alphaTest; +// hash ^= m_meta; +// } +// ShaderTag(uint64_t comphashin, uint64_t meta) : Hash(comphashin), m_meta(meta) {} +// ShaderTag(const ShaderTag& other) : Hash(other), m_meta(other.m_meta) {} +// uint8_t getColorCount() const { return m_colorCount; } +// uint8_t getUvCount() const { return m_uvCount; } +// uint8_t getWeightCount() const { return m_weightCount; } +// uint8_t getSkinSlotCount() const { return m_skinSlotCount; } +// boo::Primitive getPrimType() const { return boo::Primitive(m_primitiveType); } +// Backend::ReflectionType getReflectionType() const { return Backend::ReflectionType(m_reflectionType); } +// bool getDepthTest() const { return m_depthTest; } +// bool getDepthWrite() const { return m_depthWrite; } +// bool getBackfaceCulling() const { return m_backfaceCulling; } +// bool getAlphaTest() const { return m_alphaTest; } +// uint64_t getMetaData() const { return m_meta; } +// +// std::vector vertexFormat() const { +// std::vector ret; +// size_t elemCount = 2 + m_colorCount + m_uvCount + m_weightCount; +// ret.resize(elemCount); +// +// ret[0].semantic = boo::VertexSemantic::Position3; +// ret[1].semantic = boo::VertexSemantic::Normal3; +// size_t e = 2; +// +// for (size_t i = 0; i < m_colorCount; ++i, ++e) { +// ret[e].semantic = boo::VertexSemantic::ColorUNorm; +// ret[e].semanticIdx = i; +// } +// +// for (size_t i = 0; i < m_uvCount; ++i, ++e) { +// ret[e].semantic = boo::VertexSemantic::UV2; +// ret[e].semanticIdx = i; +// } +// +// for (size_t i = 0; i < m_weightCount; ++i, ++e) { +// ret[e].semantic = boo::VertexSemantic::Weight; +// ret[e].semanticIdx = i; +// } +// +// return ret; +// } +// +// boo::AdditionalPipelineInfo additionalInfo(const ExtensionSlot& ext, +// std::pair blendFactors) const; +//}; +// +//struct Function { +// std::string_view m_source; +// std::string_view m_entry; +// Function() = default; +// Function(std::string_view source, std::string_view entry) : m_source(source), m_entry(entry) {} +//}; +// +//struct ExtensionSlot { +// const char* shaderMacro = nullptr; +// size_t texCount = 0; +// const Backend::TextureInfo* texs = nullptr; +// Backend::BlendFactor srcFactor = Backend::BlendFactor::Original; +// Backend::BlendFactor dstFactor = Backend::BlendFactor::Original; +// Backend::ZTest depthTest = Backend::ZTest::Original; +// Backend::CullMode cullMode = Backend::CullMode::Backface; +// bool noDepthWrite = false; +// bool noColorWrite = false; +// bool noAlphaWrite = false; +// bool noAlphaOverwrite = false; +// bool noReflection = false; +// bool forceAlphaTest = false; +// bool diffuseOnly = false; +// +// constexpr ExtensionSlot(size_t texCount = 0, const Backend::TextureInfo* texs = nullptr, +// Backend::BlendFactor srcFactor = Backend::BlendFactor::Original, +// Backend::BlendFactor dstFactor = Backend::BlendFactor::Original, +// Backend::ZTest depthTest = Backend::ZTest::Original, +// Backend::CullMode cullMode = Backend::CullMode::Backface, bool noDepthWrite = false, +// bool noColorWrite = false, bool noAlphaWrite = false, bool noAlphaOverwrite = false, +// bool noReflection = false, bool forceAlphaTest = false, bool diffuseOnly = false) noexcept +// : texCount(texCount) +// , texs(texs) +// , srcFactor(srcFactor) +// , dstFactor(dstFactor) +// , depthTest(depthTest) +// , cullMode(cullMode) +// , noDepthWrite(noDepthWrite) +// , noColorWrite(noColorWrite) +// , noAlphaWrite(noAlphaWrite) +// , noAlphaOverwrite(noAlphaOverwrite) +// , noReflection(noReflection) +// , forceAlphaTest(forceAlphaTest) +// , diffuseOnly(diffuseOnly) {} +// +// mutable uint64_t m_hash = 0; +// void calculateHash() const { +// XXH64_state_t st; +// XXH64_reset(&st, 0); +// XXH64_update(&st, shaderMacro, strlen(shaderMacro)); +// for (size_t i = 0; i < texCount; ++i) { +// const Backend::TextureInfo& tinfo = texs[i]; +// XXH64_update(&st, &tinfo, sizeof(tinfo)); +// } +// XXH64_update(&st, &srcFactor, offsetof(ExtensionSlot, m_hash) - offsetof(ExtensionSlot, srcFactor)); +// m_hash = XXH64_digest(&st); +// } +// uint64_t hash() const { +// if (m_hash == 0) +// calculateHash(); +// return m_hash; +// } +//}; +// +//inline boo::AdditionalPipelineInfo ShaderTag::additionalInfo(const ExtensionSlot& ext, +// std::pair blendFactors) const { +// boo::ZTest zTest; +// switch (ext.depthTest) { +// case hecl::Backend::ZTest::Original: +// default: +// zTest = getDepthTest() ? boo::ZTest::LEqual : boo::ZTest::None; +// break; +// case hecl::Backend::ZTest::None: +// zTest = boo::ZTest::None; +// break; +// case hecl::Backend::ZTest::LEqual: +// zTest = boo::ZTest::LEqual; +// break; +// case hecl::Backend::ZTest::Greater: +// zTest = boo::ZTest::Greater; +// break; +// case hecl::Backend::ZTest::Equal: +// zTest = boo::ZTest::Equal; +// break; +// case hecl::Backend::ZTest::GEqual: +// zTest = boo::ZTest::GEqual; +// break; +// } +// +// BlendFactor srcFactor = m_alphaTest ? BlendFactor::One : blendFactors.first; +// BlendFactor dstFactor = m_alphaTest ? BlendFactor::Zero : blendFactors.second; +// return {boo::BlendFactor((ext.srcFactor == BlendFactor::Original) ? srcFactor : ext.srcFactor), +// boo::BlendFactor((ext.dstFactor == BlendFactor::Original) ? dstFactor : ext.dstFactor), +// getPrimType(), +// zTest, +// ext.noDepthWrite ? false : getDepthWrite(), +// !ext.noColorWrite, +// !ext.noAlphaWrite, +// (ext.cullMode == hecl::Backend::CullMode::Original) +// ? (getBackfaceCulling() ? boo::CullMode::Backface : boo::CullMode::None) +// : boo::CullMode(ext.cullMode), +// !ext.noAlphaOverwrite}; +//} +// } // namespace hecl::Backend - -namespace std { -template <> -struct hash { - size_t operator()(const hecl::Backend::ShaderTag& val) const noexcept { return val.valSizeT(); } -}; -} // namespace std +// +//namespace std { +//template <> +//struct hash { +// size_t operator()(const hecl::Backend::ShaderTag& val) const noexcept { return val.valSizeT(); } +//}; +//} // namespace std diff --git a/hecl/include/hecl/CVarManager.hpp b/hecl/include/hecl/CVarManager.hpp index 1576ce327..cc72f68ed 100644 --- a/hecl/include/hecl/CVarManager.hpp +++ b/hecl/include/hecl/CVarManager.hpp @@ -98,10 +98,6 @@ public: void proc(); - void list(class Console* con, const std::vector& args); - void setCVar(class Console* con, const std::vector& args); - void getCVar(class Console* con, const std::vector& args); - void setDeveloperMode(bool v, bool setDeserialized = false); void setCheatsEnabled(bool v, bool setDeserialized = false); bool restartRequired() const; diff --git a/hecl/include/hecl/Compilers.hpp b/hecl/include/hecl/Compilers.hpp deleted file mode 100644 index 0bf8e1359..000000000 --- a/hecl/include/hecl/Compilers.hpp +++ /dev/null @@ -1,96 +0,0 @@ -#pragma once - -#include -#include -#include - -#include -#include -#include -#include -#include - -namespace hecl { - -namespace PlatformType { -using PlatformEnum = boo::IGraphicsDataFactory::Platform; -struct Null {}; -struct OpenGL { - static constexpr PlatformEnum Enum = PlatformEnum::OpenGL; - static constexpr char Name[] = "OpenGL"; -#if BOO_HAS_GL - using Context = boo::GLDataFactory::Context; -#endif -}; -struct D3D11 { - static constexpr PlatformEnum Enum = PlatformEnum::D3D11; - static constexpr char Name[] = "D3D11"; -#if _WIN32 - using Context = boo::D3D11DataFactory::Context; -#endif -}; -struct Metal { - static constexpr PlatformEnum Enum = PlatformEnum::Metal; - static constexpr char Name[] = "Metal"; -#if BOO_HAS_METAL - using Context = boo::MetalDataFactory::Context; -#endif -}; -struct Vulkan { - static constexpr PlatformEnum Enum = PlatformEnum::Vulkan; - static constexpr char Name[] = "Vulkan"; -#if BOO_HAS_VULKAN - using Context = boo::VulkanDataFactory::Context; -#endif -}; -struct NX { - static constexpr PlatformEnum Enum = PlatformEnum::NX; - static constexpr char Name[] = "NX"; -#if BOO_HAS_NX - using Context = boo::NXDataFactory::Context; -#endif -}; -} // namespace PlatformType - -namespace PipelineStage { -using StageEnum = boo::PipelineStage; -struct Null { - static constexpr StageEnum Enum = StageEnum::Null; - static constexpr char Name[] = "Null"; -}; -struct Vertex { - static constexpr StageEnum Enum = StageEnum::Vertex; - static constexpr char Name[] = "Vertex"; -}; -struct Fragment { - static constexpr StageEnum Enum = StageEnum::Fragment; - static constexpr char Name[] = "Fragment"; -}; -struct Geometry { - static constexpr StageEnum Enum = StageEnum::Geometry; - static constexpr char Name[] = "Geometry"; -}; -struct Control { - static constexpr StageEnum Enum = StageEnum::Control; - static constexpr char Name[] = "Control"; -}; -struct Evaluation { - static constexpr StageEnum Enum = StageEnum::Evaluation; - static constexpr char Name[] = "Evaluation"; -}; -} // namespace PipelineStage - -#ifdef _LIBCPP_VERSION -using StageBinaryData = std::shared_ptr; -inline StageBinaryData MakeStageBinaryData(size_t sz) { - return StageBinaryData(new uint8_t[sz], std::default_delete{}); -} -#else -using StageBinaryData = std::shared_ptr; -inline StageBinaryData MakeStageBinaryData(size_t sz) { return StageBinaryData(new uint8_t[sz]); } -#endif - -template -std::pair CompileShader(std::string_view text); - -} // namespace hecl diff --git a/hecl/include/hecl/Console.hpp b/hecl/include/hecl/Console.hpp deleted file mode 100644 index a5a6532a7..000000000 --- a/hecl/include/hecl/Console.hpp +++ /dev/null @@ -1,107 +0,0 @@ -#pragma once - -#include -#include -#include -#include - -#include -#include - -namespace boo { -class IWindow; - -enum class EModifierKey; -enum class ESpecialKey; - -struct IGraphicsCommandQueue; -} // namespace boo - -namespace hecl { -class CVarManager; -class CVar; -struct SConsoleCommand { - enum class ECommandFlags { Normal = 0, Cheat = (1 << 0), Developer = (1 << 1) }; - std::string m_displayName; - std::string m_helpString; - std::string m_usage; - std::function&)> m_func; - ECommandFlags m_flags; -}; -ENABLE_BITWISE_ENUM(SConsoleCommand::ECommandFlags) - -class Console { - friend class LogVisorAdapter; - struct LogVisorAdapter : logvisor::ILogger { - Console* m_con; - LogVisorAdapter(Console* con) : logvisor::ILogger(log_typeid(LogVisorAdapter)), m_con(con) {} - - ~LogVisorAdapter() override = default; - void report(const char* modName, logvisor::Level severity, fmt::string_view format, fmt::format_args args) override; - void reportSource(const char* modName, logvisor::Level severity, const char* file, unsigned linenum, - fmt::string_view format, fmt::format_args args) override; - }; - -public: - static Console* m_instance; - enum class Level { - Info, /**< Non-error informative message */ - Warning, /**< Non-error warning message */ - Error, /**< Recoverable error message */ - Fatal /**< Non-recoverable error message (Kept for compatibility with logvisor) */ - }; - - enum class State { Closed, Closing, Opened, Opening }; - -private: - CVarManager* m_cvarMgr = nullptr; - boo::IWindow* m_window = nullptr; - std::unordered_map m_commands; - std::vector> m_log; - int m_logOffset = 0; - std::string m_commandString; - std::vector m_commandHistory; - int m_cursorPosition = -1; - int m_currentCommand = -1; - size_t m_maxLines = 0; - bool m_overwrite : 1; - bool m_cursorAtEnd : 1; - State m_state = State::Closed; - CVar* m_conSpeed; - CVar* m_conHeight; - bool m_showCursor = true; - float m_cursorTime = 0.f; - -public: - Console(CVarManager*); - void registerCommand(std::string_view name, std::string_view helpText, std::string_view usage, - std::function&)>&& func, - SConsoleCommand::ECommandFlags cmdFlags = SConsoleCommand::ECommandFlags::Normal); - void unregisterCommand(std::string_view name); - - void executeString(const std::string& strToExec); - - void help(Console* con, const std::vector& args); - void listCommands(Console* con, const std::vector& args); - bool commandExists(std::string_view cmd) const; - - void vreport(Level level, fmt::string_view format, fmt::format_args args); - template > - void report(Level level, const S& format, Args&&... args) { - vreport(level, fmt::to_string_view(format), - fmt::basic_format_args>( - fmt::make_args_checked(format, args...))); - } - - void init(boo::IWindow* ctx); - void proc(); - void draw(boo::IGraphicsCommandQueue* gfxQ); - void handleCharCode(unsigned long chr, boo::EModifierKey mod, bool repeat); - void handleSpecialKeyDown(boo::ESpecialKey sp, boo::EModifierKey mod, bool repeat); - void handleSpecialKeyUp(boo::ESpecialKey sp, boo::EModifierKey mod); - void dumpLog(); - static Console* instance(); - static void RegisterLogger(Console* con); - bool isOpen() const { return m_state == State::Opened; } -}; -} // namespace hecl diff --git a/hecl/include/hecl/Pipeline.hpp b/hecl/include/hecl/Pipeline.hpp deleted file mode 100644 index 4b61b37e8..000000000 --- a/hecl/include/hecl/Pipeline.hpp +++ /dev/null @@ -1,506 +0,0 @@ -#pragma once - -#include -#include -#include -#include -#include - -#include "hecl/hecl.hpp" -#include "hecl/PipelineBase.hpp" - -#include -#include - -/* CMake-curated rep classes for the application */ -#include "ApplicationReps.hpp" - -namespace hecl { - -#if HECL_RUNTIME -template -class StageRuntimeObject : public StageRep { - boo::ObjToken m_stage; - -public: - static constexpr StageTargetType TargetType = StageTargetType::Runtime; - static constexpr PipelineTargetType PipelineTarget = PipelineTargetType::StageRuntimeCollection; - static constexpr bool HasHash = false; - StageRuntimeObject() = default; - StageRuntimeObject(StageConverter& conv, FactoryCtx& ctx, const StageBinary& in) { - m_stage = static_cast(ctx).newShaderStage(in.data(), in.size(), S::Enum); - } - boo::ObjToken stage() const { return m_stage; } -}; - -template -class FinalPipeline : public PipelineRep

{ - boo::ObjToken m_pipeline; - -public: - static constexpr PipelineTargetType TargetType = PipelineTargetType::FinalPipeline; - static constexpr bool HasHash = false; - FinalPipeline(PipelineConverter

& conv, FactoryCtx& ctx, - const StageCollection>& in) { - m_pipeline = static_cast(ctx).newShaderPipeline( - in.m_vertex.stage(), in.m_fragment.stage(), in.m_geometry.stage(), in.m_control.stage(), - in.m_evaluation.stage(), in.m_vtxFmt, in.m_additionalInfo); - } - boo::ObjToken pipeline() const { return m_pipeline; } -}; -#endif - -template -struct pack {}; -struct null_t {}; -template -struct ShaderDB {}; - -#define STAGE_COLLECTION_SPECIALIZATIONS(T, P) StageCollection>, -#define PIPELINE_RUNTIME_SPECIALIZATIONS(P) \ - STAGE_COLLECTION_SPECIALIZATIONS(StageSourceText, P) STAGE_COLLECTION_SPECIALIZATIONS(StageBinary, P) \ - STAGE_COLLECTION_SPECIALIZATIONS(StageRuntimeObject, P) FinalPipeline

, -#define PIPELINE_OFFLINE_SPECIALIZATIONS(P) STAGE_COLLECTION_SPECIALIZATIONS(StageSourceText, P) -#define STAGE_RUNTIME_SPECIALIZATIONS(P, S) \ - StageBinary, HECL_APPLICATION_STAGE_REPS(P, S) StageRuntimeObject, -#define STAGE_OFFLINE_SPECIALIZATIONS(P, S) HECL_APPLICATION_STAGE_REPS(P, S) - -#define SPECIALIZE_RUNTIME_AVAILABLE_STAGE(P, S) \ - template <> \ - struct ShaderDB

::StageDB { \ - using StageTypes = pack; \ - }; -#define SPECIALIZE_RUNTIME_UNAVAILABLE_STAGE(P, S) \ - template <> \ - struct ShaderDB

::StageDB { \ - using StageTypes = pack; \ - }; -#define SPECIALIZE_OFFLINE_STAGE(P, S) \ - template <> \ - struct ShaderDB

::StageDB { \ - using StageTypes = pack; \ - }; -#define SPECIALIZE_RUNTIME_AVAILABLE_PLATFORM(P) \ - template <> \ - struct ShaderDB

{ \ - using PipelineTypes = pack; \ - template \ - struct StageDB {}; \ - }; \ - SPECIALIZE_RUNTIME_AVAILABLE_STAGE(P, hecl::PipelineStage::Vertex) \ - SPECIALIZE_RUNTIME_AVAILABLE_STAGE(P, hecl::PipelineStage::Fragment) \ - SPECIALIZE_RUNTIME_AVAILABLE_STAGE(P, hecl::PipelineStage::Geometry) \ - SPECIALIZE_RUNTIME_AVAILABLE_STAGE(P, hecl::PipelineStage::Control) \ - SPECIALIZE_RUNTIME_AVAILABLE_STAGE(P, hecl::PipelineStage::Evaluation) -#define SPECIALIZE_RUNTIME_UNAVAILABLE_PLATFORM(P) \ - template <> \ - struct ShaderDB

{ \ - using PipelineTypes = pack; \ - template \ - struct StageDB {}; \ - }; \ - SPECIALIZE_RUNTIME_UNAVAILABLE_STAGE(P, hecl::PipelineStage::Vertex) \ - SPECIALIZE_RUNTIME_UNAVAILABLE_STAGE(P, hecl::PipelineStage::Fragment) \ - SPECIALIZE_RUNTIME_UNAVAILABLE_STAGE(P, hecl::PipelineStage::Geometry) \ - SPECIALIZE_RUNTIME_UNAVAILABLE_STAGE(P, hecl::PipelineStage::Control) \ - SPECIALIZE_RUNTIME_UNAVAILABLE_STAGE(P, hecl::PipelineStage::Evaluation) -#define SPECIALIZE_OFFLINE_PLATFORM(P) \ - template <> \ - struct ShaderDB

{ \ - using PipelineTypes = pack; \ - template \ - struct StageDB {}; \ - }; \ - SPECIALIZE_OFFLINE_STAGE(P, hecl::PipelineStage::Vertex) \ - SPECIALIZE_OFFLINE_STAGE(P, hecl::PipelineStage::Fragment) \ - SPECIALIZE_OFFLINE_STAGE(P, hecl::PipelineStage::Geometry) \ - SPECIALIZE_OFFLINE_STAGE(P, hecl::PipelineStage::Control) \ - SPECIALIZE_OFFLINE_STAGE(P, hecl::PipelineStage::Evaluation) - -#if HECL_RUNTIME -#if BOO_HAS_GL -SPECIALIZE_RUNTIME_AVAILABLE_PLATFORM(hecl::PlatformType::OpenGL) -#else -SPECIALIZE_RUNTIME_UNAVAILABLE_PLATFORM(hecl::PlatformType::OpenGL) -#endif -#if BOO_HAS_VULKAN -SPECIALIZE_RUNTIME_AVAILABLE_PLATFORM(hecl::PlatformType::Vulkan) -#else -SPECIALIZE_RUNTIME_UNAVAILABLE_PLATFORM(hecl::PlatformType::Vulkan) -#endif -#if _WIN32 -SPECIALIZE_RUNTIME_AVAILABLE_PLATFORM(hecl::PlatformType::D3D11) -#else -SPECIALIZE_RUNTIME_UNAVAILABLE_PLATFORM(hecl::PlatformType::D3D11) -#endif -#if BOO_HAS_METAL -SPECIALIZE_RUNTIME_AVAILABLE_PLATFORM(hecl::PlatformType::Metal) -#else -SPECIALIZE_RUNTIME_UNAVAILABLE_PLATFORM(hecl::PlatformType::Metal) -#endif -#if BOO_HAS_NX -SPECIALIZE_RUNTIME_AVAILABLE_PLATFORM(hecl::PlatformType::NX) -#else -SPECIALIZE_RUNTIME_UNAVAILABLE_PLATFORM(hecl::PlatformType::NX) -#endif -#else -SPECIALIZE_OFFLINE_PLATFORM(hecl::PlatformType::OpenGL) -SPECIALIZE_OFFLINE_PLATFORM(hecl::PlatformType::Vulkan) -SPECIALIZE_OFFLINE_PLATFORM(hecl::PlatformType::D3D11) -SPECIALIZE_OFFLINE_PLATFORM(hecl::PlatformType::Metal) -SPECIALIZE_OFFLINE_PLATFORM(hecl::PlatformType::NX) -#endif - -class ShaderCacheZipStream; - -template -class StageConverter { - friend class PipelineConverter

; -#if HECL_RUNTIME - using StageTargetTp = StageRuntimeObject; -#else - using StageTargetTp = StageBinary; -#endif - std::unordered_map m_stageCache; - -#if 0 /* Horrible compiler memory explosion - DO NOT USE! */ - template - static constexpr bool is_stage_constructible_v = - std::is_constructible&, FactoryCtx&, FromTp>::value; - - template - struct is_eventually_constructible : std::false_type {}; - template - struct _is_eventually_constructible - : std::conditional_t, - std::true_type, - std::conditional_t, - is_eventually_constructible, - _is_eventually_constructible>> {}; - template - struct _is_eventually_constructible : std::false_type {}; - template - struct is_eventually_constructible> - : _is_eventually_constructible {}; - template - static constexpr bool is_eventually_constructible_v = - is_eventually_constructible::value; - - template - struct _next_type { using type = std::conditional_t && - is_eventually_constructible_v, - ToTp, - typename _next_type::type>; }; - template - struct _next_type { using type = null_t; }; - template - struct next_type { using type = null_t; }; - template - struct next_type> : _next_type {}; - template - using next_type_t = typename next_type::type; - - template - std::enable_if_t, ToTp> - _Do(FactoryCtx& ctx, const FromTp& in) - { - using NextTp = next_type_t; - return ToTp(*this, ctx, _Do(ctx, in)); - } - - template - std::enable_if_t, ToTp> - _Do(FactoryCtx& ctx, const FromTp& in) - { - return ToTp(*this, ctx, in); - } -#endif - - using StageTypes = typename ShaderDB

::template StageDB::StageTypes; - - template - static constexpr bool is_stage_constructible_v = - std::is_constructible&, FactoryCtx&, FromTp>::value; - - template - struct _next_type { - using type = std::conditional_t, ToTp, - typename _next_type::type>; - }; - template - struct _next_type { - using type = null_t; - }; - template - struct next_type { - using type = null_t; - }; - template - struct next_type> : _next_type {}; - template - using next_type_t = typename next_type::type; - - /* StageSourceText derivative -> StageBinary */ - template - std::enable_if_t> && std::is_base_of_v, NextTp>, - StageBinary> - _DoDerivative(FactoryCtx& ctx, const FromTp& in) { - return StageBinary(*this, ctx, NextTp(*this, ctx, in)); - } - - /* StageBinary derivative -> StageBinary */ - template - std::enable_if_t> && std::is_base_of_v, NextTp>, - StageBinary> - _DoDerivative(FactoryCtx& ctx, const FromTp& in) { - return NextTp(*this, ctx, in); - } - - /* Non-StageSourceText derivative -> StageBinary */ - template - std::enable_if_t> && !std::is_base_of_v, FromTp>, - StageBinary> - _Do(FactoryCtx& ctx, const FromTp& in) { - using NextTp = next_type_t; - static_assert(!std::is_same_v, "Unable to resolve StageBinary or StageSourceText derivative"); - return _DoDerivative(ctx, in); - } - - /* StageSourceText derivative -> StageBinary */ - template - std::enable_if_t> && std::is_base_of_v, FromTp>, - StageBinary> - _Do(FactoryCtx& ctx, const FromTp& in) { - return StageBinary(*this, ctx, in); - } - - /* Non-StageBinary derivative -> StageRuntimeObject */ - template - std::enable_if_t> && !std::is_base_of_v, FromTp>, - StageRuntimeObject> - _Do(FactoryCtx& ctx, const FromTp& in) { - return StageRuntimeObject(*this, ctx, _Do, FromTp>(ctx, in)); - } - - /* StageBinary derivative -> StageRuntimeObject */ - template - std::enable_if_t> && std::is_base_of_v, FromTp>, - StageRuntimeObject> - _Do(FactoryCtx& ctx, const FromTp& in) { - return StageRuntimeObject(*this, ctx, in); - } - - template - ToTp Do(FactoryCtx& ctx, const FromTp& in) { - return _Do(ctx, in); - } - -public: -#if HECL_RUNTIME - void loadFromStream(FactoryCtx& ctx, ShaderCacheZipStream& r); -#endif - - template - StageTargetTp convert(FactoryCtx& ctx, const FromTp& in) { - if constexpr (FromTp::HasStageHash) { - uint64_t hash = in.template StageHash(); - auto search = m_stageCache.find(hash); - if (search != m_stageCache.end()) - return search->second; - return m_stageCache.insert(std::make_pair(hash, Do(ctx, in))).first->second; - } - return Do(ctx, in); - } -}; - -class PipelineConverterBase { - boo::IGraphicsDataFactory* m_gfxF; - boo::IGraphicsDataFactory::Platform m_platform; - -protected: - PipelineConverterBase(boo::IGraphicsDataFactory* gfxF, boo::IGraphicsDataFactory::Platform platform) - : m_gfxF(gfxF), m_platform(platform) {} - -public: - virtual ~PipelineConverterBase() = default; -#if HECL_RUNTIME - template - boo::ObjToken convert(FactoryCtx& ctx, const FromTp& in); - template - boo::ObjToken convert(const FromTp& in); -#endif -}; - -template -class PipelineConverter : public PipelineConverterBase { -#if HECL_RUNTIME - using PipelineTargetTp = FinalPipeline

; -#else - using PipelineTargetTp = StageCollection>; -#endif - std::unordered_map m_pipelineCache; - StageConverter m_vertexConverter; - StageConverter m_fragmentConverter; - StageConverter m_geometryConverter; - StageConverter m_controlConverter; - StageConverter m_evaluationConverter; - - using PipelineTypes = typename ShaderDB

::PipelineTypes; - - template - static constexpr bool is_pipeline_constructible_v = - std::is_constructible&, FactoryCtx&, FromTp>::value; - - template - struct is_eventually_constructible : std::false_type {}; - template - struct _is_eventually_constructible - : std::conditional_t, std::true_type, - std::conditional_t, - is_eventually_constructible, - _is_eventually_constructible>> {}; - template - struct _is_eventually_constructible : std::false_type {}; - template - struct is_eventually_constructible> - : _is_eventually_constructible {}; - template - static constexpr bool is_eventually_constructible_v = - is_eventually_constructible::value; - - template - struct _next_type { - using type = - std::conditional_t && is_eventually_constructible_v, - ToTp, typename _next_type::type>; - }; - template - struct _next_type { - using type = null_t; - }; - template - struct next_type { - using type = null_t; - }; - template - struct next_type> : _next_type {}; - template - using next_type_t = typename next_type::type; - - template - std::enable_if_t, ToTp> _Do(FactoryCtx& ctx, const FromTp& in) { - using NextTp = next_type_t; - return ToTp(*this, ctx, _Do(ctx, in)); - } - - template - std::enable_if_t, ToTp> _Do(FactoryCtx& ctx, const FromTp& in) { - return ToTp(*this, ctx, in); - } - - template - ToTp Do(FactoryCtx& ctx, const FromTp& in) { - /* No idea why this fails; it works fine with manual template arguments (clang bug?) */ - // static_assert(is_eventually_constructible_v, "Unable to resolve pipeline conversion chain"); - return _Do(ctx, in); - } - -public: - PipelineConverter(boo::IGraphicsDataFactory* gfxF) : PipelineConverterBase(gfxF, P::Enum) {} -#if HECL_RUNTIME - bool loadFromFile(FactoryCtx& ctx, const char* path); -#endif - - template - PipelineTargetTp convert(FactoryCtx& ctx, const FromTp& in) { - if constexpr (FromTp::HasHash) { - uint64_t hash = in.Hash(); - auto search = m_pipelineCache.find(hash); - if (search != m_pipelineCache.end()) - return search->second; - return m_pipelineCache.insert(std::make_pair(hash, Do(ctx, in))).first->second; - } - return Do(ctx, in); - } - - StageConverter& getVertexConverter() { return m_vertexConverter; } - StageConverter& getFragmentConverter() { return m_fragmentConverter; } - StageConverter& getGeometryConverter() { return m_geometryConverter; } - StageConverter& getControlConverter() { return m_controlConverter; } - StageConverter& getEvaluationConverter() { return m_evaluationConverter; } -}; - -#if HECL_RUNTIME - -template -inline boo::ObjToken PipelineConverterBase::convert(FactoryCtx& ctx, const FromTp& in) { - assert(ctx.platform() == m_platform && "PipelineConverterBase platform mismatch"); - switch (m_platform) { -#if BOO_HAS_GL - case boo::IGraphicsDataFactory::Platform::OpenGL: - return static_cast&>(*this).convert(ctx, in).pipeline(); -#endif -#if BOO_HAS_VULKAN - case boo::IGraphicsDataFactory::Platform::Vulkan: - return static_cast&>(*this).convert(ctx, in).pipeline(); -#endif -#if _WIN32 - case boo::IGraphicsDataFactory::Platform::D3D11: - return static_cast&>(*this).convert(ctx, in).pipeline(); -#endif -#if BOO_HAS_METAL - case boo::IGraphicsDataFactory::Platform::Metal: - return static_cast&>(*this).convert(ctx, in).pipeline(); -#endif -#if BOO_HAS_NX - case boo::IGraphicsDataFactory::Platform::NX: - return static_cast&>(*this).convert(ctx, in).pipeline(); -#endif - default: - return {}; - } -} - -template -inline boo::ObjToken PipelineConverterBase::convert(const FromTp& in) { - boo::ObjToken ret; - m_gfxF->commitTransaction([this, &ret, &in](boo::IGraphicsDataFactory::Context& ctx) { - ret = convert(ctx, in); - return true; - } BooTrace); - return ret; -} - -inline std::unique_ptr NewPipelineConverter(boo::IGraphicsDataFactory* gfxF) { - switch (gfxF->platform()) { -#if BOO_HAS_GL - case boo::IGraphicsDataFactory::Platform::OpenGL: - return std::make_unique>(gfxF); -#endif -#if BOO_HAS_VULKAN - case boo::IGraphicsDataFactory::Platform::Vulkan: - return std::make_unique>(gfxF); -#endif -#if _WIN32 - case boo::IGraphicsDataFactory::Platform::D3D11: - return std::make_unique>(gfxF); -#endif -#if BOO_HAS_METAL - case boo::IGraphicsDataFactory::Platform::Metal: - setenv("HECL_NO_METAL_COMPILER", "1", 1); - return std::make_unique>(gfxF); -#endif -#if BOO_HAS_NX - case boo::IGraphicsDataFactory::Platform::NX: - return std::make_unique>(gfxF); -#endif - default: - return {}; - } -} - -extern PipelineConverterBase* conv; - -#endif - -} // namespace hecl diff --git a/hecl/include/hecl/PipelineBase.hpp b/hecl/include/hecl/PipelineBase.hpp deleted file mode 100644 index b1a62d4e7..000000000 --- a/hecl/include/hecl/PipelineBase.hpp +++ /dev/null @@ -1,222 +0,0 @@ -#pragma once - -#include -#include -#include -#include -#include - -#include "hecl/Compilers.hpp" - -#include -#include - -#define HECL_RUNTIME 1 - -namespace hecl { - -using AdditionalPipelineInfo = boo::AdditionalPipelineInfo; - -enum class StageTargetType { SourceText, Binary, Runtime }; - -enum class PipelineTargetType { - StageSourceTextCollection, - StageBinaryCollection, - StageRuntimeCollection, - FinalPipeline -}; - -template -class StageConverter; - -template -class PipelineConverter; - -#if HECL_RUNTIME -using FactoryCtx = boo::IGraphicsDataFactory::Context; -#else -struct FactoryCtx {}; -#endif - -template -class StageRep { -public: - using Platform = P; - using Stage = S; -}; - -template -class PipelineRep { -public: - using Platform = P; -}; - -class GeneralShader : public hecl::PipelineRep {}; -class TessellationShader : public hecl::PipelineRep {}; - -template -class StageSourceText : public StageRep { - std::string_view m_text; - uint64_t m_hash; - -public: - static constexpr StageTargetType TargetType = StageTargetType::SourceText; - static constexpr PipelineTargetType PipelineTarget = PipelineTargetType::StageSourceTextCollection; - static constexpr bool HasHash = true; - uint64_t Hash() const { return m_hash; } - - explicit StageSourceText(std::string_view text) : m_text(text), m_hash(XXH64(m_text.data(), m_text.size(), 0)) {} - std::string_view text() const { return m_text; } -}; - -template -class StageBinary : public StageRep { - StageBinaryData m_ownedData; - const uint8_t* m_data = nullptr; - size_t m_size = 0; - uint64_t m_hash = 0; - -public: - static constexpr StageTargetType TargetType = StageTargetType::Binary; - static constexpr PipelineTargetType PipelineTarget = PipelineTargetType::StageBinaryCollection; - static constexpr bool HasHash = true; - uint64_t Hash() const { return m_hash; } - - StageBinary(const uint8_t* data, size_t size) : m_data(data), m_size(size) { m_hash = XXH64(m_data, m_size, 0); } - StageBinary(StageBinaryData data, size_t size) - : m_ownedData(std::move(data)), m_data(m_ownedData.get()), m_size(size) { - m_hash = XXH64(m_data, m_size, 0); - } - explicit StageBinary(std::pair data) : StageBinary(data.first, data.second) {} - StageBinary(StageConverter& conv, FactoryCtx& ctx, const StageSourceText& in) - : StageBinary(CompileShader(in.text())) {} - const uint8_t* data() const { return m_data; } - size_t size() const { return m_size; } -}; - -template -class FinalPipeline; - -template -using __IsStageSubclass = - typename std::disjunction, T>, - std::is_base_of, T>, - std::is_base_of, T>, - std::is_base_of, T>, - std::is_base_of, T>>; -template -inline constexpr bool __IsStageSubclass_v = __IsStageSubclass::value; - -template -class StageCollection; -template