Skip to content

Commit

Permalink
Add transparent with alpha test surface support
Browse files Browse the repository at this point in the history
Based on surface flag from kmquake2 and rerelease documatation

https://github.com/id-Software/quake2-rerelease-dll#surf_alphatest-bit-25
  • Loading branch information
0lvin committed Oct 15, 2023
1 parent b4e78d0 commit 83a3197
Show file tree
Hide file tree
Showing 18 changed files with 72 additions and 39 deletions.
1 change: 0 additions & 1 deletion doc/100_tested_maps.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
## Quake2 ReRelease

Notes:
* mgu5m1: gl1,vk: non transparent flowers
* mgu5m2: server code: Too many models 256 (226 inline models)

| map | gl1.4 | gl3/gles3 | gl4.6 | vk | soft |
Expand Down
2 changes: 1 addition & 1 deletion src/client/refresh/files/light.c
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ R_BuildLightMap(const msurface_t *surf, byte *dest, int stride, const byte *dest
float *bl;

if (surf->texinfo->flags &
(SURF_SKY | SURF_TRANS33 | SURF_TRANS66 | SURF_WARP))
(SURF_SKY | SURF_TRANSPARENT | SURF_WARP))
{
Com_Error(ERR_DROP, "%s called for non-lit surface", __func__);
}
Expand Down
4 changes: 2 additions & 2 deletions src/client/refresh/gl1/gl1_model.c
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ Mod_LoadFaces(model_t *loadmodel, const byte *mod_base, const lump_t *l,
}

/* create lightmaps and polygons */
if (!(out->texinfo->flags & (SURF_SKY | SURF_TRANS33 | SURF_TRANS66 | SURF_WARP)))
if (!(out->texinfo->flags & (SURF_SKY | SURF_TRANSPARENT | SURF_WARP)))
{
LM_CreateSurfaceLightmap(out);
}
Expand Down Expand Up @@ -576,7 +576,7 @@ Mod_LoadQFaces(model_t *loadmodel, const byte *mod_base, const lump_t *l,
}

/* create lightmaps and polygons */
if (!(out->texinfo->flags & (SURF_SKY | SURF_TRANS33 | SURF_TRANS66 | SURF_WARP)))
if (!(out->texinfo->flags & (SURF_SKY | SURF_TRANSPARENT | SURF_WARP)))
{
LM_CreateSurfaceLightmap(out);
}
Expand Down
11 changes: 7 additions & 4 deletions src/client/refresh/gl1/gl1_surf.c
Original file line number Diff line number Diff line change
Expand Up @@ -489,8 +489,7 @@ R_RenderBrushPoly(entity_t *currententity, msurface_t *fa)
if (r_dynamic->value)
{
if (!(fa->texinfo->flags &
(SURF_SKY | SURF_TRANS33 |
SURF_TRANS66 | SURF_WARP)))
(SURF_SKY | SURF_TRANSPARENT | SURF_WARP)))
{
is_dynamic = true;
}
Expand Down Expand Up @@ -573,6 +572,10 @@ R_DrawAlphaSurfaces(void)
{
glColor4f(intens, intens, intens, 0.66);
}
else if (s->texinfo->flags & SURF_ALPHATEST)
{
glColor4f(intens, intens, intens, 0.99);
}
else
{
glColor4f(intens, intens, intens, 1);
Expand Down Expand Up @@ -672,7 +675,7 @@ R_DrawInlineBModel(entity_t *currententity, const model_t *currentmodel)
if (((psurf->flags & SURF_PLANEBACK) && (dot < -BACKFACE_EPSILON)) ||
(!(psurf->flags & SURF_PLANEBACK) && (dot > BACKFACE_EPSILON)))
{
if (psurf->texinfo->flags & (SURF_TRANS33 | SURF_TRANS66))
if (psurf->texinfo->flags & SURF_TRANSPARENT)
{
/* add to the translucent chain */
psurf->texturechain = r_alpha_surfaces;
Expand Down Expand Up @@ -897,7 +900,7 @@ R_RecursiveWorldNode(entity_t *currententity, mnode_t *node)
/* just adds to visible sky bounds */
RE_AddSkySurface(surf);
}
else if (surf->texinfo->flags & (SURF_TRANS33 | SURF_TRANS66))
else if (surf->texinfo->flags & SURF_TRANSPARENT)
{
/* add to the translucent chain */
surf->texturechain = r_alpha_surfaces;
Expand Down
2 changes: 1 addition & 1 deletion src/client/refresh/gl3/gl3_light.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ GL3_BuildLightMap(msurface_t *surf, int offsetInLMbuf, int stride)
byte *lightmap;

if (surf->texinfo->flags &
(SURF_SKY | SURF_TRANS33 | SURF_TRANS66 | SURF_WARP))
(SURF_SKY | SURF_TRANSPARENT | SURF_WARP))
{
Com_Error(ERR_DROP, "GL3_BuildLightMap called for non-lit surface");
}
Expand Down
4 changes: 2 additions & 2 deletions src/client/refresh/gl3/gl3_model.c
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ Mod_LoadFaces(gl3model_t *loadmodel, const byte *mod_base, const lump_t *l,
}

/* create lightmaps and polygons */
if (!(out->texinfo->flags & (SURF_SKY | SURF_TRANS33 | SURF_TRANS66 | SURF_WARP)))
if (!(out->texinfo->flags & (SURF_SKY | SURF_TRANSPARENT | SURF_WARP)))
{
GL3_LM_CreateSurfaceLightmap(out);
}
Expand Down Expand Up @@ -539,7 +539,7 @@ Mod_LoadQFaces(gl3model_t *loadmodel, const byte *mod_base, const lump_t *l,
}

/* create lightmaps and polygons */
if (!(out->texinfo->flags & (SURF_SKY | SURF_TRANS33 | SURF_TRANS66 | SURF_WARP)))
if (!(out->texinfo->flags & (SURF_SKY | SURF_TRANSPARENT | SURF_WARP)))
{
GL3_LM_CreateSurfaceLightmap(out);
}
Expand Down
10 changes: 7 additions & 3 deletions src/client/refresh/gl3/gl3_surf.c
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,10 @@ GL3_DrawAlphaSurfaces(void)
{
alpha = 0.666f;
}
else if (s->texinfo->flags & SURF_ALPHATEST)
{
alpha = 0.999f;
}
if(alpha != gl3state.uni3DData.alpha)
{
gl3state.uni3DData.alpha = alpha;
Expand Down Expand Up @@ -446,7 +450,7 @@ RenderLightmappedPoly(entity_t *currententity, msurface_t *surf)
hmm_vec4 lmScales[MAX_LIGHTMAPS_PER_SURFACE] = {0};
lmScales[0] = HMM_Vec4(1.0f, 1.0f, 1.0f, 1.0f);

assert((surf->texinfo->flags & (SURF_SKY | SURF_TRANS33 | SURF_TRANS66 | SURF_WARP)) == 0
assert((surf->texinfo->flags & (SURF_SKY | SURF_TRANSPARENT | SURF_WARP)) == 0
&& "RenderLightMappedPoly mustn't be called with transparent, sky or warping surfaces!");

// Any dynamic lights on this surface?
Expand Down Expand Up @@ -512,7 +516,7 @@ DrawInlineBModel(entity_t *currententity, gl3model_t *currentmodel)
if (((psurf->flags & SURF_PLANEBACK) && (dot < -BACKFACE_EPSILON)) ||
(!(psurf->flags & SURF_PLANEBACK) && (dot > BACKFACE_EPSILON)))
{
if (psurf->texinfo->flags & (SURF_TRANS33 | SURF_TRANS66))
if (psurf->texinfo->flags & SURF_TRANSPARENT)
{
/* add to the translucent chain */
psurf->texturechain = gl3_alpha_surfaces;
Expand Down Expand Up @@ -725,7 +729,7 @@ RecursiveWorldNode(entity_t *currententity, mnode_t *node)
/* just adds to visible sky bounds */
RE_AddSkySurface(surf);
}
else if (surf->texinfo->flags & (SURF_TRANS33 | SURF_TRANS66))
else if (surf->texinfo->flags & SURF_TRANSPARENT)
{
/* add to the translucent chain */
surf->texturechain = gl3_alpha_surfaces;
Expand Down
2 changes: 1 addition & 1 deletion src/client/refresh/gl4/gl4_light.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ GL4_BuildLightMap(msurface_t *surf, int offsetInLMbuf, int stride)
byte *lightmap;

if (surf->texinfo->flags &
(SURF_SKY | SURF_TRANS33 | SURF_TRANS66 | SURF_WARP))
(SURF_SKY | SURF_TRANSPARENT | SURF_WARP))
{
Com_Error(ERR_DROP, "GL4_BuildLightMap called for non-lit surface");
}
Expand Down
4 changes: 2 additions & 2 deletions src/client/refresh/gl4/gl4_model.c
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ Mod_LoadFaces(gl4model_t *loadmodel, const byte *mod_base, const lump_t *l,
}

/* create lightmaps and polygons */
if (!(out->texinfo->flags & (SURF_SKY | SURF_TRANS33 | SURF_TRANS66 | SURF_WARP)))
if (!(out->texinfo->flags & (SURF_SKY | SURF_TRANSPARENT | SURF_WARP)))
{
GL4_LM_CreateSurfaceLightmap(out);
}
Expand Down Expand Up @@ -537,7 +537,7 @@ Mod_LoadQFaces(gl4model_t *loadmodel, const byte *mod_base, const lump_t *l,
}

/* create lightmaps and polygons */
if (!(out->texinfo->flags & (SURF_SKY | SURF_TRANS33 | SURF_TRANS66 | SURF_WARP)))
if (!(out->texinfo->flags & (SURF_SKY | SURF_TRANSPARENT | SURF_WARP)))
{
GL4_LM_CreateSurfaceLightmap(out);
}
Expand Down
11 changes: 8 additions & 3 deletions src/client/refresh/gl4/gl4_surf.c
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,11 @@ GL4_DrawAlphaSurfaces(void)
{
alpha = 0.666f;
}
else if (s->texinfo->flags & SURF_ALPHATEST)
{
alpha = 0.999f;
}

if(alpha != gl4state.uni3DData.alpha)
{
gl4state.uni3DData.alpha = alpha;
Expand Down Expand Up @@ -446,7 +451,7 @@ RenderLightmappedPoly(entity_t *currententity, msurface_t *surf)
hmm_vec4 lmScales[MAX_LIGHTMAPS_PER_SURFACE] = {0};
lmScales[0] = HMM_Vec4(1.0f, 1.0f, 1.0f, 1.0f);

assert((surf->texinfo->flags & (SURF_SKY | SURF_TRANS33 | SURF_TRANS66 | SURF_WARP)) == 0
assert((surf->texinfo->flags & (SURF_SKY | SURF_TRANSPARENT | SURF_WARP)) == 0
&& "RenderLightMappedPoly mustn't be called with transparent, sky or warping surfaces!");

// Any dynamic lights on this surface?
Expand Down Expand Up @@ -511,7 +516,7 @@ DrawInlineBModel(entity_t *currententity, gl4model_t *currentmodel)
if (((psurf->flags & SURF_PLANEBACK) && (dot < -BACKFACE_EPSILON)) ||
(!(psurf->flags & SURF_PLANEBACK) && (dot > BACKFACE_EPSILON)))
{
if (psurf->texinfo->flags & (SURF_TRANS33 | SURF_TRANS66))
if (psurf->texinfo->flags & SURF_TRANSPARENT)
{
/* add to the translucent chain */
psurf->texturechain = gl4_alpha_surfaces;
Expand Down Expand Up @@ -724,7 +729,7 @@ RecursiveWorldNode(entity_t *currententity, mnode_t *node)
/* just adds to visible sky bounds */
GL4_AddSkySurface(surf);
}
else if (surf->texinfo->flags & (SURF_TRANS33 | SURF_TRANS66))
else if (surf->texinfo->flags & SURF_TRANSPARENT)
{
/* add to the translucent chain */
surf->texturechain = gl4_alpha_surfaces;
Expand Down
2 changes: 1 addition & 1 deletion src/client/refresh/soft/sw_bsp.c
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ R_DrawSolidClippedSubmodelPolygons(entity_t *currententity, const model_t *curre

pbedge[j-1].pnext = NULL; // mark end of edges

if ( !( psurf->texinfo->flags & ( SURF_TRANS66 | SURF_TRANS33 ) ))
if ( !( psurf->texinfo->flags & SURF_TRANSPARENT ))
{
// FIXME: Fan broken in borehole
// teleport: 1231.000000 770.250000 -579.375000
Expand Down
4 changes: 2 additions & 2 deletions src/client/refresh/soft/sw_poly.c
Original file line number Diff line number Diff line change
Expand Up @@ -1236,9 +1236,9 @@ R_DrawAlphaSurfaces(const entity_t *currententity)

// pass down all the texinfo flags, not just SURF_WARP.
if (s->texinfo->flags & SURF_TRANS66)
R_ClipAndDrawPoly( 0.60f, (s->texinfo->flags & (SURF_WARP|SURF_FLOWING)), true );
R_ClipAndDrawPoly( 0.60f, (s->texinfo->flags & (SURF_WARP | SURF_FLOWING)), true );
else
R_ClipAndDrawPoly( 0.30f, (s->texinfo->flags & (SURF_WARP|SURF_FLOWING)), true );
R_ClipAndDrawPoly( 0.30f, (s->texinfo->flags & (SURF_WARP | SURF_FLOWING)), true );

s = s->nextalphasurface;
}
Expand Down
4 changes: 2 additions & 2 deletions src/client/refresh/soft/sw_rast.c
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ R_RenderFace (entity_t *currententity, const model_t *currentmodel, msurface_t *
qboolean r_nearzionly;

// translucent surfaces are not drawn by the edge renderer
if (fa->texinfo->flags & (SURF_TRANS33|SURF_TRANS66))
if (fa->texinfo->flags & SURF_TRANSPARENT)
{
fa->nextalphasurface = r_alpha_surfaces;
r_alpha_surfaces = fa;
Expand Down Expand Up @@ -756,7 +756,7 @@ R_RenderBmodelFace(entity_t *currententity, bedge_t *pedges, msurface_t *psurf,
qboolean makeleftedge, makerightedge;
qboolean r_nearzionly;

if (psurf->texinfo->flags & (SURF_TRANS33|SURF_TRANS66))
if (psurf->texinfo->flags & SURF_TRANSPARENT)
{
psurf->nextalphasurface = r_alpha_surfaces;
r_alpha_surfaces = psurf;
Expand Down
30 changes: 22 additions & 8 deletions src/client/refresh/soft/sw_surf.c
Original file line number Diff line number Diff line change
Expand Up @@ -261,18 +261,22 @@ void
R_InitCaches (void)
{
int size;

// calculate size to allocate
int pix;

// surface cache size at 320X240
size = 1024*768;

pix = vid_buffer_width*vid_buffer_height;
if (pix > 64000)
size += (pix-64000)*3;
{
size += (pix - 64000) * 3;
}

if (r_farsee->value > 0)
{
size *= 2;
}

if (sw_surfcacheoverride->value > size)
{
Expand All @@ -299,7 +303,6 @@ R_InitCaches (void)
sc_base->size = sc_size;
}


/*
==================
D_FlushCaches
Expand Down Expand Up @@ -331,7 +334,7 @@ D_SCAlloc
=================
*/
static surfcache_t *
D_SCAlloc (int width, int size)
D_SCAlloc(int width, int size)
{
surfcache_t *new;

Expand All @@ -345,35 +348,41 @@ D_SCAlloc (int width, int size)
Com_Error(ERR_FATAL, "%s: bad cache size %d\n", __func__, size);
}

// Add header size
/* Add header size */
size += ((char*)sc_base->data - (char*)sc_base);
size = (size + 3) & ~3;
if (size > sc_size)
{
Com_Error(ERR_FATAL, "%s: %i > cache size of %i", __func__, size, sc_size);
}

// if there is not size bytes after the rover, reset to the start
/* if there is not size bytes after the rover, reset to the start */
if ( !sc_rover || (byte *)sc_rover - (byte *)sc_base > sc_size - size)
{
sc_rover = sc_base;
}

// colect and free surfcache_t blocks until the rover block is large enough
/* colect and free surfcache_t blocks until the rover block is large enough */
new = sc_rover;
if (sc_rover->owner)
{
*sc_rover->owner = NULL;
}

while (new->size < size)
{
// free another
/* free another */
sc_rover = sc_rover->next;

if (!sc_rover)
{
Com_Error(ERR_FATAL, "%s: hit the end of memory", __func__);
}

if (sc_rover->owner)
{
*sc_rover->owner = NULL;
}

new->size += sc_rover->size;
new->next = sc_rover->next;
Expand All @@ -391,12 +400,17 @@ D_SCAlloc (int width, int size)
new->size = size;
}
else
{
sc_rover = new->next;
}

new->width = width;

// DEBUG
if (width > 0)
{
new->height = (size - sizeof(*new) + sizeof(new->data)) / width;
}

new->owner = NULL; // should be set properly after return

Expand Down
4 changes: 2 additions & 2 deletions src/client/refresh/vk/vk_model.c
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ Mod_LoadFaces(model_t *loadmodel, const byte *mod_base, const lump_t *l,
}

/* create lightmaps and polygons */
if (!(out->texinfo->flags & (SURF_SKY | SURF_TRANS33 | SURF_TRANS66 | SURF_WARP)))
if (!(out->texinfo->flags & (SURF_SKY | SURF_TRANSPARENT | SURF_WARP)))
{
Vk_CreateSurfaceLightmap(out);
}
Expand Down Expand Up @@ -546,7 +546,7 @@ Mod_LoadQFaces(model_t *loadmodel, const byte *mod_base, const lump_t *l,
}

/* create lightmaps and polygons */
if (!(out->texinfo->flags & (SURF_SKY | SURF_TRANS33 | SURF_TRANS66 | SURF_WARP)))
if (!(out->texinfo->flags & (SURF_SKY | SURF_TRANSPARENT | SURF_WARP)))
{
Vk_CreateSurfaceLightmap(out);
}
Expand Down

0 comments on commit 83a3197

Please sign in to comment.