gl: Use same GL context for RHI and GL

This commit is contained in:
Eidolon 2026-04-09 22:44:36 -05:00
parent d3eb26a8c0
commit 0d54b41983
22 changed files with 204 additions and 336 deletions

View file

@ -2307,15 +2307,7 @@ static boolean CL_ServerConnectionTicker(const char *tmpsave, tic_t *oldtic, tic
}
I_UpdateNoVsync(); // page flip or blit buffer
#ifdef HWRENDER
// Only take screenshots after drawing.
if (moviemode && rendermode == render_opengl)
M_LegacySaveFrame();
if (rendermode == render_opengl && takescreenshot)
M_DoLegacyGLScreenShot();
#endif
if ((moviemode || takescreenshot) && rendermode == render_soft)
if ((moviemode || takescreenshot) && rendermode != render_none)
I_CaptureVideoFrame();
S_UpdateSounds();
S_UpdateClosedCaptions();

View file

@ -570,14 +570,21 @@ static bool D_Display(bool world)
memset(screens[0], 32+(timeinmap&15), vid.width * vid.height * vid.bpp);
}
}
if (r_splitscreen == 2)
{
// Draw over the fourth screen so you don't have to stare at a HOM :V
V_DrawFill(viewwidth, viewheight, viewwidth, viewheight, 31|V_NOSCALESTART);
}
}
if (r_splitscreen == 2)
{
// Draw over the fourth screen so you don't have to stare at a HOM :V
V_DrawFill(viewwidth, viewheight, viewwidth, viewheight, 31|V_NOSCALESTART);
}
#ifdef HWRENDER
if (rendermode == render_opengl)
{
VID_BeginLegacyGLRenderPass();
}
#endif
for (i = 0; i <= r_splitscreen; i++)
{
if (players[displayplayers[i]].mo || players[displayplayers[i]].playerstate == PST_DEAD)
@ -641,6 +648,13 @@ static bool D_Display(bool world)
}
}
#ifdef HWRENDER
if (rendermode == render_opengl)
{
VID_EndLegacyGLRenderPass();
}
#endif
ps_rendercalltime = I_GetPreciseTime() - ps_rendercalltime;
R_RestoreLevelInterpolators();
}
@ -687,6 +701,10 @@ static bool D_Display(bool world)
{
VID_DisplaySoftwareScreen();
}
if (rendermode != render_none)
{
VID_DisplayRHIPostimg();
}
if (lastdraw)
{
@ -1069,15 +1087,7 @@ void D_SRB2Loop(void)
ranwipe = D_Display(world);
}
#ifdef HWRENDER
// Only take screenshots after drawing.
if (moviemode && rendermode == render_opengl)
M_LegacySaveFrame();
if (rendermode == render_opengl && takescreenshot)
M_DoLegacyGLScreenShot();
#endif
if ((moviemode || takescreenshot) && rendermode == render_soft)
if ((moviemode || takescreenshot) && rendermode != render_none)
I_CaptureVideoFrame();
// consoleplayer -> displayplayers (hear sounds from viewpoint)

View file

