Merge pull request #314 from 0lvin/render_speedup_review

Render speedup
This commit is contained in:
Yamagi 2018-08-15 17:41:23 +02:00 committed by GitHub
commit 135b243b74
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
30 changed files with 694 additions and 517 deletions

View file

@ -42,7 +42,7 @@ extern cvar_t *vid_gamma;
extern cvar_t *vid_fullscreen;
extern cvar_t *vid_renderer;
static cvar_t *r_vsync;
static cvar_t *gl_anisotropic;
static cvar_t *r_anisotropic;
static cvar_t *gl_msaa_samples;
static menuframework_s s_opengl_menu;
@ -126,11 +126,11 @@ AnisotropicCallback(void *s)
if (list->curvalue == 0)
{
Cvar_SetValue("gl_anisotropic", 0);
Cvar_SetValue("r_anisotropic", 0);
}
else
{
Cvar_SetValue("gl_anisotropic", pow(2, list->curvalue));
Cvar_SetValue("r_anisotropic", pow(2, list->curvalue));
}
}
@ -362,9 +362,9 @@ VID_MenuInit(void)
r_vsync = Cvar_Get("r_vsync", "1", CVAR_ARCHIVE);
}
if (!gl_anisotropic)
if (!r_anisotropic)
{
gl_anisotropic = Cvar_Get("gl_anisotropic", "0", CVAR_ARCHIVE);
r_anisotropic = Cvar_Get("r_anisotropic", "0", CVAR_ARCHIVE);
}
if (!gl_msaa_samples)
@ -462,13 +462,13 @@ VID_MenuInit(void)
s_af_list.generic.callback = AnisotropicCallback;
s_af_list.itemnames = pow2_names;
s_af_list.curvalue = 0;
if (gl_anisotropic->value)
if (r_anisotropic->value)
{
do
{
s_af_list.curvalue++;
} while (pow2_names[s_af_list.curvalue] &&
pow(2, s_af_list.curvalue) <= gl_anisotropic->value);
pow(2, s_af_list.curvalue) <= r_anisotropic->value);
s_af_list.curvalue--;
}

View file

@ -74,3 +74,17 @@ Mod_DecompressVis(byte *in, int row)
return decompressed;
}
float
Mod_RadiusFromBounds(const vec3_t mins, const vec3_t maxs)
{
int i;
vec3_t corner;
for (i = 0; i < 3; i++)
{
corner[i] = fabs(mins[i]) > fabs(maxs[i]) ? fabs(mins[i]) : fabs(maxs[i]);
}
return VectorLength(corner);
}

View file

@ -202,18 +202,18 @@ R_TextureMode(char *string)
/* clamp selected anisotropy */
if (gl_config.anisotropic)
{
if (gl_anisotropic->value > gl_config.max_anisotropy)
if (r_anisotropic->value > gl_config.max_anisotropy)
{
ri.Cvar_SetValue("gl_anisotropic", gl_config.max_anisotropy);
ri.Cvar_SetValue("r_anisotropic", gl_config.max_anisotropy);
}
else if (gl_anisotropic->value < 1.0)
else if (r_anisotropic->value < 1.0)
{
ri.Cvar_SetValue("gl_anisotropic", 1.0);
ri.Cvar_SetValue("r_anisotropic", 1.0);
}
}
else
{
ri.Cvar_SetValue("gl_anisotropic", 0.0);
ri.Cvar_SetValue("r_anisotropic", 0.0);
}
/* change all the existing mipmap texture objects */
@ -228,10 +228,10 @@ R_TextureMode(char *string)
gl_filter_max);
/* Set anisotropic filter if supported and enabled */
if (gl_config.anisotropic && gl_anisotropic->value)
if (gl_config.anisotropic && r_anisotropic->value)
{
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT,
gl_anisotropic->value);
r_anisotropic->value);
}
}
}
@ -788,10 +788,10 @@ R_Upload32(unsigned *data, int width, int height, qboolean mipmap)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, gl_filter_max);
}
if (mipmap && gl_config.anisotropic && gl_anisotropic->value)
if (mipmap && gl_config.anisotropic && r_anisotropic->value)
{
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT,
gl_anisotropic->value);
r_anisotropic->value);
}
return res;
}

View file

@ -124,7 +124,7 @@ cvar_t *r_vsync;
cvar_t *gl_texturemode;
cvar_t *gl1_texturealphamode;
cvar_t *gl1_texturesolidmode;
cvar_t *gl_anisotropic;
cvar_t *r_anisotropic;
cvar_t *r_lockpvs;
cvar_t *gl_msaa_samples;
@ -425,7 +425,7 @@ R_DrawParticles2(int num_particles, const particle_t particles[],
vec3_t up, right;
float scale;
byte color[4];
GLfloat vtx[3*num_particles*3];
GLfloat tex[2*num_particles*3];
GLfloat clr[4*num_particles*3];
@ -433,7 +433,7 @@ R_DrawParticles2(int num_particles, const particle_t particles[],
unsigned int index_tex = 0;
unsigned int index_clr = 0;
unsigned int j;
R_Bind(r_particletexture->texnum);
glDepthMask(GL_FALSE); /* no z buffering */
glEnable(GL_BLEND);
@ -505,7 +505,7 @@ R_DrawParticles2(int num_particles, const particle_t particles[],
glDisableClientState( GL_VERTEX_ARRAY );
glDisableClientState( GL_TEXTURE_COORD_ARRAY );
glDisableClientState( GL_COLOR_ARRAY );
glDisable(GL_BLEND);
glColor4f(1, 1, 1, 1);
glDepthMask(1); /* back to normal Z buffering */
@ -523,12 +523,12 @@ R_DrawParticles(void)
int i;
unsigned char color[4];
const particle_t *p;
GLfloat vtx[3*r_newrefdef.num_particles];
GLfloat clr[4*r_newrefdef.num_particles];
unsigned int index_vtx = 0;
unsigned int index_clr = 0;
glDepthMask(GL_FALSE);
glEnable(GL_BLEND);
glDisable(GL_TEXTURE_2D);
@ -1241,7 +1241,7 @@ R_Register(void)
gl_texturemode = ri.Cvar_Get("gl_texturemode", "GL_LINEAR_MIPMAP_NEAREST", CVAR_ARCHIVE);
gl1_texturealphamode = ri.Cvar_Get("gl1_texturealphamode", "default", CVAR_ARCHIVE);
gl1_texturesolidmode = ri.Cvar_Get("gl1_texturesolidmode", "default", CVAR_ARCHIVE);
gl_anisotropic = ri.Cvar_Get("gl_anisotropic", "0", CVAR_ARCHIVE);
r_anisotropic = ri.Cvar_Get("r_anisotropic", "0", CVAR_ARCHIVE);
r_lockpvs = ri.Cvar_Get("r_lockpvs", "0", 0);
gl1_palettedtexture = ri.Cvar_Get("gl1_palettedtexture", "0", CVAR_ARCHIVE);
@ -1681,11 +1681,11 @@ RI_BeginFrame(float camera_separation)
}
/* texturemode stuff */
if (gl_texturemode->modified || (gl_config.anisotropic && gl_anisotropic->modified))
if (gl_texturemode->modified || (gl_config.anisotropic && r_anisotropic->modified))
{
R_TextureMode(gl_texturemode->string);
gl_texturemode->modified = false;
gl_anisotropic->modified = false;
r_anisotropic->modified = false;
}
if (gl1_texturealphamode->modified)
@ -1756,11 +1756,11 @@ R_DrawBeam(entity_t *e)
vec3_t direction, normalized_direction;
vec3_t start_points[NUM_BEAM_SEGS], end_points[NUM_BEAM_SEGS];
vec3_t oldorigin, origin;
GLfloat vtx[3*NUM_BEAM_SEGS*4];
unsigned int index_vtx = 0;
unsigned int pointb;
oldorigin[0] = e->oldorigin[0];
oldorigin[1] = e->oldorigin[1];
oldorigin[2] = e->oldorigin[2];

View file

@ -303,20 +303,6 @@ Mod_LoadVertexes(lump_t *l)
}
}
float
Mod_RadiusFromBounds(vec3_t mins, vec3_t maxs)
{
int i;
vec3_t corner;
for (i = 0; i < 3; i++)
{
corner[i] = fabs(mins[i]) > fabs(maxs[i]) ? fabs(mins[i]) : fabs(maxs[i]);
}
return VectorLength(corner);
}
void
Mod_LoadSubmodels(lump_t *l)
{

View file

@ -215,7 +215,7 @@ extern cvar_t *gl1_flashblend;
extern cvar_t *r_modulate;
extern cvar_t *gl_drawbuffer;
extern cvar_t *r_vsync;
extern cvar_t *gl_anisotropic;
extern cvar_t *r_anisotropic;
extern cvar_t *gl_texturemode;
extern cvar_t *gl1_texturealphamode;
extern cvar_t *gl1_texturesolidmode;

View file

@ -74,18 +74,18 @@ GL3_TextureMode(char *string)
/* clamp selected anisotropy */
if (gl3config.anisotropic)
{
if (gl_anisotropic->value > gl3config.max_anisotropy)
if (r_anisotropic->value > gl3config.max_anisotropy)
{
ri.Cvar_SetValue("gl_anisotropic", gl3config.max_anisotropy);
ri.Cvar_SetValue("r_anisotropic", gl3config.max_anisotropy);
}
else if (gl_anisotropic->value < 1.0)
else if (r_anisotropic->value < 1.0)
{
ri.Cvar_SetValue("gl_anisotropic", 1.0);
ri.Cvar_SetValue("r_anisotropic", 1.0);
}
}
else
{
ri.Cvar_SetValue("gl_anisotropic", 0.0);
ri.Cvar_SetValue("r_anisotropic", 0.0);
}
gl3image_t *glt;
@ -101,9 +101,9 @@ GL3_TextureMode(char *string)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, gl_filter_max);
/* Set anisotropic filter if supported and enabled */
if (gl3config.anisotropic && gl_anisotropic->value)
if (gl3config.anisotropic && r_anisotropic->value)
{
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, gl_anisotropic->value);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, r_anisotropic->value);
}
}
}
@ -200,9 +200,9 @@ GL3_Upload32(unsigned *data, int width, int height, qboolean mipmap)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, gl_filter_max);
}
if (mipmap && gl3config.anisotropic && gl_anisotropic->value)
if (mipmap && gl3config.anisotropic && r_anisotropic->value)
{
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, gl_anisotropic->value);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, r_anisotropic->value);
}
return res;

View file

