new vu1 renderer, added vcl preprocessor

This commit is contained in:
h4570
2020-12-24 14:35:13 +01:00
parent d60d42cac6
commit aeb25ad398
11 changed files with 273 additions and 268 deletions
+11 -64
View File
@@ -39,7 +39,6 @@ VifSender::VifSender(Light *t_light)
uploadMicroProgram();
packets[0] = packet2_create(VU1_PACKET_SIZE, P2_TYPE_NORMAL, P2_MODE_CHAIN, true);
packets[1] = packet2_create(VU1_PACKET_SIZE, P2_TYPE_NORMAL, P2_MODE_CHAIN, true);
matricesPacket = packet2_create(4, P2_TYPE_NORMAL, P2_MODE_CHAIN, true);
context = 0;
setDoubleBuffer();
}
@@ -48,7 +47,6 @@ VifSender::~VifSender()
{
packet2_free(packets[0]);
packet2_free(packets[1]);
packet2_free(matricesPacket);
}
// ----
@@ -69,10 +67,8 @@ void VifSender::uploadMicroProgram()
packet2_free(packet2);
}
void VifSender::sendMatrices(const RenderData &t_renderData, const Vector3 &t_position, const Vector3 &t_rotation)
void VifSender::calcMatrix(const RenderData &t_renderData, const Vector3 &t_position, const Vector3 &t_rotation)
{
Matrix model;
model.identity();
model.rotate(t_rotation);
model.translate(t_position);
@@ -81,12 +77,6 @@ void VifSender::sendMatrices(const RenderData &t_renderData, const Vector3 &t_po
modelViewProj = model * modelViewProj;
modelViewProj = *t_renderData.view * modelViewProj;
modelViewProj = *t_renderData.projection * modelViewProj;
packet2_reset(matricesPacket, false);
packet2_utils_vu_add_unpack_data(matricesPacket, 0, &modelViewProj.data, 8, 0);
packet2_utils_vu_add_end_tag(matricesPacket);
dma_channel_wait(DMA_CHANNEL_VIF1, 0);
dma_channel_send_packet2(matricesPacket, DMA_CHANNEL_VIF1, 1);
}
void VifSender::drawMesh(RenderData *t_renderData, Matrix t_perspective, u32 vertCount2, VECTOR *vertices, VECTOR *normals, VECTOR *coordinates, Mesh &t_mesh, LightBulb *t_bulbs, u16 t_bulbsCount, texbuffer_t *textureBuffer)
@@ -122,9 +112,9 @@ void VifSender::drawMesh(RenderData *t_renderData, Matrix t_perspective, u32 ver
void VifSender::setDoubleBuffer()
{
packet2_t *settings = packet2_create(2, P2_TYPE_NORMAL, P2_MODE_CHAIN, true);
packet2_utils_vu_add_double_buffer(settings, 8, 496);
packet2_utils_vu_add_double_buffer(settings, 10, 498);
packet2_utils_vu_add_end_tag(settings);
dma_channel_send_packet2(settings, DMA_CHANNEL_VIF1, 1);
dma_channel_send_packet2(settings, DMA_CHANNEL_VIF1, true);
dma_channel_wait(DMA_CHANNEL_VIF1, 0);
packet2_free(settings);
}
@@ -134,67 +124,24 @@ void VifSender::drawVertices(Mesh &t_mesh, u32 t_start, u32 t_end, VECTOR *t_ver
{
const u32 vertCount = t_end - t_start;
u32 vif_added_bytes = 0;
packet2_utils_vu_open_unpack(currPacket, 0, 1);
// TODO get this via screensettings
packet2_add_float(currPacket, 2048.0F); // scale
packet2_add_float(currPacket, 2048.0F); // scale
packet2_add_float(currPacket, ((float)0xFFFFFF) / 32.0F); // scale
packet2_add_u32(currPacket, vertCount); // vertex count
packet2_utils_vu_open_unpack(currPacket, 0, true);
packet2_add_data(currPacket, modelViewProj.data, 4);
packet2_add_u32(currPacket, 0); // Free
packet2_add_u32(currPacket, vertCount); // Vertex count
packet2_add_u32(currPacket, vertCount / 3); // Triangles count
packet2_add_u32(currPacket, 0); // Free
packet2_utils_gif_add_set(currPacket, 1);
packet2_utils_gs_add_lod(currPacket, &t_mesh.lod);
packet2_utils_gs_add_texbuff_clut(currPacket, textureBuffer, &t_mesh.clut);
packet2_utils_gs_add_prim_giftag(currPacket, t_prim, vertCount, DRAW_STQ2_REGLIST, 3, 0);
packet2_add_u32(currPacket, t_mesh.color.r);
packet2_add_u32(currPacket, t_mesh.color.g);
packet2_add_u32(currPacket, t_mesh.color.b);
packet2_add_u32(currPacket, t_mesh.color.a);
// Clipping tests start
// // const float minZ = 1;
// // const float maxZ = 65535;
// // const int iGuardDimXY = 2048;
// // vu1.addFloat(1.0F); // f_TODO clipping maybe there is problem?
// // vu1.addFloat(1.0F);
// // vu1.addFloat(1.0F);
// // vu1.addFloat(1.0F);
// // float xClip = (float)2048.0f/(drawContext.GetFBWidth() * 0.5f * 2.0f);
// // packet += Math::Max( xClip, 1.0f );
// // float yClip = (float)2048.0f/(drawContext.GetFBHeight() * 0.5f * 2.0f);
// // packet += Math::Max( yClip, 1.0f );
// // float depthClip = 2048.0f / depthClipToGs;
// // // F_FIXME: maybe these 2048's should be 2047.5s...
// // depthClip *= 1.003f; // round up a bit for fp error (????)
// // packet += depthClip;
// // // enable/disable clipping
// // packet += (drawContext.GetDoClipping()) ? 1 : 0;
// u32 depthBits = 24; // or 28(fog) or 16
// float depthClipToGs = (float)((1 << depthBits) - 1) / 2.0f;
// vu1.addFloat(2048.0f / (640.0F * 0.5f * 2.0f));
// vu1.addFloat(2048.0f / (480.0F * 0.5f * 2.0f));
// vu1.addFloat((2048.0f / depthClipToGs) * 1.003F);
// // vu1.addFloat(2048.0F); // scale
// // vu1.addFloat(2048.0F); // scale
// // vu1.addFloat(((float)0xFFFFFF) / 32.0F); // scale
// vu1.addFloat(0.0F);
// // vu1.addFloat(0.5f * iGuardDimXY);
// // vu1.addFloat(-0.5f * iGuardDimXY);
// // vu1.addFloat(1.0F);
// // vu1.addFloat(500.0F); // far
packet2_add_float(currPacket, 0.0F);
packet2_add_float(currPacket, 0.0F);
packet2_add_float(currPacket, 0.0F);
packet2_add_float(currPacket, 0.0F);
//// Clipping tests end
vif_added_bytes += packet2_utils_vu_close_unpack(currPacket);
packet2_utils_vu_add_unpack_data(currPacket, vif_added_bytes, t_vertices + t_start, vertCount, 1);
packet2_utils_vu_add_unpack_data(currPacket, vif_added_bytes, t_vertices + t_start, vertCount, true);
vif_added_bytes += vertCount;
packet2_utils_vu_add_unpack_data(currPacket, vif_added_bytes, t_coordinates + t_start, vertCount, 1);
packet2_utils_vu_add_unpack_data(currPacket, vif_added_bytes, t_coordinates + t_start, vertCount, true);
vif_added_bytes += vertCount;
packet2_utils_vu_add_start_program(currPacket, 0);
}