1
0
mirror of https://github.com/blawar/GLideN64.git synced 2024-07-02 09:03:37 +00:00

Rewrite depth texture clear.

This commit is contained in:
Sergey Lipskiy 2013-12-14 21:30:20 +07:00
parent 314b9098f4
commit 344df93374
7 changed files with 32 additions and 50 deletions

View File

@ -1,12 +1,16 @@
#include <malloc.h>
#include <assert.h>
#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;
}
*/
*/
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);
}

View File

@ -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

View File

@ -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()

View File

@ -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;

View File

@ -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 );

View File

@ -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)

6
gDP.h
View File

@ -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