From 19e5366c5bef6d2b98825a3fbc1847d614b2fa94 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 28 May 2025 18:31:21 +0200 Subject: [PATCH] add wireframe mode for ogl --- src/hardware/hw_main.c | 20 ++++++++++++++++++-- src/hardware/hw_main.h | 2 ++ src/hardware/r_opengl/r_opengl.c | 7 +++++++ 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 94767ff5d..0f308017d 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -226,6 +226,8 @@ consvar_t cv_glsolvetjoin = {"gr_solvetjoin", "On", 0, CV_OnOff, NULL, 0, NULL, consvar_t cv_glbatching = {"gr_batching", "On", 0, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_glwireframe = {"gr_wireframe", "Off", 0, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; + consvar_t cv_glrenderdistance = {"gr_renderdistance", "Max", CV_SAVE, glrenderdistance_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_glhorizonlines = {"gr_horizonlines", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; @@ -338,6 +340,12 @@ static void HWR_SetShaderState(void) GL_SetSpecialState(HWD_SET_SHADERS, HWR_UseShader() ? 1 : 0); } + +static boolean HWR_IsWireframeMode(void) +{ + return (cv_glwireframe.value /*&& cv_debug*/); +} + static boolean HWR_OverrideObjectLightLevel(mobj_t *thing, INT32 *lightlevel) { if (R_ThingIsFullBright(thing)) @@ -5259,6 +5267,9 @@ static void HWR_DrawSkyBackground(void) if (drewsky) return; + if (HWR_IsWireframeMode()) + return; + GL_SetBlend(PF_Translucent|PF_NoDepthTest|PF_Modulated); memcpy(&dometransform, &atransform, sizeof(FTransform)); @@ -5461,8 +5472,8 @@ void HWR_RenderViewpoint(gl_portal_t *rootportal, const float fpov, player_t *pl HWR_PortalClipping(rootportal); } - // Set transform. - GL_SetTransform(&atransform); + if (HWR_IsWireframeMode()) + GL_SetSpecialState(HWD_SET_WIREFRAME, 1); ps_numbspcalls.value.i = 0; ps_numpolyobjects.value.i = 0; @@ -5527,6 +5538,9 @@ void HWR_RenderViewpoint(gl_portal_t *rootportal, const float fpov, player_t *pl ps_hw_nodedrawtime.value.p = 0; HWR_RenderDrawNodes(); + if (HWR_IsWireframeMode()) + GL_SetSpecialState(HWD_SET_WIREFRAME, 0); + HWR_FreePortalList(portallist); } @@ -5801,6 +5815,8 @@ void HWR_AddCommands(void) CV_RegisterVar(&cv_glbatching); + CV_RegisterVar(&cv_glwireframe); + CV_RegisterVar(&cv_glrenderdistance); CV_RegisterVar(&cv_glhorizonlines); diff --git a/src/hardware/hw_main.h b/src/hardware/hw_main.h index b8d6ef939..87b1faaf4 100644 --- a/src/hardware/hw_main.h +++ b/src/hardware/hw_main.h @@ -202,6 +202,8 @@ extern consvar_t cv_glsolvetjoin; extern consvar_t cv_glbatching; +extern consvar_t cv_glwireframe; + extern consvar_t cv_glrenderdistance; extern consvar_t cv_glhorizonlines; diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index 12ec0cd97..07ceaf86f 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -350,6 +350,8 @@ typedef void (APIENTRY * PFNglDisable) (GLenum cap); static PFNglDisable pglDisable; typedef void (APIENTRY * PFNglGetFloatv) (GLenum pname, GLfloat *params); static PFNglGetFloatv pglGetFloatv; +typedef void (APIENTRY * PFNglPolygonMode) (GLenum, GLenum); +static PFNglPolygonMode pglPolygonMode; /* Depth Buffer */ typedef void (APIENTRY * PFNglClearDepth) (GLclampd depth); @@ -549,6 +551,7 @@ boolean SetupGLfunc(void) GETOPENGLFUNC(pglGetFloatv, glGetFloatv) GETOPENGLFUNC(pglGetIntegerv, glGetIntegerv) GETOPENGLFUNC(pglGetString, glGetString) + GETOPENGLFUNC(pglPolygonMode, glPolygonMode) GETOPENGLFUNC(pglClearDepth, glClearDepth) GETOPENGLFUNC(pglDepthFunc, glDepthFunc) @@ -2364,6 +2367,10 @@ void GL_SetSpecialState(hwdspecialstate_t IdState, INT32 Value) GL_Flush(); //??? if we want to change filter mode by texture, remove this break; + case HWD_SET_WIREFRAME: + pglPolygonMode(GL_FRONT_AND_BACK, Value ? GL_LINE : GL_FILL); + break; + case HWD_SET_TEXTURE_FORMAT: gltexformat = (Value == 32) ? GL_RGBA : GL_RGB5_A1; GL_Flush();