From 31e26856e01debc1dc3400c93a3adce8acbc7ea6 Mon Sep 17 00:00:00 2001 From: Daniel Gibson Date: Mon, 20 Jul 2020 05:01:51 +0200 Subject: [PATCH] (Hopefully) fix Editors messing up game viewport for good, fix #300 I worked around the issue for the particle editor, but now it turned out it can also somehow happen when switching from the Radiant to the Engine (with F2), so I implemented the "proper" fix of restoring glConfig.vidWidth/Height, that are overwritten in RenderSystemLocal::BeginFrame(), in RenderSystemLocal::EndFrame(). --- neo/renderer/RenderSystem.cpp | 18 +++++++++++------- neo/renderer/RenderSystem_init.cpp | 2 ++ neo/renderer/tr_local.h | 5 +++++ neo/tools/radiant/GLWidget.cpp | 15 --------------- 4 files changed, 18 insertions(+), 22 deletions(-) diff --git a/neo/renderer/RenderSystem.cpp b/neo/renderer/RenderSystem.cpp index 0a9629c3..08414a3a 100644 --- a/neo/renderer/RenderSystem.cpp +++ b/neo/renderer/RenderSystem.cpp @@ -610,13 +610,11 @@ void idRenderSystemLocal::BeginFrame( int windowWidth, int windowHeight ) { windowHeight = tiledViewport[1]; } - // DG: FIXME: WTF?! this is *not* reset in EndFrame() and next time - // idSessionLocal::UpdateScreen() calls this function to render a proper frame, - // passing renderSystem->GetScreenWidth()/Height() WHICH JUST RETURN glConfig.vidWidth/Height - // will render the whole frame in that resolution (in a corner of the window), unless someone - // resets glConfig.vid* manually... this is quite fragile, I wonder how many (more) bugs - // (esp. in Editor code) will turn up because of this, but right now I don't dare to change - // the behavior either, in case "fixing" it breaks other things + // DG: save the original size, so editors don't mess up the game viewport + // with their tiny (texture-preview etc) viewports. + origWidth = glConfig.vidWidth; + origHeight = glConfig.vidHeight; + glConfig.vidWidth = windowWidth; glConfig.vidHeight = windowHeight; @@ -730,6 +728,12 @@ void idRenderSystemLocal::EndFrame( int *frontEndMsec, int *backEndMsec ) { } } + // DG: restore the original size that was set before BeginFrame() overwrote it + // with its function-arguments, so editors don't mess up our viewport. + // (unsure why/how this at least *kinda* worked in original Doom3, + // maybe glConfig.vidWidth/Height was reset if the window gained focus or sth) + glConfig.vidWidth = origWidth; + glConfig.vidHeight = origHeight; } /* diff --git a/neo/renderer/RenderSystem_init.cpp b/neo/renderer/RenderSystem_init.cpp index 28147bbc..390f67ac 100644 --- a/neo/renderer/RenderSystem_init.cpp +++ b/neo/renderer/RenderSystem_init.cpp @@ -2143,6 +2143,8 @@ void idRenderSystemLocal::Init( void ) { identitySpace.modelMatrix[0*4+0] = 1.0f; identitySpace.modelMatrix[1*4+1] = 1.0f; identitySpace.modelMatrix[2*4+2] = 1.0f; + + origWidth = origHeight = 0; // DG: for resetting width/height in EndFrame() } /* diff --git a/neo/renderer/tr_local.h b/neo/renderer/tr_local.h index eca4bc87..06f5f428 100644 --- a/neo/renderer/tr_local.h +++ b/neo/renderer/tr_local.h @@ -796,6 +796,11 @@ public: int guiRecursionLevel; // to prevent infinite overruns class idGuiModel * guiModel; class idGuiModel * demoGuiModel; + + // DG: remember the original glConfig.vidWidth/Height values that get overwritten in BeginFrame() + // so they can be reset in EndFrame() (Editors tend to mess up the viewport by using BeginFrame()) + int origWidth; + int origHeight; }; extern backEndState_t backEnd; diff --git a/neo/tools/radiant/GLWidget.cpp b/neo/tools/radiant/GLWidget.cpp index df2b9179..652fa76b 100644 --- a/neo/tools/radiant/GLWidget.cpp +++ b/neo/tools/radiant/GLWidget.cpp @@ -446,18 +446,6 @@ void idGLDrawableMaterial::draw(int x, int y, int w, int h) { renderView_t refdef; - // DG: renderSystem->BeginFrame() changes glConfig.vidWidth and vidHeight to w and h - // that is never reset automatically and for some reason glConfig.vidWith/height is even - // used for renderSystem->GetScreenWidth()/Height() so idSessionLocal::UpdateScreen() - // which calls renderSystem->BeginFrame( renderSystem->GetScreenWidth(), renderSystem->GetScreenHeight() ); - // won't reset those values to something sane either, causing the game to be rendered in a tiny rectangle - // at the lower left corner of the screen once we're done picking a material here.. - // I don't dare to fix this in renderSystem, as other code might rely on this behavior.. - // (OTOH I wouldn't be surprised if other callers of renderSystem->BeginFrame() cause the same issue) - // Anyway, my workaround is to remember glConfig.vidWith/Height and set them to the original - // values once we're done rendering here.. - int oldWidth = glConfig.vidWidth; - int oldHeight = glConfig.vidHeight; // render it renderSystem->BeginFrame(w, h); memset( &refdef, 0, sizeof( refdef ) ); @@ -482,9 +470,6 @@ void idGLDrawableMaterial::draw(int x, int y, int w, int h) { qglMatrixMode( GL_MODELVIEW ); qglLoadIdentity(); - // DG: reset glConfig.vidWidth/Height - glConfig.vidWidth = oldWidth; - glConfig.vidHeight = oldHeight; } }