Skip to content

Commit a19830d

Browse files
committed
Access current/last render target via functions
To make it easier for functionality like screenshot capture and frame rendering to use the correct render target this change introduces two functions for use inside the renderer to borrow the currently presented render target and a render target suitable for drawing.
1 parent 644b353 commit a19830d

2 files changed

Lines changed: 18 additions & 6 deletions

File tree

engine/render/r_main.cpp

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1372,8 +1372,7 @@ void r_renderer_c::EndFrame()
13721372
bool decideDraw = false;
13731373
bool elideDraw = false;
13741374
{
1375-
int drawRtt = 1 - presentRtt;
1376-
glBindFramebuffer(GL_FRAMEBUFFER, rttMain[drawRtt].framebuffer);
1375+
glBindFramebuffer(GL_FRAMEBUFFER, GetDrawRenderTarget().framebuffer);
13771376
glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
13781377
int l{};
13791378
for (l = 0; l < numLayer; l++) {
@@ -1402,7 +1401,7 @@ void r_renderer_c::EndFrame()
14021401
layer->Render();
14031402
}
14041403
if (!elideDraw) {
1405-
presentRtt = drawRtt;
1404+
presentRtt = 1 - presentRtt;
14061405
++drawnFrames;
14071406
}
14081407
}
@@ -1422,7 +1421,7 @@ void r_renderer_c::EndFrame()
14221421
delete[] layerSort;
14231422

14241423
{
1425-
auto rtt = rttMain[presentRtt];
1424+
auto& rtt = GetPresentRenderTarget();
14261425
glBindFramebuffer(GL_FRAMEBUFFER, 0);
14271426
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
14281427
glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
@@ -1833,7 +1832,7 @@ void r_renderer_c::DoScreenshot(image_c* i, const char* ext)
18331832
if (i->type != IMGTYPE_RGB) {
18341833
return;
18351834
}
1836-
auto& rt = rttMain[presentRtt];
1835+
auto& rt = GetPresentRenderTarget();
18371836
int const xs = rt.width;
18381837
int const ys = rt.height;
18391838

@@ -1848,7 +1847,7 @@ void r_renderer_c::DoScreenshot(image_c* i, const char* ext)
18481847
GLenum oglErr = glGetError();
18491848
GLenum implColorReadFormat{}, implColorReadType{};
18501849
glGetIntegerv(GL_FRAMEBUFFER_BINDING, &oldFb);
1851-
glBindFramebuffer(GL_FRAMEBUFFER, rttMain[presentRtt].framebuffer);
1850+
glBindFramebuffer(GL_FRAMEBUFFER, rt.framebuffer);
18521851
glPixelStorei(GL_PACK_ALIGNMENT, 1);
18531852
glReadPixels(0, 0, xs, ys, GL_RGBA, GL_UNSIGNED_BYTE, sbuf.data());
18541853
oglErr = glGetError();
@@ -1895,6 +1894,16 @@ void r_renderer_c::DoScreenshot(image_c* i, const char* ext)
18951894
}
18961895
}
18971896

1897+
r_renderer_c::RenderTarget& r_renderer_c::GetDrawRenderTarget()
1898+
{
1899+
return rttMain[1 - presentRtt];
1900+
}
1901+
1902+
r_renderer_c::RenderTarget& r_renderer_c::GetPresentRenderTarget()
1903+
{
1904+
return rttMain[presentRtt];
1905+
}
1906+
18981907
// ============================================
18991908
// MurmurHash implementation from public domain
19001909
// ============================================

engine/render/r_main.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,4 +205,7 @@ class r_renderer_c: public r_IRenderer, public conCmdHandler_c {
205205
void DoScreenshot(image_c* i, const char* ext);
206206

207207
void C_Screenshot(IConsole* conHnd, args_c &args);
208+
209+
RenderTarget& GetDrawRenderTarget();
210+
RenderTarget& GetPresentRenderTarget();
208211
};

0 commit comments

Comments
 (0)