Skip to content

Commit

Permalink
Merge pull request #991 from qw-ctf/various-fixes
Browse files Browse the repository at this point in the history
RENDERER: Various fixes.
  • Loading branch information
dsvensson authored Jan 10, 2025
2 parents 1e0482b + 31b12b9 commit 32bf773
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 44 deletions.
4 changes: 2 additions & 2 deletions src/glm_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ typedef struct uniform_block_frame_constants_s {
float skySpeedscale;
float skySpeedscale2;
float r_farclip_unused; // NO LONGER USED, replace
float waterAlpha;
float padding;

// animated skybox
vec3_t windDir;
Expand Down Expand Up @@ -97,7 +97,7 @@ typedef struct uniform_block_world_calldata_s {
float alpha;
int samplerBase;
int flags;
int padding;
int sampler;
} uniform_block_world_calldata_t;

typedef struct uniform_block_sprite_s {
Expand Down
2 changes: 0 additions & 2 deletions src/glm_misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,6 @@ void GLM_PreRenderView(void)
frameConstants.skySpeedscale2 -= (int)frameConstants.skySpeedscale2 & ~127;
frameConstants.skySpeedscale2 /= 128.0f;

frameConstants.waterAlpha = R_WaterAlpha();

frameConstants.r_drawflat = r_drawflat.integer;
PASS_COLOR_AS_4F(frameConstants.r_wallcolor, r_wallcolor);
PASS_COLOR_AS_4F(frameConstants.r_floorcolor, r_floorcolor);
Expand Down
43 changes: 17 additions & 26 deletions src/glm_rsurf.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

#define GLM_DRAWCALL_INCREMENT 8

void GL_StartWaterSurfaceBatch(void);

static GLuint index_count;

typedef struct glm_worldmodel_req_s {
Expand Down Expand Up @@ -83,7 +81,7 @@ typedef struct glm_brushmodel_drawcall_s {
struct glm_brushmodel_drawcall_s* next;
} glm_brushmodel_drawcall_t;

static glm_brushmodel_drawcall_t* GL_FlushWorldModelBatch(void);
static glm_brushmodel_drawcall_t* GL_PrepareWorldModelBatch(glm_brushmodel_drawcall_type type);
static void GL_SortDrawCalls(glm_brushmodel_drawcall_t* drawcall);

static glm_brushmodel_drawcall_t* drawcalls;
Expand Down Expand Up @@ -329,7 +327,7 @@ static qbool GLM_AssignTexture(int texture_num, texture_t* texture)

if (sampler < 0) {
if (drawcall->material_samplers >= material_samplers_max) {
drawcall = GL_FlushWorldModelBatch();
drawcall = GL_PrepareWorldModelBatch(drawcall->type);
}

sampler = drawcall->material_samplers++;
Expand Down Expand Up @@ -399,8 +397,7 @@ static glm_worldmodel_req_t* GLM_NextBatchRequest(model_t* model, float alpha, i
}

if (drawcall->type != desired_type) {
drawcall = GL_FlushWorldModelBatch();
drawcall->type = desired_type;
drawcall = GL_PrepareWorldModelBatch(desired_type);
}
else if (drawcall->batch_count && drawcall->type == opaque_world) {
// See if previous request has same texture & matrix, if so just continue
Expand Down Expand Up @@ -444,7 +441,7 @@ static glm_worldmodel_req_t* GLM_NextBatchRequest(model_t* model, float alpha, i
}

if (drawcall->sampler_mappings >= MAX_SAMPLER_MAPPINGS || drawcall->batch_count >= MAX_WORLDMODEL_BATCH) {
drawcall = GL_FlushWorldModelBatch();
drawcall = GL_PrepareWorldModelBatch(drawcall->type);
}

req = &drawcall->worldmodel_requests[drawcall->batch_count];
Expand Down Expand Up @@ -489,7 +486,6 @@ void GLM_DrawWaterSurfaces(void)
// Waterchain has list of alpha-blended surfaces
R_TraceEnterNamedRegion(__func__);

GL_StartWaterSurfaceBatch();
for (surf = waterchain; surf; surf = surf->texturechain) {
glpoly_t* poly;
texture_t* tex = R_TextureAnimation(NULL, surf->texinfo->texture);
Expand Down Expand Up @@ -594,29 +590,27 @@ qbool GLM_CompileSimple3dProgram(void)
return R_ProgramReady(r_program_simple3d) && GLM_CompilePostProcessVAO();
}

static glm_brushmodel_drawcall_t* GL_FlushWorldModelBatch(void)
static glm_brushmodel_drawcall_t* GL_PrepareWorldModelBatch(glm_brushmodel_drawcall_type type)
{
const glm_brushmodel_drawcall_t* prev;
glm_brushmodel_drawcall_t* prev = &drawcalls[current_drawcall];
glm_brushmodel_drawcall_t* current;
int last = current_drawcall++;

if (prev->batch_count == 0) {
prev->type = type;
return prev;
}

current_drawcall++;

GLM_CheckDrawCallSize();

prev = &drawcalls[last];
current = &drawcalls[current_drawcall];

memset(current, 0, sizeof(*current));
current->type = prev->type;
current->type = type;
return current;
}

void GL_StartWaterSurfaceBatch(void)
{
GL_FlushWorldModelBatch();

drawcalls[current_drawcall].type = alpha_surfaces;
}

void GLM_PrepareWorldModelBatch(void)
{
GLintptr drawOffset = 0;
Expand Down Expand Up @@ -666,27 +660,23 @@ void GLM_PrepareWorldModelBatch(void)
static void GLM_DrawWorldExecuteCalls(glm_brushmodel_drawcall_t* drawcall, uintptr_t offset, int begin, int count)
{
int i;
int prevSampler = -1;
qbool prev_alphaTested = false;

for (i = begin; i < begin + count; ++i) {
glm_worldmodel_req_t* req = &drawcall->worldmodel_requests[i];
int sampler = req->nonDynamicSampler;
int batchCount = 1;

if (prevSampler != sampler || req->isAlphaTested != prev_alphaTested) {
if (req->isAlphaTested != prev_alphaTested) {
if (req->isAlphaTested) {
R_ProgramUse(r_program_brushmodel_alphatested);
R_ProgramUniform1i(r_program_uniform_brushmodel_alphatested_sampler, prevSampler = sampler);
}
else {
R_ProgramUse(r_program_brushmodel);
R_ProgramUniform1i(r_program_uniform_brushmodel_sampler, prevSampler = sampler);
}
prev_alphaTested = req->isAlphaTested;
}

while (i + batchCount < begin + count && drawcall->worldmodel_requests[i + batchCount].nonDynamicSampler == sampler && drawcall->worldmodel_requests[i + batchCount].isAlphaTested == req->isAlphaTested) {
while (i + batchCount < begin + count && drawcall->worldmodel_requests[i + batchCount].isAlphaTested == req->isAlphaTested) {
++batchCount;
}

Expand Down Expand Up @@ -862,6 +852,7 @@ static void GL_SortDrawCalls(glm_brushmodel_drawcall_t* drawcall)
drawcall->calls[i].flags = thisReq->flags;
memcpy(drawcall->calls[i].modelMatrix, thisReq->mvMatrix, sizeof(drawcall->calls[i].modelMatrix));
drawcall->calls[i].samplerBase = thisReq->samplerMappingBase;
drawcall->calls[i].sampler = thisReq->nonDynamicSampler;
thisReq->baseInstance = i;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/glsl/common.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ layout(std140, binding=EZQ_GL_BINDINGPOINT_FRAMECONSTANTS) uniform GlobalState {
float skySpeedscale;
float skySpeedscale2;
float r_farclip_unused; // Replace
float waterAlpha;
float padding;

// animated skybox
vec4 skyWind;
Expand Down Expand Up @@ -82,7 +82,7 @@ struct WorldDrawInfo {
float alpha;
int samplerBase;
int drawFlags;
int padding;
int sampler;
};

struct SamplerMapping {
Expand Down
14 changes: 7 additions & 7 deletions src/glsl/draw_world.fragment.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ in vec3 LumaCoord;
#endif
in vec3 FlatColor;
in flat int Flags;
uniform int SamplerNumber;
in vec3 Direction;
#ifdef DRAW_GEOMETRY
in vec3 Normal;
Expand All @@ -46,6 +45,7 @@ in vec4 UnClipped;
in float mix_floor;
in float mix_wall;
in float alpha;
in flat int SamplerNumber;

layout(location=0) out vec4 frag_colour;
#ifdef DRAW_GEOMETRY
Expand Down Expand Up @@ -149,19 +149,19 @@ void main()
// Turb surface
if (turbType != TEXTURE_TURB_SKY && r_fastturb != 0) {
if (turbType == TEXTURE_TURB_WATER) {
frag_colour = r_watercolor * waterAlpha;
frag_colour = r_watercolor * alpha;
}
else if (turbType == TEXTURE_TURB_SLIME) {
frag_colour = r_slimecolor * waterAlpha;
frag_colour = r_slimecolor * alpha;
}
else if (turbType == TEXTURE_TURB_LAVA) {
frag_colour = r_lavacolor * waterAlpha;
frag_colour = r_lavacolor * alpha;
}
else if (turbType == TEXTURE_TURB_TELE) {
frag_colour = r_telecolor * waterAlpha;
frag_colour = r_telecolor * alpha;
}
else {
frag_colour = vec4(FlatColor * waterAlpha, waterAlpha);
frag_colour = vec4(FlatColor * alpha, alpha);
}
#ifdef DRAW_FOG
frag_colour = applyFog(frag_colour, gl_FragCoord.z / gl_FragCoord.w);
Expand Down Expand Up @@ -201,7 +201,7 @@ void main()
#endif
}
else {
frag_colour = texColor * waterAlpha;
frag_colour = texColor * alpha;
if ((Flags & EZQ_SURFACE_LIT_TURB) > 0) {
frag_colour = vec4(lmColor.rgb, 1) * frag_colour;
}
Expand Down
2 changes: 2 additions & 0 deletions src/glsl/draw_world.vertex.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ layout(std140, binding = EZQ_GL_BINDINGPOINT_WORLDMODEL_SURFACES) buffer surface
out float mix_floor;
out float mix_wall;
out float alpha;
out flat int SamplerNumber;

layout(std140, binding=EZQ_GL_BINDINGPOINT_BRUSHMODEL_DRAWDATA) buffer WorldCvars {
WorldDrawInfo drawInfo[];
Expand All @@ -53,6 +54,7 @@ void main()
int drawCallFlags = drawInfo[_instanceId].drawFlags;
int textureFlags = samplerMapping[drawInfo[_instanceId].samplerBase + materialNumber].flags;
alpha = drawInfo[_instanceId].alpha;
SamplerNumber = drawInfo[_instanceId].sampler;

gl_Position = projectionMatrix * drawInfo[_instanceId].mvMatrix * vec4(position, 1.0);
#ifdef DRAW_GEOMETRY
Expand Down
2 changes: 1 addition & 1 deletion src/glsl/glc/glc_draw_sprites.fragment.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ void main()
gl_FragColor = texture2D(materialSampler, TextureCoord) * fsColor;

#ifdef DRAW_FOG
gl_FragColor = applyFog(gl_FragColor, gl_FragCoord.z / gl_FragCoord.w);
gl_FragColor = applyFogBlend(gl_FragColor, gl_FragCoord.z / gl_FragCoord.w);
#endif
}
2 changes: 2 additions & 0 deletions src/glsl/glc/glc_world_textured.fragment.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ void main()
if (gl_FragColor.a < 0.333) {
discard;
}

gl_FragColor = vec4(gl_FragColor.rgb, 1.0);
#endif

#ifdef DRAW_EXTRA_TEXTURES
Expand Down
9 changes: 5 additions & 4 deletions src/r_rmain.c
Original file line number Diff line number Diff line change
Expand Up @@ -897,9 +897,6 @@ void R_RenderView(void)
// Adds 3d effects (particles, lights, chat icons etc)
R_Render3DEffects();

// Draws transparent world surfaces
renderer.DrawWaterSurfaces();

// Render billboards
renderer.Draw3DSpritesInline();

Expand Down Expand Up @@ -1064,7 +1061,7 @@ static void R_DrawEntitiesOnList(visentlist_t *vislist, visentlist_entrytype_t t
{
int i;

if (r_drawentities.integer && vislist->typecount[type] >= 0) {
if (r_drawentities.integer && vislist->typecount[type] > 0) {
for (i = 0; i < vislist->count; i++) {
visentity_t* todraw = &vislist->list[i];

Expand Down Expand Up @@ -1143,6 +1140,10 @@ static void R_DrawEntities(void)
R_Sprite3DInitialiseBatch(SPRITE3D_ENTITIES, r_state_sprites_textured, null_texture_reference, 0, r_primitive_triangle_strip);
qsort(cl_visents.list, cl_visents.count, sizeof(cl_visents.list[0]), R_DrawEntitiesSorter);
for (ent_type = 0; ent_type < visent_max; ++ent_type) {
if (ent_type == visent_alpha) {
// Transluscent before translucent entities, but after opaque ones.
renderer.DrawWaterSurfaces();
}
R_DrawEntitiesOnList(&cl_visents, ent_type);
}
if (R_UseModernOpenGL() || R_UseVulkan()) {
Expand Down

0 comments on commit 32bf773

Please sign in to comment.