Oh, Sorry It was late at night >.< (Around 4 in the morning XD) Let me try it again.
What am trying to do is to avoid loading more than one of each texture file, so I made a std::map wtih the texture name as the key and the value would be a ID3D11ShaderResourceView* that contain the texture.
Each time I "Load" a model with materials it would check if the material would already exist inside the map, to avoid loading multipile time of the same texture.
if the texture already had been loaded i would get it by calling RequestTexture which looks like this
ID3D11ShaderResourceView* GfxHandler::RequestTexture(std::string textureName)
{
if(TotalTexture.find(textureName) != TotalTexture.end())
{
MessageBox(0,"Request Granted",textureName.c_str(),MB_OK);
TotalTextureCounter[textureName]++;
return TotalTexture[textureName];
}
else
{
MessageBox(0,"Request Failed",textureName.c_str(),MB_OK);
}
return false;
}
Where the TotalTexture and TotalTexture looks like
std::map<std::string,ID3D11ShaderResourceView*> TotalTexture;
std::map<std::string,int> TotalTextureCounter;
The ReqeustTexture returns a shader resource which I assign and insert into a seperate class which I would call the "Model", the model class have its own map which looks like the same except the only texture that gets inserted there would be the materials that the model use, the reason why I try to do this is to avoid unnecessary looping inside the bigger map.
This is how I do it inside my LoadModel
Its works great, my Testing does indeed get the same adress as the loaded texture from the map
ID3D11ShaderResourceView* Testing = 0;
Gfx->LoadTextureOld(Model->Texture.Diffuse.Location,Model->Texture.Diffuse.TextureOld,Model->Texture.Diffuse.Sampler);
for(int i = 0; i < Model->Materials.size();i++)
{
Model->Materials[i].materialName += ".jpg";
if(Gfx->TotalTexture.find(Model->Materials[i].materialName) == Gfx->TotalTexture.end())
{
Gfx->LoadTexture(Model->Materials[i].materialName,Testing);
Model->Texture.Diffuse.Texture.insert(Model->Texture.Diffuse.Texture.end(),std::pair<std::string,ID3D11ShaderResourceView*>(Model->Materials[i].materialName,Model->Texture.Diffuse.TextureOld));
Gfx->RequestInsertionOfTexture(Model->Materials[i].materialName,Testing);
// Gfx->TotalTexture.insert(Gfx->TotalTexture.end(),std::pair<std::string,ID3D11ShaderResourceView*>(Model->Materials[i].materialName,Testing));
}
else
{
Testing = Gfx->RequestTexture(Model->Materials[i].materialName);
Model->Texture.Diffuse.Texture.insert(Model->Texture.Diffuse.Texture.end(),std::pair<std::string,ID3D11ShaderResourceView*>(Model->Materials[i].materialName,Model->Texture.Diffuse.TextureOld));
//Gfx->RequestInsertionOfTexture(Model->Materials[i].materialName,Testing);
// Gfx->TotalTexture.insert(Gfx->TotalTexture.end(),std::pair<std::string,ID3D11ShaderResourceView*>(Model->Materials[i].materialName,Testing));
}
}
Now when Am trying to render my object, I try to change material depending on what group it is.
So I did something like this
for(int i = 0; i < Model->Total.Group; i++)
{
if(Model->lastMaterial != Model->groupMaterial[i])
{
//First method
Model->lastMaterial = Model->groupMaterial[i];
Gfx->D3d11DevCon->PSSetShaderResources(0,1,& Model->Texture.Diffuse.Texture[Model->lastMaterial]);//<---- //Texture
// */
//Second method Model->lastMaterial = Model->groupMaterial; pt = Model->Texture.Diffuse.Texture[Model->lastMaterial]; Gfx->D3d11DevCon->PSSetShaderResources(0,1,&pt);//<---- Texture
//*/
} Gfx->D3d11DevCon->DrawIndexed ( Model->DrawingIndexIndices.IndexCount, Model->DrawingIndexIndices.StartIndex, 0 ); }
In which case instead of getting the texture it somehow decided to insert the texture
like this