mirror of
https://github.com/FWGS/xash3d-fwgs.git
synced 2026-08-05 03:24:56 +08:00
ref: gl: refactor variable declarations
This commit is contained in:
@@ -216,14 +216,12 @@ static char *GL_PrintInfoLog( GLhandleARB object, qboolean program )
|
||||
|
||||
static GLuint GL2_GenerateShader( gl2wrap_prog_t *prog, GLenum type )
|
||||
{
|
||||
char *shader, shader_buf[MAX_SHADERLEN + 1];
|
||||
char shader_buf[MAX_SHADERLEN + 1];
|
||||
char tmp[256];
|
||||
int i;
|
||||
GLint status, len;
|
||||
GLuint id, loc;
|
||||
int version = gl2wrap_config.version;
|
||||
GLint status;
|
||||
const int version = gl2wrap_config.version;
|
||||
|
||||
shader = shader_buf;
|
||||
char *shader = shader_buf;
|
||||
//shader[0] = '\n';
|
||||
shader[0] = 0;
|
||||
|
||||
@@ -232,7 +230,7 @@ static GLuint GL2_GenerateShader( gl2wrap_prog_t *prog, GLenum type )
|
||||
Q_snprintf( tmp, sizeof( tmp ), "#define VER %d\n", version );
|
||||
Q_strncat( shader, tmp, MAX_SHADERLEN );
|
||||
|
||||
for( i = 0; i < GL2_FLAG_MAX; ++i )
|
||||
for( int i = 0; i < GL2_FLAG_MAX; ++i )
|
||||
{
|
||||
Q_snprintf( tmp, sizeof( tmp ), "#define %s %d\n", gl2wrap_flag_name[i], FBitSet( prog->flags, BIT( i )));
|
||||
Q_strncat( shader, tmp, MAX_SHADERLEN );
|
||||
@@ -240,8 +238,8 @@ static GLuint GL2_GenerateShader( gl2wrap_prog_t *prog, GLenum type )
|
||||
|
||||
if( version >= 310 )
|
||||
{
|
||||
loc = 0;
|
||||
for( i = 0; i < GL2_ATTR_MAX; ++i )
|
||||
GLuint loc = 0;
|
||||
for( int i = 0; i < GL2_ATTR_MAX; ++i )
|
||||
{
|
||||
if( FBitSet( prog->flags, BIT( i )))
|
||||
{
|
||||
@@ -262,8 +260,8 @@ static GLuint GL2_GenerateShader( gl2wrap_prog_t *prog, GLenum type )
|
||||
else
|
||||
Q_strncat( shader, gl2wrap_vert_src, MAX_SHADERLEN );
|
||||
|
||||
id = pglCreateShaderObjectARB( type );
|
||||
len = Q_strlen( shader );
|
||||
GLuint id = pglCreateShaderObjectARB( type );
|
||||
GLint len = Q_strlen( shader );
|
||||
pglShaderSourceARB( id, 1, (void *)&shader, &len );
|
||||
pglCompileShaderARB( id );
|
||||
pglGetObjectParameterivARB( id, GL_OBJECT_COMPILE_STATUS_ARB, &status );
|
||||
@@ -282,9 +280,8 @@ static GLuint GL2_GenerateShader( gl2wrap_prog_t *prog, GLenum type )
|
||||
|
||||
static gl2wrap_prog_t *GL2_GetProg( const GLuint flags )
|
||||
{
|
||||
int i, loc;
|
||||
GLuint status = 0, vp, fp, glprog;
|
||||
gl2wrap_prog_t *prog;
|
||||
int i;
|
||||
GLuint status = 0;
|
||||
|
||||
// try to find existing prog matching this feature set
|
||||
|
||||
@@ -308,22 +305,22 @@ static gl2wrap_prog_t *GL2_GetProg( const GLuint flags )
|
||||
// new prog; generate shaders
|
||||
|
||||
gEngfuncs.Con_DPrintf( S_NOTE "%s: Generating progs for 0x%04x\n", __func__, flags );
|
||||
prog = &gl2wrap.progs[i];
|
||||
gl2wrap_prog_t *prog = &gl2wrap.progs[i];
|
||||
prog->flags = flags;
|
||||
|
||||
vp = GL2_GenerateShader( prog, GL_VERTEX_SHADER_ARB );
|
||||
fp = GL2_GenerateShader( prog, GL_FRAGMENT_SHADER_ARB );
|
||||
GLuint vp = GL2_GenerateShader( prog, GL_VERTEX_SHADER_ARB );
|
||||
GLuint fp = GL2_GenerateShader( prog, GL_FRAGMENT_SHADER_ARB );
|
||||
if( !vp || !fp )
|
||||
{
|
||||
prog->flags = 0;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
glprog = pglCreateProgramObjectARB();
|
||||
GLuint glprog = pglCreateProgramObjectARB();
|
||||
pglAttachObjectARB( glprog, vp );
|
||||
pglAttachObjectARB( glprog, fp );
|
||||
|
||||
loc = 0;
|
||||
int loc = 0;
|
||||
for( i = 0; i < GL2_ATTR_MAX; ++i )
|
||||
{
|
||||
if( FBitSet( flags, BIT( i )))
|
||||
@@ -383,9 +380,7 @@ static gl2wrap_prog_t *GL2_GetProg( const GLuint flags )
|
||||
{
|
||||
if( gl2wrap_config.vao_mandatory || gl2wrap_config.incremental )
|
||||
{
|
||||
int j;
|
||||
|
||||
for( j = 0; j < gl2wrap_config.cycle_buffers; j++ )
|
||||
for( int j = 0; j < gl2wrap_config.cycle_buffers; j++ )
|
||||
{
|
||||
pglBindVertexArray( prog->vao_begin[j] );
|
||||
pglEnableVertexAttribArrayARB( prog->attridx[i] );
|
||||
@@ -449,13 +444,11 @@ static gl2wrap_prog_t *GL2_SetProg( const GLuint flags )
|
||||
|
||||
static void GL2_InitTriQuads( void )
|
||||
{
|
||||
int i;
|
||||
for( i = 0; i < ( !!pglDrawRangeElementsBaseVertex ? 1 : 4 ); i++ )
|
||||
for( int i = 0; i < ( !!pglDrawRangeElementsBaseVertex ? 1 : 4 ); i++ )
|
||||
{
|
||||
int j;
|
||||
GLushort triquads_array[TRIQUADS_SIZE];
|
||||
|
||||
for( j = 0; j < TRIQUADS_SIZE / 6; j++ )
|
||||
for( int j = 0; j < TRIQUADS_SIZE / 6; j++ )
|
||||
{
|
||||
triquads_array[j * 6] = j * 4 + i;
|
||||
triquads_array[j * 6 + 1] = j * 4 + 1 + i;
|
||||
@@ -474,19 +467,17 @@ static void GL2_InitTriQuads( void )
|
||||
|
||||
static void GL2_InitIncrementalBuffer( int i, GLuint size )
|
||||
{
|
||||
int j;
|
||||
|
||||
gl2wrap.attrbufobj[i] = Mem_Calloc( r_temppool, gl2wrap_config.cycle_buffers * sizeof( GLuint ));
|
||||
if( gl2wrap_config.buf_storage )
|
||||
gl2wrap.mappings[i] = Mem_Calloc( r_temppool, gl2wrap_config.cycle_buffers * sizeof( void * ));
|
||||
pglGenBuffersARB( gl2wrap_config.cycle_buffers, gl2wrap.attrbufobj[i] );
|
||||
|
||||
for( j = 0; j < gl2wrap_config.cycle_buffers; j++ )
|
||||
for( int j = 0; j < gl2wrap_config.cycle_buffers; j++ )
|
||||
{
|
||||
rpglBindBufferARB( GL_ARRAY_BUFFER_ARB, gl2wrap.attrbufobj[i][j] );
|
||||
if( gl2wrap_config.buf_storage )
|
||||
{
|
||||
GLuint flags = GL_MAP_WRITE_BIT | MB( !gl2wrap_config.coherent, FLUSH_EXPLICIT ) |
|
||||
const GLuint flags = GL_MAP_WRITE_BIT | MB( !gl2wrap_config.coherent, FLUSH_EXPLICIT ) |
|
||||
GL_MAP_PERSISTENT_BIT | MB( gl2wrap_config.coherent, COHERENT );
|
||||
pglBufferStorage( GL_ARRAY_BUFFER_ARB, size, NULL, GL_MAP_WRITE_BIT | MB( gl2wrap_config.coherent, COHERENT ) | GL_MAP_PERSISTENT_BIT );
|
||||
gl2wrap.mappings[i][j] = pglMapBufferRange( GL_ARRAY_BUFFER_ARB, 0, size, flags );
|
||||
@@ -512,10 +503,9 @@ static qboolean GL2_InitProgs( void )
|
||||
BIT( GL2_ATTR_POS ) | BIT( GL2_ATTR_TEXCOORD0 ) | BIT( GL2_FLAG_ALPHA_TEST ) | BIT( GL2_FLAG_FOG ), // out = tex0 * ucolor + FEAT_ALPHA_TEST + FEAT_FOG
|
||||
};
|
||||
const size_t precache_progs_count = sizeof( precache_progs ) / sizeof( precache_progs[0] );
|
||||
int i;
|
||||
|
||||
gEngfuncs.Con_DPrintf( S_NOTE "GL2_InitProgs: Pre-generating %u progs, version %d...\n", (uint)( precache_progs_count ), gl2wrap_config.version );
|
||||
for( i = 0; i < (int)( precache_progs_count ); ++i )
|
||||
for( int i = 0; i < (int)( precache_progs_count ); ++i )
|
||||
if( !GL2_GetProg( precache_progs[i] ))
|
||||
return false;
|
||||
return true;
|
||||
@@ -524,7 +514,6 @@ static qboolean GL2_InitProgs( void )
|
||||
|
||||
int GL2_ShimInit( void )
|
||||
{
|
||||
int i;
|
||||
GLuint total;
|
||||
|
||||
if( gl2wrap_init )
|
||||
@@ -612,7 +601,7 @@ int GL2_ShimInit( void )
|
||||
|
||||
total = 0;
|
||||
|
||||
for( i = 0; i < GL2_ATTR_MAX; ++i )
|
||||
for( int i = 0; i < GL2_ATTR_MAX; ++i )
|
||||
{
|
||||
GLuint size = GL2_MAX_VERTS * gl2wrap_attr_size[i] * sizeof( GLfloat );
|
||||
if( !gl2wrap_config.buf_storage )
|
||||
@@ -632,9 +621,7 @@ int GL2_ShimInit( void )
|
||||
pglGenBuffersARB( gl2wrap_config.cycle_buffers, gl2wrap.attrbufobj[i] );
|
||||
if( gl2wrap_config.supports_mapbuffer )
|
||||
{
|
||||
int j;
|
||||
|
||||
for( j = 0; j < gl2wrap_config.cycle_buffers; j++ )
|
||||
for( int j = 0; j < gl2wrap_config.cycle_buffers; j++ )
|
||||
{
|
||||
rpglBindBufferARB( GL_ARRAY_BUFFER_ARB, gl2wrap.attrbufobj[i][j] );
|
||||
pglBufferDataARB( GL_ARRAY_BUFFER_ARB, MAX_BEGINEND_VERTS, NULL, GL_STREAM_DRAW_ARB );
|
||||
@@ -672,8 +659,6 @@ int GL2_ShimInit( void )
|
||||
|
||||
void GL2_ShimShutdown( void )
|
||||
{
|
||||
int i;
|
||||
|
||||
if( !gl2wrap_init )
|
||||
return;
|
||||
|
||||
@@ -682,7 +667,7 @@ void GL2_ShimShutdown( void )
|
||||
GL2_FreeArrays();
|
||||
pglDeleteBuffersARB(( !!pglDrawRangeElementsBaseVertex ? 1 : 4 ), gl2wrap.triquads_ibo );
|
||||
|
||||
for( i = 0; i < MAX_PROGS; ++i )
|
||||
for( int i = 0; i < MAX_PROGS; ++i )
|
||||
{
|
||||
if( gl2wrap.progs[i].flags )
|
||||
{
|
||||
@@ -696,12 +681,11 @@ void GL2_ShimShutdown( void )
|
||||
|
||||
}
|
||||
|
||||
for( i = 0; i < GL2_ATTR_MAX; ++i )
|
||||
for( int i = 0; i < GL2_ATTR_MAX; ++i )
|
||||
{
|
||||
int j;
|
||||
if( gl2wrap_config.buf_storage )
|
||||
{
|
||||
for( j = 0; j < gl2wrap_config.cycle_buffers; j++ )
|
||||
for( int j = 0; j < gl2wrap_config.cycle_buffers; j++ )
|
||||
{
|
||||
pglBindBufferARB( GL_ARRAY_BUFFER_ARB, gl2wrap.attrbufobj[i][j] );
|
||||
pglUnmapBufferARB( GL_ARRAY_BUFFER_ARB );
|
||||
@@ -726,8 +710,6 @@ void GL2_ShimShutdown( void )
|
||||
|
||||
static void GL2_ResetPersistentBuffer( void )
|
||||
{
|
||||
int i;
|
||||
|
||||
#ifdef QUAD_BATCH
|
||||
GL2_FlushPrims();
|
||||
#endif
|
||||
@@ -736,13 +718,13 @@ static void GL2_ResetPersistentBuffer( void )
|
||||
if( gl2wrap_config.incremental )
|
||||
{
|
||||
gl2wrap.attrbufcycle = ( gl2wrap.attrbufcycle + 1 ) % gl2wrap_config.cycle_buffers;
|
||||
for( i = 0; i < GL2_ATTR_MAX; ++i )
|
||||
for( int i = 0; i < GL2_ATTR_MAX; ++i )
|
||||
{
|
||||
int size = GL2_MAX_VERTS * gl2wrap_attr_size[i] * sizeof( GLfloat );
|
||||
const int size = GL2_MAX_VERTS * gl2wrap_attr_size[i] * sizeof( GLfloat );
|
||||
rpglBindBufferARB( GL_ARRAY_BUFFER_ARB, gl2wrap.attrbufobj[i][gl2wrap.attrbufcycle] );
|
||||
if( gl2wrap_config.buf_storage )
|
||||
{
|
||||
GLuint flags = GL_MAP_WRITE_BIT | MB( !gl2wrap_config.coherent, FLUSH_EXPLICIT ) |
|
||||
const GLuint flags = GL_MAP_WRITE_BIT | MB( !gl2wrap_config.coherent, FLUSH_EXPLICIT ) |
|
||||
GL_MAP_PERSISTENT_BIT | MB( gl2wrap_config.coherent, COHERENT );
|
||||
pglUnmapBufferARB( GL_ARRAY_BUFFER_ARB );
|
||||
gl2wrap.mappings[i][gl2wrap.attrbufcycle] = pglMapBufferRange( GL_ARRAY_BUFFER_ARB, 0, size, flags );
|
||||
@@ -802,19 +784,17 @@ When buffer storage not supported, we still may use cached VAO, but map/unmap it
|
||||
*/
|
||||
static void GL2_UpdateIncrementalBuffer( gl2wrap_prog_t *prog, int count )
|
||||
{
|
||||
int i;
|
||||
if( !gl2wrap_config.buf_storage )
|
||||
{
|
||||
for( i = 0; i < GL2_ATTR_MAX; i++ )
|
||||
for( int i = 0; i < GL2_ATTR_MAX; i++ )
|
||||
{
|
||||
if( prog->attridx[i] >= 0 )
|
||||
{
|
||||
void *mem;
|
||||
GLuint flags = GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_RANGE_BIT |
|
||||
const GLuint flags = GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_RANGE_BIT |
|
||||
MB( gl2wrap_config.async, UNSYNCHRONIZED ) |
|
||||
MB( gl2wrap_config.force_flush, FLUSH_EXPLICIT );
|
||||
rpglBindBufferARB( GL_ARRAY_BUFFER_ARB, gl2wrap.attrbufobj[i][gl2wrap.attrbufcycle] );
|
||||
mem = pglMapBufferRange( GL_ARRAY_BUFFER_ARB, gl2wrap_attr_size[i] * 4 * gl2wrap.begin, gl2wrap_attr_size[i] * 4 * count, flags );
|
||||
void *mem = pglMapBufferRange( GL_ARRAY_BUFFER_ARB, gl2wrap_attr_size[i] * 4 * gl2wrap.begin, gl2wrap_attr_size[i] * 4 * count, flags );
|
||||
memcpy( mem, gl2wrap.attrbuf[i] + gl2wrap_attr_size[i] * gl2wrap.begin, gl2wrap_attr_size[i] * 4 * count );
|
||||
if( gl2wrap_config.force_flush )
|
||||
pglFlushMappedBufferRange( GL_ARRAY_BUFFER_ARB, 0, gl2wrap_attr_size[i] * 4 * count );
|
||||
@@ -825,7 +805,7 @@ static void GL2_UpdateIncrementalBuffer( gl2wrap_prog_t *prog, int count )
|
||||
else if( !gl2wrap_config.coherent )
|
||||
{
|
||||
// non-coherent buffers anyway require unmapping or flushing after write
|
||||
for( i = 0; i < GL2_ATTR_MAX; i++ )
|
||||
for( int i = 0; i < GL2_ATTR_MAX; i++ )
|
||||
{
|
||||
if( prog->attridx[i] >= 0 )
|
||||
{
|
||||
@@ -838,10 +818,9 @@ static void GL2_UpdateIncrementalBuffer( gl2wrap_prog_t *prog, int count )
|
||||
|
||||
static void GL2_FlushPrims( void )
|
||||
{
|
||||
int i;
|
||||
int startindex = 0;
|
||||
GLuint flags = gl2wrap.cur_flags;
|
||||
GLint count = gl2wrap.end - gl2wrap.begin;
|
||||
const GLint count = gl2wrap.end - gl2wrap.begin;
|
||||
gl2wrap_prog_t *prog;
|
||||
|
||||
if( !gl2wrap.prim || !count )
|
||||
@@ -856,7 +835,7 @@ static void GL2_FlushPrims( void )
|
||||
// disable all vertex attrib pointers
|
||||
if( !gl2wrap_config.vao_mandatory )
|
||||
{
|
||||
for( i = 0; i < GL2_ATTR_MAX; ++i )
|
||||
for( int i = 0; i < GL2_ATTR_MAX; ++i )
|
||||
pglDisableVertexAttribArrayARB( i );
|
||||
}
|
||||
|
||||
@@ -877,7 +856,7 @@ static void GL2_FlushPrims( void )
|
||||
{
|
||||
if( gl2wrap_config.vao_mandatory )
|
||||
pglBindVertexArray( prog->vao_begin[gl2wrap.attrbufcycle] );
|
||||
for( i = 0; i < GL2_ATTR_MAX; ++i )
|
||||
for( int i = 0; i < GL2_ATTR_MAX; ++i )
|
||||
{
|
||||
if( prog->attridx[i] >= 0 )
|
||||
{
|
||||
@@ -1006,12 +985,13 @@ static void APIENTRY GL2_TexImage2D( GLenum target, GLint level, GLint internalf
|
||||
internalformat == GL_LUMINANCE8 ||
|
||||
internalformat == GL_LUMINANCE4 )) // strip alpha from texture
|
||||
{
|
||||
unsigned char *in = data, *out;
|
||||
int i = 0, size = width * height * 4;
|
||||
unsigned char *in = data;
|
||||
const int size = width * height * 4;
|
||||
unsigned char *out = (unsigned char *)malloc( size );
|
||||
|
||||
data = out = (unsigned char *)malloc( size );
|
||||
data = out;
|
||||
|
||||
for( i = 0; i < size; i += 4, in += 4, out += 4 )
|
||||
for( int i = 0; i < size; i += 4, in += 4, out += 4 )
|
||||
{
|
||||
memcpy( out, in, 3 );
|
||||
out[3] = 255;
|
||||
@@ -1450,7 +1430,7 @@ static void GL2_UpdatePersistentArrayBuffer( gl2wrap_prog_t *prog, int size, int
|
||||
{
|
||||
if( gl2wrap_arrays.stream_counter + size > GL2_MAX_VERTS * 64 )
|
||||
{
|
||||
GLuint flags = GL_MAP_WRITE_BIT | MB( !gl2wrap_config.coherent, FLUSH_EXPLICIT ) |
|
||||
const GLuint flags = GL_MAP_WRITE_BIT | MB( !gl2wrap_config.coherent, FLUSH_EXPLICIT ) |
|
||||
GL_MAP_PERSISTENT_BIT | MB( gl2wrap_config.coherent, COHERENT );
|
||||
pglUnmapBufferARB( GL_ARRAY_BUFFER_ARB );
|
||||
gl2wrap_arrays.stream_counter = 0;
|
||||
@@ -1476,9 +1456,8 @@ Like persistent buffer, but map every time when copying data when BufferStorage
|
||||
*/
|
||||
static void GL2_UpdateIncrementalArrayBuffer( gl2wrap_prog_t *prog, int size, int offset, GLuint start, GLuint end, int stride, int attr )
|
||||
{
|
||||
void *mem;
|
||||
qboolean inv = false;
|
||||
GLuint flags = GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_RANGE_BIT | MB( inv,INVALIDATE_BUFFER ) |
|
||||
const GLuint flags = GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_RANGE_BIT | MB( inv,INVALIDATE_BUFFER ) |
|
||||
MB( gl2wrap_config.async, UNSYNCHRONIZED ) | MB( gl2wrap_config.force_flush, FLUSH_EXPLICIT );
|
||||
|
||||
if( gl2wrap_arrays.stream_counter + size > GL2_MAX_VERTS * 64 )
|
||||
@@ -1488,7 +1467,7 @@ static void GL2_UpdateIncrementalArrayBuffer( gl2wrap_prog_t *prog, int size, in
|
||||
gl2wrap_arrays.stream_counter = 0;
|
||||
inv = true;
|
||||
}
|
||||
mem = pglMapBufferRange( GL_ARRAY_BUFFER_ARB, gl2wrap_arrays.stream_counter, size, flags );
|
||||
void *mem = pglMapBufferRange( GL_ARRAY_BUFFER_ARB, gl2wrap_arrays.stream_counter, size, flags );
|
||||
memcpy( mem, ((char *)gl2wrap_arrays.ptr[attr].userptr ) + offset, size );
|
||||
if( gl2wrap_config.force_flush )
|
||||
pglFlushMappedBufferRange( GL_ARRAY_BUFFER_ARB, 0, size );
|
||||
@@ -1506,7 +1485,7 @@ Prepare BufferStorage
|
||||
*/
|
||||
static void GL2_AllocArrayPersistenStorage( void )
|
||||
{
|
||||
GLuint flags = GL_MAP_WRITE_BIT | MB( !gl2wrap_config.coherent, FLUSH_EXPLICIT ) |
|
||||
const GLuint flags = GL_MAP_WRITE_BIT | MB( !gl2wrap_config.coherent, FLUSH_EXPLICIT ) |
|
||||
GL_MAP_PERSISTENT_BIT | MB( gl2wrap_config.coherent, COHERENT );
|
||||
pglGenBuffersARB( 1, &gl2wrap_arrays.stream_buffer );
|
||||
rpglBindBufferARB( GL_ARRAY_BUFFER_ARB, gl2wrap_arrays.stream_buffer );
|
||||
@@ -1552,9 +1531,7 @@ Usage of client pointers is forbidden with non-default VAO and unavailiable in C
|
||||
*/
|
||||
static void GL2_SetupArrays( GLuint start, GLuint end )
|
||||
{
|
||||
gl2wrap_prog_t *prog;
|
||||
unsigned int flags = gl2wrap_arrays.flags;
|
||||
int i;
|
||||
|
||||
if( !flags )
|
||||
return; // Legacy pointers not used
|
||||
@@ -1567,7 +1544,7 @@ static void GL2_SetupArrays( GLuint start, GLuint end )
|
||||
SetBits( flags, BIT( GL2_FLAG_ALPHA_TEST ));
|
||||
if( gl2wrap_state.fog )
|
||||
SetBits( flags, BIT( GL2_FLAG_FOG ));
|
||||
prog = GL2_SetProg( flags );// | GL2_ATTR_TEXCOORD0 );
|
||||
gl2wrap_prog_t *prog = GL2_SetProg( flags );// | GL2_ATTR_TEXCOORD0 );
|
||||
if( !prog )
|
||||
return;
|
||||
|
||||
@@ -1578,7 +1555,7 @@ static void GL2_SetupArrays( GLuint start, GLuint end )
|
||||
pglBindVertexArray( gl2wrap_arrays.vao_dynamic );
|
||||
}
|
||||
|
||||
for( i = 0; i < GL2_ATTR_MAX; i++ )
|
||||
for( int i = 0; i < GL2_ATTR_MAX; i++ )
|
||||
{
|
||||
if( prog->attridx[i] < 0 )
|
||||
continue;
|
||||
@@ -1590,7 +1567,7 @@ static void GL2_SetupArrays( GLuint start, GLuint end )
|
||||
if( gl2wrap_config.vao_mandatory && !gl2wrap_arrays.ptr[i].vbo )
|
||||
{
|
||||
// detect stride by type
|
||||
int stride = gl2wrap_arrays.ptr[i].stride, size, offset;
|
||||
int stride = gl2wrap_arrays.ptr[i].stride;
|
||||
|
||||
if( stride == 0 )
|
||||
{
|
||||
@@ -1610,8 +1587,8 @@ static void GL2_SetupArrays( GLuint start, GLuint end )
|
||||
gEngfuncs.Con_Printf( S_ERROR "NON-vbo array for DrawElements call, SKIPPING!\n" );
|
||||
continue;
|
||||
}
|
||||
size = ( end - start ) * stride;
|
||||
offset = start * stride;
|
||||
int size = ( end - start ) * stride;
|
||||
int offset = start * stride;
|
||||
|
||||
// Logical buffer start can lie before real buffer start
|
||||
// but attrib pointer cannot have negative buffer offset
|
||||
|
||||
@@ -86,12 +86,9 @@ StripLength
|
||||
*/
|
||||
static int StripLength( int starttri, int startv )
|
||||
{
|
||||
int m1, m2, j, k;
|
||||
dtriangle_t *last, *check;
|
||||
|
||||
g_used[starttri] = 2;
|
||||
|
||||
last = &g_triangles[starttri];
|
||||
dtriangle_t *last = &g_triangles[starttri];
|
||||
|
||||
g_stripverts[0] = last->vertindex[(startv+0) % 3];
|
||||
g_stripverts[1] = last->vertindex[(startv+1) % 3];
|
||||
@@ -100,8 +97,10 @@ static int StripLength( int starttri, int startv )
|
||||
g_striptris[0] = starttri;
|
||||
g_stripcount = 1;
|
||||
|
||||
m1 = last->vertindex[(startv+2)%3];
|
||||
m2 = last->vertindex[(startv+1)%3];
|
||||
int m1 = last->vertindex[(startv+2)%3];
|
||||
int m2 = last->vertindex[(startv+1)%3];
|
||||
int j;
|
||||
dtriangle_t *check;
|
||||
nexttri:
|
||||
// look for a matching triangle
|
||||
for( j = starttri + 1, check = &g_triangles[starttri + 1]; j < m_pAliasHeader->numtris; j++, check++ )
|
||||
@@ -109,7 +108,7 @@ nexttri:
|
||||
if( check->facesfront != last->facesfront )
|
||||
continue;
|
||||
|
||||
for( k = 0; k < 3; k++ )
|
||||
for( int k = 0; k < 3; k++ )
|
||||
{
|
||||
if( check->vertindex[k] != m1 )
|
||||
continue;
|
||||
@@ -152,12 +151,9 @@ FanLength
|
||||
*/
|
||||
static int FanLength( int starttri, int startv )
|
||||
{
|
||||
int m1, m2, j, k;
|
||||
dtriangle_t *last, *check;
|
||||
|
||||
g_used[starttri] = 2;
|
||||
|
||||
last = &g_triangles[starttri];
|
||||
dtriangle_t *last = &g_triangles[starttri];
|
||||
|
||||
g_stripverts[0] = last->vertindex[(startv+0) % 3];
|
||||
g_stripverts[1] = last->vertindex[(startv+1) % 3];
|
||||
@@ -166,8 +162,10 @@ static int FanLength( int starttri, int startv )
|
||||
g_striptris[0] = starttri;
|
||||
g_stripcount = 1;
|
||||
|
||||
m1 = last->vertindex[(startv+0) % 3];
|
||||
m2 = last->vertindex[(startv+2) % 3];
|
||||
int m1 = last->vertindex[(startv+0) % 3];
|
||||
int m2 = last->vertindex[(startv+2) % 3];
|
||||
int j;
|
||||
dtriangle_t *check;
|
||||
|
||||
nexttri:
|
||||
// look for a matching triangle
|
||||
@@ -176,7 +174,7 @@ nexttri:
|
||||
if( check->facesfront != last->facesfront )
|
||||
continue;
|
||||
|
||||
for( k = 0; k < 3; k++ )
|
||||
for( int k = 0; k < 3; k++ )
|
||||
{
|
||||
if( check->vertindex[k] != m1 )
|
||||
continue;
|
||||
@@ -219,12 +217,8 @@ for the model, which holds for all frames
|
||||
*/
|
||||
static void BuildTris( void )
|
||||
{
|
||||
int len, bestlen, besttype = 0;
|
||||
int bestverts[1024];
|
||||
int besttris[1024];
|
||||
int type, startv;
|
||||
int i, j, k;
|
||||
float s, t;
|
||||
int bestverts[1024];
|
||||
int besttris[1024];
|
||||
|
||||
//
|
||||
// build tristrips
|
||||
@@ -233,16 +227,18 @@ static void BuildTris( void )
|
||||
g_numcommands = 0;
|
||||
g_numorder = 0;
|
||||
|
||||
for( i = 0; i < m_pAliasHeader->numtris; i++ )
|
||||
for( int i = 0; i < m_pAliasHeader->numtris; i++ )
|
||||
{
|
||||
// pick an unused triangle and start the trifan
|
||||
if( g_used[i] ) continue;
|
||||
|
||||
bestlen = 0;
|
||||
for( type = 0; type < 2; type++ )
|
||||
int bestlen = 0;
|
||||
int besttype = 0;
|
||||
for( int type = 0; type < 2; type++ )
|
||||
{
|
||||
for( startv = 0; startv < 3; startv++ )
|
||||
for( int startv = 0; startv < 3; startv++ )
|
||||
{
|
||||
int len;
|
||||
if( type == 1 ) len = StripLength( i, startv );
|
||||
else len = FanLength( i, startv );
|
||||
|
||||
@@ -251,32 +247,32 @@ static void BuildTris( void )
|
||||
besttype = type;
|
||||
bestlen = len;
|
||||
|
||||
for( j = 0; j < bestlen + 2; j++ )
|
||||
for( int j = 0; j < bestlen + 2; j++ )
|
||||
bestverts[j] = g_stripverts[j];
|
||||
|
||||
for( j = 0; j < bestlen; j++ )
|
||||
for( int j = 0; j < bestlen; j++ )
|
||||
besttris[j] = g_striptris[j];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// mark the tris on the best strip as used
|
||||
for( j = 0; j < bestlen; j++ )
|
||||
for( int j = 0; j < bestlen; j++ )
|
||||
g_used[besttris[j]] = 1;
|
||||
|
||||
if( besttype == 1 )
|
||||
g_commands[g_numcommands++] = (bestlen + 2);
|
||||
else g_commands[g_numcommands++] = -(bestlen + 2);
|
||||
|
||||
for( j = 0; j < bestlen + 2; j++ )
|
||||
for( int j = 0; j < bestlen + 2; j++ )
|
||||
{
|
||||
// emit a vertex into the reorder buffer
|
||||
k = bestverts[j];
|
||||
int k = bestverts[j];
|
||||
g_vertexorder[g_numorder++] = k;
|
||||
|
||||
// emit s/t coords into the commands stream
|
||||
s = g_stverts[k].s;
|
||||
t = g_stverts[k].t;
|
||||
float s = g_stverts[k].s;
|
||||
float t = g_stverts[k].t;
|
||||
|
||||
if( !g_triangles[besttris[0]].facesfront && g_stverts[k].onseam )
|
||||
s += m_pAliasHeader->skinwidth / 2; // on back side
|
||||
@@ -299,9 +295,6 @@ GL_MakeAliasModelDisplayLists
|
||||
*/
|
||||
static void GL_MakeAliasModelDisplayLists( model_t *m )
|
||||
{
|
||||
trivertex_t *verts;
|
||||
int i, j;
|
||||
|
||||
BuildTris( );
|
||||
|
||||
// save the data out
|
||||
@@ -311,11 +304,11 @@ static void GL_MakeAliasModelDisplayLists( model_t *m )
|
||||
memcpy( m_pAliasHeader->commands, g_commands, g_numcommands * 4 );
|
||||
|
||||
m_pAliasHeader->posedata = Mem_Malloc( m->mempool, m_pAliasHeader->numposes * m_pAliasHeader->poseverts * sizeof( trivertex_t ));
|
||||
verts = m_pAliasHeader->posedata;
|
||||
trivertex_t *verts = m_pAliasHeader->posedata;
|
||||
|
||||
for( i = 0; i < m_pAliasHeader->numposes; i++ )
|
||||
for( int i = 0; i < m_pAliasHeader->numposes; i++ )
|
||||
{
|
||||
for( j = 0; j < g_numorder; j++ )
|
||||
for( int j = 0; j < g_numorder; j++ )
|
||||
*verts++ = m_pAliasHeader->pposeverts[i][g_vertexorder[j]];
|
||||
}
|
||||
}
|
||||
@@ -336,8 +329,7 @@ Mod_CreateSkinData
|
||||
*/
|
||||
static rgbdata_t *Mod_CreateSkinData( model_t *mod, const byte *data, int width, int height )
|
||||
{
|
||||
static rgbdata_t skin;
|
||||
int i;
|
||||
static rgbdata_t skin;
|
||||
|
||||
skin.width = width;
|
||||
skin.height = height;
|
||||
@@ -352,7 +344,7 @@ static rgbdata_t *Mod_CreateSkinData( model_t *mod, const byte *data, int width,
|
||||
|
||||
if( !gEngfuncs.Image_CustomPalette() )
|
||||
{
|
||||
for( i = 0; i < skin.width * skin.height; i++ )
|
||||
for( int i = 0; i < skin.width * skin.height; i++ )
|
||||
{
|
||||
if( data[i] > 224 && data[i] != 255 )
|
||||
{
|
||||
@@ -365,13 +357,10 @@ static rgbdata_t *Mod_CreateSkinData( model_t *mod, const byte *data, int width,
|
||||
// for alias models only player can have remap textures
|
||||
if( mod != NULL && !Q_stricmp( mod->name, "player" ))
|
||||
{
|
||||
texture_t *tx = NULL;
|
||||
int i, size;
|
||||
|
||||
i = mod->numtextures;
|
||||
int i = mod->numtextures;
|
||||
mod->textures = (texture_t **)Mem_Realloc( mod->mempool, mod->textures, ( i + 1 ) * sizeof( texture_t* ));
|
||||
size = width * height + 768;
|
||||
tx = Mem_Calloc( mod->mempool, sizeof( *tx ) + size );
|
||||
int size = width * height + 768;
|
||||
texture_t *tx = Mem_Calloc( mod->mempool, sizeof( *tx ) + size );
|
||||
mod->textures[i] = tx;
|
||||
|
||||
Q_strncpy( tx->name, "DM_Skin", sizeof( tx->name ));
|
||||
@@ -396,11 +385,12 @@ static rgbdata_t *Mod_CreateSkinData( model_t *mod, const byte *data, int width,
|
||||
static const void *Mod_LoadSingleSkin( model_t *loadmodel, const daliasskintype_t *pskintype, int skinnum, int size )
|
||||
{
|
||||
const byte *ptexture = (const byte *)&pskintype[1];
|
||||
rgbdata_t *pic;
|
||||
string name, lumaname, checkname;
|
||||
|
||||
string name, checkname;
|
||||
Q_snprintf( name, sizeof( name ), "%s:frame%i", loadmodel->name, skinnum );
|
||||
Q_snprintf( checkname, sizeof( checkname ), "%s_%i.tga", loadmodel->name, skinnum );
|
||||
|
||||
rgbdata_t *pic;
|
||||
if( !gEngfuncs.fsapi->FileExists( checkname, false ) || ( pic = gEngfuncs.FS_LoadImage( checkname, NULL, 0 )) == NULL )
|
||||
pic = Mod_CreateSkinData( loadmodel, ptexture, m_pAliasHeader->skinwidth, m_pAliasHeader->skinheight );
|
||||
|
||||
@@ -412,6 +402,7 @@ static const void *Mod_LoadSingleSkin( model_t *loadmodel, const daliasskintype_
|
||||
|
||||
if( FBitSet( R_GetTexture( m_pAliasHeader->gl_texturenum[skinnum][0] )->flags, TF_HAS_LUMA ))
|
||||
{
|
||||
string lumaname;
|
||||
Q_snprintf( lumaname, sizeof( lumaname ), "%s:luma%i", loadmodel->name, skinnum );
|
||||
|
||||
pic = Mod_CreateSkinData( NULL, ptexture, m_pAliasHeader->skinwidth, m_pAliasHeader->skinheight );
|
||||
@@ -427,27 +418,23 @@ static const void *Mod_LoadSingleSkin( model_t *loadmodel, const daliasskintype_
|
||||
|
||||
static const void *Mod_LoadGroupSkin( model_t *loadmodel, const daliasskintype_t *pskintype, int skinnum, int size )
|
||||
{
|
||||
const daliasskininterval_t *pinskinintervals;
|
||||
const daliasskingroup_t *pinskingroup;
|
||||
const byte *ptexture;
|
||||
rgbdata_t *pic;
|
||||
string name, lumaname;
|
||||
int i, j;
|
||||
|
||||
// animating skin group. yuck.
|
||||
pinskingroup = (const daliasskingroup_t *)&pskintype[1];
|
||||
pinskinintervals = (const daliasskininterval_t *)(&pinskingroup[1]);
|
||||
ptexture = (const byte *)&pinskinintervals[pinskingroup->numskins];
|
||||
const daliasskingroup_t *pinskingroup = (const daliasskingroup_t *)&pskintype[1];
|
||||
const daliasskininterval_t *pinskinintervals = (const daliasskininterval_t *)(&pinskingroup[1]);
|
||||
const byte *ptexture = (const byte *)&pinskinintervals[pinskingroup->numskins];
|
||||
|
||||
int i;
|
||||
for( i = 0; i < pinskingroup->numskins; i++ )
|
||||
{
|
||||
string name;
|
||||
Q_snprintf( name, sizeof( name ), "%s_%i_%i", loadmodel->name, skinnum, i );
|
||||
pic = Mod_CreateSkinData( loadmodel, ptexture, m_pAliasHeader->skinwidth, m_pAliasHeader->skinheight );
|
||||
rgbdata_t *pic = Mod_CreateSkinData( loadmodel, ptexture, m_pAliasHeader->skinwidth, m_pAliasHeader->skinheight );
|
||||
m_pAliasHeader->gl_texturenum[skinnum][i & 3] = GL_LoadTextureInternal( name, pic, 0 );
|
||||
gEngfuncs.FS_FreeImage( pic );
|
||||
|
||||
if( FBitSet( R_GetTexture( m_pAliasHeader->gl_texturenum[skinnum][i & 3] )->flags, TF_HAS_LUMA ))
|
||||
{
|
||||
string lumaname;
|
||||
Q_snprintf( lumaname, sizeof( lumaname ), "%s_%i_%i_luma", loadmodel->name, skinnum, i );
|
||||
pic = Mod_CreateSkinData( NULL, ptexture, m_pAliasHeader->skinwidth, m_pAliasHeader->skinheight );
|
||||
m_pAliasHeader->fb_texturenum[skinnum][i & 3] = GL_LoadTextureInternal( lumaname, pic, TF_MAKELUMA );
|
||||
@@ -457,7 +444,7 @@ static const void *Mod_LoadGroupSkin( model_t *loadmodel, const daliasskintype_t
|
||||
ptexture += size;
|
||||
}
|
||||
|
||||
for( j = i; i < 4; i++ )
|
||||
for( int j = i; i < 4; i++ )
|
||||
{
|
||||
m_pAliasHeader->gl_texturenum[skinnum][i & 3] = m_pAliasHeader->gl_texturenum[skinnum][i - j];
|
||||
m_pAliasHeader->fb_texturenum[skinnum][i & 3] = m_pAliasHeader->fb_texturenum[skinnum][i - j];
|
||||
@@ -473,12 +460,10 @@ Mod_LoadAllSkins
|
||||
*/
|
||||
static const void *Mod_LoadAllSkins( model_t *mod, int numskins, const daliasskintype_t *pskintype )
|
||||
{
|
||||
int i, size;
|
||||
|
||||
size = m_pAliasHeader->skinwidth * m_pAliasHeader->skinheight;
|
||||
int size = m_pAliasHeader->skinwidth * m_pAliasHeader->skinheight;
|
||||
|
||||
// TODO: texture replacement support here
|
||||
for( i = 0; i < numskins; i++ )
|
||||
for( int i = 0; i < numskins; i++ )
|
||||
{
|
||||
if( pskintype->type == ALIAS_SKIN_SINGLE )
|
||||
pskintype = Mod_LoadSingleSkin( mod, pskintype, i, size );
|
||||
@@ -498,27 +483,22 @@ Mod_LoadAliasModel
|
||||
*/
|
||||
void Mod_LoadAliasModel( model_t *mod, const void *buffer, qboolean *loaded )
|
||||
{
|
||||
const daliasskintype_t *pskintype;
|
||||
const dtriangle_t *pintriangles;
|
||||
const daliashdr_t *pinmodel;
|
||||
const stvert_t *pinstverts;
|
||||
|
||||
if( loaded ) *loaded = false;
|
||||
pinmodel = (const daliashdr_t *)buffer;
|
||||
const daliashdr_t *pinmodel = (const daliashdr_t *)buffer;
|
||||
m_pAliasHeader = mod->cache.data;
|
||||
if( !m_pAliasHeader ) return;
|
||||
|
||||
// load the skins
|
||||
pskintype = (const daliasskintype_t *)&pinmodel[1];
|
||||
const daliasskintype_t *pskintype = (const daliasskintype_t *)&pinmodel[1];
|
||||
pskintype = Mod_LoadAllSkins( mod, m_pAliasHeader->numskins, pskintype );
|
||||
|
||||
// load base s and t vertices
|
||||
pinstverts = (const stvert_t *)pskintype;
|
||||
const stvert_t *pinstverts = (const stvert_t *)pskintype;
|
||||
memset( g_stverts, 0, sizeof( g_stverts ));
|
||||
memcpy( g_stverts, pinstverts, sizeof( g_stverts[0] ) * m_pAliasHeader->numverts );
|
||||
|
||||
// load triangle lists
|
||||
pintriangles = (const dtriangle_t *)&pinstverts[m_pAliasHeader->numverts];
|
||||
const dtriangle_t *pintriangles = (const dtriangle_t *)&pinstverts[m_pAliasHeader->numverts];
|
||||
memset( g_triangles, 0, sizeof( g_triangles ));
|
||||
memcpy( g_triangles, pintriangles, sizeof( g_triangles[0] ) * m_pAliasHeader->numtris );
|
||||
|
||||
@@ -532,18 +512,15 @@ void Mod_LoadAliasModel( model_t *mod, const void *buffer, qboolean *loaded )
|
||||
|
||||
void Mod_AliasUnloadTextures( void *data )
|
||||
{
|
||||
aliashdr_t *palias;
|
||||
int i, j;
|
||||
|
||||
palias = data;
|
||||
aliashdr_t *palias = data;
|
||||
if( !palias ) return; // already freed
|
||||
|
||||
for( i = 0; i < MAX_SKINS; i++ )
|
||||
for( int i = 0; i < MAX_SKINS; i++ )
|
||||
{
|
||||
if( !palias->gl_texturenum[i][0] )
|
||||
break;
|
||||
|
||||
for( j = 0; j < 4; j++ )
|
||||
for( int j = 0; j < 4; j++ )
|
||||
{
|
||||
GL_FreeTexture( palias->gl_texturenum[i][j] );
|
||||
GL_FreeTexture( palias->fb_texturenum[i][j] );
|
||||
@@ -588,15 +565,14 @@ R_AliasLighting
|
||||
*/
|
||||
static void R_AliasLighting( float *lv, const vec3_t normal )
|
||||
{
|
||||
float illum = g_alias.ambientlight;
|
||||
float r, lightcos;
|
||||
float illum = g_alias.ambientlight;
|
||||
|
||||
lightcos = DotProduct( normal, g_alias.lightvec_local ); // -1 colinear, 1 opposite
|
||||
float lightcos = DotProduct( normal, g_alias.lightvec_local ); // -1 colinear, 1 opposite
|
||||
if( lightcos > 1.0f ) lightcos = 1.0f;
|
||||
|
||||
illum += g_alias.shadelight;
|
||||
|
||||
r = SHADE_LAMBERT;
|
||||
float r = SHADE_LAMBERT;
|
||||
|
||||
// do modified hemispherical lighting
|
||||
if( r <= 1.0f )
|
||||
@@ -637,22 +613,16 @@ GL_DrawAliasFrame
|
||||
*/
|
||||
static void GL_DrawAliasFrame( aliashdr_t *paliashdr )
|
||||
{
|
||||
float lv_tmp;
|
||||
trivertex_t *verts0;
|
||||
trivertex_t *verts1;
|
||||
vec3_t vert, norm;
|
||||
int *order;
|
||||
int count;
|
||||
|
||||
verts0 = verts1 = paliashdr->posedata;
|
||||
trivertex_t *verts0 = paliashdr->posedata;
|
||||
trivertex_t *verts1 = paliashdr->posedata;
|
||||
verts0 += g_alias.oldpose * paliashdr->poseverts;
|
||||
verts1 += g_alias.newpose * paliashdr->poseverts;
|
||||
order = paliashdr->commands;
|
||||
int *order = paliashdr->commands;
|
||||
|
||||
while( 1 )
|
||||
{
|
||||
// get the vertex count and primitive type
|
||||
count = *order++;
|
||||
int count = *order++;
|
||||
if( !count ) break; // done
|
||||
|
||||
if( count < 0 )
|
||||
@@ -679,10 +649,13 @@ static void GL_DrawAliasFrame( aliashdr_t *paliashdr )
|
||||
}
|
||||
order += 2;
|
||||
|
||||
vec3_t norm;
|
||||
VectorLerp( m_bytenormals[verts0->lightnormalindex], g_alias.lerpfrac, m_bytenormals[verts1->lightnormalindex], norm );
|
||||
VectorNormalize( norm );
|
||||
float lv_tmp;
|
||||
R_AliasLighting( &lv_tmp, norm );
|
||||
pglColor4f( g_alias.lightcolor[0] * lv_tmp, g_alias.lightcolor[1] * lv_tmp, g_alias.lightcolor[2] * lv_tmp, tr.blend );
|
||||
vec3_t vert;
|
||||
VectorLerp( verts0->v, g_alias.lerpfrac, verts1->v, vert );
|
||||
pglVertex3fv( vert );
|
||||
verts0++, verts1++;
|
||||
@@ -699,33 +672,27 @@ GL_DrawAliasShadow
|
||||
*/
|
||||
static void GL_DrawAliasShadow( aliashdr_t *paliashdr )
|
||||
{
|
||||
trivertex_t *verts0;
|
||||
trivertex_t *verts1;
|
||||
float vec_x, vec_y;
|
||||
vec3_t av, point;
|
||||
int *order;
|
||||
int count;
|
||||
|
||||
if( FBitSet( RI.currententity->curstate.effects, EF_NOSHADOW ))
|
||||
return;
|
||||
|
||||
if( glState.stencilEnabled )
|
||||
pglEnable( GL_STENCIL_TEST );
|
||||
|
||||
vec_x = -g_alias.lightvec[0] * 8.0f;
|
||||
vec_y = -g_alias.lightvec[1] * 8.0f;
|
||||
float vec_x = -g_alias.lightvec[0] * 8.0f;
|
||||
float vec_y = -g_alias.lightvec[1] * 8.0f;
|
||||
|
||||
r_stats.c_alias_polys += paliashdr->numtris;
|
||||
|
||||
verts0 = verts1 = paliashdr->posedata;
|
||||
trivertex_t *verts0 = paliashdr->posedata;
|
||||
trivertex_t *verts1 = paliashdr->posedata;
|
||||
verts0 += g_alias.oldpose * paliashdr->poseverts;
|
||||
verts1 += g_alias.newpose * paliashdr->poseverts;
|
||||
order = paliashdr->commands;
|
||||
int *order = paliashdr->commands;
|
||||
|
||||
while( 1 )
|
||||
{
|
||||
// get the vertex count and primitive type
|
||||
count = *order++;
|
||||
int count = *order++;
|
||||
if( !count ) break; // done
|
||||
|
||||
if( count < 0 )
|
||||
@@ -745,6 +712,7 @@ static void GL_DrawAliasShadow( aliashdr_t *paliashdr )
|
||||
order += 2;
|
||||
|
||||
// normals and vertexes come from the frame list
|
||||
vec3_t av, point;
|
||||
VectorLerp( verts0->v, g_alias.lerpfrac, verts1->v, av );
|
||||
point[0] = av[0] * paliashdr->scale[0] + paliashdr->scale_origin[0];
|
||||
point[1] = av[1] * paliashdr->scale[1] + paliashdr->scale_origin[1];
|
||||
@@ -818,13 +786,8 @@ R_SetupAliasFrame
|
||||
*/
|
||||
static void R_SetupAliasFrame( cl_entity_t *e, aliashdr_t *paliashdr )
|
||||
{
|
||||
int newpose, oldpose;
|
||||
int newframe, oldframe;
|
||||
int numposes, cycle;
|
||||
float interval;
|
||||
|
||||
oldframe = e->latched.prevframe;
|
||||
newframe = e->curstate.frame;
|
||||
int oldframe = e->latched.prevframe;
|
||||
int newframe = e->curstate.frame;
|
||||
|
||||
if( newframe < 0 )
|
||||
{
|
||||
@@ -840,13 +803,14 @@ static void R_SetupAliasFrame( cl_entity_t *e, aliashdr_t *paliashdr )
|
||||
if(( oldframe >= paliashdr->numframes ) || ( oldframe < 0 ))
|
||||
oldframe = newframe;
|
||||
|
||||
numposes = paliashdr->frames[newframe].numposes;
|
||||
int numposes = paliashdr->frames[newframe].numposes;
|
||||
|
||||
int oldpose, newpose;
|
||||
if( numposes > 1 )
|
||||
{
|
||||
oldpose = newpose = paliashdr->frames[newframe].firstpose;
|
||||
interval = 1.0f / paliashdr->frames[newframe].interval;
|
||||
cycle = (int)(g_alias.time * interval);
|
||||
float interval = 1.0f / paliashdr->frames[newframe].interval;
|
||||
int cycle = (int)(g_alias.time * interval);
|
||||
oldpose += (cycle + 0) % numposes; // lerpframe from
|
||||
newpose += (cycle + 1) % numposes; // lerpframe to
|
||||
g_alias.lerpfrac = ( g_alias.time * interval );
|
||||
@@ -872,15 +836,13 @@ R_StudioDrawAbsBBox
|
||||
*/
|
||||
static void R_AliasDrawAbsBBox( cl_entity_t *e, const vec3_t absmin, const vec3_t absmax )
|
||||
{
|
||||
vec3_t p[8];
|
||||
int i;
|
||||
|
||||
// looks ugly, skip
|
||||
if( r_drawentities->value != 5 || e == tr.viewent )
|
||||
return;
|
||||
|
||||
// compute a full bounding box
|
||||
for( i = 0; i < 8; i++ )
|
||||
vec3_t p[8];
|
||||
for( int i = 0; i < 8; i++ )
|
||||
{
|
||||
p[i][0] = ( i & 1 ) ? absmin[0] : absmax[0];
|
||||
p[i][1] = ( i & 2 ) ? absmin[1] : absmax[1];
|
||||
@@ -893,7 +855,7 @@ static void R_AliasDrawAbsBBox( cl_entity_t *e, const vec3_t absmin, const vec3_
|
||||
pglTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
|
||||
|
||||
TriBegin( TRI_QUADS );
|
||||
for( i = 0; i < 6; i++ )
|
||||
for( int i = 0; i < 6; i++ )
|
||||
{
|
||||
TriBrightness( g_alias.shadelight / 255.0f );
|
||||
TriVertex3fv( p[boxpnt[i][0]] );
|
||||
@@ -971,16 +933,9 @@ R_DrawAliasModel
|
||||
*/
|
||||
void R_DrawAliasModel( cl_entity_t *e )
|
||||
{
|
||||
model_t *clmodel;
|
||||
vec3_t absmin, absmax;
|
||||
remap_info_t *pinfo = NULL;
|
||||
int anim, skin;
|
||||
alight_t lighting;
|
||||
player_info_t *playerinfo;
|
||||
vec3_t dir, angles;
|
||||
|
||||
clmodel = RI.currententity->model;
|
||||
model_t *clmodel = RI.currententity->model;
|
||||
|
||||
vec3_t absmin, absmax;
|
||||
VectorAdd( e->origin, clmodel->mins, absmin );
|
||||
VectorAdd( e->origin, clmodel->maxs, absmax );
|
||||
|
||||
@@ -997,6 +952,7 @@ void R_DrawAliasModel( cl_entity_t *e )
|
||||
R_AliasSetupTimings();
|
||||
|
||||
// angles will be modify below keep original
|
||||
vec3_t angles;
|
||||
VectorCopy( e->angles, angles );
|
||||
|
||||
R_AliasLerpMovement( e );
|
||||
@@ -1010,6 +966,8 @@ void R_DrawAliasModel( cl_entity_t *e )
|
||||
//
|
||||
// get lighting information
|
||||
//
|
||||
alight_t lighting;
|
||||
vec3_t dir;
|
||||
lighting.plightvec = dir;
|
||||
R_EntityDynamicLight( e, &lighting, FBitSet( RI.rvp.flags, RF_DRAW_WORLD ), g_alias.time, g_alias.lightspot, g_alias.lightvec );
|
||||
|
||||
@@ -1027,6 +985,7 @@ void R_DrawAliasModel( cl_entity_t *e )
|
||||
GL_SetRenderMode( e->curstate.rendermode );
|
||||
|
||||
// setup remapping only for players
|
||||
player_info_t *playerinfo;
|
||||
if( e->player && ( playerinfo = pfnPlayerInfo( e->curstate.number - 1 )) != NULL )
|
||||
{
|
||||
// get remap colors
|
||||
@@ -1046,8 +1005,9 @@ void R_DrawAliasModel( cl_entity_t *e )
|
||||
pglScalef( m_pAliasHeader->scale[0], m_pAliasHeader->scale[1], m_pAliasHeader->scale[2] );
|
||||
}
|
||||
|
||||
anim = (int)(g_alias.time * 10) & 3;
|
||||
skin = bound( 0, RI.currententity->curstate.skin, m_pAliasHeader->numskins - 1 );
|
||||
int anim = (int)(g_alias.time * 10) & 3;
|
||||
int skin = bound( 0, RI.currententity->curstate.skin, m_pAliasHeader->numskins - 1 );
|
||||
remap_info_t *pinfo = NULL;
|
||||
if( m_fDoRemap ) pinfo = gEngfuncs.CL_GetRemapInfoForEntity( e );
|
||||
|
||||
if( r_lightmap->value && !r_fullbright->value )
|
||||
|
||||
@@ -59,14 +59,10 @@ GL_BackendEndFrame
|
||||
*/
|
||||
void GL_BackendEndFrame( void )
|
||||
{
|
||||
mleaf_t *curleaf;
|
||||
|
||||
if( r_speeds->value <= 0 || !FBitSet( RI.rvp.flags, RF_DRAW_WORLD ))
|
||||
return;
|
||||
|
||||
if( !RI.viewleaf )
|
||||
curleaf = WORLDMODEL->leafs;
|
||||
else curleaf = RI.viewleaf;
|
||||
mleaf_t *curleaf = RI.viewleaf ? RI.viewleaf : WORLDMODEL->leafs;
|
||||
|
||||
switch( (int)r_speeds->value )
|
||||
{
|
||||
@@ -180,9 +176,6 @@ GL_Bind
|
||||
*/
|
||||
void GL_Bind( int tmu, unsigned int texnum )
|
||||
{
|
||||
const gl_texture_t *texture;
|
||||
GLuint glTarget;
|
||||
|
||||
// missed or invalid texture?
|
||||
if( texnum <= 0 || texnum >= MAX_TEXTURES )
|
||||
{
|
||||
@@ -195,8 +188,8 @@ void GL_Bind( int tmu, unsigned int texnum )
|
||||
GL_SelectTexture( tmu );
|
||||
else tmu = glState.activeTMU;
|
||||
|
||||
texture = R_GetTexture( texnum );
|
||||
glTarget = texture->target;
|
||||
const gl_texture_t *texture = R_GetTexture( texnum );
|
||||
GLuint glTarget = texture->target;
|
||||
|
||||
if( glTarget == GL_TEXTURE_2D_ARRAY_EXT )
|
||||
glTarget = GL_TEXTURE_2D;
|
||||
@@ -236,9 +229,7 @@ GL_CleanUpTextureUnits
|
||||
*/
|
||||
void GL_CleanUpTextureUnits( int last )
|
||||
{
|
||||
int i;
|
||||
|
||||
for( i = glState.activeTMU; i > (last - 1); i-- )
|
||||
for( int i = glState.activeTMU; i > (last - 1); i-- )
|
||||
{
|
||||
// disable upper units
|
||||
if( glState.currentTextureTargets[i] != GL_NONE )
|
||||
@@ -556,12 +547,10 @@ static const envmap_t r_envMapInfo[6] =
|
||||
|
||||
qboolean VID_ScreenShot( const char *filename, int shot_type )
|
||||
{
|
||||
rgbdata_t *r_shot;
|
||||
uint flags = IMAGE_FLIP_Y;
|
||||
int width = 0, height = 0;
|
||||
qboolean result;
|
||||
uint flags = IMAGE_FLIP_Y;
|
||||
int width = 0, height = 0;
|
||||
|
||||
r_shot = Mem_Calloc( r_temppool, sizeof( rgbdata_t ));
|
||||
rgbdata_t *r_shot = Mem_Calloc( r_temppool, sizeof( rgbdata_t ));
|
||||
r_shot->width = (gpGlobals->width + 3) & ~3;
|
||||
r_shot->height = (gpGlobals->height + 3) & ~3;
|
||||
r_shot->flags = IMAGE_HAS_COLOR;
|
||||
@@ -596,7 +585,7 @@ qboolean VID_ScreenShot( const char *filename, int shot_type )
|
||||
gEngfuncs.Image_Process( &r_shot, width, height, flags, 0.0f );
|
||||
|
||||
// write image
|
||||
result = gEngfuncs.FS_SaveImage( filename, r_shot );
|
||||
qboolean result = gEngfuncs.FS_SaveImage( filename, r_shot );
|
||||
gEngfuncs.fsapi->AllowDirectPaths( false ); // always reset after store screenshot
|
||||
gEngfuncs.FS_FreeImage( r_shot );
|
||||
|
||||
@@ -610,16 +599,11 @@ VID_CubemapShot
|
||||
*/
|
||||
qboolean VID_CubemapShot( const char *base, uint size, const float *vieworg, qboolean skyshot )
|
||||
{
|
||||
rgbdata_t *r_shot, *r_side;
|
||||
byte *temp = NULL;
|
||||
byte *buffer = NULL;
|
||||
string basename;
|
||||
int i = 1, flags, result;
|
||||
|
||||
if( !FBitSet( RI.rvp.flags, RF_DRAW_WORLD ) || !WORLDMODEL )
|
||||
return false;
|
||||
|
||||
// make sure the specified size is valid
|
||||
int i = 1;
|
||||
while( i < size ) i<<=1;
|
||||
|
||||
if( i != size ) return false;
|
||||
@@ -627,10 +611,10 @@ qboolean VID_CubemapShot( const char *base, uint size, const float *vieworg, qbo
|
||||
return false;
|
||||
|
||||
// alloc space
|
||||
temp = Mem_Malloc( r_temppool, size * size * 3 );
|
||||
buffer = Mem_Malloc( r_temppool, size * size * 3 * 6 );
|
||||
r_shot = Mem_Calloc( r_temppool, sizeof( rgbdata_t ));
|
||||
r_side = Mem_Calloc( r_temppool, sizeof( rgbdata_t ));
|
||||
byte *temp = Mem_Malloc( r_temppool, size * size * 3 );
|
||||
byte *buffer = Mem_Malloc( r_temppool, size * size * 3 * 6 );
|
||||
rgbdata_t *r_shot = Mem_Calloc( r_temppool, sizeof( rgbdata_t ));
|
||||
rgbdata_t *r_side = Mem_Calloc( r_temppool, sizeof( rgbdata_t ));
|
||||
|
||||
// use client vieworg
|
||||
if( !vieworg ) vieworg = RI.rvp.vieworigin;
|
||||
@@ -640,6 +624,7 @@ qboolean VID_CubemapShot( const char *base, uint size, const float *vieworg, qbo
|
||||
// go into 3d mode
|
||||
R_Set2DMode( false );
|
||||
|
||||
int flags;
|
||||
if( skyshot )
|
||||
{
|
||||
R_DrawCubemapView( vieworg, r_skyBoxInfo[i].angles, size );
|
||||
@@ -672,11 +657,12 @@ qboolean VID_CubemapShot( const char *base, uint size, const float *vieworg, qbo
|
||||
r_shot->buffer = buffer;
|
||||
|
||||
// make sure what we have right extension
|
||||
string basename;
|
||||
Q_strncpy( basename, base, sizeof( basename ));
|
||||
COM_ReplaceExtension( basename, ".tga", sizeof( basename ));
|
||||
|
||||
// write image as 6 sides
|
||||
result = gEngfuncs.FS_SaveImage( basename, r_shot );
|
||||
int result = gEngfuncs.FS_SaveImage( basename, r_shot );
|
||||
gEngfuncs.FS_FreeImage( r_shot );
|
||||
gEngfuncs.FS_FreeImage( r_side );
|
||||
|
||||
@@ -693,20 +679,16 @@ timerefresh [noflip]
|
||||
*/
|
||||
void SCR_TimeRefresh_f( void )
|
||||
{
|
||||
int i;
|
||||
double start, stop;
|
||||
double time;
|
||||
|
||||
if( ENGINE_GET_PARM( PARM_CONNSTATE ) != ca_active )
|
||||
return;
|
||||
|
||||
start = gEngfuncs.pfnTime();
|
||||
double start = gEngfuncs.pfnTime();
|
||||
|
||||
// run without page flipping like GoldSrc
|
||||
if( gEngfuncs.Cmd_Argc() == 1 )
|
||||
{
|
||||
pglDrawBuffer( GL_FRONT );
|
||||
for( i = 0; i < 128; i++ )
|
||||
for( int i = 0; i < 128; i++ )
|
||||
{
|
||||
gpGlobals->viewangles[1] = i / 128.0f * 360.0f;
|
||||
R_RenderScene();
|
||||
@@ -716,7 +698,7 @@ void SCR_TimeRefresh_f( void )
|
||||
}
|
||||
else
|
||||
{
|
||||
for( i = 0; i < 128; i++ )
|
||||
for( int i = 0; i < 128; i++ )
|
||||
{
|
||||
R_BeginFrame( true );
|
||||
gpGlobals->viewangles[1] = i / 128.0f * 360.0f;
|
||||
@@ -725,7 +707,7 @@ void SCR_TimeRefresh_f( void )
|
||||
}
|
||||
}
|
||||
|
||||
stop = gEngfuncs.pfnTime ();
|
||||
time = (stop - start);
|
||||
double stop = gEngfuncs.pfnTime ();
|
||||
double time = (stop - start);
|
||||
gEngfuncs.Con_Printf( "%f seconds (%f fps)\n", time, 128 / time );
|
||||
}
|
||||
|
||||
@@ -44,9 +44,7 @@ static float rgNoise[NOISE_DIVISIONS+1]; // global noise array
|
||||
// Fractal noise generator, power of 2 wavelength
|
||||
static void FracNoise( float *noise, int divs )
|
||||
{
|
||||
int div2;
|
||||
|
||||
div2 = divs >> 1;
|
||||
int div2 = divs >> 1;
|
||||
if( divs < 2 ) return;
|
||||
|
||||
// noise is normalized to +/- scale
|
||||
@@ -61,11 +59,10 @@ static void FracNoise( float *noise, int divs )
|
||||
|
||||
static void SineNoise( float *noise, int divs )
|
||||
{
|
||||
float freq = 0;
|
||||
float step = M_PI_F / (float)divs;
|
||||
int i;
|
||||
float freq = 0;
|
||||
float step = M_PI_F / (float)divs;
|
||||
|
||||
for( i = 0; i < divs; i++ )
|
||||
for( int i = 0; i < divs; i++ )
|
||||
{
|
||||
noise[i] = sin( freq );
|
||||
freq += step;
|
||||
@@ -116,10 +113,9 @@ Cull the beam by bbox
|
||||
*/
|
||||
static qboolean R_BeamCull( const vec3_t start, const vec3_t end, qboolean pvsOnly )
|
||||
{
|
||||
vec3_t mins, maxs;
|
||||
int i;
|
||||
vec3_t mins, maxs;
|
||||
|
||||
for( i = 0; i < 3; i++ )
|
||||
for( int i = 0; i < 3; i++ )
|
||||
{
|
||||
if( start[i] < end[i] )
|
||||
{
|
||||
@@ -168,18 +164,11 @@ general code for drawing beams
|
||||
*/
|
||||
static void R_DrawSegs( vec3_t source, vec3_t delta, float width, float scale, float freq, float speed, int segments, int flags )
|
||||
{
|
||||
int noiseIndex, noiseStep;
|
||||
int i, total_segs, segs_drawn;
|
||||
float div, length, fraction, factor;
|
||||
float flMaxWidth, vLast, vStep, brightness;
|
||||
vec3_t perp1, vLastNormal;
|
||||
beamseg_t curSeg;
|
||||
|
||||
if( segments < 2 ) return;
|
||||
|
||||
length = VectorLength( delta );
|
||||
flMaxWidth = width * 0.5f;
|
||||
div = 1.0f / ( segments - 1 );
|
||||
float length = VectorLength( delta );
|
||||
float flMaxWidth = width * 0.5f;
|
||||
float div = 1.0f / ( segments - 1 );
|
||||
|
||||
if( length * div < flMaxWidth * 1.414f )
|
||||
{
|
||||
@@ -193,10 +182,10 @@ static void R_DrawSegs( vec3_t source, vec3_t delta, float width, float scale, f
|
||||
|
||||
div = 1.0f / (segments - 1);
|
||||
length *= 0.01f;
|
||||
vStep = length * div; // Texture length texels per space pixel
|
||||
float vStep = length * div; // Texture length texels per space pixel
|
||||
|
||||
// Scroll speed 3.5 -- initial texture position, scrolls 3.5/sec (1.0 is entire texture)
|
||||
vLast = fmod( freq * speed, 1 );
|
||||
float vLast = fmod( freq * speed, 1 );
|
||||
|
||||
if( flags & FBEAM_SINENOISE )
|
||||
{
|
||||
@@ -214,35 +203,38 @@ static void R_DrawSegs( vec3_t source, vec3_t delta, float width, float scale, f
|
||||
}
|
||||
|
||||
// Iterator to resample noise waveform (it needs to be generated in powers of 2)
|
||||
noiseStep = (int)((float)( NOISE_DIVISIONS - 1 ) * div * 65536.0f );
|
||||
brightness = 1.0f;
|
||||
noiseIndex = 0;
|
||||
int noiseStep = (int)((float)( NOISE_DIVISIONS - 1 ) * div * 65536.0f );
|
||||
float brightness = 1.0f;
|
||||
int noiseIndex = 0;
|
||||
|
||||
if( FBitSet( flags, FBEAM_SHADEIN ))
|
||||
brightness = 0;
|
||||
|
||||
// Choose two vectors that are perpendicular to the beam
|
||||
vec3_t perp1;
|
||||
R_BeamComputePerpendicular( delta, perp1 );
|
||||
|
||||
total_segs = segments;
|
||||
segs_drawn = 0;
|
||||
int total_segs = segments;
|
||||
int segs_drawn = 0;
|
||||
beamseg_t curSeg;
|
||||
vec3_t vLastNormal;
|
||||
|
||||
// specify all the segments.
|
||||
for( i = 0; i < segments; i++ )
|
||||
for( int i = 0; i < segments; i++ )
|
||||
{
|
||||
beamseg_t nextSeg;
|
||||
vec3_t vPoint1, vPoint2;
|
||||
beamseg_t nextSeg;
|
||||
vec3_t vPoint1, vPoint2;
|
||||
|
||||
Assert( noiseIndex < ( NOISE_DIVISIONS << 16 ));
|
||||
|
||||
fraction = i * div;
|
||||
float fraction = i * div;
|
||||
|
||||
VectorMA( source, fraction, delta, nextSeg.pos );
|
||||
|
||||
// distort using noise
|
||||
if( scale != 0 )
|
||||
{
|
||||
factor = rgNoise[noiseIndex>>16] * scale;
|
||||
float factor = rgNoise[noiseIndex>>16] * scale;
|
||||
|
||||
if( FBitSet( flags, FBEAM_SINENOISE ))
|
||||
{
|
||||
@@ -350,38 +342,36 @@ Draw beamtours
|
||||
*/
|
||||
static void R_DrawTorus( vec3_t source, vec3_t delta, float width, float scale, float freq, float speed, int segments )
|
||||
{
|
||||
int i, noiseIndex, noiseStep;
|
||||
float div, length, fraction, factor, vLast, vStep;
|
||||
vec3_t last1, last2, point, screen, screenLast, tmp, normal;
|
||||
|
||||
if( segments < 2 )
|
||||
return;
|
||||
|
||||
if( segments > NOISE_DIVISIONS )
|
||||
segments = NOISE_DIVISIONS;
|
||||
|
||||
length = VectorLength( delta ) * 0.01f;
|
||||
float length = VectorLength( delta ) * 0.01f;
|
||||
if( length < 0.5f ) length = 0.5f; // don't lose all of the noise/texture on short beams
|
||||
|
||||
div = 1.0f / (segments - 1);
|
||||
float div = 1.0f / (segments - 1);
|
||||
|
||||
vStep = length * div; // Texture length texels per space pixel
|
||||
float vStep = length * div; // Texture length texels per space pixel
|
||||
|
||||
// Scroll speed 3.5 -- initial texture position, scrolls 3.5/sec (1.0 is entire texture)
|
||||
vLast = fmod( freq * speed, 1 );
|
||||
float vLast = fmod( freq * speed, 1 );
|
||||
scale = scale * length;
|
||||
|
||||
// Iterator to resample noise waveform (it needs to be generated in powers of 2)
|
||||
noiseStep = (int)((float)( NOISE_DIVISIONS - 1 ) * div * 65536.0f );
|
||||
noiseIndex = 0;
|
||||
int noiseStep = (int)((float)( NOISE_DIVISIONS - 1 ) * div * 65536.0f );
|
||||
int noiseIndex = 0;
|
||||
|
||||
for( i = 0; i < segments; i++ )
|
||||
vec3_t screenLast = { 0 };
|
||||
|
||||
for( int i = 0; i < segments; i++ )
|
||||
{
|
||||
float s, c;
|
||||
|
||||
fraction = i * div;
|
||||
float fraction = i * div;
|
||||
float s, c;
|
||||
SinCos( fraction * M_PI2_F, &s, &c );
|
||||
|
||||
vec3_t point;
|
||||
point[0] = s * freq * delta[2] + source[0];
|
||||
point[1] = c * freq * delta[2] + source[1];
|
||||
point[2] = source[2];
|
||||
@@ -391,7 +381,7 @@ static void R_DrawTorus( vec3_t source, vec3_t delta, float width, float scale,
|
||||
{
|
||||
if(( noiseIndex >> 16 ) < NOISE_DIVISIONS )
|
||||
{
|
||||
factor = rgNoise[noiseIndex>>16] * scale;
|
||||
float factor = rgNoise[noiseIndex>>16] * scale;
|
||||
VectorMA( point, factor, RI.vup, point );
|
||||
|
||||
// rotate the noise along the perpendicluar axis a bit to keep the bolt from looking diagonal
|
||||
@@ -401,20 +391,24 @@ static void R_DrawTorus( vec3_t source, vec3_t delta, float width, float scale,
|
||||
}
|
||||
|
||||
// Transform point into screen space
|
||||
vec3_t screen;
|
||||
TriWorldToScreen( point, screen );
|
||||
|
||||
if( i != 0 )
|
||||
{
|
||||
// build world-space normal to screen-space direction vector
|
||||
vec3_t tmp;
|
||||
VectorSubtract( screen, screenLast, tmp );
|
||||
|
||||
// we don't need Z, we're in screen space
|
||||
tmp[2] = 0;
|
||||
VectorNormalize( tmp );
|
||||
vec3_t normal;
|
||||
VectorScale( RI.vup, -tmp[0], normal ); // Build point along noraml line (normal is -y, x)
|
||||
VectorMA( normal, tmp[1], RI.vright, normal );
|
||||
|
||||
// Make a wide line
|
||||
vec3_t last1, last2;
|
||||
VectorMA( point, width, normal, last1 );
|
||||
VectorMA( point, -width, normal, last2 );
|
||||
|
||||
@@ -439,36 +433,31 @@ Draw beamdisk
|
||||
*/
|
||||
static void R_DrawDisk( vec3_t source, vec3_t delta, float width, float scale, float freq, float speed, int segments )
|
||||
{
|
||||
float div, length, fraction;
|
||||
float w, vLast, vStep;
|
||||
vec3_t point;
|
||||
int i;
|
||||
|
||||
if( segments < 2 )
|
||||
return;
|
||||
|
||||
if( segments > NOISE_DIVISIONS ) // UNDONE: Allow more segments?
|
||||
segments = NOISE_DIVISIONS;
|
||||
|
||||
length = VectorLength( delta ) * 0.01f;
|
||||
float length = VectorLength( delta ) * 0.01f;
|
||||
if( length < 0.5f ) length = 0.5f; // don't lose all of the noise/texture on short beams
|
||||
|
||||
div = 1.0f / (segments - 1);
|
||||
vStep = length * div; // Texture length texels per space pixel
|
||||
float div = 1.0f / (segments - 1);
|
||||
float vStep = length * div; // Texture length texels per space pixel
|
||||
|
||||
// scroll speed 3.5 -- initial texture position, scrolls 3.5/sec (1.0 is entire texture)
|
||||
vLast = fmod( freq * speed, 1 );
|
||||
float vLast = fmod( freq * speed, 1 );
|
||||
scale = scale * length;
|
||||
|
||||
// clamp the beam width
|
||||
w = fmod( freq, width * 0.1f ) * delta[2];
|
||||
float w = fmod( freq, width * 0.1f ) * delta[2];
|
||||
|
||||
// NOTE: we must force the degenerate triangles to be on the edge
|
||||
for( i = 0; i < segments; i++ )
|
||||
for( int i = 0; i < segments; i++ )
|
||||
{
|
||||
float s, c;
|
||||
|
||||
fraction = i * div;
|
||||
float s, c;
|
||||
float fraction = i * div;
|
||||
vec3_t point;
|
||||
VectorCopy( source, point );
|
||||
|
||||
TriBrightness( 1.0f );
|
||||
@@ -497,34 +486,29 @@ Draw beam cylinder
|
||||
*/
|
||||
static void R_DrawCylinder( vec3_t source, vec3_t delta, float width, float scale, float freq, float speed, int segments )
|
||||
{
|
||||
float div, length, fraction;
|
||||
float vLast, vStep;
|
||||
vec3_t point;
|
||||
int i;
|
||||
|
||||
if( segments < 2 )
|
||||
return;
|
||||
|
||||
if( segments > NOISE_DIVISIONS )
|
||||
segments = NOISE_DIVISIONS;
|
||||
|
||||
length = VectorLength( delta ) * 0.01f;
|
||||
float length = VectorLength( delta ) * 0.01f;
|
||||
if( length < 0.5f ) length = 0.5f; // don't lose all of the noise/texture on short beams
|
||||
|
||||
div = 1.0f / (segments - 1);
|
||||
vStep = length * div; // texture length texels per space pixel
|
||||
float div = 1.0f / (segments - 1);
|
||||
float vStep = length * div; // texture length texels per space pixel
|
||||
|
||||
// Scroll speed 3.5 -- initial texture position, scrolls 3.5/sec (1.0 is entire texture)
|
||||
vLast = fmod( freq * speed, 1 );
|
||||
float vLast = fmod( freq * speed, 1 );
|
||||
scale = scale * length;
|
||||
|
||||
for ( i = 0; i < segments; i++ )
|
||||
for ( int i = 0; i < segments; i++ )
|
||||
{
|
||||
float s, c;
|
||||
|
||||
fraction = i * div;
|
||||
float s, c;
|
||||
float fraction = i * div;
|
||||
SinCos( fraction * M_PI2_F, &s, &c );
|
||||
|
||||
vec3_t point;
|
||||
point[0] = s * freq * delta[2] + source[0];
|
||||
point[1] = c * freq * delta[2] + source[1];
|
||||
point[2] = source[2] + width;
|
||||
@@ -554,17 +538,13 @@ drawi followed beam
|
||||
*/
|
||||
static void R_DrawBeamFollow( BEAM *pbeam, float frametime )
|
||||
{
|
||||
particle_t *pnew, *particles;
|
||||
float fraction, div, vLast, vStep;
|
||||
vec3_t last1, last2, tmp, screen;
|
||||
vec3_t delta, screenLast, normal;
|
||||
|
||||
gEngfuncs.R_FreeDeadParticles( &pbeam->particles );
|
||||
|
||||
particles = pbeam->particles;
|
||||
pnew = NULL;
|
||||
particle_t *particles = pbeam->particles;
|
||||
particle_t *pnew = NULL;
|
||||
|
||||
div = 0;
|
||||
vec3_t delta;
|
||||
float div = 0;
|
||||
if( FBitSet( pbeam->flags, FBEAM_STARTENTITY ))
|
||||
{
|
||||
if( particles )
|
||||
@@ -597,6 +577,7 @@ static void R_DrawBeamFollow( BEAM *pbeam, float frametime )
|
||||
// nothing to draw
|
||||
if( !particles ) return;
|
||||
|
||||
vec3_t screen, screenLast;
|
||||
if( !pnew && div != 0 )
|
||||
{
|
||||
VectorCopy( pbeam->source, delta );
|
||||
@@ -619,24 +600,27 @@ static void R_DrawBeamFollow( BEAM *pbeam, float frametime )
|
||||
// first beam segment for this trail
|
||||
|
||||
// build world-space normal to screen-space direction vector
|
||||
vec3_t tmp;
|
||||
VectorSubtract( screen, screenLast, tmp );
|
||||
// we don't need Z, we're in screen space
|
||||
tmp[2] = 0;
|
||||
VectorNormalize( tmp );
|
||||
|
||||
// Build point along noraml line (normal is -y, x)
|
||||
vec3_t normal;
|
||||
VectorScale( RI.vup, tmp[0], normal ); // Build point along normal line (normal is -y, x)
|
||||
VectorMA( normal, tmp[1], RI.vright, normal );
|
||||
|
||||
// Make a wide line
|
||||
vec3_t last1, last2;
|
||||
VectorMA( delta, pbeam->width, normal, last1 );
|
||||
VectorMA( delta, -pbeam->width, normal, last2 );
|
||||
|
||||
div = 1.0f / pbeam->amplitude;
|
||||
fraction = ( pbeam->die - gp_cl->time ) * div;
|
||||
float fraction = ( pbeam->die - gp_cl->time ) * div;
|
||||
|
||||
vLast = 0.0f;
|
||||
vStep = 1.0f;
|
||||
float vLast = 0.0f;
|
||||
float vStep = 1.0f;
|
||||
|
||||
while( particles )
|
||||
{
|
||||
@@ -704,45 +688,43 @@ Draw beamring
|
||||
*/
|
||||
static void R_DrawRing( vec3_t source, vec3_t delta, float width, float amplitude, float freq, float speed, int segments )
|
||||
{
|
||||
int i, j, noiseIndex, noiseStep;
|
||||
float div, length, fraction, factor, vLast, vStep;
|
||||
vec3_t last1, last2, point, screen, screenLast;
|
||||
vec3_t tmp, normal, center, xaxis, yaxis;
|
||||
float radius, x, y, scale;
|
||||
|
||||
if( segments < 2 )
|
||||
return;
|
||||
|
||||
vec3_t screenLast;
|
||||
VectorClear( screenLast );
|
||||
segments = segments * M_PI_F;
|
||||
|
||||
if( segments > NOISE_DIVISIONS * 8 )
|
||||
segments = NOISE_DIVISIONS * 8;
|
||||
|
||||
length = VectorLength( delta ) * 0.01f * M_PI_F;
|
||||
float length = VectorLength( delta ) * 0.01f * M_PI_F;
|
||||
if( length < 0.5f ) length = 0.5f; // Don't lose all of the noise/texture on short beams
|
||||
|
||||
div = 1.0f / ( segments - 1 );
|
||||
float div = 1.0f / ( segments - 1 );
|
||||
|
||||
vStep = length * div / 8.0f; // texture length texels per space pixel
|
||||
float vStep = length * div / 8.0f; // texture length texels per space pixel
|
||||
|
||||
// Scroll speed 3.5 -- initial texture position, scrolls 3.5/sec (1.0 is entire texture)
|
||||
vLast = fmod( freq * speed, 1.0f );
|
||||
scale = amplitude * length / 8.0f;
|
||||
float vLast = fmod( freq * speed, 1.0f );
|
||||
float scale = amplitude * length / 8.0f;
|
||||
|
||||
// Iterator to resample noise waveform (it needs to be generated in powers of 2)
|
||||
noiseStep = (int)((float)( NOISE_DIVISIONS - 1 ) * div * 65536.0f ) * 8;
|
||||
noiseIndex = 0;
|
||||
int noiseStep = (int)((float)( NOISE_DIVISIONS - 1 ) * div * 65536.0f ) * 8;
|
||||
int noiseIndex = 0;
|
||||
|
||||
VectorScale( delta, 0.5f, delta );
|
||||
vec3_t center;
|
||||
VectorAdd( source, delta, center );
|
||||
|
||||
vec3_t xaxis;
|
||||
VectorCopy( delta, xaxis );
|
||||
radius = VectorLength( xaxis );
|
||||
float radius = VectorLength( xaxis );
|
||||
|
||||
// cull beamring
|
||||
// --------------------------------
|
||||
// Compute box center +/- radius
|
||||
vec3_t last1, tmp, screen;
|
||||
VectorSet( last1, radius, radius, scale );
|
||||
VectorAdd( center, last1, tmp ); // maxs
|
||||
VectorSubtract( center, last1, screen ); // mins
|
||||
@@ -756,21 +738,24 @@ static void R_DrawRing( vec3_t source, vec3_t delta, float width, float amplitud
|
||||
return;
|
||||
}
|
||||
|
||||
vec3_t yaxis;
|
||||
VectorSet( yaxis, xaxis[1], -xaxis[0], 0.0f );
|
||||
VectorNormalize( yaxis );
|
||||
VectorScale( yaxis, radius, yaxis );
|
||||
|
||||
j = segments / 8;
|
||||
int j = segments / 8;
|
||||
|
||||
for( i = 0; i < segments + 1; i++ )
|
||||
for( int i = 0; i < segments + 1; i++ )
|
||||
{
|
||||
fraction = i * div;
|
||||
float fraction = i * div;
|
||||
float x, y;
|
||||
SinCos( fraction * M_PI2_F, &x, &y );
|
||||
|
||||
vec3_t point;
|
||||
VectorMAMAM( x, xaxis, y, yaxis, 1.0f, center, point );
|
||||
|
||||
// distort using noise
|
||||
factor = rgNoise[(noiseIndex >> 16) & (NOISE_DIVISIONS - 1)] * scale;
|
||||
float factor = rgNoise[(noiseIndex >> 16) & (NOISE_DIVISIONS - 1)] * scale;
|
||||
VectorMA( point, factor, RI.vup, point );
|
||||
|
||||
// Rotate the noise along the perpendicluar axis a bit to keep the bolt from looking diagonal
|
||||
@@ -791,10 +776,12 @@ static void R_DrawRing( vec3_t source, vec3_t delta, float width, float amplitud
|
||||
VectorNormalize( tmp );
|
||||
|
||||
// Build point along normal line (normal is -y, x)
|
||||
vec3_t normal;
|
||||
VectorScale( RI.vup, tmp[0], normal );
|
||||
VectorMA( normal, tmp[1], RI.vright, normal );
|
||||
|
||||
// Make a wide line
|
||||
vec3_t last2;
|
||||
VectorMA( point, width, normal, last1 );
|
||||
VectorMA( point, -width, normal, last2 );
|
||||
|
||||
@@ -826,11 +813,9 @@ compute attachment point for beam
|
||||
*/
|
||||
static qboolean R_BeamComputePoint( int beamEnt, vec3_t pt )
|
||||
{
|
||||
cl_entity_t *ent;
|
||||
int attach;
|
||||
|
||||
ent = gEngfuncs.R_BeamGetEntity( beamEnt );
|
||||
cl_entity_t *ent = gEngfuncs.R_BeamGetEntity( beamEnt );
|
||||
|
||||
int attach;
|
||||
if( beamEnt < 0 )
|
||||
attach = BEAMENT_ATTACHMENT( -beamEnt );
|
||||
else attach = BEAMENT_ATTACHMENT( beamEnt );
|
||||
@@ -914,10 +899,7 @@ Update beam vars and draw it
|
||||
*/
|
||||
static void R_BeamDraw( BEAM *pbeam, float frametime )
|
||||
{
|
||||
model_t *model;
|
||||
vec3_t delta;
|
||||
|
||||
model = CL_ModelHandle( pbeam->modelIndex );
|
||||
model_t *model = CL_ModelHandle( pbeam->modelIndex );
|
||||
SetBits( pbeam->flags, FBEAM_ISACTIVE );
|
||||
|
||||
if( !model || model->type != mod_sprite )
|
||||
@@ -955,6 +937,7 @@ static void R_BeamDraw( BEAM *pbeam, float frametime )
|
||||
}
|
||||
|
||||
// compute segments from the new endpoints
|
||||
vec3_t delta;
|
||||
VectorSubtract( pbeam->target, pbeam->source, delta );
|
||||
VectorClear( pbeam->delta );
|
||||
|
||||
@@ -987,12 +970,11 @@ static void R_BeamDraw( BEAM *pbeam, float frametime )
|
||||
|
||||
if( pbeam->type == TE_BEAMHOSE )
|
||||
{
|
||||
float flDot;
|
||||
|
||||
vec3_t delta;
|
||||
VectorSubtract( pbeam->target, pbeam->source, delta );
|
||||
VectorNormalize( delta );
|
||||
|
||||
flDot = DotProduct( delta, RI.vforward );
|
||||
float flDot = DotProduct( delta, RI.vforward );
|
||||
|
||||
// abort if the player's looking along it away from the source
|
||||
if( flDot > 0 )
|
||||
@@ -1001,16 +983,16 @@ static void R_BeamDraw( BEAM *pbeam, float frametime )
|
||||
}
|
||||
else
|
||||
{
|
||||
float flFade = pow( flDot, 10 );
|
||||
vec3_t localDir, vecProjection, tmp;
|
||||
float flDistance;
|
||||
float flFade = pow( flDot, 10 );
|
||||
|
||||
// fade the beam if the player's not looking at the source
|
||||
vec3_t localDir;
|
||||
VectorSubtract( RI.rvp.vieworigin, pbeam->source, localDir );
|
||||
flDot = DotProduct( delta, localDir );
|
||||
vec3_t vecProjection, tmp;
|
||||
VectorScale( delta, flDot, vecProjection );
|
||||
VectorSubtract( localDir, vecProjection, tmp );
|
||||
flDistance = VectorLength( tmp );
|
||||
float flDistance = VectorLength( tmp );
|
||||
|
||||
if( flDistance > 30 )
|
||||
{
|
||||
@@ -1037,10 +1019,8 @@ static void R_BeamDraw( BEAM *pbeam, float frametime )
|
||||
|
||||
if( pbeam->type == TE_BEAMFOLLOW )
|
||||
{
|
||||
cl_entity_t *pStart;
|
||||
|
||||
// XASH SPECIFIC: get brightness from head entity
|
||||
pStart = gEngfuncs.R_BeamGetEntity( pbeam->startEntity );
|
||||
cl_entity_t *pStart = gEngfuncs.R_BeamGetEntity( pbeam->startEntity );
|
||||
if( pStart && pStart->curstate.rendermode != kRenderNormal )
|
||||
pbeam->brightness = CL_FxBlend( pStart ) / 255.0f;
|
||||
}
|
||||
@@ -1160,16 +1140,14 @@ initialize beam from server entity
|
||||
*/
|
||||
static void R_BeamDrawCustomEntity( cl_entity_t *ent )
|
||||
{
|
||||
BEAM beam;
|
||||
float amp = ent->curstate.body / 100.0f;
|
||||
float blend = CL_FxBlend( ent ) / 255.0f;
|
||||
float r, g, b;
|
||||
int beamFlags;
|
||||
float amp = ent->curstate.body / 100.0f;
|
||||
float blend = CL_FxBlend( ent ) / 255.0f;
|
||||
|
||||
r = ent->curstate.rendercolor.r / 255.0f;
|
||||
g = ent->curstate.rendercolor.g / 255.0f;
|
||||
b = ent->curstate.rendercolor.b / 255.0f;
|
||||
float r = ent->curstate.rendercolor.r / 255.0f;
|
||||
float g = ent->curstate.rendercolor.g / 255.0f;
|
||||
float b = ent->curstate.rendercolor.b / 255.0f;
|
||||
|
||||
BEAM beam;
|
||||
R_BeamSetup( &beam, ent->origin, ent->curstate.angles, ent->curstate.modelindex, 0, ent->curstate.scale, amp, blend, ent->curstate.animtime );
|
||||
R_BeamSetAttributes( &beam, r, g, b, ent->curstate.framerate, ent->curstate.frame );
|
||||
beam.pFollowModel = NULL;
|
||||
@@ -1203,7 +1181,7 @@ static void R_BeamDrawCustomEntity( cl_entity_t *ent )
|
||||
break;
|
||||
}
|
||||
|
||||
beamFlags = ( ent->curstate.rendermode & 0xF0 );
|
||||
int beamFlags = ( ent->curstate.rendermode & 0xF0 );
|
||||
|
||||
if( FBitSet( beamFlags, BEAM_FSINE ))
|
||||
SetBits( beam.flags, FBEAM_SINENOISE );
|
||||
@@ -1231,18 +1209,15 @@ draw beam loop
|
||||
*/
|
||||
void CL_DrawBeams( int fTrans, BEAM *active_beams )
|
||||
{
|
||||
BEAM *pBeam;
|
||||
int i, flags;
|
||||
|
||||
pglShadeModel( GL_SMOOTH );
|
||||
pglDepthMask( fTrans ? GL_FALSE : GL_TRUE );
|
||||
|
||||
// server beams don't allocate beam chains
|
||||
// all params are stored in cl_entity_t
|
||||
for( i = 0; i < tr.draw_list->num_beam_entities; i++ )
|
||||
for( int i = 0; i < tr.draw_list->num_beam_entities; i++ )
|
||||
{
|
||||
RI.currentbeam = tr.draw_list->beam_entities[i];
|
||||
flags = RI.currentbeam->curstate.rendermode & 0xF0;
|
||||
int flags = RI.currentbeam->curstate.rendermode & 0xF0;
|
||||
|
||||
if( fTrans && FBitSet( flags, FBEAM_SOLID ))
|
||||
continue;
|
||||
@@ -1257,7 +1232,7 @@ void CL_DrawBeams( int fTrans, BEAM *active_beams )
|
||||
RI.currentbeam = NULL;
|
||||
|
||||
// draw temporary entity beams
|
||||
for( pBeam = active_beams; pBeam; pBeam = pBeam->next )
|
||||
for( BEAM *pBeam = active_beams; pBeam; pBeam = pBeam->next )
|
||||
{
|
||||
if( fTrans && FBitSet( pBeam->flags, FBEAM_SOLID ))
|
||||
continue;
|
||||
|
||||
@@ -84,9 +84,7 @@ static qboolean Mod_LooksLikeWaterTexture( const char *name )
|
||||
|
||||
static void Mod_BrushUnloadTextures( model_t *mod )
|
||||
{
|
||||
int i;
|
||||
|
||||
for( i = 0; i < mod->numtextures; i++ )
|
||||
for( int i = 0; i < mod->numtextures; i++ )
|
||||
{
|
||||
texture_t *tx = mod->textures[i];
|
||||
if( !tx )
|
||||
@@ -163,34 +161,24 @@ static qboolean Mod_ProcessRenderData( model_t *mod, qboolean create, const byte
|
||||
|
||||
static intptr_t GL_RefGetParm( int parm, int arg )
|
||||
{
|
||||
gl_texture_t *glt;
|
||||
|
||||
switch( parm )
|
||||
{
|
||||
case PARM_TEX_WIDTH:
|
||||
glt = R_GetTexture( arg );
|
||||
return glt->width;
|
||||
return R_GetTexture( arg )->width;
|
||||
case PARM_TEX_HEIGHT:
|
||||
glt = R_GetTexture( arg );
|
||||
return glt->height;
|
||||
return R_GetTexture( arg )->height;
|
||||
case PARM_TEX_SRC_WIDTH:
|
||||
glt = R_GetTexture( arg );
|
||||
return glt->srcWidth;
|
||||
return R_GetTexture( arg )->srcWidth;
|
||||
case PARM_TEX_SRC_HEIGHT:
|
||||
glt = R_GetTexture( arg );
|
||||
return glt->srcHeight;
|
||||
return R_GetTexture( arg )->srcHeight;
|
||||
case PARM_TEX_GLFORMAT:
|
||||
glt = R_GetTexture( arg );
|
||||
return glt->format;
|
||||
return R_GetTexture( arg )->format;
|
||||
case PARM_TEX_ENCODE:
|
||||
glt = R_GetTexture( arg );
|
||||
return glt->encode;
|
||||
return R_GetTexture( arg )->encode;
|
||||
case PARM_TEX_MIPCOUNT:
|
||||
glt = R_GetTexture( arg );
|
||||
return glt->numMips;
|
||||
return R_GetTexture( arg )->numMips;
|
||||
case PARM_TEX_DEPTH:
|
||||
glt = R_GetTexture( arg );
|
||||
return glt->depth;
|
||||
return R_GetTexture( arg )->depth;
|
||||
case PARM_TEX_SKYBOX:
|
||||
Assert( arg >= 0 && arg < 6 );
|
||||
return tr.skyboxTextures[arg];
|
||||
@@ -200,14 +188,11 @@ static intptr_t GL_RefGetParm( int parm, int arg )
|
||||
arg = bound( 0, arg, MAX_LIGHTMAPS - 1 );
|
||||
return tr.lightmapTextures[arg];
|
||||
case PARM_TEX_TARGET:
|
||||
glt = R_GetTexture( arg );
|
||||
return glt->target;
|
||||
return R_GetTexture( arg )->target;
|
||||
case PARM_TEX_TEXNUM:
|
||||
glt = R_GetTexture( arg );
|
||||
return glt->texnum;
|
||||
return R_GetTexture( arg )->texnum;
|
||||
case PARM_TEX_FLAGS:
|
||||
glt = R_GetTexture( arg );
|
||||
return glt->flags;
|
||||
return R_GetTexture( arg )->flags;
|
||||
case PARM_TEX_MEMORY:
|
||||
return GL_TexMemory();
|
||||
case PARM_ACTIVE_TMU:
|
||||
@@ -342,14 +327,12 @@ R_SetupSky
|
||||
*/
|
||||
static void GAME_EXPORT R_SetupSky( int *skyboxTextures )
|
||||
{
|
||||
int i;
|
||||
|
||||
R_UnloadSkybox();
|
||||
|
||||
if( !skyboxTextures )
|
||||
return;
|
||||
|
||||
for( i = 0; i < SKYBOX_MAX_SIDES; i++ )
|
||||
for( int i = 0; i < SKYBOX_MAX_SIDES; i++ )
|
||||
tr.skyboxTextures[i] = skyboxTextures[i];
|
||||
}
|
||||
|
||||
@@ -415,9 +398,6 @@ static const char *R_GetConfigName( void )
|
||||
|
||||
static void R_NewMap( void )
|
||||
{
|
||||
texture_t *tx;
|
||||
int i;
|
||||
|
||||
tr.worldmodel = gp_cl->models[1];
|
||||
|
||||
R_ClearDecals(); // clear all level decals
|
||||
@@ -425,7 +405,7 @@ static void R_NewMap( void )
|
||||
R_StudioResetPlayerModels();
|
||||
|
||||
// clear out efrags in case the level hasn't been reloaded
|
||||
for( i = 0; i < WORLDMODEL->numleafs; i++ )
|
||||
for( int i = 0; i < WORLDMODEL->numleafs; i++ )
|
||||
WORLDMODEL->leafs[i+1].efrags = NULL;
|
||||
|
||||
glState.isFogEnabled = false;
|
||||
@@ -433,12 +413,12 @@ static void R_NewMap( void )
|
||||
pglDisable( GL_FOG );
|
||||
|
||||
// clearing texture chains
|
||||
for( i = 0; i < WORLDMODEL->numtextures; i++ )
|
||||
for( int i = 0; i < WORLDMODEL->numtextures; i++ )
|
||||
{
|
||||
if( !WORLDMODEL->textures[i] )
|
||||
continue;
|
||||
|
||||
tx = WORLDMODEL->textures[i];
|
||||
texture_t *tx = WORLDMODEL->textures[i];
|
||||
|
||||
if( !Q_strncmp( tx->name, "sky", 3 ) && tx->width == ( tx->height * 2 ))
|
||||
tr.skytexturenum = i;
|
||||
|
||||
@@ -65,7 +65,7 @@ cull invisible surfaces
|
||||
*/
|
||||
int R_CullSurface( const msurface_t *surf, const gl_frustum_t *frustum, uint clipflags )
|
||||
{
|
||||
cl_entity_t *e = RI.currententity;
|
||||
const cl_entity_t *e = RI.currententity;
|
||||
|
||||
if( surf->visframe != tr.framecount && e == CL_GetEntityByIndex( 0 ))
|
||||
return CULL_VISFRAME;
|
||||
|
||||
@@ -63,8 +63,6 @@ void R_ClearDecals( void )
|
||||
// unlink pdecal from any surface it's attached to
|
||||
static void R_DecalUnlink( decal_t *pdecal )
|
||||
{
|
||||
decal_t *tmp;
|
||||
|
||||
if( pdecal->psurface )
|
||||
{
|
||||
if( pdecal->psurface->pdecals == pdecal )
|
||||
@@ -73,7 +71,7 @@ static void R_DecalUnlink( decal_t *pdecal )
|
||||
}
|
||||
else
|
||||
{
|
||||
tmp = pdecal->psurface->pdecals;
|
||||
decal_t *tmp = pdecal->psurface->pdecals;
|
||||
if( !tmp ) gEngfuncs.Host_Error( "%s: bad decal list\n", __func__ );
|
||||
|
||||
while( tmp->pnext )
|
||||
@@ -201,10 +199,8 @@ static void R_SetupDecalTextureSpaceBasis( decal_t *pDecal, msurface_t *surf, in
|
||||
// Build the initial list of vertices from the surface verts into the global array, 'verts'.
|
||||
static void R_SetupDecalVertsForMSurface( decal_t *pDecal, msurface_t *surf, vec3_t textureSpaceBasis[3], float *verts )
|
||||
{
|
||||
float *v;
|
||||
int i;
|
||||
|
||||
for( i = 0, v = surf->polys->verts[0]; i < surf->polys->numverts; i++, v += VERTEXSIZE, verts += VERTEXSIZE )
|
||||
float *v = surf->polys->verts[0];
|
||||
for( int i = 0; i < surf->polys->numverts; i++, v += VERTEXSIZE, verts += VERTEXSIZE )
|
||||
{
|
||||
VectorCopy( v, verts ); // copy model space coordinates
|
||||
verts[3] = DotProduct( verts, textureSpaceBasis[0] ) - pDecal->dx + 0.5f;
|
||||
@@ -255,8 +251,6 @@ static int R_ClipInside( float *vert, int edge )
|
||||
|
||||
static void R_ClipIntersect( float *one, float *two, float *out, int edge )
|
||||
{
|
||||
float t;
|
||||
|
||||
// t is the parameter of the line between one and two clipped to the edge
|
||||
// or the fraction of the clipped point between one & two
|
||||
// vert[0], vert[1], vert[2] is X, Y, Z
|
||||
@@ -265,6 +259,7 @@ static void R_ClipIntersect( float *one, float *two, float *out, int edge )
|
||||
// vert[5] is lightmap u
|
||||
// vert[6] is lightmap v
|
||||
|
||||
float t;
|
||||
if( edge < TOP_EDGE )
|
||||
{
|
||||
if( edge == LEFT_EDGE )
|
||||
@@ -307,16 +302,13 @@ static void R_ClipIntersect( float *one, float *two, float *out, int edge )
|
||||
|
||||
static int SHClip( float *vert, int vertCount, float *out, int edge )
|
||||
{
|
||||
int j, outCount;
|
||||
float *s, *p;
|
||||
int outCount = 0;
|
||||
|
||||
outCount = 0;
|
||||
float *s = &vert[(vertCount - 1) * VERTEXSIZE];
|
||||
|
||||
s = &vert[(vertCount - 1) * VERTEXSIZE];
|
||||
|
||||
for( j = 0; j < vertCount; j++ )
|
||||
for( int j = 0; j < vertCount; j++ )
|
||||
{
|
||||
p = &vert[j * VERTEXSIZE];
|
||||
float *p = &vert[j * VERTEXSIZE];
|
||||
|
||||
if( R_ClipInside( p, edge ))
|
||||
{
|
||||
@@ -356,11 +348,10 @@ static int SHClip( float *vert, int vertCount, float *out, int edge )
|
||||
|
||||
static float *R_DoDecalSHClip( float *pInVerts, decal_t *pDecal, int nStartVerts, int *pVertCount )
|
||||
{
|
||||
float *pOutVerts = g_DecalClipVerts[0];
|
||||
int outCount;
|
||||
float *pOutVerts = g_DecalClipVerts[0];
|
||||
|
||||
// clip the polygon to the decal texture space
|
||||
outCount = SHClip( pInVerts, nStartVerts, g_DecalClipVerts2[0], LEFT_EDGE );
|
||||
int outCount = SHClip( pInVerts, nStartVerts, g_DecalClipVerts2[0], LEFT_EDGE );
|
||||
outCount = SHClip( g_DecalClipVerts2[0], outCount, g_DecalClipVerts[0], RIGHT_EDGE );
|
||||
outCount = SHClip( g_DecalClipVerts[0], outCount, g_DecalClipVerts2[0], TOP_EDGE );
|
||||
outCount = SHClip( g_DecalClipVerts2[0], outCount, pOutVerts, BOTTOM_EDGE );
|
||||
@@ -391,12 +382,9 @@ static float *R_DecalVertsClip( decal_t *pDecal, msurface_t *surf, int texture,
|
||||
// Generate lighting coordinates at each vertex for decal vertices v[] on surface psurf
|
||||
static void R_DecalVertsLight( float *v, msurface_t *surf, int vertCount )
|
||||
{
|
||||
float sample_size;
|
||||
int j;
|
||||
float sample_size = gEngfuncs.Mod_SampleSizeForFace( surf );
|
||||
|
||||
sample_size = gEngfuncs.Mod_SampleSizeForFace( surf );
|
||||
|
||||
for( j = 0; j < vertCount; j++, v += VERTEXSIZE )
|
||||
for( int j = 0; j < vertCount; j++, v += VERTEXSIZE )
|
||||
{
|
||||
// lightmap texture coordinates
|
||||
R_LightmapCoord( v, surf, sample_size, &v[5] );
|
||||
@@ -406,24 +394,21 @@ static void R_DecalVertsLight( float *v, msurface_t *surf, int vertCount )
|
||||
// Check for intersecting decals on this surface
|
||||
static decal_t *R_DecalIntersect( decalinfo_t *decalinfo, msurface_t *surf, int *pcount )
|
||||
{
|
||||
int texture;
|
||||
decal_t *plast, *pDecal;
|
||||
vec3_t decalExtents[2];
|
||||
float lastArea = 2;
|
||||
int mapSize[2];
|
||||
|
||||
plast = NULL;
|
||||
decal_t *plast = NULL;
|
||||
float lastArea = 2;
|
||||
*pcount = 0;
|
||||
|
||||
// (Same as R_SetupDecalClip).
|
||||
texture = decalinfo->m_iTexture;
|
||||
int texture = decalinfo->m_iTexture;
|
||||
|
||||
// precalculate the extents of decalinfo's decal in world space.
|
||||
int mapSize[2];
|
||||
R_GetDecalDimensions( texture, &mapSize[0], &mapSize[1] );
|
||||
vec3_t decalExtents[2];
|
||||
VectorScale( decalinfo->m_Basis[0], ((mapSize[0] / decalinfo->m_scale) * 0.5f), decalExtents[0] );
|
||||
VectorScale( decalinfo->m_Basis[1], ((mapSize[1] / decalinfo->m_scale) * 0.5f), decalExtents[1] );
|
||||
|
||||
pDecal = surf->pdecals;
|
||||
decal_t *pDecal = surf->pdecals;
|
||||
|
||||
while( pDecal )
|
||||
{
|
||||
@@ -494,26 +479,22 @@ creates mesh for decal on first rendering
|
||||
*/
|
||||
static glpoly2_t *R_DecalCreatePoly( decalinfo_t *decalinfo, decal_t *pdecal, msurface_t *surf )
|
||||
{
|
||||
int lnumverts;
|
||||
glpoly2_t *poly;
|
||||
float *v;
|
||||
int i;
|
||||
|
||||
if( pdecal->polys ) // already created?
|
||||
return pdecal->polys;
|
||||
|
||||
v = R_DecalSetupVerts( pdecal, surf, pdecal->texture, &lnumverts );
|
||||
int lnumverts;
|
||||
float *v = R_DecalSetupVerts( pdecal, surf, pdecal->texture, &lnumverts );
|
||||
if( !lnumverts ) return NULL; // probably this never happens
|
||||
|
||||
// allocate glpoly
|
||||
// REFTODO: com_studiocache pool!
|
||||
poly = Mem_Calloc( r_temppool, sizeof( glpoly2_t ) + lnumverts * VERTEXSIZE * sizeof( float ));
|
||||
glpoly2_t *poly = Mem_Calloc( r_temppool, sizeof( glpoly2_t ) + lnumverts * VERTEXSIZE * sizeof( float ));
|
||||
poly->next = pdecal->polys;
|
||||
poly->flags = surf->flags;
|
||||
pdecal->polys = poly;
|
||||
poly->numverts = lnumverts;
|
||||
|
||||
for( i = 0; i < lnumverts; i++, v += VERTEXSIZE )
|
||||
for( int i = 0; i < lnumverts; i++, v += VERTEXSIZE )
|
||||
{
|
||||
VectorCopy( v, poly->verts[i] );
|
||||
poly->verts[i][3] = v[3];
|
||||
@@ -528,10 +509,8 @@ static glpoly2_t *R_DecalCreatePoly( decalinfo_t *decalinfo, decal_t *pdecal, ms
|
||||
// Add the decal to the surface's list of decals.
|
||||
static void R_AddDecalToSurface( decal_t *pdecal, msurface_t *surf, decalinfo_t *decalinfo )
|
||||
{
|
||||
decal_t *pold;
|
||||
|
||||
pdecal->pnext = NULL;
|
||||
pold = surf->pdecals;
|
||||
decal_t *pold = surf->pdecals;
|
||||
|
||||
if( pold )
|
||||
{
|
||||
@@ -558,15 +537,13 @@ static void R_AddDecalToSurface( decal_t *pdecal, msurface_t *surf, decalinfo_t
|
||||
|
||||
static void R_DecalCreate( decalinfo_t *decalinfo, msurface_t *surf, float x, float y )
|
||||
{
|
||||
decal_t *pdecal, *pold;
|
||||
int count, vertCount;
|
||||
|
||||
if( !surf ) return; // ???
|
||||
|
||||
pold = R_DecalIntersect( decalinfo, surf, &count );
|
||||
int count;
|
||||
decal_t *pold = R_DecalIntersect( decalinfo, surf, &count );
|
||||
if( count < MAX_OVERLAP_DECALS ) pold = NULL;
|
||||
|
||||
pdecal = R_DecalAlloc( pold );
|
||||
decal_t *pdecal = R_DecalAlloc( pold );
|
||||
if( !pdecal ) return; // r_decals == 0 ???
|
||||
|
||||
pdecal->flags = decalinfo->m_Flags;
|
||||
@@ -583,6 +560,7 @@ static void R_DecalCreate( decalinfo_t *decalinfo, msurface_t *surf, float x, fl
|
||||
|
||||
// check to see if the decal actually intersects the surface
|
||||
// if not, then remove the decal
|
||||
int vertCount;
|
||||
R_DecalVertsClip( pdecal, surf, decalinfo->m_iTexture, &vertCount );
|
||||
|
||||
if( !vertCount )
|
||||
@@ -598,10 +576,7 @@ static void R_DecalCreate( decalinfo_t *decalinfo, msurface_t *surf, float x, fl
|
||||
static void R_DecalSurface( msurface_t *surf, decalinfo_t *decalinfo )
|
||||
{
|
||||
// get the texture associated with this surface
|
||||
mtexinfo_t *tex = surf->texinfo;
|
||||
decal_t *decal = surf->pdecals;
|
||||
vec4_t textureU, textureV;
|
||||
float s, t, w, h;
|
||||
mtexinfo_t *tex = surf->texinfo;
|
||||
connstate_t state = ENGINE_GET_PARM( PARM_CONNSTATE );
|
||||
|
||||
// we in restore mode
|
||||
@@ -609,6 +584,7 @@ static void R_DecalSurface( msurface_t *surf, decalinfo_t *decalinfo )
|
||||
{
|
||||
// NOTE: we may have the decal on this surface that come from another level.
|
||||
// check duplicate with same position and texture
|
||||
decal_t *decal = surf->pdecals;
|
||||
while( decal != NULL )
|
||||
{
|
||||
if( VectorCompare( decal->position, decalinfo->m_Position ) && decal->texture == decalinfo->m_iTexture )
|
||||
@@ -617,12 +593,13 @@ static void R_DecalSurface( msurface_t *surf, decalinfo_t *decalinfo )
|
||||
}
|
||||
}
|
||||
|
||||
vec4_t textureU, textureV;
|
||||
Vector4Copy( tex->vecs[0], textureU );
|
||||
Vector4Copy( tex->vecs[1], textureV );
|
||||
|
||||
// project decal center into the texture space of the surface
|
||||
s = DotProduct( decalinfo->m_Position, textureU ) + textureU[3] - surf->texturemins[0];
|
||||
t = DotProduct( decalinfo->m_Position, textureV ) + textureV[3] - surf->texturemins[1];
|
||||
float s = DotProduct( decalinfo->m_Position, textureU ) + textureU[3] - surf->texturemins[0];
|
||||
float t = DotProduct( decalinfo->m_Position, textureV ) + textureV[3] - surf->texturemins[1];
|
||||
|
||||
// Determine the decal basis (measured in world space)
|
||||
// Note that the decal basis vectors 0 and 1 will always lie in the same
|
||||
@@ -642,10 +619,10 @@ static void R_DecalSurface( msurface_t *surf, decalinfo_t *decalinfo )
|
||||
// (decalWidth * decalBasis[0], decalHeight * decalBasis[1])
|
||||
// in texture coordinates:
|
||||
|
||||
w = fabs( decalinfo->m_decalWidth * DotProduct( textureU, decalinfo->m_Basis[0] )) +
|
||||
float w = fabs( decalinfo->m_decalWidth * DotProduct( textureU, decalinfo->m_Basis[0] )) +
|
||||
fabs( decalinfo->m_decalHeight * DotProduct( textureU, decalinfo->m_Basis[1] ));
|
||||
|
||||
h = fabs( decalinfo->m_decalWidth * DotProduct( textureV, decalinfo->m_Basis[0] )) +
|
||||
float h = fabs( decalinfo->m_decalWidth * DotProduct( textureV, decalinfo->m_Basis[0] )) +
|
||||
fabs( decalinfo->m_decalHeight * DotProduct( textureV, decalinfo->m_Basis[1] ));
|
||||
|
||||
// move s,t to upper left corner
|
||||
@@ -668,16 +645,12 @@ static void R_DecalSurface( msurface_t *surf, decalinfo_t *decalinfo )
|
||||
static void R_DecalNodeSurfaces( model_t *model, mnode_t *node, decalinfo_t *decalinfo )
|
||||
{
|
||||
// iterate over all surfaces in the node
|
||||
msurface_t *surf;
|
||||
int i;
|
||||
int firstsurface, numsurfaces;
|
||||
int firstsurface = node_firstsurface( node, model );
|
||||
int numsurfaces = node_numsurfaces( node, model );
|
||||
|
||||
firstsurface = node_firstsurface( node, model );
|
||||
numsurfaces = node_numsurfaces( node, model );
|
||||
msurface_t *surf = model->surfaces + firstsurface;
|
||||
|
||||
surf = model->surfaces + firstsurface;
|
||||
|
||||
for( i = 0; i < numsurfaces; i++, surf++ )
|
||||
for( int i = 0; i < numsurfaces; i++, surf++ )
|
||||
{
|
||||
// never apply decals on the water or sky surfaces
|
||||
if( surf->flags & (SURF_DRAWTURB|SURF_DRAWSKY|SURF_CONVEYOR))
|
||||
@@ -697,17 +670,14 @@ static void R_DecalNodeSurfaces( model_t *model, mnode_t *node, decalinfo_t *dec
|
||||
//-----------------------------------------------------------------------------
|
||||
static void R_DecalNode( model_t *model, mnode_t *node, decalinfo_t *decalinfo )
|
||||
{
|
||||
mplane_t *splitplane;
|
||||
float dist;
|
||||
|
||||
if( node->contents < 0 )
|
||||
{
|
||||
// hit a leaf
|
||||
return;
|
||||
}
|
||||
|
||||
splitplane = node->plane;
|
||||
dist = DotProduct( decalinfo->m_Position, splitplane->normal ) - splitplane->dist;
|
||||
mplane_t *splitplane = node->plane;
|
||||
float dist = DotProduct( decalinfo->m_Position, splitplane->normal ) - splitplane->dist;
|
||||
|
||||
if( dist > decalinfo->m_Size )
|
||||
{
|
||||
@@ -730,18 +700,14 @@ static void R_DecalNode( model_t *model, mnode_t *node, decalinfo_t *decalinfo )
|
||||
// Shoots a decal onto the surface of the BSP. position is the center of the decal in world coords
|
||||
void R_DecalShoot( int textureIndex, int entityIndex, int modelIndex, vec3_t pos, int flags, float scale )
|
||||
{
|
||||
decalinfo_t decalInfo;
|
||||
cl_entity_t *ent = NULL;
|
||||
model_t *model = NULL;
|
||||
int width, height;
|
||||
hull_t *hull;
|
||||
|
||||
if( textureIndex <= 0 || textureIndex >= MAX_TEXTURES )
|
||||
{
|
||||
gEngfuncs.Con_Printf( S_ERROR "Decal has invalid texture!\n" );
|
||||
return;
|
||||
}
|
||||
|
||||
cl_entity_t *ent = NULL;
|
||||
model_t *model = NULL;
|
||||
if( entityIndex > 0 )
|
||||
{
|
||||
ent = CL_GetEntityByIndex( entityIndex );
|
||||
@@ -762,19 +728,20 @@ void R_DecalShoot( int textureIndex, int entityIndex, int modelIndex, vec3_t pos
|
||||
return;
|
||||
}
|
||||
|
||||
decalinfo_t decalInfo;
|
||||
decalInfo.m_pModel = model;
|
||||
hull = &model->hulls[0]; // always use #0 hull
|
||||
hull_t *hull = &model->hulls[0]; // always use #0 hull
|
||||
|
||||
// NOTE: all the decals at 'first shoot' placed into local space of parent entity
|
||||
// and won't transform again on a next restore, levelchange etc
|
||||
if( ent && !FBitSet( flags, FDECAL_LOCAL_SPACE ))
|
||||
{
|
||||
vec3_t pos_l;
|
||||
vec3_t pos_l;
|
||||
|
||||
// transform decal position in local bmodel space
|
||||
if( !VectorIsNull( ent->angles ))
|
||||
{
|
||||
matrix4x4 matrix;
|
||||
matrix4x4 matrix;
|
||||
|
||||
Matrix4x4_CreateFromEntity( matrix, ent->angles, ent->origin, 1.0f );
|
||||
Matrix4x4_VectorITransform( matrix, pos, pos_l );
|
||||
@@ -804,6 +771,7 @@ void R_DecalShoot( int textureIndex, int entityIndex, int modelIndex, vec3_t pos
|
||||
decalInfo.m_Entity = entityIndex;
|
||||
decalInfo.m_Flags = flags;
|
||||
|
||||
int width, height;
|
||||
R_GetDecalDimensions( textureIndex, &width, &height );
|
||||
decalInfo.m_Size = width >> 1;
|
||||
if(( height >> 1 ) > decalInfo.m_Size )
|
||||
@@ -823,18 +791,18 @@ void R_DecalShoot( int textureIndex, int entityIndex, int modelIndex, vec3_t pos
|
||||
// triangles the same way.
|
||||
float *R_DecalSetupVerts( decal_t *pDecal, msurface_t *surf, int texture, int *outCount )
|
||||
{
|
||||
glpoly2_t *p = pDecal->polys;
|
||||
int i, count;
|
||||
float *v, *v2;
|
||||
glpoly2_t *p = pDecal->polys;
|
||||
float *v;
|
||||
int count;
|
||||
|
||||
if( p )
|
||||
{
|
||||
v = g_DecalClipVerts[0];
|
||||
count = p->numverts;
|
||||
v2 = p->verts[0];
|
||||
float *v2 = p->verts[0];
|
||||
|
||||
// if we have mesh so skip clipping and just copy vertexes out (perf)
|
||||
for( i = 0; i < count; i++, v += VERTEXSIZE, v2 += VERTEXSIZE )
|
||||
for( int i = 0; i < count; i++, v += VERTEXSIZE, v2 += VERTEXSIZE )
|
||||
{
|
||||
VectorCopy( v2, v );
|
||||
v[3] = v2[3];
|
||||
@@ -860,10 +828,8 @@ float *R_DecalSetupVerts( decal_t *pDecal, msurface_t *surf, int texture, int *o
|
||||
|
||||
void DrawSingleDecal( decal_t *pDecal, msurface_t *fa )
|
||||
{
|
||||
float *v;
|
||||
int i, numVerts;
|
||||
|
||||
v = R_DecalSetupVerts( pDecal, fa, pDecal->texture, &numVerts );
|
||||
int numVerts;
|
||||
float *v = R_DecalSetupVerts( pDecal, fa, pDecal->texture, &numVerts );
|
||||
if( !numVerts ) return;
|
||||
|
||||
GL_Bind( XASH_TEXTURE0, pDecal->texture );
|
||||
@@ -874,7 +840,7 @@ void DrawSingleDecal( decal_t *pDecal, msurface_t *fa )
|
||||
|
||||
pglBegin( GL_POLYGON );
|
||||
|
||||
for( i = 0; i < numVerts; i++, v += VERTEXSIZE )
|
||||
for( int i = 0; i < numVerts; i++, v += VERTEXSIZE )
|
||||
{
|
||||
pglTexCoord2f( v[3], v[4] );
|
||||
pglVertex3fv( v );
|
||||
@@ -885,12 +851,9 @@ void DrawSingleDecal( decal_t *pDecal, msurface_t *fa )
|
||||
|
||||
void DrawSurfaceDecals( msurface_t *fa, qboolean single, qboolean reverse )
|
||||
{
|
||||
decal_t *p;
|
||||
cl_entity_t *e;
|
||||
|
||||
if( !fa->pdecals ) return;
|
||||
|
||||
e = RI.currententity;
|
||||
cl_entity_t *e = RI.currententity;
|
||||
Assert( e != NULL );
|
||||
|
||||
if( single )
|
||||
@@ -916,15 +879,14 @@ void DrawSurfaceDecals( msurface_t *fa, qboolean single, qboolean reverse )
|
||||
|
||||
if( FBitSet( fa->flags, SURF_TRANSPARENT ) && glState.stencilEnabled )
|
||||
{
|
||||
mtexinfo_t *tex = fa->texinfo;
|
||||
mtexinfo_t *tex = fa->texinfo;
|
||||
|
||||
for( p = fa->pdecals; p; p = p->pnext )
|
||||
for( decal_t *p = fa->pdecals; p; p = p->pnext )
|
||||
{
|
||||
if( p->texture )
|
||||
{
|
||||
float *o, *v;
|
||||
int i, numVerts;
|
||||
o = R_DecalSetupVerts( p, fa, p->texture, &numVerts );
|
||||
int numVerts;
|
||||
float *o = R_DecalSetupVerts( p, fa, p->texture, &numVerts );
|
||||
|
||||
pglEnable( GL_STENCIL_TEST );
|
||||
pglStencilFunc( GL_ALWAYS, 1, 0xFFFFFFFF );
|
||||
@@ -933,7 +895,8 @@ void DrawSurfaceDecals( msurface_t *fa, qboolean single, qboolean reverse )
|
||||
pglStencilOp( GL_KEEP, GL_KEEP, GL_REPLACE );
|
||||
pglBegin( GL_POLYGON );
|
||||
|
||||
for( i = 0, v = o; i < numVerts; i++, v += VERTEXSIZE )
|
||||
float *v = o;
|
||||
for( int i = 0; i < numVerts; i++, v += VERTEXSIZE )
|
||||
{
|
||||
v[5] = ( DotProduct( v, tex->vecs[0] ) + tex->vecs[0][3] ) / tex->texture->width;
|
||||
v[6] = ( DotProduct( v, tex->vecs[1] ) + tex->vecs[1][3] ) / tex->texture->height;
|
||||
@@ -948,7 +911,8 @@ void DrawSurfaceDecals( msurface_t *fa, qboolean single, qboolean reverse )
|
||||
pglEnable( GL_ALPHA_TEST );
|
||||
pglBegin( GL_POLYGON );
|
||||
|
||||
for( i = 0, v = o; i < numVerts; i++, v += VERTEXSIZE )
|
||||
v = o;
|
||||
for( int i = 0; i < numVerts; i++, v += VERTEXSIZE )
|
||||
{
|
||||
pglTexCoord2f( v[5], v[6] );
|
||||
pglVertex3fv( v );
|
||||
@@ -968,18 +932,18 @@ void DrawSurfaceDecals( msurface_t *fa, qboolean single, qboolean reverse )
|
||||
|
||||
if( reverse && e->curstate.rendermode == kRenderTransTexture )
|
||||
{
|
||||
decal_t *list[1024];
|
||||
int i, count;
|
||||
decal_t *list[1024];
|
||||
int count = 0;
|
||||
|
||||
for( p = fa->pdecals, count = 0; p && count < 1024; p = p->pnext )
|
||||
for( decal_t *p = fa->pdecals; p && count < 1024; p = p->pnext )
|
||||
if( p->texture ) list[count++] = p;
|
||||
|
||||
for( i = count - 1; i >= 0; i-- )
|
||||
for( int i = count - 1; i >= 0; i-- )
|
||||
DrawSingleDecal( list[i], fa );
|
||||
}
|
||||
else
|
||||
{
|
||||
for( p = fa->pdecals; p; p = p->pnext )
|
||||
for( decal_t *p = fa->pdecals; p; p = p->pnext )
|
||||
{
|
||||
if( !p->texture ) continue;
|
||||
DrawSingleDecal( p, fa );
|
||||
@@ -1019,13 +983,10 @@ void DrawSurfaceDecals( msurface_t *fa, qboolean single, qboolean reverse )
|
||||
|
||||
void DrawDecalsBatch( void )
|
||||
{
|
||||
cl_entity_t *e;
|
||||
int i;
|
||||
|
||||
if( !tr.num_draw_decals )
|
||||
return;
|
||||
|
||||
e = RI.currententity;
|
||||
cl_entity_t *e = RI.currententity;
|
||||
Assert( e != NULL );
|
||||
|
||||
if( e->curstate.rendermode != kRenderTransTexture )
|
||||
@@ -1041,7 +1002,7 @@ void DrawDecalsBatch( void )
|
||||
if( gl_polyoffset.value )
|
||||
GL_PushPolygonOffset( -1.0f, -gl_polyoffset.value );
|
||||
|
||||
for( i = 0; i < tr.num_draw_decals; i++ )
|
||||
for( int i = 0; i < tr.num_draw_decals; i++ )
|
||||
{
|
||||
DrawSurfaceDecals( tr.draw_decals[i], false, false );
|
||||
}
|
||||
@@ -1093,16 +1054,13 @@ static qboolean R_DecalUnProject( decal_t *pdecal, decallist_t *entry )
|
||||
//-----------------------------------------------------------------------------
|
||||
static int DecalListAdd( decallist_t *pList, int count )
|
||||
{
|
||||
vec3_t tmp;
|
||||
decallist_t *pdecal;
|
||||
int i;
|
||||
decallist_t *pdecal = pList + count;
|
||||
|
||||
pdecal = pList + count;
|
||||
|
||||
for( i = 0; i < count; i++ )
|
||||
for( int i = 0; i < count; i++ )
|
||||
{
|
||||
if( !Q_strcmp( pdecal->name, pList[i].name ) && pdecal->entityIndex == pList[i].entityIndex )
|
||||
{
|
||||
vec3_t tmp;
|
||||
VectorSubtract( pdecal->position, pList[i].position, tmp ); // Merge
|
||||
|
||||
if( VectorLength( tmp ) < DECAL_OVERLAP_DISTANCE )
|
||||
@@ -1116,10 +1074,8 @@ static int DecalListAdd( decallist_t *pList, int count )
|
||||
|
||||
static int DecalDepthCompare( const void *a, const void *b )
|
||||
{
|
||||
const decallist_t *elem1, *elem2;
|
||||
|
||||
elem1 = (const decallist_t *)a;
|
||||
elem2 = (const decallist_t *)b;
|
||||
const decallist_t *elem1 = (const decallist_t *)a;
|
||||
const decallist_t *elem2 = (const decallist_t *)b;
|
||||
|
||||
if( elem1->depth > elem2->depth )
|
||||
return 1;
|
||||
@@ -1136,23 +1092,21 @@ static int DecalDepthCompare( const void *a, const void *b )
|
||||
//-----------------------------------------------------------------------------
|
||||
int R_CreateDecalList( decallist_t *pList )
|
||||
{
|
||||
int total = 0;
|
||||
int i, depth;
|
||||
int total = 0;
|
||||
|
||||
if( WORLDMODEL )
|
||||
{
|
||||
for( i = 0; i < MAX_RENDER_DECALS; i++ )
|
||||
for( int i = 0; i < MAX_RENDER_DECALS; i++ )
|
||||
{
|
||||
decal_t *decal = &gDecalPool[i];
|
||||
decal_t *pdecals;
|
||||
decal_t *decal = &gDecalPool[i];
|
||||
|
||||
// decal is in use and is not a custom decal
|
||||
if( decal->psurface == NULL || FBitSet( decal->flags, FDECAL_DONTSAVE ))
|
||||
continue;
|
||||
|
||||
// compute depth
|
||||
depth = 0;
|
||||
pdecals = decal->psurface->pdecals;
|
||||
int depth = 0;
|
||||
decal_t *pdecals = decal->psurface->pdecals;
|
||||
|
||||
while( pdecals && pdecals != decal )
|
||||
{
|
||||
@@ -1192,15 +1146,12 @@ remove all decals with specified texture
|
||||
*/
|
||||
void R_DecalRemoveAll( int textureIndex )
|
||||
{
|
||||
decal_t *pdecal;
|
||||
int i;
|
||||
|
||||
if( textureIndex < 0 || textureIndex >= MAX_TEXTURES )
|
||||
return; // out of bounds
|
||||
|
||||
for( i = 0; i < gDecalCount; i++ )
|
||||
for( int i = 0; i < gDecalCount; i++ )
|
||||
{
|
||||
pdecal = &gDecalPool[i];
|
||||
decal_t *pdecal = &gDecalPool[i];
|
||||
|
||||
// don't remove permanent decals
|
||||
if( FBitSet( pdecal->flags, FDECAL_PERMANENT ))
|
||||
@@ -1220,17 +1171,13 @@ remove all decals from specified entity
|
||||
*/
|
||||
void R_EntityRemoveDecals( model_t *mod )
|
||||
{
|
||||
msurface_t *psurf;
|
||||
decal_t *p;
|
||||
int i;
|
||||
|
||||
if( !mod || mod->type != mod_brush )
|
||||
return;
|
||||
|
||||
psurf = &mod->surfaces[mod->firstmodelsurface];
|
||||
for( i = 0; i < mod->nummodelsurfaces; i++, psurf++ )
|
||||
msurface_t *psurf = &mod->surfaces[mod->firstmodelsurface];
|
||||
for( int i = 0; i < mod->nummodelsurfaces; i++, psurf++ )
|
||||
{
|
||||
for( p = psurf->pdecals; p; p = p->pnext )
|
||||
for( decal_t *p = psurf->pdecals; p; p = p->pnext )
|
||||
R_DecalUnlink( p );
|
||||
}
|
||||
}
|
||||
@@ -1245,13 +1192,10 @@ used for full decals restart
|
||||
*/
|
||||
void R_ClearAllDecals( void )
|
||||
{
|
||||
decal_t *pdecal;
|
||||
int i;
|
||||
|
||||
// because gDecalCount may be zeroed after recach the decal limit
|
||||
for( i = 0; i < MAX_RENDER_DECALS; i++ )
|
||||
for( int i = 0; i < MAX_RENDER_DECALS; i++ )
|
||||
{
|
||||
pdecal = &gDecalPool[i];
|
||||
decal_t *pdecal = &gDecalPool[i];
|
||||
R_DecalUnlink( pdecal );
|
||||
}
|
||||
|
||||
|
||||
@@ -22,9 +22,8 @@ R_GetImageParms
|
||||
*/
|
||||
void R_GetTextureParms( int *w, int *h, int texnum )
|
||||
{
|
||||
gl_texture_t *glt;
|
||||
gl_texture_t *glt = R_GetTexture( texnum );
|
||||
|
||||
glt = R_GetTexture( texnum );
|
||||
if( w ) *w = glt->srcWidth;
|
||||
if( h ) *h = glt->srcHeight;
|
||||
}
|
||||
@@ -60,9 +59,7 @@ GL_UpdateTexture
|
||||
*/
|
||||
void GL_UpdateTexture( int texnum, int cols, int rows, int width, int height, const byte *buffer, pixformat_t fmt )
|
||||
{
|
||||
byte *raw = NULL;
|
||||
gl_texture_t *tex;
|
||||
GLenum gl_format;
|
||||
GLenum gl_format;
|
||||
|
||||
switch( fmt )
|
||||
{
|
||||
@@ -92,6 +89,7 @@ void GL_UpdateTexture( int texnum, int cols, int rows, int width, int height, co
|
||||
height = NearestPOW( height, false );
|
||||
}
|
||||
|
||||
byte *raw;
|
||||
if( cols != width || rows != height )
|
||||
{
|
||||
raw = GL_ResampleTexture( buffer, cols, rows, width, height, false );
|
||||
@@ -106,7 +104,7 @@ void GL_UpdateTexture( int texnum, int cols, int rows, int width, int height, co
|
||||
if( rows > glConfig.max_2d_texture_size )
|
||||
gEngfuncs.Host_Error( "%s: size %i exceeds hardware limits\n", __func__, rows );
|
||||
|
||||
tex = R_GetTexture( texnum );
|
||||
gl_texture_t *tex = R_GetTexture( texnum );
|
||||
GL_Bind( GL_KEEP_UNIT, texnum );
|
||||
|
||||
if( cols == tex->width && rows == tex->height )
|
||||
@@ -130,11 +128,11 @@ void R_Set2DMode( qboolean enable )
|
||||
{
|
||||
if( enable )
|
||||
{
|
||||
matrix4x4 projection_matrix, worldview_matrix;
|
||||
|
||||
if( glState.in2DMode )
|
||||
return;
|
||||
|
||||
matrix4x4 projection_matrix;
|
||||
|
||||
// set 2D virtual screen size
|
||||
switch( tr.rotation )
|
||||
{
|
||||
@@ -160,6 +158,7 @@ void R_Set2DMode( qboolean enable )
|
||||
GL_LoadMatrix( projection_matrix );
|
||||
|
||||
pglMatrixMode( GL_MODELVIEW );
|
||||
matrix4x4 worldview_matrix;
|
||||
Matrix4x4_LoadIdentity( worldview_matrix );
|
||||
GL_LoadMatrix( worldview_matrix );
|
||||
|
||||
|
||||
@@ -30,9 +30,8 @@ static void GL_FrustumSetPlane( gl_frustum_t *out, int side, const vec3_t vecNor
|
||||
|
||||
void GL_FrustumInitProj( gl_frustum_t *out, float flZNear, float flZFar, float flFovX, float flFovY )
|
||||
{
|
||||
float xs, xc;
|
||||
vec3_t farpoint, nearpoint;
|
||||
vec3_t normal, iforward;
|
||||
float xs, xc;
|
||||
|
||||
// horizontal fov used for left and right planes
|
||||
SinCos( DEG2RAD( flFovX ) * 0.5f, &xs, &xc );
|
||||
@@ -58,6 +57,7 @@ void GL_FrustumInitProj( gl_frustum_t *out, float flZNear, float flZFar, float f
|
||||
GL_FrustumSetPlane( out, FRUSTUM_TOP, normal, DotProduct( RI.cullorigin, normal ));
|
||||
|
||||
// setup far plane
|
||||
vec3_t farpoint;
|
||||
VectorMA( RI.cullorigin, flZFar, RI.cull_vforward, farpoint );
|
||||
GL_FrustumSetPlane( out, FRUSTUM_FAR, iforward, DotProduct( iforward, farpoint ));
|
||||
|
||||
@@ -65,16 +65,16 @@ void GL_FrustumInitProj( gl_frustum_t *out, float flZNear, float flZFar, float f
|
||||
if( flZNear == 0.0f ) return;
|
||||
|
||||
// setup near plane
|
||||
vec3_t nearpoint;
|
||||
VectorMA( RI.cullorigin, flZNear, RI.cull_vforward, nearpoint );
|
||||
GL_FrustumSetPlane( out, FRUSTUM_NEAR, RI.cull_vforward, DotProduct( RI.cull_vforward, nearpoint ));
|
||||
}
|
||||
|
||||
void GL_FrustumInitOrtho( gl_frustum_t *out, float xLeft, float xRight, float yTop, float yBottom, float flZNear, float flZFar )
|
||||
{
|
||||
vec3_t iforward, iright, iup;
|
||||
|
||||
// setup the near and far planes
|
||||
float orgOffset = DotProduct( RI.cullorigin, RI.cull_vforward );
|
||||
vec3_t iforward;
|
||||
VectorNegate( RI.cull_vforward, iforward );
|
||||
|
||||
// because quake ortho is inverted and far and near should be swaped
|
||||
@@ -83,6 +83,7 @@ void GL_FrustumInitOrtho( gl_frustum_t *out, float xLeft, float xRight, float yT
|
||||
|
||||
// setup left and right planes
|
||||
orgOffset = DotProduct( RI.cullorigin, RI.cull_vright );
|
||||
vec3_t iright;
|
||||
VectorNegate( RI.cull_vright, iright );
|
||||
|
||||
GL_FrustumSetPlane( out, FRUSTUM_LEFT, RI.cull_vright, xLeft + orgOffset );
|
||||
@@ -90,6 +91,7 @@ void GL_FrustumInitOrtho( gl_frustum_t *out, float xLeft, float xRight, float yT
|
||||
|
||||
// setup top and buttom planes
|
||||
orgOffset = DotProduct( RI.cullorigin, RI.cull_vup );
|
||||
vec3_t iup;
|
||||
VectorNegate( RI.cull_vup, iup );
|
||||
|
||||
GL_FrustumSetPlane( out, FRUSTUM_TOP, RI.cull_vup, yTop + orgOffset );
|
||||
@@ -100,7 +102,6 @@ void GL_FrustumInitOrtho( gl_frustum_t *out, float xLeft, float xRight, float yT
|
||||
qboolean GL_FrustumCullBox( const gl_frustum_t *out, const vec3_t mins, const vec3_t maxs, int userClipFlags )
|
||||
{
|
||||
int iClipFlags = userClipFlags != 0 ? userClipFlags : out->clipFlags;
|
||||
int i, bit;
|
||||
|
||||
if( unlikely( r_nocull.value ))
|
||||
return false;
|
||||
@@ -108,7 +109,7 @@ qboolean GL_FrustumCullBox( const gl_frustum_t *out, const vec3_t mins, const ve
|
||||
if( !iClipFlags )
|
||||
return false;
|
||||
|
||||
for( i = FRUSTUM_PLANES, bit = 1; i > 0; i--, bit <<= 1 )
|
||||
for( int i = FRUSTUM_PLANES, bit = 1; i > 0; i--, bit <<= 1 )
|
||||
{
|
||||
const mplane_t *p = &out->planes[FRUSTUM_PLANES - i];
|
||||
|
||||
@@ -160,7 +161,6 @@ qboolean GL_FrustumCullBox( const gl_frustum_t *out, const vec3_t mins, const ve
|
||||
qboolean GL_FrustumCullSphere( const gl_frustum_t *out, const vec3_t center, float radius, int userClipFlags )
|
||||
{
|
||||
int iClipFlags = userClipFlags != 0 ? userClipFlags : out->clipFlags;
|
||||
int i, bit;
|
||||
|
||||
if( unlikely( r_nocull.value ))
|
||||
return false;
|
||||
@@ -168,7 +168,7 @@ qboolean GL_FrustumCullSphere( const gl_frustum_t *out, const vec3_t center, flo
|
||||
if( !iClipFlags )
|
||||
return false;
|
||||
|
||||
for( i = FRUSTUM_PLANES, bit = 1; i > 0; i--, bit <<= 1 )
|
||||
for( int i = FRUSTUM_PLANES, bit = 1; i > 0; i--, bit <<= 1 )
|
||||
{
|
||||
const mplane_t *p = &out->planes[FRUSTUM_PLANES - i];
|
||||
|
||||
|
||||
@@ -98,9 +98,6 @@ GL_ApplyTextureParams
|
||||
*/
|
||||
void GL_ApplyTextureParams( gl_texture_t *tex )
|
||||
{
|
||||
vec4_t border = { 0.0f, 0.0f, 0.0f, 1.0f };
|
||||
qboolean nomipmap;
|
||||
|
||||
if( !glw_state.initialized )
|
||||
return;
|
||||
|
||||
@@ -111,7 +108,7 @@ void GL_ApplyTextureParams( gl_texture_t *tex )
|
||||
return;
|
||||
|
||||
// set texture filter
|
||||
nomipmap = tex->numMips <= 1 || FBitSet( tex->flags, TF_NOMIPMAP|TF_DEPTHMAP );
|
||||
qboolean nomipmap = tex->numMips <= 1 || FBitSet( tex->flags, TF_NOMIPMAP|TF_DEPTHMAP );
|
||||
if( !GL_TextureFilteringEnabled( tex ))
|
||||
{
|
||||
pglTexParameteri( tex->target, GL_TEXTURE_MIN_FILTER, nomipmap ? GL_NEAREST : GL_NEAREST_MIPMAP_NEAREST );
|
||||
@@ -172,6 +169,7 @@ void GL_ApplyTextureParams( gl_texture_t *tex )
|
||||
if( tex->target == GL_TEXTURE_3D || tex->target == GL_TEXTURE_CUBE_MAP_ARB )
|
||||
pglTexParameteri( tex->target, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_BORDER );
|
||||
|
||||
const vec4_t border = { 0.0f, 0.0f, 0.0f, 1.0f };
|
||||
pglTexParameterfv( tex->target, GL_TEXTURE_BORDER_COLOR, border );
|
||||
}
|
||||
else if( FBitSet( tex->flags, TF_CLAMP ))
|
||||
@@ -216,8 +214,7 @@ GL_UpdateTextureParams
|
||||
*/
|
||||
static void GL_UpdateTextureParams( int iTexture )
|
||||
{
|
||||
gl_texture_t *tex = &gl_textures[iTexture];
|
||||
qboolean nomipmap;
|
||||
gl_texture_t *tex = &gl_textures[iTexture];
|
||||
|
||||
Assert( tex != NULL );
|
||||
|
||||
@@ -233,7 +230,7 @@ static void GL_UpdateTextureParams( int iTexture )
|
||||
if( GL_Support( GL_TEXTURE_LOD_BIAS ) && ( tex->numMips > 1 ) && !FBitSet( tex->flags, TF_DEPTHMAP ))
|
||||
pglTexParameterf( tex->target, GL_TEXTURE_LOD_BIAS_EXT, gl_texture_lodbias.value );
|
||||
|
||||
nomipmap = tex->numMips <= 1 || FBitSet( tex->flags, TF_NOMIPMAP|TF_DEPTHMAP );
|
||||
qboolean nomipmap = tex->numMips <= 1 || FBitSet( tex->flags, TF_NOMIPMAP|TF_DEPTHMAP );
|
||||
|
||||
if( !GL_TextureFilteringEnabled( tex ))
|
||||
{
|
||||
@@ -254,8 +251,6 @@ R_SetTextureParameters
|
||||
*/
|
||||
void R_SetTextureParameters( void )
|
||||
{
|
||||
int i;
|
||||
|
||||
if( GL_Support( GL_ANISOTROPY_EXT ))
|
||||
{
|
||||
if( gl_texture_anisotropy.value > glConfig.max_texture_anisotropy )
|
||||
@@ -278,7 +273,7 @@ void R_SetTextureParameters( void )
|
||||
ClearBits( gl_lightmap_nearest.flags, FCVAR_CHANGED );
|
||||
|
||||
// change all the existing mipmapped texture objects
|
||||
for( i = 0; i < gl_numTextures; i++ )
|
||||
for( int i = 0; i < gl_numTextures; i++ )
|
||||
GL_UpdateTextureParams( i );
|
||||
}
|
||||
|
||||
@@ -406,9 +401,6 @@ static size_t GL_CalcTextureSize( GLenum format, int width, int height, int dept
|
||||
|
||||
static int GL_CalcMipmapCount( gl_texture_t *tex, qboolean haveBuffer )
|
||||
{
|
||||
int width, height;
|
||||
int mipcount;
|
||||
|
||||
Assert( tex != NULL );
|
||||
|
||||
if( !haveBuffer || tex->target == GL_TEXTURE_3D )
|
||||
@@ -419,10 +411,11 @@ static int GL_CalcMipmapCount( gl_texture_t *tex, qboolean haveBuffer )
|
||||
return 1;
|
||||
|
||||
// mip-maps can't exceeds 16
|
||||
int mipcount;
|
||||
for( mipcount = 0; mipcount < 16; mipcount++ )
|
||||
{
|
||||
width = Q_max( 1, ( tex->width >> mipcount ));
|
||||
height = Q_max( 1, ( tex->height >> mipcount ));
|
||||
int width = Q_max( 1, ( tex->width >> mipcount ));
|
||||
int height = Q_max( 1, ( tex->height >> mipcount ));
|
||||
if( width == 1 && height == 1 )
|
||||
break;
|
||||
}
|
||||
@@ -473,14 +466,15 @@ static void GL_SetTextureDimensions( gl_texture_t *tex, int width, int height, i
|
||||
|
||||
if( !GL_Support( GL_ARB_TEXTURE_NPOT_EXT ))
|
||||
{
|
||||
int step = (int)gl_round_down.value;
|
||||
int scaled_width, scaled_height;
|
||||
int step = (int)gl_round_down.value;
|
||||
|
||||
int scaled_width;
|
||||
for( scaled_width = 1; scaled_width < width; scaled_width <<= 1 );
|
||||
|
||||
if( step > 0 && width < scaled_width && ( step == 1 || ( scaled_width - width ) > ( scaled_width >> step )))
|
||||
scaled_width >>= 1;
|
||||
|
||||
int scaled_height;
|
||||
for( scaled_height = 1; scaled_height < height; scaled_height <<= 1 );
|
||||
|
||||
if( step > 0 && height < scaled_height && ( step == 1 || ( scaled_height - height ) > ( scaled_height >> step )))
|
||||
@@ -687,22 +681,20 @@ box filter 3x3
|
||||
*/
|
||||
static void GL_BoxFilter3x3( byte *out, const byte *in, int w, int h, int x, int y )
|
||||
{
|
||||
int r = 0, g = 0, b = 0, a = 0;
|
||||
int acount = 0;
|
||||
int i, j, u, v;
|
||||
const byte *pixel;
|
||||
int r = 0, g = 0, b = 0, a = 0;
|
||||
int acount = 0;
|
||||
|
||||
for( i = 0; i < 3; i++ )
|
||||
for( int i = 0; i < 3; i++ )
|
||||
{
|
||||
u = ( i - 1 ) + x;
|
||||
int u = ( i - 1 ) + x;
|
||||
|
||||
for( j = 0; j < 3; j++ )
|
||||
for( int j = 0; j < 3; j++ )
|
||||
{
|
||||
v = ( j - 1 ) + y;
|
||||
int v = ( j - 1 ) + y;
|
||||
|
||||
if( u >= 0 && u < w && v >= 0 && v < h )
|
||||
{
|
||||
pixel = &in[( u + v * w ) * 4];
|
||||
const byte *pixel = &in[( u + v * w ) * 4];
|
||||
|
||||
if( pixel[3] != 0 )
|
||||
{
|
||||
@@ -734,14 +726,13 @@ Apply box-filter to 1-bit alpha
|
||||
*/
|
||||
static byte *GL_ApplyFilter( const byte *source, int width, int height )
|
||||
{
|
||||
byte *in = (byte *)source;
|
||||
byte *out = (byte *)source;
|
||||
int i;
|
||||
byte *in = (byte *)source;
|
||||
byte *out = (byte *)source;
|
||||
|
||||
if( FBitSet( gp_host->features, ENGINE_QUAKE_COMPATIBLE ) || glConfig.max_multisamples > 1 )
|
||||
return in;
|
||||
|
||||
for( i = 0; source && i < width * height; i++, in += 4 )
|
||||
for( int i = 0; source && i < width * height; i++, in += 4 )
|
||||
{
|
||||
if( in[0] == 0 && in[1] == 0 && in[2] == 0 && in[3] == 0 )
|
||||
GL_BoxFilter3x3( in, source, width, height, i % width, i / width );
|
||||
@@ -759,18 +750,13 @@ Operates in place, quartering the size of the texture
|
||||
*/
|
||||
static void GL_BuildMipMap( byte *in, int srcWidth, int srcHeight, int srcDepth, int flags )
|
||||
{
|
||||
byte *out = in;
|
||||
int instride = ALIGN( srcWidth * 4, 1 );
|
||||
int mipWidth, mipHeight, outpadding;
|
||||
int row, x, y, z;
|
||||
vec3_t normal;
|
||||
|
||||
if( !in ) return;
|
||||
|
||||
mipWidth = Q_max( 1, ( srcWidth >> 1 ));
|
||||
mipHeight = Q_max( 1, ( srcHeight >> 1 ));
|
||||
outpadding = ALIGN( mipWidth * 4, 1 ) - mipWidth * 4;
|
||||
row = srcWidth << 2;
|
||||
byte *out = in;
|
||||
int instride = ALIGN( srcWidth * 4, 1 );
|
||||
int mipWidth = Q_max( 1, ( srcWidth >> 1 ));
|
||||
int mipHeight = Q_max( 1, ( srcHeight >> 1 ));
|
||||
int outpadding = ALIGN( mipWidth * 4, 1 ) - mipWidth * 4;
|
||||
|
||||
if( FBitSet( flags, TF_ALPHACONTRAST ))
|
||||
{
|
||||
@@ -779,15 +765,17 @@ static void GL_BuildMipMap( byte *in, int srcWidth, int srcHeight, int srcDepth,
|
||||
}
|
||||
|
||||
// move through all layers
|
||||
for( z = 0; z < srcDepth; z++ )
|
||||
for( int z = 0; z < srcDepth; z++ )
|
||||
{
|
||||
if( FBitSet( flags, TF_NORMALMAP ))
|
||||
{
|
||||
for( y = 0; y < mipHeight; y++, in += instride * 2, out += outpadding )
|
||||
for( int y = 0; y < mipHeight; y++, in += instride * 2, out += outpadding )
|
||||
{
|
||||
byte *next = ((( y << 1 ) + 1 ) < srcHeight ) ? ( in + instride ) : in;
|
||||
for( x = 0, row = 0; x < mipWidth; x++, row += 8, out += 4 )
|
||||
int row = 0;
|
||||
for( int x = 0; x < mipWidth; x++, row += 8, out += 4 )
|
||||
{
|
||||
vec3_t normal;
|
||||
if((( x << 1 ) + 1 ) < srcWidth )
|
||||
{
|
||||
normal[0] = MAKE_SIGNED( in[row+0] ) + MAKE_SIGNED( in[row+4] )
|
||||
@@ -816,10 +804,11 @@ static void GL_BuildMipMap( byte *in, int srcWidth, int srcHeight, int srcDepth,
|
||||
}
|
||||
else
|
||||
{
|
||||
for( y = 0; y < mipHeight; y++, in += instride * 2, out += outpadding )
|
||||
for( int y = 0; y < mipHeight; y++, in += instride * 2, out += outpadding )
|
||||
{
|
||||
byte *next = ((( y << 1 ) + 1 ) < srcHeight ) ? ( in + instride ) : in;
|
||||
for( x = 0, row = 0; x < mipWidth; x++, row += 8, out += 4 )
|
||||
int row = 0;
|
||||
for( int x = 0; x < mipWidth; x++, row += 8, out += 4 )
|
||||
{
|
||||
if((( x << 1 ) + 1 ) < srcWidth )
|
||||
{
|
||||
@@ -960,11 +949,10 @@ show GL-errors on load images
|
||||
*/
|
||||
static void GL_CheckTexImageError( gl_texture_t *tex )
|
||||
{
|
||||
int err;
|
||||
|
||||
Assert( tex != NULL );
|
||||
|
||||
// catch possible errors
|
||||
int err;
|
||||
if( gl_check_errors.value && ( err = pglGetError()) != GL_NO_ERROR )
|
||||
gEngfuncs.Con_Printf( S_OPENGL_ERROR "%s while uploading %s [%s]\n", GL_ErrorString( err ), tex->name, GL_TargetToString( tex->target ));
|
||||
}
|
||||
@@ -978,14 +966,6 @@ upload texture into video memory
|
||||
*/
|
||||
static qboolean GL_UploadTexture( gl_texture_t *tex, rgbdata_t *pic )
|
||||
{
|
||||
byte *buf, *data;
|
||||
size_t texsize, size;
|
||||
uint width, height, depth;
|
||||
uint i, j, numSides;
|
||||
qboolean normalMap;
|
||||
qboolean texture3d;
|
||||
const byte *bufend;
|
||||
|
||||
// dedicated server
|
||||
if( !glw_state.initialized )
|
||||
return true;
|
||||
@@ -1025,19 +1005,19 @@ static qboolean GL_UploadTexture( gl_texture_t *tex, rgbdata_t *pic )
|
||||
gEngfuncs.Con_Reportf( "%s: %s s&3 [%d x %d]\n", __func__, tex->name, pic->width, pic->height );
|
||||
}
|
||||
|
||||
buf = pic->buffer;
|
||||
bufend = pic->buffer + pic->size; // total image size include all the layers, cube sides, mipmaps
|
||||
texsize = GL_CalcTextureSize( tex->format, tex->width, tex->height, tex->depth );
|
||||
normalMap = FBitSet( tex->flags, TF_NORMALMAP ) ? true : false;
|
||||
numSides = FBitSet( pic->flags, IMAGE_CUBEMAP ) ? 6 : 1;
|
||||
texture3d = ( tex->target == GL_TEXTURE_3D );
|
||||
byte *buf = pic->buffer;
|
||||
const byte *bufend = pic->buffer + pic->size; // total image size include all the layers, cube sides, mipmaps
|
||||
size_t texsize = GL_CalcTextureSize( tex->format, tex->width, tex->height, tex->depth );
|
||||
qboolean normalMap = FBitSet( tex->flags, TF_NORMALMAP ) ? true : false;
|
||||
uint numSides = FBitSet( pic->flags, IMAGE_CUBEMAP ) ? 6 : 1;
|
||||
qboolean texture3d = ( tex->target == GL_TEXTURE_3D );
|
||||
|
||||
// uploading texture into video memory, change the binding
|
||||
glState.currentTextures[glState.activeTMU] = tex->texnum;
|
||||
glState.currentTexturesIndex[glState.activeTMU] = tex - gl_textures;
|
||||
pglBindTexture( tex->target, tex->texnum );
|
||||
|
||||
for( i = 0; i < numSides; i++ )
|
||||
for( uint i = 0; i < numSides; i++ )
|
||||
{
|
||||
// track the buffer bounds
|
||||
if( buf != NULL && buf >= bufend )
|
||||
@@ -1045,13 +1025,13 @@ static qboolean GL_UploadTexture( gl_texture_t *tex, rgbdata_t *pic )
|
||||
|
||||
if( ImageCompressed( pic->type ))
|
||||
{
|
||||
for( j = 0; j < Q_max( 1, pic->numMips ); j++ )
|
||||
for( uint j = 0; j < Q_max( 1, pic->numMips ); j++ )
|
||||
{
|
||||
width = Q_max( 1, ( tex->width >> j ));
|
||||
height = Q_max( 1, ( tex->height >> j ));
|
||||
depth = texture3d ? Q_max( 1, ( tex->depth >> j )) : tex->depth;
|
||||
uint width = Q_max( 1, ( tex->width >> j ));
|
||||
uint height = Q_max( 1, ( tex->height >> j ));
|
||||
uint depth = texture3d ? Q_max( 1, ( tex->depth >> j )) : tex->depth;
|
||||
texsize = GL_CalcTextureSize( tex->format, width, height, depth );
|
||||
size = gEngfuncs.Image_CalcImageSize( pic->type, width, height, depth );
|
||||
size_t size = gEngfuncs.Image_CalcImageSize( pic->type, width, height, depth );
|
||||
GL_TextureImageCompressed( tex, i, j, width, height, depth, size, buf );
|
||||
tex->size += texsize;
|
||||
buf += size; // move pointer
|
||||
@@ -1062,13 +1042,13 @@ static qboolean GL_UploadTexture( gl_texture_t *tex, rgbdata_t *pic )
|
||||
}
|
||||
else if( Q_max( 1, pic->numMips ) > 1 ) // not-compressed DDS
|
||||
{
|
||||
for( j = 0; j < Q_max( 1, pic->numMips ); j++ )
|
||||
for( uint j = 0; j < Q_max( 1, pic->numMips ); j++ )
|
||||
{
|
||||
width = Q_max( 1, ( tex->width >> j ));
|
||||
height = Q_max( 1, ( tex->height >> j ));
|
||||
depth = texture3d ? Q_max( 1, ( tex->depth >> j )) : tex->depth;
|
||||
uint width = Q_max( 1, ( tex->width >> j ));
|
||||
uint height = Q_max( 1, ( tex->height >> j ));
|
||||
uint depth = texture3d ? Q_max( 1, ( tex->depth >> j )) : tex->depth;
|
||||
texsize = GL_CalcTextureSize( tex->format, width, height, depth );
|
||||
size = gEngfuncs.Image_CalcImageSize( pic->type, width, height, depth );
|
||||
size_t size = gEngfuncs.Image_CalcImageSize( pic->type, width, height, depth );
|
||||
GL_TextureImageRAW( tex, i, j, width, height, depth, pic->type, buf );
|
||||
tex->size += texsize;
|
||||
buf += size; // move pointer
|
||||
@@ -1083,6 +1063,7 @@ static qboolean GL_UploadTexture( gl_texture_t *tex, rgbdata_t *pic )
|
||||
int mipCount = GL_CalcMipmapCount( tex, ( buf != NULL ));
|
||||
|
||||
// NOTE: only single uncompressed textures can be resamples, no mips, no layers, no sides
|
||||
byte *data;
|
||||
if(( tex->depth == 1 ) && (( pic->width != tex->width ) || ( pic->height != tex->height )))
|
||||
data = GL_ResampleTexture( buf, pic->width, pic->height, tex->width, tex->height, normalMap );
|
||||
else data = buf;
|
||||
@@ -1091,12 +1072,11 @@ static qboolean GL_UploadTexture( gl_texture_t *tex, rgbdata_t *pic )
|
||||
data = GL_ApplyFilter( data, tex->width, tex->height );
|
||||
|
||||
// mips will be auto-generated if desired
|
||||
for( j = 0; j < mipCount; j++ )
|
||||
for( int j = 0; j < mipCount; j++ )
|
||||
{
|
||||
width = Q_max( 1, ( tex->width >> j ));
|
||||
height = Q_max( 1, ( tex->height >> j ));
|
||||
uint width = Q_max( 1, ( tex->width >> j ));
|
||||
uint height = Q_max( 1, ( tex->height >> j ));
|
||||
texsize = GL_CalcTextureSize( tex->format, width, height, tex->depth );
|
||||
size = gEngfuncs.Image_CalcImageSize( pic->type, width, height, tex->depth );
|
||||
GL_TextureImageRAW( tex, i, j, width, height, tex->depth, pic->type, data );
|
||||
if( mipCount > 1 )
|
||||
GL_BuildMipMap( data, width, height, tex->depth, tex->flags );
|
||||
@@ -1174,12 +1154,12 @@ static void GL_ProcessImage( gl_texture_t *tex, rgbdata_t *pic )
|
||||
if( FBitSet( pic->flags, IMAGE_PLAYERDECAL ) && pic->buffer && pic->type == PF_RGBA_32 && FBitSet( pic->flags, IMAGE_HAS_ALPHA )
|
||||
&& !FBitSet( pic->flags, IMAGE_PREMULTIPLIED ))
|
||||
{
|
||||
int i, cnt = (int)( pic->width * pic->height );
|
||||
byte *p = pic->buffer;
|
||||
int cnt = (int)( pic->width * pic->height );
|
||||
byte *p = pic->buffer;
|
||||
|
||||
for( i = 0; i < cnt; i++, p += 4 )
|
||||
for( int i = 0; i < cnt; i++, p += 4 )
|
||||
{
|
||||
int a = p[3];
|
||||
int a = p[3];
|
||||
p[0] = ( p[0] * a + 127 ) / 255;
|
||||
p[1] = ( p[1] * a + 127 ) / 255;
|
||||
p[2] = ( p[2] * a + 127 ) / 255;
|
||||
@@ -1200,12 +1180,10 @@ GL_CheckTexName
|
||||
*/
|
||||
static qboolean GL_CheckTexName( const char *name )
|
||||
{
|
||||
int len;
|
||||
|
||||
if( COM_StringEmptyOrNULL( name ))
|
||||
return false;
|
||||
|
||||
len = Q_strlen( name );
|
||||
int len = Q_strlen( name );
|
||||
|
||||
// because multi-layered textures can exceed name string
|
||||
if( len >= sizeof( gl_textures->name ))
|
||||
@@ -1224,13 +1202,10 @@ GL_TextureForName
|
||||
*/
|
||||
static gl_texture_t *GL_TextureForName( const char *name )
|
||||
{
|
||||
gl_texture_t *tex;
|
||||
uint hash;
|
||||
|
||||
// find the texture in array
|
||||
hash = COM_HashKey( name, TEXTURES_HASH_SIZE );
|
||||
uint hash = COM_HashKey( name, TEXTURES_HASH_SIZE );
|
||||
|
||||
for( tex = gl_texturesHashTable[hash]; tex != NULL; tex = tex->nextHash )
|
||||
for( gl_texture_t *tex = gl_texturesHashTable[hash]; tex != NULL; tex = tex->nextHash )
|
||||
{
|
||||
if( !Q_stricmp( tex->name, name ))
|
||||
return tex;
|
||||
@@ -1265,9 +1240,7 @@ static gl_texture_t *GL_AllocTexture( const char *name, texFlags_t flags )
|
||||
if( texnum >= MAX_TEXTURES || gl_textures[texnum].texnum != 0 )
|
||||
{
|
||||
// find a free texture_t slot
|
||||
uint i;
|
||||
|
||||
for( i = 0; i < MAX_TEXTURES; i++ )
|
||||
for( uint i = 0; i < MAX_TEXTURES; i++ )
|
||||
{
|
||||
if( gl_textures[i].texnum )
|
||||
continue;
|
||||
@@ -1309,9 +1282,6 @@ GL_DeleteTexture
|
||||
*/
|
||||
static void GL_DeleteTexture( gl_texture_t *tex )
|
||||
{
|
||||
gl_texture_t **prev;
|
||||
gl_texture_t *cur;
|
||||
|
||||
Assert( tex != NULL );
|
||||
|
||||
// already freed?
|
||||
@@ -1325,11 +1295,11 @@ static void GL_DeleteTexture( gl_texture_t *tex )
|
||||
}
|
||||
|
||||
// remove from hash table
|
||||
prev = &gl_texturesHashTable[tex->hashValue];
|
||||
gl_texture_t **prev = &gl_texturesHashTable[tex->hashValue];
|
||||
|
||||
while( 1 )
|
||||
{
|
||||
cur = *prev;
|
||||
gl_texture_t *cur = *prev;
|
||||
if( !cur ) break;
|
||||
|
||||
if( cur == tex )
|
||||
@@ -1374,25 +1344,21 @@ recalc image room
|
||||
*/
|
||||
void GL_UpdateTexSize( int texnum, int width, int height, int depth )
|
||||
{
|
||||
int i, j, texsize;
|
||||
int numSides;
|
||||
gl_texture_t *tex;
|
||||
|
||||
if( texnum <= 0 || texnum >= MAX_TEXTURES )
|
||||
return;
|
||||
|
||||
tex = &gl_textures[texnum];
|
||||
numSides = FBitSet( tex->flags, TF_CUBEMAP ) ? 6 : 1;
|
||||
gl_texture_t *tex = &gl_textures[texnum];
|
||||
int numSides = FBitSet( tex->flags, TF_CUBEMAP ) ? 6 : 1;
|
||||
GL_SetTextureDimensions( tex, width, height, depth );
|
||||
tex->size = 0; // recompute now
|
||||
|
||||
for( i = 0; i < numSides; i++ )
|
||||
for( int i = 0; i < numSides; i++ )
|
||||
{
|
||||
for( j = 0; j < Q_max( 1, tex->numMips ); j++ )
|
||||
for( int j = 0; j < Q_max( 1, tex->numMips ); j++ )
|
||||
{
|
||||
width = Q_max( 1, ( tex->width >> j ));
|
||||
height = Q_max( 1, ( tex->height >> j ));
|
||||
texsize = GL_CalcTextureSize( tex->format, width, height, tex->depth );
|
||||
int texsize = GL_CalcTextureSize( tex->format, width, height, tex->depth );
|
||||
tex->size += texsize;
|
||||
}
|
||||
}
|
||||
@@ -1405,14 +1371,13 @@ GL_LoadTexture
|
||||
*/
|
||||
int GL_LoadTexture( const char *name, const byte *buf, size_t size, int flags )
|
||||
{
|
||||
gl_texture_t *tex;
|
||||
rgbdata_t *pic;
|
||||
uint picFlags = 0;
|
||||
uint picFlags = 0;
|
||||
|
||||
if( !GL_CheckTexName( name ))
|
||||
return 0;
|
||||
|
||||
// see if already loaded
|
||||
gl_texture_t *tex;
|
||||
if(( tex = GL_TextureForName( name )))
|
||||
return (tex - gl_textures);
|
||||
|
||||
@@ -1425,7 +1390,7 @@ int GL_LoadTexture( const char *name, const byte *buf, size_t size, int flags )
|
||||
// set some image flags
|
||||
gEngfuncs.Image_SetForceFlags( picFlags );
|
||||
|
||||
pic = gEngfuncs.FS_LoadImage( name, buf, size );
|
||||
rgbdata_t *pic = gEngfuncs.FS_LoadImage( name, buf, size );
|
||||
if( !pic ) return 0; // couldn't loading image
|
||||
|
||||
// allocate the new one
|
||||
@@ -1453,19 +1418,15 @@ GL_LoadTextureArray
|
||||
*/
|
||||
int GL_LoadTextureArray( const char **names, int flags )
|
||||
{
|
||||
rgbdata_t *pic, *src;
|
||||
char basename[256];
|
||||
uint numLayers = 0;
|
||||
char name[256];
|
||||
gl_texture_t *tex;
|
||||
size_t len = 0;
|
||||
int ret = 0;
|
||||
uint i, j;
|
||||
|
||||
if( !names || !names[0] || !glw_state.initialized )
|
||||
return 0;
|
||||
|
||||
char name[256];
|
||||
char basename[256];
|
||||
|
||||
// count layers (g-cont. this is pontentially unsafe loop)
|
||||
uint numLayers = 0;
|
||||
uint i;
|
||||
for( i = 0; i < glConfig.max_2d_texture_layers && ( *names[i] != '\0' ); i++ )
|
||||
numLayers++;
|
||||
name[0] = '\0';
|
||||
@@ -1473,6 +1434,8 @@ int GL_LoadTextureArray( const char **names, int flags )
|
||||
if( numLayers <= 0 ) return 0;
|
||||
|
||||
// create complexname from layer names
|
||||
size_t len = 0;
|
||||
int ret = 0;
|
||||
for( i = 0; i < numLayers - 1; i++ )
|
||||
{
|
||||
COM_FileBase( names[i], basename, sizeof( basename ));
|
||||
@@ -1494,15 +1457,17 @@ int GL_LoadTextureArray( const char **names, int flags )
|
||||
return 0;
|
||||
|
||||
// see if already loaded
|
||||
gl_texture_t *tex;
|
||||
if(( tex = GL_TextureForName( name )))
|
||||
return (tex - gl_textures);
|
||||
|
||||
// load all the images and pack it into single image
|
||||
for( i = 0, pic = NULL; i < numLayers; i++ )
|
||||
rgbdata_t *pic = NULL;
|
||||
for( i = 0; i < numLayers; i++ )
|
||||
{
|
||||
size_t srcsize, dstsize, mipsize;
|
||||
size_t srcsize, dstsize, mipsize;
|
||||
|
||||
src = gEngfuncs.FS_LoadImage( names[i], NULL, 0 );
|
||||
rgbdata_t *src = gEngfuncs.FS_LoadImage( names[i], NULL, 0 );
|
||||
if( !src ) break; // coldn't find layer
|
||||
|
||||
if( pic )
|
||||
@@ -1550,7 +1515,7 @@ int GL_LoadTextureArray( const char **names, int flags )
|
||||
|
||||
mipsize = srcsize = dstsize = 0;
|
||||
|
||||
for( j = 0; j < Q_max( 1, pic->numMips ); j++ )
|
||||
for( uint j = 0; j < Q_max( 1, pic->numMips ); j++ )
|
||||
{
|
||||
int width = Q_max( 1, ( pic->width >> j ));
|
||||
int height = Q_max( 1, ( pic->height >> j ));
|
||||
@@ -1603,12 +1568,11 @@ GL_LoadTextureFromBuffer
|
||||
*/
|
||||
int GL_LoadTextureFromBuffer( const char *name, rgbdata_t *pic, texFlags_t flags, qboolean update )
|
||||
{
|
||||
gl_texture_t *tex;
|
||||
|
||||
if( !GL_CheckTexName( name ))
|
||||
return 0;
|
||||
|
||||
// see if already loaded
|
||||
gl_texture_t *tex;
|
||||
if(( tex = GL_TextureForName( name )) && !update )
|
||||
return (tex - gl_textures);
|
||||
|
||||
@@ -1648,9 +1612,8 @@ creates texture from buffer
|
||||
*/
|
||||
int GL_CreateTexture( const char *name, int width, int height, const void *buffer, texFlags_t flags )
|
||||
{
|
||||
qboolean update = FBitSet( flags, TF_UPDATE ) ? true : false;
|
||||
int datasize = 1;
|
||||
rgbdata_t r_empty;
|
||||
qboolean update = FBitSet( flags, TF_UPDATE ) ? true : false;
|
||||
int datasize = 1;
|
||||
|
||||
if( FBitSet( flags, TF_ARB_16BIT ))
|
||||
datasize = 2;
|
||||
@@ -1658,6 +1621,8 @@ int GL_CreateTexture( const char *name, int width, int height, const void *buffe
|
||||
datasize = 4;
|
||||
|
||||
ClearBits( flags, TF_UPDATE );
|
||||
|
||||
rgbdata_t r_empty;
|
||||
memset( &r_empty, 0, sizeof( r_empty ));
|
||||
r_empty.width = width;
|
||||
r_empty.height = height;
|
||||
@@ -1750,12 +1715,11 @@ GL_FindTexture
|
||||
*/
|
||||
int GL_FindTexture( const char *name )
|
||||
{
|
||||
gl_texture_t *tex;
|
||||
|
||||
if( !GL_CheckTexName( name ))
|
||||
return 0;
|
||||
|
||||
// see if already loaded
|
||||
gl_texture_t *tex;
|
||||
if(( tex = GL_TextureForName( name )))
|
||||
return (tex - gl_textures);
|
||||
|
||||
@@ -1783,13 +1747,11 @@ GL_ProcessTexture
|
||||
*/
|
||||
void GL_ProcessTexture( int texnum, float gamma, int topColor, int bottomColor )
|
||||
{
|
||||
gl_texture_t *image;
|
||||
rgbdata_t *pic;
|
||||
int flags = 0;
|
||||
int flags = 0;
|
||||
|
||||
if( texnum <= 0 || texnum >= MAX_TEXTURES )
|
||||
return; // missed image
|
||||
image = &gl_textures[texnum];
|
||||
gl_texture_t *image = &gl_textures[texnum];
|
||||
|
||||
// select mode
|
||||
if( gamma != -1.0f )
|
||||
@@ -1819,7 +1781,7 @@ void GL_ProcessTexture( int texnum, float gamma, int topColor, int bottomColor )
|
||||
}
|
||||
|
||||
// all the operations makes over the image copy not an original
|
||||
pic = gEngfuncs.FS_CopyImage( image->original );
|
||||
rgbdata_t *pic = gEngfuncs.FS_CopyImage( image->original );
|
||||
|
||||
// we need to expand image into RGBA buffer
|
||||
if( pic->type == PF_INDEXED_24 || pic->type == PF_INDEXED_32 )
|
||||
@@ -1842,9 +1804,9 @@ return size of all uploaded textures
|
||||
*/
|
||||
int GL_TexMemory( void )
|
||||
{
|
||||
int i, total = 0;
|
||||
int total = 0;
|
||||
|
||||
for( i = 0; i < gl_numTextures; i++ )
|
||||
for( int i = 0; i < gl_numTextures; i++ )
|
||||
total += gl_textures[i].size;
|
||||
|
||||
return total;
|
||||
@@ -1887,13 +1849,14 @@ R_TextureList_f
|
||||
*/
|
||||
void R_TextureList_f( void )
|
||||
{
|
||||
gl_texture_t *image;
|
||||
int i, texCount, bytes = 0;
|
||||
int bytes = 0;
|
||||
|
||||
gEngfuncs.Con_Printf( "\n" );
|
||||
gEngfuncs.Con_Printf( " -id- -w- -h- -size- -fmt- -type- -data- -encode- -wrap- -depth- -name--------\n" );
|
||||
|
||||
for( i = texCount = 0, image = gl_textures; i < gl_numTextures; i++, image++ )
|
||||
int texCount = 0;
|
||||
gl_texture_t *image = gl_textures;
|
||||
for( int i = 0; i < gl_numTextures; i++, image++ )
|
||||
{
|
||||
if( !image->texnum ) continue;
|
||||
|
||||
@@ -2123,13 +2086,11 @@ R_ShutdownImages
|
||||
*/
|
||||
void R_ShutdownImages( void )
|
||||
{
|
||||
gl_texture_t *tex;
|
||||
int i;
|
||||
|
||||
gEngfuncs.Cmd_RemoveCommand( "texturelist" );
|
||||
GL_CleanupAllTextureUnits();
|
||||
|
||||
for( i = 0, tex = gl_textures; i < gl_numTextures; i++, tex++ )
|
||||
gl_texture_t *tex = gl_textures;
|
||||
for( int i = 0; i < gl_numTextures; i++, tex++ )
|
||||
GL_DeleteTexture( tex );
|
||||
|
||||
memset( tr.lightmapTextures, 0, sizeof( tr.lightmapTextures ));
|
||||
@@ -2154,10 +2115,8 @@ void R_TextureReplacementReport( const char *modelname, int gl_texturenum, const
|
||||
qboolean R_SearchForTextureReplacement( char *out, size_t size, const char *modelname, const char *fmt, ... )
|
||||
{
|
||||
va_list ap;
|
||||
int ret;
|
||||
|
||||
va_start( ap, fmt );
|
||||
ret = Q_vsnprintf( out, size, fmt, ap );
|
||||
int ret = Q_vsnprintf( out, size, fmt, ap );
|
||||
va_end( ap );
|
||||
|
||||
if( ret < 0 )
|
||||
@@ -2183,18 +2142,7 @@ was there. This is used to test for texture thrashing.
|
||||
*/
|
||||
void R_ShowTextures( void )
|
||||
{
|
||||
float w, h;
|
||||
int start, k;
|
||||
int base_w, base_h;
|
||||
rgba_t color = { 255, 255, 255, 255 };
|
||||
int charHeight;
|
||||
static qboolean showHelp = true;
|
||||
float time; //nc add
|
||||
float time_cubemap; //nc add
|
||||
float cbm_cos, cbm_sin; //nc add
|
||||
int per_page; //nc add
|
||||
qboolean empty_page;
|
||||
int skipped_empty_pages;
|
||||
static qboolean showHelp = true;
|
||||
|
||||
if( !r_showtextures->value )
|
||||
return;
|
||||
@@ -2207,42 +2155,41 @@ void R_ShowTextures( void )
|
||||
|
||||
pglClear( GL_COLOR_BUFFER_BIT );
|
||||
|
||||
w = 200;
|
||||
h = 200;
|
||||
float w = 200;
|
||||
float h = 200;
|
||||
|
||||
time = gp_cl->time * 0.5f;
|
||||
float time = gp_cl->time * 0.5f;
|
||||
time -= floor( time );
|
||||
time_cubemap = gp_cl->time * 0.25f;
|
||||
float time_cubemap = gp_cl->time * 0.25f;
|
||||
time_cubemap -= floor( time_cubemap );
|
||||
time_cubemap *= M_PI2_F;
|
||||
float cbm_cos, cbm_sin;
|
||||
SinCos( time_cubemap, &cbm_sin, &cbm_cos );
|
||||
|
||||
int charHeight;
|
||||
gEngfuncs.Con_DrawStringLen( NULL, NULL, &charHeight );
|
||||
|
||||
base_w = gpGlobals->width / w;
|
||||
base_h = gpGlobals->height / ( h + charHeight * 2 );
|
||||
per_page = base_w * base_h;
|
||||
start = per_page * ( r_showtextures->value - 1 ) + 1; // skip empty null texture
|
||||
int base_w = gpGlobals->width / w;
|
||||
int base_h = gpGlobals->height / ( h + charHeight * 2 );
|
||||
int per_page = base_w * base_h;
|
||||
int start = per_page * ( r_showtextures->value - 1 ) + 1; // skip empty null texture
|
||||
|
||||
GL_SetRenderMode( kRenderTransTexture ); // nc changed from normal to trans, Con_DrawString does this anyway
|
||||
|
||||
empty_page = true;
|
||||
skipped_empty_pages = 0;
|
||||
qboolean empty_page = true;
|
||||
int skipped_empty_pages = 0;
|
||||
while( empty_page )
|
||||
{
|
||||
for( k = 0; k < per_page; k++ )
|
||||
for( int k = 0; k < per_page; k++ )
|
||||
{
|
||||
const gl_texture_t *image;
|
||||
int i;
|
||||
|
||||
i = k + start;
|
||||
int i = k + start;
|
||||
if( i >= MAX_TEXTURES )
|
||||
{
|
||||
empty_page = false;
|
||||
break;
|
||||
}
|
||||
|
||||
image = R_GetTexture( i );
|
||||
const gl_texture_t *image = R_GetTexture( i );
|
||||
if( pglIsTexture( image->texnum ))
|
||||
{
|
||||
empty_page = false;
|
||||
@@ -2264,24 +2211,19 @@ void R_ShowTextures( void )
|
||||
gEngfuncs.CL_CenterPrint( text, 0.25f );
|
||||
}
|
||||
|
||||
for( k = 0; k < per_page; k++ )
|
||||
const rgba_t color = { 255, 255, 255, 255 };
|
||||
for( int k = 0; k < per_page; k++ )
|
||||
{
|
||||
const gl_texture_t *image;
|
||||
int textlen, i;
|
||||
char text[MAX_VA_STRING];
|
||||
string shortname;
|
||||
float x, y;
|
||||
|
||||
i = k + start;
|
||||
int i = k + start;
|
||||
if ( i >= MAX_TEXTURES )
|
||||
break;
|
||||
|
||||
image = R_GetTexture( i );
|
||||
const gl_texture_t *image = R_GetTexture( i );
|
||||
if( !pglIsTexture( image->texnum ))
|
||||
continue;
|
||||
|
||||
x = k % base_w * gpGlobals->width / base_w;
|
||||
y = k / base_w * gpGlobals->height / base_h;
|
||||
float x = k % base_w * gpGlobals->width / base_w;
|
||||
float y = k / base_w * gpGlobals->height / base_h;
|
||||
|
||||
pglColor4f( 1.0f, 1.0f, 1.0f, 1.0f );
|
||||
GL_Bind( XASH_TEXTURE0, i );
|
||||
@@ -2334,7 +2276,9 @@ void R_ShowTextures( void )
|
||||
if( FBitSet( image->flags, TF_DEPTHMAP ) && !FBitSet( image->flags, TF_NOCOMPARE ))
|
||||
pglTexParameteri( image->target, GL_TEXTURE_COMPARE_MODE_ARB, GL_COMPARE_R_TO_TEXTURE_ARB );
|
||||
|
||||
string shortname;
|
||||
COM_FileBase( image->name, shortname, sizeof( shortname ));
|
||||
int textlen;
|
||||
gEngfuncs.Con_DrawStringLen( shortname, &textlen, NULL );
|
||||
|
||||
if( textlen > w )
|
||||
@@ -2346,6 +2290,7 @@ void R_ShowTextures( void )
|
||||
}
|
||||
|
||||
gEngfuncs.Con_DrawString( x + 1, y + h, shortname, color );
|
||||
char text[MAX_VA_STRING];
|
||||
if( image->target == GL_TEXTURE_3D || image->target == GL_TEXTURE_2D_ARRAY_EXT )
|
||||
Q_snprintf( text, sizeof( text ), "%ix%ix%i %s", image->width, image->height, image->depth, GL_TargetToString( image->target ));
|
||||
else
|
||||
|
||||
@@ -591,14 +591,11 @@ GL_SetDefaultTexState
|
||||
*/
|
||||
static void GL_SetDefaultTexState( void )
|
||||
{
|
||||
|
||||
int i;
|
||||
|
||||
memset( glState.currentTextures, -1, MAX_TEXTURE_UNITS * sizeof( *glState.currentTextures ));
|
||||
memset( glState.texCoordArrayMode, 0, MAX_TEXTURE_UNITS * sizeof( *glState.texCoordArrayMode ));
|
||||
memset( glState.genSTEnabled, 0, MAX_TEXTURE_UNITS * sizeof( *glState.genSTEnabled ));
|
||||
|
||||
for( i = 0; i < MAX_TEXTURE_UNITS; i++ )
|
||||
for( int i = 0; i < MAX_TEXTURE_UNITS; i++ )
|
||||
{
|
||||
glState.currentTextureTargets[i] = GL_NONE;
|
||||
glState.texIdentityMatrix[i] = true;
|
||||
@@ -734,8 +731,6 @@ static void R_RenderInfo_f( void )
|
||||
#if XASH_GLES
|
||||
static void GL_InitExtensionsGLES( void )
|
||||
{
|
||||
int extid;
|
||||
|
||||
// intialize wrapper type
|
||||
#if XASH_NANOGL
|
||||
glConfig.context = CONTEXT_TYPE_GLES_1_X;
|
||||
@@ -752,7 +747,7 @@ static void GL_InitExtensionsGLES( void )
|
||||
|
||||
glConfig.hardware_type = GLHW_GENERIC;
|
||||
|
||||
for( extid = GL_OPENGL_110 + 1; extid < GL_EXTCOUNT; extid++ )
|
||||
for( int extid = GL_OPENGL_110 + 1; extid < GL_EXTCOUNT; extid++ )
|
||||
{
|
||||
switch( extid )
|
||||
{
|
||||
@@ -1032,10 +1027,9 @@ void GL_InitExtensions( void )
|
||||
if( !major && glConfig.version_string )
|
||||
{
|
||||
const char *str = glConfig.version_string;
|
||||
float ver;
|
||||
|
||||
while( *str && ( *str < '0' || *str > '9' )) str++;
|
||||
ver = Q_atof(str);
|
||||
float ver = Q_atof(str);
|
||||
if( ver )
|
||||
{
|
||||
glConfig.version_major = ver;
|
||||
@@ -1056,16 +1050,15 @@ void GL_InitExtensions( void )
|
||||
pglGetIntegerv( GL_NUM_EXTENSIONS, &n );
|
||||
if( n && pglGetStringi )
|
||||
{
|
||||
int i, len = 1;
|
||||
char *str;
|
||||
int len = 1;
|
||||
|
||||
for( i = 0; i < n; i++ )
|
||||
for( int i = 0; i < n; i++ )
|
||||
len += Q_strlen((const char *)pglGetStringi( GL_EXTENSIONS, i )) + 1;
|
||||
|
||||
str = (char*)Mem_Calloc( r_temppool, len );
|
||||
char *str = (char*)Mem_Calloc( r_temppool, len );
|
||||
glConfig.extensions_string = str;
|
||||
|
||||
for( i = 0; i < n; i++ )
|
||||
for( int i = 0; i < n; i++ )
|
||||
{
|
||||
int l = Q_strncpy( str, pglGetStringi( GL_EXTENSIONS, i ), len );
|
||||
str += l;
|
||||
@@ -1355,7 +1348,7 @@ void GL_CheckForErrors_( const char *filename, const int fileline )
|
||||
if( !gl_check_errors.value || !gpGlobals->developer )
|
||||
return;
|
||||
|
||||
int err = pglGetError( );
|
||||
int err = pglGetError();
|
||||
|
||||
if( err == GL_NO_ERROR )
|
||||
return;
|
||||
|
||||
@@ -85,16 +85,13 @@ Sorting translucent entities by rendermode then by distance
|
||||
*/
|
||||
static int R_TransEntityCompare( const void *a, const void *b )
|
||||
{
|
||||
cl_entity_t *ent1, *ent2;
|
||||
vec3_t vecLen, org;
|
||||
float dist1, dist2;
|
||||
int rendermode1;
|
||||
int rendermode2;
|
||||
cl_entity_t *ent1 = *(cl_entity_t **)a;
|
||||
cl_entity_t *ent2 = *(cl_entity_t **)b;
|
||||
int rendermode1 = R_GetEntityRenderMode( ent1 );
|
||||
int rendermode2 = R_GetEntityRenderMode( ent2 );
|
||||
|
||||
ent1 = *(cl_entity_t **)a;
|
||||
ent2 = *(cl_entity_t **)b;
|
||||
rendermode1 = R_GetEntityRenderMode( ent1 );
|
||||
rendermode2 = R_GetEntityRenderMode( ent2 );
|
||||
vec3_t vecLen, org;
|
||||
float dist1, dist2;
|
||||
|
||||
// sort by distance
|
||||
if( ent1->model->type != mod_brush || rendermode1 != kRenderTransAlpha )
|
||||
@@ -139,19 +136,17 @@ Returns true if we behind to screen
|
||||
*/
|
||||
int R_WorldToScreen( const vec3_t point, vec3_t screen )
|
||||
{
|
||||
matrix4x4 worldToScreen;
|
||||
qboolean behind;
|
||||
float w;
|
||||
|
||||
if( !point || !screen )
|
||||
return true;
|
||||
|
||||
matrix4x4 worldToScreen;
|
||||
Matrix4x4_Copy( worldToScreen, RI.worldviewProjectionMatrix );
|
||||
screen[0] = worldToScreen[0][0] * point[0] + worldToScreen[0][1] * point[1] + worldToScreen[0][2] * point[2] + worldToScreen[0][3];
|
||||
screen[1] = worldToScreen[1][0] * point[0] + worldToScreen[1][1] * point[1] + worldToScreen[1][2] * point[2] + worldToScreen[1][3];
|
||||
w = worldToScreen[3][0] * point[0] + worldToScreen[3][1] * point[1] + worldToScreen[3][2] * point[2] + worldToScreen[3][3];
|
||||
float w = worldToScreen[3][0] * point[0] + worldToScreen[3][1] * point[1] + worldToScreen[3][2] * point[2] + worldToScreen[3][3];
|
||||
screen[2] = 0.0f; // just so we have something valid here
|
||||
|
||||
qboolean behind;
|
||||
if( w < 0.001f )
|
||||
{
|
||||
behind = true;
|
||||
@@ -176,18 +171,16 @@ Convert a given point from screen into world space
|
||||
*/
|
||||
void R_ScreenToWorld( const vec3_t screen, vec3_t point )
|
||||
{
|
||||
matrix4x4 screenToWorld;
|
||||
float w;
|
||||
|
||||
if( !point || !screen )
|
||||
return;
|
||||
|
||||
matrix4x4 screenToWorld;
|
||||
Matrix4x4_Invert_Full( screenToWorld, RI.worldviewProjectionMatrix );
|
||||
|
||||
point[0] = screen[0] * screenToWorld[0][0] + screen[1] * screenToWorld[0][1] + screen[2] * screenToWorld[0][2] + screenToWorld[0][3];
|
||||
point[1] = screen[0] * screenToWorld[1][0] + screen[1] * screenToWorld[1][1] + screen[2] * screenToWorld[1][2] + screenToWorld[1][3];
|
||||
point[2] = screen[0] * screenToWorld[2][0] + screen[1] * screenToWorld[2][1] + screen[2] * screenToWorld[2][2] + screenToWorld[2][3];
|
||||
w = screen[0] * screenToWorld[3][0] + screen[1] * screenToWorld[3][1] + screen[2] * screenToWorld[3][2] + screenToWorld[3][3];
|
||||
float w = screen[0] * screenToWorld[3][0] + screen[1] * screenToWorld[3][1] + screen[2] * screenToWorld[3][2] + screenToWorld[3][3];
|
||||
if( w != 0.0f ) VectorScale( point, ( 1.0f / w ), point );
|
||||
}
|
||||
|
||||
@@ -301,13 +294,11 @@ R_Clear
|
||||
*/
|
||||
static void R_Clear( int bitMask )
|
||||
{
|
||||
int bits;
|
||||
|
||||
if( ENGINE_GET_PARM( PARM_DEV_OVERVIEW ))
|
||||
pglClearColor( 0.0f, 1.0f, 0.0f, 1.0f ); // green background (Valve rules)
|
||||
else pglClearColor( 0.5f, 0.5f, 0.5f, 1.0f );
|
||||
|
||||
bits = GL_DEPTH_BUFFER_BIT;
|
||||
int bits = GL_DEPTH_BUFFER_BIT;
|
||||
|
||||
if( glState.stencilEnabled )
|
||||
bits |= GL_STENCIL_BUFFER_BIT;
|
||||
@@ -381,8 +372,6 @@ R_SetupProjectionMatrix
|
||||
*/
|
||||
static void R_SetupProjectionMatrix( matrix4x4 m )
|
||||
{
|
||||
GLfloat xMin, xMax, yMin, yMax, zNear, zFar;
|
||||
|
||||
if( FBitSet( RI.rvp.flags, RF_DRAW_OVERVIEW ))
|
||||
{
|
||||
const ref_overview_t *ov = gEngfuncs.GetOverviewParms();
|
||||
@@ -392,14 +381,14 @@ static void R_SetupProjectionMatrix( matrix4x4 m )
|
||||
|
||||
RI.farClip = R_GetFarClip();
|
||||
|
||||
zNear = 4.0f;
|
||||
zFar = Q_max( 256.0f, RI.farClip );
|
||||
GLfloat zNear = 4.0f;
|
||||
GLfloat zFar = Q_max( 256.0f, RI.farClip );
|
||||
|
||||
yMax = zNear * tan( RI.rvp.fov_y * M_PI_F / 360.0f );
|
||||
yMin = -yMax;
|
||||
GLfloat yMax = zNear * tan( RI.rvp.fov_y * M_PI_F / 360.0f );
|
||||
GLfloat yMin = -yMax;
|
||||
|
||||
xMax = zNear * tan( RI.rvp.fov_x * M_PI_F / 360.0f );
|
||||
xMin = -xMax;
|
||||
GLfloat xMax = zNear * tan( RI.rvp.fov_x * M_PI_F / 360.0f );
|
||||
GLfloat xMin = -xMax;
|
||||
|
||||
if( tr.rotation & 1 )
|
||||
{
|
||||
@@ -554,13 +543,11 @@ void R_SetupGL( qboolean set_gl_state )
|
||||
|
||||
if( !FBitSet( RI.rvp.flags, RF_DRAW_CUBEMAP ))
|
||||
{
|
||||
int x, x2, y, y2;
|
||||
|
||||
// set up viewport (main, playersetup)
|
||||
x = floor( RI.rvp.viewport[0] * gpGlobals->width / gpGlobals->width );
|
||||
x2 = ceil(( RI.rvp.viewport[0] + RI.rvp.viewport[2] ) * gpGlobals->width / gpGlobals->width );
|
||||
y = floor( gpGlobals->height - RI.rvp.viewport[1] * gpGlobals->height / gpGlobals->height );
|
||||
y2 = ceil( gpGlobals->height - ( RI.rvp.viewport[1] + RI.rvp.viewport[3] ) * gpGlobals->height / gpGlobals->height );
|
||||
int x = floor( RI.rvp.viewport[0] * gpGlobals->width / gpGlobals->width );
|
||||
int x2 = ceil(( RI.rvp.viewport[0] + RI.rvp.viewport[2] ) * gpGlobals->width / gpGlobals->width );
|
||||
int y = floor( gpGlobals->height - RI.rvp.viewport[1] * gpGlobals->height / gpGlobals->height );
|
||||
int y2 = ceil( gpGlobals->height - ( RI.rvp.viewport[1] + RI.rvp.viewport[3] ) * gpGlobals->height / gpGlobals->height );
|
||||
|
||||
if( tr.rotation & 1 )
|
||||
pglViewport( y2, x, y - y2, x2 - x );
|
||||
@@ -608,20 +595,16 @@ static gl_texture_t *R_RecursiveFindWaterTexture( const mnode_t *node, const mno
|
||||
|
||||
if( node->contents < 0 )
|
||||
{
|
||||
mleaf_t *pleaf;
|
||||
msurface_t **mark;
|
||||
int i, c;
|
||||
|
||||
// ignore non-liquid leaves
|
||||
if( node->contents != CONTENTS_WATER && node->contents != CONTENTS_LAVA && node->contents != CONTENTS_SLIME )
|
||||
return NULL;
|
||||
|
||||
// find texture
|
||||
pleaf = (mleaf_t *)node;
|
||||
mark = pleaf->firstmarksurface;
|
||||
c = pleaf->nummarksurfaces;
|
||||
mleaf_t *pleaf = (mleaf_t *)node;
|
||||
msurface_t **mark = pleaf->firstmarksurface;
|
||||
int c = pleaf->nummarksurfaces;
|
||||
|
||||
for( i = 0; i < c; i++, mark++ )
|
||||
for( int i = 0; i < c; i++, mark++ )
|
||||
{
|
||||
if( (*mark)->flags & SURF_DRAWTURB && (*mark)->texinfo && (*mark)->texinfo->texture )
|
||||
return R_GetTexture( (*mark)->texinfo->texture->gl_texturenum );
|
||||
@@ -671,10 +654,6 @@ from underwater leaf (idea: XaeroX)
|
||||
*/
|
||||
static void R_CheckFog( void )
|
||||
{
|
||||
cl_entity_t *ent;
|
||||
gl_texture_t *tex;
|
||||
int i, cnt, count;
|
||||
|
||||
// quake global fog
|
||||
if( FBitSet( gp_host->features, ENGINE_QUAKE_COMPATIBLE ))
|
||||
{
|
||||
@@ -717,7 +696,8 @@ static void R_CheckFog( void )
|
||||
return;
|
||||
}
|
||||
|
||||
ent = gEngfuncs.CL_GetWaterEntity( RI.rvp.vieworigin );
|
||||
cl_entity_t *ent = gEngfuncs.CL_GetWaterEntity( RI.rvp.vieworigin );
|
||||
int cnt;
|
||||
if( ent && ent->model && ent->model->type == mod_brush && ent->curstate.skin < 0 )
|
||||
cnt = ent->curstate.skin;
|
||||
else cnt = RI.viewleaf->contents;
|
||||
@@ -726,16 +706,15 @@ static void R_CheckFog( void )
|
||||
|
||||
if( !IsLiquidContents( RI.cached_contents ) && IsLiquidContents( cnt ))
|
||||
{
|
||||
tex = NULL;
|
||||
gl_texture_t *tex = NULL;
|
||||
|
||||
// check for water texture
|
||||
if( ent && ent->model && ent->model->type == mod_brush )
|
||||
{
|
||||
msurface_t *surf;
|
||||
int count = ent->model->nummodelsurfaces;
|
||||
|
||||
count = ent->model->nummodelsurfaces;
|
||||
|
||||
for( i = 0, surf = &ent->model->surfaces[ent->model->firstmodelsurface]; i < count; i++, surf++ )
|
||||
msurface_t *surf = &ent->model->surfaces[ent->model->firstmodelsurface];
|
||||
for( int i = 0; i < count; i++, surf++ )
|
||||
{
|
||||
if( surf->flags & SURF_DRAWTURB && surf->texinfo && surf->texinfo->texture )
|
||||
{
|
||||
@@ -817,13 +796,11 @@ R_DrawEntitiesOnList
|
||||
*/
|
||||
static void R_DrawEntitiesOnList( void )
|
||||
{
|
||||
int i;
|
||||
|
||||
tr.blend = 1.0f;
|
||||
GL_CheckForErrors();
|
||||
|
||||
// first draw solid entities
|
||||
for( i = 0; i < tr.draw_list->num_solid_entities && !FBitSet( RI.rvp.flags, RF_ONLY_CLIENTDRAW ); i++ )
|
||||
for( int i = 0; i < tr.draw_list->num_solid_entities && !FBitSet( RI.rvp.flags, RF_ONLY_CLIENTDRAW ); i++ )
|
||||
{
|
||||
RI.currententity = tr.draw_list->solid_entities[i];
|
||||
RI.currentmodel = RI.currententity->model;
|
||||
@@ -855,7 +832,7 @@ static void R_DrawEntitiesOnList( void )
|
||||
GL_CheckForErrors();
|
||||
|
||||
// draw sprites seperately, because of alpha blending
|
||||
for( i = 0; i < tr.draw_list->num_solid_entities && !FBitSet( RI.rvp.flags, RF_ONLY_CLIENTDRAW ); i++ )
|
||||
for( int i = 0; i < tr.draw_list->num_solid_entities && !FBitSet( RI.rvp.flags, RF_ONLY_CLIENTDRAW ); i++ )
|
||||
{
|
||||
RI.currententity = tr.draw_list->solid_entities[i];
|
||||
RI.currentmodel = RI.currententity->model;
|
||||
@@ -886,7 +863,7 @@ static void R_DrawEntitiesOnList( void )
|
||||
GL_CheckForErrors();
|
||||
|
||||
// then draw translucent entities
|
||||
for( i = 0; i < tr.draw_list->num_trans_entities && !FBitSet( RI.rvp.flags, RF_ONLY_CLIENTDRAW ); i++ )
|
||||
for( int i = 0; i < tr.draw_list->num_trans_entities && !FBitSet( RI.rvp.flags, RF_ONLY_CLIENTDRAW ); i++ )
|
||||
{
|
||||
RI.currententity = tr.draw_list->trans_entities[i];
|
||||
RI.currentmodel = RI.currententity->model;
|
||||
@@ -1174,11 +1151,8 @@ CL_FxBlend
|
||||
*/
|
||||
int CL_FxBlend( cl_entity_t *e )
|
||||
{
|
||||
int blend = 0;
|
||||
float offset, dist;
|
||||
vec3_t tmp;
|
||||
|
||||
offset = ((int)e->index ) * 363.0f; // Use ent index to de-sync these fx
|
||||
int blend = 0;
|
||||
float offset = ((int)e->index ) * 363.0f; // Use ent index to de-sync these fx
|
||||
|
||||
switch( e->curstate.renderfx )
|
||||
{
|
||||
@@ -1257,9 +1231,11 @@ int CL_FxBlend( cl_entity_t *e )
|
||||
break;
|
||||
case kRenderFxHologram:
|
||||
case kRenderFxDistort:
|
||||
{
|
||||
vec3_t tmp;
|
||||
VectorCopy( e->origin, tmp );
|
||||
VectorSubtract( tmp, RI.rvp.vieworigin, tmp );
|
||||
dist = DotProduct( tmp, RI.vforward );
|
||||
float dist = DotProduct( tmp, RI.vforward );
|
||||
|
||||
// turn off distance fade
|
||||
if( e->curstate.renderfx == kRenderFxDistort )
|
||||
@@ -1277,6 +1253,7 @@ int CL_FxBlend( cl_entity_t *e )
|
||||
blend += gEngfuncs.COM_RandomLong( -32, 31 );
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
blend = e->curstate.renderamt;
|
||||
break;
|
||||
|
||||
@@ -47,12 +47,6 @@ update particle color, position, free expired and draw it
|
||||
*/
|
||||
void CL_DrawParticles( double frametime, particle_t *cl_active_particles, float partsize )
|
||||
{
|
||||
particle_t *p;
|
||||
vec3_t right, up;
|
||||
color24 color;
|
||||
int alpha;
|
||||
float size;
|
||||
|
||||
if( !cl_active_particles )
|
||||
return; // nothing to draw?
|
||||
|
||||
@@ -66,11 +60,11 @@ void CL_DrawParticles( double frametime, particle_t *cl_active_particles, float
|
||||
|
||||
pglBegin( GL_QUADS );
|
||||
|
||||
for( p = cl_active_particles; p; p = p->next )
|
||||
for( particle_t *p = cl_active_particles; p; p = p->next )
|
||||
{
|
||||
if(( p->type != pt_blob ) || ( p->unused == 255 ))
|
||||
{
|
||||
size = partsize; // get initial size of particle
|
||||
float size = partsize; // get initial size of particle
|
||||
|
||||
// scale up to keep particles from disappearing
|
||||
size += (p->org[0] - RI.rvp.vieworigin[0]) * RI.cull_vforward[0];
|
||||
@@ -81,13 +75,14 @@ void CL_DrawParticles( double frametime, particle_t *cl_active_particles, float
|
||||
else size = partsize + size * 0.002f;
|
||||
|
||||
// scale the axes by radius
|
||||
vec3_t right, up;
|
||||
VectorScale( RI.cull_vright, size, right );
|
||||
VectorScale( RI.cull_vup, size, up );
|
||||
|
||||
p->color = bound( 0, p->color, 255 );
|
||||
color = tr.palette[p->color];
|
||||
color24 color = tr.palette[p->color];
|
||||
|
||||
alpha = 255 * (p->die - gp_cl->time) * 16.0f;
|
||||
int alpha = 255 * (p->die - gp_cl->time) * 16.0f;
|
||||
if( alpha > 255 || p->type == pt_static )
|
||||
alpha = 255;
|
||||
|
||||
@@ -120,11 +115,10 @@ check tracer bbox
|
||||
*/
|
||||
static qboolean CL_CullTracer( particle_t *p, const vec3_t start, const vec3_t end )
|
||||
{
|
||||
vec3_t mins, maxs;
|
||||
int i;
|
||||
vec3_t mins, maxs;
|
||||
|
||||
// compute the bounding box
|
||||
for( i = 0; i < 3; i++ )
|
||||
for( int i = 0; i < 3; i++ )
|
||||
{
|
||||
if( start[i] < end[i] )
|
||||
{
|
||||
@@ -157,11 +151,6 @@ update tracer color, position, free expired and draw it
|
||||
*/
|
||||
void CL_DrawTracers( double frametime, particle_t *cl_active_tracers )
|
||||
{
|
||||
float scale, atten, gravity;
|
||||
vec3_t screenLast, screen;
|
||||
vec3_t start, end, delta;
|
||||
particle_t *p;
|
||||
|
||||
// update tracer color if this is changed
|
||||
if( FBitSet( tracerred->flags|tracergreen->flags|tracerblue->flags|traceralpha->flags, FCVAR_CHANGED ))
|
||||
{
|
||||
@@ -187,17 +176,18 @@ void CL_DrawTracers( double frametime, particle_t *cl_active_tracers )
|
||||
pglDisable( GL_ALPHA_TEST );
|
||||
pglDepthMask( GL_FALSE );
|
||||
|
||||
gravity = frametime * gp_movevars->gravity;
|
||||
scale = 1.0 - (frametime * 0.9);
|
||||
float gravity = frametime * gp_movevars->gravity;
|
||||
float scale = 1.0 - (frametime * 0.9);
|
||||
if( scale < 0.0f ) scale = 0.0f;
|
||||
|
||||
pglBegin( GL_QUADS );
|
||||
|
||||
for( p = cl_active_tracers; p; p = p->next )
|
||||
for( particle_t *p = cl_active_tracers; p; p = p->next )
|
||||
{
|
||||
atten = (p->die - gp_cl->time);
|
||||
float atten = (p->die - gp_cl->time);
|
||||
if( atten > 0.1f ) atten = 0.1f;
|
||||
|
||||
vec3_t start, end, delta;
|
||||
VectorScale( p->vel, ( p->ramp * atten ), delta );
|
||||
VectorAdd( p->org, delta, end );
|
||||
VectorCopy( p->org, start );
|
||||
@@ -206,7 +196,7 @@ void CL_DrawTracers( double frametime, particle_t *cl_active_tracers )
|
||||
{
|
||||
vec3_t verts[4], tmp2;
|
||||
vec3_t tmp, normal;
|
||||
color24 color;
|
||||
vec3_t screen, screenLast;
|
||||
|
||||
// Transform point into screen space
|
||||
TriWorldToScreen( start, screen );
|
||||
@@ -235,7 +225,7 @@ void CL_DrawTracers( double frametime, particle_t *cl_active_tracers )
|
||||
p->color = TRACER_COLORINDEX_DEFAULT;
|
||||
}
|
||||
|
||||
color = gTracerColors[p->color];
|
||||
color24 color = gTracerColors[p->color];
|
||||
pglColor4ub( color.r, color.g, color.b, p->unused );
|
||||
|
||||
pglTexCoord2f( 0.0f, 0.8f );
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -31,19 +31,12 @@ between frames where are we lerping
|
||||
*/
|
||||
static float R_GetSpriteFrameInterpolant( cl_entity_t *ent, mspriteframe_t **oldframe, mspriteframe_t **curframe )
|
||||
{
|
||||
msprite_t *psprite;
|
||||
mspritegroup_t *pspritegroup;
|
||||
int i, j, numframes, frame;
|
||||
float lerpFrac, time, jtime, jinterval;
|
||||
float *pintervals, fullinterval, targettime;
|
||||
int m_fDoInterp;
|
||||
|
||||
psprite = ent->model->cache.data;
|
||||
frame = (int)ent->curstate.frame;
|
||||
lerpFrac = 1.0f;
|
||||
msprite_t *psprite = ent->model->cache.data;
|
||||
int frame = (int)ent->curstate.frame;
|
||||
float lerpFrac = 1.0f;
|
||||
|
||||
// misc info
|
||||
m_fDoInterp = (ent->curstate.effects & EF_NOINTERP) ? false : true;
|
||||
int m_fDoInterp = (ent->curstate.effects & EF_NOINTERP) ? false : true;
|
||||
|
||||
if( frame < 0 )
|
||||
{
|
||||
@@ -106,20 +99,21 @@ static float R_GetSpriteFrameInterpolant( cl_entity_t *ent, mspriteframe_t **old
|
||||
}
|
||||
else if( psprite->frames[frame].type == FRAME_GROUP )
|
||||
{
|
||||
pspritegroup = (mspritegroup_t *)psprite->frames[frame].frameptr;
|
||||
pintervals = pspritegroup->intervals;
|
||||
numframes = pspritegroup->numframes;
|
||||
fullinterval = pintervals[numframes-1];
|
||||
jinterval = pintervals[1] - pintervals[0];
|
||||
time = gp_cl->time;
|
||||
jtime = 0.0f;
|
||||
mspritegroup_t *pspritegroup = (mspritegroup_t *)psprite->frames[frame].frameptr;
|
||||
float *pintervals = pspritegroup->intervals;
|
||||
int numframes = pspritegroup->numframes;
|
||||
float fullinterval = pintervals[numframes-1];
|
||||
float jinterval = pintervals[1] - pintervals[0];
|
||||
float time = gp_cl->time;
|
||||
float jtime = 0.0f;
|
||||
|
||||
// when loading in Mod_LoadSpriteGroup, we guaranteed all interval values
|
||||
// are positive, so we don't have to worry about division by zero
|
||||
targettime = time - ((int)(time / fullinterval)) * fullinterval;
|
||||
float targettime = time - ((int)(time / fullinterval)) * fullinterval;
|
||||
|
||||
// LordHavoc: since I can't measure the time properly when it loops from numframes - 1 to 0,
|
||||
// i instead measure the time of the first frame, hoping it is consistent
|
||||
int i, j;
|
||||
for( i = 0, j = numframes - 1; i < (numframes - 1); i++ )
|
||||
{
|
||||
if( pintervals[i] > targettime )
|
||||
@@ -178,7 +172,7 @@ static float R_GetSpriteFrameInterpolant( cl_entity_t *ent, mspriteframe_t **old
|
||||
lerpFrac = 1.0f;
|
||||
}
|
||||
|
||||
pspritegroup = (mspritegroup_t *)psprite->frames[ent->latched.prevblending[0]].frameptr;
|
||||
mspritegroup_t *pspritegroup = (mspritegroup_t *)psprite->frames[ent->latched.prevblending[0]].frameptr;
|
||||
if( oldframe ) *oldframe = pspritegroup->frames[angleframe];
|
||||
|
||||
pspritegroup = (mspritegroup_t *)psprite->frames[frame].frameptr;
|
||||
@@ -225,16 +219,13 @@ Set sprite brightness factor
|
||||
*/
|
||||
static float R_SpriteGlowBlend( vec3_t origin, int rendermode, int renderfx, float *pscale )
|
||||
{
|
||||
float dist, brightness;
|
||||
vec3_t glowDist;
|
||||
pmtrace_t *tr;
|
||||
|
||||
vec3_t glowDist;
|
||||
VectorSubtract( origin, RI.rvp.vieworigin, glowDist );
|
||||
dist = VectorLength( glowDist );
|
||||
float dist = VectorLength( glowDist );
|
||||
|
||||
if( !FBitSet( RI.rvp.flags, RF_DRAW_CUBEMAP ))
|
||||
{
|
||||
tr = gEngfuncs.EV_VisTraceLine( RI.rvp.vieworigin, origin, r_traceglow.value ? PM_GLASS_IGNORE : (PM_GLASS_IGNORE|PM_STUDIO_IGNORE));
|
||||
pmtrace_t *tr = gEngfuncs.EV_VisTraceLine( RI.rvp.vieworigin, origin, r_traceglow.value ? PM_GLASS_IGNORE : (PM_GLASS_IGNORE|PM_STUDIO_IGNORE));
|
||||
|
||||
if(( 1.0f - tr->fraction ) * dist > 8.0f )
|
||||
return 0.0f;
|
||||
@@ -243,7 +234,7 @@ static float R_SpriteGlowBlend( vec3_t origin, int rendermode, int renderfx, flo
|
||||
if( renderfx == kRenderFxNoDissipation )
|
||||
return 1.0f;
|
||||
|
||||
brightness = GLARE_FALLOFF / ( dist * dist );
|
||||
float brightness = GLARE_FALLOFF / ( dist * dist );
|
||||
brightness = bound( 0.05f, brightness, 1.0f );
|
||||
*pscale *= dist * ( 1.0f / 200.0f );
|
||||
|
||||
@@ -373,28 +364,19 @@ R_DrawSpriteModel
|
||||
*/
|
||||
void R_DrawSpriteModel( cl_entity_t *e )
|
||||
{
|
||||
mspriteframe_t *frame = NULL, *oldframe = NULL;
|
||||
msprite_t *psprite;
|
||||
model_t *model;
|
||||
int i, type;
|
||||
float angle, dot, sr, cr;
|
||||
float lerp = 1.0f, ilerp, scale;
|
||||
vec3_t v_forward, v_right, v_up;
|
||||
vec3_t origin, color, color2 = { 0.0f };
|
||||
|
||||
if( FBitSet( RI.rvp.flags, RF_DRAW_CUBEMAP ))
|
||||
return;
|
||||
|
||||
model = e->model;
|
||||
psprite = (msprite_t * )model->cache.data;
|
||||
model_t *model = e->model;
|
||||
msprite_t *psprite = (msprite_t *)model->cache.data;
|
||||
vec3_t origin, color, color2 = { 0.0f };
|
||||
vec3_t v_right, v_up;
|
||||
VectorCopy( e->origin, origin ); // set render origin
|
||||
|
||||
// do movewith
|
||||
if( e->curstate.aiment > 0 && e->curstate.movetype == MOVETYPE_FOLLOW )
|
||||
{
|
||||
cl_entity_t *parent;
|
||||
|
||||
parent = CL_GetEntityByIndex( e->curstate.aiment );
|
||||
cl_entity_t *parent = CL_GetEntityByIndex( e->curstate.aiment );
|
||||
|
||||
if( parent && parent->model )
|
||||
{
|
||||
@@ -407,7 +389,7 @@ void R_DrawSpriteModel( cl_entity_t *e )
|
||||
}
|
||||
}
|
||||
|
||||
scale = e->curstate.scale;
|
||||
float scale = e->curstate.scale;
|
||||
if( !scale ) scale = 1.0f;
|
||||
|
||||
if( R_SpriteOccluded( e, origin, &scale ))
|
||||
@@ -473,11 +455,13 @@ void R_DrawSpriteModel( cl_entity_t *e )
|
||||
pglAlphaFunc( GL_GREATER, 1.0f / 3.0f );
|
||||
}
|
||||
|
||||
mspriteframe_t *frame = NULL, *oldframe = NULL;
|
||||
float lerp = 1.0f;
|
||||
if( R_SpriteAllowLerping( e, psprite ))
|
||||
lerp = R_GetSpriteFrameInterpolant( e, &oldframe, &frame );
|
||||
else frame = oldframe = gEngfuncs.R_GetSpriteFrame( model, e->curstate.frame, e->angles[YAW] );
|
||||
|
||||
type = psprite->type;
|
||||
int type = psprite->type;
|
||||
|
||||
// automatically roll parallel sprites if requested
|
||||
if( e->angles[ROLL] != 0.0f && type == SPR_FWD_PARALLEL )
|
||||
@@ -486,32 +470,40 @@ void R_DrawSpriteModel( cl_entity_t *e )
|
||||
switch( type )
|
||||
{
|
||||
case SPR_ORIENTED:
|
||||
{
|
||||
vec3_t v_forward;
|
||||
AngleVectors( e->angles, v_forward, v_right, v_up );
|
||||
VectorScale( v_forward, 0.01f, v_forward ); // to avoid z-fighting
|
||||
VectorSubtract( origin, v_forward, origin );
|
||||
break;
|
||||
}
|
||||
case SPR_FACING_UPRIGHT:
|
||||
VectorSet( v_right, origin[1] - RI.rvp.vieworigin[1], -(origin[0] - RI.rvp.vieworigin[0]), 0.0f );
|
||||
VectorSet( v_up, 0.0f, 0.0f, 1.0f );
|
||||
VectorNormalize( v_right );
|
||||
break;
|
||||
case SPR_FWD_PARALLEL_UPRIGHT:
|
||||
dot = RI.vforward[2];
|
||||
{
|
||||
float dot = RI.vforward[2];
|
||||
if(( dot > 0.999848f ) || ( dot < -0.999848f )) // cos(1 degree) = 0.999848
|
||||
return; // invisible
|
||||
VectorSet( v_up, 0.0f, 0.0f, 1.0f );
|
||||
VectorSet( v_right, RI.vforward[1], -RI.vforward[0], 0.0f );
|
||||
VectorNormalize( v_right );
|
||||
break;
|
||||
}
|
||||
case SPR_FWD_PARALLEL_ORIENTED:
|
||||
angle = e->angles[ROLL] * (M_PI2 / 360.0f);
|
||||
{
|
||||
float angle = e->angles[ROLL] * (M_PI2 / 360.0f);
|
||||
float sr, cr;
|
||||
SinCos( angle, &sr, &cr );
|
||||
for( i = 0; i < 3; i++ )
|
||||
for( int i = 0; i < 3; i++ )
|
||||
{
|
||||
v_right[i] = (RI.vright[i] * cr + RI.vup[i] * sr);
|
||||
v_up[i] = RI.vright[i] * -sr + RI.vup[i] * cr;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case SPR_FWD_PARALLEL: // normal sprite
|
||||
default:
|
||||
VectorCopy( RI.vright, v_right );
|
||||
@@ -533,7 +525,7 @@ void R_DrawSpriteModel( cl_entity_t *e )
|
||||
{
|
||||
// draw two combined lerped frames
|
||||
lerp = bound( 0.0f, lerp, 1.0f );
|
||||
ilerp = 1.0f - lerp;
|
||||
float ilerp = 1.0f - lerp;
|
||||
|
||||
if( ilerp != 0.0f )
|
||||
{
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -222,9 +222,7 @@ convert world coordinates (x,y,z) into screen (x, y)
|
||||
*/
|
||||
int TriWorldToScreen( const float *world, float *screen )
|
||||
{
|
||||
int retval;
|
||||
|
||||
retval = R_WorldToScreen( world, screen );
|
||||
int retval = R_WorldToScreen( world, screen );
|
||||
|
||||
screen[0] = 0.5f * screen[0] * (float)RI.rvp.viewport[2];
|
||||
screen[1] = -0.5f * screen[1] * (float)RI.rvp.viewport[3];
|
||||
@@ -243,12 +241,11 @@ bind current texture
|
||||
*/
|
||||
int TriSpriteTexture( model_t *pSpriteModel, int frame )
|
||||
{
|
||||
int gl_texturenum;
|
||||
|
||||
if( !pSpriteModel || pSpriteModel->type != mod_sprite || !pSpriteModel->cache.data )
|
||||
return 0;
|
||||
|
||||
if(( gl_texturenum = gEngfuncs.R_GetSpriteFrame( pSpriteModel, frame, 0.0f )->gl_texturenum ) == 0 )
|
||||
int gl_texturenum = gEngfuncs.R_GetSpriteFrame( pSpriteModel, frame, 0.0f )->gl_texturenum;
|
||||
if( gl_texturenum == 0 )
|
||||
return 0;
|
||||
|
||||
if( gl_texturenum <= 0 || gl_texturenum >= MAX_TEXTURES )
|
||||
@@ -364,11 +361,9 @@ TriBrightness
|
||||
*/
|
||||
void TriBrightness( float brightness )
|
||||
{
|
||||
float r, g, b;
|
||||
|
||||
r = ds.triRGBA[0] * ds.triRGBA[3] * brightness;
|
||||
g = ds.triRGBA[1] * ds.triRGBA[3] * brightness;
|
||||
b = ds.triRGBA[2] * ds.triRGBA[3] * brightness;
|
||||
float r = ds.triRGBA[0] * ds.triRGBA[3] * brightness;
|
||||
float g = ds.triRGBA[1] * ds.triRGBA[3] * brightness;
|
||||
float b = ds.triRGBA[2] * ds.triRGBA[3] * brightness;
|
||||
|
||||
_TriColor4f( r, g, b, 1.0f );
|
||||
}
|
||||
|
||||
123
ref/gl/gl_warp.c
123
ref/gl/gl_warp.c
@@ -77,20 +77,20 @@ static struct
|
||||
|
||||
static void DrawSkyPolygon( int nump, vec3_t vecs )
|
||||
{
|
||||
int i, j, axis;
|
||||
float s, t, dv, *vp;
|
||||
vec3_t v, av;
|
||||
|
||||
// decide which face it maps to
|
||||
vec3_t v;
|
||||
VectorClear( v );
|
||||
|
||||
for( i = 0, vp = vecs; i < nump; i++, vp += 3 )
|
||||
float *vp = vecs;
|
||||
for( int i = 0; i < nump; i++, vp += 3 )
|
||||
VectorAdd( vp, v, v );
|
||||
|
||||
vec3_t av;
|
||||
av[0] = fabs( v[0] );
|
||||
av[1] = fabs( v[1] );
|
||||
av[2] = fabs( v[2] );
|
||||
|
||||
int axis;
|
||||
if( av[0] > av[1] && av[0] > av[2] )
|
||||
axis = (v[0] < 0) ? 1 : 0;
|
||||
else if( av[1] > av[2] && av[1] > av[0] )
|
||||
@@ -98,18 +98,18 @@ static void DrawSkyPolygon( int nump, vec3_t vecs )
|
||||
else axis = (v[2] < 0) ? 5 : 4;
|
||||
|
||||
// project new texture coords
|
||||
for( i = 0; i < nump; i++, vecs += 3 )
|
||||
for( int i = 0; i < nump; i++, vecs += 3 )
|
||||
{
|
||||
j = vec_to_st[axis][2];
|
||||
dv = (j > 0) ? vecs[j-1] : -vecs[-j-1];
|
||||
int j = vec_to_st[axis][2];
|
||||
float dv = (j > 0) ? vecs[j-1] : -vecs[-j-1];
|
||||
|
||||
if( dv == 0.0f ) continue;
|
||||
|
||||
j = vec_to_st[axis][0];
|
||||
s = (j < 0) ? -vecs[-j-1] / dv : vecs[j-1] / dv;
|
||||
float s = (j < 0) ? -vecs[-j-1] / dv : vecs[j-1] / dv;
|
||||
|
||||
j = vec_to_st[axis][1];
|
||||
t = (j < 0) ? -vecs[-j-1] / dv : vecs[j-1] / dv;
|
||||
float t = (j < 0) ? -vecs[-j-1] / dv : vecs[j-1] / dv;
|
||||
|
||||
if( s < RI.skyMins[0][axis] ) RI.skyMins[0][axis] = s;
|
||||
if( t < RI.skyMins[1][axis] ) RI.skyMins[1][axis] = t;
|
||||
@@ -220,18 +220,17 @@ loc1:
|
||||
|
||||
static void MakeSkyVec( float s, float t, int axis )
|
||||
{
|
||||
int j, k, farclip;
|
||||
vec3_t v, b;
|
||||
|
||||
farclip = RI.farClip;
|
||||
int farclip = RI.farClip;
|
||||
|
||||
vec3_t b;
|
||||
b[0] = s * (farclip >> 1);
|
||||
b[1] = t * (farclip >> 1);
|
||||
b[2] = (farclip >> 1);
|
||||
|
||||
for( j = 0; j < 3; j++ )
|
||||
vec3_t v;
|
||||
for( int j = 0; j < 3; j++ )
|
||||
{
|
||||
k = st_to_vec[axis][j];
|
||||
int k = st_to_vec[axis][j];
|
||||
v[j] = (k < 0) ? -b[-k-1] : b[k-1];
|
||||
v[j] += RI.cullorigin[j];
|
||||
}
|
||||
@@ -264,9 +263,7 @@ R_ClearSkyBox
|
||||
*/
|
||||
void R_ClearSkyBox( void )
|
||||
{
|
||||
int i;
|
||||
|
||||
for( i = 0; i < SKYBOX_MAX_SIDES; i++ )
|
||||
for( int i = 0; i < SKYBOX_MAX_SIDES; i++ )
|
||||
{
|
||||
RI.skyMins[0][i] = RI.skyMins[1][i] = 9999999.0f;
|
||||
RI.skyMaxs[0][i] = RI.skyMaxs[1][i] = -9999999.0f;
|
||||
@@ -280,18 +277,14 @@ R_AddSkyBoxSurface
|
||||
*/
|
||||
void R_AddSkyBoxSurface( msurface_t *fa )
|
||||
{
|
||||
vec3_t verts[MAX_CLIP_VERTS];
|
||||
glpoly2_t *p;
|
||||
float *v;
|
||||
int i;
|
||||
|
||||
if( FBitSet( tr.world->flags, FWORLD_SKYSPHERE ) && fa->polys && !FBitSet( tr.world->flags, FWORLD_CUSTOM_SKYBOX ))
|
||||
{
|
||||
glpoly2_t *p = fa->polys;
|
||||
glpoly2_t *p = fa->polys;
|
||||
|
||||
// draw the sky poly
|
||||
pglBegin( GL_POLYGON );
|
||||
for( i = 0, v = p->verts[0]; i < p->numverts; i++, v += VERTEXSIZE )
|
||||
float *v = p->verts[0];
|
||||
for( int i = 0; i < p->numverts; i++, v += VERTEXSIZE )
|
||||
{
|
||||
pglTexCoord2f( v[3], v[4] );
|
||||
pglVertex3fv( v );
|
||||
@@ -300,9 +293,10 @@ void R_AddSkyBoxSurface( msurface_t *fa )
|
||||
}
|
||||
|
||||
// calculate vertex values for sky box
|
||||
for( p = fa->polys; p; p = p->next )
|
||||
vec3_t verts[MAX_CLIP_VERTS];
|
||||
for( glpoly2_t *p = fa->polys; p; p = p->next )
|
||||
{
|
||||
for( i = 0; i < p->numverts; i++ )
|
||||
for( int i = 0; i < p->numverts; i++ )
|
||||
VectorSubtract( p->verts[i], RI.cullorigin, verts[i] );
|
||||
ClipSkyPolygon( p->numverts, verts[0], 0 );
|
||||
}
|
||||
@@ -317,10 +311,8 @@ Unload previous skybox
|
||||
*/
|
||||
void R_UnloadSkybox( void )
|
||||
{
|
||||
int i;
|
||||
|
||||
// release old skybox
|
||||
for( i = 0; i < SKYBOX_MAX_SIDES; i++ )
|
||||
for( int i = 0; i < SKYBOX_MAX_SIDES; i++ )
|
||||
{
|
||||
if( !tr.skyboxTextures[i] ) continue;
|
||||
GL_FreeTexture( tr.skyboxTextures[i] );
|
||||
@@ -387,18 +379,16 @@ R_CloudVertex
|
||||
*/
|
||||
static void R_CloudVertex( float s, float t, int axis, vec3_t v )
|
||||
{
|
||||
int j, k, farclip;
|
||||
vec3_t b;
|
||||
|
||||
farclip = RI.farClip;
|
||||
int farclip = RI.farClip;
|
||||
|
||||
vec3_t b;
|
||||
b[0] = s * (farclip >> 1);
|
||||
b[1] = t * (farclip >> 1);
|
||||
b[2] = (farclip >> 1);
|
||||
|
||||
for( j = 0; j < 3; j++ )
|
||||
for( int j = 0; j < 3; j++ )
|
||||
{
|
||||
k = st_to_vec[axis][j];
|
||||
int k = st_to_vec[axis][j];
|
||||
v[j] = (k < 0) ? -b[-k-1] : b[k-1];
|
||||
v[j] += RI.cullorigin[j];
|
||||
}
|
||||
@@ -411,16 +401,14 @@ R_CloudTexCoord
|
||||
*/
|
||||
static void R_CloudTexCoord( const vec3_t v, float speed, float *s, float *t )
|
||||
{
|
||||
float length, speedscale;
|
||||
vec3_t dir;
|
||||
|
||||
speedscale = gp_cl->time * speed;
|
||||
float speedscale = gp_cl->time * speed;
|
||||
speedscale -= (int)speedscale & ~127;
|
||||
|
||||
vec3_t dir;
|
||||
VectorSubtract( v, RI.rvp.vieworigin, dir );
|
||||
dir[2] *= 3.0f; // flatten the sphere
|
||||
|
||||
length = VectorLength( dir );
|
||||
float length = VectorLength( dir );
|
||||
length = 6.0f * 63.0f / length;
|
||||
|
||||
*s = ( speedscale + dir[0] * length ) * (1.0f / 128.0f);
|
||||
@@ -434,16 +422,14 @@ R_CloudDrawPoly
|
||||
*/
|
||||
static void R_CloudDrawPoly( const float *verts )
|
||||
{
|
||||
const float *v;
|
||||
float s, t;
|
||||
int i;
|
||||
|
||||
GL_SetRenderMode( kRenderNormal );
|
||||
GL_Bind( XASH_TEXTURE0, tr.solidskyTexture );
|
||||
|
||||
pglBegin( GL_QUADS );
|
||||
for( i = 0, v = verts; i < 4; i++, v += VERTEXSIZE )
|
||||
const float *v = verts;
|
||||
for( int i = 0; i < 4; i++, v += VERTEXSIZE )
|
||||
{
|
||||
float s, t;
|
||||
R_CloudTexCoord( v, 8.0f, &s, &t );
|
||||
pglTexCoord2f( s, t );
|
||||
pglVertex3fv( v );
|
||||
@@ -454,8 +440,10 @@ static void R_CloudDrawPoly( const float *verts )
|
||||
GL_Bind( XASH_TEXTURE0, tr.alphaskyTexture );
|
||||
|
||||
pglBegin( GL_QUADS );
|
||||
for( i = 0, v = verts; i < 4; i++, v += VERTEXSIZE )
|
||||
v = verts;
|
||||
for( int i = 0; i < 4; i++, v += VERTEXSIZE )
|
||||
{
|
||||
float s, t;
|
||||
R_CloudTexCoord( v, 16.0f, &s, &t );
|
||||
pglTexCoord2f( s, t );
|
||||
pglVertex3fv( v );
|
||||
@@ -472,29 +460,24 @@ R_CloudRenderSide
|
||||
*/
|
||||
static void R_CloudRenderSide( int axis )
|
||||
{
|
||||
vec3_t verts[4];
|
||||
float final_verts[4][VERTEXSIZE];
|
||||
float di, qi, dj, qj;
|
||||
vec3_t vup, vright;
|
||||
vec3_t temp, temp2;
|
||||
int i, j;
|
||||
|
||||
vec3_t verts[4];
|
||||
R_CloudVertex( -1.0f, -1.0f, axis, verts[0] );
|
||||
R_CloudVertex( -1.0f, 1.0f, axis, verts[1] );
|
||||
R_CloudVertex( 1.0f, 1.0f, axis, verts[2] );
|
||||
R_CloudVertex( 1.0f, -1.0f, axis, verts[3] );
|
||||
|
||||
vec3_t vup, vright;
|
||||
VectorSubtract( verts[2], verts[3], vup );
|
||||
VectorSubtract( verts[2], verts[1], vright );
|
||||
|
||||
di = SKYCLOUDS_QUALITY;
|
||||
qi = 1.0f / di;
|
||||
dj = (axis < 4) ? di * 2 : di; //subdivide vertically more than horizontally on skybox sides
|
||||
qj = 1.0f / dj;
|
||||
float di = SKYCLOUDS_QUALITY;
|
||||
float qi = 1.0f / di;
|
||||
float dj = (axis < 4) ? di * 2 : di; //subdivide vertically more than horizontally on skybox sides
|
||||
float qj = 1.0f / dj;
|
||||
|
||||
for( i = 0; i < di; i++ )
|
||||
for( int i = 0; i < di; i++ )
|
||||
{
|
||||
for( j = 0; j < dj; j++ )
|
||||
for( int j = 0; j < dj; j++ )
|
||||
{
|
||||
if( i * qi < RI.skyMins[0][axis] / 2 + 0.5f - qi
|
||||
|| i * qi > RI.skyMaxs[0][axis] / 2 + 0.5f
|
||||
@@ -502,9 +485,11 @@ static void R_CloudRenderSide( int axis )
|
||||
|| j * qj > RI.skyMaxs[1][axis] / 2 + 0.5f )
|
||||
continue;
|
||||
|
||||
vec3_t temp, temp2;
|
||||
VectorScale( vright, qi * i, temp );
|
||||
VectorScale( vup, qj * j, temp2 );
|
||||
VectorAdd( temp, temp2, temp );
|
||||
float final_verts[4][VERTEXSIZE];
|
||||
VectorAdd( verts[0], temp, final_verts[0] );
|
||||
|
||||
VectorScale( vup, qj, temp );
|
||||
@@ -653,10 +638,6 @@ static void R_GetRippleTextureSize( const texture_t *image, int *width, int *hei
|
||||
|
||||
qboolean R_UploadRipples( texture_t *image )
|
||||
{
|
||||
const gl_texture_t *glt;
|
||||
const uint32_t *pixels;
|
||||
int y;
|
||||
int width, height, size;
|
||||
qboolean update = g_ripple.update;
|
||||
|
||||
if( !r_ripple.value )
|
||||
@@ -666,13 +647,14 @@ qboolean R_UploadRipples( texture_t *image )
|
||||
}
|
||||
|
||||
// discard unuseful textures
|
||||
glt = R_GetTexture( image->gl_texturenum );
|
||||
const gl_texture_t *glt = R_GetTexture( image->gl_texturenum );
|
||||
if( !glt || !glt->original || !glt->original->buffer )
|
||||
{
|
||||
GL_Bind( XASH_TEXTURE0, image->gl_texturenum );
|
||||
return false;
|
||||
}
|
||||
|
||||
int width, height;
|
||||
if( !image->fb_texturenum )
|
||||
{
|
||||
rgbdata_t pic = { 0 };
|
||||
@@ -708,15 +690,14 @@ qboolean R_UploadRipples( texture_t *image )
|
||||
|
||||
R_GetRippleTextureSize( image, &width, &height );
|
||||
|
||||
size = r_ripple.value == 1.0f ? 64 : RIPPLES_CACHEWIDTH;
|
||||
pixels = (const uint32_t *)glt->original->buffer;
|
||||
int size = r_ripple.value == 1.0f ? 64 : RIPPLES_CACHEWIDTH;
|
||||
const uint32_t *pixels = (const uint32_t *)glt->original->buffer;
|
||||
|
||||
for( y = 0; y < height; y++ )
|
||||
for( int y = 0; y < height; y++ )
|
||||
{
|
||||
int ry = (float)y / height * size;
|
||||
int x;
|
||||
|
||||
for( x = 0; x < width; x++ )
|
||||
for( int x = 0; x < width; x++ )
|
||||
{
|
||||
int rx = (float)x / width * size;
|
||||
int val = g_ripple.curbuf[ry * RIPPLES_CACHEWIDTH + rx] / 16;
|
||||
|
||||
@@ -124,17 +124,15 @@ extern GLboolean fogging;
|
||||
|
||||
static GLuint VGL_GenerateShader( const vgl_prog_t *prog, GLenum type )
|
||||
{
|
||||
char *shader, shader_buf[MAX_SHADERLEN + 1];
|
||||
char shader_buf[MAX_SHADERLEN + 1];
|
||||
char tmp[256];
|
||||
int i;
|
||||
GLint status, len;
|
||||
GLuint id;
|
||||
GLint status;
|
||||
|
||||
shader = shader_buf;
|
||||
char *shader = shader_buf;
|
||||
shader[0] = '\n';
|
||||
shader[1] = 0;
|
||||
|
||||
for ( i = 0; i < VGL_FLAG_MAX; ++i )
|
||||
for ( int i = 0; i < VGL_FLAG_MAX; ++i )
|
||||
{
|
||||
Q_snprintf( tmp, sizeof( tmp ), "#define %s %d\n", vgl_flag_name[i], prog->flags & ( 1 << i ) );
|
||||
Q_strncat( shader, tmp, MAX_SHADERLEN );
|
||||
@@ -145,8 +143,8 @@ static GLuint VGL_GenerateShader( const vgl_prog_t *prog, GLenum type )
|
||||
else
|
||||
Q_strncat( shader, vgl_vert_src, MAX_SHADERLEN );
|
||||
|
||||
id = glCreateShader( type );
|
||||
len = Q_strlen( shader );
|
||||
GLuint id = glCreateShader( type );
|
||||
GLint len = Q_strlen( shader );
|
||||
glShaderSource( id, 1, (const void *)&shader, &len );
|
||||
glCompileShader( id );
|
||||
glGetShaderiv( id, GL_COMPILE_STATUS, &status );
|
||||
@@ -163,9 +161,7 @@ static GLuint VGL_GenerateShader( const vgl_prog_t *prog, GLenum type )
|
||||
|
||||
static vgl_prog_t *VGL_GetProg( const GLuint flags )
|
||||
{
|
||||
int i, loc, status;
|
||||
GLuint vp, fp, glprog;
|
||||
vgl_prog_t *prog;
|
||||
int i, status;
|
||||
|
||||
// try to find existing prog matching this feature set
|
||||
|
||||
@@ -189,22 +185,22 @@ static vgl_prog_t *VGL_GetProg( const GLuint flags )
|
||||
// new prog; generate shaders
|
||||
|
||||
gEngfuncs.Con_DPrintf( S_NOTE "VGL_GetProg(): Generating progs for 0x%04x\n", flags );
|
||||
prog = &vgl.progs[i];
|
||||
vgl_prog_t *prog = &vgl.progs[i];
|
||||
prog->flags = flags;
|
||||
|
||||
vp = VGL_GenerateShader( prog, GL_VERTEX_SHADER );
|
||||
fp = VGL_GenerateShader( prog, GL_FRAGMENT_SHADER );
|
||||
GLuint vp = VGL_GenerateShader( prog, GL_VERTEX_SHADER );
|
||||
GLuint fp = VGL_GenerateShader( prog, GL_FRAGMENT_SHADER );
|
||||
if ( !vp || !fp )
|
||||
{
|
||||
prog->flags = 0;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
glprog = glCreateProgram();
|
||||
GLuint glprog = glCreateProgram();
|
||||
glAttachShader( glprog, vp );
|
||||
glAttachShader( glprog, fp );
|
||||
|
||||
loc = 0;
|
||||
int loc = 0;
|
||||
for ( i = 0; i < VGL_ATTR_MAX; ++i )
|
||||
{
|
||||
if ( flags & ( 1 << i ) )
|
||||
@@ -283,8 +279,7 @@ static vgl_prog_t *VGL_SetProg( const GLuint flags )
|
||||
|
||||
int VGL_ShimInit( void )
|
||||
{
|
||||
int i;
|
||||
GLuint total, size;
|
||||
GLuint total;
|
||||
static const GLuint precache_progs[] = {
|
||||
0x0001, // out = ucolor
|
||||
0x0005, // out = tex0 * ucolor
|
||||
@@ -308,9 +303,9 @@ int VGL_ShimInit( void )
|
||||
vgl.uchanged = GL_TRUE;
|
||||
|
||||
total = 0;
|
||||
for ( i = 0; i < VGL_ATTR_MAX; ++i )
|
||||
for ( int i = 0; i < VGL_ATTR_MAX; ++i )
|
||||
{
|
||||
size = VGL_MAX_VERTS * vgl_attr_size[i] * sizeof( GLfloat );
|
||||
GLuint size = VGL_MAX_VERTS * vgl_attr_size[i] * sizeof( GLfloat );
|
||||
vgl.attrbuf[i] = memalign( 0x100, size );
|
||||
total += size;
|
||||
}
|
||||
@@ -319,7 +314,7 @@ int VGL_ShimInit( void )
|
||||
|
||||
gEngfuncs.Con_DPrintf( S_NOTE "VGL_ShimInit(): %u bytes allocated for vertex buffer\n", total );
|
||||
gEngfuncs.Con_DPrintf( S_NOTE "VGL_ShimInit(): Pre-generating %u progs...\n", sizeof( precache_progs ) / sizeof( *precache_progs ) );
|
||||
for ( i = 0; i < (int)( sizeof( precache_progs ) / sizeof( *precache_progs ) ); ++i )
|
||||
for ( int i = 0; i < (int)( sizeof( precache_progs ) / sizeof( *precache_progs ) ); ++i )
|
||||
VGL_GetProg( precache_progs[i] );
|
||||
|
||||
vgl_init = 1;
|
||||
@@ -328,8 +323,6 @@ int VGL_ShimInit( void )
|
||||
|
||||
void VGL_ShimShutdown( void )
|
||||
{
|
||||
int i;
|
||||
|
||||
if ( !vgl_init )
|
||||
return;
|
||||
|
||||
@@ -339,14 +332,14 @@ void VGL_ShimShutdown( void )
|
||||
/*
|
||||
// FIXME: this sometimes causes the game to block on glDeleteProgram for up to a minute
|
||||
// but since this is only called on shutdown or game change, it should be fine to skip
|
||||
for ( i = 0; i < MAX_PROGS; ++i )
|
||||
for ( int i = 0; i < MAX_PROGS; ++i )
|
||||
{
|
||||
if ( vgl.progs[i].flags )
|
||||
glDeleteProgram( vgl.progs[i].glprog );
|
||||
}
|
||||
*/
|
||||
|
||||
for ( i = 0; i < VGL_ATTR_MAX; ++i )
|
||||
for ( int i = 0; i < VGL_ATTR_MAX; ++i )
|
||||
free( vgl.attrbuf[i] );
|
||||
|
||||
memset( &vgl, 0, sizeof( vgl ) );
|
||||
@@ -361,22 +354,20 @@ void VGL_ShimEndFrame( void )
|
||||
|
||||
static void VGL_Begin( GLenum prim )
|
||||
{
|
||||
int i;
|
||||
vgl.prim = prim;
|
||||
vgl.begin = vgl.end;
|
||||
// pos always enabled
|
||||
vgl.cur_flags = 1 << VGL_ATTR_POS;
|
||||
// disable all vertex attrib pointers
|
||||
for ( i = 0; i < VGL_ATTR_MAX; ++i )
|
||||
for ( int i = 0; i < VGL_ATTR_MAX; ++i )
|
||||
glDisableVertexAttribArray( i );
|
||||
}
|
||||
|
||||
static void VGL_End( void )
|
||||
{
|
||||
int i;
|
||||
vgl_prog_t *prog;
|
||||
GLuint flags = vgl.cur_flags;
|
||||
GLint count = vgl.end - vgl.begin;
|
||||
const GLint count = vgl.end - vgl.begin;
|
||||
const vgl_prog_t *prog;
|
||||
|
||||
if ( !vgl.prim || !count )
|
||||
goto _leave; // end without begin
|
||||
@@ -394,7 +385,7 @@ static void VGL_End( void )
|
||||
goto _leave;
|
||||
}
|
||||
|
||||
for ( i = 0; i < VGL_ATTR_MAX; ++i )
|
||||
for ( int i = 0; i < VGL_ATTR_MAX; ++i )
|
||||
{
|
||||
if ( prog->attridx[i] >= 0 )
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user