- fast caching of interpolation data

This commit is contained in:
Mark Vejvoda 2010-07-17 12:16:02 +00:00
parent d610650624
commit d58a3d948c
4 changed files with 50 additions and 37 deletions

View File

@ -1315,12 +1315,12 @@ void Renderer::renderObjects(const int renderFps, const int worldFrameCount) {
glEnable(GL_COLOR_MATERIAL);
glAlphaFunc(GL_GREATER, 0.5f);
int thisTeamIndex= world->getThisTeamIndex();
modelRenderer->begin(true, true, false);
int thisTeamIndex= world->getThisTeamIndex();
PosQuadIterator pqi(map, visibleQuad, Map::cellScale);
while(pqi.next()){
const Vec2i pos= pqi.getPos();
const Vec2i &pos= pqi.getPos();
if(map->isInside(pos)){
@ -1329,7 +1329,7 @@ void Renderer::renderObjects(const int renderFps, const int worldFrameCount) {
if(sc->isExplored(thisTeamIndex) && o!=NULL){
const Model *objModel= sc->getObject()->getModel();
Vec3f v= o->getPos();
const Vec3f &v= o->getConstPos();
//ambient and diffuse color is taken from cell color
float fowFactor= fowTex->getPixmap()->getPixelf(pos.x/Map::cellScale, pos.y/Map::cellScale);

View File

@ -32,6 +32,9 @@ private:
//std::map<std::string, Vec3f *> cacheVertices;
//std::map<std::string, Vec3f *> cacheNormals;
std::map<float, std::map<bool, Vec3f *> > cacheVertices;
std::map<float, std::map<bool, Vec3f *> > cacheNormals;
public:
InterpolationData(const Mesh *mesh);
~InterpolationData();

View File

@ -215,8 +215,8 @@ void ModelRendererGl::renderMeshNormals(const Mesh *mesh){
glBegin(GL_LINES);
for(int i= 0; i<mesh->getIndexCount(); ++i){
Vec3f vertex= mesh->getInterpolationData()->getVertices()[mesh->getIndices()[i]];
Vec3f normal= vertex + mesh->getInterpolationData()->getNormals()[mesh->getIndices()[i]];
const Vec3f &vertex= mesh->getInterpolationData()->getVertices()[mesh->getIndices()[i]];
const Vec3f &normal= vertex + mesh->getInterpolationData()->getNormals()[mesh->getIndices()[i]];
glVertex3fv(vertex.ptr());
glVertex3fv(normal.ptr());

View File

@ -39,24 +39,30 @@ InterpolationData::InterpolationData(const Mesh *mesh){
normals= new Vec3f[mesh->getVertexCount()];
}
//cacheVertices.clear();
//cacheNormals.clear();
cacheVertices.clear();
cacheNormals.clear();
}
InterpolationData::~InterpolationData(){
delete [] vertices;
delete [] normals;
/*
for(std::map<std::string, Vec3f *>::iterator iterVert = cacheVertices.begin();
for(std::map<float, std::map<bool, Vec3f *> >::iterator iterVert = cacheVertices.begin();
iterVert != cacheVertices.end(); iterVert++) {
delete [] iterVert->second;
for(std::map<bool, Vec3f *>::iterator iterVert2 = iterVert->second.begin();
iterVert2 != iterVert->second.end(); iterVert2++) {
delete [] iterVert2->second;
}
}
for(std::map<std::string, Vec3f *>::iterator iterVert = cacheNormals.begin();
for(std::map<float, std::map<bool, Vec3f *> >::iterator iterVert = cacheNormals.begin();
iterVert != cacheNormals.end(); iterVert++) {
delete [] iterVert->second;
for(std::map<bool, Vec3f *>::iterator iterVert2 = iterVert->second.begin();
iterVert2 != iterVert->second.end(); iterVert2++) {
delete [] iterVert2->second;
}
}
*/
}
void InterpolationData::update(float t, bool cycle){
@ -71,21 +77,22 @@ void InterpolationData::updateVertices(float t, bool cycle) {
uint32 vertexCount= mesh->getVertexCount();
if(frameCount > 1) {
/*
std::string lookupKey = floatToStr(t) + "_" + boolToStr(cycle);
std::map<std::string, Vec3f *>::iterator iterFind = cacheVertices.find(lookupKey);
std::map<float, std::map<bool, Vec3f *> >::iterator iterFind = cacheVertices.find(t);
if(iterFind != cacheVertices.end()) {
for(uint32 j=0; j< vertexCount; ++j){
vertices[j] = iterFind->second[j];
std::map<bool, Vec3f *>::iterator iterFind2 = iterFind->second.find(cycle);
if(iterFind2 != iterFind->second.end()) {
//for(uint32 j=0; j< vertexCount; ++j){
// vertices[j] = iterFind2->second[j];
//}
memcpy(vertices,iterFind2->second,sizeof(Vec3f) * vertexCount);
return;
}
return;
}
else {
cacheVertices[lookupKey] = new Vec3f[vertexCount];
iterFind = cacheVertices.find(lookupKey);
}
*/
cacheVertices[t][cycle] = new Vec3f[vertexCount];
const Vec3f *meshVertices= mesh->getVertices();
//misc vars
@ -102,7 +109,8 @@ void InterpolationData::updateVertices(float t, bool cycle) {
//interpolate vertices
for(uint32 j=0; j<vertexCount; ++j){
vertices[j]= meshVertices[prevFrameBase+j].lerp(localT, meshVertices[nextFrameBase+j]);
// iterFind->second[j] = vertices[j];
cacheVertices[t][cycle][j] = vertices[j];
}
}
}
@ -114,20 +122,21 @@ void InterpolationData::updateNormals(float t, bool cycle){
uint32 vertexCount= mesh->getVertexCount();
if(frameCount > 1) {
/*
std::string lookupKey = floatToStr(t) + "_" + boolToStr(cycle);
std::map<std::string, Vec3f *>::iterator iterFind = cacheNormals.find(lookupKey);
std::map<float, std::map<bool, Vec3f *> >::iterator iterFind = cacheNormals.find(t);
if(iterFind != cacheNormals.end()) {
for(uint32 j=0; j<vertexCount; ++j) {
normals[j] = iterFind->second[j];
std::map<bool, Vec3f *>::iterator iterFind2 = iterFind->second.find(cycle);
if(iterFind2 != iterFind->second.end()) {
//for(uint32 j=0; j< vertexCount; ++j){
// normals[j] = iterFind2->second[j];
//}
memcpy(normals,iterFind2->second,sizeof(Vec3f) * vertexCount);
return;
}
return;
}
else {
cacheNormals[lookupKey] = new Vec3f[mesh->getVertexCount()];
iterFind = cacheNormals.find(lookupKey);
}
*/
cacheNormals[t][cycle] = new Vec3f[vertexCount];
const Vec3f *meshNormals= mesh->getNormals();
//misc vars
@ -144,7 +153,8 @@ void InterpolationData::updateNormals(float t, bool cycle){
//interpolate vertices
for(uint32 j=0; j<vertexCount; ++j){
normals[j]= meshNormals[prevFrameBase+j].lerp(localT, meshNormals[nextFrameBase+j]);
// iterFind->second[j] = normals[j];
cacheNormals[t][cycle][j] = normals[j];
}
}
}