- fast caching of interpolation data
This commit is contained in:
parent
d610650624
commit
d58a3d948c
|
@ -1315,12 +1315,12 @@ void Renderer::renderObjects(const int renderFps, const int worldFrameCount) {
|
||||||
glEnable(GL_COLOR_MATERIAL);
|
glEnable(GL_COLOR_MATERIAL);
|
||||||
glAlphaFunc(GL_GREATER, 0.5f);
|
glAlphaFunc(GL_GREATER, 0.5f);
|
||||||
|
|
||||||
|
int thisTeamIndex= world->getThisTeamIndex();
|
||||||
modelRenderer->begin(true, true, false);
|
modelRenderer->begin(true, true, false);
|
||||||
int thisTeamIndex= world->getThisTeamIndex();
|
|
||||||
|
|
||||||
PosQuadIterator pqi(map, visibleQuad, Map::cellScale);
|
PosQuadIterator pqi(map, visibleQuad, Map::cellScale);
|
||||||
while(pqi.next()){
|
while(pqi.next()){
|
||||||
const Vec2i pos= pqi.getPos();
|
const Vec2i &pos= pqi.getPos();
|
||||||
|
|
||||||
if(map->isInside(pos)){
|
if(map->isInside(pos)){
|
||||||
|
|
||||||
|
@ -1329,7 +1329,7 @@ void Renderer::renderObjects(const int renderFps, const int worldFrameCount) {
|
||||||
if(sc->isExplored(thisTeamIndex) && o!=NULL){
|
if(sc->isExplored(thisTeamIndex) && o!=NULL){
|
||||||
|
|
||||||
const Model *objModel= sc->getObject()->getModel();
|
const Model *objModel= sc->getObject()->getModel();
|
||||||
Vec3f v= o->getPos();
|
const Vec3f &v= o->getConstPos();
|
||||||
|
|
||||||
//ambient and diffuse color is taken from cell color
|
//ambient and diffuse color is taken from cell color
|
||||||
float fowFactor= fowTex->getPixmap()->getPixelf(pos.x/Map::cellScale, pos.y/Map::cellScale);
|
float fowFactor= fowTex->getPixmap()->getPixelf(pos.x/Map::cellScale, pos.y/Map::cellScale);
|
||||||
|
|
|
@ -32,6 +32,9 @@ private:
|
||||||
//std::map<std::string, Vec3f *> cacheVertices;
|
//std::map<std::string, Vec3f *> cacheVertices;
|
||||||
//std::map<std::string, Vec3f *> cacheNormals;
|
//std::map<std::string, Vec3f *> cacheNormals;
|
||||||
|
|
||||||
|
std::map<float, std::map<bool, Vec3f *> > cacheVertices;
|
||||||
|
std::map<float, std::map<bool, Vec3f *> > cacheNormals;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
InterpolationData(const Mesh *mesh);
|
InterpolationData(const Mesh *mesh);
|
||||||
~InterpolationData();
|
~InterpolationData();
|
||||||
|
|
|
@ -215,8 +215,8 @@ void ModelRendererGl::renderMeshNormals(const Mesh *mesh){
|
||||||
|
|
||||||
glBegin(GL_LINES);
|
glBegin(GL_LINES);
|
||||||
for(int i= 0; i<mesh->getIndexCount(); ++i){
|
for(int i= 0; i<mesh->getIndexCount(); ++i){
|
||||||
Vec3f vertex= mesh->getInterpolationData()->getVertices()[mesh->getIndices()[i]];
|
const Vec3f &vertex= mesh->getInterpolationData()->getVertices()[mesh->getIndices()[i]];
|
||||||
Vec3f normal= vertex + mesh->getInterpolationData()->getNormals()[mesh->getIndices()[i]];
|
const Vec3f &normal= vertex + mesh->getInterpolationData()->getNormals()[mesh->getIndices()[i]];
|
||||||
|
|
||||||
glVertex3fv(vertex.ptr());
|
glVertex3fv(vertex.ptr());
|
||||||
glVertex3fv(normal.ptr());
|
glVertex3fv(normal.ptr());
|
||||||
|
|
|
@ -39,24 +39,30 @@ InterpolationData::InterpolationData(const Mesh *mesh){
|
||||||
normals= new Vec3f[mesh->getVertexCount()];
|
normals= new Vec3f[mesh->getVertexCount()];
|
||||||
}
|
}
|
||||||
|
|
||||||
//cacheVertices.clear();
|
cacheVertices.clear();
|
||||||
//cacheNormals.clear();
|
cacheNormals.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
InterpolationData::~InterpolationData(){
|
InterpolationData::~InterpolationData(){
|
||||||
delete [] vertices;
|
delete [] vertices;
|
||||||
delete [] normals;
|
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++) {
|
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++) {
|
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){
|
void InterpolationData::update(float t, bool cycle){
|
||||||
|
@ -71,21 +77,22 @@ void InterpolationData::updateVertices(float t, bool cycle) {
|
||||||
uint32 vertexCount= mesh->getVertexCount();
|
uint32 vertexCount= mesh->getVertexCount();
|
||||||
|
|
||||||
if(frameCount > 1) {
|
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()) {
|
if(iterFind != cacheVertices.end()) {
|
||||||
for(uint32 j=0; j< vertexCount; ++j){
|
std::map<bool, Vec3f *>::iterator iterFind2 = iterFind->second.find(cycle);
|
||||||
vertices[j] = iterFind->second[j];
|
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[t][cycle] = new Vec3f[vertexCount];
|
||||||
cacheVertices[lookupKey] = new Vec3f[vertexCount];
|
|
||||||
iterFind = cacheVertices.find(lookupKey);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
const Vec3f *meshVertices= mesh->getVertices();
|
const Vec3f *meshVertices= mesh->getVertices();
|
||||||
|
|
||||||
//misc vars
|
//misc vars
|
||||||
|
@ -102,7 +109,8 @@ void InterpolationData::updateVertices(float t, bool cycle) {
|
||||||
//interpolate vertices
|
//interpolate vertices
|
||||||
for(uint32 j=0; j<vertexCount; ++j){
|
for(uint32 j=0; j<vertexCount; ++j){
|
||||||
vertices[j]= meshVertices[prevFrameBase+j].lerp(localT, meshVertices[nextFrameBase+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();
|
uint32 vertexCount= mesh->getVertexCount();
|
||||||
|
|
||||||
if(frameCount > 1) {
|
if(frameCount > 1) {
|
||||||
/*
|
|
||||||
std::string lookupKey = floatToStr(t) + "_" + boolToStr(cycle);
|
std::map<float, std::map<bool, Vec3f *> >::iterator iterFind = cacheNormals.find(t);
|
||||||
std::map<std::string, Vec3f *>::iterator iterFind = cacheNormals.find(lookupKey);
|
|
||||||
if(iterFind != cacheNormals.end()) {
|
if(iterFind != cacheNormals.end()) {
|
||||||
for(uint32 j=0; j<vertexCount; ++j) {
|
std::map<bool, Vec3f *>::iterator iterFind2 = iterFind->second.find(cycle);
|
||||||
normals[j] = iterFind->second[j];
|
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[t][cycle] = new Vec3f[vertexCount];
|
||||||
cacheNormals[lookupKey] = new Vec3f[mesh->getVertexCount()];
|
|
||||||
iterFind = cacheNormals.find(lookupKey);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
const Vec3f *meshNormals= mesh->getNormals();
|
const Vec3f *meshNormals= mesh->getNormals();
|
||||||
|
|
||||||
//misc vars
|
//misc vars
|
||||||
|
@ -144,7 +153,8 @@ void InterpolationData::updateNormals(float t, bool cycle){
|
||||||
//interpolate vertices
|
//interpolate vertices
|
||||||
for(uint32 j=0; j<vertexCount; ++j){
|
for(uint32 j=0; j<vertexCount; ++j){
|
||||||
normals[j]= meshNormals[prevFrameBase+j].lerp(localT, meshNormals[nextFrameBase+j]);
|
normals[j]= meshNormals[prevFrameBase+j].lerp(localT, meshNormals[nextFrameBase+j]);
|
||||||
// iterFind->second[j] = normals[j];
|
|
||||||
|
cacheNormals[t][cycle][j] = normals[j];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user