From 8e3e41356a81d370cb96e57e64853df068d988bd Mon Sep 17 00:00:00 2001 From: Sergey Lipskiy Date: Mon, 11 Nov 2013 15:57:57 +0700 Subject: [PATCH] FrameBuffer: Replace pointer to depth texture by pointer to DepthBuffer --- FrameBuffer.cpp | 8 ++++---- FrameBuffer.h | 4 ++-- GLSLCombiner.cpp | 21 ++++++++++++--------- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/FrameBuffer.cpp b/FrameBuffer.cpp index 50dc3284..1183a7be 100644 --- a/FrameBuffer.cpp +++ b/FrameBuffer.cpp @@ -169,7 +169,7 @@ FrameBuffer *FrameBuffer_AddTop() FrameBuffer *newtop = (FrameBuffer*)malloc( sizeof( FrameBuffer ) ); newtop->texture = TextureCache_AddTop(); - newtop->depth_texture = NULL; + newtop->pDepthBuffer = NULL; newtop->fbo = 0; newtop->lower = frameBuffer.top; @@ -345,7 +345,7 @@ void _initDepthTexture() glTexImage2D(GL_TEXTURE_2D, 0, depthTextureInternalFormat, depthBuffer.top->depth_texture->realWidth, depthBuffer.top->depth_texture->realHeight, 0, GL_RED, depthTextureType, NULL); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); - frameBuffer.top->depth_texture = depthBuffer.top->depth_texture; + frameBuffer.top->pDepthBuffer = depthBuffer.top; void GLSL_ClearDepthBuffer(); GLSL_ClearDepthBuffer(); } @@ -355,13 +355,13 @@ void FrameBuffer_AttachDepthBuffer() if ( frameBuffer.top != NULL && frameBuffer.top->fbo > 0 && depthBuffer.top != NULL && depthBuffer.top->renderbuf > 0) { if (depthBuffer.top->depth_texture == NULL) _initDepthTexture(); - frameBuffer.top->depth_texture = depthBuffer.top->depth_texture; + frameBuffer.top->pDepthBuffer = depthBuffer.top; ogl_glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depthBuffer.top->renderbuf); GLuint attachments[2] = { GL_COLOR_ATTACHMENT0, GL_DEPTH_ATTACHMENT }; ogl_glDrawBuffers(2, attachments, frameBuffer.top->texture->glName); assert(checkFBO()); } else if (frameBuffer.top != NULL) { - frameBuffer.top->depth_texture = 0; + frameBuffer.top->pDepthBuffer = 0; GLuint attachments[1] = { GL_COLOR_ATTACHMENT0 }; ogl_glDrawBuffers(1, attachments, frameBuffer.top->texture->glName); assert(checkFBO()); diff --git a/FrameBuffer.h b/FrameBuffer.h index ebd7f51f..9d452e5b 100644 --- a/FrameBuffer.h +++ b/FrameBuffer.h @@ -4,13 +4,14 @@ #include "Types.h" #include "Textures.h" struct gDPTile; +struct DepthBuffer; struct FrameBuffer { FrameBuffer *higher, *lower; CachedTexture *texture; - const CachedTexture *depth_texture; + DepthBuffer *pDepthBuffer; GLuint fbo; u32 startAddress, endAddress; @@ -31,7 +32,6 @@ extern FrameBufferInfo frameBuffer; extern bool g_bCopyToRDRAM; extern bool g_bCopyFromRDRAM; extern bool g_bUseFloatDepthTexture; -struct DepthBuffer; void FrameBuffer_Init(); void FrameBuffer_Destroy(); diff --git a/GLSLCombiner.cpp b/GLSLCombiner.cpp index 9e761458..1c753293 100644 --- a/GLSLCombiner.cpp +++ b/GLSLCombiner.cpp @@ -15,6 +15,7 @@ #include "GLSLCombiner.h" #include "Shaders.h" #include "Noise_shader.h" +#include "DepthBuffer.h" static GLuint g_vertex_shader_object; static GLuint g_calc_light_shader_object; @@ -589,8 +590,9 @@ void GLSLCombiner::UpdateDepthInfo() { _unbindImageTextures(); - if (frameBuffer.top == NULL || frameBuffer.top->depth_texture == NULL) + if (frameBuffer.top == NULL || frameBuffer.top->pDepthBuffer == NULL) return; + int nDepthEnabled = (gSP.geometryMode & G_ZBUFFER) > 0 ? 1 : 0; int depth_enabled_location = glGetUniformLocation(m_program, "depthEnabled"); glUniform1i(depth_enabled_location, nDepthEnabled); @@ -610,7 +612,7 @@ void GLSLCombiner::UpdateDepthInfo() { glUniform1i(depth_polygon_offset, iPlygonOffset); } - GLuint texture = frameBuffer.top->depth_texture->glName; + GLuint texture = frameBuffer.top->pDepthBuffer->depth_texture->glName; glBindImageTexture(ZlutImageUnit, g_zlut_tex, 0, GL_FALSE, 0, GL_READ_ONLY, GL_R16UI); GLenum depthTexFormat = g_bUseFloatDepthTexture ? GL_R32F : GL_R16UI; glBindImageTexture(depthImageUnit, texture, 0, GL_FALSE, 0, GL_READ_WRITE, depthTexFormat); @@ -620,10 +622,11 @@ void GLSL_ClearDepthBuffer() { if (!OGL.bImageTexture) return; - if (frameBuffer.top == NULL || frameBuffer.top->depth_texture == NULL) + if (frameBuffer.top == NULL || frameBuffer.top->pDepthBuffer == NULL) return; - const u32 numTexels = frameBuffer.top->depth_texture->width*frameBuffer.top->depth_texture->height; + CachedTexture * pDepthTexture = frameBuffer.top->pDepthBuffer->depth_texture; + const u32 numTexels = pDepthTexture->width*pDepthTexture->height; GLenum type = GL_UNSIGNED_SHORT; int dataSize = g_bUseFloatDepthTexture ? sizeof(float) : sizeof(unsigned short); @@ -639,11 +642,11 @@ void GLSL_ClearDepthBuffer() { for (int i = 0; i < numTexels; i++) pDepth[i] = 0xfffc; } - glBindTexture(GL_TEXTURE_2D, frameBuffer.top->depth_texture->glName); + glBindTexture(GL_TEXTURE_2D, pDepthTexture->glName); glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, - frameBuffer.top->depth_texture->width, frameBuffer.top->depth_texture->height, + pDepthTexture->width, pDepthTexture->height, GL_RED, type, pData); free(pData); @@ -682,12 +685,12 @@ void GLSL_RenderDepth() { ogl_glBindFramebuffer(GL_READ_FRAMEBUFFER, 0); ogl_glBindFramebuffer(GL_DRAW_FRAMEBUFFER, frameBuffer.top != NULL ? frameBuffer.top->fbo : 0); #else - if (frameBuffer.top == NULL || frameBuffer.top->depth_texture == NULL) + if (frameBuffer.top == NULL || frameBuffer.top->pDepthBuffer == NULL) return; glPushAttrib( GL_ENABLE_BIT | GL_VIEWPORT_BIT ); glActiveTexture( GL_TEXTURE0 ); - glBindTexture(GL_TEXTURE_2D, frameBuffer.top->depth_texture->glName); + glBindTexture(GL_TEXTURE_2D, frameBuffer.top->pDepthBuffer->depth_texture->glName); // glBindTexture(GL_TEXTURE_2D, g_zlut_tex); Combiner_SetCombine( EncodeCombineMode( 0, 0, 0, TEXEL0, 0, 0, 0, 1, 0, 0, 0, TEXEL0, 0, 0, 0, 1 ) ); @@ -766,7 +769,7 @@ void GLS_SetShadowMapCombiner() { glBindImageTexture(TlutImageUnit, g_tlut_tex, 0, GL_FALSE, 0, GL_READ_ONLY, GL_R16UI); GLenum depthTexFormat = g_bUseFloatDepthTexture ? GL_R32F : GL_R16UI; - GLuint texture = frameBuffer.top->depth_texture->glName; + GLuint texture = frameBuffer.top->pDepthBuffer->depth_texture->glName; glBindImageTexture(depthImageUnit, texture, 0, GL_FALSE, 0, GL_READ_ONLY, depthTexFormat); gDP.changed |= CHANGED_COMBINE; }