Skip to content

Commit

Permalink
gfx: fix wireframe mode not working in tr2 title screen
Browse files Browse the repository at this point in the history
  • Loading branch information
rr- committed Dec 11, 2024
1 parent 4d2bf3f commit c1191a2
Showing 1 changed file with 32 additions and 24 deletions.
56 changes: 32 additions & 24 deletions src/libtrx/gfx/3d/3d_renderer.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,20 @@ struct GFX_3D_RENDERER {
GLint loc_color_key_enabled;
};

static void M_Flush(GFX_3D_RENDERER *renderer);
static void M_SelectTextureImpl(GFX_3D_RENDERER *renderer, int texture_num);
static void M_RestoreTexture(GFX_3D_RENDERER *renderer);

static void M_Flush(GFX_3D_RENDERER *const renderer)
{
glLineWidth(renderer->config->line_width);
glPolygonMode(
GL_FRONT_AND_BACK,
renderer->config->enable_wireframe ? GL_LINE : GL_FILL);
GFX_GL_CheckError();

GFX_3D_VertexStream_RenderPending(&renderer->vertex_stream);
}

static void M_SelectTextureImpl(
GFX_3D_RENDERER *const renderer, const int texture_num)
Expand Down Expand Up @@ -113,8 +126,6 @@ GFX_3D_RENDERER *GFX_3D_Renderer_Create(void)
&model_view[0][0]);

GFX_3D_VertexStream_Init(&renderer->vertex_stream);
GFX_GL_CheckError();

return renderer;
}

Expand All @@ -134,12 +145,6 @@ void GFX_3D_Renderer_RenderBegin(GFX_3D_RENDERER *const renderer)
ASSERT(renderer != NULL);
glEnable(GL_BLEND);

glLineWidth(renderer->config->line_width);
glPolygonMode(
GL_FRONT_AND_BACK,
renderer->config->enable_wireframe ? GL_LINE : GL_FILL);
GFX_GL_CheckError();

renderer->vertex_stream.rendered_count = 0;

GFX_GL_Program_Bind(&renderer->program);
Expand Down Expand Up @@ -173,14 +178,13 @@ void GFX_3D_Renderer_RenderBegin(GFX_3D_RENDERER *const renderer)
void GFX_3D_Renderer_RenderEnd(GFX_3D_RENDERER *const renderer)
{
ASSERT(renderer != NULL);
GFX_3D_VertexStream_RenderPending(&renderer->vertex_stream);

GFX_GL_CheckError();
M_Flush(renderer);
}

void GFX_3D_Renderer_ClearDepth(GFX_3D_RENDERER *const renderer)
{
GFX_3D_VertexStream_RenderPending(&renderer->vertex_stream);
ASSERT(renderer != NULL);
M_Flush(renderer);
glClear(GL_DEPTH_BUFFER_BIT);
GFX_GL_CheckError();
}
Expand All @@ -194,7 +198,6 @@ int GFX_3D_Renderer_RegisterEnvironmentMap(GFX_3D_RENDERER *const renderer)
renderer->env_map_texture = texture;

M_RestoreTexture(renderer);
GFX_GL_CheckError();
return GFX_ENV_MAP_TEXTURE;
}

Expand Down Expand Up @@ -231,7 +234,7 @@ void GFX_3D_Renderer_FillEnvironmentMap(GFX_3D_RENDERER *const renderer)

GFX_GL_TEXTURE *const env_map = renderer->env_map_texture;
if (env_map != NULL) {
GFX_3D_VertexStream_RenderPending(&renderer->vertex_stream);
M_Flush(renderer);
GFX_GL_Texture_LoadFromBackBuffer(env_map);
M_RestoreTexture(renderer);
}
Expand All @@ -257,7 +260,6 @@ int GFX_3D_Renderer_RegisterTexturePage(

M_RestoreTexture(renderer);

GFX_GL_CheckError();
return texture_num;
}

Expand Down Expand Up @@ -317,7 +319,7 @@ void GFX_3D_Renderer_SelectTexture(
GFX_3D_RENDERER *const renderer, int texture_num)
{
ASSERT(renderer != NULL);
GFX_3D_VertexStream_RenderPending(&renderer->vertex_stream);
M_Flush(renderer);
renderer->selected_texture_num = texture_num;
M_SelectTextureImpl(renderer, texture_num);
}
Expand All @@ -326,15 +328,15 @@ void GFX_3D_Renderer_SetPrimType(
GFX_3D_RENDERER *const renderer, GFX_3D_PRIM_TYPE value)
{
ASSERT(renderer != NULL);
GFX_3D_VertexStream_RenderPending(&renderer->vertex_stream);
M_Flush(renderer);
GFX_3D_VertexStream_SetPrimType(&renderer->vertex_stream, value);
}

