From 6f62f2806a5bae1816a11a3088298c0f2b0c1006 Mon Sep 17 00:00:00 2001 From: Zack Middleton Date: Sat, 2 Mar 2024 05:38:55 -0600 Subject: [PATCH] ioquake3 resync to commit f9547e45 from 93abc60a OpenGL2: Fix sun rays being affected by the viewport size OpenGL2: Fix merged lightmap hacks to have real lightmap index OpenGL2: Fix using merged lightmaps with tcGen environment OpenGL2: Fix hack for tcMod transform on merged lightmaps OpenGL2: Fix flares behind mirror being visible Fix running on Windows XP Fix GitHub Actions CI deprecation warnings OpenGL2: Don't mix drawing to default framebuffer and FBO --- .github/workflows/build.yml | 12 +-- engine/Makefile | 2 +- engine/code/renderergl2/tr_backend.c | 95 ++++++++++++------------ engine/code/renderergl2/tr_bsp.c | 6 +- engine/code/renderergl2/tr_fbo.c | 20 +++++ engine/code/renderergl2/tr_image.c | 2 +- engine/code/renderergl2/tr_local.h | 1 + engine/code/renderergl2/tr_postprocess.c | 6 +- engine/code/renderergl2/tr_postprocess.h | 2 +- engine/code/renderergl2/tr_shader.c | 57 +++++++++++--- engine/code/sys/sys_win32.c | 3 + 11 files changed, 131 insertions(+), 75 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4ffae171..05dd8736 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -6,7 +6,7 @@ jobs: name: Linux runs-on: ubuntu-20.04 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Install Dependencies run: | sudo apt-get update @@ -15,7 +15,7 @@ jobs: run: make release -C engine env: ARCHIVE: 1 - - uses: actions/upload-artifact@v3 + - uses: actions/upload-artifact@v4 with: name: Linux path: engine/build/*.zip @@ -23,14 +23,14 @@ jobs: name: Windows runs-on: windows-2019 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Compile run: | choco install zip make release -C engine env: ARCHIVE: 1 - - uses: actions/upload-artifact@v3 + - uses: actions/upload-artifact@v4 with: name: Windows path: engine/build/*.zip @@ -38,12 +38,12 @@ jobs: name: macOS runs-on: macos-11 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Compile run: make release -C engine env: ARCHIVE: 1 - - uses: actions/upload-artifact@v3 + - uses: actions/upload-artifact@v4 with: name: macOS path: engine/build/*.zip diff --git a/engine/Makefile b/engine/Makefile index 6316dfb0..15bb612c 100644 --- a/engine/Makefile +++ b/engine/Makefile @@ -48,7 +48,7 @@ ifndef BUILD_AUTOUPDATER # DON'T build unless you mean to! endif # ioquake3 git commit that this is based on -IOQ3_REVISION = 93abc60a +IOQ3_REVISION = f9547e45 ############################################################################# # diff --git a/engine/code/renderergl2/tr_backend.c b/engine/code/renderergl2/tr_backend.c index 7387101b..0cffa4ee 100644 --- a/engine/code/renderergl2/tr_backend.c +++ b/engine/code/renderergl2/tr_backend.c @@ -342,7 +342,7 @@ void RB_BeginDrawingView (void) { { FBO_t *fbo = backEnd.viewParms.targetFbo; - if (fbo == NULL && (!r_postProcess->integer || !(backEnd.refdef.rdflags & RDF_NOWORLDMODEL))) + if (fbo == NULL) fbo = tr.renderFbo; if (tr.renderCubeFbo && fbo == tr.renderCubeFbo) @@ -455,7 +455,7 @@ void RB_RenderDrawSurfList( drawSurf_t *drawSurfs, int numDrawSurfs ) { for (i = 0, drawSurf = drawSurfs ; i < numDrawSurfs ; i++, drawSurf++) { if ( drawSurf->sort == oldSort && drawSurf->cubemapIndex == oldCubemapIndex) { - if (backEnd.depthFill && shader && shader->sort != SS_OPAQUE) + if (backEnd.depthFill && shader && (shader->sort != SS_OPAQUE && shader->sort != SS_PORTAL)) continue; // fast path, same as previous sort @@ -484,7 +484,7 @@ void RB_RenderDrawSurfList( drawSurf_t *drawSurfs, int numDrawSurfs ) { oldCubemapIndex = cubemapIndex; } - if (backEnd.depthFill && shader && shader->sort != SS_OPAQUE) + if (backEnd.depthFill && shader && (shader->sort != SS_OPAQUE && shader->sort != SS_PORTAL)) continue; // @@ -708,7 +708,7 @@ void RE_StretchRaw (int x, int y, int w, int h, int cols, int rows, const byte * if (glRefConfig.framebufferObject) { - FBO_Bind(r_postProcess->integer ? NULL : tr.renderFbo); + FBO_Bind(tr.renderFbo); } RB_SetGL2D(); @@ -793,7 +793,7 @@ const void *RB_StretchPic ( const void *data ) { cmd = (const stretchPicCommand_t *)data; if (glRefConfig.framebufferObject) - FBO_Bind(r_postProcess->integer ? NULL : tr.renderFbo); + FBO_Bind(tr.renderFbo); RB_SetGL2D(); @@ -1202,15 +1202,12 @@ const void *RB_DrawBuffer( const void *data ) { // clear screen for debugging 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 ); } + + qglClearColor( 1, 0, 0.5, 1 ); + qglClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); } return (const void *)(cmd + 1); @@ -1381,18 +1378,15 @@ const void *RB_SwapBuffers( const void *data ) { if (glRefConfig.framebufferObject) { - if (!r_postProcess->integer) + if (tr.msaaResolveFbo && r_hdr->integer) { - if (tr.msaaResolveFbo && r_hdr->integer) - { - // Resolving an RGB16F MSAA FBO to the screen messes with the brightness, so resolve to an RGB16F FBO first - FBO_FastBlit(tr.renderFbo, NULL, tr.msaaResolveFbo, NULL, GL_COLOR_BUFFER_BIT, GL_NEAREST); - FBO_FastBlit(tr.msaaResolveFbo, NULL, NULL, NULL, GL_COLOR_BUFFER_BIT, GL_NEAREST); - } - else if (tr.renderFbo) - { - FBO_FastBlit(tr.renderFbo, NULL, NULL, NULL, GL_COLOR_BUFFER_BIT, GL_NEAREST); - } + // Resolving an RGB16F MSAA FBO to the screen messes with the brightness, so resolve to an RGB16F FBO first + FBO_FastBlit(tr.renderFbo, NULL, tr.msaaResolveFbo, NULL, GL_COLOR_BUFFER_BIT, GL_NEAREST); + FBO_FastBlit(tr.msaaResolveFbo, NULL, NULL, NULL, GL_COLOR_BUFFER_BIT, GL_NEAREST); + } + else if (tr.renderFbo) + { + FBO_FastBlit(tr.renderFbo, NULL, NULL, NULL, GL_COLOR_BUFFER_BIT, GL_NEAREST); } } @@ -1454,7 +1448,7 @@ RB_PostProcess const void *RB_PostProcess(const void *data) { const postProcessCommand_t *cmd = data; - FBO_t *srcFbo; + FBO_t *srcFbo, *dstFbo; ivec4_t srcBox, dstBox; qboolean autoExposure; @@ -1475,6 +1469,8 @@ const void *RB_PostProcess(const void *data) } srcFbo = tr.renderFbo; + dstFbo = tr.renderFbo; + if (tr.msaaResolveFbo) { // Resolve the MSAA before anything else @@ -1508,13 +1504,13 @@ const void *RB_PostProcess(const void *data) if (r_hdr->integer && (r_toneMap->integer || r_forceToneMap->integer)) { autoExposure = r_autoExposure->integer || r_forceAutoExposure->integer; - RB_ToneMap(srcFbo, srcBox, NULL, dstBox, autoExposure); + + // Use an intermediate FBO because it can't blit to the same FBO directly + // and can't read from an MSAA dstFbo later. + RB_ToneMap(srcFbo, srcBox, tr.screenScratchFbo, srcBox, autoExposure); + FBO_FastBlit(tr.screenScratchFbo, srcBox, srcFbo, srcBox, GL_COLOR_BUFFER_BIT, GL_NEAREST); } - else if (r_cameraExposure->value == 0.0f) - { - FBO_FastBlit(srcFbo, srcBox, NULL, dstBox, GL_COLOR_BUFFER_BIT, GL_NEAREST); - } - else + else if (r_cameraExposure->value != 0.0f) { vec4_t color; @@ -1523,17 +1519,20 @@ const void *RB_PostProcess(const void *data) color[2] = pow(2, r_cameraExposure->value); //exp2(r_cameraExposure->value); color[3] = 1.0f; - FBO_Blit(srcFbo, srcBox, NULL, NULL, dstBox, NULL, color, 0); + FBO_BlitFromTexture(tr.whiteImage, NULL, NULL, srcFbo, srcBox, NULL, color, GLS_SRCBLEND_DST_COLOR | GLS_DSTBLEND_ZERO); } } if (r_drawSunRays->integer) - RB_SunRays(NULL, srcBox, NULL, dstBox); + RB_SunRays(srcFbo, srcBox, srcFbo, srcBox); if (1) - RB_BokehBlur(NULL, srcBox, NULL, dstBox, backEnd.refdef.blurFactor); + RB_BokehBlur(srcFbo, srcBox, srcFbo, srcBox, backEnd.refdef.blurFactor); else - RB_GaussianBlur(backEnd.refdef.blurFactor); + RB_GaussianBlur(srcFbo, srcFbo, backEnd.refdef.blurFactor); + + if (srcFbo != dstFbo) + FBO_FastBlit(srcFbo, srcBox, dstFbo, dstBox, GL_COLOR_BUFFER_BIT, GL_NEAREST); #if 0 if (0) @@ -1549,7 +1548,7 @@ const void *RB_PostProcess(const void *data) if (scale < 0.01f) scale = 5.0f; - FBO_FastBlit(NULL, NULL, tr.quarterFbo[0], NULL, GL_COLOR_BUFFER_BIT, GL_LINEAR); + FBO_FastBlit(dstFbo, NULL, tr.quarterFbo[0], NULL, GL_COLOR_BUFFER_BIT, GL_LINEAR); iQtrBox[0] = backEnd.viewParms.viewportX * tr.quarterImage[0]->width / (float)glConfig.vidWidth; iQtrBox[1] = backEnd.viewParms.viewportY * tr.quarterImage[0]->height / (float)glConfig.vidHeight; @@ -1595,7 +1594,7 @@ const void *RB_PostProcess(const void *data) SetViewportAndScissor(); - FBO_FastBlit(tr.quarterFbo[1], NULL, NULL, NULL, GL_COLOR_BUFFER_BIT, GL_LINEAR); + FBO_FastBlit(tr.quarterFbo[1], NULL, dstFbo, NULL, GL_COLOR_BUFFER_BIT, GL_LINEAR); FBO_Bind(NULL); } #endif @@ -1604,42 +1603,42 @@ const void *RB_PostProcess(const void *data) { ivec4_t dstBox; VectorSet4(dstBox, 0, glConfig.vidHeight - 128, 128, 128); - FBO_BlitFromTexture(tr.sunShadowDepthImage[0], NULL, NULL, NULL, dstBox, NULL, NULL, 0); + FBO_BlitFromTexture(tr.sunShadowDepthImage[0], NULL, NULL, dstFbo, dstBox, NULL, NULL, 0); VectorSet4(dstBox, 128, glConfig.vidHeight - 128, 128, 128); - FBO_BlitFromTexture(tr.sunShadowDepthImage[1], NULL, NULL, NULL, dstBox, NULL, NULL, 0); + FBO_BlitFromTexture(tr.sunShadowDepthImage[1], NULL, NULL, dstFbo, dstBox, NULL, NULL, 0); VectorSet4(dstBox, 256, glConfig.vidHeight - 128, 128, 128); - FBO_BlitFromTexture(tr.sunShadowDepthImage[2], NULL, NULL, NULL, dstBox, NULL, NULL, 0); + FBO_BlitFromTexture(tr.sunShadowDepthImage[2], NULL, NULL, dstFbo, dstBox, NULL, NULL, 0); VectorSet4(dstBox, 384, glConfig.vidHeight - 128, 128, 128); - FBO_BlitFromTexture(tr.sunShadowDepthImage[3], NULL, NULL, NULL, dstBox, NULL, NULL, 0); + FBO_BlitFromTexture(tr.sunShadowDepthImage[3], NULL, NULL, dstFbo, dstBox, NULL, NULL, 0); } if (0 && r_shadows->integer == 4) { ivec4_t dstBox; VectorSet4(dstBox, 512 + 0, glConfig.vidHeight - 128, 128, 128); - FBO_BlitFromTexture(tr.pshadowMaps[0], NULL, NULL, NULL, dstBox, NULL, NULL, 0); + FBO_BlitFromTexture(tr.pshadowMaps[0], NULL, NULL, dstFbo, dstBox, NULL, NULL, 0); VectorSet4(dstBox, 512 + 128, glConfig.vidHeight - 128, 128, 128); - FBO_BlitFromTexture(tr.pshadowMaps[1], NULL, NULL, NULL, dstBox, NULL, NULL, 0); + FBO_BlitFromTexture(tr.pshadowMaps[1], NULL, NULL, dstFbo, dstBox, NULL, NULL, 0); VectorSet4(dstBox, 512 + 256, glConfig.vidHeight - 128, 128, 128); - FBO_BlitFromTexture(tr.pshadowMaps[2], NULL, NULL, NULL, dstBox, NULL, NULL, 0); + FBO_BlitFromTexture(tr.pshadowMaps[2], NULL, NULL, dstFbo, dstBox, NULL, NULL, 0); VectorSet4(dstBox, 512 + 384, glConfig.vidHeight - 128, 128, 128); - FBO_BlitFromTexture(tr.pshadowMaps[3], NULL, NULL, NULL, dstBox, NULL, NULL, 0); + FBO_BlitFromTexture(tr.pshadowMaps[3], NULL, NULL, dstFbo, dstBox, NULL, NULL, 0); } if (0) { ivec4_t dstBox; VectorSet4(dstBox, 256, glConfig.vidHeight - 256, 256, 256); - FBO_BlitFromTexture(tr.renderDepthImage, NULL, NULL, NULL, dstBox, NULL, NULL, 0); + FBO_BlitFromTexture(tr.renderDepthImage, NULL, NULL, dstFbo, dstBox, NULL, NULL, 0); VectorSet4(dstBox, 512, glConfig.vidHeight - 256, 256, 256); - FBO_BlitFromTexture(tr.screenShadowImage, NULL, NULL, NULL, dstBox, NULL, NULL, 0); + FBO_BlitFromTexture(tr.screenShadowImage, NULL, NULL, dstFbo, dstBox, NULL, NULL, 0); } if (0) { ivec4_t dstBox; VectorSet4(dstBox, 256, glConfig.vidHeight - 256, 256, 256); - FBO_BlitFromTexture(tr.sunRaysImage, NULL, NULL, NULL, dstBox, NULL, NULL, 0); + FBO_BlitFromTexture(tr.sunRaysImage, NULL, NULL, dstFbo, dstBox, NULL, NULL, 0); } #if 0 @@ -1651,8 +1650,8 @@ const void *RB_PostProcess(const void *data) if (cubemapIndex) { VectorSet4(dstBox, 0, glConfig.vidHeight - 256, 256, 256); - //FBO_BlitFromTexture(tr.renderCubeImage, NULL, NULL, NULL, dstBox, &tr.testcubeShader, NULL, 0); - FBO_BlitFromTexture(tr.cubemaps[cubemapIndex - 1].image, NULL, NULL, NULL, dstBox, &tr.testcubeShader, NULL, 0); + //FBO_BlitFromTexture(tr.renderCubeImage, NULL, NULL, dstFbo, dstBox, &tr.testcubeShader, NULL, 0); + FBO_BlitFromTexture(tr.cubemaps[cubemapIndex - 1].image, NULL, NULL, dstFbo, dstBox, &tr.testcubeShader, NULL, 0); } } #endif diff --git a/engine/code/renderergl2/tr_bsp.c b/engine/code/renderergl2/tr_bsp.c index b316351e..15f5f3cd 100644 --- a/engine/code/renderergl2/tr_bsp.c +++ b/engine/code/renderergl2/tr_bsp.c @@ -617,7 +617,7 @@ static shader_t *ShaderForShaderNum( int shaderNum, int lightmapNum ) { lightmapNum = LIGHTMAP_WHITEIMAGE; } - shader = R_FindShader( dsh->shader, lightmapNum, qtrue ); + shader = R_FindShaderEx( dsh->shader, FatLightmap( lightmapNum ), qtrue, lightmapNum ); // if the shader had errors, just use default shader if ( shader->defaultShader ) { @@ -706,7 +706,7 @@ static void ParseFace( dsurface_t *ds, drawVert_t *verts, float *hdrVertColors, surf->fogIndex = LittleLong( ds->fogNum ) + 1; // get shader value - surf->shader = ShaderForShaderNum( ds->shaderNum, FatLightmap(realLightmapNum) ); + surf->shader = ShaderForShaderNum( ds->shaderNum, realLightmapNum ); if ( r_singleShader->integer && !surf->shader->isSky ) { surf->shader = tr.defaultShader; } @@ -813,7 +813,7 @@ static void ParseMesh ( dsurface_t *ds, drawVert_t *verts, float *hdrVertColors, surf->fogIndex = LittleLong( ds->fogNum ) + 1; // get shader value - surf->shader = ShaderForShaderNum( ds->shaderNum, FatLightmap(realLightmapNum) ); + surf->shader = ShaderForShaderNum( ds->shaderNum, realLightmapNum ); if ( r_singleShader->integer && !surf->shader->isSky ) { surf->shader = tr.defaultShader; } diff --git a/engine/code/renderergl2/tr_fbo.c b/engine/code/renderergl2/tr_fbo.c index b0a9478f..223cbe7f 100644 --- a/engine/code/renderergl2/tr_fbo.c +++ b/engine/code/renderergl2/tr_fbo.c @@ -648,10 +648,30 @@ void FBO_FastBlit(FBO_t *src, ivec4_t srcBox, FBO_t *dst, ivec4_t dstBox, int bu int width = dst ? dst->width : glConfig.vidWidth; int height = dst ? dst->height : glConfig.vidHeight; + qglScissor(0, 0, width, height); + VectorSet4(dstBoxFinal, 0, 0, width, height); } else { + ivec4_t scissorBox; + + Vector4Copy(dstBox, scissorBox); + + if (scissorBox[2] < 0) + { + scissorBox[0] += scissorBox[2]; + scissorBox[2] = fabsf(scissorBox[2]); + } + + if (scissorBox[3] < 0) + { + scissorBox[1] += scissorBox[3]; + scissorBox[3] = fabsf(scissorBox[3]); + } + + qglScissor(scissorBox[0], scissorBox[1], scissorBox[2], scissorBox[3]); + VectorSet4(dstBoxFinal, dstBox[0], dstBox[1], dstBox[0] + dstBox[2], dstBox[1] + dstBox[3]); } diff --git a/engine/code/renderergl2/tr_image.c b/engine/code/renderergl2/tr_image.c index 09ceff08..101513b6 100644 --- a/engine/code/renderergl2/tr_image.c +++ b/engine/code/renderergl2/tr_image.c @@ -2766,7 +2766,7 @@ void R_CreateBuiltinImages( void ) { tr.renderImage = R_CreateImage("_render", NULL, width, height, IMGTYPE_COLORALPHA, IMGFLAG_NO_COMPRESSION | IMGFLAG_CLAMPTOEDGE, hdrFormat); - if (r_shadowBlur->integer) + if (r_shadowBlur->integer || r_hdr->integer) tr.screenScratchImage = R_CreateImage("screenScratch", NULL, width, height, IMGTYPE_COLORALPHA, IMGFLAG_NO_COMPRESSION | IMGFLAG_CLAMPTOEDGE, rgbFormat); if (r_shadowBlur->integer || r_ssao->integer) diff --git a/engine/code/renderergl2/tr_local.h b/engine/code/renderergl2/tr_local.h index 4ee61fde..6a0aa36f 100644 --- a/engine/code/renderergl2/tr_local.h +++ b/engine/code/renderergl2/tr_local.h @@ -1995,6 +1995,7 @@ const void *RB_TakeVideoFrameCmd( const void *data ); // tr_shader.c // shader_t *R_FindShader( const char *name, int lightmapIndex, qboolean mipRawImage ); +shader_t *R_FindShaderEx( const char *name, int lightmapIndex, qboolean mipRawImage, int realLightmapIndex ); shader_t *R_GetShaderByHandle( qhandle_t hShader ); shader_t *R_GetShaderByState( int index, long *cycleTime ); shader_t *R_FindShaderByName( const char *name ); diff --git a/engine/code/renderergl2/tr_postprocess.c b/engine/code/renderergl2/tr_postprocess.c index 9931757b..3d71f304 100644 --- a/engine/code/renderergl2/tr_postprocess.c +++ b/engine/code/renderergl2/tr_postprocess.c @@ -447,7 +447,7 @@ static void RB_VBlur(FBO_t *srcFbo, FBO_t *dstFbo, float strength) RB_BlurAxis(srcFbo, dstFbo, strength, qfalse); } -void RB_GaussianBlur(float blur) +void RB_GaussianBlur(FBO_t *srcFbo, FBO_t *dstFbo, float blur) { //float mul = 1.f; float factor = Com_Clamp(0.f, 1.f, blur); @@ -462,7 +462,7 @@ void RB_GaussianBlur(float blur) VectorSet4(color, 1, 1, 1, 1); // first, downsample the framebuffer - FBO_FastBlit(NULL, NULL, tr.quarterFbo[0], NULL, GL_COLOR_BUFFER_BIT, GL_LINEAR); + FBO_FastBlit(srcFbo, NULL, tr.quarterFbo[0], NULL, GL_COLOR_BUFFER_BIT, GL_LINEAR); FBO_FastBlit(tr.quarterFbo[0], NULL, tr.textureScratchFbo[0], NULL, GL_COLOR_BUFFER_BIT, GL_LINEAR); // set the alpha channel @@ -478,6 +478,6 @@ void RB_GaussianBlur(float blur) VectorSet4(srcBox, 0, 0, tr.textureScratchFbo[0]->width, tr.textureScratchFbo[0]->height); VectorSet4(dstBox, 0, 0, glConfig.vidWidth, glConfig.vidHeight); color[3] = factor; - FBO_Blit(tr.textureScratchFbo[0], srcBox, NULL, NULL, dstBox, NULL, color, GLS_SRCBLEND_SRC_ALPHA | GLS_DSTBLEND_ONE_MINUS_SRC_ALPHA); + FBO_Blit(tr.textureScratchFbo[0], srcBox, NULL, dstFbo, dstBox, NULL, color, GLS_SRCBLEND_SRC_ALPHA | GLS_DSTBLEND_ONE_MINUS_SRC_ALPHA); } } diff --git a/engine/code/renderergl2/tr_postprocess.h b/engine/code/renderergl2/tr_postprocess.h index 09daf134..a2d6d0b3 100644 --- a/engine/code/renderergl2/tr_postprocess.h +++ b/engine/code/renderergl2/tr_postprocess.h @@ -28,6 +28,6 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA void RB_ToneMap(FBO_t *hdrFbo, ivec4_t hdrBox, FBO_t *ldrFbo, ivec4_t ldrBox, int autoExposure); void RB_BokehBlur(FBO_t *src, ivec4_t srcBox, FBO_t *dst, ivec4_t dstBox, float blur); void RB_SunRays(FBO_t *srcFbo, ivec4_t srcBox, FBO_t *dstFbo, ivec4_t dstBox); -void RB_GaussianBlur(float blur); +void RB_GaussianBlur(FBO_t *srcFbo, FBO_t *dstFbo, float blur); #endif diff --git a/engine/code/renderergl2/tr_shader.c b/engine/code/renderergl2/tr_shader.c index 4b9fa991..b08a9328 100644 --- a/engine/code/renderergl2/tr_shader.c +++ b/engine/code/renderergl2/tr_shader.c @@ -30,6 +30,7 @@ static char *s_shaderText; static shaderStage_t stages[MAX_SHADER_STAGES]; static shader_t shader; static texModInfo_t texMods[MAX_SHADER_STAGES][TR_MAX_TEXMODS]; +static int shader_realLightmapIndex; #define FILE_HASH_SIZE 1024 static shader_t* hashTable[FILE_HASH_SIZE]; @@ -2929,7 +2930,7 @@ static void FixFatLightmapTexCoords(void) return; } - lightmapnum = shader.lightmapIndex; + lightmapnum = shader_realLightmapIndex; if (tr.worldDeluxeMapping) lightmapnum >>= 1; @@ -2943,21 +2944,44 @@ static void FixFatLightmapTexCoords(void) 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]; + // fix tcMod transform for internal lightmaps, it may be used by q3map2 lightstyles + if ( pStage->bundle[0].tcGen == TCGEN_LIGHTMAP ) { + 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; + if ( tmi->type == TMOD_TRANSFORM ) { + tmi->translate[0] /= (float)tr.fatLightmapCols; + tmi->translate[1] /= (float)tr.fatLightmapRows; + } + } + } + + // fix tcGen environment for internal lightmaps to be limited to the sub-image of the atlas + // this is done last so other tcMods are applied first in the 0.0 to 1.0 space + if ( pStage->bundle[0].tcGen == TCGEN_ENVIRONMENT_MAPPED ) { + if ( pStage->bundle[0].numTexMods == TR_MAX_TEXMODS ) { + ri.Printf( PRINT_DEVELOPER, "WARNING: too many tcmods to fix lightmap texcoords for r_mergeLightmaps in shader '%s'", shader.name ); + } else { + tmi = &pStage->bundle[0].texMods[pStage->bundle[0].numTexMods]; + pStage->bundle[0].numTexMods++; + + tmi->matrix[0][0] = 1.0f / tr.fatLightmapCols; + tmi->matrix[0][1] = 0; + tmi->matrix[1][0] = 0; + tmi->matrix[1][1] = 1.0f / tr.fatLightmapRows; + + tmi->translate[0] = ( lightmapnum % tr.fatLightmapCols ) / (float)tr.fatLightmapCols; + tmi->translate[1] = ( lightmapnum / tr.fatLightmapCols ) / (float)tr.fatLightmapRows; + + tmi->type = TMOD_TRANSFORM; } } } // 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 ); + ri.Printf( PRINT_DEVELOPER, "WARNING: too many tcmods to fix lightmap texcoords for r_mergeLightmaps in shader '%s'", shader.name ); } else { size = pStage->bundle[0].numTexMods * sizeof( texModInfo_t ); @@ -2973,8 +2997,8 @@ static void FixFatLightmapTexCoords(void) tmi->matrix[1][0] = 0; tmi->matrix[1][1] = tr.fatLightmapRows; - tmi->translate[0] = -(lightmapnum % tr.fatLightmapCols); - tmi->translate[1] = -(lightmapnum / tr.fatLightmapCols); + tmi->translate[0] = -( lightmapnum % tr.fatLightmapCols ); + tmi->translate[1] = -( lightmapnum / tr.fatLightmapCols ); tmi->type = TMOD_TRANSFORM; } @@ -2987,7 +3011,7 @@ static void FixFatLightmapTexCoords(void) InitShader =============== */ -static void InitShader( const char *name, int lightmapIndex ) { +static void InitShaderEx( const char *name, int lightmapIndex, int realLightmapIndex ) { int i; // clear the global shader @@ -2996,6 +3020,7 @@ static void InitShader( const char *name, int lightmapIndex ) { Q_strncpyz( shader.name, name, sizeof( shader.name ) ); shader.lightmapIndex = lightmapIndex; + shader_realLightmapIndex = realLightmapIndex; for ( i = 0 ; i < MAX_SHADER_STAGES ; i++ ) { stages[i].bundle[0].texMods = texMods[i]; @@ -3016,6 +3041,10 @@ static void InitShader( const char *name, int lightmapIndex ) { } } +static void InitShader( const char *name, int lightmapIndex ) { + InitShaderEx( name, lightmapIndex, lightmapIndex ); +} + /* ========================= FinishShader @@ -3337,6 +3366,10 @@ most world construction surfaces. =============== */ shader_t *R_FindShader( const char *name, int lightmapIndex, qboolean mipRawImage ) { + return R_FindShaderEx( name, lightmapIndex, mipRawImage, lightmapIndex ); +} + +shader_t *R_FindShaderEx( const char *name, int lightmapIndex, qboolean mipRawImage, int realLightmapIndex ) { char strippedName[MAX_QPATH]; int hash; char *shaderText; @@ -3376,7 +3409,7 @@ shader_t *R_FindShader( const char *name, int lightmapIndex, qboolean mipRawImag } } - InitShader( strippedName, lightmapIndex ); + InitShaderEx( strippedName, lightmapIndex, realLightmapIndex ); // // attempt to define shader from an explicit parameter file diff --git a/engine/code/sys/sys_win32.c b/engine/code/sys/sys_win32.c index d5e1c637..7d806a16 100644 --- a/engine/code/sys/sys_win32.c +++ b/engine/code/sys/sys_win32.c @@ -20,6 +20,9 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA =========================================================================== */ +// Use EnumProcesses() with Windows XP compatibility +#define PSAPI_VERSION 1 + #include "../qcommon/q_shared.h" #include "../qcommon/qcommon.h" #include "sys_local.h"