Skip to content

Commit

Permalink
Port Elite Force renderer changes to OpenGL2
Browse files Browse the repository at this point in the history
Appling the diff to renderergl2 mostly worked.

Had to change GLimp_HaveExtension to use GL_EXTENTIONS
directly because Elite Forces GL2 requires an extension that didn't fit in (the smaller than Q3)
glConfig.extensions_string.

Had to set ambientLight for RF_FULLBRIGHT, GL2 doesn't use ambientLightInt.

Made the RF_FORCE_ENT_ALPHA code change pStage->stateBits because the stateBits
are read a lot, whereas in GL1 it's done as an expression and passed to GL_State.
Copied from Spearmint.

There are a few issues; holodeck doors are missing and parts of light grid are black (???).
  • Loading branch information
zturtleman committed Oct 29, 2014
1 parent c6e5f06 commit ccd93c1
Show file tree
Hide file tree
Showing 12 changed files with 779 additions and 17 deletions.
6 changes: 6 additions & 0 deletions code/renderergl2/tr_backend.c
Expand Up @@ -518,6 +518,12 @@ void RB_BeginDrawingView (void) {
if ( r_fastsky->integer && !( backEnd.refdef.rdflags & RDF_NOWORLDMODEL ) )
{
clearBits |= GL_COLOR_BUFFER_BIT; // FIXME: only if sky shaders have been used
#ifdef ELITEFORCE
if(r_origfastsky->integer)
qglClearColor(0.8f, 0.7f, 0.4f, 1.0f);
else
qglClearColor(0.0f, 0.0f, 0.0f, 1.0f);
#endif
}

// clear to black for cube maps
Expand Down
4 changes: 3 additions & 1 deletion code/renderergl2/tr_extensions.c
Expand Up @@ -186,7 +186,9 @@ GLboolean (APIENTRY * qglIsVertexArrayARB)(GLuint array);

static qboolean GLimp_HaveExtension(const char *ext)
{
const char *ptr = Q_stristr( glConfig.extensions_string, ext );
// ZTM: FIXME: not elite force specific
//const char *ptr = Q_stristr( glConfig.extensions_string, ext );
const char *ptr = Q_stristr( (char *) qglGetString (GL_EXTENSIONS), ext );
if (ptr == NULL)
return qfalse;
ptr += strlen(ext);
Expand Down
33 changes: 31 additions & 2 deletions code/renderergl2/tr_init.c
Expand Up @@ -69,6 +69,9 @@ cvar_t *r_measureOverdraw;

cvar_t *r_inGameVideo;
cvar_t *r_fastsky;
#ifdef ELITEFORCE
cvar_t *r_origfastsky;
#endif
cvar_t *r_drawSun;
cvar_t *r_dynamiclight;
cvar_t *r_dlightBacks;
Expand Down Expand Up @@ -270,6 +273,10 @@ static void InitOpenGL( void )
GLimp_Init();
GLimp_InitExtraExtensions();

#ifdef ELITEFORCE
glConfig.textureFilterAnisotropicAvailable = textureFilterAnisotropic;
#endif

strcpy( renderer_buffer, glConfig.renderer_string );
Q_strlwr( renderer_buffer );

Expand Down Expand Up @@ -1131,7 +1138,11 @@ void R_Register( void )
// latched and archived variables
//
r_allowExtensions = ri.Cvar_Get( "r_allowExtensions", "1", CVAR_ARCHIVE | CVAR_LATCH );
#ifdef ELITEFORCE
r_ext_compressed_textures = ri.Cvar_Get( "r_ext_compress_textures", "0", CVAR_ARCHIVE | CVAR_LATCH );
#else
r_ext_compressed_textures = ri.Cvar_Get( "r_ext_compressed_textures", "0", CVAR_ARCHIVE | CVAR_LATCH );
#endif
r_ext_multitexture = ri.Cvar_Get( "r_ext_multitexture", "1", CVAR_ARCHIVE | CVAR_LATCH );
r_ext_compiled_vertex_array = ri.Cvar_Get( "r_ext_compiled_vertex_array", "1", CVAR_ARCHIVE | CVAR_LATCH);
r_ext_texture_env_add = ri.Cvar_Get( "r_ext_texture_env_add", "1", CVAR_ARCHIVE | CVAR_LATCH);
Expand Down Expand Up @@ -1245,7 +1256,11 @@ void R_Register( void )
r_displayRefresh = ri.Cvar_Get( "r_displayRefresh", "0", CVAR_LATCH );
ri.Cvar_CheckRange( r_displayRefresh, 0, 200, qtrue );
r_fullbright = ri.Cvar_Get ("r_fullbright", "0", CVAR_LATCH|CVAR_CHEAT );
#ifdef ELITEFORCE
r_mapOverBrightBits = ri.Cvar_Get ("r_mapOverBrightBits", "1", CVAR_LATCH );
#else
r_mapOverBrightBits = ri.Cvar_Get ("r_mapOverBrightBits", "2", CVAR_LATCH );
#endif
r_intensity = ri.Cvar_Get ("r_intensity", "1", CVAR_LATCH );
r_singleShader = ri.Cvar_Get ("r_singleShader", "0", CVAR_CHEAT | CVAR_LATCH );

Expand All @@ -1261,6 +1276,9 @@ void R_Register( void )
r_stereoSeparation = ri.Cvar_Get( "r_stereoSeparation", "64", CVAR_ARCHIVE );
r_ignoreGLErrors = ri.Cvar_Get( "r_ignoreGLErrors", "1", CVAR_ARCHIVE );
r_fastsky = ri.Cvar_Get( "r_fastsky", "0", CVAR_ARCHIVE );
#ifdef ELITEFORCE
r_origfastsky = ri.Cvar_Get( "r_origfastsky", "0", CVAR_ARCHIVE );
#endif
r_inGameVideo = ri.Cvar_Get( "r_inGameVideo", "1", CVAR_ARCHIVE );
r_drawSun = ri.Cvar_Get( "r_drawSun", "0", CVAR_ARCHIVE );
r_dynamiclight = ri.Cvar_Get( "r_dynamiclight", "1", CVAR_ARCHIVE );
Expand Down Expand Up @@ -1385,8 +1403,15 @@ void R_Init( void ) {
Com_Memset( &backEnd, 0, sizeof( backEnd ) );
Com_Memset( &tess, 0, sizeof( tess ) );

#ifdef ELITEFORCE
if(sizeof(glconfig_t) != 5192)
{
ri.Error( ERR_FATAL, "Mod ABI incompatible: sizeof(glconfig_t) == %u != 5192", (unsigned int) sizeof(glconfig_t));
}
#else
if(sizeof(glconfig_t) != 11332)
ri.Error( ERR_FATAL, "Mod ABI incompatible: sizeof(glconfig_t) == %u != 11332", (unsigned int) sizeof(glconfig_t));
#endif

// Swap_Init();

Expand All @@ -1395,6 +1420,8 @@ void R_Init( void ) {
}
//Com_Memset( tess.constantColor255, 255, sizeof( tess.constantColor255 ) );

R_NoiseInit();

//
// init function tables
//
Expand All @@ -1404,6 +1431,7 @@ void R_Init( void ) {
tr.squareTable[i] = ( i < FUNCTABLE_SIZE/2 ) ? 1.0f : -1.0f;
tr.sawToothTable[i] = (float)i / FUNCTABLE_SIZE;
tr.inverseSawToothTable[i] = 1.0f - tr.sawToothTable[i];
tr.noiseTable[i] = R_NoiseGet4f(0, 0, 0, i);

if ( i < FUNCTABLE_SIZE / 2 )
{
Expand All @@ -1424,8 +1452,6 @@ void R_Init( void ) {

R_InitFogTable();

R_NoiseInit();

R_Register();

max_polys = r_maxpolys->integer;
Expand Down Expand Up @@ -1567,6 +1593,9 @@ refexport_t *GetRefAPI ( int apiVersion, refimport_t *rimp ) {
re.RegisterSkin = RE_RegisterSkin;
re.RegisterShader = RE_RegisterShader;
re.RegisterShaderNoMip = RE_RegisterShaderNoMip;
#ifdef ELITEFORCE
re.RegisterShader3D = RE_RegisterShader3D;
#endif
re.LoadWorld = RE_LoadWorldMap;
re.SetWorldVisData = RE_SetWorldVisData;
re.EndRegistration = RE_EndRegistration;
Expand Down
14 changes: 14 additions & 0 deletions code/renderergl2/tr_light.c
Expand Up @@ -334,6 +334,20 @@ void R_SetupEntityLighting( const trRefdef_t *refdef, trRefEntity_t *ent ) {
}
ent->lightingCalculated = qtrue;

#ifdef ELITEFORCE
if(ent->e.renderfx & RF_FULLBRIGHT)
{
ent->ambientLight[0] = ent->ambientLight[1] = ent->ambientLight[2] = 0x7F;
((byte *)&ent->ambientLightInt)[0] = 0x7F;
((byte *)&ent->ambientLightInt)[1] = 0x7F;
((byte *)&ent->ambientLightInt)[2] = 0x7F;
((byte *)&ent->ambientLightInt)[3] = 0xFF;

ent->lightDir[0] = ent->lightDir[1] = ent->lightDir[2] = 0;
return;
}
#endif

//
// trace a sample point down to find ambient light
//
Expand Down
12 changes: 6 additions & 6 deletions code/renderergl2/tr_local.h
Expand Up @@ -172,7 +172,8 @@ typedef enum {
GF_SAWTOOTH,
GF_INVERSE_SAWTOOTH,

GF_NOISE
GF_NOISE,
GF_RANDOM

} genFunc_t;

Expand Down Expand Up @@ -1348,11 +1349,6 @@ typedef struct {
int c_dlightSurfacesCulled;
} frontEndCounters_t;

#define FOG_TABLE_SIZE 256
#define FUNCTABLE_SIZE 1024
#define FUNCTABLE_SIZE2 10
#define FUNCTABLE_MASK (FUNCTABLE_SIZE-1)


// the renderer front end should never modify glstate_t
typedef struct {
Expand Down Expand Up @@ -1655,6 +1651,7 @@ typedef struct {
float triangleTable[FUNCTABLE_SIZE];
float sawToothTable[FUNCTABLE_SIZE];
float inverseSawToothTable[FUNCTABLE_SIZE];
float noiseTable[FUNCTABLE_SIZE];
float fogTable[FOG_TABLE_SIZE];
} trGlobals_t;

Expand Down Expand Up @@ -1690,6 +1687,9 @@ extern cvar_t *r_lodscale;

extern cvar_t *r_inGameVideo; // controls whether in game video should be draw
extern cvar_t *r_fastsky; // controls whether sky should be cleared or drawn
#ifdef ELITEFORCE
extern cvar_t *r_origfastsky; // controls whether fastsky color is like in original EF.
#endif
extern cvar_t *r_drawSun; // controls drawing of sun quad
extern cvar_t *r_dynamiclight; // dynamic lights enabled/disabled
extern cvar_t *r_dlightBacks; // dlight non-facing surfaces for continuity
Expand Down
23 changes: 21 additions & 2 deletions code/renderergl2/tr_main.c
Expand Up @@ -1674,18 +1674,25 @@ See if a sprite is inside a fog volume
int R_SpriteFogNum( trRefEntity_t *ent ) {
int i, j;
fog_t *fog;
float radius;

if ( tr.refdef.rdflags & RDF_NOWORLDMODEL ) {
return 0;
}

#ifdef ELITEFORCE
radius = ent->e.data.sprite.radius;
#else
radius = ent->e.radius;
#endif

for ( i = 1 ; i < tr.world->numfogs ; i++ ) {
fog = &tr.world->fogs[i];
for ( j = 0 ; j < 3 ; j++ ) {
if ( ent->e.origin[j] - ent->e.radius >= fog->bounds[1][j] ) {
if ( ent->e.origin[j] - radius >= fog->bounds[1][j] ) {
break;
}
if ( ent->e.origin[j] + ent->e.radius <= fog->bounds[0][j] ) {
if ( ent->e.origin[j] + radius <= fog->bounds[0][j] ) {
break;
}
}
Expand Down Expand Up @@ -1887,6 +1894,18 @@ static void R_AddEntitySurface (int entityNum)
switch ( ent->e.reType ) {
case RT_PORTALSURFACE:
break; // don't draw anything

#ifdef ELITEFORCE
case RT_ORIENTEDSPRITE:
case RT_ALPHAVERTPOLY:
case RT_LINE:
case RT_ORIENTEDLINE:
case RT_LINE2:
case RT_BEZIER:
case RT_CYLINDER:
case RT_ELECTRICITY:
#endif

case RT_SPRITE:
case RT_BEAM:
case RT_LIGHTNING:
Expand Down
2 changes: 2 additions & 0 deletions code/renderergl2/tr_scene.c
Expand Up @@ -286,7 +286,9 @@ void RE_AddAdditiveLightToScene( const vec3_t org, float intensity, float r, flo

void RE_BeginScene(const refdef_t *fd)
{
#ifndef ELITEFORCE
Com_Memcpy( tr.refdef.text, fd->text, sizeof( tr.refdef.text ) );
#endif

tr.refdef.x = fd->x;
tr.refdef.y = fd->y;
Expand Down
34 changes: 34 additions & 0 deletions code/renderergl2/tr_shade.c
Expand Up @@ -1062,6 +1062,11 @@ static unsigned int RB_CalcShaderVertexAttribs( shaderCommands_t *input )
static void RB_IterateStagesGeneric( shaderCommands_t *input )
{
int stage;
#ifdef ELITEFORCE
qboolean overridealpha = qfalse;
int oldAlphaGen = AGEN_IDENTITY;
int oldStateBits = 0;
#endif

vec4_t fogDistanceVector, fogDepthVector = {0, 0, 0, 0};
float eyeT = 0;
Expand All @@ -1085,6 +1090,27 @@ static void RB_IterateStagesGeneric( shaderCommands_t *input )
break;
}

#ifdef ELITEFORCE
// Override the shader alpha channel if requested.
if(backEnd.currentEntity->e.renderfx & RF_FORCE_ENT_ALPHA)
{
overridealpha = qtrue;
oldAlphaGen = pStage->alphaGen;
oldStateBits = pStage->stateBits;
pStage->alphaGen = AGEN_ENTITY;

// set bits for blendfunc blend
pStage->stateBits = GLS_SRCBLEND_SRC_ALPHA | GLS_DSTBLEND_ONE_MINUS_SRC_ALPHA;

// keep the original alphafunc, if any
pStage->stateBits |= ( oldStateBits & GLS_ATEST_BITS );
}
else
{
overridealpha = qfalse;
}
#endif

if (backEnd.depthFill)
{
if (pStage->glslShaderGroup == tr.lightallShader)
Expand Down Expand Up @@ -1404,6 +1430,14 @@ static void RB_IterateStagesGeneric( shaderCommands_t *input )
R_DrawElementsVao(input->numIndexes, input->firstIndex, input->minIndex, input->maxIndex);
}

#ifdef ELITEFORCE
if ( overridealpha )
{
pStage->alphaGen = oldAlphaGen;
pStage->stateBits = oldStateBits;
}
#endif

// allow skipping out to show just lightmaps during development
if ( r_lightmap->integer && ( pStage->bundle[0].isLightmap || pStage->bundle[1].isLightmap ) )
{
Expand Down
6 changes: 6 additions & 0 deletions code/renderergl2/tr_shade_calc.c
Expand Up @@ -43,6 +43,8 @@ static float *TableForFunc( genFunc_t func )
return tr.sawToothTable;
case GF_INVERSE_SAWTOOTH:
return tr.inverseSawToothTable;
case GF_NOISE:
return tr.noiseTable;
case GF_NONE:
default:
break;
Expand Down Expand Up @@ -589,7 +591,9 @@ void RB_DeformTessGeometry( void ) {
case DEFORM_TEXT5:
case DEFORM_TEXT6:
case DEFORM_TEXT7:
#ifndef ELITEFORCE
DeformText( backEnd.refdef.text[ds->deformation - DEFORM_TEXT0] );
#endif
break;
}
}
Expand All @@ -613,6 +617,8 @@ float RB_CalcWaveColorSingle( const waveForm_t *wf )

if ( wf->func == GF_NOISE ) {
glow = wf->base + R_NoiseGet4f( 0, 0, 0, ( tess.shaderTime + wf->phase ) * wf->frequency ) * wf->amplitude;
} else if( wf->func == GF_RANDOM ) {
glow = wf->base + R_RandomOn( (tess.shaderTime + wf->phase) * wf->frequency ) * wf->amplitude;
} else {
glow = EvalWaveForm( wf ) * tr.identityLight;
}
Expand Down

1 comment on commit ccd93c1

@zturtleman
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: light grid are black issue was due to light grid clamping in OpenGL2 and I fixed it in mainline ioq3 after this commit.

Please sign in to comment.