@ -87,7 +87,7 @@ cvar_t *r_mode;
cvar_t *r_customwidth;
cvar_t *r_customheight;
cvar_t *vid_gamma;
cvar_t *gl_anisotropic;
cvar_t *r_anisotropic;
cvar_t *gl_texturemode;
cvar_t *gl_drawbuffer;
cvar_t *r_clear;
@ -216,7 +216,7 @@ GL3_Register(void)
gl_nobind = ri.Cvar_Get("gl_nobind", "0", 0);
gl_texturemode = ri.Cvar_Get("gl_texturemode", "GL_LINEAR_MIPMAP_NEAREST", CVAR_ARCHIVE);
gl_anisotropic = ri.Cvar_Get("gl_anisotropic", "0", CVAR_ARCHIVE);
r_anisotropic = ri.Cvar_Get("r_anisotropic", "0", CVAR_ARCHIVE);
vid_fullscreen = ri.Cvar_Get("vid_fullscreen", "0", CVAR_ARCHIVE);
vid_gamma = ri.Cvar_Get("vid_gamma", "1.2", CVAR_ARCHIVE);
@ -276,7 +276,7 @@ GL3_Register(void)
//gl_texturemode = ri.Cvar_Get("gl_texturemode", "GL_LINEAR_MIPMAP_NEAREST", CVAR_ARCHIVE);
gl1_texturealphamode = ri.Cvar_Get("gl1_texturealphamode", "default", CVAR_ARCHIVE);
gl1_texturesolidmode = ri.Cvar_Get("gl1_texturesolidmode", "default", CVAR_ARCHIVE);
//gl_anisotropic = ri.Cvar_Get("gl_anisotropic", "0", CVAR_ARCHIVE);
//r_anisotropic = ri.Cvar_Get("r_anisotropic", "0", CVAR_ARCHIVE);
//r_lockpvs = ri.Cvar_Get("r_lockpvs", "0", 0);
//gl1_palettedtexture = ri.Cvar_Get("gl1_palettedtexture", "0", CVAR_ARCHIVE); NOPE.
@ -1662,11 +1662,11 @@ GL3_BeginFrame(float camera_separation)
}
/* texturemode stuff */
if (gl_texturemode->modified || (gl3config.anisotropic && gl_anisotropic->modified))
if (gl_texturemode->modified || (gl3config.anisotropic && r_anisotropic->modified))
{
GL3_TextureMode(gl_texturemode->string);
gl_texturemode->modified = false;
gl_anisotropic->modified = false;
r_anisotropic->modified = false;
}
if (r_vsync->modified)

View file

