Memory :-/
I have implemented a terrain engine using geometrical mipmapping and everything is working well... but with triangle fans. To speed up my implementation i have decided to reorganize my code and take advantage of vertex arrays. So here is what i have actually... ONE big vertex array containing all the heightmap infos ONE texture coordinates array ONE detail texture coordinates array In each patch of the terrain i keep a vertex index array for each level of detail. Say that the calculated level of detail is 3, i'll end up with 3 vertex index arrays containing the vertex indices for the three lod (that would allows to directly give the indices without having to search for them each time) So if i have a 513x513 map with 17x17 patches, i have 30 patches per side that lead me to ... Allocated vertex array (3158028 bytes) Allocated texture array (2105352 bytes) Allocated detail texture array (2105352 bytes) Number of patches per side (17x17 patch size) : 30 Successfully allocated 900 terrain patches (18000 bytes) Maximum level of detail : 3 --> Total amount of memory allocated : 1153187532 bytes (1099.77 megs) WOW what a blast ! Am I organizing my code/allocating my memory like an idiot ? 1099.77 megs is really not acceptable... If i calculate each time my indices in the vertex array i end up with something like 8.36 megs which is there much more convenient ! But, i am loosing the gain of having not to calculate each time the indices in the vertex array for a given lod... Am I missiing something ? How would you guys face this speed/memory problem, if we can say it like this ?
Best Regards, RaPhiuS / PaRaSiTe
How on earth did you come up to 1Gb? Data vertex arrays come up to about 8mb. That's OK. But index array is less than 2mb. 4mb if you use 3 LOD levels.
You should never let your fears become the boundaries of your dreams.
Well i don't know :-/
Here my patch structure
Here is the code that allocate the vertex index'es for each lod in each patch
Here my patch structure
struct GeoMipMapPatch { float distance; // distance of the center of the patch to the eye position (camera) int lod; // Patch level of detail bool visible; // Tell if the patch is visible (for frustum culling) unsigned int *numVertexIndex; // Number of vertex index per lod unsigned int **vertexIndex; // Vertex index in the vertex array for all possible lod};
Here is the code that allocate the vertex index'es for each lod in each patch
// allocate and create all the vertex index for each lod for (int z=0; z<patchPerSide; ++z) { for (int x=0; x<patchPerSide; ++x) { int index = GetPatch(x,z); // allocate lodNumber entry (one vertex index for each lod) patches[index].vertexIndex = new unsigned int*[lodNumber]; totalMem += lodNumber*sizeof(unsigned int*); patches[index].numVertexIndex = new unsigned int[lodNumber]; totalMem += lodNumber*sizeof(unsigned int); for (int iLod=0; iLod<lodNumber; ++iLod) { // figure out the number of indices we need int indexSize = 0; if (iLod==0) { indexSize = patchSize; } else { indexSize = (int)((patchSize/pow(2,iLod))+1); } // allocate what we need to store the vertex index'es patches[index].numVertexIndex[iLod] = SQUARE((indexSize-1)*(indexSize*2)); // indexSize-1 is the number of strips and indexSize*2 the length of a strip patches[index].vertexIndex[iLod] = new unsigned int[patches[index].numVertexIndex[iLod]]; totalMem += patches[index].numVertexIndex[iLod]*sizeof(unsigned int); // now tell what are the index'es logger->Write("LOD:%d\n",iLod); int vIIndex = 0; for (int zI=0; zI<patchSize-1; zI+=(iLod+1)) // -1 because we give triangle strips ! { for (int xI=0; xI<patchSize; xI+=(iLod+1)) { int xOffset = (x*(patchSize-1))+xI; int zOffset = (z*(patchSize-1))+zI; patches[index].vertexIndex[iLod][vIIndex++] = (unsigned int)((zOffset*tData.size)+xOffset); patches[index].vertexIndex[iLod][vIIndex++] = (unsigned int)(((zOffset+(iLod+1))*tData.size)+xOffset); logger->Write("%d %d ",patches[index].vertexIndex[iLod][vIIndex-1],patches[index].vertexIndex[iLod][vIIndex]); } } logger->Write("\n\n"); } // setup the other fields with default values patches[index].lod = lodNumber; patches[index].distance = 0.0f; patches[index].visible = true; } }
Best Regards, RaPhiuS / PaRaSiTe
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement