mirror of
https://github.com/blawar/GLideN64.git
synced 2024-07-04 10:03:36 +00:00
Fix depth buffer initialization and clean.
This commit is contained in:
parent
04d1bc385a
commit
880238250b
|
@ -1,7 +1,9 @@
|
||||||
#include <malloc.h>
|
#include <malloc.h>
|
||||||
|
#include <assert.h>
|
||||||
#include "OpenGL.h"
|
#include "OpenGL.h"
|
||||||
#include "FrameBuffer.h"
|
#include "FrameBuffer.h"
|
||||||
#include "DepthBuffer.h"
|
#include "DepthBuffer.h"
|
||||||
|
#include "VI.h"
|
||||||
#include "Debug.h"
|
#include "Debug.h"
|
||||||
|
|
||||||
DepthBufferInfo depthBuffer;
|
DepthBufferInfo depthBuffer;
|
||||||
|
@ -136,12 +138,9 @@ void DepthBuffer_Destroy()
|
||||||
|
|
||||||
void DepthBuffer_SetBuffer( u32 address )
|
void DepthBuffer_SetBuffer( u32 address )
|
||||||
{
|
{
|
||||||
const FrameBuffer * pFrameBuffer = FrameBuffer_FindBuffer(address);
|
FrameBuffer * pFrameBuffer = FrameBuffer_FindBuffer(address);
|
||||||
bool bNeedClear = false;
|
if (pFrameBuffer == NULL)
|
||||||
if (pFrameBuffer != NULL) {
|
pFrameBuffer = frameBuffer.top;
|
||||||
bNeedClear = pFrameBuffer->changed > 0;
|
|
||||||
// FrameBuffer_RemoveBuffer(address);
|
|
||||||
}
|
|
||||||
|
|
||||||
DepthBuffer *current = depthBuffer.top;
|
DepthBuffer *current = depthBuffer.top;
|
||||||
|
|
||||||
|
@ -150,43 +149,37 @@ void DepthBuffer_SetBuffer( u32 address )
|
||||||
{
|
{
|
||||||
if (current->address == address)
|
if (current->address == address)
|
||||||
{
|
{
|
||||||
|
if (pFrameBuffer != NULL && current->width != pFrameBuffer->width) {
|
||||||
|
DepthBuffer_Remove( current );
|
||||||
|
current = NULL;
|
||||||
|
break;
|
||||||
|
}
|
||||||
DepthBuffer_MoveToTop( current );
|
DepthBuffer_MoveToTop( current );
|
||||||
depthBuffer.current = current;
|
break;
|
||||||
|
|
||||||
if ( frameBuffer.top != NULL && frameBuffer.top->fbo > 0) {
|
|
||||||
ogl_glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, current->renderbuf);
|
|
||||||
GLuint attachments[2] = { GL_COLOR_ATTACHMENT0, GL_DEPTH_ATTACHMENT };
|
|
||||||
ogl_glDrawBuffers(2, attachments, frameBuffer.top->texture->glName);
|
|
||||||
if (bNeedClear)
|
|
||||||
OGL_ClearDepthBuffer();
|
|
||||||
}
|
|
||||||
#ifdef DEBUG
|
|
||||||
DebugMsg( DEBUG_HIGH | DEBUG_HANDLED, "DepthBuffer_SetBuffer( 0x%08X ); color buffer is 0x%08X\n",
|
|
||||||
address, ( frameBuffer.top != NULL && frameBuffer.top->fbo > 0) ? frameBuffer.top->startAddress : 0
|
|
||||||
);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
current = current->lower;
|
current = current->lower;
|
||||||
}
|
}
|
||||||
|
|
||||||
current = DepthBuffer_AddTop();
|
if (current == NULL) {
|
||||||
|
current = DepthBuffer_AddTop();
|
||||||
|
|
||||||
|
current->address = address;
|
||||||
|
current->width = pFrameBuffer != NULL ? pFrameBuffer->width : VI.width;
|
||||||
|
if (OGL.frameBufferTextures) {
|
||||||
|
ogl_glGenRenderbuffers(1, ¤t->renderbuf);
|
||||||
|
ogl_glBindRenderbuffer(GL_RENDERBUFFER, current->renderbuf);
|
||||||
|
if (pFrameBuffer != NULL)
|
||||||
|
ogl_glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, pFrameBuffer->texture->realWidth, pFrameBuffer->texture->realHeight);
|
||||||
|
else
|
||||||
|
ogl_glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, (u32)pow2(OGL.width), (u32)pow2(OGL.height));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
current->address = address;
|
|
||||||
current->cleared = TRUE;
|
|
||||||
if (OGL.frameBufferTextures) {
|
if (OGL.frameBufferTextures) {
|
||||||
|
|
||||||
ogl_glGenRenderbuffers(1, ¤t->renderbuf);
|
|
||||||
ogl_glBindRenderbuffer(GL_RENDERBUFFER, current->renderbuf);
|
|
||||||
ogl_glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, (u32)pow2(OGL.width), (u32)pow2(OGL.height));
|
|
||||||
|
|
||||||
if ( frameBuffer.top != NULL && frameBuffer.top->fbo > 0) {
|
if ( frameBuffer.top != NULL && frameBuffer.top->fbo > 0) {
|
||||||
ogl_glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, current->renderbuf);
|
ogl_glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, current->renderbuf);
|
||||||
GLuint attachments[2] = { GL_COLOR_ATTACHMENT0, GL_DEPTH_ATTACHMENT };
|
GLuint attachments[2] = { GL_COLOR_ATTACHMENT0, GL_DEPTH_ATTACHMENT };
|
||||||
ogl_glDrawBuffers(2, attachments, frameBuffer.top->texture->glName);
|
ogl_glDrawBuffers(2, attachments, frameBuffer.top->texture->glName);
|
||||||
if (bNeedClear)
|
|
||||||
OGL_ClearDepthBuffer();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
|
@ -198,7 +191,7 @@ void DepthBuffer_SetBuffer( u32 address )
|
||||||
}
|
}
|
||||||
depthBuffer.current = current;
|
depthBuffer.current = current;
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
DepthBuffer *DepthBuffer_FindBuffer( u32 address )
|
DepthBuffer *DepthBuffer_FindBuffer( u32 address )
|
||||||
{
|
{
|
||||||
DepthBuffer *current = depthBuffer.top;
|
DepthBuffer *current = depthBuffer.top;
|
||||||
|
@ -208,10 +201,11 @@ DepthBuffer *DepthBuffer_FindBuffer( u32 address )
|
||||||
if (current->address == address) {
|
if (current->address == address) {
|
||||||
if (OGL.frameBufferTextures)
|
if (OGL.frameBufferTextures)
|
||||||
ogl_glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, current->renderbuf);
|
ogl_glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, current->renderbuf);
|
||||||
}
|
|
||||||
return current;
|
return current;
|
||||||
|
}
|
||||||
current = current->lower;
|
current = current->lower;
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
*/
|
|
@ -7,7 +7,7 @@ struct DepthBuffer
|
||||||
{
|
{
|
||||||
DepthBuffer *higher, *lower;
|
DepthBuffer *higher, *lower;
|
||||||
|
|
||||||
u32 address, cleared;
|
u32 address, width;
|
||||||
GLuint renderbuf;
|
GLuint renderbuf;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -23,6 +23,6 @@ void DepthBuffer_Init();
|
||||||
void DepthBuffer_Destroy();
|
void DepthBuffer_Destroy();
|
||||||
void DepthBuffer_SetBuffer( u32 address );
|
void DepthBuffer_SetBuffer( u32 address );
|
||||||
void DepthBuffer_RemoveBuffer( u32 address );
|
void DepthBuffer_RemoveBuffer( u32 address );
|
||||||
DepthBuffer *DepthBuffer_FindBuffer( u32 address );
|
//DepthBuffer *DepthBuffer_FindBuffer( u32 address );
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -156,7 +156,6 @@ void FrameBuffer_Destroy()
|
||||||
void FrameBuffer_SaveBuffer( u32 address, u16 size, u16 width, u16 height )
|
void FrameBuffer_SaveBuffer( u32 address, u16 size, u16 width, u16 height )
|
||||||
{
|
{
|
||||||
frameBuffer.drawBuffer = GL_DRAW_FRAMEBUFFER;
|
frameBuffer.drawBuffer = GL_DRAW_FRAMEBUFFER;
|
||||||
//DepthBuffer_RemoveBuffer( address );
|
|
||||||
|
|
||||||
FrameBuffer *current = frameBuffer.top;
|
FrameBuffer *current = frameBuffer.top;
|
||||||
// Search through saved frame buffers
|
// Search through saved frame buffers
|
||||||
|
@ -188,8 +187,6 @@ void FrameBuffer_SaveBuffer( u32 address, u16 size, u16 width, u16 height )
|
||||||
GLuint attachments[2] = { GL_COLOR_ATTACHMENT0, GL_DEPTH_ATTACHMENT };
|
GLuint attachments[2] = { GL_COLOR_ATTACHMENT0, GL_DEPTH_ATTACHMENT };
|
||||||
ogl_glDrawBuffers(2, attachments, current->texture->glName);
|
ogl_glDrawBuffers(2, attachments, current->texture->glName);
|
||||||
assert(checkFBO());
|
assert(checkFBO());
|
||||||
if (depthBuffer.top != NULL && depthBuffer.top->cleared)
|
|
||||||
OGL_ClearDepthBuffer();
|
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
DebugMsg( DEBUG_HIGH | DEBUG_HANDLED, "FrameBuffer_SaveBuffer( 0x%08X ); \n", address);
|
DebugMsg( DEBUG_HIGH | DEBUG_HANDLED, "FrameBuffer_SaveBuffer( 0x%08X ); \n", address);
|
||||||
|
@ -251,8 +248,6 @@ void FrameBuffer_SaveBuffer( u32 address, u16 size, u16 width, u16 height )
|
||||||
GLuint attachments[2] = { GL_COLOR_ATTACHMENT0, GL_DEPTH_ATTACHMENT };
|
GLuint attachments[2] = { GL_COLOR_ATTACHMENT0, GL_DEPTH_ATTACHMENT };
|
||||||
ogl_glDrawBuffers(2, attachments, current->texture->glName);
|
ogl_glDrawBuffers(2, attachments, current->texture->glName);
|
||||||
assert(checkFBO());
|
assert(checkFBO());
|
||||||
if (depthBuffer.top != NULL && depthBuffer.top->cleared)
|
|
||||||
OGL_ClearDepthBuffer();
|
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
DebugMsg( DEBUG_HIGH | DEBUG_HANDLED, "FrameBuffer_SaveBuffer( 0x%08X ); depth buffer is 0x%08X\n",
|
DebugMsg( DEBUG_HIGH | DEBUG_HANDLED, "FrameBuffer_SaveBuffer( 0x%08X ); depth buffer is 0x%08X\n",
|
||||||
|
|
21
gDP.cpp
21
gDP.cpp
|
@ -352,6 +352,8 @@ void gDPSetColorImage( u32 format, u32 size, u32 width, u32 address )
|
||||||
gDP.colorImage.height = gDP.scissor.lry;
|
gDP.colorImage.height = gDP.scissor.lry;
|
||||||
else if (width >= gSP.viewport.width-1 && width <= gSP.viewport.width+1)
|
else if (width >= gSP.viewport.width-1 && width <= gSP.viewport.width+1)
|
||||||
gDP.colorImage.height = gSP.viewport.height;
|
gDP.colorImage.height = gSP.viewport.height;
|
||||||
|
else
|
||||||
|
gDP.colorImage.height = 1;
|
||||||
|
|
||||||
if (OGL.frameBufferTextures)// && address != gDP.depthImageAddress)
|
if (OGL.frameBufferTextures)// && address != gDP.depthImageAddress)
|
||||||
{
|
{
|
||||||
|
@ -405,15 +407,9 @@ void gDPSetTextureImage( u32 format, u32 size, u32 width, u32 address )
|
||||||
|
|
||||||
void gDPSetDepthImage( u32 address )
|
void gDPSetDepthImage( u32 address )
|
||||||
{
|
{
|
||||||
// if (address != gDP.depthImageAddress)
|
address = RSP_SegmentToPhysical( address );
|
||||||
// OGL_ClearDepthBuffer();
|
DepthBuffer_SetBuffer( address );
|
||||||
|
gDP.depthImageAddress = address;
|
||||||
DepthBuffer_SetBuffer( RSP_SegmentToPhysical( address ) );
|
|
||||||
|
|
||||||
// if (depthBuffer.current->cleared)
|
|
||||||
// OGL_ClearDepthBuffer();
|
|
||||||
|
|
||||||
gDP.depthImageAddress = RSP_SegmentToPhysical( address );
|
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
DebugMsg( DEBUG_HIGH | DEBUG_HANDLED, "gDPSetDepthImage( 0x%08X );\n", gDP.depthImageAddress );
|
DebugMsg( DEBUG_HIGH | DEBUG_HANDLED, "gDPSetDepthImage( 0x%08X );\n", gDP.depthImageAddress );
|
||||||
|
@ -784,11 +780,6 @@ void gDPSetScissor( u32 mode, f32 ulx, f32 uly, f32 lrx, f32 lry )
|
||||||
|
|
||||||
void gDPFillRectangle( s32 ulx, s32 uly, s32 lrx, s32 lry )
|
void gDPFillRectangle( s32 ulx, s32 uly, s32 lrx, s32 lry )
|
||||||
{
|
{
|
||||||
DepthBuffer *buffer = DepthBuffer_FindBuffer( gDP.colorImage.address );
|
|
||||||
|
|
||||||
if (buffer)
|
|
||||||
buffer->cleared = TRUE;
|
|
||||||
|
|
||||||
if (gDP.depthImageAddress == gDP.colorImage.address) {
|
if (gDP.depthImageAddress == gDP.colorImage.address) {
|
||||||
OGL_ClearDepthBuffer();
|
OGL_ClearDepthBuffer();
|
||||||
return;
|
return;
|
||||||
|
@ -817,7 +808,6 @@ void gDPFillRectangle( s32 ulx, s32 uly, s32 lrx, s32 lry )
|
||||||
|
|
||||||
OGL_DrawRect( ulx, uly, lrx, lry, (gDP.otherMode.cycleType == G_CYC_FILL) ? fillColor : &gDP.blendColor.r );
|
OGL_DrawRect( ulx, uly, lrx, lry, (gDP.otherMode.cycleType == G_CYC_FILL) ? fillColor : &gDP.blendColor.r );
|
||||||
|
|
||||||
if (depthBuffer.top) depthBuffer.top->cleared = FALSE;
|
|
||||||
gDP.colorImage.changed = TRUE;
|
gDP.colorImage.changed = TRUE;
|
||||||
gDP.colorImage.height = (u32)max( (s32)gDP.colorImage.height, lry );
|
gDP.colorImage.height = (u32)max( (s32)gDP.colorImage.height, lry );
|
||||||
|
|
||||||
|
@ -893,7 +883,6 @@ void gDPTextureRectangle( f32 ulx, f32 uly, f32 lrx, f32 lry, s32 tile, f32 s, f
|
||||||
gSP.textureTile[0] = &gDP.tiles[gSP.texture.tile];
|
gSP.textureTile[0] = &gDP.tiles[gSP.texture.tile];
|
||||||
gSP.textureTile[1] = &gDP.tiles[gSP.texture.tile < 7 ? gSP.texture.tile + 1 : gSP.texture.tile];
|
gSP.textureTile[1] = &gDP.tiles[gSP.texture.tile < 7 ? gSP.texture.tile + 1 : gSP.texture.tile];
|
||||||
|
|
||||||
if (depthBuffer.top) depthBuffer.top->cleared = FALSE;
|
|
||||||
gDP.colorImage.changed = TRUE;
|
gDP.colorImage.changed = TRUE;
|
||||||
gDP.colorImage.height = max( gDP.colorImage.height, (u32)gDP.scissor.lry );
|
gDP.colorImage.height = max( gDP.colorImage.height, (u32)gDP.scissor.lry );
|
||||||
|
|
||||||
|
|
2
gSP.cpp
2
gSP.cpp
|
@ -889,7 +889,6 @@ void gSPTriangle( s32 v0, s32 v1, s32 v2, s32 flag )
|
||||||
DebugMsg( DEBUG_HIGH | DEBUG_ERROR | DEBUG_TRIANGLE, "// Vertex index out of range\n" );
|
DebugMsg( DEBUG_HIGH | DEBUG_ERROR | DEBUG_TRIANGLE, "// Vertex index out of range\n" );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (depthBuffer.top) depthBuffer.top->cleared = FALSE;
|
|
||||||
gDP.colorImage.changed = TRUE;
|
gDP.colorImage.changed = TRUE;
|
||||||
gDP.colorImage.height = max( gDP.colorImage.height, (u32)gDP.scissor.lry );
|
gDP.colorImage.height = max( gDP.colorImage.height, (u32)gDP.scissor.lry );
|
||||||
}
|
}
|
||||||
|
@ -1652,7 +1651,6 @@ void gSPObjSprite( u32 sp )
|
||||||
OGL_DrawTriangles();
|
OGL_DrawTriangles();
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
|
|
||||||
if (depthBuffer.top) depthBuffer.top->cleared = FALSE;
|
|
||||||
gDP.colorImage.changed = TRUE;
|
gDP.colorImage.changed = TRUE;
|
||||||
gDP.colorImage.height = max( gDP.colorImage.height, gDP.scissor.lry );
|
gDP.colorImage.height = max( gDP.colorImage.height, gDP.scissor.lry );
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user