r_lockSurfaces: Cleaner handling of view matrix creation etc

This commit is contained in:
Daniel Gibson 2021-06-12 17:45:32 +02:00
parent 907fc5771b
commit 633ce814ca
4 changed files with 28 additions and 36 deletions

View file

@ -262,7 +262,7 @@ evaluated interactively.
======================
*/
void R_SetupViewFrustum( void );
void R_SetupViewFrustum( viewDef_t* viewDef );
void R_SetupProjection( viewDef_t * viewDef );
void R_LockSurfaceScene( viewDef_t *parms ) {
@ -277,7 +277,7 @@ void R_LockSurfaceScene( viewDef_t *parms ) {
// the four sides of the view frustum are needed
// for culling and portal visibility
R_SetupViewFrustum();
R_SetupViewFrustum( tr.viewDef );
// we need to set the projection matrix before doing
// portal-to-screen scissor box calculations

View file

@ -675,6 +675,8 @@ Rendering a scene may require multiple views to be rendered
to handle mirrors,
====================
*/
extern void R_SetupViewFrustum( viewDef_t* viewDef );
extern void R_SetupProjection( viewDef_t * viewDef );
void idRenderWorldLocal::RenderScene( const renderView_t *renderView ) {
#ifndef ID_DEDICATED
renderView_t copy;
@ -758,15 +760,13 @@ void idRenderWorldLocal::RenderScene( const renderView_t *renderView ) {
if ( r_lockSurfaces.GetBool() ) {
tr.lockSurfacesRealViewDef = *parms;
// call this here already so idGuiModel::EmitToCurrentView() can use it
R_SetViewMatrix(&tr.lockSurfacesRealViewDef);
/*
viewDef_t* lockedParms = &tr.lockSurfacesViewDef;
parms->renderView = lockedParms->renderView;
parms->projectionMatrix = lockedParms->projectionMatrix;
parms->worldSpace = lockedParms->worldSpace;
parms->initialViewAreaOrigin = lockedParms->initialViewAreaOrigin;
*/
// usually the following are called later in R_RenderView(), but we pass
// the locked viewDef to that function so do these calculations here
// (the results are needed for some special cases like in-world GUIs and mirrors)
R_SetViewMatrix( &tr.lockSurfacesRealViewDef );
R_SetupViewFrustum( &tr.lockSurfacesRealViewDef);
R_SetupProjection( &tr.lockSurfacesRealViewDef );
const viewDef_t* origParms = &tr.lockSurfacesRealViewDef;
*parms = tr.lockSurfacesViewDef;
parms->renderWorld = origParms->renderWorld;
@ -788,8 +788,6 @@ void idRenderWorldLocal::RenderScene( const renderView_t *renderView ) {
tr.primaryRenderView = *renderView;
tr.primaryView = parms;
// rendering this view may cause other views to be rendered
// for mirrors / portals / shadows / environment maps
// this will also cause any necessary entities and lights to be

View file

@ -968,30 +968,30 @@ FIXME: derive from modelview matrix times projection matrix
=================
*/
//static
void R_SetupViewFrustum( void ) {
void R_SetupViewFrustum( viewDef_t* viewDef ) {
int i;
float xs, xc;
float ang;
ang = DEG2RAD( tr.viewDef->renderView.fov_x ) * 0.5f;
ang = DEG2RAD( viewDef->renderView.fov_x ) * 0.5f;
idMath::SinCos( ang, xs, xc );
tr.viewDef->frustum[0] = xs * tr.viewDef->renderView.viewaxis[0] + xc * tr.viewDef->renderView.viewaxis[1];
tr.viewDef->frustum[1] = xs * tr.viewDef->renderView.viewaxis[0] - xc * tr.viewDef->renderView.viewaxis[1];
viewDef->frustum[0] = xs * viewDef->renderView.viewaxis[0] + xc * viewDef->renderView.viewaxis[1];
viewDef->frustum[1] = xs * viewDef->renderView.viewaxis[0] - xc * viewDef->renderView.viewaxis[1];
ang = DEG2RAD( tr.viewDef->renderView.fov_y ) * 0.5f;
ang = DEG2RAD( viewDef->renderView.fov_y ) * 0.5f;
idMath::SinCos( ang, xs, xc );
tr.viewDef->frustum[2] = xs * tr.viewDef->renderView.viewaxis[0] + xc * tr.viewDef->renderView.viewaxis[2];
tr.viewDef->frustum[3] = xs * tr.viewDef->renderView.viewaxis[0] - xc * tr.viewDef->renderView.viewaxis[2];
viewDef->frustum[2] = xs * viewDef->renderView.viewaxis[0] + xc * viewDef->renderView.viewaxis[2];
viewDef->frustum[3] = xs * viewDef->renderView.viewaxis[0] - xc * viewDef->renderView.viewaxis[2];
// plane four is the front clipping plane
tr.viewDef->frustum[4] = /* vec3_origin - */ tr.viewDef->renderView.viewaxis[0];
viewDef->frustum[4] = /* vec3_origin - */ viewDef->renderView.viewaxis[0];
for ( i = 0; i < 5; i++ ) {
// flip direction so positive side faces out (FIXME: globally unify this)
tr.viewDef->frustum[i] = -tr.viewDef->frustum[i].Normal();
tr.viewDef->frustum[i][3] = -( tr.viewDef->renderView.vieworg * tr.viewDef->frustum[i].Normal() );
viewDef->frustum[i] = -viewDef->frustum[i].Normal();
viewDef->frustum[i][3] = -( viewDef->renderView.vieworg * viewDef->frustum[i].Normal() );
}
// eventually, plane five will be the rear clipping plane for fog
@ -999,16 +999,16 @@ void R_SetupViewFrustum( void ) {
float dNear, dFar, dLeft, dUp;
dNear = r_znear.GetFloat();
if ( tr.viewDef->renderView.cramZNear ) {
if ( viewDef->renderView.cramZNear ) {
dNear *= 0.25f;
}
dFar = MAX_WORLD_SIZE;
dLeft = dFar * tan( DEG2RAD( tr.viewDef->renderView.fov_x * 0.5f ) );
dUp = dFar * tan( DEG2RAD( tr.viewDef->renderView.fov_y * 0.5f ) );
tr.viewDef->viewFrustum.SetOrigin( tr.viewDef->renderView.vieworg );
tr.viewDef->viewFrustum.SetAxis( tr.viewDef->renderView.viewaxis );
tr.viewDef->viewFrustum.SetSize( dNear, dFar, dLeft, dUp );
dLeft = dFar * tan( DEG2RAD( viewDef->renderView.fov_x * 0.5f ) );
dUp = dFar * tan( DEG2RAD( viewDef->renderView.fov_y * 0.5f ) );
viewDef->viewFrustum.SetOrigin( viewDef->renderView.vieworg );
viewDef->viewFrustum.SetAxis( viewDef->renderView.viewaxis );
viewDef->viewFrustum.SetSize( dNear, dFar, dLeft, dUp );
}
/*
@ -1116,7 +1116,7 @@ void R_RenderView( viewDef_t *parms, bool isMain ) {
// the four sides of the view frustum are needed
// for culling and portal visibility
R_SetupViewFrustum();
R_SetupViewFrustum( tr.viewDef );
// we need to set the projection matrix before doing
// portal-to-screen scissor box calculations

View file

@ -850,7 +850,6 @@ void RB_CreateSingleDrawInteractions( const drawSurf_t *surf, void (*DrawInterac
RB_DrawView
=============
*/
extern void R_SetupProjection( viewDef_t * viewDef );
void RB_DrawView( const void *data ) {
const drawSurfsCommand_t *cmd;
@ -874,11 +873,6 @@ void RB_DrawView( const void *data ) {
parms->viewEntitys = origParms.viewEntitys;
parms->connectedAreas = origParms.connectedAreas;
// projection etc are usually set in R_RenderView(), hasn't happened for the "real" viewdef yet
// R_SetViewMatrix(parms); - already done in idRenderWorldLocal::RenderScene() so idGuiModel::EmitToCurrentView() can use it
// R_SetupViewFrustum( parms ); TODO unsure if necessary
R_SetupProjection( parms );
for( viewEntity_t* vModel = parms->viewEntitys ; vModel ; vModel = vModel->next ) {
myGlMultMatrix( vModel->modelMatrix,
parms->worldSpace.modelViewMatrix,