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

Implement depth texture load for nfl quaterback 98

Fixed nfl quaterback 98: missing fb effect (whatever option used) #316
This commit is contained in:
Sergey Lipskiy 2016-04-09 21:07:46 +06:00
parent 5b4ce499c4
commit 6e0d0432a7
9 changed files with 94 additions and 1 deletions

View File

@ -155,6 +155,7 @@ struct Config
#define hack_ModifyVertexXyInShader (1<<13) //Pass screen coordinates provided in gSPModifyVertex to vertes shader.
#define hack_legoRacers (1<<14) //LEGO racers course map
#define hack_doNotResetTLUTmode (1<<15) //Don't set TLUT mode to none after dlist end. Quake 64
#define hack_LoadDepthTextures (1<<16) //Load textures for depth buffer
extern Config config;

View File

@ -535,3 +535,7 @@ void SetMonochromeCombiner() {
}
gDP.changed |= CHANGED_COMBINE;
}
bool SetDepthTextureCombiner() {
return false;
}

View File

@ -133,6 +133,7 @@ void DestroyShaderCombiner();
void SetDepthFogCombiner();
void SetMonochromeCombiner();
#endif // GL_IMAGE_TEXTURES_SUPPORT
bool SetDepthTextureCombiner();
//#define USE_TOONIFY

View File

@ -29,6 +29,7 @@ static GLuint g_readtex_shader_object;
static GLuint g_readtex_ms_shader_object;
static GLuint g_dither_shader_object;
static GLuint g_monochrome_image_program = 0;
static GLuint g_depth_texture_program = 0;
#ifdef GL_IMAGE_TEXTURES_SUPPORT
GLuint g_draw_shadow_map_program = 0;
@ -228,6 +229,24 @@ void InitShaderCombiner()
glUseProgram(g_monochrome_image_program);
const int texLoc = glGetUniformLocation(g_monochrome_image_program, "uColorImage");
glUniform1i(texLoc, 0);
if ((config.generalEmulation.hacks&hack_LoadDepthTextures) != 0) {
GLuint depth_texture_shader_object = _createShader(GL_FRAGMENT_SHADER, depth_texture_fragment_shader);
g_depth_texture_program = glCreateProgram();
glBindAttribLocation(g_depth_texture_program, SC_POSITION, "aPosition");
glBindAttribLocation(g_depth_texture_program, SC_TEXCOORD0, "aTexCoord0");
glAttachShader(g_depth_texture_program, g_vertex_shader_object);
glAttachShader(g_depth_texture_program, depth_texture_shader_object);
glLinkProgram(g_depth_texture_program);
glDeleteShader(depth_texture_shader_object);
assert(checkProgramLinkStatus(g_depth_texture_program));
glUseProgram(g_depth_texture_program);
int loc = glGetUniformLocation(g_depth_texture_program, "uTex0");
glUniform1i(loc, 0);
loc = glGetUniformLocation(g_depth_texture_program, "uRenderState");
glUniform1i(loc, OGLRender::rsTexRect);
}
glUseProgram(0);
#ifdef GL_IMAGE_TEXTURES_SUPPORT
@ -267,6 +286,8 @@ void DestroyShaderCombiner() {
glDeleteProgram(g_monochrome_image_program);
g_monochrome_image_program = 0;
noiseTex.destroy();
glDeleteProgram(g_depth_texture_program);
g_depth_texture_program = 0;
#ifdef GL_IMAGE_TEXTURES_SUPPORT
DestroyZlutTexture();
@ -879,7 +900,18 @@ void SetDepthFogCombiner()
}
#endif // GL_IMAGE_TEXTURES_SUPPORT
void SetMonochromeCombiner() {
void SetMonochromeCombiner()
{
glUseProgram(g_monochrome_image_program);
gDP.changed |= CHANGED_COMBINE;
}
bool SetDepthTextureCombiner()
{
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_ALWAYS);
glDepthMask(TRUE);
glUseProgram(g_depth_texture_program);
gDP.changed |= CHANGED_COMBINE | CHANGED_RENDERMODE;
return true;
}

View File

