ref_soft: Add sprite, EFX

This commit is contained in:
mittorn 2019-03-30 20:24:58 +07:00
parent b0ed8a5ba3
commit f34db62940
9 changed files with 2753 additions and 55 deletions

1313
r_beams.c Normal file

File diff suppressed because it is too large Load Diff

View File

@ -132,10 +132,10 @@ qboolean Mod_ProcessRenderData( model_t *mod, qboolean create, const byte *buf )
switch( mod->type )
{
case mod_studio:
// Mod_LoadStudioModel( mod, buf, loaded );
//Mod_LoadStudioModel( mod, buf, loaded );
break;
case mod_sprite:
//Mod_LoadSpriteModel( mod, buf, &loaded, mod->numtexinfo );
Mod_LoadSpriteModel( mod, buf, &loaded, mod->numtexinfo );
break;
case mod_alias:
//Mod_LoadAliasModel( mod, buf, &loaded );
@ -306,7 +306,7 @@ void Mod_UnloadTextures( model_t *mod )
Mod_BrushUnloadTextures( mod );
break;
case mod_sprite:
//Mod_SpriteUnloadTextures( mod->cache.data );
Mod_SpriteUnloadTextures( mod->cache.data );
break;
default: gEngfuncs.Host_Error( "Mod_UnloadModel: unsupported type %d\n", mod->type );
}
@ -357,11 +357,6 @@ void GL_SetRenderMode(int mode)
/// maybe, setup block drawing function pointers here
}
void CL_AddCustomBeam(cl_entity_t *pEnvBeam)
{
// same for beams
}
void R_ShowTextures()
{
// textures undone too
@ -397,31 +392,6 @@ void GL_SubdivideSurface(msurface_t *fa)
}
void Mod_LoadMapSprite(model_t *mod, const void *buffer, size_t size, qboolean *loaded)
{
}
void CL_DrawParticles(double frametime, particle_t *cl_active_particles, float partsize)
{
}
void CL_DrawBeams(int fTrans, BEAM *active_beams)
{
}
void CL_DrawTracers(double frametime, particle_t *cl_active_tracers)
{
}
qboolean R_BeamCull(const vec3_t start, const vec3_t end, qboolean pvsOnly)
{
return false;
}
void DrawSingleDecal(decal_t *pDecal, msurface_t *fa)
{
@ -457,11 +427,6 @@ void GL_TextureTarget(uint target)
}
void CL_DrawParticlesExternal(const ref_viewpass_t *rvp, qboolean trans_pass, float frametime)
{
// no renderapi support
}
void GL_BuildLightmaps()
{
CL_RunLightStyles();

View File

@ -42,11 +42,11 @@ void R_GetSpriteParms( int *frameWidth, int *frameHeight, int *numFrames, int cu
mspriteframe_t *pFrame;
if( !pSprite || pSprite->type != mod_sprite ) return; // bad model ?
//pFrame = R_GetSpriteFrame( pSprite, currentFrame, 0.0f );
pFrame = R_GetSpriteFrame( pSprite, currentFrame, 0.0f );
//if( frameWidth ) *frameWidth = pFrame->width;
// if( frameHeight ) *frameHeight = pFrame->height;
//if( numFrames ) *numFrames = pSprite->numframes;
if( frameWidth ) *frameWidth = pFrame->width;
if( frameHeight ) *frameHeight = pFrame->height;
if( numFrames ) *numFrames = pSprite->numframes;
}
int R_GetSpriteTexture( const model_t *m_pSpriteModel, int frame )
@ -54,7 +54,7 @@ int R_GetSpriteTexture( const model_t *m_pSpriteModel, int frame )
if( !m_pSpriteModel || m_pSpriteModel->type != mod_sprite || !m_pSpriteModel->cache.data )
return 0;
return 0;//R_GetSpriteFrame( m_pSpriteModel, frame, 0.0f )->gl_texturenum;
return R_GetSpriteFrame( m_pSpriteModel, frame, 0.0f )->gl_texturenum;
}

View File