@ -35,10 +35,6 @@
#include "g_game.h"
#include "st_stuff.h"
#ifdef HWRENDER
#include "hardware/hw_main.h"
#endif
#if NUMSCREENS < 5
#define NOWIPE // do not enable wipe image post processing for ARM, SH and MIPS CPUs
#endif
@ -356,14 +352,6 @@ static void refresh_wipe_screen_texture(rhi::Rhi& rhi, rhi::Handle<rhi::Texture>
void F_WipeStartScreen(void)
{
#ifndef NOWIPE
#ifdef HWRENDER
if(rendermode == render_opengl)
{
HWR_StartScreenWipe();
return;
}
#endif
rhi::Rhi* rhi = srb2::sys::get_rhi(srb2::sys::g_current_rhi);
if (!rhi)
@ -392,14 +380,6 @@ void F_WipeStartScreen(void)
void F_WipeEndScreen(void)
{
#ifndef NOWIPE
#ifdef HWRENDER
if(rendermode == render_opengl)
{
HWR_EndScreenWipe();
return;
}
#endif
rhi::Rhi* rhi = srb2::sys::get_rhi(srb2::sys::g_current_rhi);
if (!rhi)
@ -501,12 +481,6 @@ void F_RunWipe(UINT8 wipemode, UINT8 wipetype, boolean drawMenu, const char *col
}
lastwipetic = nowtime;
#ifdef HWRENDER
if (rendermode == render_opengl)
HWR_DoWipe(wipetype, wipeframe-1); // send in the wipe type and wipeframe because we need to cache the graphic
else
#endif
if (rendermode != render_none) //this allows F_RunWipe to be called in dedicated servers
{
// F_DoWipe(fmask, fcolor, reverse);
@ -563,11 +537,6 @@ void F_RunWipe(UINT8 wipemode, UINT8 wipetype, boolean drawMenu, const char *col
I_FinishUpdate(); // page flip or blit buffer
#ifdef HWRENDER
if (moviemode && rendermode == render_opengl)
M_LegacySaveFrame();
else
#endif
if (moviemode && rendermode == render_soft)
I_CaptureVideoFrame();

View file

@ -1304,12 +1304,7 @@ void G_PreLevelTitleCard(void)
I_FinishUpdate(); // page flip or blit buffer
NetKeepAlive(); // Prevent timeouts
#ifdef HWRENDER
if (moviemode && rendermode == render_opengl)
M_LegacySaveFrame();
else
#endif
if (moviemode && rendermode == render_soft)
if (moviemode && rendermode != render_none)
I_CaptureVideoFrame();
while (!((nowtime = I_GetTime()) - lasttime))

View file

@ -41,6 +41,7 @@ EXPORT void HWRAPI(DrawPolygon) (FSurfaceInfo *pSurf, FOutVector *pOutVerts, FUI
EXPORT void HWRAPI(DrawIndexedTriangles) (FSurfaceInfo *pSurf, FOutVector *pOutVerts, FUINT iNumPts, FBITFIELD PolyFlags, UINT32 *IndexArray);
EXPORT void HWRAPI(RenderSkyDome) (gl_sky_t *sky);
EXPORT void HWRAPI(SetBlend) (FBITFIELD PolyFlags);
EXPORT void HWRAPI(ResetRenderState) (void);
EXPORT void HWRAPI(ClearBuffer) (FBOOLEAN ColorMask, FBOOLEAN DepthMask, FRGBAFloat *ClearColor);
EXPORT void HWRAPI(SetTexture) (GLMipmap_t *TexInfo);
EXPORT void HWRAPI(UpdateTexture) (GLMipmap_t *TexInfo);
@ -126,6 +127,7 @@ struct hwdriver_s
SetShaderInfo pfnSetShaderInfo;
LoadCustomShader pfnLoadCustomShader;
ResetRenderState pfnResetRenderState;
};
extern struct hwdriver_s hwdriver;

View file

@ -5993,6 +5993,8 @@ static void HWR_RollTransform(FTransform *tr, angle_t roll)
void HWR_RenderPlayerView(void)
{
HWD.pfnResetRenderState();
player_t * player = &players[displayplayers[viewssnum]];
const boolean skybox = (player->skybox.viewpoint && cv_skybox.value); // True if there's a skybox object and skyboxes are on

View file

@ -1532,6 +1532,8 @@ EXPORT void HWRAPI(ReadRect) (INT32 x, INT32 y, INT32 width, INT32 height,
bottom -= dst_stride;
}
free(row);
pglPixelStorei(GL_UNPACK_ALIGNMENT, 4);
pglPixelStorei(GL_PACK_ALIGNMENT, 4);
}
else
{
@ -1553,6 +1555,8 @@ EXPORT void HWRAPI(ReadRect) (INT32 x, INT32 y, INT32 width, INT32 height,
}
}
free(image);
pglPixelStorei(GL_UNPACK_ALIGNMENT, 4);
pglPixelStorei(GL_PACK_ALIGNMENT, 4);
}
}
@ -1609,8 +1613,6 @@ EXPORT void HWRAPI(ClearBuffer) (FBOOLEAN ColorMask,
SetBlend(DepthMask ? PF_Occlude | CurrentPolyFlags : CurrentPolyFlags&~PF_Occlude);
pglClear(ClearMask);
pglEnableClientState(GL_VERTEX_ARRAY); // We always use this one
pglEnableClientState(GL_TEXTURE_COORD_ARRAY); // And mostly this one, too
}
@ -1866,6 +1868,11 @@ EXPORT void HWRAPI(SetBlend) (FBITFIELD PolyFlags)
CurrentPolyFlags = PolyFlags;
}
EXPORT void HWRAPI(ResetRenderState) (void)
{
SetStates();
}
static void AllocTextureBuffer(GLMipmap_t *pTexInfo)
{
size_t size = pTexInfo->width * pTexInfo->height;
@ -2082,6 +2089,8 @@ EXPORT void HWRAPI(UpdateTexture) (GLMipmap_t *pTexInfo)
if (maximumAnisotropy)
pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, anisotropic_filter);
pglPixelStorei(GL_UNPACK_ALIGNMENT, 4);
pglPixelStorei(GL_PACK_ALIGNMENT, 4);
pglActiveTexture(GL_TEXTURE0);
}

View file

@ -45,6 +45,7 @@ struct HardwareState
std::unique_ptr<BlitRectPass> crtsharp_blit_rect;
std::unique_ptr<ScreenshotPass> screen_capture;
std::unique_ptr<UpscaleBackbuffer> backbuffer;
std::unique_ptr<UpscaleBackbuffer> legacygl_backbuffer;
std::unique_ptr<ImguiRenderer> imgui_renderer;
WipeFrames wipe_frames;
};

