don't copy the model list. It can be very big - using pointer now,
garbage is not from the texture or object changes
This commit is contained in:
parent
e1e8e165fe
commit
5c5b9ac2f1
|
@ -45,7 +45,7 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
std::vector<Modl*> vModls;
|
std::vector<Modl*>* vModls;
|
||||||
std::fstream fsMesh;
|
std::fstream fsMesh;
|
||||||
std::vector<std::string> vTextures;
|
std::vector<std::string> vTextures;
|
||||||
|
|
||||||
|
@ -63,7 +63,7 @@ private:
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
std::vector<Modl*> getModels() const;
|
std::vector<Modl*>* getModels() const;
|
||||||
std::vector<std::string> getTextureList() const;
|
std::vector<std::string> getTextureList() const;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -70,7 +70,7 @@ private:
|
||||||
// ========================================
|
// ========================================
|
||||||
|
|
||||||
// data
|
// data
|
||||||
std::vector<Modl*> vModels;
|
std::vector<Modl*>* vModels = NULL;
|
||||||
std::vector<textureData*> vTextures;
|
std::vector<textureData*> vTextures;
|
||||||
|
|
||||||
// transformation =========================
|
// transformation =========================
|
||||||
|
|
|
@ -10,6 +10,8 @@
|
||||||
|
|
||||||
Object::Object(const char* path)
|
Object::Object(const char* path)
|
||||||
{
|
{
|
||||||
|
vModls = new std::vector<Modl*>;
|
||||||
|
|
||||||
// open file
|
// open file
|
||||||
fsMesh.open(path, std::ios::in | std::ios::binary);
|
fsMesh.open(path, std::ios::in | std::ios::binary);
|
||||||
|
|
||||||
|
@ -65,9 +67,6 @@ Object::~Object()
|
||||||
{
|
{
|
||||||
// clear texture list
|
// clear texture list
|
||||||
vTextures.clear();
|
vTextures.clear();
|
||||||
|
|
||||||
// clear Model list (don't delete the elements)
|
|
||||||
vModls.clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -177,7 +176,7 @@ void Object::analyseMsh2Chunks(std::list<ChunkHeader*>& chunkList)
|
||||||
}
|
}
|
||||||
|
|
||||||
// save Model data
|
// save Model data
|
||||||
vModls.push_back(tempModl);
|
vModls->push_back(tempModl);
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -593,7 +592,7 @@ void Object::readUV(Segment* dataDestination, std::streampos position)
|
||||||
/////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////
|
||||||
// public getter
|
// public getter
|
||||||
|
|
||||||
std::vector<Modl*> Object::getModels() const
|
std::vector<Modl*>* Object::getModels() const
|
||||||
{
|
{
|
||||||
return vModls;
|
return vModls;
|
||||||
}
|
}
|
||||||
|
|
|
@ -109,10 +109,12 @@ void OpenGLController::processInit()
|
||||||
|
|
||||||
void OpenGLController::deleteVectors()
|
void OpenGLController::deleteVectors()
|
||||||
{
|
{
|
||||||
while (!vModels.empty())
|
if (vModels != NULL)
|
||||||
{
|
{
|
||||||
Modl* cursor = vModels.back();
|
while (!vModels->empty())
|
||||||
vModels.pop_back();
|
{
|
||||||
|
Modl* cursor = vModels->back();
|
||||||
|
vModels->pop_back();
|
||||||
|
|
||||||
while (!cursor->segmLst.empty())
|
while (!cursor->segmLst.empty())
|
||||||
{
|
{
|
||||||
|
@ -135,11 +137,14 @@ void OpenGLController::deleteVectors()
|
||||||
|
|
||||||
delete cursor;
|
delete cursor;
|
||||||
}
|
}
|
||||||
|
delete vModels;
|
||||||
|
}
|
||||||
|
|
||||||
while (!vTextures.empty())
|
while (!vTextures.empty())
|
||||||
{
|
{
|
||||||
textureData* cursor = vTextures.back();
|
textureData* cursor = vTextures.back();
|
||||||
vTextures.pop_back();
|
vTextures.pop_back();
|
||||||
|
cursor->data->clear();
|
||||||
delete cursor->data;
|
delete cursor->data;
|
||||||
delete cursor;
|
delete cursor;
|
||||||
}
|
}
|
||||||
|
@ -207,16 +212,16 @@ glm::mat4 OpenGLController::getModelMatrix(unsigned int index)
|
||||||
{
|
{
|
||||||
glm::mat4 tempParentMatrix = glm::mat4(1.0f);
|
glm::mat4 tempParentMatrix = glm::mat4(1.0f);
|
||||||
|
|
||||||
for (unsigned int loop = 0; loop < vModels.size(); loop++)
|
for (unsigned int loop = 0; loop < vModels->size(); loop++)
|
||||||
{
|
{
|
||||||
if (!strcmp(vModels[index]->parent.c_str(), vModels[loop]->name.c_str()))
|
if (!strcmp(vModels->at(index)->parent.c_str(), vModels->at(loop)->name.c_str()))
|
||||||
{
|
{
|
||||||
tempParentMatrix = getModelMatrix(loop);
|
tempParentMatrix = getModelMatrix(loop);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return tempParentMatrix * vModels[index]->m4x4Translation;
|
return tempParentMatrix * vModels->at(index)->m4x4Translation;
|
||||||
}
|
}
|
||||||
|
|
||||||
glm::mat4 OpenGLController::getMVPMatrix(unsigned int index)
|
glm::mat4 OpenGLController::getMVPMatrix(unsigned int index)
|
||||||
|
@ -311,16 +316,16 @@ void OpenGLController::updateScene()
|
||||||
|
|
||||||
int instanceOffset(0);
|
int instanceOffset(0);
|
||||||
|
|
||||||
for (unsigned int modelIndex = 0; modelIndex < vModels.size(); modelIndex++)
|
for (unsigned int modelIndex = 0; modelIndex < vModels->size(); modelIndex++)
|
||||||
{
|
{
|
||||||
// skip null, bones, shadowMesh, hidden things (don't increase textrue index!!)
|
// skip null, bones, shadowMesh, hidden things (don't increase textrue index!!)
|
||||||
if (vModels[modelIndex]->type == null ||
|
if (vModels->at(modelIndex)->type == null ||
|
||||||
vModels[modelIndex]->type == bone ||
|
vModels->at(modelIndex)->type == bone ||
|
||||||
vModels[modelIndex]->type == shadowMesh ||
|
vModels->at(modelIndex)->type == shadowMesh ||
|
||||||
vModels[modelIndex]->renderFlags == 1)
|
vModels->at(modelIndex)->renderFlags == 1)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
for (auto& segIt : vModels[modelIndex]->segmLst)
|
for (auto& segIt : vModels->at(modelIndex)->segmLst)
|
||||||
{
|
{
|
||||||
// give texture to the shader
|
// give texture to the shader
|
||||||
std::uint32_t tempTexIndex = segIt->textureIndex >= vTextures.size() ? vTextures.size() - 1 : segIt->textureIndex;
|
std::uint32_t tempTexIndex = segIt->textureIndex >= vTextures.size() ? vTextures.size() - 1 : segIt->textureIndex;
|
||||||
|
@ -382,7 +387,7 @@ void OpenGLController::loadMsh(const char * path)
|
||||||
// collect vertex data of all models
|
// collect vertex data of all models
|
||||||
std::vector<Vertex> tempBufferData;
|
std::vector<Vertex> tempBufferData;
|
||||||
|
|
||||||
for (auto& modIt : vModels) // for every model chunk
|
for (auto& modIt : *vModels) // for every model chunk
|
||||||
{
|
{
|
||||||
for (auto& segIt : modIt->segmLst) // for every cluster
|
for (auto& segIt : modIt->segmLst) // for every cluster
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue