diff --git a/.gitmodules b/.gitmodules index 1899f1b99..c597d511c 100644 --- a/.gitmodules +++ b/.gitmodules @@ -60,3 +60,6 @@ [submodule "extern/SDL"] path = extern/SDL url = https://github.com/libsdl-org/SDL.git +[submodule "extern/dawn"] + path = extern/dawn + url = https://github.com/encounter/dawn-cmake.git diff --git a/CMakeLists.txt b/CMakeLists.txt index a8be72c1d..8ca27b9dc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -485,7 +485,9 @@ target_link_libraries(hecl-full PRIVATE zeus nod) target_link_libraries(hecl-light PRIVATE zeus nod) add_subdirectory(extern/SDL EXCLUDE_FROM_ALL) -target_compile_options(SDL2-static PRIVATE -Wno-implicit-fallthrough) +if (NOT MSVC) + target_compile_options(SDL2-static PRIVATE -Wno-implicit-fallthrough) +endif () if(NOT TARGET atdna) # Import native atdna if cross-compiling @@ -507,7 +509,7 @@ 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(aurora) add_subdirectory(Runtime) add_subdirectory(mpcksum EXCLUDE_FROM_ALL) add_subdirectory(gbalink EXCLUDE_FROM_ALL) diff --git a/DataSpec/DNACommon/AROTBuilder.hpp b/DataSpec/DNACommon/AROTBuilder.hpp index d578c0567..9e32b23b9 100644 --- a/DataSpec/DNACommon/AROTBuilder.hpp +++ b/DataSpec/DNACommon/AROTBuilder.hpp @@ -4,6 +4,7 @@ #include "DeafBabe.hpp" #include "zeus/CAABox.hpp" #include "CMDL.hpp" +#include "IOStreams.hpp" #include namespace DataSpec { diff --git a/DataSpec/DNACommon/CMDL.cpp b/DataSpec/DNACommon/CMDL.cpp index a09122128..2af280e61 100644 --- a/DataSpec/DNACommon/CMDL.cpp +++ b/DataSpec/DNACommon/CMDL.cpp @@ -9,6 +9,7 @@ #include "DataSpec/DNAMP2/CSKR.hpp" #include "DataSpec/DNAMP3/CMDLMaterials.hpp" #include "DataSpec/DNAMP3/CSKR.hpp" +#include "IOStreams.hpp" #include #include diff --git a/DataSpec/DNACommon/PATH.cpp b/DataSpec/DNACommon/PATH.cpp index a5e330427..dff277911 100644 --- a/DataSpec/DNACommon/PATH.cpp +++ b/DataSpec/DNACommon/PATH.cpp @@ -245,4 +245,4 @@ template struct PATH; template struct PATH; template struct PATH; -} // namespace DataSpec::DNAPATH \ No newline at end of file +} // namespace DataSpec::DNAPATH diff --git a/DataSpec/DNAMP1/MLVL.cpp b/DataSpec/DNAMP1/MLVL.cpp index 149a718f2..7acce31f9 100644 --- a/DataSpec/DNAMP1/MLVL.cpp +++ b/DataSpec/DNAMP1/MLVL.cpp @@ -321,10 +321,10 @@ bool MLVL::Cook(const hecl::ProjectPath& outPath, const hecl::ProjectPath& inPat metaforce::SObjectTag tag = g_curSpec->buildTagFromPath(path.first); if (tag.id.IsValid()) { if (path.second) - areaOut.lazyDeps.emplace_back(tag.id.Value(), tag.type); + areaOut.lazyDeps.emplace_back(tag.id.Value(), tag.type.toUint32()); else areaOut.lazyDeps.emplace_back(0, FOURCC('NONE')); - areaOut.deps.emplace_back(tag.id.Value(), tag.type); + areaOut.deps.emplace_back(tag.id.Value(), tag.type.toUint32()); } } } @@ -350,17 +350,17 @@ bool MLVL::Cook(const hecl::ProjectPath& outPath, const hecl::ProjectPath& inPat metaforce::SObjectTag tag = g_curSpec->buildTagFromPath(path.first); if (tag.id.IsValid()) { if (path.second) - areaOut.lazyDeps.emplace_back(tag.id.Value(), tag.type); + areaOut.lazyDeps.emplace_back(tag.id.Value(), tag.type.toUint32()); else areaOut.lazyDeps.emplace_back(0, FOURCC('NONE')); - areaOut.deps.emplace_back(tag.id.Value(), tag.type); + areaOut.deps.emplace_back(tag.id.Value(), tag.type.toUint32()); } } hecl::ProjectPath pathPath = GetPathBeginsWith(areaDEnum, area.path, "!path"); metaforce::SObjectTag pathTag = g_curSpec->buildTagFromPath(pathPath); if (pathTag.id.IsValid()) { - areaOut.deps.emplace_back(pathTag.id.Value(), pathTag.type); + areaOut.deps.emplace_back(pathTag.id.Value(), pathTag.type.toUint32()); areaOut.lazyDeps.emplace_back(0, FOURCC('NONE')); } } diff --git a/DataSpec/SpecBase.cpp b/DataSpec/SpecBase.cpp index 13e3e9317..3cca8b98b 100644 --- a/DataSpec/SpecBase.cpp +++ b/DataSpec/SpecBase.cpp @@ -482,7 +482,7 @@ void SpecBase::copyBuildListData(std::vector>& auto& [positionOut, sizeOut, compressedOut] = fileIndex.emplace_back(); - if (tag.type == FOURCC('MLVL')) { + if (tag.type.toUint32() == FOURCC('MLVL')) { auto search = mlvlData.find(tag.id); if (search == mlvlData.end()) Log.report(logvisor::Fatal, FMT_STRING("Unable to find MLVL {}"), tag.id); @@ -635,7 +635,7 @@ void SpecBase::doPackage(const hecl::ProjectPath& path, const hecl::Database::Da std::unordered_set addedTags; addedTags.reserve(buildList.size()); for (auto& tag : buildList) { - if ((i == 0 && tag.type == FOURCC('CMDL')) || (i == 1 && tag.type != FOURCC('CMDL'))) { + if ((i == 0 && tag.type.toUint32() == FOURCC('CMDL')) || (i == 1 && tag.type.toUint32() != FOURCC('CMDL'))) { if (addedTags.find(tag) != addedTags.end()) continue; addedTags.insert(tag); @@ -820,7 +820,7 @@ FourCC SpecBase::getResourceTypeById(metaforce::CAssetId id) const { return {}; std::unique_lock lk(m_backgroundIndexMutex); - metaforce::SObjectTag searchTag = {FourCC(), id}; + metaforce::SObjectTag searchTag = {metaforce::FourCC(), id}; auto search = m_tagToPath.find(searchTag); if (search == m_tagToPath.end()) { if (m_backgroundRunning) { @@ -838,7 +838,7 @@ FourCC SpecBase::getResourceTypeById(metaforce::CAssetId id) const { return {}; } - return search->first.type; + return search->first.type.toUint32(); } void SpecBase::enumerateResources(const std::function& lambda) const { @@ -1121,7 +1121,7 @@ void SpecBase::backgroundIndexProc() { const athena::io::YAMLNode& node = *child.second; if (node.m_seqChildren.size() >= 2) { unsigned long id = strtoul(child.first.c_str(), nullptr, 16); - hecl::FourCC type(node.m_seqChildren[0]->m_scalarString.c_str()); + metaforce::FourCC type(node.m_seqChildren[0]->m_scalarString.c_str()); metaforce::SObjectTag pathTag(type, id); for (auto I = node.m_seqChildren.begin() + 1, E = node.m_seqChildren.end(); I != E; ++I) { hecl::ProjectPath path(m_project.getProjectWorkingPath(), (*I)->m_scalarString); @@ -1150,7 +1150,7 @@ void SpecBase::backgroundIndexProc() { m_catalogTagToNames.reserve(nameReader.getRootNode()->m_mapChildren.size()); for (const auto& child : nameReader.getRootNode()->m_mapChildren) { unsigned long id = strtoul(child.second->m_scalarString.c_str(), nullptr, 16); - auto search = m_tagToPath.find(metaforce::SObjectTag(FourCC(), uint32_t(id))); + auto search = m_tagToPath.find(metaforce::SObjectTag(metaforce::FourCC(), uint32_t(id))); if (search != m_tagToPath.cend()) { std::string chLower = child.first; std::transform(chLower.cbegin(), chLower.cend(), chLower.begin(), tolower); diff --git a/DataSpec/SpecMP1.cpp b/DataSpec/SpecMP1.cpp index e60408956..a6a7fa1f1 100644 --- a/DataSpec/SpecMP1.cpp +++ b/DataSpec/SpecMP1.cpp @@ -1016,7 +1016,7 @@ struct SpecMP1 : SpecBase { w.writeUint32Big(1); DNAMP1::PAK::NameEntry nameEnt; hecl::ProjectPath parentDir = worldPath.getParentPath(); - nameEnt.type = worldTag.type; + nameEnt.type = worldTag.type.toUint32(); nameEnt.id = worldTag.id.Value(); nameEnt.nameLen = atUint32(parentDir.getLastComponent().size()); nameEnt.name = parentDir.getLastComponent(); @@ -1024,19 +1024,19 @@ struct SpecMP1 : SpecBase { std::unordered_set addedTags; for (auto& area : mlvl.areas) { - metaforce::SObjectTag areaTag(FOURCC('MREA'), area.areaMREAId.toUint64()); + metaforce::SObjectTag areaTag(metaforce::FOURCC('MREA'), area.areaMREAId.toUint64()); bool dupeRes = false; if (hecl::ProjectPath areaDir = pathFromTag(areaTag).getParentPath()) dupeRes = hecl::ProjectPath(areaDir, "!duperes").isFile(); - metaforce::SObjectTag nameTag(FOURCC('STRG'), area.areaNameId.toUint64()); + metaforce::SObjectTag nameTag(metaforce::FOURCC('STRG'), area.areaNameId.toUint64()); if (nameTag) listOut.push_back(nameTag); for (const auto& dep : area.deps) { metaforce::CAssetId newId = dep.id.toUint64(); if (dupeRes || addedTags.find(newId) == addedTags.end()) { - listOut.emplace_back(dep.type, newId); + listOut.emplace_back(dep.type.toUint32(), newId); addedTags.insert(newId); } } @@ -1069,18 +1069,18 @@ struct SpecMP1 : SpecBase { area.depLayers = std::move(strippedDepLayers); } - metaforce::SObjectTag nameTag(FOURCC('STRG'), mlvl.worldNameId.toUint64()); + metaforce::SObjectTag nameTag(metaforce::FOURCC('STRG'), mlvl.worldNameId.toUint64()); if (nameTag) listOut.push_back(nameTag); - metaforce::SObjectTag savwTag(FOURCC('SAVW'), mlvl.saveWorldId.toUint64()); + metaforce::SObjectTag savwTag(metaforce::FOURCC('SAVW'), mlvl.saveWorldId.toUint64()); if (savwTag) { if (hecl::ProjectPath savwPath = pathFromTag(savwTag)) m_project.cookPath(savwPath, {}, false, true); listOut.push_back(savwTag); } - metaforce::SObjectTag mapTag(FOURCC('MAPW'), mlvl.worldMap.toUint64()); + metaforce::SObjectTag mapTag(metaforce::FOURCC('MAPW'), mlvl.worldMap.toUint64()); if (mapTag) { if (hecl::ProjectPath mapPath = pathFromTag(mapTag)) { m_project.cookPath(mapPath, {}, false, true); @@ -1096,14 +1096,14 @@ struct SpecMP1 : SpecBase { for (atUint32 i = 0; i < mapaCount; ++i) { UniqueID32 id; id.read(r); - listOut.emplace_back(FOURCC('MAPA'), id.toUint64()); + listOut.emplace_back(metaforce::FOURCC('MAPA'), id.toUint64()); } } } listOut.push_back(mapTag); } - metaforce::SObjectTag skyboxTag(FOURCC('CMDL'), mlvl.worldSkyboxId.toUint64()); + metaforce::SObjectTag skyboxTag(metaforce::FOURCC('CMDL'), mlvl.worldSkyboxId.toUint64()); if (skyboxTag) { listOut.push_back(skyboxTag); hecl::ProjectPath skyboxPath = pathFromTag(skyboxTag); @@ -1126,7 +1126,7 @@ struct SpecMP1 : SpecBase { for (const auto& item : listOut) { DNAMP1::PAK::Entry ent; ent.compressed = 0; - ent.type = item.type; + ent.type = item.type.toUint32(); ent.id = item.id.Value(); ent.size = 0; ent.offset = 0; @@ -1153,7 +1153,7 @@ struct SpecMP1 : SpecBase { w.writeUint32Big(atUint32(nameList.size())); for (const auto& item : nameList) { DNAMP1::PAK::NameEntry nameEnt; - nameEnt.type = item.first.type; + nameEnt.type = item.first.type.toUint32(); nameEnt.id = item.first.id.Value(); nameEnt.nameLen = atUint32(item.second.size()); nameEnt.name = item.second; @@ -1165,7 +1165,7 @@ struct SpecMP1 : SpecBase { for (const auto& item : list) { DNAMP1::PAK::Entry ent; ent.compressed = 0; - ent.type = item.type; + ent.type = item.type.toUint32(); ent.id = item.id.Value(); ent.size = 0; ent.offset = 0; @@ -1182,7 +1182,7 @@ struct SpecMP1 : SpecBase { const metaforce::SObjectTag& tag = *it++; DNAMP1::PAK::Entry ent; ent.compressed = atUint32(std::get<2>(item)); - ent.type = tag.type; + ent.type = tag.type.toUint32(); ent.id = tag.id.Value(); ent.size = atUint32(std::get<1>(item)); ent.offset = atUint32(std::get<0>(item)); diff --git a/NESEmulator/CNESEmulator.hpp b/NESEmulator/CNESEmulator.hpp index e60ffc551..782a406b1 100644 --- a/NESEmulator/CNESEmulator.hpp +++ b/NESEmulator/CNESEmulator.hpp @@ -35,7 +35,7 @@ private: zeus::CColor m_color; }; - std::shared_ptr m_texture; + std::shared_ptr m_texture; // boo::ObjToken m_uniBuf; // boo::ObjToken m_vbo; // boo::ObjToken m_shadBind; diff --git a/Runtime/Audio/CAudioGroupSet.cpp b/Runtime/Audio/CAudioGroupSet.cpp index 83ca2f65a..d24e2c62f 100644 --- a/Runtime/Audio/CAudioGroupSet.cpp +++ b/Runtime/Audio/CAudioGroupSet.cpp @@ -8,7 +8,7 @@ amuse::AudioGroupData CAudioGroupSet::LoadData() { const auto readU32 = [](const u8* ptr) { uint32_t value; std::memcpy(&value, ptr, sizeof(value)); - return hecl::SBig(value); + return SBig(value); }; athena::io::MemoryReader r(m_buffer.get(), INT32_MAX); diff --git a/Runtime/Audio/CStreamAudioManager.cpp b/Runtime/Audio/CStreamAudioManager.cpp index 810c52822..71e5d48bd 100644 --- a/Runtime/Audio/CStreamAudioManager.cpp +++ b/Runtime/Audio/CStreamAudioManager.cpp @@ -810,12 +810,12 @@ std::array CDSPStreamManager::g_Streams{}; SDSPStreamInfo::SDSPStreamInfo(const CDSPStreamManager& stream) { x0_fileName = stream.x60_fileName.c_str(); - x4_sampleRate = hecl::SBig(stream.x0_header.x8_sample_rate); - xc_adpcmBytes = (hecl::SBig(stream.x0_header.x4_num_nibbles) / 2) & 0x7FFFFFE0; + x4_sampleRate = SBig(stream.x0_header.x8_sample_rate); + xc_adpcmBytes = (SBig(stream.x0_header.x4_num_nibbles) / 2) & 0x7FFFFFE0; if (stream.x0_header.xc_loop_flag) { - u32 loopStartNibble = hecl::SBig(stream.x0_header.x10_loop_start_nibble); - u32 loopEndNibble = hecl::SBig(stream.x0_header.x14_loop_end_nibble); + u32 loopStartNibble = SBig(stream.x0_header.x10_loop_start_nibble); + u32 loopEndNibble = SBig(stream.x0_header.x14_loop_end_nibble); x10_loopFlag = true; x14_loopStartByte = (loopStartNibble / 2) & 0x7FFFFFE0; x18_loopEndByte = std::min((loopEndNibble / 2) & 0x7FFFFFE0, xc_adpcmBytes); @@ -826,8 +826,8 @@ SDSPStreamInfo::SDSPStreamInfo(const CDSPStreamManager& stream) { } for (int i = 0; i < 8; ++i) { - x1c_coef[i][0] = hecl::SBig(stream.x0_header.x1c_coef[i][0]); - x1c_coef[i][1] = hecl::SBig(stream.x0_header.x1c_coef[i][1]); + x1c_coef[i][0] = SBig(stream.x0_header.x1c_coef[i][0]); + x1c_coef[i][1] = SBig(stream.x0_header.x1c_coef[i][1]); } } diff --git a/Runtime/AutoMapper/CMapWorldInfo.hpp b/Runtime/AutoMapper/CMapWorldInfo.hpp index 65dd5aaff..14474e8fc 100644 --- a/Runtime/AutoMapper/CMapWorldInfo.hpp +++ b/Runtime/AutoMapper/CMapWorldInfo.hpp @@ -3,7 +3,8 @@ #include #include -#include "Runtime/RetroTypes.hpp" +#include "RetroTypes.hpp" +#include "IOStreams.hpp" namespace metaforce { class CWorldSaveGameInfo; diff --git a/Runtime/AutoMapper/CMappableObject.hpp b/Runtime/AutoMapper/CMappableObject.hpp index 0b52196c6..ca679e8b2 100644 --- a/Runtime/AutoMapper/CMappableObject.hpp +++ b/Runtime/AutoMapper/CMappableObject.hpp @@ -63,7 +63,7 @@ private: CMapSurfaceShader m_surface; CLineRenderer m_outline; explicit DoorSurface() - : m_surface(aurora::ArrayRef{skDoorVerts}, aurora::ArrayRef{skDoorIndices}) + : m_surface(skDoorVerts, skDoorIndices) , m_outline(CLineRenderer::EPrimitiveMode::LineLoop, 5, nullptr, false, false, true) {} }; std::optional m_doorSurface; diff --git a/Runtime/CMain.cpp b/Runtime/CMain.cpp index 479aa5b5b..46d529a49 100644 --- a/Runtime/CMain.cpp +++ b/Runtime/CMain.cpp @@ -19,9 +19,7 @@ * (used by MSVC to definitively link DataSpecs) */ #include "DataSpecRegistry.hpp" -#include "Graphics/include/aurora.hpp" -#include "aurora.h" -#include "aurora_shaders.h" +#include using namespace std::literals; @@ -521,6 +519,14 @@ public: } } + void onImGuiInit(float scale) noexcept override { + ImGuiEngine_Initialize(scale); + } + + void onImGuiAddTextures() noexcept override { + ImGuiEngine_AddTextures(); + } + [[nodiscard]] std::string getGraphicsApi() const { return m_cvarCommons.getGraphicsApi(); } [[nodiscard]] uint32_t getSamples() const { return m_cvarCommons.getSamples(); } @@ -577,8 +583,6 @@ static bool IsClientLoggingEnabled(int argc, char** argv) { } #if !WINDOWS_STORE -extern "C" void cxxbridge1$rust_vec$u8$set_len(rust::Vec* ptr, std::size_t len) noexcept; - int main(int argc, char** argv) { //TODO: This seems to fix a lot of weird issues with rounding // but breaks animations, need to research why this is the case @@ -622,17 +626,13 @@ int main(int argc, char** argv) { hecl::SetCpuCountOverride(argc, argv); auto app = std::make_unique(fileMgr, cvarMgr, cvarCmns); - auto data = aurora::Icon{}; - { - auto icon = metaforce::GetIcon(); - data.data.reserve(icon.size); - std::memcpy(data.data.data(), icon.data.get(), icon.size); - // terrible hack: https://github.com/dtolnay/cxx/issues/990 - cxxbridge1$rust_vec$u8$set_len(&data.data, icon.size); - data.width = icon.width; - data.height = icon.height; - } - aurora::app_run(std::move(app), data); + auto icon = metaforce::GetIcon(); + auto data = aurora::Icon{ + .data = std::move(icon.data), + .width = icon.width, + .height = icon.height, + }; + aurora::app_run(std::move(app), std::move(data)); return 0; } #endif diff --git a/Runtime/CTextureCache.hpp b/Runtime/CTextureCache.hpp index 81bd4bc16..3dc558331 100644 --- a/Runtime/CTextureCache.hpp +++ b/Runtime/CTextureCache.hpp @@ -1,6 +1,10 @@ #pragma once + #include "Runtime/RetroTypes.hpp" #include "Runtime/Graphics/CTexture.hpp" + +#include + namespace metaforce { class CPaletteInfo { u32 m_format; diff --git a/Runtime/Collision/CAreaOctTree.cpp b/Runtime/Collision/CAreaOctTree.cpp index 045dd4081..5cf30f2a3 100644 --- a/Runtime/Collision/CAreaOctTree.cpp +++ b/Runtime/Collision/CAreaOctTree.cpp @@ -1,6 +1,7 @@ #include "Runtime/Collision/CAreaOctTree.hpp" #include "Runtime/Collision/CMaterialFilter.hpp" +#include "IOStreams.hpp" #include #include diff --git a/Runtime/Collision/CCollisionEdge.hpp b/Runtime/Collision/CCollisionEdge.hpp index 10d9e90e3..8735fe009 100644 --- a/Runtime/Collision/CCollisionEdge.hpp +++ b/Runtime/Collision/CCollisionEdge.hpp @@ -16,8 +16,8 @@ public: [[nodiscard]] constexpr u16 GetVertIndex2() const noexcept { return x2_index2; } constexpr void swapBig() noexcept { - x0_index1 = hecl::SBig(x0_index1); - x2_index2 = hecl::SBig(x2_index2); + x0_index1 = SBig(x0_index1); + x2_index2 = SBig(x2_index2); } }; } // namespace metaforce diff --git a/Runtime/Graphics/CBooRenderer.cpp b/Runtime/Graphics/CBooRenderer.cpp index 755f0fedf..9a455605a 100644 --- a/Runtime/Graphics/CBooRenderer.cpp +++ b/Runtime/Graphics/CBooRenderer.cpp @@ -436,9 +436,9 @@ void CBooRenderer::RenderFogVolumeModel(const zeus::CAABox& aabb, const CModel* for (size_t i = 0; i < planes.size(); ++i) { DrawFogSlices(planes.data(), planes.size(), i, xfAABB.center(), longestAxis, fvs); } - aurora::shaders::queue_fog_volume_plane(fvs.m_verts, 0); + aurora::gfx::queue_fog_volume_plane(fvs.m_verts, 0); } else { - aurora::shaders::queue_fog_volume_plane({}, pass); + aurora::gfx::queue_fog_volume_plane({}, pass); } } else { CModelFlags flags; @@ -568,9 +568,9 @@ void CBooRenderer::ReallyRenderFogVolume(const zeus::CColor& color, const zeus:: CGraphics::ResolveSpareDepth(rect, 1); - aurora::shaders::queue_fog_volume_filter(color, true); + aurora::gfx::queue_fog_volume_filter(color, true); if (camInModel) - aurora::shaders::queue_fog_volume_filter(color, false); + aurora::gfx::queue_fog_volume_filter(color, false); // CGraphics::SetScissor(g_Viewport.x0_left, g_Viewport.x4_top, g_Viewport.x8_width, g_Viewport.xc_height); } @@ -589,7 +589,7 @@ void CBooRenderer::ReallyRenderFogVolume(const zeus::CColor& color, const zeus:: // } // } // x1b8_fogVolumeRamp = -// aurora::new_static_texture_2d(FOGVOL_RAMP_RES, FOGVOL_RAMP_RES, 1, aurora::shaders::TextureFormat::R32Float, +// aurora::new_static_texture_2d(FOGVOL_RAMP_RES, FOGVOL_RAMP_RES, 1, aurora::gfx::TextureFormat::R32Float, // {data[0].data(), FOGVOL_RAMP_RES * FOGVOL_RAMP_RES * 2}); //} // @@ -603,7 +603,7 @@ void CBooRenderer::ReallyRenderFogVolume(const zeus::CColor& color, const zeus:: // } // } // x220_sphereRamp = -// aurora::new_static_texture_2d(SPHERE_RAMP_RES, SPHERE_RAMP_RES, 1, aurora::shaders::TextureFormat::R8, +// aurora::new_static_texture_2d(SPHERE_RAMP_RES, SPHERE_RAMP_RES, 1, aurora::gfx::TextureFormat::R8, // {data[0].data(), SPHERE_RAMP_RES * SPHERE_RAMP_RES}); //} // @@ -644,7 +644,7 @@ void CBooRenderer::ReallyRenderFogVolume(const zeus::CColor& color, const zeus:: // m_scanLinesOddVBO = ctx.newStaticBuffer(boo::BufferUse::Vertex, verts.data(), sizeof(zeus::CVector3f), verts.size()); //} -std::shared_ptr 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; @@ -652,8 +652,7 @@ std::shared_ptr CBooRenderer::GetColorTexture(const zeus: std::array pixel{}; color.toRGBA8(pixel[0], pixel[1], pixel[2], pixel[3]); - auto tex = aurora::new_static_texture_2d(1, 1, 1, aurora::shaders::TextureFormat::RGBA8, {pixel.data(), pixel.size()}, - "Color Texture"sv); + auto tex = aurora::gfx::new_static_texture_2d(1, 1, 1, aurora::gfx::TextureFormat::RGBA8, pixel, "Color Texture"sv); m_colorTextures.emplace(color, tex); return tex; } @@ -681,20 +680,20 @@ CBooRenderer::CBooRenderer(IObjectStore& store, IFactory& resFac) m_staticEntropy = store.GetObj("RandomStaticEntropy"); 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); + m_clearTexture = + aurora::gfx::new_static_texture_2d(1, 1, 1, aurora::gfx::TextureFormat::RGBA8, clearPixel, "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); + m_blackTexture = + aurora::gfx::new_static_texture_2d(1, 1, 1, aurora::gfx::TextureFormat::RGBA8, blackPixel, "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); + m_whiteTexture = + aurora::gfx::new_static_texture_2d(1, 1, 1, aurora::gfx::TextureFormat::RGBA8, whitePixel, "White Texture"sv); -// GenerateFogVolumeRampTex(); + // GenerateFogVolumeRampTex(); // GenerateSphereRampTex(); - m_ballShadowId = aurora::new_render_texture(m_ballShadowIdW, m_ballShadowIdH, 1, 0, "Ball Shadow"); + m_ballShadowId = aurora::gfx::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 = aurora::gfx::new_render_texture(256, 256, 1, 0, "Reflection"); // x14c_reflectionTex = ctx.newRenderTexture(256, 256, boo::TextureClampMode::ClampToBlack, 1, 0); // GenerateScanLinesVBO(); // LoadThermoPalette(); diff --git a/Runtime/Graphics/CBooRenderer.hpp b/Runtime/Graphics/CBooRenderer.hpp index 8200876da..b816dd692 100644 --- a/Runtime/Graphics/CBooRenderer.hpp +++ b/Runtime/Graphics/CBooRenderer.hpp @@ -101,20 +101,20 @@ class CBooRenderer final : public IRenderer { // boo::ITextureS* xe4_blackTex = nullptr; bool xee_24_ : 1 = true; - std::shared_ptr m_clearTexture; - std::shared_ptr m_blackTexture; - std::shared_ptr 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; - std::shared_ptr x14c_reflectionTex; + std::shared_ptr x14c_reflectionTex; // boo::ITextureS* x150_mirrorRamp = nullptr; -// std::shared_ptr x1b8_fogVolumeRamp; - std::shared_ptr x220_sphereRamp; +// std::shared_ptr x1b8_fogVolumeRamp; + std::shared_ptr x220_sphereRamp; // TLockedToken m_thermoPaletteTex; -// std::shared_ptr x288_thermoPalette; +// std::shared_ptr x288_thermoPalette; // TLockedToken m_ballFadeTex; - std::shared_ptr m_ballFade; - std::shared_ptr m_ballShadowId; + std::shared_ptr m_ballFade; + std::shared_ptr m_ballShadowId; // boo::ObjToken m_scanLinesEvenVBO; // boo::ObjToken m_scanLinesOddVBO; int m_ballShadowIdW = 64; @@ -269,11 +269,11 @@ public: // const boo::ObjToken& GetScanLinesEvenVBO() const { return m_scanLinesEvenVBO; } // const boo::ObjToken& GetScanLinesOddVBO() const { return m_scanLinesOddVBO; } - 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; } + 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; } - std::shared_ptr GetColorTexture(const zeus::CColor& color); + std::shared_ptr GetColorTexture(const zeus::CColor& color); static void BindMainDrawTarget() { // CGraphics::g_BooMainCommandQueue->setRenderTarget(CGraphics::g_SpareTexture); diff --git a/Runtime/Graphics/CCubeModel.cpp b/Runtime/Graphics/CCubeModel.cpp index 302bd93cc..184eba72d 100644 --- a/Runtime/Graphics/CCubeModel.cpp +++ b/Runtime/Graphics/CCubeModel.cpp @@ -17,7 +17,7 @@ static u8* MemoryFromPartData(u8*& dataCur, const u32*& secSizeCur) { if (*secSizeCur != 0) { ret = dataCur; } - dataCur += hecl::SBig(*secSizeCur); + dataCur += SBig(*secSizeCur); ++secSizeCur; return ret; } @@ -28,17 +28,17 @@ CModel::CModel(std::unique_ptr in, u32 dataLen, IObjectStore* store) , x34_next(sThisFrameList) , x38_lastFrame(CGraphics::GetFrameCounter() - 2) { u8* data = x0_data.get(); - u32 flags = hecl::SBig(*reinterpret_cast(data + 8)); + u32 flags = SBig(*reinterpret_cast(data + 8)); u32 sectionSizeStart = 0x2c; - if (hecl::SBig(*reinterpret_cast(data + 4)) == 1) { + if (SBig(*reinterpret_cast(data + 4)) == 1) { sectionSizeStart = 0x28; } const u32* secSizeCur = reinterpret_cast(data + sectionSizeStart); s32 numMatSets = 1; - if (hecl::SBig(*reinterpret_cast(data + 4)) > 1) { - numMatSets = hecl::SBig(*reinterpret_cast(data + 0x28)); + if (SBig(*reinterpret_cast(data + 4)) > 1) { + numMatSets = SBig(*reinterpret_cast(data + 0x28)); } - u8* dataCur = data + ROUND_UP_32(sectionSizeStart + hecl::SBig(*reinterpret_cast(data + 0x24)) * 4); + u8* dataCur = data + ROUND_UP_32(sectionSizeStart + SBig(*reinterpret_cast(data + 0x24)) * 4); x18_matSets.reserve(numMatSets); for (s32 i = 0; i < numMatSets; ++i) { x18_matSets.emplace_back(static_cast(MemoryFromPartData(dataCur, secSizeCur))); @@ -48,54 +48,54 @@ CModel::CModel(std::unique_ptr in, u32 dataLen, IObjectStore* store) } /* Metaforce note: Due to padding in zeus types we need to convert these and store locally */ - u32 numVertices = hecl::SBig(*secSizeCur) / (sizeof(float) * 3); + u32 numVertices = SBig(*secSizeCur) / (sizeof(float) * 3); const u8* positions = MemoryFromPartData(dataCur, secSizeCur); for (u32 i = 0; i < numVertices; ++i) { const auto* pos = reinterpret_cast(positions + (i * (sizeof(float) * 3))); - m_positions.emplace_back(hecl::SBig(pos[0]), hecl::SBig(pos[1]), hecl::SBig(pos[2])); + m_positions.emplace_back(SBig(pos[0]), SBig(pos[1]), SBig(pos[2])); } - u32 numNormals = hecl::SBig(*secSizeCur); + u32 numNormals = SBig(*secSizeCur); numNormals /= ((flags & 2) == 0 ? sizeof(float) : sizeof(s16)) * 3; const u8* normals = MemoryFromPartData(dataCur, secSizeCur); for (u32 i = 0; i < numNormals; ++i) { if ((flags & 2) == 0) { const auto* norm = reinterpret_cast(normals + (i * (sizeof(float) * 3))); - m_normals.emplace_back(hecl::SBig(norm[0]), hecl::SBig(norm[1]), hecl::SBig(norm[2])); + m_normals.emplace_back(SBig(norm[0]), SBig(norm[1]), SBig(norm[2])); } else { const auto* norm = reinterpret_cast(normals + (i * (sizeof(s16) * 3))); - m_normals.emplace_back(hecl::SBig(norm[0]) / 32767.f, hecl::SBig(norm[1]) / 32767.f, - hecl::SBig(norm[2]) / 32767.f); + m_normals.emplace_back(SBig(norm[0]) / 32767.f, SBig(norm[1]) / 32767.f, + SBig(norm[2]) / 32767.f); } } - u32 numColors = hecl::SBig(*secSizeCur) / (sizeof(int)); + u32 numColors = SBig(*secSizeCur) / (sizeof(int)); const u8* vtxColors = MemoryFromPartData(dataCur, secSizeCur); for (u32 i = 0; i < numColors; ++i) { - const u32 col = hecl::SBig(*reinterpret_cast(vtxColors + (i * (sizeof(u32))))); + const u32 col = SBig(*reinterpret_cast(vtxColors + (i * (sizeof(u32))))); m_colors.emplace_back(zeus::CColor(zeus::Comp32(col))); } - u32 numFloatUVs = hecl::SBig(*reinterpret_cast(secSizeCur)) / (sizeof(float) * 2); + u32 numFloatUVs = SBig(*reinterpret_cast(secSizeCur)) / (sizeof(float) * 2); const u8* floatUVs = MemoryFromPartData(dataCur, secSizeCur); for (u32 i = 0; i < numFloatUVs; ++i) { const auto* norm = reinterpret_cast(floatUVs + (i * (sizeof(float) * 2))); - m_floatUVs.emplace_back(hecl::SBig(norm[0]), hecl::SBig(norm[1])); + m_floatUVs.emplace_back(SBig(norm[0]), SBig(norm[1])); } if ((flags & 4) != 0) { - u32 numShortUVs = hecl::SBig(*reinterpret_cast(secSizeCur)) / (sizeof(s16) * 2); + u32 numShortUVs = SBig(*reinterpret_cast(secSizeCur)) / (sizeof(s16) * 2); const u8* shortUVs = MemoryFromPartData(dataCur, secSizeCur); for (u32 i = 0; i < numShortUVs; ++i) { const auto* norm = reinterpret_cast(shortUVs + (i * (sizeof(s16) * 2))); - m_shortUVs.emplace_back(std::array{hecl::SBig(norm[0]), hecl::SBig(norm[1])}); + m_shortUVs.emplace_back(std::array{SBig(norm[0]), SBig(norm[1])}); } } const u8* surfaceInfo = MemoryFromPartData(dataCur, secSizeCur); - u32 surfaceCount = hecl::SBig(*reinterpret_cast(surfaceInfo)); + u32 surfaceCount = SBig(*reinterpret_cast(surfaceInfo)); x8_surfaces.reserve(surfaceCount); for (u32 i = 0; i < surfaceCount; ++i) { @@ -108,8 +108,8 @@ CModel::CModel(std::unique_ptr in, u32 dataLen, IObjectStore* store) const float* bounds = reinterpret_cast(data + 12); zeus::CAABox aabox = zeus::skNullBox; - aabox.min = {hecl::SBig(bounds[0]), hecl::SBig(bounds[1]), hecl::SBig(bounds[2])}; - aabox.max = {hecl::SBig(bounds[3]), hecl::SBig(bounds[4]), hecl::SBig(bounds[5])}; + aabox.min = {SBig(bounds[0]), SBig(bounds[1]), SBig(bounds[2])}; + aabox.max = {SBig(bounds[3]), SBig(bounds[4]), SBig(bounds[5])}; /* This constructor has been changed from the original to take into account platform differences */ x28_modelInst = @@ -222,10 +222,10 @@ CCubeMaterial CCubeModel::GetMaterialByIndex(u32 idx) { const u8* matData = x0_modelInstance.GetMaterialPointer(); matData += (x1c_textures->size() + 1) * 4; if (idx != 0) { - materialOffset = hecl::SBig(*reinterpret_cast(matData + (idx * 4))); + materialOffset = SBig(*reinterpret_cast(matData + (idx * 4))); } - u32 materialCount = hecl::SBig(*reinterpret_cast(matData)); + u32 materialCount = SBig(*reinterpret_cast(matData)); return CCubeMaterial(matData + materialOffset + (materialCount * 4) + 4); } @@ -238,10 +238,10 @@ void CCubeModel::UnlockTextures() { void CCubeModel::MakeTexturesFromMats(const u8* ptr, std::vector>& textures, IObjectStore* store, bool b1) { const u32* curId = reinterpret_cast(ptr + 4); - u32 textureCount = hecl::SBig(*reinterpret_cast(ptr)); + u32 textureCount = SBig(*reinterpret_cast(ptr)); textures.reserve(textureCount); for (u32 i = 0; i < textureCount; ++i) { - textures.emplace_back(store->GetObj({FOURCC('TXTR'), hecl::SBig(curId[i])})); + textures.emplace_back(store->GetObj({FOURCC('TXTR'), SBig(curId[i])})); if (!b1 && textures.back().IsNull()) { textures.back().GetObj(); diff --git a/Runtime/Graphics/CCubeModel.hpp b/Runtime/Graphics/CCubeModel.hpp index 58967304b..c91e31afb 100644 --- a/Runtime/Graphics/CCubeModel.hpp +++ b/Runtime/Graphics/CCubeModel.hpp @@ -186,16 +186,16 @@ public: [[nodiscard]] u32 GetCompressedBlend() { const u32* ptr = reinterpret_cast(x0_data[(GetTextureCount() * 4) + 16]); if (IsFlagSet(EStateFlags::KonstEnabled)) { - ptr += hecl::SBig(*ptr) + 1; + ptr += SBig(*ptr) + 1; } - return hecl::SBig(*ptr); + return SBig(*ptr); } - [[nodiscard]] EStateFlags GetFlags() const { return EStateFlags(hecl::SBig(*reinterpret_cast(x0_data))); } + [[nodiscard]] EStateFlags GetFlags() const { return EStateFlags(SBig(*reinterpret_cast(x0_data))); } [[nodiscard]] bool IsFlagSet(EStateFlags flag) const { return True(GetFlags() & flag); } [[nodiscard]] u32 GetUsedTextureSlots() const { return static_cast(GetFlags()) >> 16; } - [[nodiscard]] u32 GetTextureCount() const { return hecl::SBig(*reinterpret_cast(&x0_data[4])); } - [[nodiscard]] u32 GetVertexDesc() const { return hecl::SBig(*reinterpret_cast(&x0_data[(GetTextureCount() * 4) + 8])); } + [[nodiscard]] u32 GetTextureCount() const { return SBig(*reinterpret_cast(&x0_data[4])); } + [[nodiscard]] u32 GetVertexDesc() const { return SBig(*reinterpret_cast(&x0_data[(GetTextureCount() * 4) + 8])); } }; #pragma endregion diff --git a/Runtime/Graphics/CGraphics.cpp b/Runtime/Graphics/CGraphics.cpp index 8b64a9e9e..2e4c84798 100644 --- a/Runtime/Graphics/CGraphics.cpp +++ b/Runtime/Graphics/CGraphics.cpp @@ -11,7 +11,7 @@ namespace metaforce { CGraphics::CProjectionState CGraphics::g_Proj; -CGraphics::CFogState CGraphics::g_Fog; +CFogState CGraphics::g_Fog; std::array CGraphics::g_ColorRegs{}; float CGraphics::g_ProjAspect = 1.f; u32 CGraphics::g_NumLightsActive = 0; @@ -156,7 +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()); + aurora::gfx::update_model_view(g_GXModelView.toMatrix4f(), g_GXModelViewInvXpose.toMatrix4f()); } void CGraphics::SetModelMatrix(const zeus::CTransform& xf) { @@ -323,7 +323,7 @@ void CGraphics::FlushProjection() { } else { // Convert and load ortho } - aurora::shaders::update_projection(GetPerspectiveProjectionMatrix(true)); + aurora::gfx::update_projection(GetPerspectiveProjectionMatrix(true)); } zeus::CVector2i CGraphics::ProjectPoint(const zeus::CVector3f& point) { @@ -423,17 +423,17 @@ void CGraphics::SetViewport(int leftOff, int bottomOff, int width, int height) { CachedVP.position[1] = bottomOff; CachedVP.size[0] = width; CachedVP.size[1] = height; - aurora::shaders::set_viewport(CachedVP, g_CachedDepthRange[0], g_CachedDepthRange[1]); + aurora::gfx::set_viewport(CachedVP, g_CachedDepthRange[0], g_CachedDepthRange[1]); } void CGraphics::SetScissor(int leftOff, int bottomOff, int width, int height) { - aurora::shaders::set_scissor(leftOff, bottomOff, width, height); + aurora::gfx::set_scissor(leftOff, bottomOff, width, height); } void CGraphics::SetDepthRange(float znear, float zfar) { g_CachedDepthRange[0] = znear; g_CachedDepthRange[1] = zfar; - aurora::shaders::set_viewport(CachedVP, g_CachedDepthRange[0], g_CachedDepthRange[1]); + aurora::gfx::set_viewport(CachedVP, g_CachedDepthRange[0], g_CachedDepthRange[1]); } CTimeProvider* CGraphics::g_ExternalTimeProvider = nullptr; diff --git a/Runtime/Graphics/CGraphics.hpp b/Runtime/Graphics/CGraphics.hpp index d1ee59308..2791af843 100644 --- a/Runtime/Graphics/CGraphics.hpp +++ b/Runtime/Graphics/CGraphics.hpp @@ -20,77 +20,10 @@ #include #include -#include "aurora.h" -#include "aurora_shaders.h" +#include 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_dynamic_texture_2d(uint32_t width, uint32_t height, uint32_t mips, - aurora::shaders::TextureFormat format, - std::string_view label) { - rust::Str rlabel{label.data(), label.size()}; - auto ref = aurora::shaders::create_dynamic_texture_2d(width, height, mips, format, 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; @@ -160,8 +93,6 @@ enum class ERglAlphaFunc { enum class ERglAlphaOp { And = 0, Or = 1, Xor = 2, XNor = 3 }; -using ERglFogMode = aurora::shaders::FogMode; - struct SViewport { u32 x0_left; u32 x4_top; @@ -200,7 +131,7 @@ struct SClipScreenRect { , x20_uvYMin(uvYMin) , x24_uvYMax(uvYMax) {} - SClipScreenRect(const aurora::shaders::ClipRect& rect) { + SClipScreenRect(const aurora::gfx::ClipRect& rect) { x4_left = rect.x; x8_top = rect.y; xc_width = rect.width; @@ -298,15 +229,6 @@ public: float x18_far; }; - 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; static CFogState g_Fog; @@ -435,12 +357,12 @@ public: // g_BooMainCommandQueue->setShaderDataBinding(binding); // } static void ResolveSpareTexture(const SClipScreenRect& rect, int bindIdx = 0, bool clearDepth = false) { - aurora::shaders::resolve_color({rect.x4_left, rect.x8_top, rect.xc_width, rect.x10_height}, bindIdx, clearDepth); + aurora::gfx::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) { - aurora::shaders::resolve_depth({rect.x4_left, rect.x8_top, rect.xc_width, rect.x10_height}, bindIdx); + aurora::gfx::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); } diff --git a/Runtime/Graphics/CLineRenderer.cpp b/Runtime/Graphics/CLineRenderer.cpp index 1c3f6c1ef..52e46a412 100644 --- a/Runtime/Graphics/CLineRenderer.cpp +++ b/Runtime/Graphics/CLineRenderer.cpp @@ -20,7 +20,7 @@ void CLineRenderer::Shutdown() { //hecl::VertexBufferPool CLineRenderer::s_vertPoolNoTex = {}; //hecl::UniformBufferPool CLineRenderer::s_uniformPool = {}; -CLineRenderer::CLineRenderer(EPrimitiveMode mode, u32 maxVerts, const std::shared_ptr& 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(); diff --git a/Runtime/Graphics/CLineRenderer.hpp b/Runtime/Graphics/CLineRenderer.hpp index bc3b88f0f..0394090e9 100644 --- a/Runtime/Graphics/CLineRenderer.hpp +++ b/Runtime/Graphics/CLineRenderer.hpp @@ -35,7 +35,7 @@ public: struct SDrawUniform { zeus::CColor moduColor; - CGraphics::CFogState fog; + CFogState fog; }; private: @@ -72,7 +72,7 @@ public: // hecl::UniformBufferPool::Token m_uniformBuf; // std::array, 2> m_shaderBind; - CLineRenderer(EPrimitiveMode mode, u32 maxVerts, const std::shared_ptr& texture, bool additive, + CLineRenderer(EPrimitiveMode mode, u32 maxVerts, const std::shared_ptr& texture, bool additive, bool zTest = false, bool zGEqual = false); CLineRenderer(CLineRenderer&&) = default; diff --git a/Runtime/Graphics/CModel.hpp b/Runtime/Graphics/CModel.hpp index a580bb86c..2977f32f4 100644 --- a/Runtime/Graphics/CModel.hpp +++ b/Runtime/Graphics/CModel.hpp @@ -239,16 +239,16 @@ public: static void EnsureViewDepStateCached(const CBooModel& model, const CBooSurface* surf, zeus::CMatrix4f* mtxsOut, float& alphaOut); - static inline std::shared_ptr g_shadowMap; + static inline std::shared_ptr g_shadowMap; static inline zeus::CTransform g_shadowTexXf; - static void EnableShadowMaps(const std::shared_ptr& map, const zeus::CTransform& texXf); + static void EnableShadowMaps(const std::shared_ptr& map, const zeus::CTransform& texXf); static void DisableShadowMaps(); - static inline std::shared_ptr g_disintegrateTexture; - static void SetDisintegrateTexture(const std::shared_ptr& map) { g_disintegrateTexture = map; } + static inline std::shared_ptr g_disintegrateTexture; + static void SetDisintegrateTexture(const std::shared_ptr& map) { g_disintegrateTexture = map; } - static inline std::shared_ptr g_reflectionCube; - static void SetReflectionCube(const std::shared_ptr& 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; } diff --git a/Runtime/Graphics/CModelBoo.cpp b/Runtime/Graphics/CModelBoo.cpp index 26286b4b0..9c7bb2558 100644 --- a/Runtime/Graphics/CModelBoo.cpp +++ b/Runtime/Graphics/CModelBoo.cpp @@ -135,7 +135,7 @@ void CBooModel::EnsureViewDepStateCached(const CBooModel& model, const CBooSurfa } } -void CBooModel::EnableShadowMaps(const std::shared_ptr& map, const zeus::CTransform& texXf) { +void CBooModel::EnableShadowMaps(const std::shared_ptr& map, const zeus::CTransform& texXf) { g_shadowMap = map; g_shadowTexXf = texXf; } diff --git a/Runtime/Graphics/CMoviePlayer.cpp b/Runtime/Graphics/CMoviePlayer.cpp index 91fbf49bf..236416c58 100644 --- a/Runtime/Graphics/CMoviePlayer.cpp +++ b/Runtime/Graphics/CMoviePlayer.cpp @@ -44,50 +44,50 @@ void CMoviePlayer::Initialize() { TjHandle = tjInitDecompress(); } void CMoviePlayer::Shutdown() { tjDestroy(TjHandle); } void CMoviePlayer::THPHeader::swapBig() { - magic = hecl::SBig(magic); - version = hecl::SBig(version); - maxBufferSize = hecl::SBig(maxBufferSize); - maxAudioSamples = hecl::SBig(maxAudioSamples); - fps = hecl::SBig(fps); - numFrames = hecl::SBig(numFrames); - firstFrameSize = hecl::SBig(firstFrameSize); - dataSize = hecl::SBig(dataSize); - componentDataOffset = hecl::SBig(componentDataOffset); - offsetsDataOffset = hecl::SBig(offsetsDataOffset); - firstFrameOffset = hecl::SBig(firstFrameOffset); - lastFrameOffset = hecl::SBig(lastFrameOffset); + magic = SBig(magic); + version = SBig(version); + maxBufferSize = SBig(maxBufferSize); + maxAudioSamples = SBig(maxAudioSamples); + fps = SBig(fps); + numFrames = SBig(numFrames); + firstFrameSize = SBig(firstFrameSize); + dataSize = SBig(dataSize); + componentDataOffset = SBig(componentDataOffset); + offsetsDataOffset = SBig(offsetsDataOffset); + firstFrameOffset = SBig(firstFrameOffset); + lastFrameOffset = SBig(lastFrameOffset); } -void CMoviePlayer::THPComponents::swapBig() { numComponents = hecl::SBig(numComponents); } +void CMoviePlayer::THPComponents::swapBig() { numComponents = SBig(numComponents); } void CMoviePlayer::THPVideoInfo::swapBig() { - width = hecl::SBig(width); - height = hecl::SBig(height); + width = SBig(width); + height = SBig(height); } void CMoviePlayer::THPAudioInfo::swapBig() { - numChannels = hecl::SBig(numChannels); - sampleRate = hecl::SBig(sampleRate); - numSamples = hecl::SBig(numSamples); + numChannels = SBig(numChannels); + sampleRate = SBig(sampleRate); + numSamples = SBig(numSamples); } void CMoviePlayer::THPFrameHeader::swapBig() { - nextSize = hecl::SBig(nextSize); - prevSize = hecl::SBig(prevSize); - imageSize = hecl::SBig(imageSize); - audioSize = hecl::SBig(audioSize); + nextSize = SBig(nextSize); + prevSize = SBig(prevSize); + imageSize = SBig(imageSize); + audioSize = SBig(audioSize); } void CMoviePlayer::THPAudioFrameHeader::swapBig() { - channelSize = hecl::SBig(channelSize); - numSamples = hecl::SBig(numSamples); + channelSize = SBig(channelSize); + numSamples = SBig(numSamples); for (int i = 0; i < 2; ++i) { for (int j = 0; j < 8; ++j) { - channelCoefs[i][j][0] = hecl::SBig(channelCoefs[i][j][0]); - channelCoefs[i][j][1] = hecl::SBig(channelCoefs[i][j][1]); + channelCoefs[i][j][0] = SBig(channelCoefs[i][j][0]); + channelCoefs[i][j][1] = SBig(channelCoefs[i][j][1]); } - channelPrevs[i][0] = hecl::SBig(channelPrevs[i][0]); - channelPrevs[i][1] = hecl::SBig(channelPrevs[i][1]); + channelPrevs[i][0] = SBig(channelPrevs[i][0]); + channelPrevs[i][1] = SBig(channelPrevs[i][1]); } } @@ -187,29 +187,29 @@ CMoviePlayer::CMoviePlayer(const char* path, float preLoadSeconds, bool loop, bo CTHPTextureSet& set = x80_textures.emplace_back(); if (deinterlace) { /* metaforce addition: this way interlaced THPs don't look horrible */ - set.Y[0] = aurora::new_dynamic_texture_2d(x6c_videoInfo.width, x6c_videoInfo.height / 2, 1, - aurora::shaders::TextureFormat::R8, - fmt::format(FMT_STRING("Movie {} Texture Set {} Y[0]"), path, i)); - set.Y[1] = aurora::new_dynamic_texture_2d(x6c_videoInfo.width, x6c_videoInfo.height / 2, 1, - aurora::shaders::TextureFormat::R8, - fmt::format(FMT_STRING("Movie {} Texture Set {} Y[1]"), path, i)); - set.U = aurora::new_dynamic_texture_2d(x6c_videoInfo.width / 2, x6c_videoInfo.height / 2, 1, - aurora::shaders::TextureFormat::R8, - fmt::format(FMT_STRING("Movie {} Texture Set {} U"), path, i)); - set.V = aurora::new_dynamic_texture_2d(x6c_videoInfo.width / 2, x6c_videoInfo.height / 2, 1, - aurora::shaders::TextureFormat::R8, - fmt::format(FMT_STRING("Movie {} Texture Set {} V"), path, i)); + set.Y[0] = aurora::gfx::new_dynamic_texture_2d(x6c_videoInfo.width, x6c_videoInfo.height / 2, 1, + aurora::gfx::TextureFormat::R8, + fmt::format(FMT_STRING("Movie {} Texture Set {} Y[0]"), path, i)); + set.Y[1] = aurora::gfx::new_dynamic_texture_2d(x6c_videoInfo.width, x6c_videoInfo.height / 2, 1, + aurora::gfx::TextureFormat::R8, + fmt::format(FMT_STRING("Movie {} Texture Set {} Y[1]"), path, i)); + set.U = aurora::gfx::new_dynamic_texture_2d(x6c_videoInfo.width / 2, x6c_videoInfo.height / 2, 1, + aurora::gfx::TextureFormat::R8, + fmt::format(FMT_STRING("Movie {} Texture Set {} U"), path, i)); + set.V = aurora::gfx::new_dynamic_texture_2d(x6c_videoInfo.width / 2, x6c_videoInfo.height / 2, 1, + aurora::gfx::TextureFormat::R8, + fmt::format(FMT_STRING("Movie {} Texture Set {} V"), path, i)); } else { /* normal progressive presentation */ - set.Y[0] = aurora::new_dynamic_texture_2d(x6c_videoInfo.width, x6c_videoInfo.height, 1, - aurora::shaders::TextureFormat::R8, - fmt::format(FMT_STRING("Movie {} Texture Set {} Y"), path, i)); - set.U = aurora::new_dynamic_texture_2d(x6c_videoInfo.width / 2, x6c_videoInfo.height / 2, 1, - aurora::shaders::TextureFormat::R8, - fmt::format(FMT_STRING("Movie {} Texture Set {} U"), path, i)); - set.V = aurora::new_dynamic_texture_2d(x6c_videoInfo.width / 2, x6c_videoInfo.height / 2, 1, - aurora::shaders::TextureFormat::R8, - fmt::format(FMT_STRING("Movie {} Texture Set {} V"), path, i)); + set.Y[0] = aurora::gfx::new_dynamic_texture_2d(x6c_videoInfo.width, x6c_videoInfo.height, 1, + aurora::gfx::TextureFormat::R8, + fmt::format(FMT_STRING("Movie {} Texture Set {} Y"), path, i)); + set.U = aurora::gfx::new_dynamic_texture_2d(x6c_videoInfo.width / 2, x6c_videoInfo.height / 2, 1, + aurora::gfx::TextureFormat::R8, + fmt::format(FMT_STRING("Movie {} Texture Set {} U"), path, i)); + set.V = aurora::gfx::new_dynamic_texture_2d(x6c_videoInfo.width / 2, x6c_videoInfo.height / 2, 1, + aurora::gfx::TextureFormat::R8, + fmt::format(FMT_STRING("Movie {} Texture Set {} V"), path, i)); } if (xf4_25_hasAudio) set.audioBuf.reset(new s16[x28_thpHead.maxAudioSamples * 2]); @@ -373,8 +373,8 @@ void CMoviePlayer::DrawFrame() { /* draw appropriate field */ CTHPTextureSet& tex = x80_textures[xd0_drawTexSlot]; - aurora::shaders::queue_movie_player(tex.Y[m_deinterlace ? (xfc_fieldIndex != 0) : 0]->ref, tex.U->ref, tex.V->ref, - zeus::skWhite, m_hpad, m_vpad); + aurora::gfx::queue_movie_player(tex.Y[m_deinterlace ? (xfc_fieldIndex != 0) : 0]->ref, tex.U->ref, tex.V->ref, + zeus::skWhite, m_hpad, m_vpad); /* ensure second field is being displayed by VI to signal advance * (faked in metaforce with continuous xor) */ @@ -495,18 +495,18 @@ void CMoviePlayer::DecodeFromRead(const void* data) { memcpy(buffer.get() + x6c_videoInfo.width * y, m_yuvBuf.get() + x6c_videoInfo.width * (y * 2), x6c_videoInfo.width); } - aurora::shaders::write_texture(tex.Y[0]->ref, {buffer.get(), planeSizeHalf}); + aurora::gfx::write_texture(tex.Y[0]->ref, {buffer.get(), planeSizeHalf}); for (unsigned y = 0; y < x6c_videoInfo.height / 2; ++y) { memcpy(buffer.get() + x6c_videoInfo.width * y, m_yuvBuf.get() + x6c_videoInfo.width * (y * 2 + 1), x6c_videoInfo.width); } - aurora::shaders::write_texture(tex.Y[1]->ref, {buffer.get(), planeSizeHalf}); + aurora::gfx::write_texture(tex.Y[1]->ref, {buffer.get(), planeSizeHalf}); } else { /* Direct planar load */ - aurora::shaders::write_texture(tex.Y[0]->ref, {m_yuvBuf.get(), planeSize}); + aurora::gfx::write_texture(tex.Y[0]->ref, {m_yuvBuf.get(), planeSize}); } - aurora::shaders::write_texture(tex.U->ref, {m_yuvBuf.get() + planeSize, planeSizeQuarter}); - aurora::shaders::write_texture(tex.V->ref, {m_yuvBuf.get() + planeSize + planeSizeQuarter, planeSizeQuarter}); + aurora::gfx::write_texture(tex.U->ref, {m_yuvBuf.get() + planeSize, planeSizeQuarter}); + aurora::gfx::write_texture(tex.V->ref, {m_yuvBuf.get() + planeSize + planeSizeQuarter, planeSizeQuarter}); break; } @@ -538,7 +538,7 @@ void CMoviePlayer::ReadCompleted() { /* store params of next read operation */ xb4_nextReadOff += xb0_nextReadSize; - xb0_nextReadSize = hecl::SBig(frameHeader->nextSize); + xb0_nextReadSize = SBig(frameHeader->nextSize); ++xc0_curLoadFrame; if (xc0_curLoadFrame == xf0_preLoadFrames) { diff --git a/Runtime/Graphics/CMoviePlayer.hpp b/Runtime/Graphics/CMoviePlayer.hpp index ff4df7f8a..dcc9c7f69 100644 --- a/Runtime/Graphics/CMoviePlayer.hpp +++ b/Runtime/Graphics/CMoviePlayer.hpp @@ -69,9 +69,9 @@ private: }; struct CTHPTextureSet { - std::shared_ptr Y[2]; - std::shared_ptr U; - std::shared_ptr V; + std::shared_ptr Y[2]; + std::shared_ptr U; + std::shared_ptr V; u32 playedSamples = 0; u32 audioSamples = 0; std::unique_ptr audioBuf; diff --git a/Runtime/Graphics/CPVSAreaSet.cpp b/Runtime/Graphics/CPVSAreaSet.cpp index 450b661d9..085d0c8d5 100644 --- a/Runtime/Graphics/CPVSAreaSet.cpp +++ b/Runtime/Graphics/CPVSAreaSet.cpp @@ -1,4 +1,5 @@ #include "Runtime/Graphics/CPVSAreaSet.hpp" +#include "IOStreams.hpp" namespace metaforce { diff --git a/Runtime/Graphics/CPVSVisOctree.cpp b/Runtime/Graphics/CPVSVisOctree.cpp index 37391418d..5f58e334a 100644 --- a/Runtime/Graphics/CPVSVisOctree.cpp +++ b/Runtime/Graphics/CPVSVisOctree.cpp @@ -1,4 +1,5 @@ #include "Runtime/Graphics/CPVSVisOctree.hpp" +#include "IOStreams.hpp" #include diff --git a/Runtime/Graphics/CPVSVisSet.cpp b/Runtime/Graphics/CPVSVisSet.cpp index f8180a56d..674f612a4 100644 --- a/Runtime/Graphics/CPVSVisSet.cpp +++ b/Runtime/Graphics/CPVSVisSet.cpp @@ -54,7 +54,7 @@ void CPVSVisSet::SetTestPoint(const CPVSVisOctree& octree, const zeus::CVector3f if (nextNodeRel) { /* Skip node data */ if (!(curNode & 0x60)) { - octCur += hecl::SBig(reinterpret_cast(octCur)[nextNodeRel - 1]); + octCur += SBig(reinterpret_cast(octCur)[nextNodeRel - 1]); } else if (curNode & 0x20) { octCur += *(octCur + nextNodeRel - 1); } else { diff --git a/Runtime/Graphics/CTexture.hpp b/Runtime/Graphics/CTexture.hpp index de1f237b1..1e391e1ad 100644 --- a/Runtime/Graphics/CTexture.hpp +++ b/Runtime/Graphics/CTexture.hpp @@ -33,8 +33,8 @@ private: u16 x6_h; u32 x8_mips; // boo::ObjToken m_booTex; - std::shared_ptr m_tex; - std::shared_ptr m_paletteTex; + std::shared_ptr m_tex; + std::shared_ptr m_paletteTex; std::unique_ptr m_otex; EFontType m_ftype = EFontType::None; const CTextureInfo* m_textureInfo; @@ -70,11 +70,11 @@ public: u16 GetHeight() const { return x6_h; } u32 GetNumMips() const { return x8_mips; } void Load(int slot, EClampMode clamp) const; - const std::shared_ptr& GetTexture() const { return m_tex; } + 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; } + const std::shared_ptr& GetPaletteTexture() const { return m_paletteTex; } std::unique_ptr BuildMemoryCardTex(u32& sizeOut, ETexelFormat& fmtOut, std::unique_ptr& paletteOut) const; - const std::shared_ptr& 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 3c359b14f..5e1a64cff 100644 --- a/Runtime/Graphics/CTextureBoo.cpp +++ b/Runtime/Graphics/CTextureBoo.cpp @@ -111,8 +111,8 @@ void CTexture::BuildI4FromGCN(CInputStream& in, std::string_view label) { } } - m_tex = aurora::new_static_texture_2d(x4_w, x6_h, x8_mips, aurora::shaders::TextureFormat::RGBA8, - {reinterpret_cast(buf.get()), texelCount * 4}, label); + m_tex = aurora::gfx::new_static_texture_2d(x4_w, x6_h, x8_mips, aurora::gfx::TextureFormat::RGBA8, + {reinterpret_cast(buf.get()), texelCount * 4}, label); } void CTexture::BuildI8FromGCN(CInputStream& in, std::string_view label) { @@ -151,8 +151,8 @@ void CTexture::BuildI8FromGCN(CInputStream& in, std::string_view label) { } } - m_tex = aurora::new_static_texture_2d(x4_w, x6_h, x8_mips, aurora::shaders::TextureFormat::RGBA8, - {reinterpret_cast(buf.get()), texelCount * 4}, label); + m_tex = aurora::gfx::new_static_texture_2d(x4_w, x6_h, x8_mips, aurora::gfx::TextureFormat::RGBA8, + {reinterpret_cast(buf.get()), texelCount * 4}, label); } void CTexture::BuildIA4FromGCN(CInputStream& in, std::string_view label) { @@ -192,8 +192,8 @@ void CTexture::BuildIA4FromGCN(CInputStream& in, std::string_view label) { } } - m_tex = aurora::new_static_texture_2d(x4_w, x6_h, x8_mips, aurora::shaders::TextureFormat::RGBA8, - {reinterpret_cast(buf.get()), texelCount * 4}, label); + m_tex = aurora::gfx::new_static_texture_2d(x4_w, x6_h, x8_mips, aurora::gfx::TextureFormat::RGBA8, + {reinterpret_cast(buf.get()), texelCount * 4}, label); } void CTexture::BuildIA8FromGCN(CInputStream& in, std::string_view label) { @@ -233,8 +233,8 @@ void CTexture::BuildIA8FromGCN(CInputStream& in, std::string_view label) { } } - m_tex = aurora::new_static_texture_2d(x4_w, x6_h, x8_mips, aurora::shaders::TextureFormat::RGBA8, - {reinterpret_cast(buf.get()), texelCount * 4}, label); + m_tex = aurora::gfx::new_static_texture_2d(x4_w, x6_h, x8_mips, aurora::gfx::TextureFormat::RGBA8, + {reinterpret_cast(buf.get()), texelCount * 4}, label); } static std::vector DecodePalette(int numEntries, CInputStream& in) { @@ -312,8 +312,8 @@ void CTexture::BuildC4FromGCN(CInputStream& in, std::string_view label) { } } - m_tex = aurora::new_static_texture_2d(x4_w, x6_h, x8_mips, aurora::shaders::TextureFormat::RGBA8, - {reinterpret_cast(buf.get()), texelCount * 4}, label); + m_tex = aurora::gfx::new_static_texture_2d(x4_w, x6_h, x8_mips, aurora::gfx::TextureFormat::RGBA8, + {reinterpret_cast(buf.get()), texelCount * 4}, label); } void CTexture::BuildC8FromGCN(CInputStream& in, std::string_view label) { @@ -350,8 +350,8 @@ void CTexture::BuildC8FromGCN(CInputStream& in, std::string_view label) { } } - m_tex = aurora::new_static_texture_2d(x4_w, x6_h, x8_mips, aurora::shaders::TextureFormat::RGBA8, - {reinterpret_cast(buf.get()), texelCount * 4}, label); + m_tex = aurora::gfx::new_static_texture_2d(x4_w, x6_h, x8_mips, aurora::gfx::TextureFormat::RGBA8, + {reinterpret_cast(buf.get()), texelCount * 4}, label); } void CTexture::BuildC14X2FromGCN(CInputStream& in, std::string_view label) { @@ -393,8 +393,8 @@ void CTexture::BuildRGB565FromGCN(CInputStream& in, std::string_view label) { } } - m_tex = aurora::new_static_texture_2d(x4_w, x6_h, x8_mips, aurora::shaders::TextureFormat::RGBA8, - {reinterpret_cast(buf.get()), texelCount * 4}, label); + m_tex = aurora::gfx::new_static_texture_2d(x4_w, x6_h, x8_mips, aurora::gfx::TextureFormat::RGBA8, + {reinterpret_cast(buf.get()), texelCount * 4}, label); } void CTexture::BuildRGB5A3FromGCN(CInputStream& in, std::string_view label) { @@ -439,8 +439,8 @@ void CTexture::BuildRGB5A3FromGCN(CInputStream& in, std::string_view label) { } } - m_tex = aurora::new_static_texture_2d(x4_w, x6_h, x8_mips, aurora::shaders::TextureFormat::RGBA8, - {reinterpret_cast(buf.get()), texelCount * 4}, label); + m_tex = aurora::gfx::new_static_texture_2d(x4_w, x6_h, x8_mips, aurora::gfx::TextureFormat::RGBA8, + {reinterpret_cast(buf.get()), texelCount * 4}, label); } void CTexture::BuildRGBA8FromGCN(CInputStream& in, std::string_view label) { @@ -484,8 +484,8 @@ void CTexture::BuildRGBA8FromGCN(CInputStream& in, std::string_view label) { } } - m_tex = aurora::new_static_texture_2d(x4_w, x6_h, x8_mips, aurora::shaders::TextureFormat::RGBA8, - {reinterpret_cast(buf.get()), texelCount * 4}, label); + m_tex = aurora::gfx::new_static_texture_2d(x4_w, x6_h, x8_mips, aurora::gfx::TextureFormat::RGBA8, + {reinterpret_cast(buf.get()), texelCount * 4}, label); } void CTexture::BuildDXT1FromGCN(CInputStream& in, std::string_view label) { @@ -532,8 +532,8 @@ void CTexture::BuildDXT1FromGCN(CInputStream& in, std::string_view label) { } } - m_tex = aurora::new_static_texture_2d(x4_w, x6_h, x8_mips, aurora::shaders::TextureFormat::DXT1, - {reinterpret_cast(buf.get()), blockCount * 8}, label); + m_tex = aurora::gfx::new_static_texture_2d(x4_w, x6_h, x8_mips, aurora::gfx::TextureFormat::DXT1, + {reinterpret_cast(buf.get()), blockCount * 8}, label); } void CTexture::BuildRGBA8(const void* data, size_t length, std::string_view label) { @@ -542,8 +542,8 @@ void CTexture::BuildRGBA8(const void* data, size_t length, std::string_view labe if (expectedSize > length) Log.report(logvisor::Fatal, FMT_STRING("insufficient TXTR length ({}/{})"), length, expectedSize); - m_tex = aurora::new_static_texture_2d(x4_w, x6_h, x8_mips, aurora::shaders::TextureFormat::RGBA8, - {reinterpret_cast(data), expectedSize}, label); + m_tex = aurora::gfx::new_static_texture_2d(x4_w, x6_h, x8_mips, aurora::gfx::TextureFormat::RGBA8, + {reinterpret_cast(data), expectedSize}, label); } void CTexture::BuildC8(const void* data, size_t length, std::string_view label) { @@ -554,10 +554,10 @@ void CTexture::BuildC8(const void* data, size_t length, std::string_view label) 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); + m_paletteTex = aurora::gfx::new_static_texture_2d(nentries, 1, 1, aurora::gfx::TextureFormat::RGBA8, + {paletteTexels, nentries * 4}, label); + m_tex = aurora::gfx::new_static_texture_2d(x4_w, x6_h, x8_mips, aurora::gfx::TextureFormat::R8, {texels, texelCount}, + label); } void CTexture::BuildC8Font(const void* data, EFontType ftype, std::string_view label) { @@ -660,13 +660,13 @@ void CTexture::BuildC8Font(const void* data, EFontType ftype, std::string_view l } 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); + m_tex = aurora::gfx::new_static_texture_2d(x4_w, x6_h, x8_mips, aurora::gfx::TextureFormat::DXT1, + {reinterpret_cast(data), length}, label); } 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); + m_tex = aurora::gfx::new_static_texture_2d(x4_w, x6_h, x8_mips, aurora::gfx::TextureFormat::DXT3, + {reinterpret_cast(data), length}, label); } static std::string_view TextureFormatString(ETexelFormat format) { @@ -754,14 +754,14 @@ CTexture::CTexture(std::unique_ptr&& in, u32 length, bool otex, const CTex BuildRGBA8FromGCN(r, label); break; case ETexelFormat::CMPR: - if (aurora::get_dxt_compression_supported()) { + if (aurora::gfx::get_dxt_compression_supported()) { BuildDXT1FromGCN(r, label); } else { Log.report(logvisor::Error, FMT_STRING("BC/DXT1 compression is not supported on your GPU, unable to load {}"), label); x0_fmt = ETexelFormat::RGBA8PC; x8_mips = 1; - std::unique_ptr data= std::make_unique(x4_w * x6_h * 4); + std::unique_ptr data = std::make_unique(x4_w * x6_h * 4); /* Build a fake texture to use */ for (u32 i = 0; i < (x4_w * x6_h) * 4; i += 4) { data[i + 0] = 0xFF; @@ -769,8 +769,9 @@ CTexture::CTexture(std::unique_ptr&& in, u32 length, bool otex, const CTex data[i + 2] = 0xFF; data[i + 3] = 0xFF; } - m_tex = aurora::new_static_texture_2d(x4_w, x6_h, x8_mips, aurora::shaders::TextureFormat::RGBA8, - {reinterpret_cast(data.get()), (x4_w * x6_h * 4ul)}, label); + m_tex = aurora::gfx::new_static_texture_2d(x4_w, x6_h, x8_mips, aurora::gfx::TextureFormat::RGBA8, + {reinterpret_cast(data.get()), (x4_w * x6_h * 4ul)}, + label); } break; case ETexelFormat::RGBA8PC: @@ -880,7 +881,7 @@ std::unique_ptr CTexture::BuildMemoryCardTex(u32& sizeOut, ETexelFormat& f return ret; } -const std::shared_ptr& 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, "Font (TODO)"sv); diff --git a/Runtime/Graphics/Shaders/CColoredStripShader.cpp b/Runtime/Graphics/Shaders/CColoredStripShader.cpp index 5413cd540..315a3c1b1 100644 --- a/Runtime/Graphics/Shaders/CColoredStripShader.cpp +++ b/Runtime/Graphics/Shaders/CColoredStripShader.cpp @@ -61,7 +61,7 @@ void CColoredStripShader::Shutdown() { // stages.data(), nullptr, nullptr, texs.size(), texs.data(), nullptr, nullptr); //} -CColoredStripShader::CColoredStripShader(size_t maxVerts, Mode mode, std::shared_ptr 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; diff --git a/Runtime/Graphics/Shaders/CColoredStripShader.hpp b/Runtime/Graphics/Shaders/CColoredStripShader.hpp index 62f7bafed..9a5e002de 100644 --- a/Runtime/Graphics/Shaders/CColoredStripShader.hpp +++ b/Runtime/Graphics/Shaders/CColoredStripShader.hpp @@ -32,7 +32,7 @@ public: }; static void Initialize(); static void Shutdown(); - CColoredStripShader(size_t maxVerts, Mode mode, std::shared_ptr 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/CFluidPlaneShader.cpp b/Runtime/Graphics/Shaders/CFluidPlaneShader.cpp index 6acebef40..a2ceb9f6c 100644 --- a/Runtime/Graphics/Shaders/CFluidPlaneShader.cpp +++ b/Runtime/Graphics/Shaders/CFluidPlaneShader.cpp @@ -198,7 +198,7 @@ CFluidPlaneShader::CFluidPlaneShader(EFluidType type, const TLockedToken& patternTex2, const TLockedToken& colorTex, const TLockedToken& bumpMap, const TLockedToken& envMap, const TLockedToken& envBumpMap, const TLockedToken& lightmap, - const std::shared_ptr& rippleMap, bool doubleLightmapBlend, + const std::shared_ptr& rippleMap, bool doubleLightmapBlend, bool additive, u32 maxVertCount) : m_patternTex1(patternTex1) , m_patternTex2(patternTex2) diff --git a/Runtime/Graphics/Shaders/CFluidPlaneShader.hpp b/Runtime/Graphics/Shaders/CFluidPlaneShader.hpp index c672f85db..dbded69d6 100644 --- a/Runtime/Graphics/Shaders/CFluidPlaneShader.hpp +++ b/Runtime/Graphics/Shaders/CFluidPlaneShader.hpp @@ -106,7 +106,7 @@ private: TLockedToken m_envMap; TLockedToken m_envBumpMap; TLockedToken m_lightmap; - std::shared_ptr m_rippleMap; + std::shared_ptr m_rippleMap; // boo::ObjToken m_vbo; // boo::ObjToken m_pvbo; // boo::ObjToken m_uniBuf; @@ -145,7 +145,7 @@ public: const TLockedToken& patternTex2, const TLockedToken& colorTex, const TLockedToken& bumpMap, const TLockedToken& envMap, const TLockedToken& envBumpMap, const TLockedToken& lightmap, - const std::shared_ptr& 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); diff --git a/Runtime/Graphics/Shaders/CLineRendererShaders.cpp b/Runtime/Graphics/Shaders/CLineRendererShaders.cpp index eeee0976a..c15e95ff7 100644 --- a/Runtime/Graphics/Shaders/CLineRendererShaders.cpp +++ b/Runtime/Graphics/Shaders/CLineRendererShaders.cpp @@ -54,7 +54,7 @@ void CLineRendererShaders::Shutdown() { } void CLineRendererShaders::BuildShaderDataBinding(CLineRenderer& renderer, - const std::shared_ptr& texture, bool additive, + const std::shared_ptr& texture, bool additive, bool zTest, bool zGEqual) { // std::array, 2>* pipeline = nullptr; // diff --git a/Runtime/Graphics/Shaders/CLineRendererShaders.hpp b/Runtime/Graphics/Shaders/CLineRendererShaders.hpp index 132bae2dd..ad83c74f9 100644 --- a/Runtime/Graphics/Shaders/CLineRendererShaders.hpp +++ b/Runtime/Graphics/Shaders/CLineRendererShaders.hpp @@ -26,7 +26,7 @@ public: static void Initialize(); static void Shutdown(); static void BuildShaderDataBinding(CLineRenderer& renderer, - const std::shared_ptr& texture, bool additive, bool zTest, + const std::shared_ptr& texture, bool additive, bool zTest, bool zGEqual); }; diff --git a/Runtime/Graphics/Shaders/CModelShaders.hpp b/Runtime/Graphics/Shaders/CModelShaders.hpp index 961f59bf3..a37e8c4c8 100644 --- a/Runtime/Graphics/Shaders/CModelShaders.hpp +++ b/Runtime/Graphics/Shaders/CModelShaders.hpp @@ -73,7 +73,7 @@ public: std::array colorRegs; zeus::CColor mulColor; zeus::CColor addColor; - CGraphics::CFogState fog; + CFogState fog; void ActivateLights(const std::vector& lts); }; @@ -94,7 +94,7 @@ public: struct OneTextureUniform { zeus::CColor addColor; - CGraphics::CFogState fog; + CFogState fog; }; static void Initialize(); diff --git a/Runtime/Graphics/Shaders/CSpaceWarpFilter.cpp b/Runtime/Graphics/Shaders/CSpaceWarpFilter.cpp index 5b9618a4a..6e9438036 100644 --- a/Runtime/Graphics/Shaders/CSpaceWarpFilter.cpp +++ b/Runtime/Graphics/Shaders/CSpaceWarpFilter.cpp @@ -35,8 +35,8 @@ void CSpaceWarpFilter::GenerateWarpRampTex() { data[y][x][0] = data[y][x][1] = data[y][x][2]; } } - m_warpTex = aurora::new_static_texture_2d( - WARP_RAMP_RES + 1, WARP_RAMP_RES + 1, 1, aurora::shaders::TextureFormat::R8, + m_warpTex = aurora::gfx::new_static_texture_2d( + WARP_RAMP_RES + 1, WARP_RAMP_RES + 1, 1, aurora::gfx::TextureFormat::R8, {reinterpret_cast(data.data()), (WARP_RAMP_RES + 1) * (WARP_RAMP_RES + 1) * 4}, "Warp Ramp"); } diff --git a/Runtime/Graphics/Shaders/CSpaceWarpFilter.hpp b/Runtime/Graphics/Shaders/CSpaceWarpFilter.hpp index 8c85fd5be..a89962492 100644 --- a/Runtime/Graphics/Shaders/CSpaceWarpFilter.hpp +++ b/Runtime/Graphics/Shaders/CSpaceWarpFilter.hpp @@ -17,7 +17,7 @@ class CSpaceWarpFilter { zeus::CVector3f m_strength; }; std::array, 8>, 4> m_shiftTexture{}; - std::shared_ptr m_warpTex; + std::shared_ptr m_warpTex; // boo::ObjToken m_vbo; // boo::ObjToken m_uniBuf; // boo::ObjToken m_dataBind; diff --git a/Runtime/Graphics/Shaders/CTexturedQuadFilter.cpp b/Runtime/Graphics/Shaders/CTexturedQuadFilter.cpp index d175a3e36..bd571ec81 100644 --- a/Runtime/Graphics/Shaders/CTexturedQuadFilter.cpp +++ b/Runtime/Graphics/Shaders/CTexturedQuadFilter.cpp @@ -178,11 +178,11 @@ void CTexturedQuadFilterAlpha::Shutdown() { // } //} -CTexturedQuadFilter::CTexturedQuadFilter(const std::shared_ptr& tex) : m_booTex(tex) { +CTexturedQuadFilter::CTexturedQuadFilter(const std::shared_ptr& tex) : m_booTex(tex) { m_flipRect = true; // TODO? } -CTexturedQuadFilter::CTexturedQuadFilter(EFilterType type, const std::shared_ptr& tex, ERglEnum ztest) +CTexturedQuadFilter::CTexturedQuadFilter(EFilterType type, const std::shared_ptr& tex, ERglEnum ztest) : m_booTex(tex), m_zTest(ztest) { m_flipRect = true; // TODO? // tex->setClampMode(boo::TextureClampMode::ClampToEdge); @@ -322,7 +322,7 @@ void CTexturedQuadFilter::DrawFilter(EFilterShape shape, const zeus::CColor& col } } -CTexturedQuadFilterAlpha::CTexturedQuadFilterAlpha(EFilterType type, const std::shared_ptr& 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); diff --git a/Runtime/Graphics/Shaders/CTexturedQuadFilter.hpp b/Runtime/Graphics/Shaders/CTexturedQuadFilter.hpp index 9319464c0..9881eb44e 100644 --- a/Runtime/Graphics/Shaders/CTexturedQuadFilter.hpp +++ b/Runtime/Graphics/Shaders/CTexturedQuadFilter.hpp @@ -26,7 +26,7 @@ protected: float m_lod = 0.f; }; TLockedToken m_tex; - std::shared_ptr m_booTex; + std::shared_ptr m_booTex; // boo::ObjToken m_vbo; // boo::ObjToken m_uniBuf; // boo::ObjToken m_dataBind; @@ -34,7 +34,7 @@ protected: ERglEnum m_zTest; bool m_flipRect = false; - explicit CTexturedQuadFilter(const std::shared_ptr& tex); + explicit CTexturedQuadFilter(const std::shared_ptr& tex); public: struct Vert { @@ -45,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, ERglEnum zTest = ERglEnum::Never); - explicit CTexturedQuadFilter(EFilterType type, const std::shared_ptr& tex, + explicit CTexturedQuadFilter(EFilterType type, const std::shared_ptr& tex, ERglEnum zTest = ERglEnum::Never); CTexturedQuadFilter(const CTexturedQuadFilter&) = delete; CTexturedQuadFilter& operator=(const CTexturedQuadFilter&) = delete; @@ -56,7 +56,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 std::shared_ptr& GetBooTex() const { return m_booTex; } + const std::shared_ptr& GetBooTex() const { return m_booTex; } }; class CTexturedQuadFilterAlpha : public CTexturedQuadFilter { @@ -64,7 +64,7 @@ public: static void Initialize(); static void Shutdown(); explicit CTexturedQuadFilterAlpha(EFilterType type, TLockedToken tex); - explicit CTexturedQuadFilterAlpha(EFilterType type, const std::shared_ptr& tex); + explicit CTexturedQuadFilterAlpha(EFilterType type, const std::shared_ptr& tex); }; } // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CWorldShadowShader.hpp b/Runtime/Graphics/Shaders/CWorldShadowShader.hpp index ef3473516..4308d2b9d 100644 --- a/Runtime/Graphics/Shaders/CWorldShadowShader.hpp +++ b/Runtime/Graphics/Shaders/CWorldShadowShader.hpp @@ -13,7 +13,7 @@ namespace metaforce { class CWorldShadowShader { - std::shared_ptr m_tex; + std::shared_ptr m_tex; std::optional m_prevQuad; u32 m_w, m_h; @@ -40,7 +40,7 @@ public: u32 GetWidth() const { return m_w; } u32 GetHeight() const { return m_h; } - const std::shared_ptr& GetTexture() const { return m_tex; } + const std::shared_ptr& GetTexture() const { return m_tex; } }; } // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CXRayBlurFilter.hpp b/Runtime/Graphics/Shaders/CXRayBlurFilter.hpp index 2d82a353c..f889745ce 100644 --- a/Runtime/Graphics/Shaders/CXRayBlurFilter.hpp +++ b/Runtime/Graphics/Shaders/CXRayBlurFilter.hpp @@ -15,7 +15,7 @@ class CXRayBlurFilter { std::array m_uv; }; TLockedToken m_paletteTex; - std::shared_ptr m_booTex; + std::shared_ptr m_booTex; // boo::ObjToken m_vbo; // boo::ObjToken m_uniBuf; // boo::ObjToken m_dataBind; diff --git a/Runtime/GuiSys/CAuiImagePane.cpp b/Runtime/GuiSys/CAuiImagePane.cpp index e9aa7c022..a7a5588f5 100644 --- a/Runtime/GuiSys/CAuiImagePane.cpp +++ b/Runtime/GuiSys/CAuiImagePane.cpp @@ -83,21 +83,18 @@ void CAuiImagePane::DoDrawImagePane(const zeus::CColor& color, const CTexture& t bool zTest = xac_drawFlags == EGuiModelDrawFlags::Shadeless || xac_drawFlags == EGuiModelDrawFlags::Opaque; if (noBlur) { - aurora::shaders::queue_textured_quad_verts( - aurora::shaders::CameraFilterType(filter), tex.GetTexture()->ref, aurora::shaders::ZTest::LEqual, zTest, useColor, - {xe0_coords.data(), xe0_coords.size()}, {realUseUvs.data(), xe0_coords.size()}, 0); + aurora::gfx::queue_textured_quad_verts(aurora::gfx::CameraFilterType(filter), tex.GetTexture()->ref, + aurora::gfx::ZTest::LEqual, zTest, useColor, xe0_coords, realUseUvs, 0); // quad.drawVerts(useColor, verts); } else if ((x14c_deResFactor == 0.f && alpha == 1.f) || tex.GetNumMips() == 1) { - aurora::shaders::queue_textured_quad_verts( - aurora::shaders::CameraFilterType(filter), tex.GetTexture()->ref, aurora::shaders::ZTest::LEqual, zTest, - useColor, {xe0_coords.data(), xe0_coords.size()}, {realUseUvs.data(), xe0_coords.size()}, 0); + aurora::gfx::queue_textured_quad_verts(aurora::gfx::CameraFilterType(filter), tex.GetTexture()->ref, + aurora::gfx::ZTest::LEqual, zTest, useColor, xe0_coords, realUseUvs, 0); } else { const float tmp = (1.f - x14c_deResFactor) * alpha; const float tmp3 = 1.f - tmp * tmp * tmp; const float mip = tmp3 * static_cast(tex.GetNumMips() - 1); - aurora::shaders::queue_textured_quad_verts( - aurora::shaders::CameraFilterType(filter), tex.GetTexture()->ref, aurora::shaders::ZTest::LEqual, zTest, - useColor, {xe0_coords.data(), xe0_coords.size()}, {realUseUvs.data(), xe0_coords.size()}, mip); + aurora::gfx::queue_textured_quad_verts(aurora::gfx::CameraFilterType(filter), tex.GetTexture()->ref, + aurora::gfx::ZTest::LEqual, zTest, useColor, xe0_coords, realUseUvs, mip); } } diff --git a/Runtime/GuiSys/CGuiFrame.cpp b/Runtime/GuiSys/CGuiFrame.cpp index e7186b17e..fb93c4887 100644 --- a/Runtime/GuiSys/CGuiFrame.cpp +++ b/Runtime/GuiSys/CGuiFrame.cpp @@ -169,9 +169,8 @@ void CGuiFrame::LoadWidgetsInGame(CInputStream& in, CSimplePool* sp) { for (u32 i = 0; i < count; ++i) { DataSpec::DNAFourCC type; type.read(in); - std::shared_ptr widget = CGuiSys::CreateWidgetInGame(type, in, this, sp); - type = widget->GetWidgetTypeID(); - switch (type.toUint32()) { + std::shared_ptr widget = CGuiSys::CreateWidgetInGame(type.toUint32(), in, this, sp); + switch (widget->GetWidgetTypeID().toUint32()) { case SBIG('CAMR'): case SBIG('LITE'): case SBIG('BGND'): diff --git a/Runtime/GuiSys/CGuiPane.cpp b/Runtime/GuiSys/CGuiPane.cpp index 4832fc7c8..228535324 100644 --- a/Runtime/GuiSys/CGuiPane.cpp +++ b/Runtime/GuiSys/CGuiPane.cpp @@ -3,8 +3,6 @@ #include "Runtime/Graphics/CGraphics.hpp" -#include - namespace metaforce { CGuiPane::CGuiPane(const CGuiWidgetParms& parms, const zeus::CVector2f& dim, const zeus::CVector3f& scaleCenter) @@ -18,8 +16,8 @@ void CGuiPane::Draw(const CGuiWidgetDrawParms& parms) { auto col = xa8_color2; col.a() = parms.x0_alphaMod * xa8_color2.a(); - aurora::shaders::queue_colored_quad_verts(aurora::shaders::CameraFilterType::Blend, aurora::shaders::ZTest::Always, - false, col, {xc0_verts.data(), xc0_verts.size()}); + aurora::gfx::queue_colored_quad_verts(aurora::gfx::CameraFilterType::Blend, aurora::gfx::ZTest::Always, false, col, + xc0_verts); } CGuiWidget::Draw(parms); } @@ -50,7 +48,6 @@ void CGuiPane::InitializeBuffers() { xc0_verts[1].assign(-xb8_dim.x() * 0.5f, 0.f, -xb8_dim.y() * 0.5f); xc0_verts[2].assign(xb8_dim.x() * 0.5f, 0.f, xb8_dim.y() * 0.5f); xc0_verts[3].assign(xb8_dim.x() * 0.5f, 0.f, -xb8_dim.y() * 0.5f); - } void CGuiPane::WriteData(COutputStream& out, bool flag) const {} diff --git a/Runtime/GuiSys/CGuiWidget.cpp b/Runtime/GuiSys/CGuiWidget.cpp index aa566ead0..775be6e3b 100644 --- a/Runtime/GuiSys/CGuiWidget.cpp +++ b/Runtime/GuiSys/CGuiWidget.cpp @@ -2,9 +2,6 @@ #include "Runtime/GuiSys/CGuiWidget.hpp" #include "Runtime/GuiSys/CGuiFrame.hpp" -#include -#include - #include namespace metaforce { diff --git a/Runtime/GuiSys/CRasterFont.hpp b/Runtime/GuiSys/CRasterFont.hpp index 5b0b68945..8b8c08c94 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 std::shared_ptr& 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/CSplashScreen.cpp b/Runtime/GuiSys/CSplashScreen.cpp index fc6f9f288..7581754fe 100644 --- a/Runtime/GuiSys/CSplashScreen.cpp +++ b/Runtime/GuiSys/CSplashScreen.cpp @@ -73,10 +73,10 @@ void CSplashScreen::Draw() { rect.position.x() = 0.5f - rect.size.x() / 2.f; rect.position.y() = 0.5f - rect.size.y() / 2.f; - aurora::shaders::queue_textured_quad( - aurora::shaders::CameraFilterType::Blend, + aurora::gfx::queue_textured_quad( + aurora::gfx::CameraFilterType::Blend, m_texture->GetTexture()->ref, - aurora::shaders::ZTest::Always, + aurora::gfx::ZTest::Always, false, color, 1.f, diff --git a/Runtime/GuiSys/CStringTable.cpp b/Runtime/GuiSys/CStringTable.cpp index 2874e052c..c35914d73 100644 --- a/Runtime/GuiSys/CStringTable.cpp +++ b/Runtime/GuiSys/CStringTable.cpp @@ -54,11 +54,11 @@ void CStringTable::LoadStringTable(CInputStream& in) { u32* off = reinterpret_cast(x4_data.get()); for (u32 i = 0; i < x0_stringCount; ++i, ++off) - *off = hecl::SBig(*off); + *off = SBig(*off); for (u32 i = x0_stringCount * 4; i < dataLen; i += 2) { u16* chr = reinterpret_cast(x4_data.get() + i); - *chr = hecl::SBig(*chr); + *chr = SBig(*chr); } } diff --git a/Runtime/Input/CFinalInput.hpp b/Runtime/Input/CFinalInput.hpp index 146108b4f..9e3c82d18 100644 --- a/Runtime/Input/CFinalInput.hpp +++ b/Runtime/Input/CFinalInput.hpp @@ -5,10 +5,6 @@ #include "Runtime/Input/CKeyboardMouseController.hpp" #include "Runtime/RetroTypes.hpp" -#include "aurora.h" - -//#include - namespace metaforce { struct SAuroraControllerState { diff --git a/Runtime/Input/CKeyboardMouseController.hpp b/Runtime/Input/CKeyboardMouseController.hpp index dc5236a11..e7da7c6b3 100644 --- a/Runtime/Input/CKeyboardMouseController.hpp +++ b/Runtime/Input/CKeyboardMouseController.hpp @@ -1,8 +1,9 @@ #pragma once #include + +#include #include -#include "aurora.h" namespace metaforce { diff --git a/Runtime/MP1/CFrontEndUI.cpp b/Runtime/MP1/CFrontEndUI.cpp index 218b360b0..b3f2e1710 100644 --- a/Runtime/MP1/CFrontEndUI.cpp +++ b/Runtime/MP1/CFrontEndUI.cpp @@ -2045,8 +2045,8 @@ void CFrontEndUI::Draw() { x38_pressStart->GetHeight() / 480.f * vPad); zeus::CColor color = zeus::skWhite; color.a() = x64_pressStartAlpha; - aurora::shaders::queue_textured_quad(aurora::shaders::CameraFilterType::Add, x38_pressStart->GetTexture()->ref, - aurora::shaders::ZTest::Always, false, color, 1.f, rect, 0.f); + aurora::gfx::queue_textured_quad(aurora::gfx::CameraFilterType::Add, x38_pressStart->GetTexture()->ref, + aurora::gfx::ZTest::Always, false, color, 1.f, rect, 0.f); } if (xc0_attractCount > 0) { @@ -2058,8 +2058,8 @@ void CFrontEndUI::Draw() { zeus::CColor color = zeus::skBlack; color.a() = 1.f - x58_fadeBlackTimer; zeus::CRectangle rect(0, 0, 1, 1); - aurora::shaders::queue_colored_quad(aurora::shaders::CameraFilterType::Blend, aurora::shaders::ZTest::Always, - false, color, rect, 0.f); + aurora::gfx::queue_colored_quad(aurora::gfx::CameraFilterType::Blend, aurora::gfx::ZTest::Always, false, color, + rect, 0.f); } } @@ -2070,15 +2070,15 @@ void CFrontEndUI::Draw() { zeus::CColor color = zeus::skBlack; color.a() = zeus::clamp(0.f, 1.f - x58_fadeBlackTimer, 1.f); zeus::CRectangle rect(0, 0, 1, 1); - aurora::shaders::queue_colored_quad(aurora::shaders::CameraFilterType::Blend, aurora::shaders::ZTest::Always, - false, color, rect, 0.f); + aurora::gfx::queue_colored_quad(aurora::gfx::CameraFilterType::Blend, aurora::gfx::ZTest::Always, false, color, + rect, 0.f); } else if (x50_curScreen == EScreen::Title && x54_nextScreen == EScreen::Title) { /* From black with 30-sec skip to title */ zeus::CColor color = zeus::skBlack; color.a() = 1.f - zeus::clamp(0.f, 30.f - x58_fadeBlackTimer, 1.f); zeus::CRectangle rect(0, 0, 1, 1); - aurora::shaders::queue_colored_quad(aurora::shaders::CameraFilterType::Blend, aurora::shaders::ZTest::Always, - false, color, rect, 0.f); + aurora::gfx::queue_colored_quad(aurora::gfx::CameraFilterType::Blend, aurora::gfx::ZTest::Always, false, color, + rect, 0.f); } } diff --git a/Runtime/Particle/CElementGen.cpp b/Runtime/Particle/CElementGen.cpp index 0a2115d88..6ae248bb5 100644 --- a/Runtime/Particle/CElementGen.cpp +++ b/Runtime/Particle/CElementGen.cpp @@ -209,7 +209,7 @@ CElementGen::CElementGen(TToken gen, EModelOrientationType orie if (x26c_31_LINE) { CUVElement* texr = desc->x54_x40_TEXR.get(); - std::shared_ptr tex; + std::shared_ptr tex; if (texr) tex = texr->GetValueTexture(0).GetObj()->GetTexture(); int maxVerts = x90_MAXP; diff --git a/Runtime/RetroTypes.hpp b/Runtime/RetroTypes.hpp index 9db002783..2025461da 100644 --- a/Runtime/RetroTypes.hpp +++ b/Runtime/RetroTypes.hpp @@ -6,11 +6,9 @@ #include #include -#include "Runtime/GCNTypes.hpp" -#include "Runtime/IOStreams.hpp" -#include "Runtime/rstl.hpp" +#include "GCNTypes.hpp" +#include "rstl.hpp" -#include #include #include #include @@ -21,6 +19,12 @@ #undef max using namespace std::literals; + +namespace athena::io { +class IStreamReader; +class IStreamWriter; +} // namespace athena::io + namespace metaforce { using kUniqueIdType = u16; static constexpr int kMaxEntities = 1024; @@ -33,7 +37,165 @@ constexpr kUniqueIdType kUniqueIdValueMask = kMaxEntities - 1; constexpr kUniqueIdType kUniqueIdValueBits = 10; constexpr kUniqueIdType kUniqueIdVersionBits = 6; -using FourCC = hecl::FourCC; +#undef bswap16 +#undef bswap32 +#undef bswap64 + +/* Type-sensitive byte swappers */ +template +constexpr T bswap16(T val) noexcept { +#if __GNUC__ + return __builtin_bswap16(val); +#elif _WIN32 + return _byteswap_ushort(val); +#else + return (val = (val << 8) | ((val >> 8) & 0xFF)); +#endif +} + +template +constexpr T bswap32(T val) noexcept { +#if __GNUC__ + return __builtin_bswap32(val); +#elif _WIN32 + return _byteswap_ulong(val); +#else + val = (val & 0x0000FFFF) << 16 | (val & 0xFFFF0000) >> 16; + val = (val & 0x00FF00FF) << 8 | (val & 0xFF00FF00) >> 8; + return val; +#endif +} + +template +constexpr T bswap64(T val) noexcept { +#if __GNUC__ + return __builtin_bswap64(val); +#elif _WIN32 + return _byteswap_uint64(val); +#else + return ((val & 0xFF00000000000000ULL) >> 56) | ((val & 0x00FF000000000000ULL) >> 40) | + ((val & 0x0000FF0000000000ULL) >> 24) | ((val & 0x000000FF00000000ULL) >> 8) | + ((val & 0x00000000FF000000ULL) << 8) | ((val & 0x0000000000FF0000ULL) << 24) | + ((val & 0x000000000000FF00ULL) << 40) | ((val & 0x00000000000000FFULL) << 56); +#endif +} + +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ +constexpr int16_t SBig(int16_t val) noexcept { return bswap16(val); } +constexpr uint16_t SBig(uint16_t val) noexcept { return bswap16(val); } +constexpr int32_t SBig(int32_t val) noexcept { return bswap32(val); } +constexpr uint32_t SBig(uint32_t val) noexcept { return bswap32(val); } +constexpr int64_t SBig(int64_t val) noexcept { return bswap64(val); } +constexpr uint64_t SBig(uint64_t val) noexcept { return bswap64(val); } +constexpr float SBig(float val) noexcept { + union { + float f; + atInt32 i; + } uval1 = {val}; + union { + atInt32 i; + float f; + } uval2 = {bswap32(uval1.i)}; + return uval2.f; +} +constexpr double SBig(double val) noexcept { + union { + double f; + atInt64 i; + } uval1 = {val}; + union { + atInt64 i; + double f; + } uval2 = {bswap64(uval1.i)}; + return uval2.f; +} +#ifndef SBIG +#define SBIG(q) (((q)&0x000000FF) << 24 | ((q)&0x0000FF00) << 8 | ((q)&0x00FF0000) >> 8 | ((q)&0xFF000000) >> 24) +#endif + +constexpr int16_t SLittle(int16_t val) noexcept { return val; } +constexpr uint16_t SLittle(uint16_t val) noexcept { return val; } +constexpr int32_t SLittle(int32_t val) noexcept { return val; } +constexpr uint32_t SLittle(uint32_t val) noexcept { return val; } +constexpr int64_t SLittle(int64_t val) noexcept { return val; } +constexpr uint64_t SLittle(uint64_t val) noexcept { return val; } +constexpr float SLittle(float val) noexcept { return val; } +constexpr double SLittle(double val) noexcept { return val; } +#ifndef SLITTLE +#define SLITTLE(q) (q) +#endif +#else +constexpr int16_t SLittle(int16_t val) noexcept { return bswap16(val); } +constexpr uint16_t SLittle(uint16_t val) noexcept { return bswap16(val); } +constexpr int32_t SLittle(int32_t val) noexcept { return bswap32(val); } +constexpr uint32_t SLittle(uint32_t val) noexcept { return bswap32(val); } +constexpr int64_t SLittle(int64_t val) noexcept { return bswap64(val); } +constexpr uint64_t SLittle(uint64_t val) noexcept { return bswap64(val); } +constexpr float SLittle(float val) noexcept { + int32_t ival = bswap32(*((int32_t*)(&val))); + return *((float*)(&ival)); +} +constexpr double SLittle(double val) noexcept { + int64_t ival = bswap64(*((int64_t*)(&val))); + return *((double*)(&ival)); +} +#ifndef SLITTLE +#define SLITTLE(q) (((q)&0x000000FF) << 24 | ((q)&0x0000FF00) << 8 | ((q)&0x00FF0000) >> 8 | ((q)&0xFF000000) >> 24) +#endif + +constexpr int16_t SBig(int16_t val) noexcept { return val; } +constexpr uint16_t SBig(uint16_t val) noexcept { return val; } +constexpr int32_t SBig(int32_t val) noexcept { return val; } +constexpr uint32_t SBig(uint32_t val) noexcept { return val; } +constexpr int64_t SBig(int64_t val) noexcept { return val; } +constexpr uint64_t SBig(uint64_t val) noexcept { return val; } +constexpr float SBig(float val) noexcept { return val; } +constexpr double SBig(double val) noexcept { return val; } +#ifndef SBIG +#define SBIG(q) (q) +#endif +#endif + +class FourCC { +protected: + union { + char fcc[4]; + uint32_t num = 0; + }; + +public: + // Sentinel FourCC + constexpr FourCC() noexcept = default; + constexpr FourCC(const FourCC& other) noexcept = default; + constexpr FourCC(FourCC&& other) noexcept = default; + constexpr FourCC(const char* name) noexcept : fcc{name[0], name[1], name[2], name[3]} {} + constexpr FourCC(uint32_t n) noexcept : num(n) {} + + constexpr FourCC& operator=(const FourCC&) noexcept = default; + constexpr FourCC& operator=(FourCC&&) noexcept = default; + + constexpr bool operator==(const FourCC& other) const noexcept { return num == other.num; } + constexpr bool operator!=(const FourCC& other) const noexcept { return !operator==(other); } + constexpr bool operator==(const char* other) const noexcept { + return other[0] == fcc[0] && other[1] == fcc[1] && other[2] == fcc[2] && other[3] == fcc[3]; + } + constexpr bool operator!=(const char* other) const noexcept { return !operator==(other); } + constexpr bool operator==(int32_t other) const noexcept { return num == uint32_t(other); } + constexpr bool operator!=(int32_t other) const noexcept { return !operator==(other); } + constexpr bool operator==(uint32_t other) const noexcept { return num == other; } + constexpr bool operator!=(uint32_t other) const noexcept { return !operator==(other); } + + std::string toString() const { return std::string(std::begin(fcc), std::end(fcc)); } + constexpr std::string_view toStringView() const { return std::string_view(fcc, std::size(fcc)); } + constexpr uint32_t toUint32() const noexcept { return num; } + constexpr const char* getChars() const noexcept { return fcc; } + constexpr char* getChars() noexcept { return fcc; } + constexpr bool IsValid() const noexcept { return num != 0; } +}; +#define FOURCC(chars) FourCC(SBIG(chars)) + +using CInputStream = athena::io::IStreamReader; +using COutputStream = athena::io::IStreamWriter; class CAssetId { u64 id = UINT64_MAX; @@ -184,6 +346,11 @@ public: } // namespace metaforce namespace std { +template <> +struct hash { + size_t operator()(const metaforce::FourCC& val) const noexcept { return val.toUint32(); } +}; + template <> struct hash { size_t operator()(const metaforce::SObjectTag& tag) const noexcept { return tag.id.Value(); } @@ -200,6 +367,8 @@ FMT_CUSTOM_FORMATTER(metaforce::TEditorId, "{:08X}", obj.id) static_assert(sizeof(metaforce::kUniqueIdType) == sizeof(u16), "TUniqueId size does not match expected size! Update TUniqueId format string!"); FMT_CUSTOM_FORMATTER(metaforce::TUniqueId, "{:04X}", obj.id) +FMT_CUSTOM_FORMATTER(metaforce::FourCC, "{:c}{:c}{:c}{:c}", obj.getChars()[0], obj.getChars()[1], obj.getChars()[2], + obj.getChars()[3]) FMT_CUSTOM_FORMATTER(metaforce::SObjectTag, "{} {}", obj.type, obj.id) FMT_CUSTOM_FORMATTER(zeus::CVector3f, "({} {} {})", float(obj.x()), float(obj.y()), float(obj.z())) diff --git a/Runtime/Weapon/CPlasmaProjectile.cpp b/Runtime/Weapon/CPlasmaProjectile.cpp index 6082ca672..cf161cbff 100644 --- a/Runtime/Weapon/CPlasmaProjectile.cpp +++ b/Runtime/Weapon/CPlasmaProjectile.cpp @@ -12,8 +12,8 @@ namespace metaforce { -CPlasmaProjectile::RenderObjects::RenderObjects(std::shared_ptr tex, - std::shared_ptr glowTex) +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) diff --git a/Runtime/Weapon/CPlasmaProjectile.hpp b/Runtime/Weapon/CPlasmaProjectile.hpp index 11635a4ff..18b65f1c0 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(std::shared_ptr tex, - std::shared_ptr glowTex); + RenderObjects(std::shared_ptr tex, + std::shared_ptr glowTex); }; std::optional m_renderObjs; diff --git a/Runtime/World/CActor.hpp b/Runtime/World/CActor.hpp index 5b197ae56..f99978bb2 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; - std::shared_ptr m_reflectionCube; + std::shared_ptr m_reflectionCube; zeus::CColor m_debugAddColor = zeus::skClear; float m_debugAddColorTime = 0.f; diff --git a/Runtime/World/CFluidPlaneCPU.cpp b/Runtime/World/CFluidPlaneCPU.cpp index 474e1bfe8..ef9db7e2b 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 : std::shared_ptr{}, + m_tessellation ? CFluidPlaneManager::RippleMapTex : std::shared_ptr{}, m_cachedDoubleLightmapBlend, m_cachedAdditive, m_maxVertCount); } diff --git a/Runtime/World/CFluidPlaneManager.cpp b/Runtime/World/CFluidPlaneManager.cpp index bfd6b4d4b..06f8f8f6c 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{}; -std::shared_ptr CFluidPlaneManager::RippleMapTex; +std::shared_ptr CFluidPlaneManager::RippleMapTex; void CFluidPlaneManager::SetupRippleMap() { if (g_RippleMapSetup) { @@ -135,9 +135,9 @@ void CFluidPlaneManager::SetupRippleMap() { curX += (1.f / 63.f); } - RippleMapTex = - aurora::new_static_texture_2d(64, 64, 1, aurora::shaders::TextureFormat::R8, - {reinterpret_cast(RippleValues.data()), 64 * 64}, "Ripple Map"); + RippleMapTex = aurora::gfx::new_static_texture_2d(64, 64, 1, aurora::gfx::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 a550ee5e6..3187efe92 100644 --- a/Runtime/World/CFluidPlaneManager.hpp +++ b/Runtime/World/CFluidPlaneManager.hpp @@ -46,7 +46,7 @@ public: static std::array, 64> RippleValues; static std::array RippleMins; static std::array RippleMaxs; - static std::shared_ptr RippleMapTex; + static std::shared_ptr RippleMapTex; CFluidPlaneManager(); void StartFrame(bool); diff --git a/Runtime/World/CGameArea.cpp b/Runtime/World/CGameArea.cpp index b3ebbf0c4..17b854979 100644 --- a/Runtime/World/CGameArea.cpp +++ b/Runtime/World/CGameArea.cpp @@ -1020,7 +1020,7 @@ void CGameArea::PostConstructArea() { athena::io::MemoryReader r(x12c_postConstructed->x10c8_sclyBuf, x12c_postConstructed->x10d0_sclySize); hecl::DNAFourCC magic; magic.read(r); - if (magic == FOURCC('SCLY')) { + if (magic == hecl::FOURCC('SCLY')) { r.readUint32Big(); u32 layerCount = r.readUint32Big(); x12c_postConstructed->x110c_layerPtrs.resize(layerCount); diff --git a/Runtime/World/CPathFindRegion.hpp b/Runtime/World/CPathFindRegion.hpp index 226c6d951..51b5e1416 100644 --- a/Runtime/World/CPathFindRegion.hpp +++ b/Runtime/World/CPathFindRegion.hpp @@ -2,7 +2,8 @@ #include -#include "Runtime/RetroTypes.hpp" +#include "RetroTypes.hpp" +#include "IOStreams.hpp" #include #include diff --git a/aurora/CMakeLists.txt b/aurora/CMakeLists.txt new file mode 100644 index 000000000..e38410963 --- /dev/null +++ b/aurora/CMakeLists.txt @@ -0,0 +1,10 @@ +add_subdirectory(../extern/dawn dawn EXCLUDE_FROM_ALL) +if (NOT MSVC) + target_compile_options(SPIRV-Tools-static PRIVATE -Wno-implicit-fallthrough) + target_compile_options(SPIRV-Tools-opt PRIVATE -Wno-implicit-fallthrough) +endif () + +add_library(aurora STATIC lib/aurora.cpp lib/imgui.cpp lib/gfx/common.cpp) +target_include_directories(aurora PUBLIC include ../Runtime) +target_include_directories(aurora PRIVATE ../imgui ../extern/imgui) +target_link_libraries(aurora PRIVATE webgpu_dawn zeus logvisor) # TODO remove logvisor from rstl.hpp diff --git a/aurora/include/aurora/aurora.hpp b/aurora/include/aurora/aurora.hpp new file mode 100644 index 000000000..8cab4adae --- /dev/null +++ b/aurora/include/aurora/aurora.hpp @@ -0,0 +1,231 @@ +#pragma once + +#include +#include +#include +#include +#include +#ifndef ENABLE_BITWISE_ENUM +#define ENABLE_BITWISE_ENUM(type) \ + constexpr type operator|(type a, type b) noexcept { \ + using T = std::underlying_type_t; \ + return type(static_cast(a) | static_cast(b)); \ + } \ + constexpr type operator&(type a, type b) noexcept { \ + using T = std::underlying_type_t; \ + return type(static_cast(a) & static_cast(b)); \ + } \ + constexpr type& operator|=(type& a, type b) noexcept { \ + using T = std::underlying_type_t; \ + a = type(static_cast(a) | static_cast(b)); \ + return a; \ + } \ + constexpr type& operator&=(type& a, type b) noexcept { \ + using T = std::underlying_type_t; \ + a = type(static_cast(a) & static_cast(b)); \ + return a; \ + } \ + constexpr type operator~(type key) noexcept { \ + using T = std::underlying_type_t; \ + return type(~static_cast(key)); \ + } \ + constexpr bool True(type key) noexcept { \ + using T = std::underlying_type_t; \ + return static_cast(key) != 0; \ + } \ + constexpr bool False(type key) noexcept { \ + using T = std::underlying_type_t; \ + return static_cast(key) == 0; \ + } +#endif + +namespace aurora { +enum class SpecialKey : uint8_t { + 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, + F13 = 13, + F14 = 14, + F15 = 15, + F16 = 16, + F17 = 17, + F18 = 18, + F19 = 19, + F20 = 20, + F21 = 21, + F22 = 22, + F23 = 23, + F24 = 24, + Esc = 25, + Enter = 26, + Backspace = 27, + Insert = 28, + Delete = 29, + Home = 30, + End = 31, + PgUp = 32, + PgDown = 33, + Left = 34, + Right = 35, + Up = 36, + Down = 37, + Tab = 38, + PrintScreen = 39, + ScrollLock = 40, + Pause = 41, + NumLockClear = 42, + KpDivide = 43, + KpMultiply = 44, + KpMinus = 45, + KpPlus = 46, + KpEnter = 47, + KpNum0 = 48, + KpNum1 = 49, + KpNum2 = 51, + KpNum3 = 52, + KpNum4 = 53, + KpNum5 = 54, + KpNum6 = 55, + KpNum7 = 56, + KpNum8 = 57, + KpNum9 = 58, + KpPercent = 59, + KpPeriod = 60, + KpComma = 61, + KpEquals = 62, + Application = 63, + Power = 64, + Execute = 65, + Help = 66, + Menu = 67, + Select = 68, + Stop = 69, + Again = 70, + Undo = 71, + Cut = 72, + Paste = 73, + Find = 74, + VolumeUp = 75, + VolumeDown = 76, + MAX, +}; +enum class ModifierKey : uint16_t { + None = 0, + LeftShift = 1 << 0, + RightShift = 1 << 1, + LeftControl = 1 << 2, + RightControl = 1 << 3, + LeftAlt = 1 << 3, + RightAlt = 1 << 4, + LeftGui = 1 << 5, + RightGui = 1 << 6, + Num = 1 << 7, + Caps = 1 << 8, + Mode = 1 << 9, + // SDL has a reserved value we don't need +}; +ENABLE_BITWISE_ENUM(ModifierKey); + +enum class ControllerButton : uint8_t { + A, + B, + X, + Y, + Back, + Guide, + Start, + LeftStick, + RightStick, + LeftShoulder, + RightShoulder, + DPadUp, + DPadDown, + DPadLeft, + DPadRight, + Other, + MAX, +}; +enum class ControllerAxis : uint8_t { + LeftX, + LeftY, + RightX, + RightY, + TriggerLeft, + TriggerRight, + MAX, +}; +struct Icon { + std::unique_ptr data; + uint32_t width; + uint32_t height; +}; +struct WindowSize { + uint32_t width; + uint32_t height; +}; +enum class Backend : uint8_t { + Invalid, + Vulkan, + Metal, + D3D12, + D3D11, + OpenGL, + WebGPU, +}; + +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 onAppWindowResized(const WindowSize& size) noexcept = 0; + virtual void onAppWindowMoved(int32_t x, int32_t y) noexcept = 0; + virtual void onAppExiting() noexcept = 0; + + // ImGui + virtual void onImGuiInit(float scale) noexcept = 0; + virtual void onImGuiAddTextures() noexcept = 0; + + // Input + virtual void onCharKeyDown(uint8_t charCode, ModifierKey mods, bool isRepeat) noexcept = 0; + virtual void onCharKeyUp(uint8_t charCode, ModifierKey mods) noexcept = 0; + virtual void onSpecialKeyDown(SpecialKey key, ModifierKey mods, bool isRepeat) noexcept = 0; + virtual void onSpecialKeyUp(SpecialKey key, ModifierKey mods) noexcept = 0; + + // Controller + virtual void onControllerAdded(uint32_t which) noexcept = 0; + virtual void onControllerRemoved(uint32_t which) noexcept = 0; + virtual void onControllerButton(uint32_t which, ControllerButton button, bool pressed) noexcept = 0; + virtual void onControllerAxis(uint32_t which, ControllerAxis axis, int16_t value) noexcept = 0; +}; + +void app_run(std::unique_ptr app, Icon icon) noexcept; +[[nodiscard]] std::vector get_args() noexcept; +[[nodiscard]] WindowSize get_window_size() noexcept; +void set_window_title(std::string_view title) noexcept; +[[nodiscard]] Backend get_backend() noexcept; +[[nodiscard]] std::string_view get_backend_string() noexcept; +void set_fullscreen(bool fullscreen) noexcept; +[[nodiscard]] int32_t get_controller_player_index(uint32_t which) noexcept; +void set_controller_player_index(uint32_t which, int32_t index) noexcept; +[[nodiscard]] bool is_controller_gamecube(uint32_t which) noexcept; +[[nodiscard]] std::string get_controller_name(uint32_t which) noexcept; +} // namespace aurora diff --git a/aurora/include/aurora/common.hpp b/aurora/include/aurora/common.hpp new file mode 100644 index 000000000..007cc2b3d --- /dev/null +++ b/aurora/include/aurora/common.hpp @@ -0,0 +1,72 @@ +#pragma once + +#include +#include +#include + +#include "RetroTypes.hpp" + +namespace aurora { +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 reverse_iterator = std::reverse_iterator; + using const_reverse_iterator = std::reverse_iterator; + using size_type = std::size_t; + using difference_type = std::ptrdiff_t; + + ArrayRef() = default; + explicit ArrayRef(const T& one) : ptr(&one), length(1) {} + ArrayRef(const T* data, size_t length) : ptr(data), length(length) {} + ArrayRef(const T* begin, const T* end) : ptr(begin), length(end - begin) {} + template + constexpr ArrayRef(const T (&arr)[N]) : ptr(arr), length(N) {} + template + constexpr ArrayRef(const std::array& arr) : ptr(arr.data()), length(arr.size()) {} + ArrayRef(const std::vector& vec) : ptr(vec.data()), length(vec.size()) {} + template + ArrayRef(const rstl::reserved_vector& vec) : ptr(vec.data()), length(vec.size()) {} + + const T* data() const { return ptr; } + size_t size() const { return length; } + bool empty() const { return length == 0; } + + const T& front() const { + assert(!empty()); + return ptr[0]; + } + const T& back() const { + assert(!empty()); + return ptr[length - 1]; + } + const T& operator[](size_t i) const { + assert(i < length && "Invalid index!"); + return ptr[i]; + } + + iterator begin() const { return ptr; } + iterator end() const { return ptr + length; } + + reverse_iterator rbegin() const { return reverse_iterator(end()); } + reverse_iterator rend() const { return reverse_iterator(begin()); } + + /// Disallow accidental assignment from a temporary. + template + std::enable_if_t::value, ArrayRef>& operator=(U&& Temporary) = delete; + + /// Disallow accidental assignment from a temporary. + template + std::enable_if_t::value, ArrayRef>& operator=(std::initializer_list) = delete; + +private: + const T* ptr = nullptr; + size_t length = 0; +}; +} // namespace aurora diff --git a/aurora/include/aurora/gfx.hpp b/aurora/include/aurora/gfx.hpp new file mode 100644 index 000000000..f7200dc0f --- /dev/null +++ b/aurora/include/aurora/gfx.hpp @@ -0,0 +1,129 @@ +#pragma once + +#include "common.hpp" + +#include + +#include +#include +#include +#include +#include +#include +#include + +namespace metaforce { +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 +}; + +struct CFogState { + zeus::CColor m_color; + float m_A = 0.f; + float m_B = 0.5f; + float m_C = 0.f; + ERglFogMode m_mode; +}; +} // namespace metaforce + +namespace aurora::gfx { +struct TextureRef { + uint32_t id; + bool render; +}; +struct TextureHandle { + TextureRef ref; + explicit TextureHandle(TextureRef ref) : ref(ref) {} + ~TextureHandle() noexcept; + TextureHandle(const TextureHandle&) = delete; + TextureHandle& operator=(const TextureHandle&) = delete; +}; +enum class TextureFormat : uint8_t { + RGBA8, + R8, + R32Float, + DXT1, + DXT3, + DXT5, + BPTC, +}; + +struct ClipRect { + int32_t x; + int32_t y; + int32_t width; + int32_t height; +}; +enum class CameraFilterType : uint8_t { + Passthru, + Multiply, + Invert, + Add, + Subtract, + Blend, + Widescreen, + SceneAdd, + NoColor, + InvDstMultiply, +}; +enum class ZTest : uint8_t { + Never, + Less, + Equal, + LEqual, + Greater, + NEqual, + GEqual, + Always, +}; + +[[nodiscard]] bool get_dxt_compression_supported() noexcept; + +void update_model_view(const zeus::CMatrix4f& mv, const zeus::CMatrix4f& mv_inv) noexcept; +void update_projection(const zeus::CMatrix4f& proj) noexcept; +void update_fog_state(const metaforce::CFogState& state) noexcept; +void set_viewport(const zeus::CRectangle& rect, float znear, float zfar) noexcept; +void set_scissor(uint32_t x, uint32_t y, uint32_t w, uint32_t h) noexcept; + +void resolve_color(const ClipRect& rect, uint32_t bind, bool clear_depth) noexcept; +void resolve_depth(const ClipRect& rect, uint32_t bind) noexcept; + +void add_material_set(/* TODO */) noexcept; +void add_model(/* TODO */) noexcept; + +void queue_aabb(const zeus::CAABox& aabb, const zeus::CColor& color, bool z_only) noexcept; +void queue_fog_volume_plane(const ArrayRef& verts, uint8_t pass); +void queue_fog_volume_filter(const zeus::CColor& color, bool two_way) noexcept; +void queue_textured_quad_verts(CameraFilterType filter_type, TextureRef texture, ZTest z_comparison, bool z_test, + const zeus::CColor& color, const ArrayRef& pos, + const ArrayRef& uvs, float lod) noexcept; +void queue_textured_quad(CameraFilterType filter_type, TextureRef texture, ZTest z_comparison, bool z_test, + const zeus::CColor& color, float uv_scale, const zeus::CRectangle& rect, float z) noexcept; +void queue_colored_quad_verts(CameraFilterType filter_type, ZTest z_comparison, bool z_test, const zeus::CColor& color, + const ArrayRef& pos) noexcept; +void queue_colored_quad(CameraFilterType filter_type, ZTest z_comparison, bool z_test, const zeus::CColor& color, + const zeus::CRectangle& rect, float z) noexcept; +void queue_movie_player(TextureRef tex_y, TextureRef tex_u, TextureRef tex_v, const zeus::CColor& color, float h_pad, + float v_pad) noexcept; + +std::shared_ptr new_static_texture_2d(uint32_t width, uint32_t height, uint32_t mips, + TextureFormat format, ArrayRef data, + std::string_view label) noexcept; +std::shared_ptr new_dynamic_texture_2d(uint32_t width, uint32_t height, uint32_t mips, + TextureFormat format, std::string_view label) noexcept; +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) noexcept; +void write_texture(TextureRef ref, ArrayRef data) noexcept; +} // namespace aurora::gfx diff --git a/aurora/include/aurora/imgui.hpp b/aurora/include/aurora/imgui.hpp new file mode 100644 index 000000000..5795c71ee --- /dev/null +++ b/aurora/include/aurora/imgui.hpp @@ -0,0 +1,9 @@ +#pragma once + +#include "common.hpp" + +#include + +namespace aurora::imgui { +ImTextureID add_texture(uint32_t width, uint32_t height, ArrayRef data) noexcept; +} // namespace aurora::imgui diff --git a/aurora/lib/aurora.cpp b/aurora/lib/aurora.cpp new file mode 100644 index 000000000..3211b3c7f --- /dev/null +++ b/aurora/lib/aurora.cpp @@ -0,0 +1,36 @@ +#include +#include + +namespace aurora { +void app_run(std::unique_ptr app, Icon icon) noexcept {} +std::vector get_args() noexcept { + return {}; // TODO +} +WindowSize get_window_size() noexcept { + return {}; // TODO +} +void set_window_title(std::string_view title) noexcept { + // TODO +} +Backend get_backend() noexcept { + return Backend::Vulkan; // TODO +} +std::string_view get_backend_string() noexcept { + return {}; // TODO +} +void set_fullscreen(bool fullscreen) noexcept { + // TODO +} +int32_t get_controller_player_index(uint32_t which) noexcept { + return -1; // TODO +} +void set_controller_player_index(uint32_t which, int32_t index) noexcept { + // TODO +} +bool is_controller_gamecube(uint32_t which) noexcept { + return true; // TODO +} +std::string get_controller_name(uint32_t which) noexcept { + return ""; // TODO +} +} // namespace aurora diff --git a/aurora/lib/gfx/common.cpp b/aurora/lib/gfx/common.cpp new file mode 100644 index 000000000..dde449f50 --- /dev/null +++ b/aurora/lib/gfx/common.cpp @@ -0,0 +1,81 @@ +#include + +namespace aurora::gfx { +bool get_dxt_compression_supported() noexcept { + return true; // TODO +} + +void update_model_view(const zeus::CMatrix4f& mv, const zeus::CMatrix4f& mv_inv) noexcept { + // TODO +} +void update_projection(const zeus::CMatrix4f& proj) noexcept { + // TODO +} +void update_fog_state(const metaforce::CFogState& state) noexcept { + // TODO +} +void set_viewport(const zeus::CRectangle& rect, float znear, float zfar) noexcept { + // TODO +} +void set_scissor(uint32_t x, uint32_t y, uint32_t w, uint32_t h) noexcept { + // TODO +} + +void resolve_color(const ClipRect& rect, uint32_t bind, bool clear_depth) noexcept { + // TODO +} +void resolve_depth(const ClipRect& rect, uint32_t bind) noexcept { + // TODO +} + +void add_material_set(/* TODO */) noexcept {} +void add_model(/* TODO */) noexcept {} + +void queue_aabb(const zeus::CAABox& aabb, const zeus::CColor& color, bool z_only) noexcept { + // TODO +} +void queue_fog_volume_plane(const ArrayRef& verts, uint8_t pass) { + // TODO +} +void queue_fog_volume_filter(const zeus::CColor& color, bool two_way) noexcept { + // TODO +} +void queue_textured_quad_verts(CameraFilterType filter_type, TextureRef texture, ZTest z_comparison, bool z_test, + const zeus::CColor& color, const ArrayRef& pos, + const ArrayRef& uvs, float lod) noexcept { + // TODO +} +void queue_textured_quad(CameraFilterType filter_type, TextureRef texture, ZTest z_comparison, bool z_test, + const zeus::CColor& color, float uv_scale, const zeus::CRectangle& rect, float z) noexcept { + // TODO +} +void queue_colored_quad_verts(CameraFilterType filter_type, ZTest z_comparison, bool z_test, const zeus::CColor& color, + const ArrayRef& pos) noexcept { + // TODO +} +void queue_colored_quad(CameraFilterType filter_type, ZTest z_comparison, bool z_test, const zeus::CColor& color, + const zeus::CRectangle& rect, float z) noexcept { + // TODO +} +void queue_movie_player(TextureRef tex_y, TextureRef tex_u, TextureRef tex_v, const zeus::CColor& color, float h_pad, + float v_pad) noexcept { + // TODO +} + +std::shared_ptr new_static_texture_2d(uint32_t width, uint32_t height, uint32_t mips, + TextureFormat format, ArrayRef data, + std::string_view label) noexcept { + return {}; // TODO +} +std::shared_ptr new_dynamic_texture_2d(uint32_t width, uint32_t height, uint32_t mips, + TextureFormat format, std::string_view label) noexcept { + return {}; // TODO +} +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) noexcept { + return {}; // TODO +} +void write_texture(TextureRef ref, ArrayRef data) noexcept { + // TODO +} +} // namespace aurora::gfx diff --git a/aurora/lib/imgui.cpp b/aurora/lib/imgui.cpp new file mode 100644 index 000000000..c9a8a25a4 --- /dev/null +++ b/aurora/lib/imgui.cpp @@ -0,0 +1,7 @@ +#include + +namespace aurora::imgui { +ImTextureID add_texture(uint32_t width, uint32_t height, ArrayRef data) noexcept { + return 0; // TODO +} +} // namespace aurora::imgui diff --git a/extern/dawn b/extern/dawn new file mode 160000 index 000000000..883681caf --- /dev/null +++ b/extern/dawn @@ -0,0 +1 @@ +Subproject commit 883681cafb2563de3b8af270726e30e83f240721 diff --git a/imgui/ImGuiEngine.cpp b/imgui/ImGuiEngine.cpp index 8d77bc2ac..d56cb4e1d 100644 --- a/imgui/ImGuiEngine.cpp +++ b/imgui/ImGuiEngine.cpp @@ -1,6 +1,6 @@ #include "ImGuiEngine.hpp" -#include "aurora_imgui.h" +#include #include "athena/Compression.hpp" @@ -69,9 +69,9 @@ Icon GetIcon() { }; } -void ImGuiEngine_AddTextures(ImGuiState& state, const DeviceHolder& gpu) { +void ImGuiEngine_AddTextures() { auto icon = GetIcon(); ImGuiEngine::metaforceIcon = - ImGuiEngine_AddTexture(state, gpu, icon.width, icon.height, {icon.data.get(), icon.size}); + aurora::imgui::add_texture(icon.width, icon.height, {icon.data.get(), icon.size}); } } // namespace metaforce diff --git a/imgui/ImGuiEngine.hpp b/imgui/ImGuiEngine.hpp index 12e4be85d..ac8c99832 100644 --- a/imgui/ImGuiEngine.hpp +++ b/imgui/ImGuiEngine.hpp @@ -14,10 +14,7 @@ public: // Called from Rust void ImGuiEngine_Initialize(float scale); - -struct ImGuiState; -struct DeviceHolder; -void ImGuiEngine_AddTextures(ImGuiState& state, const DeviceHolder& gpu); +void ImGuiEngine_AddTextures(); struct Icon { std::unique_ptr data;