Merge pull request #175 from GuidoDQR/texture-generation-id
Texture generation id
This commit is contained in:
@@ -16,6 +16,7 @@
|
|||||||
#include "./models/texture.hpp"
|
#include "./models/texture.hpp"
|
||||||
#include "renderer/3d/mesh/mesh.hpp"
|
#include "renderer/3d/mesh/mesh.hpp"
|
||||||
#include "renderer/core/2d/sprite/sprite.hpp"
|
#include "renderer/core/2d/sprite/sprite.hpp"
|
||||||
|
#include "./renderer_core_texture_buffers.hpp"
|
||||||
#include "loaders/texture/base/texture_loader_selector.hpp"
|
#include "loaders/texture/base/texture_loader_selector.hpp"
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
@@ -25,6 +26,8 @@ class TextureRepository {
|
|||||||
TextureRepository();
|
TextureRepository();
|
||||||
~TextureRepository();
|
~TextureRepository();
|
||||||
|
|
||||||
|
void init(std::vector<RendererCoreTextureBuffers>* textureBuffers);
|
||||||
|
|
||||||
/** Returns all repository textures. */
|
/** Returns all repository textures. */
|
||||||
std::vector<Texture*>* getAll() { return &textures; }
|
std::vector<Texture*>* getAll() { return &textures; }
|
||||||
|
|
||||||
@@ -99,6 +102,13 @@ class TextureRepository {
|
|||||||
void freeByMesh(const Mesh& mesh);
|
void freeByMesh(const Mesh& mesh);
|
||||||
void freeByMesh(const Mesh* mesh);
|
void freeByMesh(const Mesh* mesh);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* remove texture buffer id if exist.
|
||||||
|
* Texture buffer is NOT destructed.
|
||||||
|
* easy way to create another texture buffer.
|
||||||
|
*/
|
||||||
|
int removeBufferId(const u32& t_texId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove texture from repository.
|
* Remove texture from repository.
|
||||||
* Texture is NOT destructed.
|
* Texture is NOT destructed.
|
||||||
@@ -110,6 +120,7 @@ class TextureRepository {
|
|||||||
void removeByIndex(const u32& t_index);
|
void removeByIndex(const u32& t_index);
|
||||||
|
|
||||||
std::vector<Texture*> textures;
|
std::vector<Texture*> textures;
|
||||||
|
std::vector<RendererCoreTextureBuffers>* textureBuffers;
|
||||||
TextureLoaderSelector texLoaderSelector;
|
TextureLoaderSelector texLoaderSelector;
|
||||||
};
|
};
|
||||||
} // namespace Tyra
|
} // namespace Tyra
|
||||||
|
|||||||
@@ -19,8 +19,18 @@
|
|||||||
|
|
||||||
namespace Tyra {
|
namespace Tyra {
|
||||||
|
|
||||||
|
namespace TyraTexture {
|
||||||
|
u32 textureCounter = 1;
|
||||||
|
std::vector<u32> deletedIDs;
|
||||||
|
} // namespace TyraTexture
|
||||||
|
|
||||||
Texture::Texture(TextureBuilderData* t_data) {
|
Texture::Texture(TextureBuilderData* t_data) {
|
||||||
id = rand() % 1000000;
|
if (TyraTexture::deletedIDs.empty() == false) {
|
||||||
|
id = TyraTexture::deletedIDs.front();
|
||||||
|
TyraTexture::deletedIDs.erase(TyraTexture::deletedIDs.begin());
|
||||||
|
} else {
|
||||||
|
id = TyraTexture::textureCounter++;
|
||||||
|
}
|
||||||
|
|
||||||
name = t_data->name;
|
name = t_data->name;
|
||||||
|
|
||||||
@@ -50,6 +60,7 @@ Texture::Texture(TextureBuilderData* t_data) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Texture::~Texture() {
|
Texture::~Texture() {
|
||||||
|
TyraTexture::deletedIDs.push_back(id);
|
||||||
if (links.size() > 0) links.clear();
|
if (links.size() > 0) links.clear();
|
||||||
if (core) delete core;
|
if (core) delete core;
|
||||||
if (clut) delete clut;
|
if (clut) delete clut;
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ RendererCoreTexture::~RendererCoreTexture() {}
|
|||||||
void RendererCoreTexture::init(RendererCoreGS* t_gs, Path3* t_path3) {
|
void RendererCoreTexture::init(RendererCoreGS* t_gs, Path3* t_path3) {
|
||||||
gs = t_gs;
|
gs = t_gs;
|
||||||
sender.init(t_path3, t_gs);
|
sender.init(t_path3, t_gs);
|
||||||
|
repository.init(¤tAllocations);
|
||||||
path3 = t_path3;
|
path3 = t_path3;
|
||||||
initClut();
|
initClut();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,11 @@ TextureRepository::~TextureRepository() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TextureRepository::init(
|
||||||
|
std::vector<RendererCoreTextureBuffers>* t_textureBuffers) {
|
||||||
|
textureBuffers = t_textureBuffers;
|
||||||
|
}
|
||||||
|
|
||||||
Texture* TextureRepository::getBySpriteId(const u32& t_id) const {
|
Texture* TextureRepository::getBySpriteId(const u32& t_id) const {
|
||||||
for (u32 i = 0; i < textures.size(); i++) {
|
for (u32 i = 0; i < textures.size(); i++) {
|
||||||
if (textures[i]->isLinkedWith(t_id)) return textures[i];
|
if (textures[i]->isLinkedWith(t_id)) return textures[i];
|
||||||
@@ -57,10 +62,20 @@ void TextureRepository::removeByIndex(const u32& t_index) {
|
|||||||
textures.erase(textures.begin() + t_index);
|
textures.erase(textures.begin() + t_index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int TextureRepository::removeBufferId(const u32& t_texId) {
|
||||||
|
for (u32 i = 0; i < textureBuffers->size(); i++)
|
||||||
|
if ((*textureBuffers)[i].id == t_texId) {
|
||||||
|
(*textureBuffers)[i].id = -1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
void TextureRepository::removeById(const u32& t_texId) {
|
void TextureRepository::removeById(const u32& t_texId) {
|
||||||
s32 index = getIndexOf(t_texId);
|
s32 index = getIndexOf(t_texId);
|
||||||
TYRA_ASSERT(index != -1, "Cant remove texture, because it was not found!");
|
TYRA_ASSERT(index != -1, "Cant remove texture, because it was not found!");
|
||||||
removeByIndex(index);
|
removeByIndex(index);
|
||||||
|
removeBufferId(t_texId);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextureRepository::freeByMesh(const Mesh& mesh) {
|
void TextureRepository::freeByMesh(const Mesh& mesh) {
|
||||||
@@ -93,6 +108,7 @@ void TextureRepository::free(const u32& t_texId) {
|
|||||||
|
|
||||||
TYRA_ASSERT(index != -1, "Cant remove texture, because it was not found!");
|
TYRA_ASSERT(index != -1, "Cant remove texture, because it was not found!");
|
||||||
removeByIndex(index);
|
removeByIndex(index);
|
||||||
|
removeBufferId(t_texId);
|
||||||
|
|
||||||
delete tex;
|
delete tex;
|
||||||
}
|
}
|
||||||
@@ -116,7 +132,7 @@ void TextureRepository::addByMesh(const Mesh* mesh, const char* directory,
|
|||||||
if (dirFixed.back() != '/' && dirFixed.back() != ':') dirFixed += "/";
|
if (dirFixed.back() != '/' && dirFixed.back() != ':') dirFixed += "/";
|
||||||
|
|
||||||
for (u32 i = 0; i < mesh->materials.size(); i++) {
|
for (u32 i = 0; i < mesh->materials.size(); i++) {
|
||||||
if (!mesh->materials[i]->textureName.has_value()) {
|
if (!mesh->materials[i]->textureName.has_value()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user