View file

@ -47,17 +47,29 @@ void UpscaleBackbuffer::begin_pass(Rhi& rhi)
}
TextureDesc color_tex {};
color_tex.format = TextureFormat::kRGBA;
color_tex.format = TextureFormat::kRGB;
color_tex.width = vid_width;
color_tex.height = vid_height;
color_tex.u_wrap = TextureWrapMode::kClamp;
color_tex.v_wrap = TextureWrapMode::kClamp;
color_ = rhi.create_texture(color_tex);
if (depth_)
{
rhi.destroy_renderbuffer(depth_);
depth_ = kNullHandle;
}
RenderbufferDesc rb_desc {};
rb_desc.width = vid_width;
rb_desc.height = vid_height;
depth_ = rhi.create_renderbuffer(rb_desc);
}
RenderPassBeginInfo begin_info {};
begin_info.clear_color = {0, 0, 0, 1};
begin_info.color_attachment = color_;
begin_info.depth_stencil_attachment = depth_;
begin_info.color_load_op = rhi::AttachmentLoadOp::kLoad;
begin_info.color_store_op = rhi::AttachmentStoreOp::kStore;
begin_info.depth_load_op = rhi::AttachmentLoadOp::kLoad;

View file

@ -19,6 +19,7 @@ namespace srb2::hwr2
class UpscaleBackbuffer
{
rhi::Handle<rhi::Texture> color_;
rhi::Handle<rhi::Renderbuffer> depth_;
public:
UpscaleBackbuffer();

View file

@ -170,6 +170,9 @@ UINT32 I_GetRefreshRate(void);
void I_CaptureVideoFrame(void);
void VID_BeginLegacyGLRenderPass(void);
void VID_EndLegacyGLRenderPass(void);
#ifdef __cplusplus
} // extern "C"
#endif

View file

