mirror of
https://github.com/ZDoom/gzdoom.git
synced 2024-11-11 15:21:51 +00:00
- moved some buffer variables out of GLRenderer into common parts of the code so that they can be accessed from hwrenderer as well.
This will allow more code to be moved out of the API dependent parts.
This commit is contained in:
parent
c5b3b9e107
commit
f7c7c8d1c5
12 changed files with 66 additions and 104 deletions
|
@ -52,7 +52,7 @@ CVAR(Int, gl_dither_bpc, 0, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_NOINITCALL)
|
|||
|
||||
void FGLRenderer::RenderScreenQuad()
|
||||
{
|
||||
mVBO->Bind(gl_RenderState);
|
||||
screen->mVertexData->Bind(gl_RenderState);
|
||||
gl_RenderState.ApplyBuffers();
|
||||
glDrawArrays(GL_TRIANGLE_STRIP, FFlatVertexBuffer::PRESENT_INDEX, 4);
|
||||
}
|
||||
|
|
|
@ -102,15 +102,10 @@ void FGLRenderer::Initialize(int width, int height)
|
|||
glBindVertexArray(mVAOID);
|
||||
FGLDebug::LabelObject(GL_VERTEX_ARRAY, mVAOID, "FGLRenderer.mVAOID");
|
||||
|
||||
mVBO = new FFlatVertexBuffer(width, height);
|
||||
mSkyVBO = new FSkyVertexBuffer;
|
||||
mLights = new FLightBuffer();
|
||||
mViewpoints = new GLViewpointBuffer;
|
||||
GLRenderer->mVBO->Bind(gl_RenderState);
|
||||
mFBID = 0;
|
||||
mOldFBID = 0;
|
||||
|
||||
SetupLevel();
|
||||
mShaderManager = new FShaderManager;
|
||||
mSamplerManager = new FSamplerManager;
|
||||
}
|
||||
|
@ -122,10 +117,7 @@ FGLRenderer::~FGLRenderer()
|
|||
FMaterial::FlushAll();
|
||||
if (mShaderManager != nullptr) delete mShaderManager;
|
||||
if (mSamplerManager != nullptr) delete mSamplerManager;
|
||||
if (mVBO != nullptr) delete mVBO;
|
||||
if (mSkyVBO != nullptr) delete mSkyVBO;
|
||||
if (mLights != nullptr) delete mLights;
|
||||
if (mViewpoints != nullptr) delete mViewpoints;
|
||||
if (mFBID != 0) glDeleteFramebuffers(1, &mFBID);
|
||||
if (mVAOID != 0)
|
||||
{
|
||||
|
@ -160,7 +152,7 @@ void FGLRenderer::ResetSWScene()
|
|||
|
||||
void FGLRenderer::SetupLevel()
|
||||
{
|
||||
mVBO->CreateVBO();
|
||||
screen->mVertexData->CreateVBO();
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
|
@ -200,8 +192,8 @@ void FGLRenderer::EndOffscreen()
|
|||
|
||||
sector_t *FGLRenderer::RenderView(player_t* player)
|
||||
{
|
||||
GLRenderer->mVBO->Bind(gl_RenderState);
|
||||
mVBO->Reset();
|
||||
screen->mVertexData->Bind(gl_RenderState);
|
||||
screen->mVertexData->Reset();
|
||||
sector_t *retsec;
|
||||
|
||||
if (!V_IsHardwareRenderer())
|
||||
|
@ -223,7 +215,7 @@ sector_t *FGLRenderer::RenderView(player_t* player)
|
|||
P_FindParticleSubsectors();
|
||||
|
||||
mLights->Clear();
|
||||
mViewpoints->Clear();
|
||||
screen->mViewpoints->Clear();
|
||||
|
||||
// NoInterpolateView should have no bearing on camera textures, but needs to be preserved for the main view below.
|
||||
bool saved_niv = NoInterpolateView;
|
||||
|
@ -315,17 +307,17 @@ void FGLRenderer::WriteSavePic (player_t *player, FileWriter *file, int width, i
|
|||
bounds.width = width;
|
||||
bounds.height = height;
|
||||
|
||||
// if mVBO is persistently mapped we must be sure the GPU finished reading from it before we fill it with new data.
|
||||
// we must be sure the GPU finished reading from the buffer before we fill it with new data.
|
||||
glFinish();
|
||||
|
||||
// Switch to render buffers dimensioned for the savepic
|
||||
mBuffers = mSaveBuffers;
|
||||
|
||||
P_FindParticleSubsectors(); // make sure that all recently spawned particles have a valid subsector.
|
||||
GLRenderer->mVBO->Bind(gl_RenderState);
|
||||
mVBO->Reset();
|
||||
screen->mVertexData->Bind(gl_RenderState);
|
||||
screen->mVertexData->Reset();
|
||||
mLights->Clear();
|
||||
mViewpoints->Clear();
|
||||
screen->mViewpoints->Clear();
|
||||
|
||||
// This shouldn't overwrite the global viewpoint even for a short time.
|
||||
FRenderViewpoint savevp;
|
||||
|
@ -422,7 +414,7 @@ void FGLRenderer::Draw2D(F2DDrawer *drawer)
|
|||
FDrawInfo di; // For access to the virtual interface. This should be placed elsewhere...
|
||||
const auto &mScreenViewport = screen->mScreenViewport;
|
||||
glViewport(mScreenViewport.left, mScreenViewport.top, mScreenViewport.width, mScreenViewport.height);
|
||||
GLRenderer->mViewpoints->Set2D(&di, screen->GetWidth(), screen->GetHeight());
|
||||
screen->mViewpoints->Set2D(&di, screen->GetWidth(), screen->GetHeight());
|
||||
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
|
||||
|
@ -543,7 +535,7 @@ void FGLRenderer::Draw2D(F2DDrawer *drawer)
|
|||
glDisable(GL_SCISSOR_TEST);
|
||||
|
||||
gl_RenderState.SetRenderStyle(STYLE_Translucent);
|
||||
GLRenderer->mVBO->Bind(gl_RenderState);
|
||||
screen->mVertexData->Bind(gl_RenderState);
|
||||
gl_RenderState.EnableTexture(true);
|
||||
gl_RenderState.EnableBrightmap(true);
|
||||
gl_RenderState.SetTextureMode(TM_NORMAL);
|
||||
|
|
|
@ -69,10 +69,7 @@ public:
|
|||
|
||||
//FRotator mAngles;
|
||||
|
||||
FFlatVertexBuffer *mVBO = nullptr;
|
||||
FSkyVertexBuffer *mSkyVBO = nullptr;
|
||||
FLightBuffer *mLights = nullptr;
|
||||
GLViewpointBuffer *mViewpoints = nullptr;
|
||||
SWSceneDrawer *swdrawer = nullptr;
|
||||
|
||||
float mSceneClearColor[3];
|
||||
|
|
|
@ -71,22 +71,16 @@ void FDrawInfo::DrawSorted(int listindex)
|
|||
|
||||
if (!dl->sorted)
|
||||
{
|
||||
GLRenderer->mVBO->Map();
|
||||
screen->mVertexData->Map();
|
||||
dl->Sort(this);
|
||||
GLRenderer->mVBO->Unmap();
|
||||
screen->mVertexData->Unmap();
|
||||
}
|
||||
gl_RenderState.ClearClipSplit();
|
||||
if (!(gl.flags & RFL_NO_CLIP_PLANES))
|
||||
{
|
||||
glEnable(GL_CLIP_DISTANCE1);
|
||||
glEnable(GL_CLIP_DISTANCE2);
|
||||
}
|
||||
EnableClipDistance(1, true);
|
||||
EnableClipDistance(2, true);
|
||||
dl->DrawSorted(this, gl_RenderState, dl->sorted);
|
||||
if (!(gl.flags & RFL_NO_CLIP_PLANES))
|
||||
{
|
||||
glDisable(GL_CLIP_DISTANCE1);
|
||||
glDisable(GL_CLIP_DISTANCE2);
|
||||
}
|
||||
EnableClipDistance(1, false);
|
||||
EnableClipDistance(2, false);
|
||||
gl_RenderState.ClearClipSplit();
|
||||
}
|
||||
|
||||
|
@ -128,7 +122,6 @@ static Clipper staticClipper;
|
|||
FDrawInfo *FDrawInfo::StartDrawInfo(FRenderViewpoint &parentvp, HWViewpointUniforms *uniforms)
|
||||
{
|
||||
FDrawInfo *di=di_list.GetNew();
|
||||
di->mVBO = GLRenderer->mVBO;
|
||||
di->mClipper = &staticClipper;
|
||||
di->Viewpoint = parentvp;
|
||||
if (uniforms)
|
||||
|
@ -193,7 +186,7 @@ void FDrawInfo::AddSubsectorToPortal(FSectorPortalGroup *ptg, subsector_t *sub)
|
|||
std::pair<FFlatVertex *, unsigned int> FDrawInfo::AllocVertices(unsigned int count)
|
||||
{
|
||||
unsigned int index = -1;
|
||||
auto p = GLRenderer->mVBO->Alloc(count, &index);
|
||||
auto p = screen->mVertexData->Alloc(count, &index);
|
||||
return std::make_pair(p, index);
|
||||
}
|
||||
|
||||
|
@ -243,14 +236,14 @@ void FDrawInfo::DrawModel(GLSprite *spr, FRenderState &state)
|
|||
{
|
||||
FGLModelRenderer renderer(this, state, spr->dynlightindex);
|
||||
renderer.RenderModel(spr->x, spr->y, spr->z, spr->modelframe, spr->actor, Viewpoint.TicFrac);
|
||||
GLRenderer->mVBO->Bind(state);
|
||||
screen->mVertexData->Bind(state);
|
||||
}
|
||||
|
||||
void FDrawInfo::DrawHUDModel(HUDSprite *huds, FRenderState &state)
|
||||
{
|
||||
FGLModelRenderer renderer(this, state, huds->lightindex);
|
||||
renderer.RenderHUDModel(huds->weapon, huds->mx, huds->my);
|
||||
GLRenderer->mVBO->Bind(state);
|
||||
screen->mVertexData->Bind(state);
|
||||
}
|
||||
|
||||
void FDrawInfo::RenderPortal(HWPortal *p, bool usestencil)
|
||||
|
@ -262,8 +255,8 @@ void FDrawInfo::RenderPortal(HWPortal *p, bool usestencil)
|
|||
gl_RenderState.SetLightIndex(-1);
|
||||
gp->DrawContents(new_di, gl_RenderState);
|
||||
new_di->EndDrawInfo();
|
||||
GLRenderer->mVBO->Bind(gl_RenderState);
|
||||
GLRenderer->mViewpoints->Bind(this, vpIndex);
|
||||
screen->mVertexData->Bind(gl_RenderState);
|
||||
screen->mViewpoints->Bind(this, vpIndex);
|
||||
gp->RemoveStencil(this, gl_RenderState, usestencil);
|
||||
|
||||
}
|
||||
|
@ -345,7 +338,7 @@ void FDrawInfo::ClearScreen()
|
|||
{
|
||||
bool multi = !!glIsEnabled(GL_MULTISAMPLE);
|
||||
|
||||
GLRenderer->mViewpoints->Set2D(this, SCREENWIDTH, SCREENHEIGHT);
|
||||
screen->mViewpoints->Set2D(this, SCREENWIDTH, SCREENHEIGHT);
|
||||
gl_RenderState.SetColor(0, 0, 0);
|
||||
gl_RenderState.Apply();
|
||||
|
||||
|
|
|
@ -78,7 +78,7 @@ EXTERN_CVAR (Bool, r_drawvoxels)
|
|||
void FDrawInfo::ApplyVPUniforms()
|
||||
{
|
||||
VPUniforms.CalcDependencies();
|
||||
vpIndex = GLRenderer->mViewpoints->SetViewpoint(this, &VPUniforms);
|
||||
vpIndex = screen->mViewpoints->SetViewpoint(this, &VPUniforms);
|
||||
}
|
||||
|
||||
|
||||
|
@ -104,7 +104,7 @@ void FDrawInfo::CreateScene()
|
|||
|
||||
// clip the scene and fill the drawlists
|
||||
Bsp.Clock();
|
||||
GLRenderer->mVBO->Map();
|
||||
screen->mVertexData->Map();
|
||||
GLRenderer->mLights->Begin();
|
||||
|
||||
// Give the DrawInfo the viewpoint in fixed point because that's what the nodes are.
|
||||
|
@ -131,7 +131,7 @@ void FDrawInfo::CreateScene()
|
|||
ProcessSectorStacks(in_area); // merge visplanes of sector stacks
|
||||
PrepareUnhandledMissingTextures();
|
||||
GLRenderer->mLights->Finish();
|
||||
GLRenderer->mVBO->Unmap();
|
||||
screen->mVertexData->Unmap();
|
||||
|
||||
ProcessAll.Unclock();
|
||||
|
||||
|
@ -280,7 +280,7 @@ void FDrawInfo::DrawScene(int drawmode)
|
|||
GLRenderer->mBuffers->BindSceneFB(true);
|
||||
gl_RenderState.EnableDrawBuffers(gl_RenderState.GetPassDrawBufferCount());
|
||||
gl_RenderState.Apply();
|
||||
GLRenderer->mViewpoints->Bind(this, vpIndex);
|
||||
screen->mViewpoints->Bind(this, vpIndex);
|
||||
}
|
||||
|
||||
// Handle all portals after rendering the opaque objects but before
|
||||
|
@ -329,7 +329,7 @@ void FDrawInfo::DrawEndScene2D(sector_t * viewsector)
|
|||
HWViewpointUniforms vp = VPUniforms;
|
||||
vp.mViewMatrix.loadIdentity();
|
||||
vp.mProjectionMatrix = vrmode->GetHUDSpriteProjection();
|
||||
GLRenderer->mViewpoints->SetViewpoint(this, &vp);
|
||||
screen->mViewpoints->SetViewpoint(this, &vp);
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glDisable(GL_MULTISAMPLE);
|
||||
|
||||
|
|
|
@ -39,6 +39,8 @@
|
|||
#include "hwrenderer/utility/hw_clock.h"
|
||||
#include "hwrenderer/utility/hw_vrmodes.h"
|
||||
#include "hwrenderer/models/hw_models.h"
|
||||
#include "hwrenderer/scene/hw_skydome.h"
|
||||
#include "hwrenderer/data/hw_viewpointbuffer.h"
|
||||
#include "gl/shaders/gl_shaderprogram.h"
|
||||
#include "gl_debug.h"
|
||||
#include "r_videoscale.h"
|
||||
|
@ -82,6 +84,10 @@ OpenGLFrameBuffer::OpenGLFrameBuffer(void *hMonitor, bool fullscreen) :
|
|||
|
||||
OpenGLFrameBuffer::~OpenGLFrameBuffer()
|
||||
{
|
||||
if (mVertexData != nullptr) delete mVertexData;
|
||||
if (mSkyData != nullptr) delete mSkyData;
|
||||
if (mViewpoints != nullptr) delete mViewpoints;
|
||||
|
||||
if (GLRenderer)
|
||||
{
|
||||
delete GLRenderer;
|
||||
|
@ -140,6 +146,10 @@ void OpenGLFrameBuffer::InitializeState()
|
|||
GLRenderer->Initialize(GetWidth(), GetHeight());
|
||||
SetViewportRects(nullptr);
|
||||
|
||||
mVertexData = new FFlatVertexBuffer(GetWidth(), GetHeight());
|
||||
mSkyData = new FSkyVertexBuffer;
|
||||
mViewpoints = new GLViewpointBuffer;
|
||||
|
||||
mDebug = std::make_shared<FGLDebug>();
|
||||
mDebug->Update();
|
||||
}
|
||||
|
@ -160,20 +170,7 @@ void OpenGLFrameBuffer::Update()
|
|||
Flush3D.Unclock();
|
||||
|
||||
Swap();
|
||||
CheckBench();
|
||||
|
||||
int initialWidth = GetClientWidth();
|
||||
int initialHeight = GetClientHeight();
|
||||
int clientWidth = ViewportScaledWidth(initialWidth, initialHeight);
|
||||
int clientHeight = ViewportScaledHeight(initialWidth, initialHeight);
|
||||
if (clientWidth < 320) clientWidth = 320;
|
||||
if (clientHeight < 200) clientHeight = 200;
|
||||
if (clientWidth > 0 && clientHeight > 0 && (GetWidth() != clientWidth || GetHeight() != clientHeight))
|
||||
{
|
||||
SetVirtualSize(clientWidth, clientHeight);
|
||||
V_OutputResized(clientWidth, clientHeight);
|
||||
GLRenderer->mVBO->OutputResized(clientWidth, clientHeight);
|
||||
}
|
||||
Super::Update();
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
|
|
|
@ -458,7 +458,7 @@ void HWDrawInfo::DoSubsector(subsector_t * sub)
|
|||
{
|
||||
int a = 0;
|
||||
}
|
||||
mVBO->CheckUpdate(sector);
|
||||
screen->mVertexData->CheckUpdate(sector);
|
||||
}
|
||||
|
||||
// [RH] Add particles
|
||||
|
|
|
@ -199,7 +199,6 @@ struct HWDrawInfo
|
|||
BitArray CurrentMapSections; // this cannot be a single number, because a group of portals with the same displacement may link different sections.
|
||||
area_t in_area;
|
||||
fixed_t viewx, viewy; // since the nodes are still fixed point, keeping the view position also fixed point for node traversal is faster.
|
||||
FFlatVertexBuffer *mVBO; // this class needs access because the sector vertex updating is part of BSP traversal.
|
||||
|
||||
|
||||
private:
|
||||
|
|
|
@ -84,7 +84,6 @@ EXTERN_CVAR(Float, skyoffset)
|
|||
|
||||
FSkyVertexBuffer::FSkyVertexBuffer()
|
||||
{
|
||||
screen->mSkyData = this;
|
||||
CreateDome();
|
||||
mVertexBuffer = screen->CreateVertexBuffer();
|
||||
|
||||
|
@ -103,17 +102,6 @@ FSkyVertexBuffer::FSkyVertexBuffer()
|
|||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
FSkyVertexBuffer::~FSkyVertexBuffer()
|
||||
{
|
||||
if (screen && screen->mSkyData) screen->mSkyData = nullptr;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void FSkyVertexBuffer::Bind(FRenderState &state)
|
||||
{
|
||||
state.SetVertexBuffer(mVertexBuffer, 0, 0);
|
||||
|
|
|
@ -67,7 +67,6 @@ public:
|
|||
public:
|
||||
|
||||
FSkyVertexBuffer();
|
||||
virtual ~FSkyVertexBuffer();
|
||||
void SetupMatrices(FMaterial *tex, float x_offset, float y_offset, bool mirror, int mode, VSMatrix &modelmatrix, VSMatrix &textureMatrix);
|
||||
void Bind(FRenderState &state);
|
||||
|
||||
|
|
|
@ -49,6 +49,8 @@
|
|||
#include "r_videoscale.h"
|
||||
#include "i_time.h"
|
||||
#include "hwrenderer/scene/hw_portal.h"
|
||||
#include "hwrenderer/utility/hw_clock.h"
|
||||
#include "hwrenderer/data/flatvertices.h"
|
||||
|
||||
|
||||
CVAR(Bool, gl_scale_viewport, true, CVAR_ARCHIVE);
|
||||
|
@ -286,6 +288,24 @@ void DFrameBuffer::GetFlashedPalette(PalEntry pal[256])
|
|||
DoBlending(SourcePalette, pal, 256, Flash.r, Flash.g, Flash.b, Flash.a);
|
||||
}
|
||||
|
||||
void DFrameBuffer::Update()
|
||||
{
|
||||
CheckBench();
|
||||
|
||||
int initialWidth = GetClientWidth();
|
||||
int initialHeight = GetClientHeight();
|
||||
int clientWidth = ViewportScaledWidth(initialWidth, initialHeight);
|
||||
int clientHeight = ViewportScaledHeight(initialWidth, initialHeight);
|
||||
if (clientWidth < 320) clientWidth = 320;
|
||||
if (clientHeight < 200) clientHeight = 200;
|
||||
if (clientWidth > 0 && clientHeight > 0 && (GetWidth() != clientWidth || GetHeight() != clientHeight))
|
||||
{
|
||||
SetVirtualSize(clientWidth, clientHeight);
|
||||
V_OutputResized(clientWidth, clientHeight);
|
||||
mVertexData->OutputResized(clientWidth, clientHeight);
|
||||
}
|
||||
}
|
||||
|
||||
PalEntry *DFrameBuffer::GetPalette()
|
||||
{
|
||||
return SourcePalette;
|
||||
|
@ -533,30 +553,3 @@ void DFrameBuffer::ScaleCoordsFromWindow(int16_t &x, int16_t &y)
|
|||
x = int16_t((x - letterboxX) * Width / letterboxWidth);
|
||||
y = int16_t((y - letterboxY) * Height / letterboxHeight);
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
//
|
||||
//
|
||||
//===========================================================================
|
||||
|
||||
#define DBGBREAK assert(0)
|
||||
|
||||
class DDummyFrameBuffer : public DFrameBuffer
|
||||
{
|
||||
typedef DFrameBuffer Super;
|
||||
public:
|
||||
DDummyFrameBuffer(int width, int height)
|
||||
: DFrameBuffer(0, 0)
|
||||
{
|
||||
SetVirtualSize(width, height);
|
||||
}
|
||||
// These methods should never be called.
|
||||
void Update() { DBGBREAK; }
|
||||
bool IsFullscreen() { DBGBREAK; return 0; }
|
||||
int GetClientWidth() { DBGBREAK; return 0; }
|
||||
int GetClientHeight() { DBGBREAK; return 0; }
|
||||
|
||||
float Gamma;
|
||||
};
|
||||
|
||||
|
|
|
@ -53,6 +53,8 @@ class FSkyVertexBuffer;
|
|||
class IIndexBuffer;
|
||||
class IVertexBuffer;
|
||||
class IDataBuffer;
|
||||
class FFlatVertexBuffer;
|
||||
class GLViewpointBuffer;
|
||||
|
||||
enum EHWCaps
|
||||
{
|
||||
|
@ -373,7 +375,9 @@ public:
|
|||
bool enable_quadbuffered = false; // Quad-buffered stereo available?
|
||||
unsigned int uniformblockalignment = 256; // Hardware dependent uniform buffer alignment.
|
||||
FPortalSceneState *mPortalState; // global portal state.
|
||||
FSkyVertexBuffer *mSkyData; // we need access to this in the device independent part, but cannot depend on how the renderer manages it internally.
|
||||
FSkyVertexBuffer *mSkyData = nullptr; // the sky vertex buffer
|
||||
FFlatVertexBuffer *mVertexData = nullptr; // Global vertex data
|
||||
GLViewpointBuffer *mViewpoints = nullptr; // Viewpoint render data.
|
||||
|
||||
IntRect mScreenViewport;
|
||||
IntRect mSceneViewport;
|
||||
|
@ -404,7 +408,7 @@ public:
|
|||
}
|
||||
|
||||
// Make the surface visible.
|
||||
virtual void Update () = 0;
|
||||
virtual void Update ();
|
||||
|
||||
// Return a pointer to 256 palette entries that can be written to.
|
||||
PalEntry *GetPalette ();
|
||||
|
|
Loading…
Reference in a new issue