- bugfix for users toggling back from Linux tty session
This commit is contained in:
parent
016771ed81
commit
c4d32ae0d2
|
@ -3685,7 +3685,7 @@ void Renderer::computeSelected( Selection::UnitContainer &units, const Object *&
|
||||||
// ==================== shadows ====================
|
// ==================== shadows ====================
|
||||||
|
|
||||||
void Renderer::renderShadowsToTexture(const int renderFps){
|
void Renderer::renderShadowsToTexture(const int renderFps){
|
||||||
if(!shadowsOffDueToMinRender &&
|
if(shadowsOffDueToMinRender == false &&
|
||||||
(shadows == sProjected || shadows == sShadowMapping)) {
|
(shadows == sProjected || shadows == sShadowMapping)) {
|
||||||
|
|
||||||
shadowMapFrame= (shadowMapFrame + 1) % (shadowFrameSkip + 1);
|
shadowMapFrame= (shadowMapFrame + 1) % (shadowFrameSkip + 1);
|
||||||
|
@ -3695,10 +3695,10 @@ void Renderer::renderShadowsToTexture(const int renderFps){
|
||||||
|
|
||||||
glPushAttrib(GL_ENABLE_BIT | GL_CURRENT_BIT | GL_COLOR_BUFFER_BIT | GL_VIEWPORT_BIT | GL_POLYGON_BIT);
|
glPushAttrib(GL_ENABLE_BIT | GL_CURRENT_BIT | GL_COLOR_BUFFER_BIT | GL_VIEWPORT_BIT | GL_POLYGON_BIT);
|
||||||
|
|
||||||
if(shadows==sShadowMapping){
|
if(shadows == sShadowMapping) {
|
||||||
glClear(GL_DEPTH_BUFFER_BIT);
|
glClear(GL_DEPTH_BUFFER_BIT);
|
||||||
}
|
}
|
||||||
else{
|
else {
|
||||||
float color= 1.0f-shadowAlpha;
|
float color= 1.0f-shadowAlpha;
|
||||||
glColor3f(color, color, color);
|
glColor3f(color, color, color);
|
||||||
glClearColor(1.f, 1.f, 1.f, 1.f);
|
glClearColor(1.f, 1.f, 1.f, 1.f);
|
||||||
|
@ -3706,12 +3706,16 @@ void Renderer::renderShadowsToTexture(const int renderFps){
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//assertGl();
|
||||||
|
|
||||||
//clear color buffer
|
//clear color buffer
|
||||||
//
|
//
|
||||||
//set viewport, we leave one texel always in white to avoid problems
|
//set viewport, we leave one texel always in white to avoid problems
|
||||||
glViewport(1, 1, shadowTextureSize-2, shadowTextureSize-2);
|
glViewport(1, 1, shadowTextureSize-2, shadowTextureSize-2);
|
||||||
|
|
||||||
if(nearestLightPos.w==0.f){
|
//assertGl();
|
||||||
|
|
||||||
|
if(nearestLightPos.w == 0.f) {
|
||||||
//directional light
|
//directional light
|
||||||
|
|
||||||
//light pos
|
//light pos
|
||||||
|
@ -3726,6 +3730,9 @@ void Renderer::renderShadowsToTexture(const int renderFps){
|
||||||
glMatrixMode(GL_PROJECTION);
|
glMatrixMode(GL_PROJECTION);
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
|
|
||||||
|
//assertGl();
|
||||||
|
|
||||||
if(game->getGameCamera()->getState()==GameCamera::sGame){
|
if(game->getGameCamera()->getState()==GameCamera::sGame){
|
||||||
//glOrtho(-35, 5, -15, 15, -1000, 1000);
|
//glOrtho(-35, 5, -15, 15, -1000, 1000);
|
||||||
//glOrtho(-30, 30, -20, 20, -1000, 1000);
|
//glOrtho(-30, 30, -20, 20, -1000, 1000);
|
||||||
|
@ -3735,6 +3742,8 @@ void Renderer::renderShadowsToTexture(const int renderFps){
|
||||||
glOrtho(-30, 30, -20, 20, -1000, 1000);
|
glOrtho(-30, 30, -20, 20, -1000, 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//assertGl();
|
||||||
|
|
||||||
//push and set modelview
|
//push and set modelview
|
||||||
glMatrixMode(GL_MODELVIEW);
|
glMatrixMode(GL_MODELVIEW);
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
|
@ -3747,39 +3756,59 @@ void Renderer::renderShadowsToTexture(const int renderFps){
|
||||||
const Vec3f &pos= game->getGameCamera()->getPos();
|
const Vec3f &pos= game->getGameCamera()->getPos();
|
||||||
|
|
||||||
glTranslatef(static_cast<int>(-pos.x), 0, static_cast<int>(-pos.z));
|
glTranslatef(static_cast<int>(-pos.x), 0, static_cast<int>(-pos.z));
|
||||||
|
|
||||||
|
//assertGl();
|
||||||
}
|
}
|
||||||
else{
|
else {
|
||||||
//non directional light
|
//non directional light
|
||||||
|
|
||||||
//push projection
|
//push projection
|
||||||
glMatrixMode(GL_PROJECTION);
|
glMatrixMode(GL_PROJECTION);
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
|
|
||||||
|
//assertGl();
|
||||||
|
|
||||||
gluPerspective(perspFov, 1.f, perspNearPlane, perspFarPlane);
|
gluPerspective(perspFov, 1.f, perspNearPlane, perspFarPlane);
|
||||||
//const Metrics &metrics= Metrics::getInstance();
|
//const Metrics &metrics= Metrics::getInstance();
|
||||||
//gluPerspective(perspFov, metrics.getAspectRatio(), perspNearPlane, perspFarPlane);
|
//gluPerspective(perspFov, metrics.getAspectRatio(), perspNearPlane, perspFarPlane);
|
||||||
|
|
||||||
|
|
||||||
|
assertGl();
|
||||||
|
|
||||||
//push modelview
|
//push modelview
|
||||||
glMatrixMode(GL_MODELVIEW);
|
glMatrixMode(GL_MODELVIEW);
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
glRotatef(-90, -1, 0, 0);
|
glRotatef(-90, -1, 0, 0);
|
||||||
glTranslatef(-nearestLightPos.x, -nearestLightPos.y-2, -nearestLightPos.z);
|
glTranslatef(-nearestLightPos.x, -nearestLightPos.y-2, -nearestLightPos.z);
|
||||||
|
|
||||||
|
//assertGl();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(shadows == sShadowMapping) {
|
if(shadows == sShadowMapping) {
|
||||||
glEnable(GL_POLYGON_OFFSET_FILL);
|
glEnable(GL_POLYGON_OFFSET_FILL);
|
||||||
glPolygonOffset(1.0f, 16.0f);
|
glPolygonOffset(1.0f, 16.0f);
|
||||||
|
|
||||||
|
//assertGl();
|
||||||
}
|
}
|
||||||
|
|
||||||
//render 3d
|
//render 3d
|
||||||
renderUnitsFast(true);
|
renderUnitsFast(true);
|
||||||
renderObjectsFast(true,false);
|
renderObjectsFast(true,false);
|
||||||
|
|
||||||
|
//assertGl();
|
||||||
|
|
||||||
//read color buffer
|
//read color buffer
|
||||||
glBindTexture(GL_TEXTURE_2D, shadowMapHandle);
|
glBindTexture(GL_TEXTURE_2D, shadowMapHandle);
|
||||||
|
assertGl();
|
||||||
glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, shadowTextureSize, shadowTextureSize);
|
glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, shadowTextureSize, shadowTextureSize);
|
||||||
|
GLenum error = glGetError();
|
||||||
|
// This error can happen when a Linux user switches from an X session
|
||||||
|
// back to a running game, and 'seems' to be safe to ignore it
|
||||||
|
if(error != GL_INVALID_OPERATION) {
|
||||||
|
assertGlWithErrorNumber(error);
|
||||||
|
}
|
||||||
|
|
||||||
//get elemental matrices
|
//get elemental matrices
|
||||||
static Matrix4f matrix1;
|
static Matrix4f matrix1;
|
||||||
|
@ -3794,6 +3823,8 @@ void Renderer::renderShadowsToTexture(const int renderFps){
|
||||||
Matrix4f matrix2;
|
Matrix4f matrix2;
|
||||||
glGetFloatv(GL_PROJECTION_MATRIX, matrix2.ptr());
|
glGetFloatv(GL_PROJECTION_MATRIX, matrix2.ptr());
|
||||||
|
|
||||||
|
//assertGl();
|
||||||
|
|
||||||
Matrix4f matrix3;
|
Matrix4f matrix3;
|
||||||
glGetFloatv(GL_MODELVIEW_MATRIX, matrix3.ptr());
|
glGetFloatv(GL_MODELVIEW_MATRIX, matrix3.ptr());
|
||||||
|
|
||||||
|
@ -3805,12 +3836,16 @@ void Renderer::renderShadowsToTexture(const int renderFps){
|
||||||
glMatrixMode(GL_PROJECTION);
|
glMatrixMode(GL_PROJECTION);
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
|
|
||||||
|
//assertGl();
|
||||||
|
|
||||||
//compute texture matrix
|
//compute texture matrix
|
||||||
glLoadMatrixf(matrix1.ptr());
|
glLoadMatrixf(matrix1.ptr());
|
||||||
glMultMatrixf(matrix2.ptr());
|
glMultMatrixf(matrix2.ptr());
|
||||||
glMultMatrixf(matrix3.ptr());
|
glMultMatrixf(matrix3.ptr());
|
||||||
glGetFloatv(GL_TRANSPOSE_PROJECTION_MATRIX_ARB, shadowMapMatrix.ptr());
|
glGetFloatv(GL_TRANSPOSE_PROJECTION_MATRIX_ARB, shadowMapMatrix.ptr());
|
||||||
|
|
||||||
|
//assertGl();
|
||||||
|
|
||||||
//if(shadows == sShadowMapping) {
|
//if(shadows == sShadowMapping) {
|
||||||
// glDisable(GL_POLYGON_OFFSET_FILL);
|
// glDisable(GL_POLYGON_OFFSET_FILL);
|
||||||
// glPolygonOffset(0.0f, 0.0f);
|
// glPolygonOffset(0.0f, 0.0f);
|
||||||
|
@ -3819,6 +3854,8 @@ void Renderer::renderShadowsToTexture(const int renderFps){
|
||||||
//pop
|
//pop
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
|
|
||||||
|
//assertGl();
|
||||||
|
|
||||||
glPopAttrib();
|
glPopAttrib();
|
||||||
|
|
||||||
assertGl();
|
assertGl();
|
||||||
|
|
|
@ -48,23 +48,24 @@ int getGlModelviewMatrixStackDepth();
|
||||||
int getGlProjectionMatrixStackDepth();
|
int getGlProjectionMatrixStackDepth();
|
||||||
void checkGlExtension(const char *extensionName);
|
void checkGlExtension(const char *extensionName);
|
||||||
|
|
||||||
void inline _assertGl(const char *file, int line){
|
void inline _assertGl(const char *file, int line, GLenum *forceErrorNumber = NULL) {
|
||||||
|
GLenum error = (forceErrorNumber != NULL ? *forceErrorNumber : glGetError());
|
||||||
GLenum error= glGetError();
|
if(error != GL_NO_ERROR) {
|
||||||
|
|
||||||
if(error != GL_NO_ERROR){
|
|
||||||
const char *errorString= reinterpret_cast<const char*>(gluErrorString(error));
|
const char *errorString= reinterpret_cast<const char*>(gluErrorString(error));
|
||||||
throw runtime_error("OpenGL error: "+string(errorString)+" at file: "+string(file)+", line "+intToStr(line));
|
throw runtime_error("OpenGL error #" + intToStr(error) + " : " + string(errorString) + " at file: " + string(file) + ", line " + intToStr(line));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef NDEBUG
|
#ifdef NDEBUG
|
||||||
|
|
||||||
#define assertGl() ((void) 0);
|
#define assertGl() ((void) 0);
|
||||||
|
#define assertGlWithErrorNumber(forceErrorNumber) ((void) 0);
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
#define assertGl() _assertGl(__FILE__, __LINE__);
|
#define assertGl() _assertGl(__FILE__, __LINE__);
|
||||||
|
#define assertGlWithErrorNumber(forceErrorNumber) _assertGl(__FILE__, __LINE__, &forceErrorNumber);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user