@ -87,6 +87,7 @@ static void reset_hardware_state(Rhi* rhi)
g_hw_state.crtsharp_blit_rect = std::make_unique<BlitRectPass>(BlitRectPass::BlitMode::kCrtSharp);
g_hw_state.screen_capture = std::make_unique<ScreenshotPass>();
g_hw_state.backbuffer = std::make_unique<UpscaleBackbuffer>();
g_hw_state.legacygl_backbuffer = std::make_unique<UpscaleBackbuffer>();
g_hw_state.imgui_renderer = std::make_unique<ImguiRenderer>();
g_hw_state.wipe_frames = {};
@ -215,13 +216,6 @@ void I_StartDisplayUpdate(void)
return;
}
#ifdef HWRENDER
if (rendermode == render_opengl)
{
return;
}
#endif
rhi::Rhi* rhi = sys::get_rhi(sys::g_current_rhi);
if (rhi == nullptr)
@ -252,15 +246,6 @@ void I_FinishUpdate(void)
return;
}
#ifdef HWRENDER
if (rendermode == render_opengl)
{
finish_legacy_ogl_update();
FrameMark;
return;
}
#endif
temp_legacy_finishupdate_draws();
rhi::Rhi* rhi = sys::get_rhi(sys::g_current_rhi);
@ -338,3 +323,40 @@ void I_FinishUpdate(void)
// Immediately prepare to begin drawing the next frame
I_StartDisplayUpdate();
}
void VID_BeginLegacyGLRenderPass(void)
{
if (rendermode == render_none)
{
return;
}
rhi::Rhi* rhi = sys::get_rhi(sys::g_current_rhi);
if (rhi == nullptr)
{
// ???
return;
}
g_hw_state.twodee_renderer->flush(*rhi, g_2d);
g_hw_state.legacygl_backbuffer->begin_pass(*rhi);
}
void VID_EndLegacyGLRenderPass(void)
{
if (rendermode == render_none)
{
return;
}
rhi::Rhi* rhi = sys::get_rhi(sys::g_current_rhi);
if (rhi == nullptr)
{
// ???
return;
}
rhi->pop_render_pass();
}

View file