@ -673,3 +673,19 @@ MAIN_SHADER_VERSION
"} \n"
;
#endif
static const char* depth_texture_fragment_shader =
MAIN_SHADER_VERSION
"uniform sampler2D uTex0; \n"
"in mediump vec2 vTexCoord0; \n"
"void main() \n"
"{ \n"
#ifdef GLESX
"#ifdef GL_NV_fragdepth \n"
" gl_FragDepth = texture(uTex0, vTexCoord0).r; \n"
"#endif \n"
#else
" gl_FragDepth = texture(uTex0, vTexCoord0).r; \n"
#endif
"} \n"
;

View File

@ -988,6 +988,18 @@ bool texturedRectDepthBufferCopy(const OGLRender::TexturedRectParams & _params)
return false;
}
static
bool texturedRectDepthBufferRender(const OGLRender::TexturedRectParams & _params)
{
if (gDP.colorImage.address == gDP.depthImageAddress) {
FrameBuffer * pCurBuf = frameBufferList().getCurrent();
if (pCurBuf == nullptr || pCurBuf->m_pDepthBuffer == nullptr)
return true;
return !SetDepthTextureCombiner();
}
return false;
}
static
bool texturedRectCopyToItself(const OGLRender::TexturedRectParams & _params)
{
@ -1485,6 +1497,8 @@ void OGLRender::_setSpecialTexrect() const
texturedRectSpecial = texturedRectPaletteMod;
else if (strstr(name, (const char *)"ZELDA"))
texturedRectSpecial = texturedRectMonochromeBackground;
else if (strstr(name, (const char *)"quarterback_club_98"))
texturedRectSpecial = texturedRectDepthBufferRender;
else
texturedRectSpecial = NULL;
}

View File

@ -352,6 +352,8 @@ void RSP_Init()
config.generalEmulation.hacks |= hack_ModifyVertexXyInShader;
else if (strstr(RSP.romname, (const char *)"Quake") != NULL)
config.generalEmulation.hacks |= hack_doNotResetTLUTmode;
else if (strstr(RSP.romname, (const char *)"quarterback_club_98") != NULL)
config.generalEmulation.hacks |= hack_LoadDepthTextures;
api().FindPluginPath(RSP.pluginpath);

View File

@ -881,6 +881,22 @@ bool TextureCache::_loadHiresTexture(u32 _tile, CachedTexture *_pTexture, u64 &
return false;
}
void TextureCache::_loadDepthTexture(CachedTexture * _pTexture, u16* _pDest)
{
#ifndef GLES2
const u32 numTexels = _pTexture->realWidth * _pTexture->realHeight;
_pTexture->textureBytes = numTexels * sizeof(GLfloat);
GLfloat * pDestF = (GLfloat*)malloc(_pTexture->textureBytes);
assert(pDestF != NULL);
for (u32 t = 0; t < numTexels; ++t)
pDestF[t] = _pDest[t] / 65535.0f;
glTexImage2D(GL_TEXTURE_2D, 0, GL_RED, _pTexture->realWidth, _pTexture->realHeight, 0, GL_RED, GL_FLOAT, pDestF);
free(pDestF);
#endif
}
/*
* Worker function for _load
*/
@ -1047,6 +1063,12 @@ void TextureCache::_load(u32 _tile, CachedTexture *_pTexture)
while (true) {
_getTextureDestData(tmptex, pDest, glInternalFormat, GetTexel, &line);
if ((config.generalEmulation.hacks&hack_LoadDepthTextures) != 0 && gDP.colorImage.address == gDP.depthImageAddress) {
_loadDepthTexture(_pTexture, (u16*)pDest);
free(pDest);
return;
}
if (m_toggleDumpTex &&
config.textureFilter.txHiresEnable != 0 &&
config.textureFilter.txDump != 0) {

View File

@ -77,6 +77,7 @@ private:
bool _loadHiresTexture(u32 _tile, CachedTexture *_pTexture, u64 & _ricecrc);
void _loadBackground(CachedTexture *pTexture);
bool _loadHiresBackground(CachedTexture *_pTexture);
void _loadDepthTexture(CachedTexture * _pTexture, u16* _pDest);
void _updateBackground();
void _clear();
void _initDummyTexture(CachedTexture * _pDummy);