implemented alpha texture repository
This commit is contained in:
@@ -81,15 +81,21 @@ void Renderer::deallocateTextureBuffer()
|
||||
}
|
||||
}
|
||||
|
||||
void Renderer::changeTexture(Mesh *t_mesh, u8 t_textureIndex)
|
||||
void Renderer::changeTexture(Mesh *t_mesh, u32 t_materialId)
|
||||
{
|
||||
if (t_mesh->textures[t_textureIndex].getId() != lastTextureId)
|
||||
MeshTexture *tex = textureRepo.getByMesh(t_mesh->id, t_materialId);
|
||||
if (tex != NULL)
|
||||
{
|
||||
lastTextureId = t_mesh->textures[t_textureIndex].getId();
|
||||
deallocateTextureBuffer();
|
||||
allocateTextureBuffer(t_mesh->textures[t_textureIndex].getWidth(), t_mesh->textures[t_textureIndex].getHeight());
|
||||
GifSender::sendTexture(t_mesh->textures[t_textureIndex], &textureBuffer);
|
||||
if (tex->getId() != lastTextureId)
|
||||
{
|
||||
lastTextureId = tex->getId();
|
||||
deallocateTextureBuffer();
|
||||
allocateTextureBuffer(tex->getWidth(), tex->getHeight());
|
||||
GifSender::sendTexture(*tex, &textureBuffer);
|
||||
}
|
||||
}
|
||||
else
|
||||
PRINT_ERR("Texture was not found in texture repository!");
|
||||
}
|
||||
|
||||
/** Initializes drawing environment (1st app packet) */
|
||||
@@ -208,9 +214,9 @@ void Renderer::draw(Mesh *t_mesh, LightBulb *t_bulbs, u16 t_bulbsCount)
|
||||
if (t_mesh->isObjLoaded)
|
||||
{
|
||||
t_mesh->obj->animate();
|
||||
for (u32 i = 0; i < t_mesh->obj->frames[0].getMaterialsCount(); i++)
|
||||
for (u32 i = 0; i < t_mesh->getMaterialsCount(); i++)
|
||||
{
|
||||
changeTexture(t_mesh, i);
|
||||
changeTexture(t_mesh, t_mesh->getMaterial(i).getId());
|
||||
vertCount = t_mesh->getDrawData(i, vertices, normals, coordinates, *renderData.cameraPosition);
|
||||
vifSender->drawMesh(&renderData, perspective, vertCount, vertices, normals, coordinates, t_mesh, t_bulbs, t_bulbsCount, &textureBuffer);
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
TextureRepository::TextureRepository()
|
||||
{
|
||||
PRINT_LOG("Initializing texture repository");
|
||||
|
||||
texturesCount = 0;
|
||||
PRINT_LOG("Texture repository initialized!");
|
||||
}
|
||||
|
||||
@@ -27,3 +27,59 @@ TextureRepository::~TextureRepository() {}
|
||||
// ----
|
||||
// Methods
|
||||
// ----
|
||||
|
||||
MeshTexture *TextureRepository::add(char *t_subfolder, char *t_name)
|
||||
{
|
||||
increaseArray(texturesCount + 1);
|
||||
// texturesCount is updated
|
||||
loader.load(*textures[texturesCount - 1], t_subfolder, t_name, ".bmp");
|
||||
return textures[texturesCount - 1];
|
||||
}
|
||||
|
||||
void TextureRepository::addByMesh(char *t_path, Mesh &mesh)
|
||||
{
|
||||
#define MATERIAL mesh.getMaterial(i)
|
||||
u32 newLength = texturesCount + mesh.getMaterialsCount();
|
||||
increaseArray(newLength);
|
||||
for (u8 i = newLength - mesh.getMaterialsCount(); i < newLength; i++)
|
||||
{
|
||||
textures[i] = new MeshTexture();
|
||||
loader.load(*textures[i], t_path, MATERIAL.getName(), ".bmp");
|
||||
textures[i]->setName(mesh.getMaterial(i).getName());
|
||||
textures[i]->addLink(mesh.id, MATERIAL.getId());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove texture from repository.
|
||||
* Texture is not destructed.
|
||||
*/
|
||||
void TextureRepository::remove(u32 t_textureId)
|
||||
{
|
||||
MeshTexture **savedTextures = textures;
|
||||
textures = new MeshTexture *[texturesCount - 1];
|
||||
u32 savedCount = 0;
|
||||
for (u32 i = 0; i < texturesCount; i++)
|
||||
if (savedTextures[i]->getId() != t_textureId)
|
||||
textures[savedCount++] = savedTextures[i];
|
||||
delete[] savedTextures;
|
||||
texturesCount--;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resize textures array.
|
||||
* texturesCount variable is updated.
|
||||
* Classes are NOT instantiated.
|
||||
*/
|
||||
void TextureRepository::increaseArray(u32 newLength)
|
||||
{
|
||||
MeshTexture **savedTextures = textures;
|
||||
textures = new MeshTexture *[newLength];
|
||||
if (texturesCount)
|
||||
{
|
||||
for (u32 i = 0; i < texturesCount; i++)
|
||||
textures[i] = savedTextures[i];
|
||||
delete[] savedTextures;
|
||||
}
|
||||
texturesCount = newLength;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user