@ -184,20 +184,6 @@ Mod_LoadVertexes(lump_t *l)
}
}
static float
Mod_RadiusFromBounds(vec3_t mins, vec3_t maxs)
{
int i;
vec3_t corner;
for (i = 0; i < 3; i++)
{
corner[i] = fabs(mins[i]) > fabs(maxs[i]) ? fabs(mins[i]) : fabs(maxs[i]);
}
return VectorLength(corner);
}
static void
Mod_LoadSubmodels(lump_t *l)
{

View file

@ -498,7 +498,7 @@ extern cvar_t *r_drawworld;
extern cvar_t *vid_gamma;
extern cvar_t *gl3_intensity;
extern cvar_t *gl3_intensity_2D;
extern cvar_t *gl_anisotropic;
extern cvar_t *r_anisotropic;
extern cvar_t *r_lightlevel;
extern cvar_t *gl3_overbrightbits;

View file

@ -67,5 +67,6 @@ extern qboolean LoadSTB(const char *origname, const char* type, byte **pic, int
extern void GetWalInfo(char *name, int *width, int *height);
extern float Mod_RadiusFromBounds(const vec3_t mins, const vec3_t maxs);
extern byte* Mod_DecompressVis(byte *in, int row);
#endif /* SRC_CLIENT_REFRESH_REF_SHARED_H_ */

View file

@ -138,7 +138,7 @@ extern oldrefdef_t r_refdef;
#define VID_GRADES (1 << VID_CBITS)
// r_shared.h: general refresh-related stuff shared between the refresh and the
// sw_local.h: general refresh-related stuff shared between the refresh and the
// driver
@ -208,11 +208,11 @@ typedef struct
** listed after it!
*/
typedef struct finalvert_s {
int u, v, s, t;
int l;
int zi;
int flags;
float xyz[3]; // eye space
int u, v, s, t;
int l;
zvalue_t zi;
int flags;
float xyz[3]; // eye space
} finalvert_t;
@ -279,7 +279,7 @@ typedef struct espan_s
} espan_t;
extern espan_t *vid_polygon_spans; // space for spans in r_poly
// used by the polygon drawer (R_POLY.C) and sprite setup code (R_SPRITE.C)
// used by the polygon drawer (sw_poly.c) and sprite setup code (sw_sprite.c)
typedef struct
{
int nump;
@ -291,7 +291,7 @@ typedef struct
float dist;
float s_offset, t_offset;
float viewer_position[3];
void (*drawspanlet)(void);
void (*drawspanlet)(const int *r_turb_turb);
int stipple_parity;
} polydesc_t;
@ -362,10 +362,10 @@ extern float d_sdivzstepu, d_tdivzstepu, d_zistepu;
extern float d_sdivzstepv, d_tdivzstepv, d_zistepv;
extern float d_sdivzorigin, d_tdivzorigin, d_ziorigin;
void D_DrawSpans16(espan_t *pspans);
void D_DrawSpansPow2(espan_t *pspans);
void D_DrawZSpans(espan_t *pspans);
void Turbulent8(espan_t *pspan);
void NonTurbulent8(espan_t *pspan); //PGM
void TurbulentPow2(espan_t *pspan);
void NonTurbulentPow2(espan_t *pspan); //PGM
surfcache_t *D_CacheSurface (msurface_t *surface, int miplevel);
@ -402,7 +402,7 @@ extern surf_t *surfaces, *surface_p, *surf_max;
// pointer is greater than another one, it should be drawn in front
// surfaces[1] is the background, and is used as the active surface stack.
// surfaces[0] is a dummy, because index 0 is used to indicate no surface
// attached to an edge_t
// attached to an edge_t
//===================================================================
@ -505,7 +505,8 @@ typedef struct {
zvalue_t *pz;
int count;
pixel_t *ptex;
int sfrac, tfrac, light, zi;
int sfrac, tfrac, light;
zvalue_t zi;
} spanpackage_t;
extern spanpackage_t *triangle_spans;
@ -525,15 +526,8 @@ extern int r_outofverts;
extern mvertex_t *r_pcurrentvertbase;
typedef struct
{
finalvert_t *a, *b, *c;
} aliastriangleparms_t;
extern aliastriangleparms_t aliastriangleparms;
void R_DrawTriangle( void );
void R_AliasClipTriangle (finalvert_t *index0, finalvert_t *index1, finalvert_t *index2);
void R_DrawTriangle(const finalvert_t *a, const finalvert_t *b, const finalvert_t *c);
void R_AliasClipTriangle (const finalvert_t *index0, const finalvert_t *index1, finalvert_t *index2);
extern float r_time1;

View file

@ -31,7 +31,7 @@ pfv0 is the unclipped vertex, pfv1 is the z-clipped vertex
================
*/
static void
R_Alias_clip_z (finalvert_t *pfv0, finalvert_t *pfv1, finalvert_t *out)
R_Alias_clip_z (const finalvert_t *pfv0, const finalvert_t *pfv1, finalvert_t *out)
{
float scale;
@ -50,7 +50,7 @@ R_Alias_clip_z (finalvert_t *pfv0, finalvert_t *pfv1, finalvert_t *out)
}
static void
R_Alias_clip_left (finalvert_t *pfv0, finalvert_t *pfv1, finalvert_t *out)
R_Alias_clip_left (const finalvert_t *pfv0, const finalvert_t *pfv1, finalvert_t *out)
{
float scale;
@ -79,7 +79,7 @@ R_Alias_clip_left (finalvert_t *pfv0, finalvert_t *pfv1, finalvert_t *out)
}
static void
R_Alias_clip_right (finalvert_t *pfv0, finalvert_t *pfv1, finalvert_t *out)
R_Alias_clip_right (const finalvert_t *pfv0, const finalvert_t *pfv1, finalvert_t *out)
{
float scale;
@ -108,7 +108,7 @@ R_Alias_clip_right (finalvert_t *pfv0, finalvert_t *pfv1, finalvert_t *out)
}
static void
R_Alias_clip_top (finalvert_t *pfv0, finalvert_t *pfv1, finalvert_t *out)
R_Alias_clip_top (const finalvert_t *pfv0, const finalvert_t *pfv1, finalvert_t *out)
{
float scale;
@ -138,8 +138,7 @@ R_Alias_clip_top (finalvert_t *pfv0, finalvert_t *pfv1, finalvert_t *out)
static void
R_Alias_clip_bottom (finalvert_t *pfv0, finalvert_t *pfv1,
finalvert_t *out)
R_Alias_clip_bottom (const finalvert_t *pfv0, const finalvert_t *pfv1, finalvert_t *out)
{
float scale;
@ -171,8 +170,8 @@ R_Alias_clip_bottom (finalvert_t *pfv0, finalvert_t *pfv1,
int
R_AliasClip (finalvert_t *in, finalvert_t *out, int flag, int count,
void(*clip)(finalvert_t *pfv0, finalvert_t *pfv1, finalvert_t *out) )
R_AliasClip (const finalvert_t *in, finalvert_t *out, int flag, int count,
void(*clip)(const finalvert_t *pfv0, const finalvert_t *pfv1, finalvert_t *out) )
{
int i,j,k;
@ -218,7 +217,7 @@ R_AliasClipTriangle
================
*/
void
R_AliasClipTriangle (finalvert_t *index0, finalvert_t *index1, finalvert_t *index2)
R_AliasClipTriangle (const finalvert_t *index0, const finalvert_t *index1, finalvert_t *index2)
{
int i, k, pingpong;
unsigned clipflags;
@ -305,9 +304,6 @@ R_AliasClipTriangle (finalvert_t *index0, finalvert_t *index1, finalvert_t *inde
// draw triangles
for (i=1 ; i<k-1 ; i++)
{
aliastriangleparms.a = &fv[pingpong][0];
aliastriangleparms.b = &fv[pingpong][i];
aliastriangleparms.c = &fv[pingpong][i+1];
R_DrawTriangle();
R_DrawTriangle(&fv[pingpong][0], &fv[pingpong][i], &fv[pingpong][i+1]);
}
}

View file

@ -53,12 +53,12 @@ static vec3_t s_alias_forward, s_alias_right, s_alias_up;
#define NUMVERTEXNORMALS 162
static float r_avertexnormals[NUMVERTEXNORMALS][3] = {
static const float r_avertexnormals[NUMVERTEXNORMALS][3] = {
#include "../constants/anorms.h"
};
static void R_AliasTransformVector(vec3_t in, vec3_t out, float m[3][4]);
static void R_AliasTransformVector(const vec3_t in, vec3_t out, const float m[3][4]);
static void R_AliasTransformFinalVerts(int numpoints, finalvert_t *fv, dtrivertx_t *oldv, dtrivertx_t *newv );
void R_AliasProjectAndClipTestFinalVert(finalvert_t *fv);
@ -206,7 +206,7 @@ R_AliasTransformVector
================
*/
static void
R_AliasTransformVector(vec3_t in, vec3_t out, float xf[3][4] )
R_AliasTransformVector(const vec3_t in, vec3_t out, const float xf[3][4] )
{
out[0] = DotProduct(in, xf[0]) + xf[0][3];
out[1] = DotProduct(in, xf[1]) + xf[1][3];
@ -223,7 +223,7 @@ General clipped case
*/
static void
R_AliasPreparePoints (finalvert_t *verts, finalvert_t *verts_max)
R_AliasPreparePoints (finalvert_t *verts, const finalvert_t *verts_max)
{
int i;
dstvert_t *pstverts;
@ -269,12 +269,9 @@ R_AliasPreparePoints (finalvert_t *verts, finalvert_t *verts_max)
pfv[2]->t = pstverts[ptri->index_st[2]].t << SHIFT16XYZ;
if ( ! (pfv[0]->flags | pfv[1]->flags | pfv[2]->flags) )
{ // totally unclipped
aliastriangleparms.a = pfv[2];
aliastriangleparms.b = pfv[1];
aliastriangleparms.c = pfv[0];
R_DrawTriangle();
{
// totally unclipped
R_DrawTriangle(pfv[2], pfv[1], pfv[0]);
}
else
{
@ -304,12 +301,9 @@ R_AliasPreparePoints (finalvert_t *verts, finalvert_t *verts_max)
pfv[2]->t = pstverts[ptri->index_st[2]].t << SHIFT16XYZ;
if ( ! (pfv[0]->flags | pfv[1]->flags | pfv[2]->flags) )
{ // totally unclipped
aliastriangleparms.a = pfv[0];
aliastriangleparms.b = pfv[1];
aliastriangleparms.c = pfv[2];
R_DrawTriangle();
{
// totally unclipped
R_DrawTriangle(pfv[0], pfv[1], pfv[2]);
}
else
{ // partially clipped
@ -402,7 +396,8 @@ R_AliasTransformFinalVerts( int numpoints, finalvert_t *fv, dtrivertx_t *oldv, d
for ( i = 0; i < numpoints; i++, fv++, oldv++, newv++ )
{
int temp;
float lightcos, *plightnormal;
float lightcos;
const float *plightnormal;
vec3_t lerped_vert;
lerped_vert[0] = r_lerp_move[0] + oldv->v[0]*r_lerp_backv[0] + newv->v[0]*r_lerp_frontv[0];

View file

@ -158,7 +158,7 @@ RE_Draw_StretchPicImplementation
=============
*/
void
RE_Draw_StretchPicImplementation (int x, int y, int w, int h, image_t *pic)
RE_Draw_StretchPicImplementation (int x, int y, int w, int h, const image_t *pic)
{
pixel_t *dest;
byte *source;
@ -283,39 +283,72 @@ RE_Draw_PicScaled(int x, int y, char *name, float scale)
if (!pic->transparent)
{
for (v=0; v<height; v++)
if (iscale == 1)
{
for(ypos=0; ypos < iscale; ypos++)
for (v=0; v<height; v++)
{
for (u=0; u<pic->width; u++)
{
for(xpos=0; xpos < iscale; xpos++)
{
dest[u * iscale + xpos] = source[u];
}
}
memcpy(dest, source, pic->width);
dest += vid.width;
source += pic->width;
}
}
else
{
for (v=0; v<height; v++)
{
for(ypos=0; ypos < iscale; ypos++)
{
pixel_t *dest_u = dest;
pixel_t *source_u = source;
u = pic->width;
do
{
xpos = iscale;
do
{
*dest_u++ = *source_u;
} while (--xpos > 0);
source_u++;
} while (--u > 0);
dest += vid.width;
}
source += pic->width;
}
source += pic->width;
}
}
else
{
for (v=0; v<height; v++)
if (iscale == 1)
{
for(ypos=0; ypos < iscale; ypos++)
for (v=0; v<height; v++)
{
for (u=0; u<pic->width; u++)
{
if (source[u] != TRANSPARENT_COLOR)
for(xpos=0; xpos < iscale; xpos++)
{
dest[u * iscale + xpos] = source[u];
}
dest[u] = source[u];
}
dest += vid.width;
source += pic->width;
}
}
else
{
for (v=0; v<height; v++)
{
for(ypos=0; ypos < iscale; ypos++)
{
for (u=0; u<pic->width; u++)
{
if (source[u] != TRANSPARENT_COLOR)
for(xpos=0; xpos < iscale; xpos++)
{
dest[u * iscale + xpos] = source[u];
}
}
dest += vid.width;
}
source += pic->width;
}
source += pic->width;
}
}
}
@ -382,7 +415,7 @@ void
RE_Draw_Fill (int x, int y, int w, int h, int c)
{
pixel_t *dest;
int u, v;
int v;
if (x+w > vid.width)
w = vid.width - x;
@ -405,8 +438,7 @@ RE_Draw_Fill (int x, int y, int w, int h, int c)
dest = vid_buffer + y * vid.width + x;
for (v=0 ; v<h ; v++, dest += vid.width)
for (u=0 ; u<w ; u++)
dest[u] = c;
memset(dest, c, w);
}
//=============================================================================

View file

@ -62,8 +62,6 @@ extern void R_TransformFrustum (void);
static void R_GenerateSpans (void);
static void R_GenerateSpansBackward (void);
static void R_LeadingEdge (edge_t *edge);
static void R_LeadingEdgeBackwards (edge_t *edge);
static void R_TrailingEdge (surf_t *surf, edge_t *edge);
/*
@ -252,7 +250,7 @@ D_SurfSearchBackwards
==============
*/
static surf_t*
D_SurfSearchBackwards(surf_t *surf, surf_t *surf2)
D_SurfSearchBackwards(const surf_t *surf, surf_t *surf2)
{
do
{
@ -277,7 +275,7 @@ R_LeadingEdgeBackwards
==============
*/
static void
R_LeadingEdgeBackwards (edge_t *edge)
R_LeadingEdgeBackwards (const edge_t *edge)
{
surf_t *surf, *surf2;
@ -376,7 +374,7 @@ D_SurfSearchForward
==============
*/
static surf_t*
D_SurfSearchForward(surf_t *surf, surf_t *surf2)
D_SurfSearchForward(const surf_t *surf, surf_t *surf2)
{
do
{
@ -397,7 +395,7 @@ R_LeadingEdgeSearch
==============
*/
static surf_t*
R_LeadingEdgeSearch (edge_t *edge, surf_t *surf, surf_t *surf2)
R_LeadingEdgeSearch (const edge_t *edge, const surf_t *surf, surf_t *surf2)
{
float testzi, newzitop;
@ -431,18 +429,62 @@ R_LeadingEdgeSearch (edge_t *edge, surf_t *surf, surf_t *surf2)
return surf2;
}
/*
==============
R_InsertBeforeSurf
==============
*/
static void
R_InsertBeforeSurf(surf_t *surf, surf_t *surf2)
{
surf->next = surf2;
surf->prev = surf2->prev;
surf2->prev->next = surf;
surf2->prev = surf;
}
/*
==============
R_EmitSpanBeforeTop
==============
*/
static void
R_EmitSpanBeforeTop(const edge_t *edge, surf_t *surf, surf_t *surf2)
{
shift20_t iu;
iu = edge->u >> shift_size;
if (iu > surf2->last_u)
{
espan_t *span;
span = span_p++;
span->u = surf2->last_u;
span->count = iu - span->u;
span->v = current_iv;
span->pnext = surf2->spans;
surf2->spans = span;
}
// set last_u on the new span
surf->last_u = iu;
// insert before surf2
R_InsertBeforeSurf(surf, surf2);
}
/*
==============
R_LeadingEdge
==============
*/
static void
R_LeadingEdge (edge_t *edge)
R_LeadingEdge (const edge_t *edge)
{
if (edge->surfs[1])
{
surf_t *surf, *surf2;
shift20_t iu;
surf_t *surf;
// it's adding a new surface in, so find the correct place
surf = &surfaces[edge->surfs[1]];
@ -452,10 +494,16 @@ R_LeadingEdge (edge_t *edge)
// end edge)
if (++surf->spanstate == 1)
{
surf_t *surf2;
surf2 = surfaces[1].next;
if (surf->key < surf2->key)
goto newtop;
{
// emit a span (obscures current top)
R_EmitSpanBeforeTop(edge, surf, surf2);
return;
}
// if it's two surfaces on the same plane, the one that's already
// active is in front, so keep going unless it's a bmodel
@ -474,7 +522,9 @@ R_LeadingEdge (edge_t *edge)
if (newzibottom >= testzi)
{
goto newtop;
// emit a span (obscures current top)
R_EmitSpanBeforeTop(edge, surf, surf2);
return;
}
newzitop = newzi * 1.01;
@ -482,38 +532,16 @@ R_LeadingEdge (edge_t *edge)
{
if (surf->d_zistepu >= surf2->d_zistepu)
{
goto newtop;
// emit a span (obscures current top)
R_EmitSpanBeforeTop(edge, surf, surf2);
return;
}
}
}
surf2 = R_LeadingEdgeSearch (edge, surf, surf2);
goto gotposition;
newtop:
// emit a span (obscures current top)
iu = edge->u >> shift_size;
if (iu > surf2->last_u)
{
espan_t *span;
span = span_p++;
span->u = surf2->last_u;
span->count = iu - span->u;
span->v = current_iv;
span->pnext = surf2->spans;
surf2->spans = span;
}
// set last_u on the new span
surf->last_u = iu;
gotposition:
// insert before surf2
surf->next = surf2;
surf->prev = surf2->prev;
surf2->prev->next = surf;
surf2->prev = surf;
R_InsertBeforeSurf(surf, surf2);
}
}
}
@ -750,20 +778,16 @@ Simple single color fill with no texture mapping
==============
*/
static void
D_FlatFillSurface (surf_t *surf, int color)
D_FlatFillSurface (surf_t *surf, pixel_t color)
{
espan_t *span;
for (span=surf->spans ; span ; span=span->pnext)
{
pixel_t *pdest;
shift20_t u, u2;
pdest = d_viewbuffer + r_screenwidth*span->v;
u = span->u;
u2 = span->u + span->count - 1;
for ( ; u <= u2 ; u++)
pdest[u] = color;
pdest = d_viewbuffer + r_screenwidth*span->v + span->u;
memset(pdest, color&0xFF, span->count * sizeof(pixel_t));
}
}
@ -869,7 +893,7 @@ D_TurbulentSurf (surf_t *s)
// FIXME: we don't want to do all this for every polygon!
// TODO: store once at start of frame
currententity = s->entity; //FIXME: make this passed in to
// R_RotateBmodel ()
// R_RotateBmodel ()
VectorSubtract (r_origin, currententity->origin,
local_modelorg);
TransformVector (local_modelorg, transformed_modelorg);
@ -882,11 +906,11 @@ D_TurbulentSurf (surf_t *s)
//============
//PGM
// textures that aren't warping are just flowing. Use NonTurbulent8 instead
// textures that aren't warping are just flowing. Use NonTurbulentPow2 instead
if(!(pface->texinfo->flags & SURF_WARP))
NonTurbulent8 (s->spans);
NonTurbulentPow2 (s->spans);
else
Turbulent8 (s->spans);
TurbulentPow2 (s->spans);
//PGM
//============
@ -930,7 +954,7 @@ D_SkySurf (surf_t *s)
D_CalcGradients (pface);
D_DrawSpans16 (s->spans);
D_DrawSpansPow2 (s->spans);
// set up a gradient for the background surface that places it
// effectively at infinity distance from the viewpoint
@ -981,7 +1005,7 @@ D_SolidSurf (surf_t *s)
D_CalcGradients (pface);
D_DrawSpans16 (s->spans);
D_DrawSpansPow2 (s->spans);
D_DrawZSpans (s->spans);

View file

@ -43,6 +43,13 @@ R_ImageList_f (void)
for (i=0, image=r_images ; i<numr_images ; i++, image++)
{
char *in_use = "";
if (image->registration_sequence == registration_sequence)
{
in_use = "*";
}
if (image->registration_sequence <= 0)
continue;
texels += image->width*image->height;
@ -65,8 +72,9 @@ R_ImageList_f (void)
break;
}
R_Printf(PRINT_ALL, " %3i %3i : %s\n",
image->width, image->height, image->name);
R_Printf(PRINT_ALL, " %3i %3i : %s %s\n",
image->width, image->height, image->name,
in_use);
}
R_Printf(PRINT_ALL, "Total texel count: %i\n", texels);
}
@ -335,7 +343,7 @@ R_ShutdownImages
void
R_ShutdownImages (void)
{
int i;
int i;
image_t *image;
for (i=0, image=r_images ; i<numr_images ; i++, image++)

View file

@ -137,7 +137,7 @@ cvar_t *sw_surfcacheoverride;
cvar_t *sw_waterwarp;
static cvar_t *sw_overbrightbits;
cvar_t *sw_custom_particles;
cvar_t *sw_texture_filtering;
cvar_t *r_anisotropic;
cvar_t *r_drawworld;
static cvar_t *r_drawentities;
@ -210,9 +210,9 @@ static struct texture_buffer {
static void Draw_GetPalette (void);
static void RE_BeginFrame( float camera_separation );
static void Draw_BuildGammaTable( void );
static void Draw_BuildGammaTable(void);
static void RE_EndFrame(void);
static void R_DrawBeam(entity_t *e);
static void R_DrawBeam(const entity_t *e);
/*
==================
@ -269,8 +269,8 @@ R_InitTurb (void)
}
}
void R_ImageList_f( void );
static void R_ScreenShot_f( void );
void R_ImageList_f(void);
static void R_ScreenShot_f(void);
static void
R_Register (void)
@ -290,7 +290,7 @@ R_Register (void)
sw_waterwarp = ri.Cvar_Get ("sw_waterwarp", "1", 0);
sw_overbrightbits = ri.Cvar_Get("sw_overbrightbits", "1.0", CVAR_ARCHIVE);
sw_custom_particles = ri.Cvar_Get("sw_custom_particles", "0", CVAR_ARCHIVE);
sw_texture_filtering = ri.Cvar_Get("sw_texture_filtering", "0", CVAR_ARCHIVE);
r_anisotropic = ri.Cvar_Get("r_anisotropic", "0", CVAR_ARCHIVE);
r_mode = ri.Cvar_Get( "r_mode", "0", CVAR_ARCHIVE );
r_lefthand = ri.Cvar_Get( "hand", "0", CVAR_USERINFO | CVAR_ARCHIVE );
@ -332,7 +332,7 @@ R_UnRegister (void)
ri.Cmd_RemoveCommand( "imagelist" );
}
static void SWimp_Shutdown(void );
static void SWimp_DestroyRender(void);
/*
===============
@ -402,7 +402,7 @@ RE_Shutdown (void)
Mod_FreeAll ();
R_ShutdownImages ();
SWimp_Shutdown();
SWimp_DestroyRender();
}
/*
@ -597,7 +597,7 @@ R_MarkLeaves (void)
** IMPLEMENT THIS!
*/
static void
R_DrawNullModel( void )
R_DrawNullModel(void)
{
}
@ -714,7 +714,7 @@ R_BmodelCheckBBox
=============
*/
static int
R_BmodelCheckBBox (float *minmaxs)
R_BmodelCheckBBox (const float *minmaxs)
{
int i, clipflags;
@ -809,7 +809,7 @@ Returns an axially aligned box that contains the input box at the given rotation
=============
*/
static void
RotatedBBox (vec3_t mins, vec3_t maxs, vec3_t angles, vec3_t tmins, vec3_t tmaxs)
RotatedBBox (const vec3_t mins, const vec3_t maxs, vec3_t angles, vec3_t tmins, vec3_t tmaxs)
{
vec3_t tmp, v;
int i, j;
@ -1366,7 +1366,7 @@ Draw_BuildGammaTable (void)
** R_DrawBeam
*/
static void
R_DrawBeam( entity_t *e )
R_DrawBeam(const entity_t *e)
{
#define NUM_BEAM_SEGS 6
@ -1422,8 +1422,8 @@ RE_SetSky
============
*/
// 3dstudio environment map names
char *suf[6] = {"rt", "bk", "lf", "ft", "up", "dn"};
static int r_skysideimage[6] = {5, 2, 4, 1, 0, 3};
static const char *suf[6] = {"rt", "bk", "lf", "ft", "up", "dn"};
static const int r_skysideimage[6] = {5, 2, 4, 1, 0, 3};
extern mtexinfo_t r_skytexinfo[6];
static void
@ -1570,21 +1570,20 @@ GetRefAPI(refimport_t imp)
* is only one software renderer.
*/
static SDL_Window* window = NULL;
static SDL_Surface *surface = NULL;
static SDL_Texture *texture = NULL;
static SDL_Renderer *renderer = NULL;
static qboolean X11_active = false;
static SDL_Window *window = NULL;
static SDL_Surface *surface = NULL;
static SDL_Texture *texture = NULL;
static SDL_Renderer *renderer = NULL;
/*
* Sets the window icon
*/
/* The 64x64 32bit window icon */
#include "../../vid/icon/q2icon64.h"
static void
SetSDLIcon()
{
/* The 64x64 32bit window icon */
#include "../../vid/icon/q2icon64.h"
/* these masks are needed to tell SDL_CreateRGBSurface(From)
to assume the data it gets is byte-wise RGB(A) data */
Uint32 rmask, gmask, bmask, amask;
@ -1641,7 +1640,7 @@ GetWindowSize(int* w, int* h)
}
static int
R_InitContext(void* win)
R_InitContext(SDL_Window *win)
{
char title[40] = {0};
@ -1651,7 +1650,7 @@ R_InitContext(void* win)
return false;
}
window = (SDL_Window*)win;
window = win;
/* Window title - set here so we can display renderer name in it */
snprintf(title, sizeof(title), "Yamagi Quake II %s - Soft Render", YQ2VERSION);
@ -1941,7 +1940,6 @@ SWimp_InitGraphics(int fullscreen, int *pwidth, int *pheight)
memset(sw_state.palette_colors, 0, sizeof(sw_state.palette_colors));
sdl_palette_outdated = true;
X11_active = true;
return true;
}
@ -1978,21 +1976,6 @@ RE_CopyFrame (Uint32 * pixels, int pitch)
// no gaps between images rows
if (pitch == vid.width)
{
int y,x, buffer_pos;
buffer_pos = 0;
for (y=0; y < vid.height; y++)
{
for (x=0; x < vid.width; x ++)
{
pixels[x] = sw_state.palette_colors[vid_buffer[buffer_pos + x]];
}
pixels += pitch;
buffer_pos += vid.width;
}
}
else
{
const Uint32 *max_pixels;
Uint32 *pixels_pos;
@ -2007,6 +1990,21 @@ RE_CopyFrame (Uint32 * pixels, int pitch)
buffer_pos++;
}
}
else
{
int y,x, buffer_pos;
buffer_pos = 0;
for (y=0; y < vid.height; y++)
{
for (x=0; x < vid.width; x ++)
{
pixels[x] = sw_state.palette_colors[vid_buffer[buffer_pos + x]];
}
pixels += pitch;
buffer_pos += vid.width;
}
}
}
/*
@ -2027,7 +2025,6 @@ RE_EndFrame (void)
RE_CopyFrame (pixels, pitch);
SDL_UpdateTexture(texture, NULL, surface->pixels, surface->pitch);
SDL_RenderClear(renderer);
SDL_RenderCopy(renderer, texture, NULL, NULL);
@ -2062,26 +2059,6 @@ SWimp_SetMode(int *pwidth, int *pheight, int mode, int fullscreen )
return retval;
}
/*
** SWimp_Shutdown
**
** System specific graphics subsystem shutdown routine. Destroys
** DIBs or DDRAW surfaces as appropriate.
*/
static void
SWimp_Shutdown( void )
{
SWimp_DestroyRender();
if (SDL_WasInit(SDL_INIT_EVERYTHING) == SDL_INIT_VIDEO)
SDL_Quit();
else
SDL_QuitSubSystem(SDL_INIT_VIDEO);
X11_active = false;
}
// this is only here so the functions in q_shared.c and q_shwin.c can link
void
Sys_Error (char *error, ...)

View file

@ -30,7 +30,7 @@ float d_scalemip[NUM_MIPS-1];
static mleaf_t *r_viewleaf;
static int r_frustum_indexes[4*6];
static float basemip[NUM_MIPS-1] = {1.0, 0.5*0.8, 0.25*0.8};
static const float basemip[NUM_MIPS-1] = {1.0, 0.5*0.8, 0.25*0.8};
int d_vrectx, d_vrecty, d_vrectright_particle, d_vrectbottom_particle;
float xcenter, ycenter;
int d_pix_min, d_pix_max, d_pix_mul;

View file

@ -61,9 +61,17 @@ Mod_Modellist_f (void)
R_Printf(PRINT_ALL,"Loaded models:\n");
for (i=0, mod=mod_known ; i < mod_numknown ; i++, mod++)
{
char *in_use = "";
if (mod->registration_sequence == registration_sequence)
{
in_use = "*";
}
if (!mod->name[0])
continue;
R_Printf(PRINT_ALL, "%8i : %s\n",mod->extradatasize, mod->name);
R_Printf(PRINT_ALL, "%8i : %s %s\n",
mod->extradatasize, mod->name, in_use);
total += mod->extradatasize;
}
R_Printf(PRINT_ALL, "Total resident: %i\n", total);

View file

@ -47,7 +47,8 @@ R_DrawParticle(particle_t *pparticle, int level)
byte *pdest;
zvalue_t *pz;
int color = pparticle->color;
int i, izi, pix, count, u, v;
int i, pix, count, u, v;
zvalue_t izi;
int custom_particle = (int)sw_custom_particles->value;
/*

View file

@ -42,8 +42,6 @@ polydesc_t r_polydesc;
msurface_t *r_alpha_surfaces;
extern int *r_turb_turb;
static int clip_current;
vec5_t r_clip_verts[2][MAXWORKINGVERTS+2];
static emitpoint_t outverts[MAXWORKINGVERTS+3];
@ -56,7 +54,7 @@ static void R_DrawPoly(int iswater);
** R_DrawSpanletOpaque
*/
static void
R_DrawSpanletOpaque( void )
R_DrawSpanletOpaque(const int *r_turb_turb)
{
do
{
@ -88,11 +86,11 @@ R_DrawSpanletOpaque( void )
** R_DrawSpanletTurbulentStipple33
*/
static void
R_DrawSpanletTurbulentStipple33( void )
R_DrawSpanletTurbulentStipple33(const int *r_turb_turb)
{
pixel_t *pdest = s_spanletvars.pdest;
zvalue_t *pz = s_spanletvars.pz;
int izi = s_spanletvars.izi;
zvalue_t izi = s_spanletvars.izi;
if ( s_spanletvars.v & 1 )
{
@ -147,13 +145,13 @@ R_DrawSpanletTurbulentStipple33( void )
** R_DrawSpanletTurbulentStipple66
*/
static void
R_DrawSpanletTurbulentStipple66( void )
R_DrawSpanletTurbulentStipple66(const int *r_turb_turb)
{
unsigned btemp;
int sturb, tturb;
pixel_t *pdest = s_spanletvars.pdest;
zvalue_t *pz = s_spanletvars.pz;
int izi = s_spanletvars.izi;
zvalue_t izi = s_spanletvars.izi;
if ( !( s_spanletvars.v & 1 ) )
{
@ -235,7 +233,7 @@ R_DrawSpanletTurbulentStipple66( void )
** R_DrawSpanletTurbulentBlended
*/
static void
R_DrawSpanletTurbulentBlended66( void )
R_DrawSpanletTurbulentBlended66(const int *r_turb_turb)
{
do
{
@ -260,7 +258,7 @@ R_DrawSpanletTurbulentBlended66( void )
}
static void
R_DrawSpanletTurbulentBlended33( void )
R_DrawSpanletTurbulentBlended33(const int *r_turb_turb)
{
do
{
@ -288,7 +286,7 @@ R_DrawSpanletTurbulentBlended33( void )
** R_DrawSpanlet33
*/
static void
R_DrawSpanlet33( void )
R_DrawSpanlet33(const int *r_turb_turb)
{
do
{
@ -317,7 +315,7 @@ R_DrawSpanlet33( void )
}
static void
R_DrawSpanletConstant33( void )
R_DrawSpanletConstant33(const int *r_turb_turb)
{
do
{
@ -336,7 +334,7 @@ R_DrawSpanletConstant33( void )
** R_DrawSpanlet66
*/
static void
R_DrawSpanlet66( void )
R_DrawSpanlet66(const int *r_turb_turb)
{
do
{
@ -368,11 +366,11 @@ R_DrawSpanlet66( void )
** R_DrawSpanlet33Stipple
*/
static void
R_DrawSpanlet33Stipple( void )
R_DrawSpanlet33Stipple(const int *r_turb_turb)
{
pixel_t *pdest = s_spanletvars.pdest;
zvalue_t *pz = s_spanletvars.pz;
int izi = s_spanletvars.izi;
zvalue_t izi = s_spanletvars.izi;
if ( r_polydesc.stipple_parity ^ ( s_spanletvars.v & 1 ) )
{
@ -428,12 +426,12 @@ R_DrawSpanlet33Stipple( void )
** R_DrawSpanlet66Stipple
*/
static void
R_DrawSpanlet66Stipple( void )
R_DrawSpanlet66Stipple(const int *r_turb_turb)
{
unsigned btemp;
pixel_t *pdest = s_spanletvars.pdest;
zvalue_t *pz = s_spanletvars.pz;
int izi = s_spanletvars.izi;
zvalue_t izi = s_spanletvars.izi;
s_spanletvars.pdest += s_spanletvars.spancount;
s_spanletvars.pz += s_spanletvars.spancount;
@ -598,13 +596,15 @@ R_PolygonDrawSpans(espan_t *pspan, int iswater )
int snext, tnext;
float sdivz, tdivz, zi, z, du, dv, spancountminus1;
float sdivzspanletstepu, tdivzspanletstepu, zispanletstepu;
int *r_turb_turb;
s_spanletvars.pbase = cacheblock;
//PGM
if ( iswater & SURF_WARP)
r_turb_turb = sintable + ((int)(r_newrefdef.time*SPEED)&(CYCLE-1));
else if (iswater & SURF_FLOWING)
else
// iswater & SURF_FLOWING
r_turb_turb = blanktable;
//PGM
@ -740,7 +740,7 @@ R_PolygonDrawSpans(espan_t *pspan, int iswater )
s_spanletvars.t = s_spanletvars.t & ((CYCLE<<16)-1);
}
r_polydesc.drawspanlet();
r_polydesc.drawspanlet(r_turb_turb);
s_spanletvars.s = snext;
s_spanletvars.t = tnext;
@ -1210,7 +1210,7 @@ R_DrawPoly(int iswater)
** R_DrawAlphaSurfaces
*/
void
R_DrawAlphaSurfaces( void )
R_DrawAlphaSurfaces(void)
{
msurface_t *s = r_alpha_surfaces;

View file

@ -36,8 +36,6 @@ typedef struct {
int *prightedgevert2;
} edgetable;
aliastriangleparms_t aliastriangleparms;
static int ubasestep, errorterm, erroradjustup, erroradjustdown;
static int r_p0[6], r_p1[6], r_p2[6];
@ -64,7 +62,7 @@ static edgetable edgetables[12] = {
// FIXME: some of these can become statics
static int a_sstepxfrac, a_tstepxfrac, r_lstepx, a_ststepxwhole;
static int r_sstepx, r_tstepx, r_lstepy, r_sstepy, r_tstepy;
static int r_zistepx, r_zistepy;
static zvalue_t r_zistepx, r_zistepy;
static int d_aspancount, d_countextrastep;
static spanpackage_t *a_spans;
@ -75,13 +73,14 @@ spanpackage_t *triangle_spans;
static int ystart;
static pixel_t *d_pdest, *d_ptex;
static zvalue_t *d_pz;
static int d_sfrac, d_tfrac, d_light, d_zi;
static int d_sfrac, d_tfrac, d_light;
static zvalue_t d_zi;
static int d_ptexextrastep, d_sfracextrastep;
static int d_tfracextrastep, d_lightextrastep, d_pdestextrastep;
static int d_lightbasestep, d_pdestbasestep, d_ptexbasestep;
static int d_sfracbasestep, d_tfracbasestep;
static int d_ziextrastep, d_zibasestep;
static int d_pzextrastep, d_pzbasestep;
static zvalue_t d_ziextrastep, d_zibasestep;
static zvalue_t d_pzextrastep, d_pzbasestep;
typedef struct {
int quotient;
@ -110,45 +109,47 @@ static void R_PolysetScanLeftEdge_C(int height);
// ======================
// PGM
// 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
static byte irtable[256] = { 79, 78, 77, 76, 75, 74, 73, 72, // black/white
71, 70, 69, 68, 67, 66, 65, 64,
64, 65, 66, 67, 68, 69, 70, 71, // dark taupe
72, 73, 74, 75, 76, 77, 78, 79,
static const byte irtable[256] = {
79, 78, 77, 76, 75, 74, 73, 72, // black/white
71, 70, 69, 68, 67, 66, 65, 64,
64, 65, 66, 67, 68, 69, 70, 71, // dark taupe
72, 73, 74, 75, 76, 77, 78, 79,
64, 65, 66, 67, 68, 69, 70, 71, // slate grey
72, 73, 74, 75, 76, 77, 78, 79,
208, 208, 208, 208, 208, 208, 208, 208, // unused?'
64, 66, 68, 70, 72, 74, 76, 78, // dark yellow
64, 65, 66, 67, 68, 69, 70, 71, // slate grey
72, 73, 74, 75, 76, 77, 78, 79,
208, 208, 208, 208, 208, 208, 208, 208, // unused?'
64, 66, 68, 70, 72, 74, 76, 78, // dark yellow
64, 65, 66, 67, 68, 69, 70, 71, // dark red
72, 73, 74, 75, 76, 77, 78, 79,
64, 65, 66, 67, 68, 69, 70, 71, // grey/tan
72, 73, 74, 75, 76, 77, 78, 79,
64, 65, 66, 67, 68, 69, 70, 71, // dark red
72, 73, 74, 75, 76, 77, 78, 79,
64, 65, 66, 67, 68, 69, 70, 71, // grey/tan
72, 73, 74, 75, 76, 77, 78, 79,
64, 66, 68, 70, 72, 74, 76, 78, // chocolate
68, 67, 66, 65, 64, 65, 66, 67, // mauve / teal
68, 69, 70, 71, 72, 73, 74, 75,
76, 76, 77, 77, 78, 78, 79, 79,
64, 66, 68, 70, 72, 74, 76, 78, // chocolate
68, 67, 66, 65, 64, 65, 66, 67, // mauve / teal
68, 69, 70, 71, 72, 73, 74, 75,
76, 76, 77, 77, 78, 78, 79, 79,
64, 65, 66, 67, 68, 69, 70, 71, // more mauve
72, 73, 74, 75, 76, 77, 78, 79,
64, 65, 66, 67, 68, 69, 70, 71, // olive
72, 73, 74, 75, 76, 77, 78, 79,
64, 65, 66, 67, 68, 69, 70, 71, // more mauve
72, 73, 74, 75, 76, 77, 78, 79,
64, 65, 66, 67, 68, 69, 70, 71, // olive
72, 73, 74, 75, 76, 77, 78, 79,
64, 65, 66, 67, 68, 69, 70, 71, // maroon
72, 73, 74, 75, 76, 77, 78, 79,
64, 65, 66, 67, 68, 69, 70, 71, // sky blue
72, 73, 74, 75, 76, 77, 78, 79,
64, 65, 66, 67, 68, 69, 70, 71, // maroon
72, 73, 74, 75, 76, 77, 78, 79,
64, 65, 66, 67, 68, 69, 70, 71, // sky blue
72, 73, 74, 75, 76, 77, 78, 79,
64, 65, 66, 67, 68, 69, 70, 71, // olive again
72, 73, 74, 75, 76, 77, 78, 79,
64, 65, 66, 67, 68, 69, 70, 71, // nuclear green
64, 65, 66, 67, 68, 69, 70, 71, // bright yellow
64, 65, 66, 67, 68, 69, 70, 71, // olive again
72, 73, 74, 75, 76, 77, 78, 79,
64, 65, 66, 67, 68, 69, 70, 71, // nuclear green
64, 65, 66, 67, 68, 69, 70, 71, // bright yellow
64, 65, 66, 67, 68, 69, 70, 71, // fire colors
72, 73, 74, 75, 76, 77, 78, 79,
208, 208, 64, 64, 70, 71, 72, 64, // mishmash1
66, 68, 70, 64, 65, 66, 67, 68}; // mishmash2
64, 65, 66, 67, 68, 69, 70, 71, // fire colors
72, 73, 74, 75, 76, 77, 78, 79,
208, 208, 64, 64, 70, 71, 72, 64, // mishmash1
66, 68, 70, 64, 65, 66, 67, 68}; // mishmash2
// PGM
// ======================
@ -181,24 +182,24 @@ R_DrawTriangle
================
*/
void
R_DrawTriangle( void )
R_DrawTriangle(const finalvert_t *a, const finalvert_t *b, const finalvert_t *c)
{
int dv1_ab, dv0_ac;
int dv0_ab, dv1_ac;
/*
d_xdenom = ( aliastriangleparms.a->v[1] - aliastriangleparms.b->v[1] ) * ( aliastriangleparms.a->v[0] - aliastriangleparms.c->v[0] ) -
( aliastriangleparms.a->v[0] - aliastriangleparms.b->v[0] ) * ( aliastriangleparms.a->v[1] - aliastriangleparms.c->v[1] );
d_xdenom = ( a->v[1] - b->v[1] ) * ( a->v[0] - c->v[0] ) -
( a->v[0] - b->v[0] ) * ( a->v[1] - c->v[1] );
*/
dv0_ab = aliastriangleparms.a->u - aliastriangleparms.b->u;
dv1_ab = aliastriangleparms.a->v - aliastriangleparms.b->v;
dv0_ab = a->u - b->u;
dv1_ab = a->v - b->v;
if ( !( dv0_ab | dv1_ab ) )
return;
dv0_ac = aliastriangleparms.a->u - aliastriangleparms.c->u;
dv1_ac = aliastriangleparms.a->v - aliastriangleparms.c->v;
dv0_ac = a->u - c->u;
dv1_ac = a->v - c->v;
if ( !( dv0_ac | dv1_ac ) )
return;
@ -209,26 +210,26 @@ R_DrawTriangle( void )
{
a_spans = triangle_spans;
r_p0[0] = aliastriangleparms.a->u; // u
r_p0[1] = aliastriangleparms.a->v; // v
r_p0[2] = aliastriangleparms.a->s; // s
r_p0[3] = aliastriangleparms.a->t; // t
r_p0[4] = aliastriangleparms.a->l; // light
r_p0[5] = aliastriangleparms.a->zi; // iz
r_p0[0] = a->u; // u
r_p0[1] = a->v; // v
r_p0[2] = a->s; // s
r_p0[3] = a->t; // t
r_p0[4] = a->l; // light
r_p0[5] = a->zi; // iz
r_p1[0] = aliastriangleparms.b->u;
r_p1[1] = aliastriangleparms.b->v;
r_p1[2] = aliastriangleparms.b->s;
r_p1[3] = aliastriangleparms.b->t;
r_p1[4] = aliastriangleparms.b->l;
r_p1[5] = aliastriangleparms.b->zi;
r_p1[0] = b->u;
r_p1[1] = b->v;
r_p1[2] = b->s;
r_p1[3] = b->t;
r_p1[4] = b->l;
r_p1[5] = b->zi;
r_p2[0] = aliastriangleparms.c->u;
r_p2[1] = aliastriangleparms.c->v;
r_p2[2] = aliastriangleparms.c->s;
r_p2[3] = aliastriangleparms.c->t;
r_p2[4] = aliastriangleparms.c->l;
r_p2[5] = aliastriangleparms.c->zi;
r_p2[0] = c->u;
r_p2[1] = c->v;
r_p2[2] = c->s;
r_p2[3] = c->t;
r_p2[4] = c->l;
r_p2[5] = c->zi;
R_PolysetSetEdgeTable ();
R_RasterizeAliasPolySmooth ();
@ -460,7 +461,7 @@ R_PolysetDrawSpans8_33( spanpackage_t *pspanpackage)
byte *lptex;
int lsfrac, ltfrac;
int llight;
int lzi;
zvalue_t lzi;
zvalue_t *lpz;
do
@ -572,7 +573,7 @@ R_PolysetDrawSpans8_66(spanpackage_t *pspanpackage)
pixel_t *lptex;
int lsfrac, ltfrac;
int llight;
int lzi;
zvalue_t lzi;
zvalue_t *lpz;
do
@ -636,7 +637,7 @@ void
R_PolysetDrawSpansConstant8_66( spanpackage_t *pspanpackage)
{
pixel_t *lpdest;
int lzi;
zvalue_t lzi;
zvalue_t *lpz;
do
@ -703,7 +704,7 @@ R_PolysetDrawSpans8_Opaque (spanpackage_t *pspanpackage)
pixel_t *lpdest;
pixel_t *lptex;
int llight;
int lzi;
zvalue_t lzi;
zvalue_t *lpz;
lpdest = pspanpackage->pdest;

View file

@ -67,15 +67,15 @@ static medge_t *r_skyedges;
static int *r_skysurfedges;
// I just copied this data from a box map...
static int skybox_planes[12] = {2,-128, 0,-128, 2,128, 1,128, 0,128, 1,-128};
static const int skybox_planes[12] = {2,-128, 0,-128, 2,128, 1,128, 0,128, 1,-128};
static int box_surfedges[24] = { 1,2,3,4, -1,5,6,7, 8,9,-6,10, -2,-7,-9,11,
static const int box_surfedges[24] = { 1,2,3,4, -1,5,6,7, 8,9,-6,10, -2,-7,-9,11,
12,-3,-11,-8, -12,-10,-5,-4};
static int box_edges[24] = { 1,2, 2,3, 3,4, 4,1, 1,5, 5,6, 6,2, 7,8, 8,6, 5,7, 8,3, 7,4};
static const int box_edges[24] = { 1,2, 2,3, 3,4, 4,1, 1,5, 5,6, 6,2, 7,8, 8,6, 5,7, 8,3, 7,4};
static int box_faces[6] = {0,0,2,2,2,0};
static const int box_faces[6] = {0,0,2,2,2,0};
static vec3_t box_vecs[6][2] = {
static const vec3_t box_vecs[6][2] = {
{ {0,-1,0}, {-1,0,0} },
{ {0,1,0}, {0,0,-1} },
{ {0,-1,0}, {1,0,0} },
@ -84,7 +84,7 @@ static vec3_t box_vecs[6][2] = {
{ {-1,0,0}, {0,0,-1} }
};
static float box_verts[8][3] = {
static const float box_verts[8][3] = {
{-1,-1,-1},
{-1,1,-1},
{1,1,-1},

View file

@ -23,12 +23,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "header/local.h"
static pixel_t *r_turb_pbase, *r_turb_pdest;
static int r_turb_s, r_turb_t, r_turb_sstep, r_turb_tstep;
int *r_turb_turb;
static int r_turb_spancount;
static void D_DrawTurbulent8Span (void);
#define SPANSTEP_SHIFT 4
#define SPANSTEP (1 << SPANSTEP_SHIFT)
byte **warp_rowptr;
int *warp_column;
@ -94,52 +91,98 @@ D_WarpScreen (void)
}
}
/*
=============
D_DrawTurbulent8Span
D_DrawSpanGetStep
Return safe span step for u/z and v/z
=============
*/
static void
D_DrawTurbulent8Span (void)
static int
D_DrawSpanGetStep(float d_zistepu, float d_zistepv, int cachewidth)
{
do
int spanzshift = SPANSTEP_SHIFT;
int spanzshift_value = (1 << spanzshift);
float d_zistepu_shifted, d_zistepv_shifted;
d_zistepu_shifted = d_zistepu * SHIFT16XYZ_MULT;
d_zistepv_shifted = d_zistepv * SHIFT16XYZ_MULT;
// check that we can draw parallel surfaces to screen surface
// (both ends have same z value)
if ((int)(d_zistepu_shifted * spanzshift_value) == 0 &&
(int)(d_zistepv_shifted * spanzshift_value) == 0)
{
int sturb, tturb;
sturb = ((r_turb_s + r_turb_turb[(r_turb_t>>16)&(CYCLE-1)])>>16)&63;
tturb = ((r_turb_t + r_turb_turb[(r_turb_s>>16)&(CYCLE-1)])>>16)&63;
*r_turb_pdest++ = *(r_turb_pbase + (tturb<<6) + sturb);
r_turb_s += r_turb_sstep;
r_turb_t += r_turb_tstep;
} while (--r_turb_spancount > 0);
// search next safe value
while (spanzshift_value < vid.width &&
(int)(d_zistepu_shifted * spanzshift_value) == 0 &&
(int)(d_zistepv_shifted * spanzshift_value) == 0)
{
spanzshift ++;
spanzshift_value <<= 1;
}
// step back to last safe value
if ((int)(d_zistepu_shifted * spanzshift_value) != 0 ||
(int)(d_zistepv_shifted * spanzshift_value) != 0)
{
spanzshift --;
}
}
return spanzshift;
}
/*
=============
Turbulent8
D_DrawTurbulentSpan
=============
*/
static pixel_t *
D_DrawTurbulentSpan (pixel_t *pdest, const pixel_t *pbase,
int s, int t,
int sstep, int tstep,
int spancount,
int *turb)
{
do
{
int sturb, tturb;
sturb = ((s + turb[(t>>SHIFT16XYZ)&(CYCLE-1)])>>16)&63;
tturb = ((t + turb[(s>>SHIFT16XYZ)&(CYCLE-1)])>>16)&63;
*pdest++ = *(pbase + (tturb<<6) + sturb);
s += sstep;
t += tstep;
} while (--spancount > 0);
return pdest;
}
/*
=============
TurbulentPow2
=============
*/
void
Turbulent8 (espan_t *pspan)
TurbulentPow2 (espan_t *pspan)
{
int snext, tnext;
float spancountminus1;
float sdivz16stepu, tdivz16stepu, zi16stepu;
float sdivzpow2stepu, tdivzpow2stepu, zipow2stepu;
pixel_t *r_turb_pbase;
int *r_turb_turb;
r_turb_turb = sintable + ((int)(r_newrefdef.time*SPEED)&(CYCLE-1));
r_turb_sstep = 0; // keep compiler happy
r_turb_tstep = 0; // ditto
r_turb_pbase = (unsigned char *)cacheblock;
sdivz16stepu = d_sdivzstepu * 16;
tdivz16stepu = d_tdivzstepu * 16;
zi16stepu = d_zistepu * 16;
sdivzpow2stepu = d_sdivzstepu * SPANSTEP;
tdivzpow2stepu = d_tdivzstepu * SPANSTEP;
zipow2stepu = d_zistepu * SPANSTEP;
do
{
int count;
int count, r_turb_s, r_turb_t;
float sdivz, tdivz, zi, z, du, dv;
pixel_t *r_turb_pdest;
r_turb_pdest = d_viewbuffer + (r_screenwidth * pspan->v) + pspan->u;
@ -168,9 +211,16 @@ Turbulent8 (espan_t *pspan)
do
{
int snext, tnext;
int r_turb_sstep, r_turb_tstep;
int r_turb_spancount;
r_turb_sstep = 0; // keep compiler happy
r_turb_tstep = 0; // ditto
// calculate s and t at the far end of the span
if (count >= 16)
r_turb_spancount = 16;
if (count >= SPANSTEP)
r_turb_spancount = SPANSTEP;
else
r_turb_spancount = count;
@ -180,27 +230,29 @@ Turbulent8 (espan_t *pspan)
{
// calculate s/z, t/z, zi->fixed s and t at far end of span,
// calculate s and t steps across span by shifting
sdivz += sdivz16stepu;
tdivz += tdivz16stepu;
zi += zi16stepu;
sdivz += sdivzpow2stepu;
tdivz += tdivzpow2stepu;
zi += zipow2stepu;
z = (float)SHIFT16XYZ_MULT / zi; // prescale to 16.16 fixed-point
snext = (int)(sdivz * z) + sadjust;
if (snext > bbextents)
snext = bbextents;
else if (snext < 16)
snext = 16; // prevent round-off error on <0 steps from
// from causing overstepping & running off the
// edge of the texture
else if (snext < SPANSTEP)
// prevent round-off error on <0 steps from
// from causing overstepping & running off the
// edge of the texture
snext = SPANSTEP;
tnext = (int)(tdivz * z) + tadjust;
if (tnext > bbextentt)
tnext = bbextentt;
else if (tnext < 16)
tnext = 16; // guard against round-off error on <0 steps
else if (tnext < SPANSTEP)
// guard against round-off error on <0 steps
tnext = SPANSTEP;
r_turb_sstep = (snext - r_turb_s) >> 4;
r_turb_tstep = (tnext - r_turb_t) >> 4;
r_turb_sstep = (snext - r_turb_s) >> SPANSTEP_SHIFT;
r_turb_tstep = (tnext - r_turb_t) >> SPANSTEP_SHIFT;
}
else
{
@ -216,16 +268,18 @@ Turbulent8 (espan_t *pspan)
snext = (int)(sdivz * z) + sadjust;
if (snext > bbextents)
snext = bbextents;
else if (snext < 16)
snext = 16; // prevent round-off error on <0 steps from
// from causing overstepping & running off the
// edge of the texture
else if (snext < SPANSTEP)
// prevent round-off error on <0 steps from
// from causing overstepping & running off the
// edge of the texture
snext = SPANSTEP;
tnext = (int)(tdivz * z) + tadjust;
if (tnext > bbextentt)
tnext = bbextentt;
else if (tnext < 16)
tnext = 16; // guard against round-off error on <0 steps
else if (tnext < SPANSTEP)
// guard against round-off error on <0 steps
tnext = SPANSTEP;
if (r_turb_spancount > 1)
{
@ -234,10 +288,14 @@ Turbulent8 (espan_t *pspan)
}
}
r_turb_s = r_turb_s & ((CYCLE<<16)-1);
r_turb_t = r_turb_t & ((CYCLE<<16)-1);
r_turb_s = r_turb_s & ((CYCLE<<SHIFT16XYZ)-1);
r_turb_t = r_turb_t & ((CYCLE<<SHIFT16XYZ)-1);
D_DrawTurbulent8Span ();
r_turb_pdest = D_DrawTurbulentSpan (r_turb_pdest, r_turb_pbase,
r_turb_s, r_turb_t,
r_turb_sstep, r_turb_tstep,
r_turb_spancount,
r_turb_turb);
r_turb_s = snext;
r_turb_t = tnext;
@ -251,32 +309,31 @@ Turbulent8 (espan_t *pspan)
//PGM
/*
=============
NonTurbulent8 - this is for drawing scrolling textures. they're warping water textures
NonTurbulentPow2 - this is for drawing scrolling textures. they're warping water textures
but the turbulence is automatically 0.
=============
*/
void
NonTurbulent8 (espan_t *pspan)
NonTurbulentPow2 (espan_t *pspan)
{
int snext, tnext;
float spancountminus1;
float sdivz16stepu, tdivz16stepu, zi16stepu;
float sdivzpow2stepu, tdivzpow2stepu, zipow2stepu;
pixel_t *r_turb_pbase;
int *r_turb_turb;
r_turb_turb = blanktable;
r_turb_sstep = 0; // keep compiler happy
r_turb_tstep = 0; // ditto
r_turb_pbase = (unsigned char *)cacheblock;
sdivz16stepu = d_sdivzstepu * 16;
tdivz16stepu = d_tdivzstepu * 16;
zi16stepu = d_zistepu * 16;
sdivzpow2stepu = d_sdivzstepu * SPANSTEP;
tdivzpow2stepu = d_tdivzstepu * SPANSTEP;
zipow2stepu = d_zistepu * SPANSTEP;
do
{
int count;
int count, r_turb_s, r_turb_t;
float sdivz, tdivz, zi, z, dv, du;
pixel_t *r_turb_pdest;
r_turb_pdest = d_viewbuffer + (r_screenwidth * pspan->v) + pspan->u;
@ -305,9 +362,16 @@ NonTurbulent8 (espan_t *pspan)
do
{
int snext, tnext;
int r_turb_sstep, r_turb_tstep;
int r_turb_spancount;
r_turb_sstep = 0; // keep compiler happy
r_turb_tstep = 0; // ditto
// calculate s and t at the far end of the span
if (count >= 16)
r_turb_spancount = 16;
if (count >= SPANSTEP)
r_turb_spancount = SPANSTEP;
else
r_turb_spancount = count;
@ -317,27 +381,29 @@ NonTurbulent8 (espan_t *pspan)
{
// calculate s/z, t/z, zi->fixed s and t at far end of span,
// calculate s and t steps across span by shifting
sdivz += sdivz16stepu;
tdivz += tdivz16stepu;
zi += zi16stepu;
sdivz += sdivzpow2stepu;
tdivz += tdivzpow2stepu;
zi += zipow2stepu;
z = (float)SHIFT16XYZ_MULT / zi; // prescale to 16.16 fixed-point
snext = (int)(sdivz * z) + sadjust;
if (snext > bbextents)
snext = bbextents;
else if (snext < 16)
snext = 16; // prevent round-off error on <0 steps from
// from causing overstepping & running off the
// edge of the texture
else if (snext < SPANSTEP)
// prevent round-off error on <0 steps from
// from causing overstepping & running off the
// edge of the texture
snext = SPANSTEP;
tnext = (int)(tdivz * z) + tadjust;
if (tnext > bbextentt)
tnext = bbextentt;
else if (tnext < 16)
tnext = 16; // guard against round-off error on <0 steps
else if (tnext < SPANSTEP)
// guard against round-off error on <0 steps
tnext = SPANSTEP;
r_turb_sstep = (snext - r_turb_s) >> 4;
r_turb_tstep = (tnext - r_turb_t) >> 4;
r_turb_sstep = (snext - r_turb_s) >> SPANSTEP_SHIFT;
r_turb_tstep = (tnext - r_turb_t) >> SPANSTEP_SHIFT;
}
else
{
@ -353,16 +419,18 @@ NonTurbulent8 (espan_t *pspan)
snext = (int)(sdivz * z) + sadjust;
if (snext > bbextents)
snext = bbextents;
else if (snext < 16)
snext = 16; // prevent round-off error on <0 steps from
// from causing overstepping & running off the
// edge of the texture
else if (snext < SPANSTEP)
// prevent round-off error on <0 steps from
// from causing overstepping & running off the
// edge of the texture
snext = SPANSTEP;
tnext = (int)(tdivz * z) + tadjust;
if (tnext > bbextentt)
tnext = bbextentt;
else if (tnext < 16)
tnext = 16; // guard against round-off error on <0 steps
else if (tnext < SPANSTEP)
// guard against round-off error on <0 steps
tnext = SPANSTEP;
if (r_turb_spancount > 1)
{
@ -371,10 +439,14 @@ NonTurbulent8 (espan_t *pspan)
}
}
r_turb_s = r_turb_s & ((CYCLE<<16)-1);
r_turb_t = r_turb_t & ((CYCLE<<16)-1);
r_turb_s = r_turb_s & ((CYCLE<<SHIFT16XYZ)-1);
r_turb_t = r_turb_t & ((CYCLE<<SHIFT16XYZ)-1);
D_DrawTurbulent8Span ();
r_turb_pdest = D_DrawTurbulentSpan (r_turb_pdest, r_turb_pbase,
r_turb_s, r_turb_t,
r_turb_sstep, r_turb_tstep,
r_turb_spancount,
r_turb_turb);
r_turb_s = snext;
r_turb_t = tnext;
@ -387,47 +459,133 @@ NonTurbulent8 (espan_t *pspan)
//====================
// Enable custom filtering
extern cvar_t *sw_texture_filtering;
static int filtering_kernel[2][2][2] = {
extern cvar_t *r_anisotropic;
static const int filtering_kernel[2][2][2] = {
{
{16384, 0},
{49152, 32768}
{0x1 << (SHIFT16XYZ-2), 0x0},
{0xC << (SHIFT16XYZ-4), 0x1 << (SHIFT16XYZ-1)}
},
{
{32768, 49152},
{0, 16384}
{0x1 << (SHIFT16XYZ-1), 0xC << (SHIFT16XYZ-4)},
{0x0, 0x1 << (SHIFT16XYZ-2)}
}
};
/*
=============
D_DrawSpans16
D_DrawSpan
=============
*/
static pixel_t *
D_DrawSpan(pixel_t *pdest, const pixel_t *pbase, int s, int t, int sstep, int tstep, int spancount)
{
const pixel_t *tdest_max = pdest + spancount;
FIXME: actually make this subdivide by 16 instead of 8!!!
// horisontal span (span in same row)
if (((t + tstep * spancount) >> SHIFT16XYZ) == (t >> SHIFT16XYZ))
{
// position in texture
const pixel_t *tbase = pbase + (t >> SHIFT16XYZ) * cachewidth;
do
{
*pdest++ = *(tbase + (s >> SHIFT16XYZ));
s += sstep;
} while (pdest < tdest_max);
}
// vertical span (span in same column)
else if (((s + sstep * spancount) >> SHIFT16XYZ) == (s >> SHIFT16XYZ))
{
// position in texture
const pixel_t *tbase = pbase + (s >> SHIFT16XYZ);
do
{
*pdest++ = *(tbase + (t >> SHIFT16XYZ) * cachewidth);
t += tstep;
} while (pdest < tdest_max);
}
// diagonal span
else
{
do
{
*pdest++ = *(pbase + (s >> SHIFT16XYZ) + (t >> SHIFT16XYZ) * cachewidth);
s += sstep;
t += tstep;
} while (pdest < tdest_max);
}
return pdest;
}
/*
=============
D_DrawSpanFiltered
=============
*/
static pixel_t *
D_DrawSpanFiltered(pixel_t *pdest, pixel_t *pbase, int s, int t, int sstep, int tstep, int spancount,
const espan_t *pspan)
{
do
{
int idiths = s;
int iditht = t;
int X = (pspan->u + spancount) & 1;
int Y = (pspan->v)&1;
//Using the kernel
idiths += filtering_kernel[X][Y][0];
iditht += filtering_kernel[X][Y][1];
idiths = idiths >> SHIFT16XYZ;
idiths = idiths ? idiths -1 : idiths;
iditht = iditht >> SHIFT16XYZ;
iditht = iditht ? iditht -1 : iditht;
*pdest++ = *(pbase + idiths + iditht * cachewidth);
s += sstep;
t += tstep;
} while (--spancount > 0);
return pdest;
}
/*
=============
D_DrawSpansPow2
=============
*/
void
D_DrawSpans16 (espan_t *pspan)
D_DrawSpansPow2 (espan_t *pspan)
{
int spancount;
unsigned char *pbase;
int snext, tnext, sstep, tstep;
float spancountminus1;
float sdivz8stepu, tdivz8stepu, zi8stepu;
int spancount;
pixel_t *pbase;
int snext, tnext;
float spancountminus1;
float sdivzpow2stepu, tdivzpow2stepu, zipow2stepu;
int texture_filtering;
int spanstep_shift, spanstep_value;
sstep = 0; // keep compiler happy
tstep = 0; // ditto
spanstep_shift = D_DrawSpanGetStep(d_zistepu, d_zistepv, cachewidth);
spanstep_value = (1 << spanstep_shift);
pbase = (unsigned char *)cacheblock;
sdivz8stepu = d_sdivzstepu * 8;
tdivz8stepu = d_tdivzstepu * 8;
zi8stepu = d_zistepu * 8;
texture_filtering = (int)r_anisotropic->value;
sdivzpow2stepu = d_sdivzstepu * spanstep_value;
tdivzpow2stepu = d_tdivzstepu * spanstep_value;
zipow2stepu = d_zistepu * spanstep_value;
do
{
pixel_t *pdest;
int count, s, t;
int count, s, t;
float sdivz, tdivz, zi, z, du, dv;
pdest = d_viewbuffer + (r_screenwidth * pspan->v) + pspan->u;
@ -457,9 +615,14 @@ D_DrawSpans16 (espan_t *pspan)
do
{
int sstep, tstep;
sstep = 0; // keep compiler happy
tstep = 0; // ditto
// calculate s and t at the far end of the span
if (count >= 8)
spancount = 8;
if (count >= spanstep_value)
spancount = spanstep_value;
else
spancount = count;
@ -469,27 +632,29 @@ D_DrawSpans16 (espan_t *pspan)
{
// calculate s/z, t/z, zi->fixed s and t at far end of span,
// calculate s and t steps across span by shifting
sdivz += sdivz8stepu;
tdivz += tdivz8stepu;
zi += zi8stepu;
sdivz += sdivzpow2stepu;
tdivz += tdivzpow2stepu;
zi += zipow2stepu;
z = (float)SHIFT16XYZ_MULT / zi; // prescale to 16.16 fixed-point
snext = (int)(sdivz * z) + sadjust;
if (snext > bbextents)
snext = bbextents;
else if (snext < 8)
snext = 8; // prevent round-off error on <0 steps from
// from causing overstepping & running off the
// edge of the texture
else if (snext < spanstep_value)
// prevent round-off error on <0 steps from
// from causing overstepping & running off the
// edge of the texture
snext = spanstep_value;
tnext = (int)(tdivz * z) + tadjust;
if (tnext > bbextentt)
tnext = bbextentt;
else if (tnext < 8)
tnext = 8; // guard against round-off error on <0 steps
else if (tnext < spanstep_value)
// guard against round-off error on <0 steps
tnext = spanstep_value;
sstep = (snext - s) >> 3;
tstep = (tnext - t) >> 3;
sstep = (snext - s) >> spanstep_shift;
tstep = (tnext - t) >> spanstep_shift;
}
else
{
@ -505,16 +670,18 @@ D_DrawSpans16 (espan_t *pspan)
snext = (int)(sdivz * z) + sadjust;
if (snext > bbextents)
snext = bbextents;
else if (snext < 8)
snext = 8; // prevent round-off error on <0 steps from
// from causing overstepping & running off the
// edge of the texture
else if (snext < spanstep_value)
// prevent round-off error on <0 steps from
// from causing overstepping & running off the
// edge of the texture
snext = spanstep_value;
tnext = (int)(tdivz * z) + tadjust;
if (tnext > bbextentt)
tnext = bbextentt;
else if (tnext < 8)
tnext = 8; // guard against round-off error on <0 steps
else if (tnext < spanstep_value)
// guard against round-off error on <0 steps
tnext = spanstep_value;
if (spancount > 1)
{
@ -524,46 +691,18 @@ D_DrawSpans16 (espan_t *pspan)
}
// Drawing phrase
if (sw_texture_filtering->value == 0.0f)
if (texture_filtering == 0)
{
do
{
*pdest++ = *(pbase + (s >> SHIFT16XYZ) + (t >> SHIFT16XYZ) * cachewidth);
s += sstep;
t += tstep;
} while (--spancount > 0);
s = snext;
t = tnext;
pdest = D_DrawSpan(pdest, pbase, s, t, sstep, tstep,
spancount);
}
else if (sw_texture_filtering->value == 1.0f)
else
{
do
{
int idiths = s;
int iditht = t;
int X = (pspan->u + spancount) & 1;
int Y = (pspan->v)&1;
//Using the kernel
idiths += filtering_kernel[X][Y][0];
iditht += filtering_kernel[X][Y][1];
idiths = idiths >> SHIFT16XYZ;
idiths = idiths ? idiths -1 : idiths;
iditht = iditht >> SHIFT16XYZ;
iditht = iditht ? iditht -1 : iditht;
*pdest++ = *(pbase + idiths + iditht * cachewidth);
s += sstep;
t += tstep;
} while (--spancount > 0);
pdest = D_DrawSpanFiltered(pdest, pbase, s, t, sstep, tstep,
spancount, pspan);
}
s = snext;
t = tnext;
} while (count > 0);
} while ((pspan = pspan->pnext) != NULL);
@ -577,7 +716,7 @@ D_DrawZSpans
void
D_DrawZSpans (espan_t *pspan)
{
int izistep;
zvalue_t izistep;
// FIXME: check for clamping/range problems
// we count on FP exceptions being turned off to avoid range problems
@ -586,7 +725,7 @@ D_DrawZSpans (espan_t *pspan)
do
{
int count;
int izi;
zvalue_t izi;
zvalue_t *pdest;
float zi;
float du, dv;

View file

@ -185,6 +185,8 @@ GLimp_Init(void)
void
GLimp_Shutdown(void)
{
ShutdownGraphics();
if (SDL_WasInit(SDL_INIT_EVERYTHING) == SDL_INIT_VIDEO)
{
SDL_Quit();
@ -332,6 +334,16 @@ GLimp_InitGraphics(int fullscreen, int *pwidth, int *pheight)
return true;
}
/*
* Shuts the window down.
*/
void
GLimp_ShutdownGraphics(void)
{
SDL_GL_ResetAttributes();
ShutdownGraphics();
}
/*
* (Un)grab Input
*/

View file

@ -58,6 +58,7 @@ extern int glimp_refreshRate;
qboolean GLimp_Init(void);
void GLimp_Shutdown(void);
qboolean GLimp_InitGraphics(int fullscreen, int *pwidth, int *pheight);
void GLimp_ShutdownGraphics(void);
void GLimp_GrabInput(qboolean grab);
int GLimp_GetRefreshRate(void);

View file

@ -337,6 +337,7 @@ VID_ShutdownRenderer(void)
{
/* Shut down the renderer */
re.Shutdown();
GLimp_ShutdownGraphics();
Sys_FreeLibrary(reflib_handle);
reflib_handle = NULL;
memset(&re, 0, sizeof(re));

View file

@ -39,6 +39,7 @@ typedef struct
replacement_t replacements[] = {
{"cd_shuffle", "ogg_shuffle"},
{"cl_drawfps", "cl_showfps"},
{"gl_anisotropic", "r_anisotropic"},
{"gl_drawentities", "r_drawentities"},
{"gl_drawworld", "r_drawworld"},
{"gl_fullbright", "r_fullbright"},

View file

@ -163,15 +163,15 @@ Graphics (all renderers):
* **r_vsync**: Enables the vsync: frames are synchronized with
display refresh rate, should (but doesn't always) prevent tearing.
Graphics (GL renderers only):
-----------------------------
* **gl_anisotropic**: Anisotropic filtering. Possible values are
* **r_anisotropic**: Anisotropic filtering. Possible values are
dependent on the GPU driver, most of them support `1`, `2`, `4`, `8`
and `16`. Anisotropic filtering gives a huge improvement to texture
quality by a negligible performance impact.
Graphics (GL renderers only):
-----------------------------
* **gl_msaa_samples**: Full scene anti aliasing samples. The number of
samples depends on the GPU driver, most drivers support at least
`2`, `4` and `8` samples. If an invalid value is set, the value is