don't double buffer 3D framebuffers for the GL Renderer
looks like leftovers from when 3D+2D composition was done in the frontend
This commit is contained in:
parent
b11b5bf522
commit
d9c0834120
|
@ -232,29 +232,26 @@ std::unique_ptr<GLRenderer> GLRenderer::New() noexcept
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, result->IndexBufferID);
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, result->IndexBufferID);
|
||||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(IndexBuffer), nullptr, GL_DYNAMIC_DRAW);
|
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(IndexBuffer), nullptr, GL_DYNAMIC_DRAW);
|
||||||
|
|
||||||
glGenFramebuffers(4, &result->FramebufferID[0]);
|
glGenFramebuffers(1, &result->MainFramebuffer);
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, result->FramebufferID[0]);
|
|
||||||
|
|
||||||
glGenTextures(8, &result->FramebufferTex[0]);
|
|
||||||
result->FrontBuffer = 0;
|
|
||||||
|
|
||||||
// color buffers
|
// color buffers
|
||||||
SetupDefaultTexParams(result->FramebufferTex[0]);
|
glGenTextures(1, &result->ColorBufferTex);
|
||||||
SetupDefaultTexParams(result->FramebufferTex[1]);
|
SetupDefaultTexParams(result->ColorBufferTex);
|
||||||
|
|
||||||
// depth/stencil buffer
|
// depth/stencil buffer
|
||||||
SetupDefaultTexParams(result->FramebufferTex[4]);
|
glGenTextures(1, &result->DepthBufferTex);
|
||||||
SetupDefaultTexParams(result->FramebufferTex[6]);
|
SetupDefaultTexParams(result->DepthBufferTex);
|
||||||
|
|
||||||
// attribute buffer
|
// attribute buffer
|
||||||
// R: opaque polyID (for edgemarking)
|
// R: opaque polyID (for edgemarking)
|
||||||
// G: edge flag
|
// G: edge flag
|
||||||
// B: fog flag
|
// B: fog flag
|
||||||
SetupDefaultTexParams(result->FramebufferTex[5]);
|
glGenTextures(1, &result->AttrBufferTex);
|
||||||
SetupDefaultTexParams(result->FramebufferTex[7]);
|
SetupDefaultTexParams(result->AttrBufferTex);
|
||||||
|
|
||||||
// downscale framebuffer for display capture (always 256x192)
|
// downscale framebuffer for display capture (always 256x192)
|
||||||
SetupDefaultTexParams(result->FramebufferTex[3]);
|
glGenTextures(1, &result->DownScaleBufferTex);
|
||||||
|
SetupDefaultTexParams(result->DownScaleBufferTex);
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 256, 192, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 256, 192, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
|
||||||
|
|
||||||
glEnable(GL_BLEND);
|
glEnable(GL_BLEND);
|
||||||
|
@ -292,8 +289,12 @@ GLRenderer::~GLRenderer()
|
||||||
glDeleteTextures(1, &TexMemID);
|
glDeleteTextures(1, &TexMemID);
|
||||||
glDeleteTextures(1, &TexPalMemID);
|
glDeleteTextures(1, &TexPalMemID);
|
||||||
|
|
||||||
glDeleteFramebuffers(4, &FramebufferID[0]);
|
glDeleteFramebuffers(1, &MainFramebuffer);
|
||||||
glDeleteTextures(8, &FramebufferTex[0]);
|
glDeleteFramebuffers(1, &DownscaleFramebuffer);
|
||||||
|
glDeleteTextures(1, &ColorBufferTex);
|
||||||
|
glDeleteTextures(1, &DepthBufferTex);
|
||||||
|
glDeleteTextures(1, &AttrBufferTex);
|
||||||
|
glDeleteTextures(1, &DownScaleBufferTex);
|
||||||
|
|
||||||
glDeleteVertexArrays(1, &VertexArrayID);
|
glDeleteVertexArrays(1, &VertexArrayID);
|
||||||
glDeleteBuffers(1, &VertexBufferID);
|
glDeleteBuffers(1, &VertexBufferID);
|
||||||
|
@ -323,40 +324,25 @@ void GLRenderer::SetRenderSettings(GPU::RenderSettings& settings)
|
||||||
ScreenW = 256 * scale;
|
ScreenW = 256 * scale;
|
||||||
ScreenH = 192 * scale;
|
ScreenH = 192 * scale;
|
||||||
|
|
||||||
glBindTexture(GL_TEXTURE_2D, FramebufferTex[0]);
|
glBindTexture(GL_TEXTURE_2D, ColorBufferTex);
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, ScreenW, ScreenH, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
|
|
||||||
glBindTexture(GL_TEXTURE_2D, FramebufferTex[1]);
|
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, ScreenW, ScreenH, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, ScreenW, ScreenH, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
|
||||||
|
|
||||||
glBindTexture(GL_TEXTURE_2D, FramebufferTex[4]);
|
glBindTexture(GL_TEXTURE_2D, DepthBufferTex);
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH24_STENCIL8, ScreenW, ScreenH, 0, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, NULL);
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH24_STENCIL8, ScreenW, ScreenH, 0, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, NULL);
|
||||||
glBindTexture(GL_TEXTURE_2D, FramebufferTex[5]);
|
glBindTexture(GL_TEXTURE_2D, AttrBufferTex);
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, ScreenW, ScreenH, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, ScreenW, ScreenH, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
|
||||||
|
|
||||||
glBindTexture(GL_TEXTURE_2D, FramebufferTex[6]);
|
glBindFramebuffer(GL_FRAMEBUFFER, DownscaleFramebuffer);
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH24_STENCIL8, ScreenW, ScreenH, 0, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, NULL);
|
glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, DownScaleBufferTex, 0);
|
||||||
glBindTexture(GL_TEXTURE_2D, FramebufferTex[7]);
|
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, ScreenW, ScreenH, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
|
|
||||||
|
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, FramebufferID[3]);
|
|
||||||
glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, FramebufferTex[3], 0);
|
|
||||||
|
|
||||||
GLenum fbassign[2] = {GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1};
|
GLenum fbassign[2] = {GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1};
|
||||||
|
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, FramebufferID[0]);
|
glBindFramebuffer(GL_FRAMEBUFFER, MainFramebuffer);
|
||||||
glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, FramebufferTex[0], 0);
|
glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, ColorBufferTex, 0);
|
||||||
glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, FramebufferTex[4], 0);
|
glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, DepthBufferTex, 0);
|
||||||
glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, FramebufferTex[5], 0);
|
glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, AttrBufferTex, 0);
|
||||||
glDrawBuffers(2, fbassign);
|
glDrawBuffers(2, fbassign);
|
||||||
|
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, FramebufferID[1]);
|
|
||||||
glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, FramebufferTex[1], 0);
|
|
||||||
glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, FramebufferTex[6], 0);
|
|
||||||
glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, FramebufferTex[7], 0);
|
|
||||||
glDrawBuffers(2, fbassign);
|
|
||||||
|
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, FramebufferID[0]);
|
|
||||||
|
|
||||||
glBindBuffer(GL_PIXEL_PACK_BUFFER, PixelbufferID);
|
glBindBuffer(GL_PIXEL_PACK_BUFFER, PixelbufferID);
|
||||||
glBufferData(GL_PIXEL_PACK_BUFFER, 256*192*4, NULL, GL_DYNAMIC_READ);
|
glBufferData(GL_PIXEL_PACK_BUFFER, 256*192*4, NULL, GL_DYNAMIC_READ);
|
||||||
|
|
||||||
|
@ -1065,9 +1051,9 @@ void GLRenderer::RenderSceneChunk(int y, int h)
|
||||||
glStencilMask(0);
|
glStencilMask(0);
|
||||||
|
|
||||||
glActiveTexture(GL_TEXTURE0);
|
glActiveTexture(GL_TEXTURE0);
|
||||||
glBindTexture(GL_TEXTURE_2D, FramebufferTex[FrontBuffer ? 6 : 4]);
|
glBindTexture(GL_TEXTURE_2D, DepthBufferTex);
|
||||||
glActiveTexture(GL_TEXTURE1);
|
glActiveTexture(GL_TEXTURE1);
|
||||||
glBindTexture(GL_TEXTURE_2D, FramebufferTex[FrontBuffer ? 7 : 5]);
|
glBindTexture(GL_TEXTURE_2D, AttrBufferTex);
|
||||||
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, ClearVertexBufferID);
|
glBindBuffer(GL_ARRAY_BUFFER, ClearVertexBufferID);
|
||||||
glBindVertexArray(ClearVertexArrayID);
|
glBindVertexArray(ClearVertexArrayID);
|
||||||
|
@ -1116,7 +1102,7 @@ void GLRenderer::RenderFrame()
|
||||||
CurShaderID = -1;
|
CurShaderID = -1;
|
||||||
|
|
||||||
glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
|
glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
|
||||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, FramebufferID[FrontBuffer]);
|
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, MainFramebuffer);
|
||||||
|
|
||||||
ShaderConfig.uScreenSize[0] = ScreenW;
|
ShaderConfig.uScreenSize[0] = ScreenW;
|
||||||
ShaderConfig.uScreenSize[1] = ScreenH;
|
ShaderConfig.uScreenSize[1] = ScreenH;
|
||||||
|
@ -1282,22 +1268,17 @@ void GLRenderer::RenderFrame()
|
||||||
|
|
||||||
RenderSceneChunk(0, 192);
|
RenderSceneChunk(0, 192);
|
||||||
}
|
}
|
||||||
|
|
||||||
FrontBuffer = FrontBuffer ? 0 : 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLRenderer::PrepareCaptureFrame()
|
void GLRenderer::PrepareCaptureFrame()
|
||||||
{
|
{
|
||||||
// TODO: make sure this picks the right buffer when doing antialiasing
|
glBindFramebuffer(GL_READ_FRAMEBUFFER, MainFramebuffer);
|
||||||
int original_fb = FrontBuffer^1;
|
|
||||||
|
|
||||||
glBindFramebuffer(GL_READ_FRAMEBUFFER, FramebufferID[original_fb]);
|
|
||||||
glReadBuffer(GL_COLOR_ATTACHMENT0);
|
glReadBuffer(GL_COLOR_ATTACHMENT0);
|
||||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, FramebufferID[3]);
|
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, DownscaleFramebuffer);
|
||||||
glDrawBuffer(GL_COLOR_ATTACHMENT0);
|
glDrawBuffer(GL_COLOR_ATTACHMENT0);
|
||||||
glBlitFramebuffer(0, 0, ScreenW, ScreenH, 0, 0, 256, 192, GL_COLOR_BUFFER_BIT, GL_NEAREST);
|
glBlitFramebuffer(0, 0, ScreenW, ScreenH, 0, 0, 256, 192, GL_COLOR_BUFFER_BIT, GL_NEAREST);
|
||||||
|
|
||||||
glBindFramebuffer(GL_READ_FRAMEBUFFER, FramebufferID[3]);
|
glBindFramebuffer(GL_READ_FRAMEBUFFER, DownscaleFramebuffer);
|
||||||
glReadPixels(0, 0, 256, 192, GL_BGRA, GL_UNSIGNED_BYTE, NULL);
|
glReadPixels(0, 0, 256, 192, GL_BGRA, GL_UNSIGNED_BYTE, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1326,7 +1307,7 @@ u32* GLRenderer::GetLine(int line)
|
||||||
|
|
||||||
void GLRenderer::SetupAccelFrame()
|
void GLRenderer::SetupAccelFrame()
|
||||||
{
|
{
|
||||||
glBindTexture(GL_TEXTURE_2D, FramebufferTex[FrontBuffer]);
|
glBindTexture(GL_TEXTURE_2D, ColorBufferTex);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -143,11 +143,11 @@ private:
|
||||||
bool BetterPolygons {};
|
bool BetterPolygons {};
|
||||||
int ScreenW {}, ScreenH {};
|
int ScreenW {}, ScreenH {};
|
||||||
|
|
||||||
GLuint FramebufferTex[8] {};
|
GLuint ColorBufferTex {}, DepthBufferTex {}, AttrBufferTex {};
|
||||||
int FrontBuffer {};
|
GLuint DownScaleBufferTex {};
|
||||||
GLuint FramebufferID[4] {}, PixelbufferID {};
|
GLuint PixelbufferID {};
|
||||||
|
|
||||||
|
GLuint MainFramebuffer {}, DownscaleFramebuffer {};
|
||||||
u32 Framebuffer[256*192] {};
|
u32 Framebuffer[256*192] {};
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
|
@ -181,9 +181,9 @@ void GLCompositor::Stop()
|
||||||
|
|
||||||
void GLCompositor::RenderFrame()
|
void GLCompositor::RenderFrame()
|
||||||
{
|
{
|
||||||
int frontbuf = GPU::FrontBuffer;
|
int backbuf = GPU::FrontBuffer ^ 1;
|
||||||
glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
|
glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
|
||||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, CompScreenOutputFB[frontbuf]);
|
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, CompScreenOutputFB[backbuf]);
|
||||||
|
|
||||||
glDisable(GL_DEPTH_TEST);
|
glDisable(GL_DEPTH_TEST);
|
||||||
glDisable(GL_STENCIL_TEST);
|
glDisable(GL_STENCIL_TEST);
|
||||||
|
@ -204,12 +204,12 @@ void GLCompositor::RenderFrame()
|
||||||
glActiveTexture(GL_TEXTURE0);
|
glActiveTexture(GL_TEXTURE0);
|
||||||
glBindTexture(GL_TEXTURE_2D, CompScreenInputTex);
|
glBindTexture(GL_TEXTURE_2D, CompScreenInputTex);
|
||||||
|
|
||||||
if (GPU::Framebuffer[frontbuf][0] && GPU::Framebuffer[frontbuf][1])
|
if (GPU::Framebuffer[backbuf][0] && GPU::Framebuffer[backbuf][1])
|
||||||
{
|
{
|
||||||
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 256*3 + 1, 192, GL_RGBA_INTEGER,
|
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 256*3 + 1, 192, GL_RGBA_INTEGER,
|
||||||
GL_UNSIGNED_BYTE, GPU::Framebuffer[frontbuf][0]);
|
GL_UNSIGNED_BYTE, GPU::Framebuffer[backbuf][0]);
|
||||||
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 192, 256*3 + 1, 192, GL_RGBA_INTEGER,
|
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 192, 256*3 + 1, 192, GL_RGBA_INTEGER,
|
||||||
GL_UNSIGNED_BYTE, GPU::Framebuffer[frontbuf][1]);
|
GL_UNSIGNED_BYTE, GPU::Framebuffer[backbuf][1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
glActiveTexture(GL_TEXTURE1);
|
glActiveTexture(GL_TEXTURE1);
|
||||||
|
|
Loading…
Reference in New Issue