Added translation and rotation, initializing GTE with the renderer
This commit is contained in:
3
Makefile
3
Makefile
@@ -2,6 +2,7 @@ TARGET = psxsplash
|
|||||||
TYPE = ps-exe
|
TYPE = ps-exe
|
||||||
|
|
||||||
SRCS = \
|
SRCS = \
|
||||||
src/main.cpp
|
src/main.cpp \
|
||||||
|
src/renderer.cpp
|
||||||
|
|
||||||
include third_party/nugget/psyqo/psyqo.mk
|
include third_party/nugget/psyqo/psyqo.mk
|
||||||
|
|||||||
22
src/main.cpp
22
src/main.cpp
@@ -1,5 +1,7 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#include "EASTL/array.h"
|
||||||
|
#include "gameobject.hh"
|
||||||
#include "psyqo/application.hh"
|
#include "psyqo/application.hh"
|
||||||
#include "psyqo/font.hh"
|
#include "psyqo/font.hh"
|
||||||
#include "psyqo/gpu.hh"
|
#include "psyqo/gpu.hh"
|
||||||
@@ -25,6 +27,8 @@ class MainScene final : public psyqo::Scene {
|
|||||||
|
|
||||||
uint8_t m_anim = 0;
|
uint8_t m_anim = 0;
|
||||||
bool m_direction = true;
|
bool m_direction = true;
|
||||||
|
|
||||||
|
eastl::array<psxsplash::GameObject> objects;
|
||||||
};
|
};
|
||||||
|
|
||||||
PSXSplash psxSplash;
|
PSXSplash psxSplash;
|
||||||
@@ -39,6 +43,7 @@ void PSXSplash::prepare() {
|
|||||||
.set(psyqo::GPU::ColorMode::C15BITS)
|
.set(psyqo::GPU::ColorMode::C15BITS)
|
||||||
.set(psyqo::GPU::Interlace::PROGRESSIVE);
|
.set(psyqo::GPU::Interlace::PROGRESSIVE);
|
||||||
gpu().initialize(config);
|
gpu().initialize(config);
|
||||||
|
m_renderer.initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PSXSplash::createScene() {
|
void PSXSplash::createScene() {
|
||||||
@@ -47,22 +52,7 @@ void PSXSplash::createScene() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void MainScene::frame() {
|
void MainScene::frame() {
|
||||||
if (m_anim == 0) {
|
psxSplash.m_renderer.render(objects);
|
||||||
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(); }
|
int main() { return psxSplash.run(); }
|
||||||
|
|||||||
@@ -2,15 +2,30 @@
|
|||||||
|
|
||||||
#include "psyqo/primitives/triangles.hh"
|
#include "psyqo/primitives/triangles.hh"
|
||||||
|
|
||||||
#include "renderer.hh"
|
|
||||||
#include "gameobject.hh"
|
#include "gameobject.hh"
|
||||||
|
#include "psyqo/soft-math.hh"
|
||||||
|
#include "renderer.hh"
|
||||||
|
|
||||||
|
void psxsplash::Renderer::initialize() {
|
||||||
|
psyqo::GTE::clear<psyqo::GTE::Register::TRX, psyqo::GTE::Unsafe>();
|
||||||
|
psyqo::GTE::clear<psyqo::GTE::Register::TRY, psyqo::GTE::Unsafe>();
|
||||||
|
psyqo::GTE::clear<psyqo::GTE::Register::TRZ, psyqo::GTE::Unsafe>();
|
||||||
|
|
||||||
|
psyqo::GTE::write<psyqo::GTE::Register::OFX, psyqo::GTE::Unsafe>(psyqo::FixedPoint<16>(160.0).raw());
|
||||||
|
psyqo::GTE::write<psyqo::GTE::Register::OFY, psyqo::GTE::Unsafe>(psyqo::FixedPoint<16>(120.0).raw());
|
||||||
|
|
||||||
|
psyqo::GTE::write<psyqo::GTE::Register::H, psyqo::GTE::Unsafe>(120);
|
||||||
|
|
||||||
|
psyqo::GTE::write<psyqo::GTE::Register::ZSF3, psyqo::GTE::Unsafe>(ORDERING_TABLE_SIZE / 3);
|
||||||
|
psyqo::GTE::write<psyqo::GTE::Register::ZSF4, psyqo::GTE::Unsafe>(ORDERING_TABLE_SIZE / 4);
|
||||||
|
}
|
||||||
|
|
||||||
void psxsplash::Renderer::render(eastl::array<GameObject> &objects) {
|
void psxsplash::Renderer::render(eastl::array<GameObject> &objects) {
|
||||||
uint8_t parity = m_gpu.getParity();
|
uint8_t parity = m_gpu.getParity();
|
||||||
|
|
||||||
auto& ot = m_ots[parity];
|
auto &ot = m_ots[parity];
|
||||||
auto& clear = m_clear[parity];
|
auto &clear = m_clear[parity];
|
||||||
auto& balloc = m_ballocs[parity];
|
auto &balloc = m_ballocs[parity];
|
||||||
|
|
||||||
eastl::array<psyqo::Vertex, 3> projected;
|
eastl::array<psyqo::Vertex, 3> projected;
|
||||||
|
|
||||||
@@ -19,13 +34,33 @@ void psxsplash::Renderer::render(eastl::array<GameObject> &objects) {
|
|||||||
|
|
||||||
balloc.reset();
|
balloc.reset();
|
||||||
|
|
||||||
for (auto& obj : objects) {
|
for (auto &obj : objects) {
|
||||||
|
|
||||||
auto& mesh = obj.m_mesh;
|
auto &mesh = obj.m_mesh;
|
||||||
auto& texture = mesh.m_texture;
|
auto &texture = mesh.m_texture;
|
||||||
|
|
||||||
for (auto& tri : mesh.m_polygons) {
|
psyqo::GTE::write<psyqo::GTE::Register::TRX, psyqo::GTE::Unsafe>(
|
||||||
|
obj.m_pos.x.raw());
|
||||||
|
psyqo::GTE::write<psyqo::GTE::Register::TRY, psyqo::GTE::Unsafe>(
|
||||||
|
obj.m_pos.y.raw());
|
||||||
|
psyqo::GTE::write<psyqo::GTE::Register::TRZ, psyqo::GTE::Unsafe>(
|
||||||
|
obj.m_pos.z.raw());
|
||||||
|
|
||||||
|
auto transform = psyqo::SoftMath::generateRotationMatrix33(
|
||||||
|
obj.m_rot[0], psyqo::SoftMath::Axis::X, m_trig);
|
||||||
|
auto rot = psyqo::SoftMath::generateRotationMatrix33(
|
||||||
|
obj.m_rot[1], psyqo::SoftMath::Axis::Y, m_trig);
|
||||||
|
|
||||||
|
psyqo::SoftMath::multiplyMatrix33(transform, rot, &transform);
|
||||||
|
|
||||||
|
auto rotZ = psyqo::SoftMath::generateRotationMatrix33(
|
||||||
|
obj.m_rot[2], psyqo::SoftMath::Axis::Z, m_trig);
|
||||||
|
|
||||||
|
psyqo::SoftMath::multiplyMatrix33(transform, rotZ, &transform);
|
||||||
|
|
||||||
|
psyqo::GTE::writeUnsafe<psyqo::GTE::PseudoRegister::Rotation>(transform);
|
||||||
|
|
||||||
|
for (auto &tri : mesh.m_polygons) {
|
||||||
|
|
||||||
psyqo::GTE::writeUnsafe<psyqo::GTE::PseudoRegister::V0>(tri.v0);
|
psyqo::GTE::writeUnsafe<psyqo::GTE::PseudoRegister::V0>(tri.v0);
|
||||||
psyqo::GTE::writeUnsafe<psyqo::GTE::PseudoRegister::V1>(tri.v1);
|
psyqo::GTE::writeUnsafe<psyqo::GTE::PseudoRegister::V1>(tri.v1);
|
||||||
@@ -35,19 +70,24 @@ void psxsplash::Renderer::render(eastl::array<GameObject> &objects) {
|
|||||||
psyqo::GTE::Kernels::nclip();
|
psyqo::GTE::Kernels::nclip();
|
||||||
|
|
||||||
int32_t mac0 = 0;
|
int32_t mac0 = 0;
|
||||||
psyqo::GTE::read<psyqo::GTE::Register::MAC0>(reinterpret_cast<uint32_t*>(&mac0));
|
psyqo::GTE::read<psyqo::GTE::Register::MAC0>(
|
||||||
if (mac0 <= 0) continue;
|
reinterpret_cast<uint32_t *>(&mac0));
|
||||||
|
if (mac0 <= 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
psyqo::GTE::Kernels::avsz4();
|
psyqo::GTE::Kernels::avsz4();
|
||||||
int32_t zIndex = 0;
|
int32_t zIndex = 0;
|
||||||
psyqo::GTE::read<psyqo::GTE::Register::OTZ>(reinterpret_cast<uint32_t*>(&zIndex));
|
psyqo::GTE::read<psyqo::GTE::Register::OTZ>(
|
||||||
if (zIndex < 0 || zIndex >= ORDERING_TABLE_SIZE) continue;
|
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::SXY0>(&projected[1].packed);
|
||||||
psyqo::GTE::read<psyqo::GTE::Register::SXY1>(&projected[2].packed);
|
psyqo::GTE::read<psyqo::GTE::Register::SXY1>(&projected[2].packed);
|
||||||
psyqo::GTE::read<psyqo::GTE::Register::SXY2>(&projected[3].packed);
|
psyqo::GTE::read<psyqo::GTE::Register::SXY2>(&projected[3].packed);
|
||||||
|
|
||||||
auto& prim = balloc.allocate<psyqo::Fragments::SimpleFragment<psyqo::Prim::TexturedTriangle>>();
|
auto &prim = balloc.allocate<
|
||||||
|
psyqo::Fragments::SimpleFragment<psyqo::Prim::TexturedTriangle>>();
|
||||||
|
|
||||||
prim.primitive.pointA = projected[0];
|
prim.primitive.pointA = projected[0];
|
||||||
prim.primitive.pointB = projected[1];
|
prim.primitive.pointB = projected[1];
|
||||||
@@ -59,7 +99,6 @@ void psxsplash::Renderer::render(eastl::array<GameObject> &objects) {
|
|||||||
|
|
||||||
ot.insert(prim, zIndex);
|
ot.insert(prim, zIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
m_gpu.chain(ot);
|
m_gpu.chain(ot);
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
#include "psyqo/primitives/common.hh"
|
#include "psyqo/primitives/common.hh"
|
||||||
#include "psyqo/primitives/misc.hh"
|
#include "psyqo/primitives/misc.hh"
|
||||||
#include "psyqo/bump-allocator.hh"
|
#include "psyqo/bump-allocator.hh"
|
||||||
|
#include "psyqo/trigonometry.hh"
|
||||||
|
|
||||||
namespace psxsplash {
|
namespace psxsplash {
|
||||||
|
|
||||||
@@ -16,14 +17,16 @@ class Renderer final {
|
|||||||
static constexpr size_t BUMP_ALLOCATOR_SIZE = 100000;
|
static constexpr size_t BUMP_ALLOCATOR_SIZE = 100000;
|
||||||
|
|
||||||
psyqo::GPU& m_gpu;
|
psyqo::GPU& m_gpu;
|
||||||
|
psyqo::Trig<> m_trig;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
psyqo::OrderingTable<ORDERING_TABLE_SIZE> m_ots[2];
|
psyqo::OrderingTable<ORDERING_TABLE_SIZE> m_ots[2];
|
||||||
psyqo::Fragments::SimpleFragment<psyqo::Prim::FastFill> m_clear[2];
|
psyqo::Fragments::SimpleFragment<psyqo::Prim::FastFill> m_clear[2];
|
||||||
psyqo::Color m_clearcolor = {.r = 0, .g = 0, .b = 0};
|
psyqo::Color m_clearcolor = {.r = 63, .g = 63, .b = 63};
|
||||||
psyqo::BumpAllocator<BUMP_ALLOCATOR_SIZE> m_ballocs[2];
|
psyqo::BumpAllocator<BUMP_ALLOCATOR_SIZE> m_ballocs[2];
|
||||||
|
|
||||||
Renderer(psyqo::GPU& gpuInstance) : m_gpu(gpuInstance) {}
|
Renderer(psyqo::GPU& gpuInstance) : m_gpu(gpuInstance) {}
|
||||||
|
void initialize();
|
||||||
void render(eastl::array<GameObject>& objects);
|
void render(eastl::array<GameObject>& objects);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user