void Init() { PROFILE_SCOPED() frac = 1.0 / double(edgeLen-1); // also want vtx indices for tris not touching edge of patch indices.reset(new unsigned short[IDX_VBO_COUNT_ALL_IDX()]); unsigned short *idx = indices.get(); for (int x=0; x<edgeLen-1; x++) { for (int y=0; y<edgeLen-1; y++) { idx[0] = x + edgeLen*y; idx[1] = x+1 + edgeLen*y; idx[2] = x + edgeLen*(y+1); idx+=3; idx[0] = x+1 + edgeLen*y; idx[1] = x+1 + edgeLen*(y+1); idx[2] = x + edgeLen*(y+1); idx+=3; } } // these will hold the optimised indices std::vector<unsigned short> pl_short; // populate the N indices lists from the arrays built during InitTerrainIndices() // iterate over each index list and optimize it unsigned int tri_count = GetIndices(pl_short); VertexCacheOptimizerUShort vco; VertexCacheOptimizerUShort::Result res = vco.Optimize(&pl_short[0], tri_count); assert(0 == res); //create buffer & copy indexBuffer.Reset(Pi::renderer->CreateIndexBuffer(pl_short.size(), Graphics::BUFFER_USAGE_STATIC)); Uint16* idxPtr = indexBuffer->Map(Graphics::BUFFER_MAP_WRITE); for (Uint32 j = 0; j < pl_short.size(); j++) { idxPtr[j] = pl_short[j]; } indexBuffer->Unmap(); if (indices) { indices.reset(); } }