Splashpack fixes, rendering from splaspack now works

This commit is contained in:
2025-03-23 00:04:20 +01:00
parent 29cbd54254
commit 3c6989c291
5 changed files with 44 additions and 37 deletions

View File

@@ -7,8 +7,8 @@
#include "psyqo/gpu.hh"
#include "psyqo/scene.hh"
#include "renderer.hh"
#include "output.h"
#include "renderer.hh"
#include "splashpack.hh"
namespace {
@@ -25,7 +25,7 @@ class PSXSplash final : public psyqo::Application {
class MainScene final : public psyqo::Scene {
void frame() override;
void start(StartReason reason) override;
eastl::vector<psxsplash::GameObject*> objects;
eastl::vector<psxsplash::GameObject *> objects;
};
PSXSplash psxSplash;
@@ -48,7 +48,6 @@ void PSXSplash::createScene() {
pushScene(&mainScene);
}
void MainScene::start(StartReason reason) {
objects = psxsplash::LoadSplashpack(bin2c_output_bin);
}

File diff suppressed because one or more lines are too long

View File

@@ -4,6 +4,7 @@
#include "psyqo/fixed-point.hh"
#include "psyqo/gte-kernels.hh"
#include "psyqo/gte-registers.hh"
#include "psyqo/primitives/common.hh"
#include "psyqo/primitives/triangles.hh"
#include "psyqo/soft-math.hh"
#include "psyqo/trigonometry.hh"
@@ -54,18 +55,11 @@ void psxsplash::Renderer::render(eastl::vector<GameObject *> &objects) {
for (auto &obj : objects) {
/*psyqo::GTE::write<psyqo::GTE::Register::TRX, psyqo::GTE::Unsafe>(
obj->position.x.raw());
psyqo::GTE::write<psyqo::GTE::Register::TRY, psyqo::GTE::Unsafe>(
obj->position.y.raw());
auto transform = psyqo::SoftMath::generateRotationMatrix33(
0, psyqo::SoftMath::Axis::X, m_trig);
psyqo::GTE::writeUnsafe<psyqo::GTE::PseudoRegister::Rotation>(
obj->rotation);*/
transform);
psyqo::GTE::write<psyqo::GTE::Register::TRZ, psyqo::GTE::Unsafe>(1024);
psyqo::GTE::writeUnsafe<psyqo::GTE::PseudoRegister::Rotation>(
obj->rotation);
for (int i = 0; i < obj->polyCount; i++) {
Tri &tri = obj->polygons[i];
@@ -80,23 +74,24 @@ void psxsplash::Renderer::render(eastl::vector<GameObject *> &objects) {
int32_t mac0 = 0;
psyqo::GTE::read<psyqo::GTE::Register::MAC0>(
reinterpret_cast<uint32_t *>(&mac0));
// if (mac0 <= 0)
// continue;
if (mac0 <= 0)
continue;
psyqo::GTE::Kernels::avsz3();
int32_t zIndex = 0;
psyqo::GTE::read<psyqo::GTE::Register::OTZ>(
reinterpret_cast<uint32_t *>(&zIndex));
// if (zIndex < 0 || zIndex >= ORDERING_TABLE_SIZE)
// continue;
if (zIndex < 0 || zIndex >= ORDERING_TABLE_SIZE)
continue;
psyqo::GTE::read<psyqo::GTE::Register::SXY0>(&projected[0].packed);
psyqo::GTE::read<psyqo::GTE::Register::SXY1>(&projected[1].packed);
psyqo::GTE::read<psyqo::GTE::Register::SXY2>(&projected[2].packed);
auto &prim =
balloc.allocateFragment<psyqo::Prim::TexturedTriangle>();
balloc.allocateFragment<psyqo::Prim::GouraudTexturedTriangle>();
prim.primitive.pointA = projected[0];
prim.primitive.pointB = projected[1];
prim.primitive.pointC = projected[2];
@@ -104,8 +99,11 @@ void psxsplash::Renderer::render(eastl::vector<GameObject *> &objects) {
prim.primitive.uvB = tri.uvB;
prim.primitive.uvC = tri.uvC;
prim.primitive.tpage = obj->texture;
prim.primitive.tpage.setPageX(5);
prim.primitive.tpage.setPageY(0);
prim.primitive.tpage.setDithering(true);
prim.primitive.setColorA(tri.colorA);
prim.primitive.setColorB(tri.colorB);
prim.primitive.setColorC(tri.colorC);
prim.primitive.setOpaque();

View File

@@ -21,7 +21,7 @@ class Renderer final {
Renderer(const Renderer&) = delete;
Renderer& operator=(const Renderer&) = delete;
static constexpr size_t ORDERING_TABLE_SIZE = 1024;
static constexpr size_t ORDERING_TABLE_SIZE = 4096*16;
static constexpr size_t BUMP_ALLOCATOR_SIZE = 100000;
static void init(psyqo::GPU &gpuInstance);

View File

@@ -7,33 +7,43 @@
namespace psxsplash {
eastl::vector<psxsplash::GameObject*> LoadSplashpack(uint8_t *data) {
psyqo::Kernel::assert(data != nullptr, "Splashpack loading data pointer is null");
eastl::vector<psxsplash::GameObject *> LoadSplashpack(uint8_t *data) {
psyqo::Kernel::assert(data != nullptr,
"Splashpack loading data pointer is null");
psxsplash::SPLASHPACKFileHeader *header =
reinterpret_cast<psxsplash::SPLASHPACKFileHeader *>(data);
psyqo::Kernel::assert(memcmp(header->magic, "SP", 2) == 0, "Splashpack has incorrect magic");
psyqo::Kernel::assert(memcmp(header->magic, "SP", 2) == 0,
"Splashpack has incorrect magic");
eastl::vector<psxsplash::GameObject*> gameObjects;
eastl::vector<psxsplash::GameObject *> gameObjects;
gameObjects.reserve(header->gameObjectCount);
uint8_t* curentPointer = data + sizeof(psxsplash::SPLASHPACKFileHeader);
uint8_t *curentPointer = data + sizeof(psxsplash::SPLASHPACKFileHeader);
for(uint16_t i = 0; i < header->gameObjectCount; i++) {
psxsplash::GameObject* go = reinterpret_cast<psxsplash::GameObject*>(curentPointer);
go->polygons = reinterpret_cast<psxsplash::Tri*>(data + go->polygonsOffset);
for (uint16_t i = 0; i < header->gameObjectCount; i++) {
psxsplash::GameObject *go =
reinterpret_cast<psxsplash::GameObject *>(curentPointer);
go->polygons =
reinterpret_cast<psxsplash::Tri *>(data + go->polygonsOffset);
gameObjects.push_back(go);
curentPointer += sizeof(psxsplash::GameObject);
}
for(uint16_t i = 0; i < header->textureAtlasCount; i++) {
psxsplash::SPLASHPACKTextureAtlas* atlas = reinterpret_cast<psxsplash::SPLASHPACKTextureAtlas *>(curentPointer);
uint8_t* offsetData = data + atlas->polygonsOffset; // Ensure correct byte offset
uint16_t* castedData = reinterpret_cast<uint16_t*>(offsetData); // Safe cast
psxsplash::Renderer::getInstance().vramUpload(castedData, atlas->x, atlas->y, atlas->width, atlas->height);
for (uint16_t i = 0; i < header->textureAtlasCount; i++) {
psxsplash::SPLASHPACKTextureAtlas *atlas =
reinterpret_cast<psxsplash::SPLASHPACKTextureAtlas *>(
curentPointer);
uint8_t *offsetData =
data + atlas->polygonsOffset; // Ensure correct byte offset
uint16_t *castedData =
reinterpret_cast<uint16_t *>(offsetData); // Safe cast
psxsplash::Renderer::getInstance().vramUpload(
castedData, atlas->x, atlas->y, atlas->width, atlas->height);
curentPointer += sizeof(psxsplash::SPLASHPACKTextureAtlas);
}
return gameObjects;
}
}
} // namespace psxsplash