@ -502,7 +502,7 @@ static qboolean GL_UploadTexture( image_t *tex, rgbdata_t *pic )
GL_SetTextureDimensions( tex, pic->width, pic->height, pic->depth );
GL_SetTextureFormat( tex, pic->type, pic->flags );
gEngfuncs.Con_Printf("%s %d %d\n", tex->name, tex->width, tex->height );
//gEngfuncs.Con_Printf("%s %d %d\n", tex->name, tex->width, tex->height );
Assert( pic != NULL );
Assert( tex != NULL );
@ -533,7 +533,7 @@ static qboolean GL_UploadTexture( image_t *tex, rgbdata_t *pic )
//GL_TextureImageRAW( tex, i, j, width, height, tex->depth, pic->type, data );
// increase size to workaround triangle renderer bugs
// it seems to assume memory readable. maybe it was pointed to WAD?
tex->pixels[j] = (byte*)Mem_Calloc( r_temppool, width * height * sizeof(pixel_t) + 256 ) + 128;
tex->pixels[j] = (byte*)Mem_Calloc( r_temppool, width * height * sizeof(pixel_t) + 1024 ) + 512;
if( j == 0 && tex->flags & TF_HAS_ALPHA )
tex->alpha_pixels = (byte*)Mem_Calloc( r_temppool, width * height * sizeof(pixel_t) + 256 ) + 128;

View File

@ -394,13 +394,13 @@ void GL_Cull( unsigned int cull );
void R_ShowTextures( void );
void R_ShowTree( void );
void SCR_TimeRefresh_f( void );
#endif
//
// gl_beams.c
//
void CL_DrawBeams( int fTrans, BEAM *active_beams );
qboolean R_BeamCull( const vec3_t start, const vec3_t end, qboolean pvsOnly );
#if 0
//
// gl_cull.c
//
@ -534,7 +534,7 @@ void GL_ResetFogColor( void );
void R_GenerateVBO();
void R_ClearVBO();
void R_AddDecalVBO( decal_t *pdecal, msurface_t *surf );
#endif
//
// gl_rpart.c
//
@ -550,7 +550,7 @@ void R_SpriteInit( void );
void Mod_LoadSpriteModel( model_t *mod, const void *buffer, qboolean *loaded, uint texFlags );
mspriteframe_t *R_GetSpriteFrame( const model_t *pModel, int frame, float yaw );
void R_DrawSpriteModel( cl_entity_t *e );
#endif
//
// gl_studio.c
//
@ -679,7 +679,7 @@ void TriVertex3fv( const float *v );
void TriVertex3f( float x, float y, float z );
void _TriColor4f( float r, float g, float b, float a );
void TriColor4ub( byte r, byte g, byte b, byte a );
int TriWorldToScreen( float *world, float *screen );
int TriWorldToScreen( const float *world, float *screen );
int TriSpriteTexture( model_t *pSpriteModel, int frame );
void TriFog( float flFogColor[3], float flStart, float flEnd, int bOn );
void TriGetMatrix( const int pname, float *matrix );
@ -1225,10 +1225,15 @@ extern cvar_t *sw_surfcacheoverride;
extern cvar_t *sw_waterwarp;
extern cvar_t *sw_texfilt;
extern cvar_t *r_decals;
extern cvar_t *r_traceglow;
extern cvar_t *sw_notransbrushes;
extern cvar_t *sw_noalphabrushes;
extern cvar_t *tracerred;
extern cvar_t *tracergreen;
extern cvar_t *tracerblue;
extern cvar_t *traceralpha;
extern vec3_t modelorg;

View File

