mirror of
https://github.com/Q3Rally-Team/q3rally.git
synced 2024-11-24 21:01:34 +00:00
ioquake3 resync to commit 5ede35d8 from 972635ea
OpenGL2: Fix q3map2 lightstyles effects OpenGL2: Fix parsing q3gl2_sun without two additional tokens Fix building QVMs on Linux with Windows line endings
This commit is contained in:
parent
d69613a527
commit
aa3deb6ed1
8 changed files with 181 additions and 16 deletions
|
@ -48,7 +48,7 @@ ifndef BUILD_AUTOUPDATER # DON'T build unless you mean to!
|
||||||
endif
|
endif
|
||||||
|
|
||||||
# ioquake3 git commit that this is based on
|
# ioquake3 git commit that this is based on
|
||||||
IOQ3_REVISION = 972635ea
|
IOQ3_REVISION = 5ede35d8
|
||||||
|
|
||||||
#############################################################################
|
#############################################################################
|
||||||
#
|
#
|
||||||
|
|
|
@ -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)
|
static float FatPackU(float input, int lightmapnum)
|
||||||
{
|
{
|
||||||
if (lightmapnum < 0)
|
if (lightmapnum < 0)
|
||||||
|
|
|
@ -1841,12 +1841,17 @@ static qboolean ParseShader( char **text )
|
||||||
tr.sunShadowScale = atof(token);
|
tr.sunShadowScale = atof(token);
|
||||||
|
|
||||||
// parse twice, since older shaders may include mapLightScale before sunShadowScale
|
// parse twice, since older shaders may include mapLightScale before sunShadowScale
|
||||||
token = COM_ParseExt( text, qfalse );
|
if (token[0]) {
|
||||||
if (token[0])
|
token = COM_ParseExt( text, qfalse );
|
||||||
tr.sunShadowScale = atof(token);
|
if (token[0]) {
|
||||||
|
tr.sunShadowScale = atof(token);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SkipRestOfLine( text );
|
if (token[0]) {
|
||||||
|
SkipRestOfLine( text );
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// tonemap parms
|
// tonemap parms
|
||||||
|
@ -2580,13 +2585,15 @@ static int CollapseStagesToGLSL(void)
|
||||||
numStages++;
|
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.
|
// only do this with r_sunlightMode non-zero, as it's only for correct shadows.
|
||||||
if (r_sunlightMode->integer && shader.numDeforms == 0)
|
if (r_sunlightMode->integer && shader.numDeforms == 0)
|
||||||
{
|
{
|
||||||
for (i = 0; i < MAX_SHADER_STAGES; i++)
|
for (i = 0; i < MAX_SHADER_STAGES; i++)
|
||||||
{
|
{
|
||||||
shaderStage_t *pStage = &stages[i];
|
shaderStage_t *pStage = &stages[i];
|
||||||
|
int blendBits;
|
||||||
|
|
||||||
if (!pStage->active)
|
if (!pStage->active)
|
||||||
continue;
|
continue;
|
||||||
|
@ -2594,15 +2601,23 @@ static int CollapseStagesToGLSL(void)
|
||||||
if (pStage->adjustColorsForFog)
|
if (pStage->adjustColorsForFog)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (pStage->bundle[TB_DIFFUSEMAP].tcGen == TCGEN_LIGHTMAP)
|
if (pStage->bundle[TB_DIFFUSEMAP].tcGen != TCGEN_LIGHTMAP)
|
||||||
{
|
continue;
|
||||||
pStage->glslShaderGroup = tr.lightallShader;
|
|
||||||
pStage->glslShaderIndex = LIGHTDEF_USE_LIGHTMAP;
|
blendBits = pStage->stateBits & (GLS_DSTBLEND_BITS | GLS_SRCBLEND_BITS);
|
||||||
pStage->bundle[TB_LIGHTMAP] = pStage->bundle[TB_DIFFUSEMAP];
|
|
||||||
pStage->bundle[TB_DIFFUSEMAP].image[0] = tr.whiteImage;
|
if (blendBits != 0 &&
|
||||||
pStage->bundle[TB_DIFFUSEMAP].isLightmap = qfalse;
|
blendBits != (GLS_DSTBLEND_SRC_COLOR | GLS_SRCBLEND_ZERO) &&
|
||||||
pStage->bundle[TB_DIFFUSEMAP].tcGen = TCGEN_TEXTURE;
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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
|
InitShader
|
||||||
|
@ -3081,6 +3173,8 @@ static shader_t *FinishShader( void ) {
|
||||||
hasLightmapStage = qfalse;
|
hasLightmapStage = qfalse;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FixFatLightmapTexCoords();
|
||||||
|
|
||||||
//
|
//
|
||||||
// look for multitexture potential
|
// look for multitexture potential
|
||||||
//
|
//
|
||||||
|
|
|
@ -511,6 +511,25 @@ foldline(Source *s)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This doesn't have proper tracking across read() to only remove \r from \r\n sequence.
|
||||||
|
// The lexer doesn't correctly handle standalone \r anyway though.
|
||||||
|
int
|
||||||
|
crlf_to_lf(unsigned char *buf, int n) {
|
||||||
|
int i, count;
|
||||||
|
|
||||||
|
count = 0;
|
||||||
|
|
||||||
|
for (i = 0; i < n; i++) {
|
||||||
|
if (buf[i] == '\r') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
buf[count++] = buf[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
fillbuf(Source *s)
|
fillbuf(Source *s)
|
||||||
{
|
{
|
||||||
|
@ -521,6 +540,7 @@ fillbuf(Source *s)
|
||||||
error(FATAL, "Input buffer overflow");
|
error(FATAL, "Input buffer overflow");
|
||||||
if (s->fd<0 || (n=read(s->fd, (char *)s->inl, INS/8)) <= 0)
|
if (s->fd<0 || (n=read(s->fd, (char *)s->inl, INS/8)) <= 0)
|
||||||
n = 0;
|
n = 0;
|
||||||
|
n = crlf_to_lf(s->inl, n);
|
||||||
if ((*s->inp&0xff) == EOB) /* sentinel character appears in input */
|
if ((*s->inp&0xff) == EOB) /* sentinel character appears in input */
|
||||||
*s->inp = EOFC;
|
*s->inp = EOFC;
|
||||||
s->inl += n;
|
s->inl += n;
|
||||||
|
|
|
@ -65,6 +65,9 @@ setup(int argc, char **argv)
|
||||||
fp = (char*)newstring((uchar*)argv[optind], strlen(argv[optind]), 0);
|
fp = (char*)newstring((uchar*)argv[optind], strlen(argv[optind]), 0);
|
||||||
if ((fd = open(fp, 0)) <= 0)
|
if ((fd = open(fp, 0)) <= 0)
|
||||||
error(FATAL, "Can't open input file %s", fp);
|
error(FATAL, "Can't open input file %s", fp);
|
||||||
|
#ifdef WIN32
|
||||||
|
_setmode(fd, _O_BINARY);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
if (optind+1<argc) {
|
if (optind+1<argc) {
|
||||||
int fdo;
|
int fdo;
|
||||||
|
@ -75,6 +78,9 @@ setup(int argc, char **argv)
|
||||||
#endif
|
#endif
|
||||||
if (fdo<0)
|
if (fdo<0)
|
||||||
error(FATAL, "Can't open output file %s", argv[optind+1]);
|
error(FATAL, "Can't open output file %s", argv[optind+1]);
|
||||||
|
#ifdef WIN32
|
||||||
|
_setmode(fdo, _O_BINARY);
|
||||||
|
#endif
|
||||||
dup2(fdo, 1);
|
dup2(fdo, 1);
|
||||||
}
|
}
|
||||||
if(Mflag)
|
if(Mflag)
|
||||||
|
|
|
@ -1553,12 +1553,32 @@ static char buf[BUFSIZ], *bp = buf;
|
||||||
static int ppercent = 0;
|
static int ppercent = 0;
|
||||||
static int code = 0;
|
static int code = 0;
|
||||||
|
|
||||||
|
static void crlf_to_lf(char *buf, int bufmax) {
|
||||||
|
int i, count;
|
||||||
|
|
||||||
|
count = 0;
|
||||||
|
|
||||||
|
for (i = 0; i < bufmax; i++) {
|
||||||
|
if (buf[i] == '\r' && buf[i+1] == '\n') {
|
||||||
|
// skip '\r'
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
buf[count++] = buf[i];
|
||||||
|
|
||||||
|
if (buf[i] == '\0') {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static int get(void) {
|
static int get(void) {
|
||||||
if (*bp == 0) {
|
if (*bp == 0) {
|
||||||
bp = buf;
|
bp = buf;
|
||||||
*bp = 0;
|
*bp = 0;
|
||||||
if (fgets(buf, sizeof buf, infp) == NULL)
|
if (fgets(buf, sizeof buf, infp) == NULL)
|
||||||
return EOF;
|
return EOF;
|
||||||
|
crlf_to_lf(buf, sizeof buf);
|
||||||
yylineno++;
|
yylineno++;
|
||||||
while (buf[0] == '%' && buf[1] == '{' && buf[2] == '\n') {
|
while (buf[0] == '%' && buf[1] == '{' && buf[2] == '\n') {
|
||||||
for (;;) {
|
for (;;) {
|
||||||
|
@ -1566,6 +1586,7 @@ static int get(void) {
|
||||||
yywarn("unterminated %{...%}\n");
|
yywarn("unterminated %{...%}\n");
|
||||||
return EOF;
|
return EOF;
|
||||||
}
|
}
|
||||||
|
crlf_to_lf(buf, sizeof buf);
|
||||||
yylineno++;
|
yylineno++;
|
||||||
if (strcmp(buf, "%}\n") == 0)
|
if (strcmp(buf, "%}\n") == 0)
|
||||||
break;
|
break;
|
||||||
|
@ -1573,6 +1594,7 @@ static int get(void) {
|
||||||
}
|
}
|
||||||
if (fgets(buf, sizeof buf, infp) == NULL)
|
if (fgets(buf, sizeof buf, infp) == NULL)
|
||||||
return EOF;
|
return EOF;
|
||||||
|
crlf_to_lf(buf, sizeof buf);
|
||||||
yylineno++;
|
yylineno++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,12 +70,32 @@ static char buf[BUFSIZ], *bp = buf;
|
||||||
static int ppercent = 0;
|
static int ppercent = 0;
|
||||||
static int code = 0;
|
static int code = 0;
|
||||||
|
|
||||||
|
static void crlf_to_lf(char *buf, int bufmax) {
|
||||||
|
int i, count;
|
||||||
|
|
||||||
|
count = 0;
|
||||||
|
|
||||||
|
for (i = 0; i < bufmax; i++) {
|
||||||
|
if (buf[i] == '\r' && buf[i+1] == '\n') {
|
||||||
|
// skip '\r'
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
buf[count++] = buf[i];
|
||||||
|
|
||||||
|
if (buf[i] == '\0') {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static int get(void) {
|
static int get(void) {
|
||||||
if (*bp == 0) {
|
if (*bp == 0) {
|
||||||
bp = buf;
|
bp = buf;
|
||||||
*bp = 0;
|
*bp = 0;
|
||||||
if (fgets(buf, sizeof buf, infp) == NULL)
|
if (fgets(buf, sizeof buf, infp) == NULL)
|
||||||
return EOF;
|
return EOF;
|
||||||
|
crlf_to_lf(buf, sizeof buf);
|
||||||
yylineno++;
|
yylineno++;
|
||||||
while (buf[0] == '%' && buf[1] == '{' && buf[2] == '\n') {
|
while (buf[0] == '%' && buf[1] == '{' && buf[2] == '\n') {
|
||||||
for (;;) {
|
for (;;) {
|
||||||
|
@ -83,6 +103,7 @@ static int get(void) {
|
||||||
yywarn("unterminated %{...%}\n");
|
yywarn("unterminated %{...%}\n");
|
||||||
return EOF;
|
return EOF;
|
||||||
}
|
}
|
||||||
|
crlf_to_lf(buf, sizeof buf);
|
||||||
yylineno++;
|
yylineno++;
|
||||||
if (strcmp(buf, "%}\n") == 0)
|
if (strcmp(buf, "%}\n") == 0)
|
||||||
break;
|
break;
|
||||||
|
@ -90,6 +111,7 @@ static int get(void) {
|
||||||
}
|
}
|
||||||
if (fgets(buf, sizeof buf, infp) == NULL)
|
if (fgets(buf, sizeof buf, infp) == NULL)
|
||||||
return EOF;
|
return EOF;
|
||||||
|
crlf_to_lf(buf, sizeof buf);
|
||||||
yylineno++;
|
yylineno++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,14 +56,14 @@ int main(int argc, char *argv[]) {
|
||||||
} else if (infp == NULL) {
|
} else if (infp == NULL) {
|
||||||
if (strcmp(argv[i], "-") == 0)
|
if (strcmp(argv[i], "-") == 0)
|
||||||
infp = stdin;
|
infp = stdin;
|
||||||
else if ((infp = fopen(argv[i], "r")) == NULL) {
|
else if ((infp = fopen(argv[i], "rb")) == NULL) {
|
||||||
yyerror("%s: can't read `%s'\n", argv[0], argv[i]);
|
yyerror("%s: can't read `%s'\n", argv[0], argv[i]);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
} else if (outfp == NULL) {
|
} else if (outfp == NULL) {
|
||||||
if (strcmp(argv[i], "-") == 0)
|
if (strcmp(argv[i], "-") == 0)
|
||||||
outfp = stdout;
|
outfp = stdout;
|
||||||
if ((outfp = fopen(argv[i], "w")) == NULL) {
|
if ((outfp = fopen(argv[i], "wb")) == NULL) {
|
||||||
yyerror("%s: can't write `%s'\n", argv[0], argv[i]);
|
yyerror("%s: can't write `%s'\n", argv[0], argv[i]);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue