GL3: Cleanup (remove TODOs, STUBs and old commented out code, ...)

This commit is contained in:
Daniel Gibson 2017-04-03 00:23:56 +02:00
parent 85c8c83c4b
commit b91b244431
10 changed files with 115 additions and 246 deletions

View file

@ -266,6 +266,97 @@ GL3_Upload8(byte *data, int width, int height, qboolean mipmap, qboolean is_sky)
return GL3_Upload32(trans, width, height, mipmap);
}
typedef struct
{
short x, y;
} floodfill_t;
/* must be a power of 2 */
#define FLOODFILL_FIFO_SIZE 0x1000
#define FLOODFILL_FIFO_MASK (FLOODFILL_FIFO_SIZE - 1)
#define FLOODFILL_STEP(off, dx, dy) \
{ \
if (pos[off] == fillcolor) \
{ \
pos[off] = 255; \
fifo[inpt].x = x + (dx), fifo[inpt].y = y + (dy); \
inpt = (inpt + 1) & FLOODFILL_FIFO_MASK; \
} \
else if (pos[off] != 255) \
{ \
fdc = pos[off]; \
} \
}
/*
* Fill background pixels so mipmapping doesn't have haloes
*/
static void
FloodFillSkin(byte *skin, int skinwidth, int skinheight)
{
byte fillcolor = *skin; /* assume this is the pixel to fill */
floodfill_t fifo[FLOODFILL_FIFO_SIZE];
int inpt = 0, outpt = 0;
int filledcolor = -1;
int i;
if (filledcolor == -1)
{
filledcolor = 0;
/* attempt to find opaque black */
for (i = 0; i < 256; ++i)
{
if (LittleLong(d_8to24table[i]) == (255 << 0)) /* alpha 1.0 */
{
filledcolor = i;
break;
}
}
}
/* can't fill to filled color or to transparent color (used as visited marker) */
if ((fillcolor == filledcolor) || (fillcolor == 255))
{
return;
}
fifo[inpt].x = 0, fifo[inpt].y = 0;
inpt = (inpt + 1) & FLOODFILL_FIFO_MASK;
while (outpt != inpt)
{
int x = fifo[outpt].x, y = fifo[outpt].y;
int fdc = filledcolor;
byte *pos = &skin[x + skinwidth * y];
outpt = (outpt + 1) & FLOODFILL_FIFO_MASK;
if (x > 0)
{
FLOODFILL_STEP(-1, -1, 0);
}
if (x < skinwidth - 1)
{
FLOODFILL_STEP(1, 1, 0);
}
if (y > 0)
{
FLOODFILL_STEP(-skinwidth, 0, -1);
}
if (y < skinheight - 1)
{
FLOODFILL_STEP(skinwidth, 0, 1);
}
skin[x + skinwidth * y] = fdc;
}
}
/*
* This is also used as an entry point for the generated r_notexture
*/
@ -318,11 +409,11 @@ GL3_LoadPic(char *name, byte *pic, int width, int realwidth,
if ((type == it_skin) && (bits == 8))
{
//R_FloodFillSkin(pic, width, height);
STUB_ONCE("TODO: Implement and call GL3_FloodFillSkin()!");
FloodFillSkin(pic, width, height);
}
image->scrap = false; // FIXME: not sure if we need scrap anymore..
// image->scrap = false; // TODO: reintroduce scrap? would allow optimizations in 2D rendering..
glGenTextures(1, &texNum);
@ -343,11 +434,6 @@ GL3_LoadPic(char *name, byte *pic, int width, int realwidth,
(image->type != it_pic && image->type != it_sky));
}
// TODO: I don't think we even need image->upload_*
image->upload_width = width; // upload_width; /* after power of 2 and scales */
image->upload_height = height; // upload_height;
//image->paletted = uploaded_paletted;
if (realwidth && realheight)
{
if ((realwidth <= image->width) && (realheight <= image->height))
@ -373,7 +459,7 @@ GL3_LoadPic(char *name, byte *pic, int width, int realwidth,
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
}
#if 0 // TODO: do we need the scrap? (probably not)
#if 0 // TODO: the scrap could allow batch rendering 2D stuff? not sure it's worth the hassle..
/* load little pics into the scrap */
if (!nolerp && (image->type == it_pic) && (bits == 8) &&
(image->width < 64) && (image->height < 64))
@ -789,8 +875,8 @@ GL3_ImageList_f(void)
{
continue;
}
w = image->upload_width;
h = image->upload_height;
w = image->width;
h = image->height;
isNPOT = IsNPOT(w) || IsNPOT(h);

View file

@ -264,7 +264,7 @@ GL3_LightPoint(vec3_t p, vec3_t color)
vec3_t dist;
float add;
if (!gl3_worldmodel->lightdata || !currententity) // FIXME: the currententity check is new
if (!gl3_worldmodel->lightdata || !currententity)
{
color[0] = color[1] = color[2] = 1.0;
return;
@ -307,100 +307,6 @@ GL3_LightPoint(vec3_t p, vec3_t color)
VectorScale(color, gl_modulate->value, color);
}
#if 0 // TODO: REMOVE! (currently kept to look at when writing shader for this)
static void
AddDynamicLights(msurface_t *surf)
{
int lnum;
int sd, td;
float fdist, frad, fminlight;
vec3_t impact, local;
int s, t;
int i;
int smax, tmax;
mtexinfo_t *tex;
dlight_t *dl;
float *pfBL;
float fsacc, ftacc;
smax = (surf->extents[0] >> 4) + 1;
tmax = (surf->extents[1] >> 4) + 1;
tex = surf->texinfo;
for (lnum = 0; lnum < gl3_newrefdef.num_dlights; lnum++)
{
if (!(surf->dlightbits & (1 << lnum)))
{
continue; /* not lit by this light */
}
dl = &gl3_newrefdef.dlights[lnum];
frad = dl->intensity;
fdist = DotProduct(dl->origin, surf->plane->normal) -
surf->plane->dist;
frad -= fabs(fdist);
/* rad is now the highest intensity on the plane */
fminlight = DLIGHT_CUTOFF;
if (frad < fminlight)
{
continue;
}
fminlight = frad - fminlight;
for (i = 0; i < 3; i++)
{
impact[i] = dl->origin[i] -
surf->plane->normal[i] * fdist;
}
local[0] = DotProduct(impact,
tex->vecs[0]) + tex->vecs[0][3] - surf->texturemins[0];
local[1] = DotProduct(impact,
tex->vecs[1]) + tex->vecs[1][3] - surf->texturemins[1];
pfBL = s_blocklights;
for (t = 0, ftacc = 0; t < tmax; t++, ftacc += 16)
{
td = local[1] - ftacc;
if (td < 0)
{
td = -td;
}
for (s = 0, fsacc = 0; s < smax; s++, fsacc += 16, pfBL += 3)
{
sd = Q_ftol(local[0] - fsacc);
if (sd < 0)
{
sd = -sd;
}
if (sd > td)
{
fdist = sd + (td >> 1);
}
else
{
fdist = td + (sd >> 1);
}
if (fdist < fminlight)
{
pfBL[0] += (frad - fdist) * dl->color[0];
pfBL[1] += (frad - fdist) * dl->color[1];
pfBL[2] += (frad - fdist) * dl->color[2];
}
}
}
}
}
#endif // 0
/*
* Combine and scale multiple lightmaps into the floating format in blocklights
@ -442,7 +348,7 @@ GL3_BuildLightMap(msurface_t *surf, int offsetInLMbuf, int stride)
for (map = 0; map < MAX_LIGHTMAPS_PER_SURFACE; ++map)
{
// we always create 4 (MAXLIGHTMAP) lightmaps.
// we always create 4 (MAX_LIGHTMAPS_PER_SURFACE) lightmaps.
// if surf has less (numMaps < 4), the remaining ones are zeroed out.
// this makes sure that all 4 lightmap textures in gl3state.lightmap_textureIDs[i] have the same layout
// and the shader can use the same texture coordinates for all of them
@ -462,15 +368,7 @@ GL3_BuildLightMap(msurface_t *surf, int offsetInLMbuf, int stride)
/* add all the lightmaps */
STUB_ONCE("TODO: handly dynamic lights (prolly somewhere else entirely)");
#if 0
/* add all the dynamic lights */
if (surf->dlightframe == gl3_framecount)
{
AddDynamicLights(surf);
}
#endif // 0
// Note: dynamic lights aren't handled here anymore, they're handled in the shader
// as we don't apply scale here anymore, nor blend the numMaps lightmaps together,
// the code has gotten a lot easier and we can copy directly from surf->samples to dest

View file

@ -38,7 +38,7 @@
#define DG_DYNARR_IMPLEMENTATION
#include "header/DG_dynarr.h"
// TODO: put this in local.h ?
#define REF_VERSION "Yamagi Quake II OpenGL3 Refresher"
refimport_t ri;
@ -68,8 +68,6 @@ vec3_t gl3_origin;
hmm_mat4 gl3_projectionMatrix; // eye cord -> clip coord
hmm_mat4 gl3_world_matrix; // the view matrix: world coord -> eye coord
// TODO: I don't know yet if we'll also need a model matrix (model coord -> world coord) here.
int gl3_visframecount; /* bumped when going to a new PVS */
int gl3_framecount; /* used for dlight push checking */
@ -837,7 +835,7 @@ GL3_DrawParticles(void)
part_vtx buf[numParticles];
// FIXME: viewOrg could be in UBO
// TODO: viewOrg could be in UBO
vec3_t viewOrg;
VectorCopy(gl3_newrefdef.vieworg, viewOrg);
@ -1133,7 +1131,6 @@ GL3_SetGL2D(void)
glDisable(GL_DEPTH_TEST);
glDisable(GL_CULL_FACE);
glDisable(GL_BLEND);
// glColor4f(1, 1, 1, 1); // FIXME: change to GL3 code!
}
// equivalent to R_x * R_y * R_z where R_x is the trans matrix for rotating around X axis for aroundXdeg
@ -1278,9 +1275,6 @@ SetupGL(void)
glDisable(GL_CULL_FACE);
}
STUB_ONCE("Should I do anything about disabling GL_BLEND and GL_ALPHA_TEST?");
//glDisable(GL_BLEND);
//glDisable(GL_ALPHA_TEST);
glEnable(GL_DEPTH_TEST);
}
@ -1409,15 +1403,11 @@ GL3_RenderView(refdef_t *fd)
gl3_newrefdef = *fd;
STUB_ONCE("TODO: Implement!");
if (!gl3_worldmodel && !(gl3_newrefdef.rdflags & RDF_NOWORLDMODEL))
{
ri.Sys_Error(ERR_DROP, "R_RenderView: NULL worldmodel");
}
if (gl_speeds->value)
{
c_brush_polys = 0;
@ -1634,7 +1624,6 @@ GL3_BeginFrame(float camera_separation)
}
// in GL3, overbrightbits can have any positive value
// TODO: rename to gl3_overbrightbits?
if (gl3_overbrightbits->modified)
{
gl3_overbrightbits->modified = false;
@ -1685,21 +1674,6 @@ GL3_BeginFrame(float camera_separation)
GL3_SetSwapInterval();
}
STUB_ONCE("TODO: texture-alpha/solid-mode stuff??")
#if 0
if (gl_texturealphamode->modified)
{
R_TextureAlphaMode(gl_texturealphamode->string);
gl_texturealphamode->modified = false;
}
if (gl_texturesolidmode->modified)
{
R_TextureSolidMode(gl_texturesolidmode->string);
gl_texturesolidmode->modified = false;
}
#endif // 0
/* clear screen if desired */
GL3_Clear();
}

View file

@ -309,10 +309,11 @@ DrawAliasFrameLerp(dmdl_t *paliashdr, float backlerp)
glBufferData(GL_ELEMENT_ARRAY_BUFFER, da_count(idxBuf)*sizeof(GLushort), idxBuf.p, GL_STREAM_DRAW);
glDrawElements(GL_TRIANGLES, da_count(idxBuf), GL_UNSIGNED_SHORT, NULL);
}
#if 0 // TODO: implemenet some time..
static void
DrawAliasShadow(dmdl_t *paliashdr, int posenum)
{
unsigned short total;
GLenum type;
int *order;
@ -325,7 +326,7 @@ DrawAliasShadow(dmdl_t *paliashdr, int posenum)
height = -lheight + 0.1f;
/* stencilbuffer shadows */
STUB_ONCE("TODO: OpenGL: *proper* stencil shadows!");
#if 0
if (have_stencil && gl_stencilshadow->value)
{
@ -377,7 +378,6 @@ DrawAliasShadow(dmdl_t *paliashdr, int posenum)
}
while (--count);
STUB_ONCE("TODO: OpenGL!");
#if 0
glEnableClientState( GL_VERTEX_ARRAY );
@ -391,10 +391,10 @@ DrawAliasShadow(dmdl_t *paliashdr, int posenum)
/* stencilbuffer shadows */
if (have_stencil && gl_stencilshadow->value)
{
STUB_ONCE("TODO: OpenGL: stencil shadows!");
//glDisable(GL_STENCIL_TEST);
}
}
#endif // 0
static qboolean
CullAliasModel(vec3_t bbox[8], entity_t *e)
@ -715,8 +715,6 @@ GL3_DrawAliasModel(entity_t *e)
/* locate the proper data */
c_alias_polys += paliashdr->num_tris;
/* draw all the triangles */
if (currententity->flags & RF_DEPTHHACK)
{
@ -776,14 +774,6 @@ GL3_DrawAliasModel(entity_t *e)
GL3_Bind(skin->texnum);
STUB_ONCE("TODO: OpenGL3 stuff (shade model, texenv)!");
#if 0
/* draw it */
glShadeModel(GL_SMOOTH);
R_TexEnv(GL_MODULATE);
#endif // 0
if (currententity->flags & RF_TRANSLUCENT)
{
glEnable(GL_BLEND);
@ -808,25 +798,12 @@ GL3_DrawAliasModel(entity_t *e)
currententity->oldframe = 0;
}
/* Fuck this, gl_lerpmodels 0 looks horrible anyway
if (!gl_lerpmodels->value)
{
currententity->backlerp = 0;
}
*/
DrawAliasFrameLerp(paliashdr, currententity->backlerp);
STUB_ONCE("TODO: even more OpenGL3 stuff!");
//R_TexEnv(GL_REPLACE);
//glShadeModel(GL_FLAT);
//glPopMatrix();
gl3state.uni3DData.transModelMat4 = origModelMat;
GL3_UpdateUBO3D();
if ((currententity->flags & RF_WEAPONMODEL) && (gl_lefthand->value == 1.0F))
{
gl3state.uni3DData.transProjMat4 = origProjMat;
@ -844,6 +821,7 @@ GL3_DrawAliasModel(entity_t *e)
glDepthRange(gl3depthmin, gl3depthmax);
}
STUB_ONCE("TODO: *proper* stencil shadows!")
#if 0
if (gl_shadows->value &&
!(currententity->flags & (RF_TRANSLUCENT | RF_WEAPONMODEL | RF_NOSHADOW)))

View file

@ -36,25 +36,15 @@ GL3_SetDefaultState(void)
glClearColor(1, 0, 0.5, 0.5);
glDisable(GL_MULTISAMPLE);
glCullFace(GL_FRONT);
//glEnable(GL_TEXTURE_2D);
// TODO: this must be done in shader instead,
// see https://www.khronos.org/opengl/wiki/Transparency_Sorting#Alpha_test
//glEnable(GL_ALPHA_TEST);
//glAlphaFunc(GL_GREATER, 0.666);
glDisable(GL_DEPTH_TEST);
glDisable(GL_CULL_FACE);
glDisable(GL_BLEND);
//glColor4f(1, 1, 1, 1);
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
//glShadeModel(GL_FLAT);
// TODO: gl_texturemode, gl_texturealphamode?
//GL3_TextureMode(gl_texturemode->string);
STUB("call GL3_TextureMode(gl_texturemode->string);");
STUB("Use gl_texturealphamode and somehow or only support one mode? => R_TextureAlphaMode(), R_TextureSolidMode()");
//R_TextureAlphaMode(gl_texturealphamode->string);
//R_TextureSolidMode(gl_texturesolidmode->string);
@ -66,7 +56,6 @@ GL3_SetDefaultState(void)
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
if (gl_msaa_samples->value)
{
glEnable(GL_MULTISAMPLE);

View file

@ -494,7 +494,7 @@ Mod_LoadFaces(lump_t *l)
Mod_CalcSurfaceExtents(out);
/* lighting info */
for (i = 0; i < MAXLIGHTMAPS; i++)
for (i = 0; i < MAX_LIGHTMAPS_PER_SURFACE; i++)
{
out->styles[i] = in->styles[i];
}

View file

@ -345,8 +345,6 @@ RenderBrushPoly(msurface_t *fa)
{
GL3_Bind(image->texnum);
STUB_ONCE("TODO: do something about inverse intensity on water surfaces b/c they have no lightmap!");
GL3_EmitWaterPolys(fa);
return;
@ -354,8 +352,6 @@ RenderBrushPoly(msurface_t *fa)
else
{
GL3_Bind(image->texnum);
// R_TexEnv(GL_REPLACE); TODO!
}
hmm_vec4 lmScales[MAX_LIGHTMAPS_PER_SURFACE] = {0};
@ -404,11 +400,6 @@ GL3_DrawAlphaSurfaces(void)
glEnable(GL_BLEND);
/* the textures are prescaled up for a better
lighting range, so scale it back down */
//flat intens = gl3state.inverse_intensity;
STUB_ONCE("Something about inverse intensity??");
for (s = gl3_alpha_surfaces; s != NULL; s = s->texturechain)
{
GL3_Bind(s->texinfo->image->texnum);
@ -487,9 +478,6 @@ DrawTextureChains(void)
}
// TODO: maybe one loop for normal faces and one for SURF_DRAWTURB ???
STUB_ONCE("TODO: do something about R_TexEnv()!");
// R_TexEnv(GL_REPLACE);
}
static void
@ -513,16 +501,6 @@ RenderLightmappedPoly(msurface_t *surf)
lmScales[map].A = 1.0f;
}
// Normal dynamic lights
if (surf->dlightframe == gl3_framecount)
{
if (gl_dynamic->value)
{
//is_dynamic = true;
STUB_ONCE("TODO: Handle dynamic lights!");
}
}
c_brush_polys++;
GL3_Bind(image->texnum);
@ -563,10 +541,8 @@ DrawInlineBModel(void)
if (currententity->flags & RF_TRANSLUCENT)
{
STUB_ONCE("TODO: implement for OpenGL3 (esp. the alpha 0.25 part in color?)");
glEnable(GL_BLEND);
/* TODO: if you change this, also do at the end of the function
glEnable(GL_BLEND);
/* TODO: should I care about the 0.25 part? we'll just set alpha to 0.33 or 0.66 depending on surface flag..
glColor4f(1, 1, 1, 0.25);
R_TexEnv(GL_MODULATE);
*/
@ -605,10 +581,6 @@ DrawInlineBModel(void)
if (currententity->flags & RF_TRANSLUCENT)
{
glDisable(GL_BLEND);
/*
glColor4f(1, 1, 1, 1);
R_TexEnv(GL_REPLACE);
*/
}
}
@ -625,7 +597,6 @@ GL3_DrawBrushModel(entity_t *e)
}
currententity = e;
//gl3state.currenttextures[0] = gl3state.currenttextures[1] = -1;
gl3state.currenttexture = -1;
if (e->angles[0] || e->angles[1] || e->angles[2])
@ -680,21 +651,6 @@ GL3_DrawBrushModel(entity_t *e)
e->angles[0] = -e->angles[0];
e->angles[2] = -e->angles[2];
STUB_ONCE("TODO: something about R_TexEnv() and gl_lightmap");
#if 0
R_TexEnv(GL_REPLACE);
if (gl_lightmap->value)
{
R_TexEnv(GL_REPLACE);
}
else
{
R_TexEnv(GL_MODULATE);
}
#endif // 0
DrawInlineBModel();
// glPopMatrix();
@ -874,9 +830,6 @@ GL3_DrawWorld(void)
gl3state.currenttexture = -1;
STUB_ONCE("somehow set color to 1,1,1,1 maybe");
//glColor4f(1, 1, 1, 1);
GL3_ClearSkyBox();
RecursiveWorldNode(gl3_worldmodel->nodes);
DrawTextureChains();

