mirror of
https://github.com/blawar/GLideN64.git
synced 2024-07-04 10:03:36 +00:00
FrameBuffer: Replace pointer to depth texture by pointer to DepthBuffer
This commit is contained in:
parent
5070a1aa82
commit
8e3e41356a
|
@ -169,7 +169,7 @@ FrameBuffer *FrameBuffer_AddTop()
|
||||||
FrameBuffer *newtop = (FrameBuffer*)malloc( sizeof( FrameBuffer ) );
|
FrameBuffer *newtop = (FrameBuffer*)malloc( sizeof( FrameBuffer ) );
|
||||||
|
|
||||||
newtop->texture = TextureCache_AddTop();
|
newtop->texture = TextureCache_AddTop();
|
||||||
newtop->depth_texture = NULL;
|
newtop->pDepthBuffer = NULL;
|
||||||
newtop->fbo = 0;
|
newtop->fbo = 0;
|
||||||
|
|
||||||
newtop->lower = frameBuffer.top;
|
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);
|
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_MAG_FILTER, GL_LINEAR );
|
||||||
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_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();
|
void GLSL_ClearDepthBuffer();
|
||||||
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 ( frameBuffer.top != NULL && frameBuffer.top->fbo > 0 && depthBuffer.top != NULL && depthBuffer.top->renderbuf > 0) {
|
||||||
if (depthBuffer.top->depth_texture == NULL)
|
if (depthBuffer.top->depth_texture == NULL)
|
||||||
_initDepthTexture();
|
_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);
|
ogl_glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depthBuffer.top->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);
|
||||||
assert(checkFBO());
|
assert(checkFBO());
|
||||||
} else if (frameBuffer.top != NULL) {
|
} else if (frameBuffer.top != NULL) {
|
||||||
frameBuffer.top->depth_texture = 0;
|
frameBuffer.top->pDepthBuffer = 0;
|
||||||
GLuint attachments[1] = { GL_COLOR_ATTACHMENT0 };
|
GLuint attachments[1] = { GL_COLOR_ATTACHMENT0 };
|
||||||
ogl_glDrawBuffers(1, attachments, frameBuffer.top->texture->glName);
|
ogl_glDrawBuffers(1, attachments, frameBuffer.top->texture->glName);
|
||||||
assert(checkFBO());
|
assert(checkFBO());
|
||||||
|
|
|
@ -4,13 +4,14 @@
|
||||||
#include "Types.h"
|
#include "Types.h"
|
||||||
#include "Textures.h"
|
#include "Textures.h"
|
||||||
struct gDPTile;
|
struct gDPTile;
|
||||||
|
struct DepthBuffer;
|
||||||
|
|
||||||
struct FrameBuffer
|
struct FrameBuffer
|
||||||
{
|
{
|
||||||
FrameBuffer *higher, *lower;
|
FrameBuffer *higher, *lower;
|
||||||
|
|
||||||
CachedTexture *texture;
|
CachedTexture *texture;
|
||||||
const CachedTexture *depth_texture;
|
DepthBuffer *pDepthBuffer;
|
||||||
GLuint fbo;
|
GLuint fbo;
|
||||||
|
|
||||||
u32 startAddress, endAddress;
|
u32 startAddress, endAddress;
|
||||||
|
@ -31,7 +32,6 @@ extern FrameBufferInfo frameBuffer;
|
||||||
extern bool g_bCopyToRDRAM;
|
extern bool g_bCopyToRDRAM;
|
||||||
extern bool g_bCopyFromRDRAM;
|
extern bool g_bCopyFromRDRAM;
|
||||||
extern bool g_bUseFloatDepthTexture;
|
extern bool g_bUseFloatDepthTexture;
|
||||||
struct DepthBuffer;
|
|
||||||
|
|
||||||
void FrameBuffer_Init();
|
void FrameBuffer_Init();
|
||||||
void FrameBuffer_Destroy();
|
void FrameBuffer_Destroy();
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
#include "GLSLCombiner.h"
|
#include "GLSLCombiner.h"
|
||||||
#include "Shaders.h"
|
#include "Shaders.h"
|
||||||
#include "Noise_shader.h"
|
#include "Noise_shader.h"
|
||||||
|
#include "DepthBuffer.h"
|
||||||
|
|
||||||
static GLuint g_vertex_shader_object;
|
static GLuint g_vertex_shader_object;
|
||||||
static GLuint g_calc_light_shader_object;
|
static GLuint g_calc_light_shader_object;
|
||||||
|
@ -589,8 +590,9 @@ void GLSLCombiner::UpdateDepthInfo() {
|
||||||
|
|
||||||
_unbindImageTextures();
|
_unbindImageTextures();
|
||||||
|
|
||||||
if (frameBuffer.top == NULL || frameBuffer.top->depth_texture == NULL)
|
if (frameBuffer.top == NULL || frameBuffer.top->pDepthBuffer == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
int nDepthEnabled = (gSP.geometryMode & G_ZBUFFER) > 0 ? 1 : 0;
|
int nDepthEnabled = (gSP.geometryMode & G_ZBUFFER) > 0 ? 1 : 0;
|
||||||
int depth_enabled_location = glGetUniformLocation(m_program, "depthEnabled");
|
int depth_enabled_location = glGetUniformLocation(m_program, "depthEnabled");
|
||||||
glUniform1i(depth_enabled_location, nDepthEnabled);
|
glUniform1i(depth_enabled_location, nDepthEnabled);
|
||||||
|
@ -610,7 +612,7 @@ void GLSLCombiner::UpdateDepthInfo() {
|
||||||
glUniform1i(depth_polygon_offset, iPlygonOffset);
|
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);
|
glBindImageTexture(ZlutImageUnit, g_zlut_tex, 0, GL_FALSE, 0, GL_READ_ONLY, GL_R16UI);
|
||||||
GLenum depthTexFormat = g_bUseFloatDepthTexture ? GL_R32F : GL_R16UI;
|
GLenum depthTexFormat = g_bUseFloatDepthTexture ? GL_R32F : GL_R16UI;
|
||||||
glBindImageTexture(depthImageUnit, texture, 0, GL_FALSE, 0, GL_READ_WRITE, depthTexFormat);
|
glBindImageTexture(depthImageUnit, texture, 0, GL_FALSE, 0, GL_READ_WRITE, depthTexFormat);
|
||||||
|
@ -620,10 +622,11 @@ void GLSL_ClearDepthBuffer() {
|
||||||
if (!OGL.bImageTexture)
|
if (!OGL.bImageTexture)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (frameBuffer.top == NULL || frameBuffer.top->depth_texture == NULL)
|
if (frameBuffer.top == NULL || frameBuffer.top->pDepthBuffer == NULL)
|
||||||
return;
|
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;
|
GLenum type = GL_UNSIGNED_SHORT;
|
||||||
int dataSize = g_bUseFloatDepthTexture ? sizeof(float) : sizeof(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++)
|
for (int i = 0; i < numTexels; i++)
|
||||||
pDepth[i] = 0xfffc;
|
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,
|
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);
|
GL_RED, type, pData);
|
||||||
free(pData);
|
free(pData);
|
||||||
|
|
||||||
|
@ -682,12 +685,12 @@ void GLSL_RenderDepth() {
|
||||||
ogl_glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
|
ogl_glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
|
||||||
ogl_glBindFramebuffer(GL_DRAW_FRAMEBUFFER, frameBuffer.top != NULL ? frameBuffer.top->fbo : 0);
|
ogl_glBindFramebuffer(GL_DRAW_FRAMEBUFFER, frameBuffer.top != NULL ? frameBuffer.top->fbo : 0);
|
||||||
#else
|
#else
|
||||||
if (frameBuffer.top == NULL || frameBuffer.top->depth_texture == NULL)
|
if (frameBuffer.top == NULL || frameBuffer.top->pDepthBuffer == NULL)
|
||||||
return;
|
return;
|
||||||
glPushAttrib( GL_ENABLE_BIT | GL_VIEWPORT_BIT );
|
glPushAttrib( GL_ENABLE_BIT | GL_VIEWPORT_BIT );
|
||||||
|
|
||||||
glActiveTexture( GL_TEXTURE0 );
|
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);
|
// 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 ) );
|
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);
|
glBindImageTexture(TlutImageUnit, g_tlut_tex, 0, GL_FALSE, 0, GL_READ_ONLY, GL_R16UI);
|
||||||
GLenum depthTexFormat = g_bUseFloatDepthTexture ? GL_R32F : 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);
|
glBindImageTexture(depthImageUnit, texture, 0, GL_FALSE, 0, GL_READ_ONLY, depthTexFormat);
|
||||||
gDP.changed |= CHANGED_COMBINE;
|
gDP.changed |= CHANGED_COMBINE;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user