diff --git a/DepthBuffer.cpp b/DepthBuffer.cpp index 53ce0064..7e2d50d7 100644 --- a/DepthBuffer.cpp +++ b/DepthBuffer.cpp @@ -1,12 +1,16 @@ #include #include #include "OpenGL.h" +#include "Combiner.h" #include "FrameBuffer.h" #include "DepthBuffer.h" #include "VI.h" #include "Debug.h" DepthBufferInfo depthBuffer; +const GLuint ZlutImageUnit = 0; +const GLuint TlutImageUnit = 1; +const GLuint depthImageUnit = 2; void DepthBuffer_Init() { @@ -212,4 +216,14 @@ DepthBuffer *DepthBuffer_FindBuffer( u32 address ) return NULL; } -*/ \ No newline at end of file +*/ +void DepthBuffer_ClearBuffer() { + DepthBuffer *current = depthBuffer.top; + if (current == NULL || current->fbo == 0) + return; + float color[4] = {1.0f, 1.0f, 0.0f, 0.0f}; + glBindImageTexture(depthImageUnit, 0, 0, GL_FALSE, 0, GL_READ_WRITE, GL_RGBA32F); + ogl_glBindFramebuffer(GL_DRAW_FRAMEBUFFER, current->fbo); + OGL_DrawRect(0,0,VI.width, VI.height, color); + ogl_glBindFramebuffer(GL_DRAW_FRAMEBUFFER, frameBuffer.top->fbo); +} diff --git a/DepthBuffer.h b/DepthBuffer.h index bfa083f7..0626b5ab 100644 --- a/DepthBuffer.h +++ b/DepthBuffer.h @@ -22,10 +22,15 @@ struct DepthBufferInfo extern DepthBufferInfo depthBuffer; +extern const GLuint ZlutImageUnit; +extern const GLuint TlutImageUnit; +extern const GLuint depthImageUnit; + void DepthBuffer_Init(); void DepthBuffer_Destroy(); void DepthBuffer_SetBuffer( u32 address ); void DepthBuffer_RemoveBuffer( u32 address ); +void DepthBuffer_ClearBuffer(); //DepthBuffer *DepthBuffer_FindBuffer( u32 address ); #endif diff --git a/FrameBuffer.cpp b/FrameBuffer.cpp index 21e87983..c76a8d31 100644 --- a/FrameBuffer.cpp +++ b/FrameBuffer.cpp @@ -375,8 +375,7 @@ void _initDepthTexture() ogl_glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); ogl_glBindFramebuffer(GL_DRAW_FRAMEBUFFER, frameBuffer.top->fbo); frameBuffer.top->pDepthBuffer = depthBuffer.top; - void GLSL_ClearDepthBuffer(); - GLSL_ClearDepthBuffer(); + DepthBuffer_ClearBuffer(); } void FrameBuffer_AttachDepthBuffer() diff --git a/GLSLCombiner.cpp b/GLSLCombiner.cpp index 692b0fb2..3226ff03 100644 --- a/GLSLCombiner.cpp +++ b/GLSLCombiner.cpp @@ -23,10 +23,6 @@ static GLuint g_draw_shadow_map_program; GLuint g_tlut_tex = 0; static u32 g_paletteCRC256 = 0; -static const GLuint ZlutImageUnit = 0; -static const GLuint TlutImageUnit = 1; -static const GLuint depthImageUnit = 2; - static void display_warning(const char *text, ...) { @@ -562,8 +558,7 @@ void GLSLCombiner::UpdateFBInfo() { glUniform1i(fbFixedAlpha_location, nFbFixedAlpha); } -static -void _unbindImageTextures() { +void unbindImageTextures() { glBindImageTexture(TlutImageUnit, 0, 0, GL_FALSE, 0, GL_READ_WRITE, GL_R16UI); glBindImageTexture(ZlutImageUnit, 0, 0, GL_FALSE, 0, GL_READ_WRITE, GL_R16UI); glBindImageTexture(depthImageUnit, 0, 0, GL_FALSE, 0, GL_READ_WRITE, GL_RGBA32F); @@ -573,7 +568,7 @@ void GLSLCombiner::UpdateDepthInfo() { if (!OGL.bImageTexture) return; - _unbindImageTextures(); + unbindImageTextures(); if (frameBuffer.top == NULL || frameBuffer.top->pDepthBuffer == NULL) return; @@ -600,38 +595,6 @@ void GLSLCombiner::UpdateDepthInfo() { glBindImageTexture(depthImageUnit, texture, 0, GL_FALSE, 0, GL_READ_WRITE, GL_RGBA32F); } -void GLSL_ClearDepthBuffer() { - if (!OGL.bImageTexture) - return; - - if (frameBuffer.top == NULL || frameBuffer.top->pDepthBuffer == NULL) - return; - - _unbindImageTextures(); - CachedTexture * pDepthTexture = frameBuffer.top->pDepthBuffer->depth_texture; - const u32 numTexels = pDepthTexture->width*pDepthTexture->height*4; - - char * pData = (char*)malloc(numTexels * sizeof(float)); - f32 * pDepth = (f32*)pData; - for (int i = 0; i < numTexels; i+=4) { - pDepth[i] = 1.0f; - pDepth[i+1] = 1.0f; - pDepth[i+2] = 0.0f; - pDepth[i+3] = 0.0f; - } - glBindTexture(GL_TEXTURE_2D, pDepthTexture->glName); - - - glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, - pDepthTexture->width, pDepthTexture->height, - GL_RGBA, GL_FLOAT, pData - ); - free(pData); - - gSP.changed |= CHANGED_TEXTURE; - gDP.changed |= CHANGED_COMBINE; -} - void GLSLCombiner::UpdateAlphaTestInfo() { int at_enabled_location = glGetUniformLocation(m_program, "alphaTestEnabled"); int at_value_location = glGetUniformLocation(m_program, "alphaTestValue"); @@ -665,8 +628,7 @@ void GLSL_RenderDepth() { #else if (frameBuffer.top == NULL || frameBuffer.top->pDepthBuffer == NULL) return; - _unbindImageTextures(); - return; + unbindImageTextures(); glPushAttrib( GL_ENABLE_BIT | GL_VIEWPORT_BIT ); glActiveTexture( GL_TEXTURE0 ); @@ -732,7 +694,7 @@ void GLS_SetShadowMapCombiner() { if (!OGL.bImageTexture) return; - _unbindImageTextures(); + unbindImageTextures(); if (g_paletteCRC256 != gDP.paletteCRC256) { g_paletteCRC256 = gDP.paletteCRC256; diff --git a/OpenGL.cpp b/OpenGL.cpp index fb5284f6..f210e7a9 100644 --- a/OpenGL.cpp +++ b/OpenGL.cpp @@ -10,6 +10,7 @@ #include "Textures.h" #include "Combiner.h" #include "FrameBuffer.h" +#include "DepthBuffer.h" #include "VI.h" GLInfo OGL; @@ -1037,8 +1038,7 @@ void OGL_ClearDepthBuffer() if (OGL.frameBufferTextures && frameBuffer.top == NULL) return; - void GLSL_ClearDepthBuffer(); - GLSL_ClearDepthBuffer(); + DepthBuffer_ClearBuffer(); glDisable( GL_SCISSOR_TEST ); diff --git a/RSP.cpp b/RSP.cpp index 4b325756..37746829 100644 --- a/RSP.cpp +++ b/RSP.cpp @@ -211,6 +211,8 @@ void RSP_ProcessDList() GBI.cmd[RSP.cmd]( w0, w1 ); } +void unbindImageTextures(); +unbindImageTextures(); if (g_bCopyToRDRAM) FrameBuffer_CopyToRDRAM( gDP.colorImage.address, false ); if (g_bCopyDepthToRDRAM) diff --git a/gDP.h b/gDP.h index d055d035..cf7c64df 100644 --- a/gDP.h +++ b/gDP.h @@ -166,7 +166,7 @@ struct gDPInfo gDPTile tiles[8], *loadTile; - struct + struct Color { f32 r, g, b, a; } fogColor, blendColor, envColor; @@ -177,9 +177,9 @@ struct gDPInfo u32 color; } fillColor; - struct + struct PrimColor : public Color { - f32 m, l, r, g, b, a; + f32 m, l; } primColor; struct