Skip to content

Commit

Permalink
Merge branch 'ioquake:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
oitzujoey authored Jan 14, 2024
2 parents 028e8bc + 5ede35d commit 75abcd4
Show file tree
Hide file tree
Showing 22 changed files with 1,296 additions and 68 deletions.
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -1070,7 +1070,6 @@ endif

ifneq ($(HAVE_VM_COMPILED),true)
BASE_CFLAGS += -DNO_VM_COMPILED
BUILD_GAME_QVM=0
endif

TARGETS =
Expand Down
2 changes: 1 addition & 1 deletion code/botlib/be_aas.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,5 +217,5 @@ typedef struct aas_predictroute_s
int endcontents; //contents at the end of movement prediction
int endtravelflags; //end travel flags
int numareas; //number of areas predicted ahead
int time; //time predicted ahead (in hundreth of a sec)
int time; //time predicted ahead (in hundredths of a sec)
} aas_predictroute_t;
2 changes: 1 addition & 1 deletion code/botlib/be_aas_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ void AAS_FileInfo(void)
aasworld.reachabilitysize * sizeof(aas_reachability_t) +
aasworld.numportals * sizeof(aas_portal_t) +
aasworld.numclusters * sizeof(aas_cluster_t);
botimport.Print(PRT_MESSAGE, "optimzed size %d KB\n", optimized >> 10);
botimport.Print(PRT_MESSAGE, "optimized size %d KB\n", optimized >> 10);
} //end of the function AAS_FileInfo
#endif //AASFILEDEBUG
//===========================================================================
Expand Down
38 changes: 19 additions & 19 deletions code/renderergl2/tr_backend.c
Original file line number Diff line number Diff line change
Expand Up @@ -342,9 +342,7 @@ void RB_BeginDrawingView (void) {
{
FBO_t *fbo = backEnd.viewParms.targetFbo;

// FIXME: HUGE HACK: render to the screen fbo if we've already postprocessed the frame and aren't drawing more world
// drawing more world check is in case of double renders, such as skyportals
if (fbo == NULL && !(backEnd.framePostProcessed && (backEnd.refdef.rdflags & RDF_NOWORLDMODEL)))
if (fbo == NULL && (!r_postProcess->integer || !(backEnd.refdef.rdflags & RDF_NOWORLDMODEL)))
fbo = tr.renderFbo;

if (tr.renderCubeFbo && fbo == tr.renderCubeFbo)
Expand Down Expand Up @@ -708,10 +706,9 @@ void RE_StretchRaw (int x, int y, int w, int h, int cols, int rows, const byte *
ri.Printf( PRINT_ALL, "qglTexSubImage2D %i, %i: %i msec\n", cols, rows, end - start );
}

// FIXME: HUGE hack
if (glRefConfig.framebufferObject)
{
FBO_Bind(backEnd.framePostProcessed ? NULL : tr.renderFbo);
FBO_Bind(r_postProcess->integer ? NULL : tr.renderFbo);
}

RB_SetGL2D();
Expand Down Expand Up @@ -795,9 +792,8 @@ const void *RB_StretchPic ( const void *data ) {

cmd = (const stretchPicCommand_t *)data;

// FIXME: HUGE hack
if (glRefConfig.framebufferObject)
FBO_Bind(backEnd.framePostProcessed ? NULL : tr.renderFbo);
FBO_Bind(r_postProcess->integer ? NULL : tr.renderFbo);

RB_SetGL2D();

Expand Down Expand Up @@ -1173,6 +1169,13 @@ const void *RB_DrawSurfs( const void *data ) {
qglGenerateTextureMipmapEXT(cubemap->image->texnum, GL_TEXTURE_CUBE_MAP);
}

// FIXME? backEnd.viewParms doesn't get properly initialized for 2D drawing.
// r_cubeMapping 1 generates cubemaps with R_RenderCubemapSide()
// and sets isMirror = qtrue. Clear it here to prevent it from leaking
// to 2D drawing and causing the loading screen to be culled.
backEnd.viewParms.isMirror = qfalse;
backEnd.viewParms.flags = 0;

return (const void *)(cmd + 1);
}

Expand Down Expand Up @@ -1201,6 +1204,13 @@ const void *RB_DrawBuffer( const void *data ) {
if ( r_clear->integer ) {
qglClearColor( 1, 0, 0.5, 1 );
qglClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

if (glRefConfig.framebufferObject && tr.renderFbo) {
FBO_Bind(tr.renderFbo);

qglClearColor( 1, 0, 0.5, 1 );
qglClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
}
}

return (const void *)(cmd + 1);
Expand Down Expand Up @@ -1313,14 +1323,7 @@ const void *RB_ClearDepth(const void *data)

if (glRefConfig.framebufferObject)
{
if (!tr.renderFbo || backEnd.framePostProcessed)
{
FBO_Bind(NULL);
}
else
{
FBO_Bind(tr.renderFbo);
}
FBO_Bind(tr.renderFbo);
}

qglClear(GL_DEPTH_BUFFER_BIT);
Expand Down Expand Up @@ -1378,7 +1381,7 @@ const void *RB_SwapBuffers( const void *data ) {

if (glRefConfig.framebufferObject)
{
if (!backEnd.framePostProcessed)
if (!r_postProcess->integer)
{
if (tr.msaaResolveFbo && r_hdr->integer)
{
Expand All @@ -1401,7 +1404,6 @@ const void *RB_SwapBuffers( const void *data ) {

GLimp_EndFrame();

backEnd.framePostProcessed = qfalse;
backEnd.projection2D = qfalse;

return (const void *)(cmd + 1);
Expand Down Expand Up @@ -1655,8 +1657,6 @@ const void *RB_PostProcess(const void *data)
}
#endif

backEnd.framePostProcessed = qtrue;

return (const void *)(cmd + 1);
}

Expand Down
1 change: 1 addition & 0 deletions code/renderergl2/tr_bsp.c
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,7 @@ static void R_LoadLightmaps( lump_t *l, lump_t *surfs ) {
}


// If FatPackU() or FatPackV() changes, update FixFatLightmapTexCoords()
static float FatPackU(float input, int lightmapnum)
{
if (lightmapnum < 0)
Expand Down
6 changes: 5 additions & 1 deletion code/renderergl2/tr_fbo.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,13 @@ void FBO_CreateBuffer(FBO_t *fbo, int format, int index, int multisample)
}

absent = *pRenderBuffer == 0;
if (absent)
if (absent) {
qglGenRenderbuffers(1, pRenderBuffer);

// workaround AMD Windows driver requiring bind to create renderbuffer
GL_BindRenderbuffer(*pRenderBuffer);
}

if (multisample && glRefConfig.framebufferMultisample)
qglNamedRenderbufferStorageMultisampleEXT(*pRenderBuffer, multisample, format, fbo->width, fbo->height);
else
Expand Down
1 change: 0 additions & 1 deletion code/renderergl2/tr_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -1472,7 +1472,6 @@ typedef struct {

FBO_t *last2DFBO;
qboolean colorMask[4];
qboolean framePostProcessed;
qboolean depthFill;
} backEndState_t;

Expand Down
120 changes: 107 additions & 13 deletions code/renderergl2/tr_shader.c
Original file line number Diff line number Diff line change
Expand Up @@ -1841,12 +1841,17 @@ static qboolean ParseShader( char **text )
tr.sunShadowScale = atof(token);

// parse twice, since older shaders may include mapLightScale before sunShadowScale
token = COM_ParseExt( text, qfalse );
if (token[0])
tr.sunShadowScale = atof(token);
if (token[0]) {
token = COM_ParseExt( text, qfalse );
if (token[0]) {
tr.sunShadowScale = atof(token);
}
}
}

SkipRestOfLine( text );
if (token[0]) {
SkipRestOfLine( text );
}
continue;
}
// tonemap parms
Expand Down Expand Up @@ -2580,29 +2585,39 @@ static int CollapseStagesToGLSL(void)
numStages++;
}

// convert any remaining lightmap stages to a lighting pass with a white texture
// convert any remaining lightmap stages with no blending or blendfunc filter
// to a lighting pass with a white texture
// only do this with r_sunlightMode non-zero, as it's only for correct shadows.
if (r_sunlightMode->integer && shader.numDeforms == 0)
{
for (i = 0; i < MAX_SHADER_STAGES; i++)
{
shaderStage_t *pStage = &stages[i];
int blendBits;

if (!pStage->active)
continue;

if (pStage->adjustColorsForFog)
continue;

if (pStage->bundle[TB_DIFFUSEMAP].tcGen == TCGEN_LIGHTMAP)
{
pStage->glslShaderGroup = tr.lightallShader;
pStage->glslShaderIndex = LIGHTDEF_USE_LIGHTMAP;
pStage->bundle[TB_LIGHTMAP] = pStage->bundle[TB_DIFFUSEMAP];
pStage->bundle[TB_DIFFUSEMAP].image[0] = tr.whiteImage;
pStage->bundle[TB_DIFFUSEMAP].isLightmap = qfalse;
pStage->bundle[TB_DIFFUSEMAP].tcGen = TCGEN_TEXTURE;
if (pStage->bundle[TB_DIFFUSEMAP].tcGen != TCGEN_LIGHTMAP)
continue;

blendBits = pStage->stateBits & (GLS_DSTBLEND_BITS | GLS_SRCBLEND_BITS);

if (blendBits != 0 &&
blendBits != (GLS_DSTBLEND_SRC_COLOR | GLS_SRCBLEND_ZERO) &&
blendBits != (GLS_DSTBLEND_ZERO | GLS_SRCBLEND_DST_COLOR)) {
continue;
}

pStage->glslShaderGroup = tr.lightallShader;
pStage->glslShaderIndex = LIGHTDEF_USE_LIGHTMAP;
pStage->bundle[TB_LIGHTMAP] = pStage->bundle[TB_DIFFUSEMAP];
pStage->bundle[TB_DIFFUSEMAP].image[0] = tr.whiteImage;
pStage->bundle[TB_DIFFUSEMAP].isLightmap = qfalse;
pStage->bundle[TB_DIFFUSEMAP].tcGen = TCGEN_TEXTURE;
}
}

Expand Down Expand Up @@ -2890,6 +2905,83 @@ static void VertexLightingCollapse( void ) {
}
}

/*
=================
FixFatLightmapTexCoords
Handle edge cases of altering lightmap texcoords for fat lightmap atlas
=================
*/
static void FixFatLightmapTexCoords(void)
{
texModInfo_t *tmi;
int lightmapnum;
int stage;
int size;
int i;

if ( !r_mergeLightmaps->integer || tr.fatLightmapCols <= 0) {
return;
}

if ( shader.lightmapIndex < 0 ) {
// no internal lightmap, texcoords were not modified
return;
}

lightmapnum = shader.lightmapIndex;

if (tr.worldDeluxeMapping)
lightmapnum >>= 1;

lightmapnum %= (tr.fatLightmapCols * tr.fatLightmapRows);

for ( stage = 0; stage < MAX_SHADER_STAGES; stage++ ) {
shaderStage_t *pStage = &stages[stage];

if ( !pStage->active ) {
break;
}

// fix tcMod transform for internal lightmaps, it may be used by q3map2 lightstyles
if ( pStage->bundle[0].isLightmap ) {
for ( i = 0; i < pStage->bundle[0].numTexMods; i++ ) {
tmi = &pStage->bundle[0].texMods[i];

if ( tmi->type == TMOD_TRANSFORM ) {
tmi->translate[0] /= (float)tr.fatLightmapCols;
tmi->translate[1] /= (float)tr.fatLightmapRows;
}
}
}
// add a tcMod transform for external lightmaps to convert back to the original texcoords
else if ( pStage->bundle[0].tcGen == TCGEN_LIGHTMAP ) {
if ( pStage->bundle[0].numTexMods == TR_MAX_TEXMODS ) {
ri.Printf( PRINT_DEVELOPER, "WARNING: too many tcmods to fix external lightmap texcoords for r_mergeLightmaps in shader '%s'", shader.name );
} else {
size = pStage->bundle[0].numTexMods * sizeof( texModInfo_t );

if ( size ) {
memmove( &pStage->bundle[0].texMods[1], &pStage->bundle[0].texMods[0], size );
}

tmi = &pStage->bundle[0].texMods[0];
pStage->bundle[0].numTexMods++;

tmi->matrix[0][0] = tr.fatLightmapCols;
tmi->matrix[0][1] = 0;
tmi->matrix[1][0] = 0;
tmi->matrix[1][1] = tr.fatLightmapRows;

tmi->translate[0] = -(lightmapnum % tr.fatLightmapCols);
tmi->translate[1] = -(lightmapnum / tr.fatLightmapCols);

tmi->type = TMOD_TRANSFORM;
}
}
}
}

/*
===============
InitShader
Expand Down Expand Up @@ -3081,6 +3173,8 @@ static shader_t *FinishShader( void ) {
hasLightmapStage = qfalse;
}

FixFatLightmapTexCoords();

//
// look for multitexture potential
//
Expand Down
9 changes: 9 additions & 0 deletions code/sys/sys_unix.c
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,10 @@ void Sys_ListFilteredFiles( const char *basedir, char *subdirs, char *filter, ch
return;
}

if ( basedir[0] == '\0' ) {
return;
}

if (strlen(subdirs)) {
Com_sprintf( search, sizeof(search), "%s/%s", basedir, subdirs );
}
Expand Down Expand Up @@ -425,6 +429,11 @@ char **Sys_ListFiles( const char *directory, const char *extension, char *filter
return listCopy;
}

if ( directory[0] == '\0' ) {
*numfiles = 0;
return NULL;
}

if ( !extension)
extension = "";

Expand Down
9 changes: 9 additions & 0 deletions code/sys/sys_win32.c
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,10 @@ void Sys_ListFilteredFiles( const char *basedir, char *subdirs, char *filter, ch
return;
}

if ( basedir[0] == '\0' ) {
return;
}

if (strlen(subdirs)) {
Com_sprintf( search, sizeof(search), "%s\\%s\\*", basedir, subdirs );
}
Expand Down Expand Up @@ -584,6 +588,11 @@ char **Sys_ListFiles( const char *directory, const char *extension, char *filter
return listCopy;
}

if ( directory[0] == '\0' ) {
*numfiles = 0;
return NULL;
}

if ( !extension) {
extension = "";
}
Expand Down
Loading

0 comments on commit 75abcd4

Please sign in to comment.