I'm very new to directx and all I can do I learned from books and tutorials, there never was anything mentioned about wrappers
I simply create them with D3DX11CreateShaderResourceViewFromFile( d3d11Device, "tt1.jpg",NULL, NULL, &slopeTexture, NULL );
and set them later as in my code aboth.
EDIT: I think I have an idea where the low FPS could come from: The function which is called every frame to look where new chunks are needed, the terrain::update
Let me post it, I'm sure you will find tons of things to be fixed:
What it does is:
If the player is inside of the size of the terrain, look for each chunkposition around him if there already is one. And if not, create a new one and pass it the part of height and shadowmap. Then check if there are more chunks then I want to hold in memory and erase the first of them which are not visible.
Could it be that the checking is timeconsuming and therefor slowing everything down? (I'm just using one thread at the moment!)
void terrain::Update(float playerXin, float playerZin){
int playerChunkX = ((int)playerXin/(chunkSize-1))*(chunkSize-1);
int playerChunkZ = ((int)playerZin/(chunkSize-1))*(chunkSize-1);
// LOAD NEW // UNLOAD OLD CHUNKS!!
if(playerXin > startX && playerZin > startZ && playerXin < startX+terrainWidth && playerZin < startZ+terrainHeight){
for(int z =0;z<loadPerSide;z++){
for(int x=0;x<loadPerSide;x++){
int xIndex, zIndex;
xIndex = (x-((loadPerSide-1)/2))*(chunkSize-1);
zIndex = (z-((loadPerSide-1)/2))*(chunkSize-1);
chunkNum = chunkList.size();
bool isThereAChunk = false;
//ADD NEW CHUNKS
for(int i=0;i<chunkNum;i++){
if(playerXin+xIndex > chunkList[i]->startX && playerXin+xIndex < chunkList[i]->startX+chunkList[i]->width && playerZin+zIndex > chunkList[i]->startZ && playerZin+zIndex < chunkList[i]->startZ+chunkList[i]->height){
isThereAChunk = true;
continue;
}
}
// test if there is a chunk in this zone to load
if(isThereAChunk == false && playerXin+xIndex > 0 && playerZin+zIndex > 0 && playerXin+xIndex < startX+terrainWidth && playerZin+zIndex < startZ+terrainHeight-chunkSize){
//get heights from map
for(int z=0;z<chunkSize;z++){
for(int x=0;x<chunkSize;x++){
heightsToPass[z*chunkSize+x] = heightMap[(z*terrainWidth+x) + ((int)playerXin+xIndex)/(chunkSize-1)*(chunkSize-1) + ((int)playerZin+zIndex)/(chunkSize-1)*(chunkSize-1)*terrainWidth];
}
}
//get normals from map
for(int z=0;z<chunkSize;z++){
for(int x=0;x<chunkSize;x++){
normalsToPass[z*chunkSize+x] = normalMap[(z*terrainWidth+x) + ((int)playerXin+xIndex)/(chunkSize-1)*(chunkSize-1) + ((int)playerZin+zIndex)/(chunkSize-1)*terrainWidth*(chunkSize-1)];
}
}
int k;
k = 0;
//get shadows from map
for(int z=0;z<chunkSize;z++){
for(int x=0;x<chunkSize;x++){
lightsToPass[k] = lightMapImage[((z*terrainWidth+x) + ((int)playerXin+xIndex)/(chunkSize-1)*(chunkSize-1) + ((int)playerZin+zIndex)/(chunkSize-1)*terrainWidth*(chunkSize-1)) * 3];
lightsToPass[k+1] = lightMapImage[((z*terrainWidth+x) + ((int)playerXin+xIndex)/(chunkSize-1)*(chunkSize-1) + ((int)playerZin+zIndex)/(chunkSize-1)*terrainWidth*(chunkSize-1))*3+1];
lightsToPass[k+2] = lightMapImage[((z*terrainWidth+x) + ((int)playerXin+xIndex)/(chunkSize-1)*(chunkSize-1) + ((int)playerZin+zIndex)/(chunkSize-1)*terrainWidth*(chunkSize-1))*3+2];
k += 3;
}
}
int timebegin = timeGetTime();
chunkAddIndex++;
int toLoad = -1;
for(int i=0;i<chunkCache;i++){
if(bufferInUse[i] == false){
toLoad = i;
bufferInUse[i] = true;
break;
}
}
if(toLoad == -1){ // NOT FINISHED!!!!
printf("chunkCache buffers full!\n");
}
chunkList.push_back(new chunk());
chunkList[chunkNum]->preInit(d3d11Device, d3d11DevCon, chunkSize, chunkSize, playerChunkX+xIndex, playerChunkZ+zIndex, chunkAddIndex, vBuffers[toLoad], iBuffers[toLoad]);
chunkList[chunkNum]->Init(heightsToPass, indices, normalsToPass, lightsToPass, verticesToLock);
int timeend = timeGetTime();
//printf("init chunk took %d ms\n", timeend-timebegin);
}
} // X end!
}// Z end!
}//if player > 0 end !
if(chunkNum > chunkCache){
int toEraseNum = chunkNum-chunkCache;
for(int i=0;i<toEraseNum;i++){
if(chunkList[i]->isVisible == false){
chunkList[i]->CleanUp();
chunkList.erase(chunkList.begin()+i);
chunkNum = chunkList.size();
}else{
toEraseNum--;
}
}
}
visibleIndex = 0;
for(int i = 0; i<chunkList.size(); i++){ // calculate visible chunks
if(FCD->CheckRectangle(chunkList[i]->CenterX, chunkList[i]->CenterY, chunkList[i]->CenterZ, chunkList[i]->width, 256.0f, chunkList[i]->height) == true){
chunkList[i]->isVisible = true;
currentlyVisible[visibleIndex] = i;
visibleIndex++;
}else{
chunkList[i]->isVisible = false;
}
}
playerX = playerXin;
playerZ = playerZin;
for(int i=0;i<chunkList.size();i++){
chunkList[i]->Update(playerX, playerZ);
}
}
chunk::Update() is only saving the playerX and playerZ to the chunk.