@ -94,6 +94,12 @@ cvar_t *r_lerpmodels;
cvar_t *r_novis;
cvar_t *r_lightmap;
cvar_t *r_dynamic;
cvar_t *r_traceglow;
cvar_t *tracerred;
cvar_t *tracergreen;
cvar_t *tracerblue;
cvar_t *traceralpha;
cvar_t *r_speeds;
cvar_t *r_lightlevel; //FIXME HACK
@ -1091,6 +1097,7 @@ void R_DrawEntitiesOnList( void )
// GL_CheckForErrors();
R_SetUpWorldTransform();
// draw sprites seperately, because of alpha blending
for( i = 0; i < tr.draw_list->num_solid_entities && !RI.onlyClientDraw; i++ )
{
@ -1103,7 +1110,7 @@ void R_DrawEntitiesOnList( void )
switch( RI.currentmodel->type )
{
case mod_sprite:
// R_DrawSpriteModel( RI.currententity );
R_DrawSpriteModel( RI.currententity );
break;
}
}
@ -1133,7 +1140,7 @@ void R_DrawEntitiesOnList( void )
tr.blend = gEngfuncs.CL_FxBlend( RI.currententity ) / 255.0f;
else tr.blend = 1.0f; // draw as solid but sorted by distance
//if( tr.blend <= 0.0f ) continue;
if( tr.blend <= 0.0f ) continue;
Assert( RI.currententity != NULL );
Assert( RI.currentmodel != NULL );
@ -1151,7 +1158,8 @@ void R_DrawEntitiesOnList( void )
R_DrawStudioModel( RI.currententity );
break;
case mod_sprite:
// R_DrawSpriteModel( RI.currententity );
R_SetUpWorldTransform();
R_DrawSpriteModel( RI.currententity );
break;
default:
break;
@ -1963,6 +1971,7 @@ qboolean R_Init()
sw_waterwarp = gEngfuncs.Cvar_Get ("sw_waterwarp", "1", 0, "");
sw_notransbrushes = gEngfuncs.Cvar_Get( "sw_notransbrushes", "0", FCVAR_ARCHIVE, "do not apply transparency to water/glasses (faster)");
sw_noalphabrushes = gEngfuncs.Cvar_Get( "sw_noalphabrushes", "0", FCVAR_ARCHIVE, "do not draw brush holes (faster)");
r_traceglow = gEngfuncs.Cvar_Get( "r_traceglow", "1", FCVAR_ARCHIVE, "cull flares behind models" );
sw_texfilt = gEngfuncs.Cvar_Get ("sw_texfilt", "0", 0, "texture dither");
//r_lefthand = ri.Cvar_Get( "hand", "0", FCVAR_USERINFO | FCVAR_ARCHIVE );
@ -1974,6 +1983,11 @@ qboolean R_Init()
//r_lerpmodels = ri.Cvar_Get( "r_lerpmodels", "1", 0 );
r_novis = gEngfuncs.Cvar_Get( "r_novis", "0", 0, "" );
tracerred = gEngfuncs.Cvar_Get( "tracerred", "0.8", 0, "tracer red component weight ( 0 - 1.0 )" );
tracergreen = gEngfuncs.Cvar_Get( "tracergreen", "0.8", 0, "tracer green component weight ( 0 - 1.0 )" );
tracerblue = gEngfuncs.Cvar_Get( "tracerblue", "0.4", 0, "tracer blue component weight ( 0 - 1.0 )" );
traceralpha = gEngfuncs.Cvar_Get( "traceralpha", "0.5", 0, "tracer alpha amount ( 0 - 1.0 )" );
// create the window and set up the context
r_temppool = Mem_AllocPool( "ref_sw zone" );
@ -1998,6 +2012,7 @@ qboolean R_Init()
view_clipplanes[1].leftedge = view_clipplanes[2].leftedge =view_clipplanes[3].leftedge = false;
view_clipplanes[0].rightedge = view_clipplanes[2].rightedge = view_clipplanes[3].rightedge = false;
R_StudioInit();
R_SpriteInit();
R_InitTurb();
return true;

300
r_part.c Normal file
View File

