- attempt to improve rendering speed

This commit is contained in:
Mark Vejvoda 2010-07-06 06:30:49 +00:00
parent 8478ab80b3
commit 413c492684

View File

@ -41,12 +41,6 @@ namespace Glest { namespace Game{
bool MeshCallbackTeamColor::noTeamColors = false;
// if FPS is less than this we start to skip 3D renders
//int MIN_RENDER_FPS_ALLOWED = 10;
int MIN_RENDER_FPS_ALLOWED = -1;
int MIN_RENDER_LAG_ALLOWED = 1;
int MAX_RENDER_LAG_ITEMCOUNT_ALLOWED = 200;
bool RenderEntity::operator<(const RenderEntity &rhs) const {
if(this->type == retUnit || this->type == retUnitFast) {
return(this->unit->getLastRenderFrame() < rhs.unit->getLastRenderFrame());
@ -144,8 +138,8 @@ const float Renderer::magicCircleRadius= 1.f;
//perspective values
const float Renderer::perspFov= 60.f;
const float Renderer::perspNearPlane= 1.f;
//const float Renderer::perspFarPlane= 50.f;
const float Renderer::perspFarPlane= 1000.f;
const float Renderer::perspFarPlane= 50.f;
//const float Renderer::perspFarPlane= 1000.f;
const float Renderer::ambFactor= 0.7f;
const Vec4f Renderer::fowColor= Vec4f(0.0f, 0.0f, 0.0f, 1.0f);
@ -154,8 +148,8 @@ const Vec4f Renderer::defDiffuseColor= Vec4f(1.f, 1.f, 1.f, 1.f);
const Vec4f Renderer::defAmbientColor= Vec4f(1.f * ambFactor, 1.f * ambFactor, 1.f * ambFactor, 1.f);
const Vec4f Renderer::defColor= Vec4f(1.f, 1.f, 1.f, 1.f);
//const float Renderer::maxLightDist= 100.f;
const float Renderer::maxLightDist= 1000.f;
const float Renderer::maxLightDist= 100.f;
//const float Renderer::maxLightDist= 1000.f;
// ==================== constructor and destructor ====================
@ -1314,19 +1308,6 @@ void Renderer::renderObjects(const int renderFps, const int worldFrameCount) {
bool isVisible = true;
if(isExplored == true && isVisible == true) {
/*
//
//if(renderFps >= 0 && renderFps < MIN_RENDER_FPS_ALLOWED) {
// int renderLag = worldFrameCount - o->getLastRenderFrame();
// if(renderLag > MIN_RENDER_LAG_ALLOWED) {
// vctEntity.push_back(RenderEntity(retObject,o,mapPos,NULL));
// }
//}
//else {
//
vctEntity.push_back(RenderEntity(retObject,o,mapPos,NULL));
//}
*/
const Model *objModel= o->getModel();
if(objModel != NULL) {
objModel->updateInterpolationData(0.f, true);
@ -1346,29 +1327,11 @@ void Renderer::renderObjects(const int renderFps, const int worldFrameCount) {
}
void Renderer::renderObjectList(std::vector<RenderEntity> &vctEntity,const Vec3f &baseFogColor,const int renderFps, const int worldFrameCount) {
// Need to do something to manage bad FPS
/*
if(renderFps >= 0 && renderFps < MIN_RENDER_FPS_ALLOWED) {
// Oldest rendered objects go to top
std::sort(vctEntity.begin(), vctEntity.end());
for(int idx=0; idx < vctEntity.size(); ++idx) {
RenderEntity &entity = vctEntity[idx];
prepareObjectForRender(entity);
renderObject(entity,baseFogColor,renderFps, worldFrameCount);
if(idx >= MAX_RENDER_LAG_ITEMCOUNT_ALLOWED) {
break;
}
}
}
else {
*/
for(int idx=0; idx < vctEntity.size(); ++idx) {
RenderEntity &entity = vctEntity[idx];
prepareObjectForRender(entity);
renderObject(entity,baseFogColor,renderFps, worldFrameCount);
}
//}
}
void Renderer::prepareObjectForRender(RenderEntity &entity) {
@ -1582,18 +1545,6 @@ void Renderer::renderUnits(const int renderFps, const int worldFrameCount) {
for(int j=0; j<world->getFaction(i)->getUnitCount(); ++j){
Unit *unit = world->getFaction(i)->getUnit(j);
if(world->toRenderUnit(unit, visibleQuad)) {
/*
if(renderFps >= 0 && renderFps < MIN_RENDER_FPS_ALLOWED) {
int unitRenderLag = worldFrameCount - unit->getLastRenderFrame();
if(unitRenderLag > MIN_RENDER_LAG_ALLOWED) {
vctEntity.push_back(RenderEntity(retUnit,NULL,Vec2i(),unit,teamTexture));
}
}
else {
vctEntity.push_back(RenderEntity(retUnit,NULL,Vec2i(),unit,teamTexture));
}
*/
const Model *model= unit->getCurrentModel();
model->updateInterpolationData(unit->getAnimProgress(), unit->isAlive());
renderUnit(unit,&meshCallbackTeamColor, teamTexture, worldFrameCount);
@ -1617,26 +1568,10 @@ void Renderer::renderUnits(const int renderFps, const int worldFrameCount) {
}
void Renderer::renderUnitList(std::vector<RenderEntity> &vctEntity,MeshCallbackTeamColor *meshCallbackTeamColor,const int renderFps, const int worldFrameCount) {
// Need to do something to manage bad FPS
if(renderFps >= 0 && renderFps < MIN_RENDER_FPS_ALLOWED) {
// Oldest rendered units go to top
std::sort(vctEntity.begin(), vctEntity.end());
for(int idx=0; idx < vctEntity.size(); ++idx) {
RenderEntity &entity = vctEntity[idx];
prepareUnitForRender(entity);
renderUnit(entity,meshCallbackTeamColor,renderFps, worldFrameCount);
if(idx >= MAX_RENDER_LAG_ITEMCOUNT_ALLOWED) {
break;
}
}
}
else {
for(int idx=0; idx < vctEntity.size(); ++idx) {
RenderEntity &entity = vctEntity[idx];
prepareUnitForRender(entity);
renderUnit(entity,meshCallbackTeamColor,renderFps, worldFrameCount);
}
}
}
@ -2339,19 +2274,10 @@ void Renderer::computeSelected(Selection::UnitContainer &units, const Vec2i &pos
// ==================== shadows ====================
void Renderer::renderShadowsToTexture(const int renderFps){
Chrono chrono;
chrono.start();
if(renderFps >= 0 && renderFps >= MIN_RENDER_FPS_ALLOWED) {
if(shadows==sProjected || shadows==sShadowMapping){
shadowMapFrame= (shadowMapFrame + 1) % (shadowFrameSkip + 1);
if(shadowMapFrame==0){
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
chrono.start();
assertGl();
glPushAttrib(GL_ENABLE_BIT | GL_CURRENT_BIT | GL_COLOR_BUFFER_BIT | GL_VIEWPORT_BIT | GL_POLYGON_BIT);
@ -2367,9 +2293,6 @@ void Renderer::renderShadowsToTexture(const int renderFps){
glClear(GL_COLOR_BUFFER_BIT);
}
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
chrono.start();
//clear color buffer
//
//set viewport, we leave one texel always in white to avoid problems
@ -2409,9 +2332,6 @@ void Renderer::renderShadowsToTexture(const int renderFps){
Vec3f pos= game->getGameCamera()->getPos();
glTranslatef(static_cast<int>(-pos.x), 0, static_cast<int>(-pos.z));
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
chrono.start();
}
else{
//non directional light
@ -2428,35 +2348,22 @@ void Renderer::renderShadowsToTexture(const int renderFps){
glLoadIdentity();
glRotatef(-90, -1, 0, 0);
glTranslatef(-nearestLightPos.x, -nearestLightPos.y-2, -nearestLightPos.z);
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
chrono.start();
}
if(shadows==sShadowMapping){
glEnable(GL_POLYGON_OFFSET_FILL);
glPolygonOffset(1.0f, 0.001f);
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
chrono.start();
}
//render 3d
renderUnitsFast();
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
chrono.start();
renderObjectsFast();
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
chrono.start();
//read color buffer
glBindTexture(GL_TEXTURE_2D, shadowMapHandle);
glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, shadowTextureSize, shadowTextureSize);
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
chrono.start();
//get elemental matrices
Matrix4f matrix1;
matrix1[0]= 0.5f; matrix1[4]= 0.f; matrix1[8]= 0.f; matrix1[12]= 0.5f;
@ -2478,9 +2385,6 @@ void Renderer::renderShadowsToTexture(const int renderFps){
glMatrixMode(GL_PROJECTION);
glPushMatrix();
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
chrono.start();
//compute texture matrix
glLoadMatrixf(matrix1.ptr());
glMultMatrixf(matrix2.ptr());
@ -2493,16 +2397,10 @@ void Renderer::renderShadowsToTexture(const int renderFps){
glPopAttrib();
assertGl();
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
chrono.start();
}
}
}
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
}
// ==================== gl wrap ====================
@ -2729,7 +2627,7 @@ void Renderer::renderUnitsFast(){
glDisable(GL_TEXTURE_2D);
glDisable(GL_LIGHTING);
std::vector<RenderEntity> vctEntity;
//std::vector<RenderEntity> vctEntity;
modelRenderer->begin(false, false, false);
glInitNames();