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

Fix depth compare for texrects rendered with TexrectDrawer.

Fixed Duke Nukem 64: 2D Render Issue #1915
This commit is contained in:
Sergey Lipskiy 2018-10-21 20:14:58 +07:00
parent a44d5a8960
commit f72553a524
2 changed files with 34 additions and 10 deletions

View File

@ -2,6 +2,7 @@
#include <N64.h> #include <N64.h>
#include <FrameBuffer.h> #include <FrameBuffer.h>
#include <gDP.h> #include <gDP.h>
#include <GBI.h>
#include <Config.h> #include <Config.h>
#include <PaletteTexture.h> #include <PaletteTexture.h>
#include <ZlutTexture.h> #include <ZlutTexture.h>
@ -301,15 +302,25 @@ namespace glsl {
; ;
} else { } else {
m_part = m_part =
"uniform sampler2D uTex0; \n" "uniform sampler2D uTex0; \n"
"uniform lowp int uEnableAlphaTest; \n" "uniform lowp int uEnableAlphaTest; \n"
"lowp vec4 uTestColor = vec4(4.0/255.0, 2.0/255.0, 1.0/255.0, 0.0); \n" "uniform highp float uPrimDepth; \n"
"in mediump vec2 vTexCoord0; \n" "lowp vec4 uTestColor = vec4(4.0/255.0, 2.0/255.0, 1.0/255.0, 0.0); \n"
"out lowp vec4 fragColor; \n" "in mediump vec2 vTexCoord0; \n"
"void main() \n" "out lowp vec4 fragColor; \n"
"{ \n" "void main() \n"
" TEX_FILTER(fragColor, uTex0, vTexCoord0); \n" "{ \n"
"} \n" " TEX_FILTER(fragColor, uTex0, vTexCoord0); \n"
;
if (!_glinfo.isGLES2 &&
config.generalEmulation.enableFragmentDepthWrite != 0 &&
config.frameBufferEmulation.N64DepthCompare == 0) {
m_part +=
" gl_FragDepth = uPrimDepth; \n"
;
}
m_part +=
"} \n"
; ;
} }
} }
@ -552,6 +563,7 @@ namespace glsl {
const ShaderPart * _fragmentHeader) const ShaderPart * _fragmentHeader)
: m_program(0) : m_program(0)
, m_useProgram(_useProgram) , m_useProgram(_useProgram)
, m_depth(0)
{ {
VertexShaderTexturedRect vertexBody(_glinfo); VertexShaderTexturedRect vertexBody(_glinfo);
std::stringstream ssVertexShader; std::stringstream ssVertexShader;
@ -581,6 +593,7 @@ namespace glsl {
glUniform1i(loc, 0); glUniform1i(loc, 0);
m_textureSizeLoc = glGetUniformLocation(GLuint(m_program), "uTextureSize"); m_textureSizeLoc = glGetUniformLocation(GLuint(m_program), "uTextureSize");
m_enableAlphaTestLoc = glGetUniformLocation(GLuint(m_program), "uEnableAlphaTest"); m_enableAlphaTestLoc = glGetUniformLocation(GLuint(m_program), "uEnableAlphaTest");
m_primDepthLoc = glGetUniformLocation(GLuint(m_program), "uPrimDepth");
m_useProgram->useProgram(graphics::ObjectHandle::null); m_useProgram->useProgram(graphics::ObjectHandle::null);
} }
@ -593,6 +606,13 @@ namespace glsl {
void activate() override void activate() override
{ {
m_useProgram->useProgram(m_program); m_useProgram->useProgram(m_program);
if (m_primDepthLoc >= 0) {
const GLfloat depth = gDP.otherMode.depthSource == G_ZS_PRIM ? gDP.primDepth.z : 0.0f;
if (depth != m_depth) {
m_depth = depth;
glUniform1f(m_primDepthLoc, m_depth);
}
}
gDP.changed |= CHANGED_COMBINE; gDP.changed |= CHANGED_COMBINE;
} }
@ -617,6 +637,8 @@ namespace glsl {
opengl::CachedUseProgram * m_useProgram; opengl::CachedUseProgram * m_useProgram;
GLint m_enableAlphaTestLoc; GLint m_enableAlphaTestLoc;
GLint m_textureSizeLoc; GLint m_textureSizeLoc;
GLint m_primDepthLoc;
GLfloat m_depth;
}; };
typedef SpecialShader<VertexShaderTexturedRect, TexrectDrawerFragmentClear> TexrectDrawerShaderClear; typedef SpecialShader<VertexShaderTexturedRect, TexrectDrawerFragmentClear> TexrectDrawerShaderClear;

View File

@ -228,7 +228,9 @@ bool TexrectDrawer::add()
m_pBuffer = frameBufferList().getCurrent(); m_pBuffer = frameBufferList().getCurrent();
m_otherMode = gDP.otherMode._u64; m_otherMode = gDP.otherMode._u64;
m_mux = gDP.combine.mux; m_mux = gDP.combine.mux;
m_Z = (gDP.otherMode.depthSource == G_ZS_PRIM) ? gDP.primDepth.z : gSP.viewport.nearz; m_Z = (gDP.otherMode.depthSource == G_ZS_PRIM) ?
(gDP.primDepth.z - gSP.viewport.vtrans[2]) / gSP.viewport.vscale[2] :
gSP.viewport.nearz;
m_scissor = gDP.scissor; m_scissor = gDP.scissor;
m_ulx = pRect[0].x; m_ulx = pRect[0].x;