mirror of
https://github.com/blawar/GLideN64.git
synced 2024-07-04 10:03:36 +00:00
Refactor: Make frame buffer singleton
This commit is contained in:
parent
954d5c3552
commit
bd8b73d5b5
|
@ -150,6 +150,7 @@ void DepthBuffer_Destroy()
|
|||
|
||||
void DepthBuffer_SetBuffer( u32 address )
|
||||
{
|
||||
FrameBufferList & frameBuffer = frameBufferList();
|
||||
FrameBuffer * pFrameBuffer = FrameBuffer_FindBuffer(address);
|
||||
if (pFrameBuffer == NULL)
|
||||
pFrameBuffer = frameBuffer.top;
|
||||
|
@ -232,6 +233,6 @@ void DepthBuffer_ClearBuffer() {
|
|||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, current->fbo);
|
||||
OGL_DrawRect(0,0,VI.width, VI.height, color);
|
||||
glBindImageTexture(depthImageUnit, current->depth_texture->glName, 0, GL_FALSE, 0, GL_READ_WRITE, GL_RGBA32F);
|
||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, frameBuffer.top->fbo);
|
||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, frameBufferList().top->fbo);
|
||||
#endif // GLES2
|
||||
}
|
||||
|
|
|
@ -22,8 +22,6 @@ const GLint monohromeInternalformat = GL_LUMINANCE;
|
|||
const GLenum monohromeformat = GL_LUMINANCE;
|
||||
#endif // GLES2
|
||||
|
||||
FrameBufferList frameBuffer;
|
||||
|
||||
#ifndef GLES2
|
||||
class FrameBufferToRDRAM
|
||||
{
|
||||
|
@ -118,6 +116,7 @@ RDRAMtoFrameBuffer g_RDRAMtoFB;
|
|||
|
||||
void FrameBuffer_Init()
|
||||
{
|
||||
FrameBufferList & frameBuffer = frameBufferList();
|
||||
frameBuffer.current = NULL;
|
||||
frameBuffer.top = NULL;
|
||||
frameBuffer.bottom = NULL;
|
||||
|
@ -132,6 +131,7 @@ void FrameBuffer_Init()
|
|||
|
||||
void FrameBuffer_RemoveBottom()
|
||||
{
|
||||
FrameBufferList & frameBuffer = frameBufferList();
|
||||
FrameBuffer *newBottom = frameBuffer.bottom->higher;
|
||||
|
||||
textureCache().removeFrameBufferTexture(frameBuffer.bottom->texture);
|
||||
|
@ -153,6 +153,7 @@ void FrameBuffer_RemoveBottom()
|
|||
|
||||
void FrameBuffer_Remove( FrameBuffer *buffer )
|
||||
{
|
||||
FrameBufferList & frameBuffer = frameBufferList();
|
||||
if ((buffer == frameBuffer.bottom) &&
|
||||
(buffer == frameBuffer.top))
|
||||
{
|
||||
|
@ -191,7 +192,7 @@ void FrameBuffer_Remove( FrameBuffer *buffer )
|
|||
|
||||
void FrameBuffer_RemoveBuffer( u32 address )
|
||||
{
|
||||
FrameBuffer *current = frameBuffer.bottom;
|
||||
FrameBuffer *current = frameBufferList().bottom;
|
||||
|
||||
while (current != NULL)
|
||||
{
|
||||
|
@ -207,6 +208,7 @@ void FrameBuffer_RemoveBuffer( u32 address )
|
|||
|
||||
FrameBuffer *FrameBuffer_AddTop()
|
||||
{
|
||||
FrameBufferList & frameBuffer = frameBufferList();
|
||||
FrameBuffer *newtop = (FrameBuffer*)malloc( sizeof( FrameBuffer ) );
|
||||
|
||||
newtop->texture = textureCache().addFrameBufferTexture();
|
||||
|
@ -231,6 +233,7 @@ FrameBuffer *FrameBuffer_AddTop()
|
|||
|
||||
void FrameBuffer_MoveToTop( FrameBuffer *newtop )
|
||||
{
|
||||
FrameBufferList & frameBuffer = frameBufferList();
|
||||
if (newtop == frameBuffer.top)
|
||||
return;
|
||||
|
||||
|
@ -253,6 +256,7 @@ void FrameBuffer_MoveToTop( FrameBuffer *newtop )
|
|||
|
||||
void FrameBuffer_Destroy()
|
||||
{
|
||||
FrameBufferList & frameBuffer = frameBufferList();
|
||||
while (frameBuffer.bottom)
|
||||
FrameBuffer_RemoveBottom();
|
||||
frameBuffer.top = frameBuffer.bottom = frameBuffer.current = NULL;
|
||||
|
@ -265,6 +269,7 @@ void FrameBuffer_Destroy()
|
|||
|
||||
void FrameBuffer_SaveBuffer( u32 address, u16 format, u16 size, u16 width, u16 height )
|
||||
{
|
||||
FrameBufferList & frameBuffer = frameBufferList();
|
||||
frameBuffer.drawBuffer = GL_FRAMEBUFFER;
|
||||
FrameBuffer *current = frameBuffer.top;
|
||||
if (current != NULL && gDP.colorImage.height > 1) {
|
||||
|
@ -364,6 +369,7 @@ static
|
|||
void _initDepthTexture()
|
||||
{
|
||||
#ifndef GLES2
|
||||
FrameBufferList & frameBuffer = frameBufferList();
|
||||
depthBuffer.top->depth_texture = textureCache().addFrameBufferTexture();
|
||||
|
||||
depthBuffer.top->depth_texture->width = (u32)(frameBuffer.top->width * OGL.scaleX);
|
||||
|
@ -405,6 +411,7 @@ void _initDepthTexture()
|
|||
|
||||
void FrameBuffer_AttachDepthBuffer()
|
||||
{
|
||||
FrameBufferList & frameBuffer = frameBufferList();
|
||||
if ( frameBuffer.top != NULL && frameBuffer.top->fbo > 0 && depthBuffer.top != NULL && depthBuffer.top->renderbuf > 0) {
|
||||
if (depthBuffer.top->depth_texture == NULL)
|
||||
_initDepthTexture();
|
||||
|
@ -484,7 +491,7 @@ void FrameBuffer_RenderBuffer( u32 address )
|
|||
}
|
||||
glEnable(GL_SCISSOR_TEST);
|
||||
glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
|
||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, frameBuffer.top->fbo);
|
||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, frameBufferList().top->fbo);
|
||||
OGL_SwapBuffers();
|
||||
gDP.changed |= CHANGED_SCISSOR;
|
||||
}
|
||||
|
@ -519,6 +526,7 @@ void FrameBuffer_RenderBuffer( u32 address )
|
|||
gSP.textureTile[0]->fuls = gSP.textureTile[0]->fult = 0.0f;
|
||||
combiner.current->compiled->UpdateTextureInfo(true);
|
||||
|
||||
FrameBufferList & frameBuffer = frameBufferList();
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
frameBuffer.drawBuffer = GL_BACK;
|
||||
OGL_DrawTexturedRect( 0.0f, 0.0f, width, height, 0.0f, 0.0f, width-1.0f, height-1.0f, false );
|
||||
|
@ -533,7 +541,7 @@ void FrameBuffer_RenderBuffer( u32 address )
|
|||
|
||||
FrameBuffer *FrameBuffer_FindBuffer( u32 address )
|
||||
{
|
||||
FrameBuffer *current = frameBuffer.top;
|
||||
FrameBuffer *current = frameBufferList().top;
|
||||
|
||||
while (current)
|
||||
{
|
||||
|
@ -666,7 +674,7 @@ void FrameBufferToRDRAM::CopyToRDRAM( u32 address, bool bSync ) {
|
|||
0, 0, current->width, current->height,
|
||||
GL_COLOR_BUFFER_BIT, GL_LINEAR
|
||||
);
|
||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, frameBuffer.top->fbo);
|
||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, frameBufferList().top->fbo);
|
||||
|
||||
glBindFramebuffer(GL_READ_FRAMEBUFFER, m_FBO);
|
||||
glReadBuffer(GL_COLOR_ATTACHMENT0);
|
||||
|
@ -801,7 +809,7 @@ void DepthBufferToRDRAM::CopyToRDRAM( u32 address) {
|
|||
0, 0, current->width, current->height,
|
||||
GL_COLOR_BUFFER_BIT, GL_LINEAR
|
||||
);
|
||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, frameBuffer.top->fbo);
|
||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, frameBufferList().top->fbo);
|
||||
|
||||
m_curIndex = (m_curIndex + 1) % 2;
|
||||
const u32 nextIndex = m_aAddress[m_curIndex] == 0 ? m_curIndex : (m_curIndex + 1) % 2;
|
||||
|
@ -975,7 +983,7 @@ void RDRAMtoFrameBuffer::CopyFromRDRAM( u32 _address, bool _bUseAlpha)
|
|||
GL_COLOR_BUFFER_BIT, GL_LINEAR
|
||||
);
|
||||
glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
|
||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, frameBuffer.top->fbo);
|
||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, frameBufferList().top->fbo);
|
||||
#else
|
||||
if (_bUseAlpha)
|
||||
CombinerInfo::get().setCombine( EncodeCombineMode( 0, 0, 0, TEXEL0, 0, 0, 0, TEXEL0, 0, 0, 0, TEXEL0, 0, 0, 0, TEXEL0 ) );
|
||||
|
|
|
@ -26,9 +26,23 @@ struct FrameBufferList
|
|||
FrameBuffer *top, *bottom, *current;
|
||||
int numBuffers;
|
||||
GLenum drawBuffer;
|
||||
|
||||
static FrameBufferList & get()
|
||||
{
|
||||
static FrameBufferList frameBufferList;
|
||||
return frameBufferList;
|
||||
}
|
||||
|
||||
private:
|
||||
FrameBufferList() : current(NULL), drawBuffer(GL_BACK) {}
|
||||
FrameBufferList(const FrameBufferList &);
|
||||
};
|
||||
|
||||
extern FrameBufferList frameBuffer;
|
||||
inline
|
||||
FrameBufferList & frameBufferList()
|
||||
{
|
||||
return FrameBufferList::get();
|
||||
}
|
||||
|
||||
void FrameBuffer_Init();
|
||||
void FrameBuffer_Destroy();
|
||||
|
|
|
@ -693,6 +693,7 @@ void ShaderCombiner::updateDepthInfo(bool _bForce) {
|
|||
if (!OGL.bImageTexture)
|
||||
return;
|
||||
|
||||
FrameBufferList & frameBuffer = frameBufferList();
|
||||
if (frameBuffer.top == NULL || frameBuffer.top->pDepthBuffer == NULL)
|
||||
return;
|
||||
|
||||
|
@ -727,6 +728,7 @@ void ShaderCombiner::updateAlphaTestInfo(bool _bForce) {
|
|||
void GLSL_RenderDepth() {
|
||||
if (!OGL.bImageTexture)
|
||||
return;
|
||||
FrameBufferList & frameBuffer = frameBufferList();
|
||||
#if 0
|
||||
glBindFramebuffer(GL_READ_FRAMEBUFFER, g_zbuf_fbo);
|
||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
|
||||
|
|
|
@ -589,11 +589,11 @@ void OGL_UpdateCullFace()
|
|||
|
||||
void OGL_UpdateViewport()
|
||||
{
|
||||
if (frameBuffer.drawBuffer == GL_BACK)
|
||||
if (frameBufferList().drawBuffer == GL_BACK)
|
||||
glViewport( gSP.viewport.x * OGL.scaleX, (VI.height - (gSP.viewport.y + gSP.viewport.height)) * OGL.scaleY + OGL.heightOffset,
|
||||
gSP.viewport.width * OGL.scaleX, gSP.viewport.height * OGL.scaleY );
|
||||
else
|
||||
glViewport( gSP.viewport.x * OGL.scaleX, (frameBuffer.top->height - (gSP.viewport.y + gSP.viewport.height)) * OGL.scaleY,
|
||||
glViewport( gSP.viewport.x * OGL.scaleX, (frameBufferList().top->height - (gSP.viewport.y + gSP.viewport.height)) * OGL.scaleY,
|
||||
gSP.viewport.width * OGL.scaleX, gSP.viewport.height * OGL.scaleY );
|
||||
}
|
||||
|
||||
|
@ -798,6 +798,7 @@ void OGL_UpdateStates()
|
|||
|
||||
if (gDP.changed & CHANGED_SCISSOR)
|
||||
{
|
||||
FrameBufferList & frameBuffer = frameBufferList();
|
||||
const u32 screenHeight = (frameBuffer.top == NULL || frameBuffer.top->height == 0 || frameBuffer.drawBuffer == GL_BACK) ? VI.height : frameBuffer.top->height;
|
||||
glScissor( gDP.scissor.ulx * OGL.scaleX, (screenHeight - gDP.scissor.lry) * OGL.scaleY + (frameBuffer.drawBuffer == GL_BACK ? OGL.heightOffset : 0),
|
||||
(gDP.scissor.lrx - gDP.scissor.ulx) * OGL.scaleX, (gDP.scissor.lry - gDP.scissor.uly) * OGL.scaleY );
|
||||
|
@ -1016,6 +1017,7 @@ void OGL_DrawRect( int ulx, int uly, int lrx, int lry, float *color )
|
|||
currentCombiner()->updateRenderState();
|
||||
}
|
||||
|
||||
FrameBufferList & frameBuffer = frameBufferList();
|
||||
if (frameBuffer.drawBuffer != GL_FRAMEBUFFER)
|
||||
glViewport( 0, (frameBuffer.drawBuffer == GL_BACK ? OGL.heightOffset : 0), OGL.width, OGL.height );
|
||||
else
|
||||
|
@ -1071,6 +1073,7 @@ void OGL_DrawTexturedRect( float ulx, float uly, float lrx, float lry, float uls
|
|||
GLS_SetShadowMapCombiner();
|
||||
#endif // GLES2
|
||||
|
||||
FrameBufferList & frameBuffer = frameBufferList();
|
||||
if (frameBuffer.drawBuffer != GL_FRAMEBUFFER)
|
||||
glViewport( 0, (frameBuffer.drawBuffer == GL_BACK ? OGL.heightOffset : 0), OGL.width, OGL.height );
|
||||
else
|
||||
|
@ -1204,7 +1207,7 @@ void OGL_DrawTexturedRect( float ulx, float uly, float lrx, float lry, float uls
|
|||
|
||||
void OGL_ClearDepthBuffer()
|
||||
{
|
||||
if (config.frameBufferEmulation.enable && frameBuffer.top == NULL)
|
||||
if (config.frameBufferEmulation.enable && frameBufferList().top == NULL)
|
||||
return;
|
||||
|
||||
DepthBuffer_ClearBuffer();
|
||||
|
|
1
gDP.cpp
1
gDP.cpp
|
@ -752,6 +752,7 @@ void gDPFillRDRAM(u32 address, s32 ulx, s32 uly, s32 lrx, s32 lry, u32 width, u3
|
|||
{
|
||||
if (g_bDepthClearOnly && color != DEPTH_CLEAR_COLOR)
|
||||
return;
|
||||
FrameBufferList & frameBuffer = frameBufferList();
|
||||
if (frameBuffer.drawBuffer == GL_FRAMEBUFFER) {
|
||||
frameBuffer.top->cleared = true;
|
||||
frameBuffer.top->fillcolor = color;
|
||||
|
|
5
gSP.cpp
5
gSP.cpp
|
@ -1684,14 +1684,14 @@ void _copyDepthBuffer()
|
|||
// It will be copy depth buffer
|
||||
DepthBuffer_SetBuffer(gDP.colorImage.address);
|
||||
// Take any frame buffer and attach source depth buffer to it, to blit it into copy depth buffer
|
||||
FrameBuffer * pTmpBuffer = frameBuffer.top->lower;
|
||||
FrameBuffer * pTmpBuffer = frameBufferList().top->lower;
|
||||
DepthBuffer * pTmpBufferDepth = pTmpBuffer->pDepthBuffer;
|
||||
pTmpBuffer->pDepthBuffer = DepthBuffer_FindBuffer(gSP.bgImage.address);
|
||||
glBindFramebuffer(GL_READ_FRAMEBUFFER, pTmpBuffer->fbo);
|
||||
glFramebufferRenderbuffer(GL_READ_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, pTmpBuffer->pDepthBuffer->renderbuf);
|
||||
GLuint attachments[2] = { GL_COLOR_ATTACHMENT0, GL_DEPTH_ATTACHMENT };
|
||||
glDrawBuffers(2, attachments);
|
||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, frameBuffer.top->fbo);
|
||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, frameBufferList().top->fbo);
|
||||
glBlitFramebuffer(
|
||||
0, 0, OGL.width, OGL.height,
|
||||
0, 0, OGL.width, OGL.height,
|
||||
|
@ -1945,6 +1945,7 @@ void gSPObjSprite( u32 sp )
|
|||
gDPSetTileSize( 0, 0, 0, (imageW - 1) << 2, (imageH - 1) << 2 );
|
||||
gSPTexture( 1.0f, 1.0f, 0, 0, TRUE );
|
||||
|
||||
FrameBufferList & frameBuffer = frameBufferList();
|
||||
const float scaleX = frameBuffer.drawBuffer == GL_FRAMEBUFFER ? 1.0f/frameBuffer.top->width : VI.rwidth;
|
||||
const float scaleY = frameBuffer.drawBuffer == GL_FRAMEBUFFER ? 1.0f/frameBuffer.top->height : VI.rheight;
|
||||
OGL.triangles.vertices[v0].x = 2.0f * scaleX * OGL.triangles.vertices[v0].x - 1.0f;
|
||||
|
|
Loading…
Reference in New Issue
Block a user