@ -1415,97 +1415,6 @@ void M_StartMovie(moviemode_t mode)
static void M_SaveFrame_AVRecorder(uint32_t width, uint32_t height, tcb::span<const std::byte> data);
void M_LegacySaveFrame(void)
{
#if NUMSCREENS > 2
// TODO: until HWR2 replaces legacy OpenGL renderer, this
// function still needs to called for OpenGL.
#ifdef HWRENDER
if (rendermode != render_opengl)
#endif
{
return;
}
// paranoia: should be unnecessary without singletics
static tic_t oldtic = 0;
#ifdef SRB2_CONFIG_ENABLE_WEBM_MOVIES
if (moviemode == MM_AVRECORDER)
{
if (M_AVRecorder_IsExpired())
{
M_StopMovie();
return;
}
}
#endif
// skip interpolated frames for other modes
if (oldtic == I_GetTime())
return;
else
oldtic = I_GetTime();
switch (moviemode)
{
case MM_SCREENSHOT:
takescreenshot = true;
return;
case MM_GIF:
GIF_frame();
return;
case MM_APNG:
#ifdef USE_APNG
{
UINT8 *linear = NULL;
if (!apng_FILE) // should not happen!!
{
moviemode = MM_OFF;
return;
}
if (rendermode == render_soft)
{
// munge planar buffer to linear
linear = screens[2];
I_ReadScreen(linear);
}
#ifdef HWRENDER
else
linear = HWR_GetScreenshot();
#endif
M_PNGFrame(apng_ptr, apng_info_ptr, (png_bytep)linear);
#ifdef HWRENDER
if (rendermode == render_opengl && linear)
free(linear);
#endif
if (apng_frames == PNG_UINT_31_MAX)
{
CONS_Alert(CONS_NOTICE, M_GetText("Max movie size reached\n"));
M_StopMovie();
}
}
#else
moviemode = MM_OFF;
#endif
return;
case MM_AVRECORDER:
#if defined(SRB2_CONFIG_ENABLE_WEBM_MOVIES) && defined(HWRENDER)
{
UINT8 *linear = HWR_GetScreenshot();
M_SaveFrame_AVRecorder(vid.width, vid.height, tcb::as_bytes(tcb::span(linear, 3 * vid.width * vid.height)));
free(linear);
}
#endif
return;
default:
return;
}
#endif
}
static void M_SaveFrame_GIF(uint32_t width, uint32_t height, tcb::span<const std::byte> data)
{
if (moviemode != MM_GIF)
@ -1801,12 +1710,6 @@ void M_ScreenShot(void)
takescreenshot = true;
}
void M_DoLegacyGLScreenShot(void)
{
const std::byte* fake_data = nullptr;
M_DoScreenShot(vid.width, vid.height, tcb::span(fake_data, vid.width * vid.height));
}
/** Takes a screenshot.
* The screenshot is saved as "srb2xxxx.png" where xxxx is the lowest
* four-digit number for which a file does not already exist.

View file

@ -60,7 +60,6 @@ extern consvar_t cv_zlib_memorya, cv_zlib_levela, cv_zlib_strategya, cv_zlib_win
extern consvar_t cv_apng_delay, cv_apng_downscale;
void M_StartMovie(moviemode_t mode);
void M_LegacySaveFrame(void);
void M_StopMovie(void);
// the file where game vars and settings are saved
@ -108,9 +107,6 @@ boolean M_SavePNG(const char *filename, const void *data, int width, int height,
extern boolean takescreenshot;
void M_ScreenShot(void);
#ifdef HWRENDER
void M_DoLegacyGLScreenShot(void);
#endif
void M_ScreenshotTicker(void);
void M_MinimapGenerate(void);

View file

@ -8571,9 +8571,7 @@ boolean P_LoadLevel(boolean fromnetsave, boolean reloadinggamestate)
I_UpdateTime(); \
} \
lastwipetic = nowtime; \
if (moviemode && rendermode == render_opengl) \
M_LegacySaveFrame(); \
else if (moviemode && rendermode == render_soft) \
if (moviemode && rendermode != render_none) \
I_CaptureVideoFrame(); \
NetKeepAlive(); \
} \
@ -8768,9 +8766,7 @@ boolean P_LoadLevel(boolean fromnetsave, boolean reloadinggamestate)
}
lastwipetic = nowtime;
if (moviemode && rendermode == render_opengl)
M_LegacySaveFrame();
else if (moviemode && rendermode == render_soft)
if (moviemode && rendermode != render_none)
I_CaptureVideoFrame();
NetKeepAlive();
}

View file

@ -1024,7 +1024,7 @@ void Gl2Rhi::apply_framebuffer(const RenderPassBeginInfo& info, bool allow_clear
SRB2_ASSERT(texture_slab_.is_valid(info.color_attachment));
auto& texture = texture_slab_[info.color_attachment];
SRB2_ASSERT(texture.desc.format == TextureFormat::kRGBA);
SRB2_ASSERT(texture.desc.format == TextureFormat::kRGBA || texture.desc.format == TextureFormat::kRGB);
gl_->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture.texture, 0);
GL_ASSERT;
@ -1432,6 +1432,13 @@ void Gl2Rhi::set_rasterizer_state(const RasterizerStateDesc& desc)
}
gl_->Scissor(desc.scissor.x, desc.scissor.y, desc.scissor.w, desc.scissor.h);
GL_ASSERT;
// We never use fixed func alpha test, but Legacy GL does, so it has to be turned off.
// Note that Core profile and GLES 2+ don't have this at all.
gl_->Disable(GL_ALPHA_TEST);
GL_ASSERT;
gl_->AlphaFunc(GL_ALWAYS, 0);
GL_ASSERT;
}
void Gl2Rhi::set_viewport(const Rect& rect)

View file

@ -107,6 +107,7 @@ void *hwSym(const char *funcName,void *handle)
GETFUNC(SetShaderInfo);
GETFUNC(LoadCustomShader);
GETFUNC(ResetRenderState);
#else //HWRENDER
if (0 == strcmp("FinishUpdate", funcName))

View file

@ -1321,27 +1321,6 @@ static void init_imgui()
static SDL_bool Impl_CreateContext(void)
{
#ifdef HWRENDER
if (rendermode == render_opengl)
{
if (!g_legacy_gl_context)
{
SDL_GL_ResetAttributes();
g_legacy_gl_context = SDL_GL_CreateContext(window);
}
if (g_legacy_gl_context == NULL)
{
SDL_DestroyWindow(window);
I_Error("Failed to create a Legacy GL context: %s\n", SDL_GetError());
}
init_imgui();
SDL_GL_MakeCurrent(window, g_legacy_gl_context);
return SDL_TRUE;
}
#endif
// RHI always uses OpenGL 2.0 (for now)
if (!sdlglcontext)
{
SDL_GL_ResetAttributes();
@ -1352,11 +1331,18 @@ static SDL_bool Impl_CreateContext(void)
if (sdlglcontext == NULL)
{
SDL_DestroyWindow(window);
I_Error("Failed to create an RHI GL context: %s\n", SDL_GetError());
I_Error("Failed to create a GL context: %s\n", SDL_GetError());
}
init_imgui();
SDL_GL_MakeCurrent(window, sdlglcontext);
#ifdef HWRENDER
if (rendermode == render_opengl)
{
LoadGL();
}
#endif
if (!g_rhi)
{
std::unique_ptr<rhi::SdlGl2Platform> platform = std::make_unique<rhi::SdlGl2Platform>();
@ -1674,6 +1660,7 @@ void VID_StartupOpenGL(void)
*(void**)&HWD.pfnSetShaderInfo = hwSym("SetShaderInfo",NULL);
*(void**)&HWD.pfnLoadCustomShader = hwSym("LoadCustomShader",NULL);
*(void**)&HWD.pfnResetRenderState = hwSym("ResetRenderState",NULL);
glstartup = true;
}
@ -1746,24 +1733,9 @@ void srb2::cvarhandler::on_set_vid_wait()
interval = 1;
}
switch (rendermode)
if (sdlglcontext == nullptr || SDL_GL_GetCurrentContext() != sdlglcontext)
{
case render_soft:
if (sdlglcontext == nullptr || SDL_GL_GetCurrentContext() != sdlglcontext)
{
return;
}
SDL_GL_SetSwapInterval(interval);
break;
#ifdef HWRENDER
case render_opengl:
if (g_legacy_gl_context == nullptr || SDL_GL_GetCurrentContext() != g_legacy_gl_context)
{
return;
}
SDL_GL_SetSwapInterval(interval);
#endif
default:
break;
return;
}
SDL_GL_SetSwapInterval(interval);
}

View file

@ -66,7 +66,6 @@ PFNglGetString pglGetString;
INT32 oglflags = 0;
void *GLUhandle = NULL;
SDL_GLContext sdlglcontext = 0;
SDL_GLContext g_legacy_gl_context = 0;
void *GetGLFunc(const char *proc)
{

View file

@ -30,10 +30,13 @@ boolean OglSdlSurface(INT32 w, INT32 h);
void OglSdlFinishUpdate(boolean vidwait);
extern SDL_GLContext sdlglcontext;
extern SDL_GLContext g_legacy_gl_context;
extern Uint16 realwidth;
extern Uint16 realheight;
#ifdef HWRENDER
boolean LoadGL(void);
#endif
#ifdef _CREATE_DLL_
EXPORT void HWRAPI( OglSdlSetPalette ) (RGBA_t *palette);
#endif

View file

@ -440,15 +440,14 @@ void V_SetPalette(INT32 palettenum)
}
}
#if (defined (__unix__) && !defined (MSDOS)) || defined (UNIXCOMMON) || defined (HAVE_SDL)
if (rendermode != render_none)
I_SetPalette(&pLocalPalette[palettenum*256]);
#endif
#ifdef HWRENDER
if (rendermode == render_opengl)
HWR_SetPalette(&pLocalPalette[palettenum*256]);
#if (defined (__unix__) && !defined (MSDOS)) || defined (UNIXCOMMON) || defined (HAVE_SDL)
else
#endif
#endif
if (rendermode != render_none)
I_SetPalette(&pLocalPalette[palettenum*256]);
}
void V_SetPaletteLump(const char *pal)
@ -798,14 +797,6 @@ void V_DrawStretchyFixedPatch(fixed_t x, fixed_t y, fixed_t pscale, fixed_t vsca
if (rendermode == render_none)
return;
#ifdef HWRENDER
if (rendermode == render_opengl)
{
HWR_DrawStretchyFixedPatch(patch, x, y, pscale, vscale, scrn, colormap);
return;
}
#endif
if ((blendmode = ((scrn & V_BLENDMASK) >> V_BLENDSHIFT)))
blendmode++; // realign to constants
if ((alphalevel = V_GetAlphaLevel(scrn)) >= 10)
@ -1016,14 +1007,6 @@ void V_DrawFill(INT32 x, INT32 y, INT32 w, INT32 h, INT32 c)
if (rendermode == render_none)
return;
#ifdef HWRENDER
if (rendermode == render_opengl)
{
HWR_DrawFill(x, y, w, h, c);
return;
}
#endif
UINT32 alphalevel;
if ((alphalevel = V_GetAlphaLevel(c)) >= 10)
return;
@ -1139,15 +1122,6 @@ void V_DrawFillConsoleMap(INT32 x, INT32 y, INT32 w, INT32 h, INT32 c)
if (rendermode == render_none)
return;
#ifdef HWRENDER
if (rendermode == render_opengl)
{
UINT32 hwcolor = V_GetHWConsBackColor();
HWR_DrawConsoleFill(x, y, w, h, c, hwcolor); // we still use the regular color stuff but only for flags. actual draw color is "hwcolor" for this.
return;
}
#endif
if ((alphalevel = V_GetAlphaLevel(c)) >= 10)
return;
@ -1210,14 +1184,6 @@ void V_DrawDiag(INT32 x, INT32 y, INT32 wh, INT32 c)
if (rendermode == render_none)
return;
#ifdef HWRENDER
if (rendermode == render_opengl)
{
HWR_DrawDiag(x, y, wh, c);
return;
}
#endif
if (!(c & V_NOSCALESTART))
{
INT32 dupx = vid.dupx, dupy = vid.dupy;
@ -1292,15 +1258,6 @@ void V_DrawFadeFill(INT32 x, INT32 y, INT32 w, INT32 h, INT32 c, UINT16 color, U
if (rendermode == render_none)
return;
#ifdef HWRENDER
if (rendermode == render_opengl)
{
// ughhhhh please can someone else do this? thanks ~toast 25/7/19 in 38 degrees centigrade w/o AC
HWR_DrawFadeFill(x, y, w, h, c, color, strength); // toast two days later - left above comment in 'cause it's funny
return;
}
#endif
if (!(c & V_NOSCALESTART))
{
INT32 dupx = vid.dupx, dupy = vid.dupy;
@ -1380,13 +1337,6 @@ void V_DrawFlatFill(INT32 x, INT32 y, INT32 w, INT32 h, lumpnum_t flatnum)
size_t size;
size_t lflatsize;
#ifdef HWRENDER
if (rendermode == render_opengl)
{
HWR_DrawFlatFill(x, y, w, h, flatnum);
return;
}
#endif
size = W_LumpLength(flatnum);
switch (size)
@ -1521,14 +1471,6 @@ void V_DrawVhsEffect(boolean rewind)
//
void V_DrawFadeScreen(UINT16 color, UINT8 strength)
{
#ifdef HWRENDER
if (rendermode == render_opengl)
{
HWR_FadeScreenMenuBack(color, strength);
return;
}
#endif
float r;
float g;
float b;
@ -1638,13 +1580,6 @@ void V_DrawCustomFadeScreen(const char *lump, UINT8 strength)
void V_DrawFadeConsBack(INT32 plines)
{
UINT32 hwcolor = V_GetHWConsBackColor();
#ifdef HWRENDER // not win32 only 19990829 by Kin
if (rendermode == render_opengl)
{
HWR_DrawConsoleBack(hwcolor, plines);
return;
}
#endif
float r = ((hwcolor & 0xFF000000) >> 24) / 255.f;
float g = ((hwcolor & 0xFF0000) >> 16) / 255.f;
@ -1663,14 +1598,6 @@ void V_DrawFadeConsBack(INT32 plines)
//
void V_EncoreInvertScreen(void)
{
#ifdef HWRENDER
if (rendermode == render_opengl)
{
HWR_EncoreInvertScreen();
return;
}
#endif
g_2d.begin_quad()
.blend(hwr2::BlendMode::kInvertDest)
.color(1, 1, 1, 1)
@ -1698,14 +1625,6 @@ void V_DrawPromptBack(INT32 boxheight, INT32 color)
UINT32 hwcolor = V_GetHWConsBackColor();
#ifdef HWRENDER
if (rendermode == render_opengl)
{
HWR_DrawTutorialBack(hwcolor, boxheight);
return;
}
#endif
float r = ((color & 0xFF000000) >> 24) / 255.f;
float g = ((color & 0xFF0000) >> 16) / 255.f;
float b = ((color & 0xFF00) >> 8) / 255.f;
@ -3771,13 +3690,17 @@ void VID_DisplaySoftwareScreen()
{
ZoneScoped;
// TODO implement
// upload framebuffer, bind pipeline, draw
rhi::Rhi* rhi = srb2::sys::get_rhi(srb2::sys::g_current_rhi);
hwr2::HardwareState* hw_state = srb2::sys::main_hardware_state();
// Misnomer; this just uploads the screen to the software indexed screen texture
hw_state->software_screen_renderer->draw(*rhi);
}
void VID_DisplayRHIPostimg(void)
{
rhi::Rhi* rhi = srb2::sys::get_rhi(srb2::sys::g_current_rhi);
hwr2::HardwareState* hw_state = srb2::sys::main_hardware_state();
const int screens = std::clamp(r_splitscreen + 1, 1, MAXSPLITSCREENPLAYERS);
hw_state->blit_postimg_screens->set_num_screens(screens);
@ -3791,43 +3714,91 @@ void VID_DisplaySoftwareScreen()
if (screens > 2)
{
uv_size = glm::vec2(.5f, .5f);
switch (i)
if (rendermode == render_opengl)
{
case 0:
uv_offset = glm::vec2(0.f, 0.f);
break;
case 1:
uv_offset = glm::vec2(.5f, 0.f);
break;
case 2:
uv_offset = glm::vec2(0.f, .5f);
break;
case 3:
uv_offset = glm::vec2(.5f, .5f);
break;
switch (i)
{
case 0:
uv_offset = glm::vec2(0.f, .5f);
break;
case 1:
uv_offset = glm::vec2(.5f, .5f);
break;
case 2:
uv_offset = glm::vec2(0.f, 0.f);
break;
case 3:
uv_offset = glm::vec2(.5f, 0.f);
break;
}
}
else
{
switch (i)
{
case 0:
uv_offset = glm::vec2(0.f, 0.f);
break;
case 1:
uv_offset = glm::vec2(.5f, 0.f);
break;
case 2:
uv_offset = glm::vec2(0.f, .5f);
break;
case 3:
uv_offset = glm::vec2(.5f, .5f);
break;
}
}
}
else if (screens > 1)
{
uv_size = glm::vec2(1.f, .5f);
if (i == 1)
if (rendermode == render_opengl)
{
uv_offset = glm::vec2(0.f, .5f);
uv_offset = glm::vec2(0.f, i == 0 ? .5f : 0.f);
}
else
{
if (i == 1)
{
uv_offset = glm::vec2(0.f, .5f);
}
}
}
rhi::Handle<rhi::Texture> source;
bool indexed;
bool vflip;
bool mirror;
if (rendermode == render_soft)
{
source = hw_state->software_screen_renderer->screen();
indexed = true;
vflip = postimgtype[i] == postimg_flip;
mirror = postimgtype[i] == postimg_mirror;
}
else
{
source = hw_state->legacygl_backbuffer->color();
indexed = false;
// Legacy GL handles these on its own.
vflip = true;
mirror = false;
}
hw_state->blit_postimg_screens->set_screen(
i,
{
hw_state->software_screen_renderer->screen(),
true,
source,
indexed,
uv_offset,
uv_size,
{
postimgtype[i] == postimg_water && !cv_reducevfx.value,
postimgtype[i] == postimg_heat && !cv_reducevfx.value,
postimgtype[i] == postimg_flip,
postimgtype[i] == postimg_mirror
vflip,
mirror
}
}
);

View file

@ -442,6 +442,8 @@ void VID_BlitLinearScreen(const UINT8 *srcptr, UINT8 *destptr, INT32 width, INT3
*/
void VID_DisplaySoftwareScreen(void);
void VID_DisplayRHIPostimg(void);
char *V_ParseText(const char *rawText); // Launder srb2::draw::TextElement.parse() through C code!