refactored texturelink, loadFrom(), mesh color
This commit is contained in:
@@ -131,16 +131,16 @@ void GifSender::addClear(zbuffer_t *t_zBuffer, color_t *t_rgb)
|
||||
}
|
||||
|
||||
/** Adds meshes to current packet */
|
||||
void GifSender::addObject(RenderData *t_renderData, Mesh &t_mesh, u32 vertexCount, VECTOR *vertices, VECTOR *normals, VECTOR *coordinates, LightBulb *t_bulbs, u16 t_bulbsCount, texbuffer_t *textureBuffer)
|
||||
void GifSender::addObject(RenderData *t_renderData, Mesh &t_mesh, u32 vertexCount, VECTOR *vertices, VECTOR *normals, VECTOR *coordinates, LightBulb *t_bulbs, u16 t_bulbsCount, texbuffer_t *textureBuffer, color_t *t_color)
|
||||
{
|
||||
packet2_chain_open_cnt(currentPacket, 0, 0, 0);
|
||||
packet2_update(currentPacket, draw_texture_sampling(currentPacket->next, 0, &t_mesh.lod));
|
||||
packet2_update(currentPacket, draw_texturebuffer(currentPacket->next, 0, textureBuffer, &t_mesh.clut));
|
||||
packet2_update(currentPacket, draw_prim_start(currentPacket->next, 0, t_renderData->prim, &t_mesh.color));
|
||||
packet2_update(currentPacket, draw_prim_start(currentPacket->next, 0, t_renderData->prim, t_color));
|
||||
xyz = new xyz_t[vertexCount];
|
||||
rgbaq = new color_t[vertexCount];
|
||||
st = new texel_t[vertexCount];
|
||||
calc3DObject(*t_renderData->projection, t_mesh, vertexCount, vertices, normals, coordinates, t_renderData, t_bulbs, t_bulbsCount);
|
||||
calc3DObject(*t_renderData->projection, t_mesh, vertexCount, vertices, normals, coordinates, t_renderData, t_bulbs, t_bulbsCount, t_color);
|
||||
addCurrentCalcs(vertexCount);
|
||||
delete[] xyz;
|
||||
delete[] rgbaq;
|
||||
@@ -152,7 +152,7 @@ void GifSender::addObject(RenderData *t_renderData, Mesh &t_mesh, u32 vertexCoun
|
||||
/** Calculates 3D object data into xyz, rgbq, st
|
||||
* After it addCurrentCalcs() can be done
|
||||
*/
|
||||
void GifSender::calc3DObject(Matrix t_perspective, Mesh &t_mesh, u32 vertexCount, VECTOR *vertices, VECTOR *normals, VECTOR *coordinates, RenderData *t_renderData, LightBulb *t_bulbs, u16 t_bulbsCount)
|
||||
void GifSender::calc3DObject(Matrix t_perspective, Mesh &t_mesh, u32 vertexCount, VECTOR *vertices, VECTOR *normals, VECTOR *coordinates, RenderData *t_renderData, LightBulb *t_bulbs, u16 t_bulbsCount, color_t *t_color)
|
||||
{
|
||||
VECTOR *colors = new VECTOR[vertexCount];
|
||||
VECTOR position, rotation;
|
||||
@@ -187,9 +187,9 @@ void GifSender::calc3DObject(Matrix t_perspective, Mesh &t_mesh, u32 vertexCount
|
||||
for (u32 i = 0; i < vertexCount; i++)
|
||||
{
|
||||
// Apply the light value to the colour.
|
||||
colors[i][0] = (t_mesh.color.r * lights[i][0]);
|
||||
colors[i][1] = (t_mesh.color.g * lights[i][1]);
|
||||
colors[i][2] = (t_mesh.color.b * lights[i][2]);
|
||||
colors[i][0] = (t_color->r * lights[i][0]);
|
||||
colors[i][1] = (t_color->g * lights[i][1]);
|
||||
colors[i][2] = (t_color->b * lights[i][2]);
|
||||
vector_clamp(colors[i], colors[i], 0.00F, 1.99F);
|
||||
}
|
||||
|
||||
@@ -201,14 +201,14 @@ void GifSender::calc3DObject(Matrix t_perspective, Mesh &t_mesh, u32 vertexCount
|
||||
else
|
||||
for (u32 i = 0; i < vertexCount; i++)
|
||||
{
|
||||
colors[i][0] = t_mesh.color.r / 128.0F;
|
||||
colors[i][1] = t_mesh.color.g / 128.0F;
|
||||
colors[i][2] = t_mesh.color.b / 128.0F;
|
||||
colors[i][0] = t_color->r / 128.0F;
|
||||
colors[i][1] = t_color->g / 128.0F;
|
||||
colors[i][2] = t_color->b / 128.0F;
|
||||
}
|
||||
|
||||
calculate_vertices(vertices, vertexCount, vertices, localScreen);
|
||||
|
||||
convertCalcs(vertexCount, vertices, colors, coordinates, t_mesh.color);
|
||||
convertCalcs(vertexCount, vertices, colors, coordinates, *t_color);
|
||||
|
||||
delete[] colors;
|
||||
}
|
||||
|
||||
@@ -105,7 +105,7 @@ void Renderer::changeTexture(Texture *t_tex)
|
||||
|
||||
void Renderer::draw(Sprite &t_sprite)
|
||||
{
|
||||
Texture *texture = textureRepo.getBySprite(t_sprite.getId());
|
||||
Texture *texture = textureRepo.getBySpriteOrMesh(t_sprite.getId());
|
||||
texrect_t rect;
|
||||
float sizeX, sizeY;
|
||||
if (t_sprite.getMode() == MODE_REPEAT)
|
||||
@@ -242,17 +242,18 @@ void Renderer::drawByPath3(Mesh &t_mesh, LightBulb *t_bulbs, u16 t_bulbsCount)
|
||||
t_mesh.animate();
|
||||
for (u32 i = 0; i < t_mesh.getMaterialsCount(); i++)
|
||||
{
|
||||
if (t_mesh.shouldBeFrustumCulled && !t_mesh.getMaterial(i).isInFrustum(renderData.frustumPlanes, t_mesh.position))
|
||||
MeshMaterial *material = &t_mesh.getMaterial(i);
|
||||
if (t_mesh.shouldBeFrustumCulled && !material->isInFrustum(renderData.frustumPlanes, t_mesh.position))
|
||||
return;
|
||||
Texture *tex = textureRepo.getByMesh(t_mesh.getId(), t_mesh.getMaterial(i).getId());
|
||||
Texture *tex = textureRepo.getBySpriteOrMesh(material->getId());
|
||||
changeTexture(tex);
|
||||
gifSender->initPacket(context);
|
||||
u32 vertCount = t_mesh.getMaterial(i).getFacesCount();
|
||||
u32 vertCount = material->getFacesCount();
|
||||
VECTOR *vertices = new VECTOR[vertCount];
|
||||
VECTOR *normals = new VECTOR[vertCount];
|
||||
VECTOR *coordinates = new VECTOR[vertCount];
|
||||
vertCount = t_mesh.getDrawData(i, vertices, normals, coordinates, *renderData.cameraPosition);
|
||||
gifSender->addObject(&renderData, t_mesh, vertCount, vertices, normals, coordinates, t_bulbs, t_bulbsCount, &textureBuffer);
|
||||
gifSender->addObject(&renderData, t_mesh, vertCount, vertices, normals, coordinates, t_bulbs, t_bulbsCount, &textureBuffer, &material->color);
|
||||
gifSender->sendPacket();
|
||||
delete[] vertices;
|
||||
delete[] normals;
|
||||
@@ -315,16 +316,17 @@ void Renderer::draw(Mesh &t_mesh, LightBulb *t_bulbs, u16 t_bulbsCount)
|
||||
t_mesh.animate();
|
||||
for (u32 i = 0; i < t_mesh.getMaterialsCount(); i++)
|
||||
{
|
||||
if (t_mesh.shouldBeFrustumCulled && !t_mesh.getMaterial(i).isInFrustum(renderData.frustumPlanes, t_mesh.position))
|
||||
MeshMaterial *material = &t_mesh.getMaterial(i);
|
||||
if (t_mesh.shouldBeFrustumCulled && !material->isInFrustum(renderData.frustumPlanes, t_mesh.position))
|
||||
return;
|
||||
u32 vertCount = t_mesh.getMaterial(i).getFacesCount();
|
||||
u32 vertCount = material->getFacesCount();
|
||||
VECTOR vertices[vertCount] __attribute__((aligned(16)));
|
||||
VECTOR normals[vertCount] __attribute__((aligned(16)));
|
||||
VECTOR coordinates[vertCount] __attribute__((aligned(16)));
|
||||
Texture *tex = textureRepo.getByMesh(t_mesh.getId(), t_mesh.getMaterial(i).getId());
|
||||
Texture *tex = textureRepo.getBySpriteOrMesh(material->getId());
|
||||
changeTexture(tex);
|
||||
vertCount = t_mesh.getDrawData(i, vertices, normals, coordinates, rotatedCamera);
|
||||
vifSender->drawMesh(&renderData, perspective, vertCount, vertices, normals, coordinates, t_mesh, t_bulbs, t_bulbsCount, &textureBuffer);
|
||||
vifSender->drawMesh(&renderData, perspective, vertCount, vertices, normals, coordinates, t_mesh, t_bulbs, t_bulbsCount, &textureBuffer, &material->color);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -57,7 +57,7 @@ void TextureRepository::addByMesh(char *t_path, Mesh &mesh, TextureFormat t_form
|
||||
else
|
||||
pngLoader.load(*texture, t_path, mesh.getMaterial(i).getName(), ".png");
|
||||
texture->setName(mesh.getMaterial(i).getName());
|
||||
texture->addLink(mesh.getId(), mesh.getMaterial(i).getId());
|
||||
texture->addLink(mesh.getMaterial(i).getId());
|
||||
textures.push_back(texture);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@ void VifSender::calcMatrix(const RenderData &t_renderData, const Vector3 &t_posi
|
||||
modelViewProj = *t_renderData.projection * modelViewProj;
|
||||
}
|
||||
|
||||
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)
|
||||
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, color_t *t_color)
|
||||
{
|
||||
// we have to split 3D object into small parts, because of small memory of VU1
|
||||
|
||||
@@ -97,7 +97,7 @@ void VifSender::drawMesh(RenderData *t_renderData, Matrix t_perspective, u32 ver
|
||||
i -= 3;
|
||||
|
||||
const u32 endI = i + (VU1_PACKAGE_VERTS_PER_BUFF - 1) > vertCount2 ? vertCount2 : i + (VU1_PACKAGE_VERTS_PER_BUFF - 1);
|
||||
drawVertices(t_mesh, i, endI, vertices, coordinates, t_renderData->prim, textureBuffer, isDrawWaitEnabled ? endI == vertCount2 : false);
|
||||
drawVertices(t_mesh, i, endI, vertices, coordinates, t_renderData->prim, textureBuffer, isDrawWaitEnabled ? endI == vertCount2 : false, t_color);
|
||||
if (endI == vertCount2) // if there are no more vertices to draw, break
|
||||
{
|
||||
i = vertCount2;
|
||||
@@ -130,7 +130,7 @@ void VifSender::setDoubleBufferAddStaticData()
|
||||
}
|
||||
|
||||
/** Draw using PATH1 */
|
||||
void VifSender::drawVertices(Mesh &t_mesh, u32 t_start, u32 t_end, VECTOR *t_vertices, VECTOR *t_coordinates, prim_t *t_prim, texbuffer_t *t_texBuff, u8 t_addDrawWait)
|
||||
void VifSender::drawVertices(Mesh &t_mesh, u32 t_start, u32 t_end, VECTOR *t_vertices, VECTOR *t_coordinates, prim_t *t_prim, texbuffer_t *t_texBuff, u8 t_addDrawWait, color_t *t_color)
|
||||
{
|
||||
const u32 vertCount = t_end - t_start;
|
||||
lastVertCount = vertCount;
|
||||
@@ -143,10 +143,10 @@ void VifSender::drawVertices(Mesh &t_mesh, u32 t_start, u32 t_end, VECTOR *t_ver
|
||||
packet2_utils_gs_add_lod(currPacket, &t_mesh.lod);
|
||||
packet2_utils_gs_add_texbuff_clut(currPacket, t_texBuff, &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);
|
||||
packet2_add_u32(currPacket, t_color->r);
|
||||
packet2_add_u32(currPacket, t_color->g);
|
||||
packet2_add_u32(currPacket, t_color->b);
|
||||
packet2_add_u32(currPacket, t_color->a);
|
||||
u32 vif_added_bytes = packet2_utils_vu_close_unpack(currPacket);
|
||||
packet2_utils_vu_add_unpack_data(currPacket, vif_added_bytes, t_vertices + t_start, vertCount, true);
|
||||
vif_added_bytes += vertCount;
|
||||
@@ -183,10 +183,10 @@ void VifSender::drawTheSameWithOtherMatrices(const RenderData &t_renderData, Mes
|
||||
packet2_utils_vu_close_unpack(currMPacket);
|
||||
packet2_utils_vu_open_unpack(currMPacket, VU1_RGBA_ADDRESS, true);
|
||||
{
|
||||
packet2_add_u32(currMPacket, t_meshes[i]->color.r);
|
||||
packet2_add_u32(currMPacket, t_meshes[i]->color.g);
|
||||
packet2_add_u32(currMPacket, t_meshes[i]->color.b);
|
||||
packet2_add_u32(currMPacket, t_meshes[i]->color.a);
|
||||
packet2_add_u32(currMPacket, t_meshes[i]->getMaterial(0).color.r);
|
||||
packet2_add_u32(currMPacket, t_meshes[i]->getMaterial(0).color.g);
|
||||
packet2_add_u32(currMPacket, t_meshes[i]->getMaterial(0).color.b);
|
||||
packet2_add_u32(currMPacket, t_meshes[i]->getMaterial(0).color.a);
|
||||
}
|
||||
packet2_utils_vu_close_unpack(currMPacket);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user