View file

@ -606,7 +606,7 @@ MakeSkyVec(float s, float t, int axis, gl3_3D_vtx_t* vert)
vec3_t v, b;
int j, k;
float dist = (gl_farsee->value == 0) ? 2300.0f : 4096.0f; // TODO: really dist?
float dist = (gl_farsee->value == 0) ? 2300.0f : 4096.0f;
b[0] = s * dist;
b[1] = t * dist;

View file

@ -181,7 +181,6 @@ enum {
typedef struct
{
// TODO: what of this do we need?
float inverse_intensity;
qboolean fullscreen;
int prev_mode;
@ -193,7 +192,6 @@ typedef struct
// most surfaces only have one really and the remaining for are filled with dummy data
GLuint lightmap_textureIDs[MAX_LIGHTMAPS][MAX_LIGHTMAPS_PER_SURFACE]; // instead of lightmap_textures+i use lightmap_textureIDs[i]
//int currenttextures[2];
GLuint currenttexture; // bound to GL_TEXTURE0
int currentlightmap; // lightmap_textureIDs[currentlightmap] bound to GL_TEXTURE1
GLuint currenttmu; // GL_TEXTURE0 or GL_TEXTURE1
@ -264,19 +262,17 @@ extern int c_brush_polys, c_alias_polys;
*/
typedef struct image_s
{
// TODO: what of this is actually needed?
char name[MAX_QPATH]; /* game path, including extension */
imagetype_t type;
int width, height; /* source image */
int upload_width, upload_height; /* after power of two and picmip */
//int upload_width, upload_height; /* after power of two and picmip */
int registration_sequence; /* 0 = free */
struct msurface_s *texturechain; /* for sort-by-texture world drawing */
GLuint texnum; /* gl texture binding */
float sl, tl, sh, th; /* 0,0 - 1,1 unless part of the scrap */
qboolean scrap;
// qboolean scrap; // currently unused
qboolean has_alpha;
//qboolean paletted;
} gl3image_t;
enum {MAX_GL3TEXTURES = 1024};

View file

@ -27,9 +27,6 @@
#ifndef SRC_CLIENT_REFRESH_GL3_HEADER_MODEL_H_
#define SRC_CLIENT_REFRESH_GL3_HEADER_MODEL_H_
// TODO: maybe lots of these things should get a gl3_ prefix and might
// need to be adapted and so on
enum {
SIDE_FRONT = 0,
SIDE_BACK = 1,
@ -41,9 +38,7 @@ enum {
SURF_DRAWSKY = 4,
SURF_DRAWTURB = 0x10,
SURF_DRAWBACKGROUND = 0x40,
SURF_UNDERWATER = 0x80,
//VERTEXSIZE = 7 - is 10 now, and I use a struct - TODO: REMOVE!
SURF_UNDERWATER = 0x80
};
// used for vertex array elements when drawing brushes, sprites, sky and more
@ -130,7 +125,7 @@ typedef struct msurface_s
int dlightbits;
int lightmaptexturenum;
byte styles[MAXLIGHTMAPS];
byte styles[MAXLIGHTMAPS]; // MAXLIGHTMAPS = MAX_LIGHTMAPS_PER_SURFACE (defined in local.h)
// I think cached_light is not used/needed anymore
//float cached_light[MAXLIGHTMAPS]; /* values currently used in lightmap */
byte *samples; /* [numstyles*surfsize] */