void GFX_3D_Renderer_SetTextureFilter(
GFX_3D_RENDERER *const renderer, GFX_TEXTURE_FILTER filter)
{
ASSERT(renderer != NULL);
GFX_3D_VertexStream_RenderPending(&renderer->vertex_stream);
M_Flush(renderer);
GFX_GL_Sampler_Parameteri(
&renderer->sampler, GL_TEXTURE_MAG_FILTER,
filter == GFX_TF_BILINEAR ? GL_LINEAR : GL_NEAREST);
Expand All @@ -351,28 +353,31 @@ void GFX_3D_Renderer_SetDepthWritesEnabled(
GFX_3D_RENDERER *const renderer, const bool is_enabled)
{
ASSERT(renderer != NULL);
GFX_3D_VertexStream_RenderPending(&renderer->vertex_stream);
M_Flush(renderer);
glDepthMask(is_enabled ? GL_TRUE : GL_FALSE);
GFX_GL_CheckError();
}

void GFX_3D_Renderer_SetDepthTestEnabled(
GFX_3D_RENDERER *const renderer, const bool is_enabled)
{
ASSERT(renderer != NULL);
GFX_3D_VertexStream_RenderPending(&renderer->vertex_stream);
M_Flush(renderer);
if (is_enabled) {
glEnable(GL_DEPTH_TEST);
} else {
glDisable(GL_DEPTH_TEST);
}
GFX_GL_CheckError();
}

void GFX_3D_Renderer_SetDepthBufferEnabled(
GFX_3D_RENDERER *renderer, bool is_enabled)
{
ASSERT(renderer != NULL);
GFX_3D_VertexStream_RenderPending(&renderer->vertex_stream);
M_Flush(renderer);
glDepthFunc(is_enabled ? GL_LEQUAL : GL_ALWAYS);
GFX_GL_CheckError();
}

void GFX_3D_Renderer_SetBlendingMode(
Expand All @@ -382,40 +387,43 @@ void GFX_3D_Renderer_SetBlendingMode(
if (renderer->selected_blend_mode == blend_mode) {
return;
}
GFX_3D_VertexStream_RenderPending(&renderer->vertex_stream);
M_Flush(renderer);

GFX_GL_Program_Bind(&renderer->program);
switch (blend_mode) {
case GFX_BLEND_MODE_OFF:
glBlendFunc(GL_ONE, GL_ZERO);
GFX_GL_CheckError();
GFX_GL_Program_Uniform1i(
&renderer->program, renderer->loc_color_key_enabled, false);
break;
case GFX_BLEND_MODE_NORMAL:
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
GFX_GL_CheckError();
GFX_GL_Program_Uniform1i(
&renderer->program, renderer->loc_color_key_enabled, false);
break;
case GFX_BLEND_MODE_MULTIPLY:
glBlendFunc(GL_DST_COLOR, GL_SRC_COLOR);
GFX_GL_CheckError();
GFX_GL_Program_Uniform1i(
&renderer->program, renderer->loc_color_key_enabled, false);
break;
case GFX_BLEND_MODE_COLOR_KEY:
glBlendFunc(GL_ONE, GL_ZERO);
GFX_GL_CheckError();
GFX_GL_Program_Uniform1i(
&renderer->program, renderer->loc_color_key_enabled, true);
break;
}
GFX_GL_CheckError();
renderer->selected_blend_mode = blend_mode;
}

void GFX_3D_Renderer_SetTexturingEnabled(
GFX_3D_RENDERER *const renderer, const bool is_enabled)
{
ASSERT(renderer != NULL);
GFX_3D_VertexStream_RenderPending(&renderer->vertex_stream);
M_Flush(renderer);
GFX_GL_Program_Bind(&renderer->program);
GFX_GL_Program_Uniform1i(
&renderer->program, renderer->loc_texturing_enabled, is_enabled);
Expand Down

0 comments on commit c1191a2

Please sign in to comment.