@ -0,0 +1,300 @@
/*
cl_part.c - particles and tracers
Copyright (C) 2010 Uncle Mike
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*/
#include "r_local.h"
#include "r_efx.h"
#include "event_flags.h"
#include "entity_types.h"
#include "triangleapi.h"
#include "pm_local.h"
#include "cl_tent.h"
#include "studio.h"
static float gTracerSize[11] = { 1.5f, 0.5f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f };
static color24 gTracerColors[] =
{
{ 255, 255, 255 }, // White
{ 255, 0, 0 }, // Red
{ 0, 255, 0 }, // Green
{ 0, 0, 255 }, // Blue
{ 0, 0, 0 }, // Tracer default, filled in from cvars, etc.
{ 255, 167, 17 }, // Yellow-orange sparks
{ 255, 130, 90 }, // Yellowish streaks (garg)
{ 55, 60, 144 }, // Blue egon streak
{ 255, 130, 90 }, // More Yellowish streaks (garg)
{ 255, 140, 90 }, // More Yellowish streaks (garg)
{ 200, 130, 90 }, // More red streaks (garg)
{ 255, 120, 70 }, // Darker red streaks (garg)
};
/*
================
CL_DrawParticles
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 *pColor;
int alpha;
float size;
if( !cl_active_particles )
return; // nothing to draw?
//pglEnable( GL_BLEND );
//pglDisable( GL_ALPHA_TEST );
//pglBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
GL_Bind( XASH_TEXTURE0, tr.particleTexture );
//pglTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
//pglDepthMask( GL_FALSE );
TriBegin( TRI_QUADS );
for( p = cl_active_particles; p; p = p->next )
{
if(( p->type != pt_blob ) || ( p->packedColor == 255 ))
{
size = partsize; // get initial size of particle
// scale up to keep particles from disappearing
size += (p->org[0] - RI.vieworg[0]) * RI.cull_vforward[0];
size += (p->org[1] - RI.vieworg[1]) * RI.cull_vforward[1];
size += (p->org[2] - RI.vieworg[2]) * RI.cull_vforward[2];
if( size < 20.0f ) size = partsize;
else size = partsize + size * 0.002f;
// scale the axes by radius
VectorScale( RI.cull_vright, size, right );
VectorScale( RI.cull_vup, size, up );
p->color = bound( 0, p->color, 255 );
pColor = gEngfuncs.CL_GetPaletteColor( p->color );
alpha = 255 * (p->die - gpGlobals->time) * 16.0f;
if( alpha > 255 || p->type == pt_static )
alpha = 255;
TriColor4ub( gEngfuncs.LightToTexGamma( pColor->r ),
gEngfuncs.LightToTexGamma( pColor->g ),
gEngfuncs.LightToTexGamma( pColor->b ), alpha );
TriTexCoord2f( 0.0f, 1.0f );
TriVertex3f( p->org[0] - right[0] + up[0], p->org[1] - right[1] + up[1], p->org[2] - right[2] + up[2] );
TriTexCoord2f( 0.0f, 0.0f );
TriVertex3f( p->org[0] + right[0] + up[0], p->org[1] + right[1] + up[1], p->org[2] + right[2] + up[2] );
TriTexCoord2f( 1.0f, 0.0f );
TriVertex3f( p->org[0] + right[0] - up[0], p->org[1] + right[1] - up[1], p->org[2] + right[2] - up[2] );
TriTexCoord2f( 1.0f, 1.0f );
TriVertex3f( p->org[0] - right[0] - up[0], p->org[1] - right[1] - up[1], p->org[2] - right[2] - up[2] );
r_stats.c_particle_count++;
}
gEngfuncs.CL_ThinkParticle( frametime, p );
}
TriEnd();
//pglDepthMask( GL_TRUE );
}
/*
================
CL_CullTracer
check tracer bbox
================
*/
static qboolean CL_CullTracer( particle_t *p, const vec3_t start, const vec3_t end )
{
vec3_t mins, maxs;
int i;
return false;
/*
// compute the bounding box
for( i = 0; i < 3; i++ )
{
if( start[i] < end[i] )
{
mins[i] = start[i];
maxs[i] = end[i];
}
else
{
mins[i] = end[i];
maxs[i] = start[i];
}
// don't let it be zero sized
if( mins[i] == maxs[i] )
{
maxs[i] += gTracerSize[p->type] * 2.0f;
}
}
// check bbox
return R_CullBox( mins, maxs );*/
}
/*
================
CL_DrawTracers
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 ))
{
color24 *customColors = &gTracerColors[4];
customColors->r = (byte)(tracerred->value * traceralpha->value * 255);
customColors->g = (byte)(tracergreen->value * traceralpha->value * 255);
customColors->b = (byte)(tracerblue->value * traceralpha->value * 255);
ClearBits( tracerred->flags, FCVAR_CHANGED );
ClearBits( tracergreen->flags, FCVAR_CHANGED );
ClearBits( tracerblue->flags, FCVAR_CHANGED );
ClearBits( traceralpha->flags, FCVAR_CHANGED );
}
if( !cl_active_tracers )
return; // nothing to draw?
if( !TriSpriteTexture( gEngfuncs.GetDefaultSprite( REF_DOT_SPRITE ), 0 ))
return;
//pglEnable( GL_BLEND );
//pglBlendFunc( GL_SRC_ALPHA, GL_ONE );
//pglDisable( GL_ALPHA_TEST );
//pglDepthMask( GL_FALSE );
gravity = frametime * MOVEVARS->gravity;
scale = 1.0 - (frametime * 0.9);
if( scale < 0.0f ) scale = 0.0f;
for( p = cl_active_tracers; p; p = p->next )
{
atten = (p->die - gpGlobals->time);
if( atten > 0.1f ) atten = 0.1f;
VectorScale( p->vel, ( p->ramp * atten ), delta );
VectorAdd( p->org, delta, end );
VectorCopy( p->org, start );
if( !CL_CullTracer( p, start, end ))
{
vec3_t verts[4], tmp2;
vec3_t tmp, normal;
color24 *pColor;
// Transform point into screen space
TriWorldToScreen( start, screen );
TriWorldToScreen( end, screenLast );
// build world-space normal to screen-space direction vector
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)
VectorScale( RI.cull_vup, tmp[0] * gTracerSize[p->type], normal );
VectorScale( RI.cull_vright, -tmp[1] * gTracerSize[p->type], tmp2 );
VectorSubtract( normal, tmp2, normal );
// compute four vertexes
VectorSubtract( start, normal, verts[0] );
VectorAdd( start, normal, verts[1] );
VectorAdd( verts[0], delta, verts[2] );
VectorAdd( verts[1], delta, verts[3] );
if( p->color > sizeof( gTracerColors ) / sizeof( color24 ) )
{
gEngfuncs.Con_Printf( S_ERROR "UserTracer with color > %d\n", sizeof( gTracerColors ) / sizeof( color24 ));
p->color = 0;
}
pColor = &gTracerColors[p->color];
TriColor4ub( pColor->r, pColor->g, pColor->b, p->packedColor );
TriBegin( TRI_QUADS );
TriTexCoord2f( 0.0f, 0.8f );
TriVertex3fv( verts[2] );
TriTexCoord2f( 1.0f, 0.8f );
TriVertex3fv( verts[3] );
TriTexCoord2f( 1.0f, 0.0f );
TriVertex3fv( verts[1] );
TriTexCoord2f( 0.0f, 0.0f );
TriVertex3fv( verts[0] );
TriEnd();
}
// evaluate position
VectorMA( p->org, frametime, p->vel, p->org );
if( p->type == pt_grav )
{
p->vel[0] *= scale;
p->vel[1] *= scale;
p->vel[2] -= gravity;
p->packedColor = 255 * (p->die - gpGlobals->time) * 2;
if( p->packedColor > 255 ) p->packedColor = 255;
}
else if( p->type == pt_slowgrav )
{
p->vel[2] = gravity * 0.05;
}
}
//pglDepthMask( GL_TRUE );
}
/*
===============
CL_DrawParticlesExternal
allow to draw effects from custom renderer
===============
*/
void CL_DrawParticlesExternal( const ref_viewpass_t *rvp, qboolean trans_pass, float frametime )
{
ref_instance_t oldRI = RI;
memcpy( &oldRI, &RI, sizeof( ref_instance_t ));
R_SetupRefParams( rvp );
R_SetupFrustum();
// R_SetupGL( false ); // don't touch GL-states
// setup PVS for frame
memcpy( RI.visbytes, tr.visbytes, gpGlobals->visbytes );
tr.frametime = frametime;
gEngfuncs.CL_DrawEFX( frametime, trans_pass );
// restore internal state
memcpy( &RI, &oldRI, sizeof( ref_instance_t ));
}

1087
r_sprite.c Normal file

File diff suppressed because it is too large Load Diff

View File

@ -116,6 +116,8 @@ void TriBegin( int mode1 )
pglBegin( mode );
#endif
if( mode1 == TRI_QUADS )
mode1 = TRI_TRIANGLE_FAN;
mode = mode1;
vertcount = n = vertcount = 0;
}
@ -242,6 +244,17 @@ TriVertex3f
*/
void TriVertex3f( float x, float y, float z )
{
if( mode == TRI_TRIANGLES )
{
R_SetupFinalVert( &triv[vertcount], x, y, z, light << 8,s,t);
vertcount++;
if( vertcount == 3 )
{
R_RenderTriangle( &triv[0], &triv[1], &triv[2] );
R_RenderTriangle( &triv[2], &triv[1], &triv[0] );
vertcount = 0;
}
}
if( mode == TRI_TRIANGLE_FAN )
{
R_SetupFinalVert( &triv[vertcount], x, y, z, light << 8,s,t);
@ -300,7 +313,7 @@ TriWorldToScreen
convert world coordinates (x,y,z) into screen (x, y)
=============
*/
int TriWorldToScreen( float *world, float *screen )
int TriWorldToScreen( const float *world, float *screen )
{
int retval;