diff options
Diffstat (limited to 'src/renderer')
-rw-r--r-- | src/renderer/tr_cmds.c | 97 | ||||
-rw-r--r-- | src/renderer/tr_init.c | 1 | ||||
-rw-r--r-- | src/renderer/tr_local.h | 3 | ||||
-rw-r--r-- | src/renderer/tr_public.h | 1 |
4 files changed, 96 insertions, 6 deletions
diff --git a/src/renderer/tr_cmds.c b/src/renderer/tr_cmds.c index 1b39c56b..ce0fa680 100644 --- a/src/renderer/tr_cmds.c +++ b/src/renderer/tr_cmds.c @@ -245,9 +245,9 @@ Passing NULL will set the color to white void RE_SetColor( const float *rgba ) { setColorCommand_t *cmd; - if ( !tr.registered ) { - return; - } + if ( !tr.registered ) { + return; + } cmd = R_GetCommandBuffer( sizeof( *cmd ) ); if ( !cmd ) { return; @@ -265,6 +265,88 @@ void RE_SetColor( const float *rgba ) { cmd->color[3] = rgba[3]; } +/* +============= +R_ClipRegion +============= +*/ +static qboolean R_ClipRegion ( float *x, float *y, float *w, float *h, + float *s1, float *t1, float *s2, float *t2 ) { + float left, top, right, bottom; + float _s1, _t1, _s2, _t2; + float clipLeft, clipTop, clipRight, clipBottom; + + if (tr.clipRegion[2] <= tr.clipRegion[0] || + tr.clipRegion[3] <= tr.clipRegion[1] ) { + return qfalse; + } + + left = *x; + top = *y; + right = *x + *w; + bottom = *y + *h; + + _s1 = *s1; + _t1 = *t1; + _s2 = *s2; + _t2 = *t2; + + clipLeft = tr.clipRegion[0]; + clipTop = tr.clipRegion[1]; + clipRight = tr.clipRegion[2]; + clipBottom = tr.clipRegion[3]; + + // Completely clipped away + if ( right <= clipLeft || left >= clipRight || + bottom <= clipTop || top >= clipBottom ) { + return qtrue; + } + + // Clip left edge + if ( left < clipLeft ) { + float f = ( clipLeft - left ) / ( right - left ); + *s1 = ( f * ( _s2 - _s1 ) ) + _s1; + *x = clipLeft; + *w -= ( clipLeft - left ); + } + + // Clip right edge + if ( right > clipRight ) { + float f = ( clipRight - right ) / ( left - right ); + *s2 = ( f * ( _s1 - _s2 ) ) + _s2; + *w = clipRight - *x; + } + + // Clip top edge + if ( top < clipTop ) { + float f = ( clipTop - top ) / ( bottom - top ); + *t1 = ( f * ( _t2 - _t1 ) ) + _t1; + *y = clipTop; + *h -= ( clipTop - top ); + } + + // Clip bottom edge + if ( bottom > clipBottom ) { + float f = ( clipBottom - bottom ) / ( top - bottom ); + *t2 = ( f * ( _t1 - _t2 ) ) + _t2; + *h = clipBottom - *y; + } + + return qfalse; +} + +/* +============= +RE_SetClipRegion +============= +*/ +void RE_SetClipRegion( const float *region ) { + if ( region == NULL ) { + Com_Memset( tr.clipRegion, 0, sizeof( vec4_t ) ); + } else { + Vector4Copy( region, tr.clipRegion ); + } +} /* ============= @@ -275,9 +357,12 @@ void RE_StretchPic ( float x, float y, float w, float h, float s1, float t1, float s2, float t2, qhandle_t hShader ) { stretchPicCommand_t *cmd; - if (!tr.registered) { - return; - } + if (!tr.registered) { + return; + } + if (R_ClipRegion(&x, &y, &w, &h, &s1, &t1, &s2, &t2)) { + return; + } cmd = R_GetCommandBuffer( sizeof( *cmd ) ); if ( !cmd ) { return; diff --git a/src/renderer/tr_init.c b/src/renderer/tr_init.c index ce2b8642..a0f301a5 100644 --- a/src/renderer/tr_init.c +++ b/src/renderer/tr_init.c @@ -1235,6 +1235,7 @@ refexport_t *GetRefAPI ( int apiVersion, refimport_t *rimp ) { re.RenderScene = RE_RenderScene; re.SetColor = RE_SetColor; + re.SetClipRegion = RE_SetClipRegion; re.DrawStretchPic = RE_StretchPic; re.DrawStretchRaw = RE_StretchRaw; re.UploadCinematic = RE_UploadCinematic; diff --git a/src/renderer/tr_local.h b/src/renderer/tr_local.h index 9f8e44f9..4e0e27f8 100644 --- a/src/renderer/tr_local.h +++ b/src/renderer/tr_local.h @@ -943,6 +943,8 @@ typedef struct { frontEndCounters_t pc; int frontEndMsec; // not in pc due to clearing issue + vec4_t clipRegion; // 2D clipping region + // // put large tables at the end, so most elements will be // within the +/32K indexed range on risc processors @@ -1690,6 +1692,7 @@ void R_SyncRenderThread( void ); void R_AddDrawSurfCmd( drawSurf_t *drawSurfs, int numDrawSurfs ); void RE_SetColor( const float *rgba ); +void RE_SetClipRegion( const float *region ); void RE_StretchPic ( float x, float y, float w, float h, float s1, float t1, float s2, float t2, qhandle_t hShader ); void RE_BeginFrame( stereoFrame_t stereoFrame ); diff --git a/src/renderer/tr_public.h b/src/renderer/tr_public.h index eac2cd29..a6c72893 100644 --- a/src/renderer/tr_public.h +++ b/src/renderer/tr_public.h @@ -71,6 +71,7 @@ typedef struct { void (*RenderScene)( const refdef_t *fd ); void (*SetColor)( const float *rgba ); // NULL = 1,1,1,1 + void (*SetClipRegion)( const float *region ); void (*DrawStretchPic) ( float x, float y, float w, float h, float s1, float t1, float s2, float t2, qhandle_t hShader ); // 0 = white |