fixing rendering issue on real PS2

This commit is contained in:
Sandro Sobczyński
2020-11-08 21:50:06 +01:00
parent b11df0262e
commit 3b5fb1b670
14 changed files with 110 additions and 77 deletions
+1 -1
View File
@@ -104,7 +104,7 @@ void Engine::gameLoop()
timer.primeTimer();
renderer->endFrame(fps);
/** -6~ FPS */
SetAlarm(fps > 49.0F ? 24 : 48, &Engine::wakeup, &mainThreadId);
SetAlarm(150, &Engine::wakeup, &mainThreadId);
SleepThread();
}
}
@@ -22,6 +22,7 @@ public:
DffLoader();
~DffLoader();
// void im_not_used_anywhere(MeshFrame *o_result, char *t_fileName, float t_scale, u8 t_invertT);
void load(MeshFrame *o_result, char *t_fileName, float t_scale, u8 t_invertT);
void serialize(MeshFrame *o_result, u8 t_invertT, u8 *t_data, float t_scale);
+2 -4
View File
@@ -147,10 +147,8 @@ private:
_isBoundingBoxCalculated;
u32 vertexCount, stsCount, normalsCount, materialsCount;
MeshMaterial *materials;
Point *sts __attribute__((aligned(16)));
Vector3
*vertices __attribute__((aligned(16))),
*normals __attribute__((aligned(16)));
Point __attribute__((aligned(16))) * sts;
Vector3 __attribute__((aligned(16))) * vertices, *normals;
};
#endif
+14 -18
View File
@@ -32,10 +32,12 @@ BmpLoader::~BmpLoader() {}
*/
void BmpLoader::load(MeshTexture &o_texture, char *t_subfolder, char *t_name, char *t_extension)
{
char *t_path_part = String::createConcatenated(t_subfolder, t_name);
char *t_path = String::createConcatenated(t_path_part, t_extension);
delete[] t_path_part;
FILE *file = fopen(t_path, "rb");
char *path_part1 = String::createConcatenated(t_subfolder, t_name);
char *path_part2 = String::createConcatenated("host:", path_part1);
char *path = String::createConcatenated(path_part2, t_extension);
delete[] path_part1;
delete[] path_part2;
FILE *file = fopen(path, "rb");
if (file == NULL)
{
@@ -46,8 +48,8 @@ void BmpLoader::load(MeshTexture &o_texture, char *t_subfolder, char *t_name, ch
unsigned char header[54];
fread(header, sizeof(unsigned char), 54, file);
u32 width = *(u32 *)&header[18];
u32 height = *(u32 *)&header[22];
u32 width = (u32)header[18];
u32 height = (u32)header[22];
o_texture.setSize(width, height);
printf("BMPLoader - width: %d | height: %d\n", width, height);
if (width > 128 || height > 128)
@@ -55,27 +57,21 @@ void BmpLoader::load(MeshTexture &o_texture, char *t_subfolder, char *t_name, ch
u64 rowPadded = (width * 3 + 3) & (~3);
unsigned char *data = new unsigned char[rowPadded];
unsigned char tmp;
unsigned char row[rowPadded];
u32 x = 0;
for (u32 i = 0; i < height; i++)
{
fread(data, sizeof(unsigned char), rowPadded, file);
fread(&row, sizeof(unsigned char), rowPadded, file);
for (u32 j = 0; j < width * 3; j += 3)
{
// Convert (B, G, R) to (R, G, B)
tmp = data[j];
data[j] = data[j + 2];
data[j + 2] = tmp;
o_texture.setData(x, data[j]);
o_texture.setData(x + 1, data[j + 1]);
o_texture.setData(x + 2, data[j + 2]);
o_texture.setData(x, row[j + 2]);
o_texture.setData(x + 1, row[j + 1]);
o_texture.setData(x + 2, row[j]);
x += 3;
}
}
delete[] t_path;
delete[] data;
delete[] path;
fclose(file);
}
+22 -1
View File
@@ -37,7 +37,8 @@ DffLoader::~DffLoader() {}
void DffLoader::load(MeshFrame *o_result, char *t_filename, float t_scale, u8 t_invertT)
{
PRINT_LOG("Loading dff file");
FILE *file = fopen(t_filename, "rb");
char *path = String::createConcatenated("host:", t_filename);
FILE *file = fopen(path, "rb");
if (file == NULL)
PRINT_ERR("Failed to load .dff file!");
fseek(file, 0L, SEEK_END);
@@ -48,9 +49,29 @@ void DffLoader::load(MeshFrame *o_result, char *t_filename, float t_scale, u8 t_
fclose(file);
serialize(o_result, t_invertT, data, t_scale);
o_result->calculateBoundingBoxes();
delete[] path;
PRINT_LOG("Dff file loaded!");
}
// void DffLoader::im_not_used_anywhere(MeshFrame *o_result, char *t_filename, float t_scale, u8 t_invertT)
// {
// PRINT_LOG("Loading dff file");
// char *path = String::createConcatenated("host:", t_filename);
// FILE *file = fopen(path, "rb");
// if (file == NULL)
// PRINT_ERR("Failed to load .dff file!");
// fseek(file, 0L, SEEK_END);
// long fileSize = ftell(file);
// u8 data[fileSize];
// rewind(file);
// fread(&data, sizeof(u8), fileSize, file);
// fclose(file);
// serialize(o_result, t_invertT, data, t_scale);
// o_result->calculateBoundingBoxes();
// delete[] path;
// PRINT_LOG("Dff file loaded!");
// }
void DffLoader::serialize(MeshFrame *o_result, u8 t_invertT, u8 *t_data, float t_scale)
{
u32 ptrPos = 0;
+3 -1
View File
@@ -46,8 +46,10 @@ MeshFrame *MD2Loader::load(u32 &o_framesCount, char *t_subpath, char *t_nameWith
{
PRINT_LOG("Loading new MD2 file");
char *part1 = String::createConcatenated(t_subpath, t_nameWithoutExtension);
char *finalPath = String::createConcatenated(part1, ".md2"); // "folder/object.md2"
char *part2 = String::createConcatenated("host:", part1);
char *finalPath = String::createConcatenated(part2, ".md2"); // "folder/object.md2"
delete[] part1;
delete[] part2;
md2_t header;
FILE *file = fopen(finalPath, "rb");
+3 -1
View File
@@ -28,7 +28,8 @@ ObjLoader::~ObjLoader() {}
void ObjLoader::load(MeshFrame *o_result, char *t_filename, float t_scale, u8 t_invertT)
{
FILE *file = fopen(t_filename, "rb");
char *path = String::createConcatenated("host:", t_filename);
FILE *file = fopen(path, "rb");
if (file == NULL)
PRINT_ERR("Failed to load .obj file!");
allocateObjMemory(file, o_result);
@@ -98,6 +99,7 @@ void ObjLoader::load(MeshFrame *o_result, char *t_filename, float t_scale, u8 t_
}
o_result->calculateBoundingBoxes();
fclose(file);
delete[] path;
}
/** Calculate how many vertices(v), coordinates(vt), normals(vn) and faces(f) have .obj file */
+5 -1
View File
@@ -13,6 +13,7 @@
#include "../include/utils/math.hpp"
#include "../include/utils/debug.hpp"
#include "../include/modules/light.hpp"
#include <kernel.h>
#include <dma.h>
#include <draw.h>
#include <stdio.h>
@@ -61,6 +62,7 @@ void GifSender::sendTexture(MeshTexture &texture, texbuffer_t *t_texBuffer)
q++;
q = draw_texture_wrapping(q, 0, texture.getWrapSettings());
q = draw_texture_flush(q);
FlushCache(0);
dma_channel_send_chain(DMA_CHANNEL_GIF, packet->data, q - packet->data, 0, 0);
dma_wait_fast();
packet_free(packet);
@@ -79,6 +81,7 @@ void GifSender::sendClear(zbuffer_t *t_zBuffer)
q = draw_enable_tests(q, 0, t_zBuffer);
q = draw_finish(q);
DMATAG_END(packet->data, q - packet->data - 1, 0, 0, 0);
FlushCache(0);
dma_channel_send_chain(DMA_CHANNEL_GIF, packet->data, q - packet->data, 0, 0);
dma_wait_fast();
packet_free(packet);
@@ -108,8 +111,9 @@ void GifSender::sendPacket()
}
q = draw_finish(q);
DMATAG_END(dmatag, q - dmatag - 1, 0, 0, 0);
dma_wait_fast();
FlushCache(0);
dma_channel_send_chain(DMA_CHANNEL_GIF, currentPacket->data, q - currentPacket->data, 0, 0);
dma_wait_fast();
}
/** Adds clear screen to current packet */
+3 -6
View File
@@ -222,15 +222,12 @@ void Renderer::draw(Mesh &t_mesh, LightBulb *t_bulbs, u16 t_bulbsCount)
if (t_mesh.shouldBeFrustumCulled && !t_mesh.getMaterial(i).isInFrustum(renderData.frustumPlanes, t_mesh.position))
return;
u32 vertCount = t_mesh.getMaterial(i).getFacesCount();
VECTOR *vertices = new VECTOR[vertCount];
VECTOR *normals = new VECTOR[vertCount];
VECTOR *coordinates = new VECTOR[vertCount];
VECTOR __attribute__((aligned(16))) vertices[vertCount];
VECTOR __attribute__((aligned(16))) normals[vertCount];
VECTOR __attribute__((aligned(16))) coordinates[vertCount];
changeTexture(t_mesh, t_mesh.getMaterial(i).getId());
vertCount = t_mesh.getDrawData(i, vertices, normals, coordinates, rotatedCamera);
vifSender->drawMesh(&renderData, perspective, vertCount, vertices, normals, coordinates, t_mesh, t_bulbs, t_bulbsCount, &textureBuffer);
delete[] vertices;
delete[] normals;
delete[] coordinates;
}
}
+1 -1
View File
@@ -43,7 +43,7 @@ void VifSender::sendMatrices(const RenderData &t_renderData, const Vector3 &t_po
vec3ToNative(rotation, t_rotation, 1.0F);
create_local_world(localWorld, position, rotation);
create_local_screen(localScreen, localWorld, t_renderData.worldView->data, t_renderData.perspective->data);
vu1.sendSingleRefList(0, &localScreen, 4);
vu1.sendSingleRefList(0, &localScreen, 8);
}
void VifSender::drawMesh(RenderData *t_renderData, Matrix t_perspective, u32 vertCount2, VECTOR *vertices, VECTOR *normals, VECTOR *coordinates, const Mesh &t_mesh, LightBulb *t_bulbs, u16 t_bulbsCount, texbuffer_t *textureBuffer)
+5 -4
View File
@@ -127,7 +127,7 @@ void VU1::addReferenceList(u32 t_offset, void *t_data, u32 t_size, u8 t_useTops)
*((u64 *)currentBuffer)++ = DMA_REF_TAG((u32)t_data, t_size);
*((u32 *)currentBuffer)++ = VIF_CODE(VIF_STCYL, 0, 0x0101);
*((u32 *)currentBuffer)++ =
AddUnpack(V4_32, t_useTops == 1 ? buildList.dmaSize / 16 : t_offset / 16, t_size, t_useTops);
AddUnpack(V4_32, t_useTops == 1 ? buildList.dmaSize >> 4 : t_offset >> 4, t_size, t_useTops);
buildList.dmaSize += t_size * 8;
buildList.dmaSizeAll += buildList.dmaSize;
}
@@ -135,7 +135,7 @@ void VU1::addReferenceList(u32 t_offset, void *t_data, u32 t_size, u8 t_useTops)
/** Start VU1 program */
void VU1::addStartProgram()
{
*((u64 *)currentBuffer)++ = DMA_CNT_TAG(8 >> 4);
*((u64 *)currentBuffer)++ = DMA_CNT_TAG(0);
*((u32 *)currentBuffer)++ = VIF_CODE(VIF_MSCAL, 0, 0);
*((u32 *)currentBuffer)++ = VIF_CODE(VIF_FLUSH, 0, 0);
;
@@ -144,7 +144,7 @@ void VU1::addStartProgram()
/** Continue VU1 program from "--cont" line */
void VU1::addContinueProgram()
{
*((u64 *)currentBuffer)++ = DMA_CNT_TAG(8 >> 4);
*((u64 *)currentBuffer)++ = DMA_CNT_TAG(0);
*((u32 *)currentBuffer)++ = VIF_CODE(VIF_MSCAL, 0, 0);
*((u32 *)currentBuffer)++ = VIF_CODE(VIF_FLUSH, 0, 0);
;
@@ -156,8 +156,9 @@ void VU1::sendList()
*((u64 *)currentBuffer)++ = DMA_END_TAG(0);
*((u32 *)currentBuffer)++ = VIF_CODE(VIF_NOP, 0, 0);
*((u32 *)currentBuffer)++ = VIF_CODE(VIF_NOP, 0, 0);
dma_channel_wait(DMA_CHANNEL_VIF1, VU1_DMA_CHAN_TIMEOUT);
FlushCache(0);
dma_channel_send_chain(DMA_CHANNEL_VIF1, buildList.kickBuffer, (u32 *)currentBuffer - (u32 *)buildList.kickBuffer, DMA_FLAG_TRANSFERTAG, 0);
dma_channel_wait(DMA_CHANNEL_VIF1, VU1_DMA_CHAN_TIMEOUT);
}
void VU1::addDoubleBufferSetting()