- cleanup of the 2D interface.

Lots of this was still laid out for DirectDraw. This removes most of Begin2D so that it can be done more cleanlz.
Note that this commit renders weapon sprites and screen blends incorrectly. Those will be fixed in an upcoming commit.
This commit is contained in:
Christoph Oelckers 2018-04-29 20:15:19 +02:00
parent 1345c8e7b4
commit 67cb6e63b5
10 changed files with 42 additions and 89 deletions

View file

@ -753,13 +753,15 @@ void D_Display ()
screen->FrameTime = I_msTimeFS(); screen->FrameTime = I_msTimeFS();
TexMan.UpdateAnimations(screen->FrameTime); TexMan.UpdateAnimations(screen->FrameTime);
R_UpdateSky(screen->FrameTime); R_UpdateSky(screen->FrameTime);
screen->BeginFrame();
screen->ClearClipRect();
switch (gamestate) switch (gamestate)
{ {
case GS_FULLCONSOLE: case GS_FULLCONSOLE:
screen->SetBlendingRect(0,0,0,0);
screen->Begin2D(false); screen->Begin2D(false);
C_DrawConsole (); C_DrawConsole ();
M_Drawer (); M_Drawer ();
screen->End2D();
screen->Update (); screen->Update ();
return; return;
@ -775,6 +777,7 @@ void D_Display ()
//E_RenderFrame(); //E_RenderFrame();
// //
screen->RenderView(&players[consoleplayer]); screen->RenderView(&players[consoleplayer]);
screen->Begin2D(false);
// returns with 2S mode set. // returns with 2S mode set.
if (automapactive) if (automapactive)
{ {
@ -820,21 +823,18 @@ void D_Display ()
break; break;
case GS_INTERMISSION: case GS_INTERMISSION:
screen->SetBlendingRect(0,0,0,0);
screen->Begin2D(false); screen->Begin2D(false);
WI_Drawer (); WI_Drawer ();
CT_Drawer (); CT_Drawer ();
break; break;
case GS_FINALE: case GS_FINALE:
screen->SetBlendingRect(0,0,0,0);
screen->Begin2D(false); screen->Begin2D(false);
F_Drawer (); F_Drawer ();
CT_Drawer (); CT_Drawer ();
break; break;
case GS_DEMOSCREEN: case GS_DEMOSCREEN:
screen->SetBlendingRect(0,0,0,0);
screen->Begin2D(false); screen->Begin2D(false);
D_PageDrawer (); D_PageDrawer ();
CT_Drawer (); CT_Drawer ();

View file

@ -356,21 +356,6 @@ void FGLRenderer::SetupLevel()
mVBO->CreateVBO(); mVBO->CreateVBO();
} }
void FGLRenderer::Begin2D()
{
if (mBuffers->Setup(mScreenViewport.width, mScreenViewport.height, mSceneViewport.width, mSceneViewport.height))
{
if (mDrawingScene2D)
mBuffers->BindSceneFB(false);
else
mBuffers->BindCurrentFB();
}
glViewport(mScreenViewport.left, mScreenViewport.top, mScreenViewport.width, mScreenViewport.height);
glScissor(mScreenViewport.left, mScreenViewport.top, mScreenViewport.width, mScreenViewport.height);
gl_RenderState.EnableFog(false);
}
//=========================================================================== //===========================================================================
// //
// //
@ -533,6 +518,12 @@ void FGLRenderer::WriteSavePic(player_t *player, FileWriter *file, int width, in
drawer.WriteSavePic(player, file, width, height); drawer.WriteSavePic(player, file, width, height);
} }
void FGLRenderer::BeginFrame()
{
buffersActive = GLRenderer->mBuffers->Setup(GLRenderer->mScreenViewport.width, GLRenderer->mScreenViewport.height, GLRenderer->mSceneViewport.width, GLRenderer->mSceneViewport.height);
}
void gl_FillScreen() void gl_FillScreen()
{ {
@ -721,9 +712,31 @@ public:
void LegacyColorOverlay(F2DDrawer *drawer, F2DDrawer::RenderCommand & cmd); void LegacyColorOverlay(F2DDrawer *drawer, F2DDrawer::RenderCommand & cmd);
int LegacyDesaturation(F2DDrawer::RenderCommand &cmd); int LegacyDesaturation(F2DDrawer::RenderCommand &cmd);
CVAR(Bool, gl_aalines, false, CVAR_ARCHIVE)
void FGLRenderer::Draw2D(F2DDrawer *drawer) void FGLRenderer::Draw2D(F2DDrawer *drawer)
{ {
if (buffersActive)
{
mBuffers->BindCurrentFB();
}
glViewport(mScreenViewport.left, mScreenViewport.top, mScreenViewport.width, mScreenViewport.height);
gl_RenderState.mViewMatrix.loadIdentity();
gl_RenderState.mProjectionMatrix.ortho(0, screen->GetWidth(), screen->GetHeight(), 0, -1.0f, 1.0f);
gl_RenderState.ApplyMatrices();
glDisable(GL_DEPTH_TEST);
// Korshun: ENABLE AUTOMAP ANTIALIASING!!!
if (gl_aalines)
glEnable(GL_LINE_SMOOTH);
else
{
glDisable(GL_MULTISAMPLE);
glDisable(GL_LINE_SMOOTH);
glLineWidth(1.0);
}
auto &vertices = drawer->mVertices; auto &vertices = drawer->mVertices;
@ -741,6 +754,7 @@ void FGLRenderer::Draw2D(F2DDrawer *drawer)
vb->UploadData(&vertices[0], vertices.Size(), &indices[0], indices.Size()); vb->UploadData(&vertices[0], vertices.Size(), &indices[0], indices.Size());
gl_RenderState.SetVertexBuffer(vb); gl_RenderState.SetVertexBuffer(vb);
gl_RenderState.SetFixedColormap(CM_DEFAULT); gl_RenderState.SetFixedColormap(CM_DEFAULT);
gl_RenderState.EnableFog(false);
for(auto &cmd : commands) for(auto &cmd : commands)
{ {

View file

@ -152,6 +152,7 @@ public:
GL_IRECT mSceneViewport; GL_IRECT mSceneViewport;
GL_IRECT mOutputLetterbox; GL_IRECT mOutputLetterbox;
bool mDrawingScene2D = false; bool mDrawingScene2D = false;
bool buffersActive = false;
float mSceneClearColor[3]; float mSceneClearColor[3];
@ -166,7 +167,6 @@ public:
void Initialize(int width, int height); void Initialize(int width, int height);
void Begin2D();
void ClearBorders(); void ClearBorders();
void FlushTextures(); void FlushTextures();
@ -193,7 +193,7 @@ public:
void WriteSavePic(player_t *player, FileWriter *file, int width, int height); void WriteSavePic(player_t *player, FileWriter *file, int width, int height);
void RenderView(player_t *player); void RenderView(player_t *player);
void DrawBlend(sector_t * viewsector, bool FixedColormap, bool docolormap, bool in2d = false); void DrawBlend(sector_t * viewsector, bool FixedColormap, bool docolormap, bool in2d = false);
void BeginFrame();
bool StartOffscreen(); bool StartOffscreen();
void EndOffscreen(); void EndOffscreen();

View file

@ -134,7 +134,7 @@ void GLSceneDrawer::Reset3DViewport()
void GLSceneDrawer::Set3DViewport(bool mainview) void GLSceneDrawer::Set3DViewport(bool mainview)
{ {
if (mainview && GLRenderer->mBuffers->Setup(GLRenderer->mScreenViewport.width, GLRenderer->mScreenViewport.height, GLRenderer->mSceneViewport.width, GLRenderer->mSceneViewport.height)) if (mainview && GLRenderer->buffersActive)
{ {
bool useSSAO = (gl_ssao != 0); bool useSSAO = (gl_ssao != 0);
GLRenderer->mBuffers->BindSceneFB(useSSAO); GLRenderer->mBuffers->BindSceneFB(useSSAO);
@ -526,8 +526,6 @@ void GLSceneDrawer::EndDrawScene(sector_t * viewsector)
glDisable(GL_STENCIL_TEST); glDisable(GL_STENCIL_TEST);
GLRenderer->framebuffer->Begin2D(false);
Reset3DViewport(); Reset3DViewport();
// Delay drawing psprites until after bloom has been applied, if enabled. // Delay drawing psprites until after bloom has been applied, if enabled.
@ -776,7 +774,6 @@ void GLSceneDrawer::WriteSavePic (player_t *player, FileWriter *file, int width,
glDisable(GL_STENCIL_TEST); glDisable(GL_STENCIL_TEST);
gl_RenderState.SetFixedColormap(CM_DEFAULT); gl_RenderState.SetFixedColormap(CM_DEFAULT);
gl_RenderState.SetSoftLightLevel(-1); gl_RenderState.SetSoftLightLevel(-1);
screen->Begin2D(false);
if (!FGLRenderBuffers::IsEnabled()) if (!FGLRenderBuffers::IsEnabled())
{ {
DrawBlend(viewsector); DrawBlend(viewsector);

View file

@ -119,7 +119,6 @@ void SWSceneDrawer::RenderView(player_t *player)
FBTexture->SystemTexture[0]->CreateTexture(nullptr, screen->GetWidth(), screen->GetHeight(), 0, false, 0, "swbuffer"); FBTexture->SystemTexture[0]->CreateTexture(nullptr, screen->GetWidth(), screen->GetHeight(), 0, false, 0, "swbuffer");
auto map = swrenderer::CameraLight::Instance()->ShaderColormap(); auto map = swrenderer::CameraLight::Instance()->ShaderColormap();
screen->Begin2D(false);
screen->DrawTexture(FBTexture, 0, 0, DTA_SpecialColormap, map, TAG_DONE); screen->DrawTexture(FBTexture, 0, 0, DTA_SpecialColormap, map, TAG_DONE);
SWRenderer->DrawRemainingPlayerSprites(); SWRenderer->DrawRemainingPlayerSprites();
GLRenderer->DrawBlend(r_viewpoint.sector, !!map, V_IsTrueColor(), true); GLRenderer->DrawBlend(r_viewpoint.sector, !!map, V_IsTrueColor(), true);

View file

@ -44,8 +44,6 @@
EXTERN_CVAR (Bool, vid_vsync) EXTERN_CVAR (Bool, vid_vsync)
CVAR(Bool, gl_aalines, false, CVAR_ARCHIVE)
FGLRenderer *GLRenderer; FGLRenderer *GLRenderer;
void gl_LoadExtensions(); void gl_LoadExtensions();
@ -140,7 +138,6 @@ void OpenGLFrameBuffer::InitializeState()
GLRenderer->Initialize(GetWidth(), GetHeight()); GLRenderer->Initialize(GetWidth(), GetHeight());
GLRenderer->SetOutputViewport(nullptr); GLRenderer->SetOutputViewport(nullptr);
Begin2D(false);
} }
//========================================================================== //==========================================================================
@ -157,8 +154,6 @@ void OpenGLFrameBuffer::Update()
return; return;
} }
Begin2D(false);
DrawRateStuff(); DrawRateStuff();
GLRenderer->Flush(); GLRenderer->Flush();
@ -442,32 +437,10 @@ void OpenGLFrameBuffer::SetClearColor(int color)
} }
//========================================================================== void OpenGLFrameBuffer::BeginFrame()
//
//
//
//==========================================================================
void OpenGLFrameBuffer::Begin2D(bool copy3d)
{ {
Super::Begin2D(copy3d); if (GLRenderer != nullptr)
gl_RenderState.mViewMatrix.loadIdentity(); GLRenderer->BeginFrame();
gl_RenderState.mProjectionMatrix.ortho(0, GetWidth(), GetHeight(), 0, -1.0f, 1.0f);
gl_RenderState.ApplyMatrices();
glDisable(GL_DEPTH_TEST);
// Korshun: ENABLE AUTOMAP ANTIALIASING!!!
if (gl_aalines)
glEnable(GL_LINE_SMOOTH);
else
{
glDisable(GL_MULTISAMPLE);
glDisable(GL_LINE_SMOOTH);
glLineWidth(1.0);
}
if (GLRenderer != NULL)
GLRenderer->Begin2D();
} }
//=========================================================================== //===========================================================================

View file

@ -31,7 +31,6 @@ public:
PalEntry *GetPalette () override; PalEntry *GetPalette () override;
bool SetFlash(PalEntry rgb, int amount) override; bool SetFlash(PalEntry rgb, int amount) override;
void GetFlash(PalEntry &rgb, int &amount) override; void GetFlash(PalEntry &rgb, int &amount) override;
void Begin2D(bool copy3d) override;
void GameRestart() override; void GameRestart() override;
void InitForLevel() override; void InitForLevel() override;
void SetClearColor(int color) override; void SetClearColor(int color) override;
@ -46,6 +45,7 @@ public:
void FlushTextures() override; void FlushTextures() override;
void TextureFilterChanged() override; void TextureFilterChanged() override;
void ResetFixedColormap() override; void ResetFixedColormap() override;
void BeginFrame() override;
// Retrieves a buffer containing image data for a screenshot. // Retrieves a buffer containing image data for a screenshot.
// Hint: Pitch can be negative for upside-down images, in which case buffer // Hint: Pitch can be negative for upside-down images, in which case buffer

View file

@ -229,7 +229,6 @@ void DIntermissionScreenFader::Drawer ()
if (mType == FADE_In) factor = 1.0 - factor; if (mType == FADE_In) factor = 1.0 - factor;
int color = MAKEARGB(int(factor*255), 0,0,0); int color = MAKEARGB(int(factor*255), 0,0,0);
screen->Begin2D(false);
screen->DrawTexture (TexMan[mBackground], 0, 0, DTA_Fullscreen, true, DTA_ColorOverlay, color, TAG_DONE); screen->DrawTexture (TexMan[mBackground], 0, 0, DTA_Fullscreen, true, DTA_ColorOverlay, color, TAG_DONE);
for (unsigned i=0; i < mOverlays.Size(); i++) for (unsigned i=0; i < mOverlays.Size(); i++)
{ {

View file

@ -839,33 +839,6 @@ void DFrameBuffer::NewRefreshRate ()
{ {
} }
//==========================================================================
//
// DFrameBuffer :: SetBlendingRect
//
// Defines the area of the screen containing the 3D view.
//
//==========================================================================
void DFrameBuffer::SetBlendingRect (int x1, int y1, int x2, int y2)
{
}
//==========================================================================
//
// DFrameBuffer :: Begin2D
//
// Signal that 3D rendering is complete, and the rest of the operations on
// the canvas until Unlock() will be 2D ones.
//
//==========================================================================
void DFrameBuffer::Begin2D (bool copy3d)
{
isIn2D = true;
ClearClipRect();
}
//========================================================================== //==========================================================================
// //
// DFrameBuffer :: WipeStartScreen // DFrameBuffer :: WipeStartScreen

View file

@ -372,9 +372,6 @@ public:
// Tells the device to recreate itself with the new setting from vid_refreshrate. // Tells the device to recreate itself with the new setting from vid_refreshrate.
virtual void NewRefreshRate (); virtual void NewRefreshRate ();
// Set the rect defining the area affected by blending.
virtual void SetBlendingRect (int x1, int y1, int x2, int y2);
// Delete any resources that need to be deleted after restarting with a different IWAD // Delete any resources that need to be deleted after restarting with a different IWAD
virtual void CleanForRestart() {} virtual void CleanForRestart() {}
virtual void SetTextureFilterMode() {} virtual void SetTextureFilterMode() {}
@ -384,10 +381,11 @@ public:
virtual void FlushTextures() {} virtual void FlushTextures() {}
virtual void TextureFilterChanged() {} virtual void TextureFilterChanged() {}
virtual void ResetFixedColormap() {} virtual void ResetFixedColormap() {}
virtual void BeginFrame() {}
// Begin 2D drawing operations. // Begin 2D drawing operations.
// Returns true if hardware-accelerated 2D has been entered, false if not. // Returns true if hardware-accelerated 2D has been entered, false if not.
virtual void Begin2D(bool copy3d); void Begin2D(bool copy3d) { isIn2D = true; }
void End2D() { isIn2D = false; } void End2D() { isIn2D = false; }
// Returns true if Begin2D has been called and 2D drawing is now active // Returns true if Begin2D has been called and 2D drawing is now active