From 48433876c71dc1c87109edbb572644b58a3e8081 Mon Sep 17 00:00:00 2001 From: jracek Date: Tue, 18 Mar 2025 23:46:34 +0100 Subject: [PATCH] Created basic class structure, Added renderer --- .gitignore | 13 +++++++++ .gitmodules | 3 ++ Makefile | 7 +++++ src/gameobject.hh | 17 ++++++++++++ src/main.cpp | 68 ++++++++++++++++++++++++++++++++++++++++++++++ src/mesh.hh | 24 ++++++++++++++++ src/renderer.cpp | 66 ++++++++++++++++++++++++++++++++++++++++++++ src/renderer.hh | 30 ++++++++++++++++++++ src/texture.hh | 14 ++++++++++ third_party/nugget | 1 + 10 files changed, 243 insertions(+) create mode 100644 .gitignore create mode 100644 .gitmodules create mode 100644 Makefile create mode 100644 src/gameobject.hh create mode 100644 src/main.cpp create mode 100644 src/mesh.hh create mode 100644 src/renderer.cpp create mode 100644 src/renderer.hh create mode 100644 src/texture.hh create mode 160000 third_party/nugget diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0d3b5c8 --- /dev/null +++ b/.gitignore @@ -0,0 +1,13 @@ +PSX.Dev-README.md +*.elf +*.map +*.cpe +*.ps-exe +*.dep +*.o +*.a + +.cache/ +.vscode/ +.editorconfig +compile_commands.json diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..d96a991 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "third_party/nugget"] + path = third_party/nugget + url = https://github.com/pcsx-redux/nugget.git diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..a1fe741 --- /dev/null +++ b/Makefile @@ -0,0 +1,7 @@ +TARGET = psxsplash +TYPE = ps-exe + +SRCS = \ +src/main.cpp + +include third_party/nugget/psyqo/psyqo.mk diff --git a/src/gameobject.hh b/src/gameobject.hh new file mode 100644 index 0000000..f3a9994 --- /dev/null +++ b/src/gameobject.hh @@ -0,0 +1,17 @@ +#pragma once + +#include "psyqo/trigonometry.hh" +#include "psyqo/vector.hh" + +#include "mesh.hh" + +namespace psxsplash { + + class GameObject final { + public: + psyqo::Vec3 m_pos; + psyqo::Angle m_rot[3]; + Mesh m_mesh; + bool m_is_static; + }; +} \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..ae447b6 --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,68 @@ +#include + +#include "psyqo/application.hh" +#include "psyqo/font.hh" +#include "psyqo/gpu.hh" +#include "psyqo/scene.hh" + +#include "renderer.hh" + +namespace { + +class PSXSplash final : public psyqo::Application { + + void prepare() override; + void createScene() override; + + public: + psyqo::Font<> m_font; + psxsplash::Renderer m_renderer; + PSXSplash() : m_renderer(gpu()) {} +}; + +class MainScene final : public psyqo::Scene { + void frame() override; + + uint8_t m_anim = 0; + bool m_direction = true; +}; + +PSXSplash psxSplash; +MainScene mainScene; + +} + +void PSXSplash::prepare() { + psyqo::GPU::Configuration config; + config.set(psyqo::GPU::Resolution::W320) + .set(psyqo::GPU::VideoMode::AUTO) + .set(psyqo::GPU::ColorMode::C15BITS) + .set(psyqo::GPU::Interlace::PROGRESSIVE); + gpu().initialize(config); +} + +void PSXSplash::createScene() { + m_font.uploadSystemFont(gpu()); + pushScene(&mainScene); +} + +void MainScene::frame() { + if (m_anim == 0) { + m_direction = true; + } else if (m_anim == 255) { + m_direction = false; + } + psyqo::Color bg{{.r = 0, .g = 64, .b = 91}}; + bg.r = m_anim; + psxSplash.gpu().clear(bg); + if (m_direction) { + m_anim++; + } else { + m_anim--; + } + + psyqo::Color c = {{.r = 255, .g = 255, .b = uint8_t(255 - m_anim)}}; + psxSplash.m_font.print(psxSplash.gpu(), "Hello World!", {{.x = 16, .y = 32}}, c); +} + +int main() { return psxSplash.run(); } diff --git a/src/mesh.hh b/src/mesh.hh new file mode 100644 index 0000000..8bbd487 --- /dev/null +++ b/src/mesh.hh @@ -0,0 +1,24 @@ +#pragma once + +#include "EASTL/array.h" +#include "psyqo/gte-registers.hh" +#include "psyqo/primitives/common.hh" +#include "texture.hh" + +namespace psxsplash { + +class Tri final { + public: + psyqo::GTE::PackedVec3 v0,v1,v2; + psyqo::GTE::PackedVec3 n0,n1,n2; + psyqo::PrimPieces::UVCoords uvA, uvB; + psyqo::PrimPieces::UVCoordsPadded uvC; + psyqo::Color colorA, colorB, colorC; +}; + +class Mesh final { + public: + Texture m_texture; + eastl::array m_polygons; +}; +} \ No newline at end of file diff --git a/src/renderer.cpp b/src/renderer.cpp new file mode 100644 index 0000000..4293a37 --- /dev/null +++ b/src/renderer.cpp @@ -0,0 +1,66 @@ +#include + +#include "psyqo/primitives/triangles.hh" + +#include "renderer.hh" +#include "gameobject.hh" + +void psxsplash::Renderer::render(eastl::array &objects) { + uint8_t parity = m_gpu.getParity(); + + auto& ot = m_ots[parity]; + auto& clear = m_clear[parity]; + auto& balloc = m_ballocs[parity]; + + eastl::array projected; + + m_gpu.getNextClear(clear.primitive, m_clearcolor); + m_gpu.chain(clear); + + balloc.reset(); + + for (auto& obj : objects) { + + auto& mesh = obj.m_mesh; + auto& texture = mesh.m_texture; + + for (auto& tri : mesh.m_polygons) { + + + psyqo::GTE::writeUnsafe(tri.v0); + psyqo::GTE::writeUnsafe(tri.v1); + psyqo::GTE::writeUnsafe(tri.v2); + + psyqo::GTE::Kernels::rtpt(); + psyqo::GTE::Kernels::nclip(); + + int32_t mac0 = 0; + psyqo::GTE::read(reinterpret_cast(&mac0)); + if (mac0 <= 0) continue; + + psyqo::GTE::Kernels::avsz4(); + int32_t zIndex = 0; + psyqo::GTE::read(reinterpret_cast(&zIndex)); + if (zIndex < 0 || zIndex >= ORDERING_TABLE_SIZE) continue; + + psyqo::GTE::read(&projected[1].packed); + psyqo::GTE::read(&projected[2].packed); + psyqo::GTE::read(&projected[3].packed); + + auto& prim = balloc.allocate>(); + + prim.primitive.pointA = projected[0]; + prim.primitive.pointB = projected[1]; + prim.primitive.pointC = projected[2]; + prim.primitive.uvA = tri.uvA; + prim.primitive.uvB = tri.uvB; + prim.primitive.uvC = tri.uvC; + prim.primitive.tpage = texture.m_tpage; + + ot.insert(prim, zIndex); + } + + } + + m_gpu.chain(ot); +} \ No newline at end of file diff --git a/src/renderer.hh b/src/renderer.hh new file mode 100644 index 0000000..e6ea891 --- /dev/null +++ b/src/renderer.hh @@ -0,0 +1,30 @@ +#pragma once + +#include "EASTL/array.h" +#include "gameobject.hh" +#include "psyqo/fragments.hh" +#include "psyqo/gpu.hh" +#include "psyqo/ordering-table.hh" +#include "psyqo/primitives/common.hh" +#include "psyqo/primitives/misc.hh" +#include "psyqo/bump-allocator.hh" + +namespace psxsplash { + +class Renderer final { + static constexpr size_t ORDERING_TABLE_SIZE = 1024; + static constexpr size_t BUMP_ALLOCATOR_SIZE = 100000; + + psyqo::GPU& m_gpu; + + public: + psyqo::OrderingTable m_ots[2]; + psyqo::Fragments::SimpleFragment m_clear[2]; + psyqo::Color m_clearcolor = {.r = 0, .g = 0, .b = 0}; + psyqo::BumpAllocator m_ballocs[2]; + + Renderer(psyqo::GPU& gpuInstance) : m_gpu(gpuInstance) {} + void render(eastl::array& objects); +}; + +} \ No newline at end of file diff --git a/src/texture.hh b/src/texture.hh new file mode 100644 index 0000000..58e3969 --- /dev/null +++ b/src/texture.hh @@ -0,0 +1,14 @@ +#pragma once + +#include + +#include "psyqo/primitives/common.hh" + +namespace psxsplash { +class Texture final { + public: + psyqo::Prim::TPageAttr::ColorMode m_colormode; + psyqo::PrimPieces::TPageAttr m_tpage; + uint8_t m_width, m_height; +}; +} \ No newline at end of file diff --git a/third_party/nugget b/third_party/nugget new file mode 160000 index 0000000..e429a93 --- /dev/null +++ b/third_party/nugget @@ -0,0 +1 @@ +Subproject commit e429a934eb8bf25d08ea0e2fe278b32653579c8e