Created basic class structure, Added renderer

This commit is contained in:
2025-03-18 23:46:34 +01:00
commit 48433876c7
10 changed files with 243 additions and 0 deletions

17
src/gameobject.hh Normal file
View File

@@ -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;
};
}

68
src/main.cpp Normal file
View File

@@ -0,0 +1,68 @@
#include <stdint.h>
#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(); }

24
src/mesh.hh Normal file
View File

@@ -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<Tri> m_polygons;
};
}

66
src/renderer.cpp Normal file
View File

@@ -0,0 +1,66 @@
#include <cstdint>
#include "psyqo/primitives/triangles.hh"
#include "renderer.hh"
#include "gameobject.hh"
void psxsplash::Renderer::render(eastl::array<GameObject> &objects) {
uint8_t parity = m_gpu.getParity();
auto& ot = m_ots[parity];
auto& clear = m_clear[parity];
auto& balloc = m_ballocs[parity];
eastl::array<psyqo::Vertex, 3> 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<psyqo::GTE::PseudoRegister::V0>(tri.v0);
psyqo::GTE::writeUnsafe<psyqo::GTE::PseudoRegister::V1>(tri.v1);
psyqo::GTE::writeUnsafe<psyqo::GTE::PseudoRegister::V2>(tri.v2);
psyqo::GTE::Kernels::rtpt();
psyqo::GTE::Kernels::nclip();
int32_t mac0 = 0;
psyqo::GTE::read<psyqo::GTE::Register::MAC0>(reinterpret_cast<uint32_t*>(&mac0));
if (mac0 <= 0) continue;
psyqo::GTE::Kernels::avsz4();
int32_t zIndex = 0;
psyqo::GTE::read<psyqo::GTE::Register::OTZ>(reinterpret_cast<uint32_t*>(&zIndex));
if (zIndex < 0 || zIndex >= ORDERING_TABLE_SIZE) continue;
psyqo::GTE::read<psyqo::GTE::Register::SXY0>(&projected[1].packed);
psyqo::GTE::read<psyqo::GTE::Register::SXY1>(&projected[2].packed);
psyqo::GTE::read<psyqo::GTE::Register::SXY2>(&projected[3].packed);
auto& prim = balloc.allocate<psyqo::Fragments::SimpleFragment<psyqo::Prim::TexturedTriangle>>();
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);
}

30
src/renderer.hh Normal file
View File

@@ -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<ORDERING_TABLE_SIZE> m_ots[2];
psyqo::Fragments::SimpleFragment<psyqo::Prim::FastFill> m_clear[2];
psyqo::Color m_clearcolor = {.r = 0, .g = 0, .b = 0};
psyqo::BumpAllocator<BUMP_ALLOCATOR_SIZE> m_ballocs[2];
Renderer(psyqo::GPU& gpuInstance) : m_gpu(gpuInstance) {}
void render(eastl::array<GameObject>& objects);
};
}

14
src/texture.hh Normal file
View File

@@ -0,0 +1,14 @@
#pragma once
#include <cstdint>
#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;
};
}