Render3D:

- In the OpenGL renderer, optimize edge marking performance.
- In SoftRasterizer, fix a bug where edge marking and fog weren’t being drawn if multithreading was off.
This commit is contained in:
rogerman 2015-04-29 17:35:50 +00:00
parent 8f38fb38e8
commit 5c64a3858f
8 changed files with 53 additions and 141 deletions

View File

@ -329,7 +329,7 @@ static const char *fragmentShader_100 = {"\
\n\ \n\
gl_FragData[0] = newFragColor;\n\ gl_FragData[0] = newFragColor;\n\
gl_FragData[1] = vec4( packVec3FromFloat(newFragDepth), float(polyEnableDepthWrite && (newFragColor.a > 0.999 || polySetNewDepthForTranslucent)));\n\ gl_FragData[1] = vec4( packVec3FromFloat(newFragDepth), float(polyEnableDepthWrite && (newFragColor.a > 0.999 || polySetNewDepthForTranslucent)));\n\
gl_FragData[2] = vec4(float(polyID)/63.0, float(stateEnableAntialiasing), 0.0, float(newFragColor.a > 0.999));\n\ gl_FragData[2] = vec4(float(polyID)/63.0, 0.0, 0.0, float(newFragColor.a > 0.999));\n\
gl_FragData[3] = vec4( float(polyEnableFog), 0.0, 0.0, float(newFragColor.a > 0.999 || !polyEnableFog));\n\ gl_FragData[3] = vec4( float(polyEnableFog), 0.0, 0.0, float(newFragColor.a > 0.999 || !polyEnableFog));\n\
gl_FragDepth = newFragDepth;\n\ gl_FragDepth = newFragDepth;\n\
} \n\ } \n\
@ -360,7 +360,6 @@ static const char *EdgeMarkVtxShader_100 = {"\
static const char *EdgeMarkFragShader_100 = {"\ static const char *EdgeMarkFragShader_100 = {"\
varying vec2 texCoord[5];\n\ varying vec2 texCoord[5];\n\
\n\ \n\
uniform sampler2D texInFragColor;\n\
uniform sampler2D texInFragDepth;\n\ uniform sampler2D texInFragDepth;\n\
uniform sampler2D texInPolyID;\n\ uniform sampler2D texInPolyID;\n\
uniform vec4 stateEdgeColor[8];\n\ uniform vec4 stateEdgeColor[8];\n\
@ -373,9 +372,6 @@ static const char *EdgeMarkFragShader_100 = {"\
\n\ \n\
void main()\n\ void main()\n\
{\n\ {\n\
vec4 inFragColor = texture2D(texInFragColor, texCoord[0]);\n\
float inFragDepth = unpackFloatFromVec3(texture2D(texInFragDepth, texCoord[0]).rgb);\n\
\n\
vec4 inPolyIDAttributes[5];\n\ vec4 inPolyIDAttributes[5];\n\
inPolyIDAttributes[0] = texture2D(texInPolyID, texCoord[0]);\n\ inPolyIDAttributes[0] = texture2D(texInPolyID, texCoord[0]);\n\
inPolyIDAttributes[1] = texture2D(texInPolyID, texCoord[1]);\n\ inPolyIDAttributes[1] = texture2D(texInPolyID, texCoord[1]);\n\
@ -390,13 +386,6 @@ static const char *EdgeMarkFragShader_100 = {"\
polyID[3] = int((inPolyIDAttributes[3].r * 63.0) + 0.5);\n\ polyID[3] = int((inPolyIDAttributes[3].r * 63.0) + 0.5);\n\
polyID[4] = int((inPolyIDAttributes[4].r * 63.0) + 0.5);\n\ polyID[4] = int((inPolyIDAttributes[4].r * 63.0) + 0.5);\n\
\n\ \n\
bool antialias[5];\n\
antialias[0] = bool(inPolyIDAttributes[0].g);\n\
antialias[1] = bool(inPolyIDAttributes[1].g);\n\
antialias[2] = bool(inPolyIDAttributes[2].g);\n\
antialias[3] = bool(inPolyIDAttributes[3].g);\n\
antialias[4] = bool(inPolyIDAttributes[4].g);\n\
\n\
float depth[5];\n\ float depth[5];\n\
depth[0] = unpackFloatFromVec3(texture2D(texInFragDepth, texCoord[0]).rgb);\n\ depth[0] = unpackFloatFromVec3(texture2D(texInFragDepth, texCoord[0]).rgb);\n\
depth[1] = unpackFloatFromVec3(texture2D(texInFragDepth, texCoord[1]).rgb);\n\ depth[1] = unpackFloatFromVec3(texture2D(texInFragDepth, texCoord[1]).rgb);\n\
@ -404,22 +393,18 @@ static const char *EdgeMarkFragShader_100 = {"\
depth[3] = unpackFloatFromVec3(texture2D(texInFragDepth, texCoord[3]).rgb);\n\ depth[3] = unpackFloatFromVec3(texture2D(texInFragDepth, texCoord[3]).rgb);\n\
depth[4] = unpackFloatFromVec3(texture2D(texInFragDepth, texCoord[4]).rgb);\n\ depth[4] = unpackFloatFromVec3(texture2D(texInFragDepth, texCoord[4]).rgb);\n\
\n\ \n\
vec4 edgeColor = stateEdgeColor[polyID[0]/8];\n\ vec4 edgeColor = vec4(0.0, 0.0, 0.0, 0.0);\n\
bool doEdgeMark = false;\n\
bool doAntialias = false;\n\
\n\ \n\
for (int i = 1; i < 5; i++)\n\ for (int i = 1; i < 5; i++)\n\
{\n\ {\n\
if (polyID[0] != polyID[i] && depth[0] >= depth[i])\n\ if (polyID[0] != polyID[i] && depth[0] >= depth[i])\n\
{\n\ {\n\
doEdgeMark = true;\n\
edgeColor = stateEdgeColor[polyID[i]/8];\n\ edgeColor = stateEdgeColor[polyID[i]/8];\n\
doAntialias = antialias[i];\n\
break;\n\ break;\n\
}\n\ }\n\
}\n\ }\n\
\n\ \n\
gl_FragData[0] = mix(inFragColor, edgeColor, (doEdgeMark) ? ((doAntialias) ? (16.0/31.0) : 1.0) : 0.0);\n\ gl_FragData[0] = edgeColor;\n\
}\n\ }\n\
"}; "};
@ -1391,7 +1376,6 @@ Render3DError OpenGLRenderer_1_2::CreateFBOs()
glGenTextures(1, &OGLRef.texGPolyID); glGenTextures(1, &OGLRef.texGPolyID);
glGenTextures(1, &OGLRef.texGFogAttrID); glGenTextures(1, &OGLRef.texGFogAttrID);
glGenTextures(1, &OGLRef.texGDepthStencilID); glGenTextures(1, &OGLRef.texGDepthStencilID);
glGenTextures(1, &OGLRef.texPostprocessEdgeMarkID);
glGenTextures(1, &OGLRef.texPostprocessFogID); glGenTextures(1, &OGLRef.texPostprocessFogID);
glBindTexture(GL_TEXTURE_2D, OGLRef.texGColorID); glBindTexture(GL_TEXTURE_2D, OGLRef.texGColorID);
@ -1430,13 +1414,6 @@ Render3DError OpenGLRenderer_1_2::CreateFBOs()
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, GFX3D_FRAMEBUFFER_WIDTH, GFX3D_FRAMEBUFFER_HEIGHT, 0, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, NULL); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, GFX3D_FRAMEBUFFER_WIDTH, GFX3D_FRAMEBUFFER_HEIGHT, 0, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, NULL);
glBindTexture(GL_TEXTURE_2D, OGLRef.texPostprocessEdgeMarkID);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, GFX3D_FRAMEBUFFER_WIDTH, GFX3D_FRAMEBUFFER_HEIGHT, 0, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, NULL);
glBindTexture(GL_TEXTURE_2D, OGLRef.texPostprocessFogID); glBindTexture(GL_TEXTURE_2D, OGLRef.texPostprocessFogID);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
@ -1470,7 +1447,6 @@ Render3DError OpenGLRenderer_1_2::CreateFBOs()
glDeleteTextures(1, &OGLRef.texGPolyID); glDeleteTextures(1, &OGLRef.texGPolyID);
glDeleteTextures(1, &OGLRef.texGFogAttrID); glDeleteTextures(1, &OGLRef.texGFogAttrID);
glDeleteTextures(1, &OGLRef.texGDepthStencilID); glDeleteTextures(1, &OGLRef.texGDepthStencilID);
glDeleteTextures(1, &OGLRef.texPostprocessEdgeMarkID);
glDeleteTextures(1, &OGLRef.texPostprocessFogID); glDeleteTextures(1, &OGLRef.texPostprocessFogID);
this->isFBOSupported = false; this->isFBOSupported = false;
@ -1481,8 +1457,7 @@ Render3DError OpenGLRenderer_1_2::CreateFBOs()
glReadBuffer(GL_COLOR_ATTACHMENT0_EXT); glReadBuffer(GL_COLOR_ATTACHMENT0_EXT);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, OGLRef.fboPostprocessID); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, OGLRef.fboPostprocessID);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, OGLRef.texPostprocessEdgeMarkID, 0); glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, OGLRef.texPostprocessFogID, 0);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT1_EXT, GL_TEXTURE_2D, OGLRef.texPostprocessFogID, 0);
if (glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT) != GL_FRAMEBUFFER_COMPLETE_EXT) if (glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT) != GL_FRAMEBUFFER_COMPLETE_EXT)
{ {
@ -1496,7 +1471,6 @@ Render3DError OpenGLRenderer_1_2::CreateFBOs()
glDeleteTextures(1, &OGLRef.texGPolyID); glDeleteTextures(1, &OGLRef.texGPolyID);
glDeleteTextures(1, &OGLRef.texGFogAttrID); glDeleteTextures(1, &OGLRef.texGFogAttrID);
glDeleteTextures(1, &OGLRef.texGDepthStencilID); glDeleteTextures(1, &OGLRef.texGDepthStencilID);
glDeleteTextures(1, &OGLRef.texPostprocessEdgeMarkID);
glDeleteTextures(1, &OGLRef.texPostprocessFogID); glDeleteTextures(1, &OGLRef.texPostprocessFogID);
this->isFBOSupported = false; this->isFBOSupported = false;
@ -1530,7 +1504,7 @@ void OpenGLRenderer_1_2::DestroyFBOs()
glDeleteTextures(1, &OGLRef.texGPolyID); glDeleteTextures(1, &OGLRef.texGPolyID);
glDeleteTextures(1, &OGLRef.texGFogAttrID); glDeleteTextures(1, &OGLRef.texGFogAttrID);
glDeleteTextures(1, &OGLRef.texGDepthStencilID); glDeleteTextures(1, &OGLRef.texGDepthStencilID);
glDeleteTextures(1, &OGLRef.texPostprocessEdgeMarkID); glDeleteTextures(1, &OGLRef.texPostprocessFogID);
OGLRef.fboRenderID = 0; OGLRef.fboRenderID = 0;
OGLRef.fboPostprocessID = 0; OGLRef.fboPostprocessID = 0;
@ -1659,9 +1633,6 @@ Render3DError OpenGLRenderer_1_2::InitFinalRenderStates(const std::set<std::stri
// Mirrored Repeat Mode Support // Mirrored Repeat Mode Support
OGLRef.stateTexMirroredRepeat = isTexMirroredRepeatSupported ? GL_MIRRORED_REPEAT : GL_REPEAT; OGLRef.stateTexMirroredRepeat = isTexMirroredRepeatSupported ? GL_MIRRORED_REPEAT : GL_REPEAT;
// Always enable depth test, and control using glDepthMask().
glEnable(GL_DEPTH_TEST);
// Map the vertex list's colors with 4 floats per color. This is being done // Map the vertex list's colors with 4 floats per color. This is being done
// because OpenGL needs 4-colors per vertex to support translucency. (The DS // because OpenGL needs 4-colors per vertex to support translucency. (The DS
// uses 3-colors per vertex, and adds alpha through the poly, so we can't // uses 3-colors per vertex, and adds alpha through the poly, so we can't
@ -2243,7 +2214,6 @@ Render3DError OpenGLRenderer_1_2::EndRender(const u64 frameCount)
TexCache_EvictFrame(); TexCache_EvictFrame();
this->ReadBackPixels(); this->ReadBackPixels();
this->didRenderEdgeMark = false;
return OGLERROR_NOERR; return OGLERROR_NOERR;
} }
@ -2539,7 +2509,6 @@ Render3DError OpenGLRenderer_1_2::Reset()
this->gpuScreen3DHasNewData[0] = false; this->gpuScreen3DHasNewData[0] = false;
this->gpuScreen3DHasNewData[1] = false; this->gpuScreen3DHasNewData[1] = false;
didRenderEdgeMark = false;
glFinish(); glFinish();
@ -2693,9 +2662,6 @@ Render3DError OpenGLRenderer_1_4::InitFinalRenderStates(const std::set<std::stri
// Mirrored Repeat Mode Support // Mirrored Repeat Mode Support
OGLRef.stateTexMirroredRepeat = GL_MIRRORED_REPEAT; OGLRef.stateTexMirroredRepeat = GL_MIRRORED_REPEAT;
// Always enable depth test, and control using glDepthMask().
glEnable(GL_DEPTH_TEST);
// Map the vertex list's colors with 4 floats per color. This is being done // Map the vertex list's colors with 4 floats per color. This is being done
// because OpenGL needs 4-colors per vertex to support translucency. (The DS // because OpenGL needs 4-colors per vertex to support translucency. (The DS
// uses 3-colors per vertex, and adds alpha through the poly, so we can't // uses 3-colors per vertex, and adds alpha through the poly, so we can't
@ -3069,9 +3035,6 @@ Render3DError OpenGLRenderer_2_0::InitFinalRenderStates(const std::set<std::stri
// Mirrored Repeat Mode Support // Mirrored Repeat Mode Support
OGLRef.stateTexMirroredRepeat = GL_MIRRORED_REPEAT; OGLRef.stateTexMirroredRepeat = GL_MIRRORED_REPEAT;
// Always enable depth test, and control using glDepthMask().
glEnable(GL_DEPTH_TEST);
// Ignore our color buffer since we'll transfer the polygon alpha through a uniform. // Ignore our color buffer since we'll transfer the polygon alpha through a uniform.
OGLRef.color4fBuffer = NULL; OGLRef.color4fBuffer = NULL;
@ -3423,48 +3386,47 @@ Render3DError OpenGLRenderer_2_0::BeginRender(const GFX3D_State *renderState)
return OGLERROR_NOERR; return OGLERROR_NOERR;
} }
Render3DError OpenGLRenderer_2_0::RenderEdgeMarking(const u16 *colorTable) Render3DError OpenGLRenderer_2_0::RenderEdgeMarking(const u16 *colorTable, const bool useAntialias)
{ {
OGLRenderRef &OGLRef = *this->ref; OGLRenderRef &OGLRef = *this->ref;
const GLfloat alpha = (useAntialias) ? (16.0f/31.0f) : 1.0f;
const GLfloat oglColor[4*8] = {divide5bitBy31_LUT[(colorTable[0] ) & 0x001F], const GLfloat oglColor[4*8] = {divide5bitBy31_LUT[(colorTable[0] ) & 0x001F],
divide5bitBy31_LUT[(colorTable[0] >> 5) & 0x001F], divide5bitBy31_LUT[(colorTable[0] >> 5) & 0x001F],
divide5bitBy31_LUT[(colorTable[0] >> 10) & 0x001F], divide5bitBy31_LUT[(colorTable[0] >> 10) & 0x001F],
1.0f, alpha,
divide5bitBy31_LUT[(colorTable[1] ) & 0x001F], divide5bitBy31_LUT[(colorTable[1] ) & 0x001F],
divide5bitBy31_LUT[(colorTable[1] >> 5) & 0x001F], divide5bitBy31_LUT[(colorTable[1] >> 5) & 0x001F],
divide5bitBy31_LUT[(colorTable[1] >> 10) & 0x001F], divide5bitBy31_LUT[(colorTable[1] >> 10) & 0x001F],
1.0f, alpha,
divide5bitBy31_LUT[(colorTable[2] ) & 0x001F], divide5bitBy31_LUT[(colorTable[2] ) & 0x001F],
divide5bitBy31_LUT[(colorTable[2] >> 5) & 0x001F], divide5bitBy31_LUT[(colorTable[2] >> 5) & 0x001F],
divide5bitBy31_LUT[(colorTable[2] >> 10) & 0x001F], divide5bitBy31_LUT[(colorTable[2] >> 10) & 0x001F],
1.0f, alpha,
divide5bitBy31_LUT[(colorTable[3] ) & 0x001F], divide5bitBy31_LUT[(colorTable[3] ) & 0x001F],
divide5bitBy31_LUT[(colorTable[3] >> 5) & 0x001F], divide5bitBy31_LUT[(colorTable[3] >> 5) & 0x001F],
divide5bitBy31_LUT[(colorTable[3] >> 10) & 0x001F], divide5bitBy31_LUT[(colorTable[3] >> 10) & 0x001F],
1.0f, alpha,
divide5bitBy31_LUT[(colorTable[4] ) & 0x001F], divide5bitBy31_LUT[(colorTable[4] ) & 0x001F],
divide5bitBy31_LUT[(colorTable[4] >> 5) & 0x001F], divide5bitBy31_LUT[(colorTable[4] >> 5) & 0x001F],
divide5bitBy31_LUT[(colorTable[4] >> 10) & 0x001F], divide5bitBy31_LUT[(colorTable[4] >> 10) & 0x001F],
1.0f, alpha,
divide5bitBy31_LUT[(colorTable[5] ) & 0x001F], divide5bitBy31_LUT[(colorTable[5] ) & 0x001F],
divide5bitBy31_LUT[(colorTable[5] >> 5) & 0x001F], divide5bitBy31_LUT[(colorTable[5] >> 5) & 0x001F],
divide5bitBy31_LUT[(colorTable[5] >> 10) & 0x001F], divide5bitBy31_LUT[(colorTable[5] >> 10) & 0x001F],
1.0f, alpha,
divide5bitBy31_LUT[(colorTable[6] ) & 0x001F], divide5bitBy31_LUT[(colorTable[6] ) & 0x001F],
divide5bitBy31_LUT[(colorTable[6] >> 5) & 0x001F], divide5bitBy31_LUT[(colorTable[6] >> 5) & 0x001F],
divide5bitBy31_LUT[(colorTable[6] >> 10) & 0x001F], divide5bitBy31_LUT[(colorTable[6] >> 10) & 0x001F],
1.0f, alpha,
divide5bitBy31_LUT[(colorTable[7] ) & 0x001F], divide5bitBy31_LUT[(colorTable[7] ) & 0x001F],
divide5bitBy31_LUT[(colorTable[7] >> 5) & 0x001F], divide5bitBy31_LUT[(colorTable[7] >> 5) & 0x001F],
divide5bitBy31_LUT[(colorTable[7] >> 10) & 0x001F], divide5bitBy31_LUT[(colorTable[7] >> 10) & 0x001F],
1.0f}; alpha};
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, OGLRef.fboPostprocessID); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, OGLRef.fboRenderID);
glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT); glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT);
glReadBuffer(GL_COLOR_ATTACHMENT0_EXT);
glUseProgram(OGLRef.programEdgeMarkID); glUseProgram(OGLRef.programEdgeMarkID);
glUniform1i(OGLRef.uniformTexGColor_EdgeMark, OGLTextureUnitID_GColor);
glUniform1i(OGLRef.uniformTexGDepth_EdgeMark, OGLTextureUnitID_GDepth); glUniform1i(OGLRef.uniformTexGDepth_EdgeMark, OGLTextureUnitID_GDepth);
glUniform1i(OGLRef.uniformTexGPolyID_EdgeMark, OGLTextureUnitID_GPolyID); glUniform1i(OGLRef.uniformTexGPolyID_EdgeMark, OGLTextureUnitID_GPolyID);
glUniform2f(OGLRef.uniformFramebufferSize, GFX3D_FRAMEBUFFER_WIDTH, GFX3D_FRAMEBUFFER_HEIGHT); glUniform2f(OGLRef.uniformFramebufferSize, GFX3D_FRAMEBUFFER_WIDTH, GFX3D_FRAMEBUFFER_HEIGHT);
@ -3473,7 +3435,7 @@ Render3DError OpenGLRenderer_2_0::RenderEdgeMarking(const u16 *colorTable)
glViewport(0, 0, GFX3D_FRAMEBUFFER_WIDTH, GFX3D_FRAMEBUFFER_HEIGHT); glViewport(0, 0, GFX3D_FRAMEBUFFER_WIDTH, GFX3D_FRAMEBUFFER_HEIGHT);
glDisable(GL_DEPTH_TEST); glDisable(GL_DEPTH_TEST);
glDisable(GL_STENCIL_TEST); glDisable(GL_STENCIL_TEST);
glDisable(GL_BLEND); glEnable(GL_BLEND);
glDisable(GL_CULL_FACE); glDisable(GL_CULL_FACE);
glBindBuffer(GL_ARRAY_BUFFER, OGLRef.vboPostprocessVtxID); glBindBuffer(GL_ARRAY_BUFFER, OGLRef.vboPostprocessVtxID);
@ -3491,8 +3453,6 @@ Render3DError OpenGLRenderer_2_0::RenderEdgeMarking(const u16 *colorTable)
glVertexAttribPointer(OGLVertexAttributeID_TexCoord0, 2, GL_FLOAT, GL_FALSE, 0, (const GLvoid *)(sizeof(GLfloat) * 8)); glVertexAttribPointer(OGLVertexAttributeID_TexCoord0, 2, GL_FLOAT, GL_FALSE, 0, (const GLvoid *)(sizeof(GLfloat) * 8));
} }
glActiveTexture(GL_TEXTURE0 + OGLTextureUnitID_GColor);
glBindTexture(GL_TEXTURE_2D, OGLRef.texGColorID);
glActiveTexture(GL_TEXTURE0 + OGLTextureUnitID_GDepth); glActiveTexture(GL_TEXTURE0 + OGLTextureUnitID_GDepth);
glBindTexture(GL_TEXTURE_2D, OGLRef.texGDepthID); glBindTexture(GL_TEXTURE_2D, OGLRef.texGDepthID);
glActiveTexture(GL_TEXTURE0 + OGLTextureUnitID_GPolyID); glActiveTexture(GL_TEXTURE0 + OGLTextureUnitID_GPolyID);
@ -3510,8 +3470,6 @@ Render3DError OpenGLRenderer_2_0::RenderEdgeMarking(const u16 *colorTable)
glDisableVertexAttribArray(OGLVertexAttributeID_TexCoord0); glDisableVertexAttribArray(OGLVertexAttributeID_TexCoord0);
} }
this->didRenderEdgeMark = true;
return RENDER3DERROR_NOERR; return RENDER3DERROR_NOERR;
} }
@ -3539,8 +3497,6 @@ Render3DError OpenGLRenderer_2_0::RenderFog(const u8 *densityTable, const u32 co
const GLfloat oglFogStep = (GLfloat)(0x0400 >> shift) / 32767.0f; const GLfloat oglFogStep = (GLfloat)(0x0400 >> shift) / 32767.0f;
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, OGLRef.fboPostprocessID); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, OGLRef.fboPostprocessID);
glDrawBuffer(GL_COLOR_ATTACHMENT1_EXT);
glReadBuffer(GL_COLOR_ATTACHMENT1_EXT);
glUseProgram(OGLRef.programFogID); glUseProgram(OGLRef.programFogID);
glUniform1i(OGLRef.uniformTexGColor_Fog, OGLTextureUnitID_GColor); glUniform1i(OGLRef.uniformTexGColor_Fog, OGLTextureUnitID_GColor);
glUniform1i(OGLRef.uniformTexGDepth_Fog, OGLTextureUnitID_GDepth); glUniform1i(OGLRef.uniformTexGDepth_Fog, OGLTextureUnitID_GDepth);
@ -3573,7 +3529,7 @@ Render3DError OpenGLRenderer_2_0::RenderFog(const u8 *densityTable, const u32 co
} }
glActiveTexture(GL_TEXTURE0 + OGLTextureUnitID_GColor); glActiveTexture(GL_TEXTURE0 + OGLTextureUnitID_GColor);
glBindTexture(GL_TEXTURE_2D, (this->didRenderEdgeMark) ? OGLRef.texPostprocessEdgeMarkID : OGLRef.texGColorID); glBindTexture(GL_TEXTURE_2D, OGLRef.texGColorID);
glActiveTexture(GL_TEXTURE0 + OGLTextureUnitID_GDepth); glActiveTexture(GL_TEXTURE0 + OGLTextureUnitID_GDepth);
glBindTexture(GL_TEXTURE_2D, OGLRef.texGDepthID); glBindTexture(GL_TEXTURE_2D, OGLRef.texGDepthID);
glActiveTexture(GL_TEXTURE0 + OGLTextureUnitID_FogAttr); glActiveTexture(GL_TEXTURE0 + OGLTextureUnitID_FogAttr);

View File

@ -325,7 +325,6 @@ struct OGLRenderRef
GLuint texGFogAttrID; GLuint texGFogAttrID;
GLuint texGPolyID; GLuint texGPolyID;
GLuint texGDepthStencilID; GLuint texGDepthStencilID;
GLuint texPostprocessEdgeMarkID;
GLuint texPostprocessFogID; GLuint texPostprocessFogID;
GLuint rboMSGColorID; GLuint rboMSGColorID;
@ -466,7 +465,6 @@ protected:
CACHE_ALIGN u32 GPU_screen3D[2][GFX3D_FRAMEBUFFER_WIDTH * GFX3D_FRAMEBUFFER_HEIGHT * sizeof(u32)]; CACHE_ALIGN u32 GPU_screen3D[2][GFX3D_FRAMEBUFFER_WIDTH * GFX3D_FRAMEBUFFER_HEIGHT * sizeof(u32)];
bool gpuScreen3DHasNewData[2]; bool gpuScreen3DHasNewData[2];
bool didRenderEdgeMark;
size_t doubleBufferIndex; size_t doubleBufferIndex;
// OpenGL-specific methods // OpenGL-specific methods
@ -634,7 +632,7 @@ protected:
virtual Render3DError DisableVertexAttributes(); virtual Render3DError DisableVertexAttributes();
virtual Render3DError BeginRender(const GFX3D_State *renderState); virtual Render3DError BeginRender(const GFX3D_State *renderState);
virtual Render3DError RenderEdgeMarking(const u16 *colorTable); virtual Render3DError RenderEdgeMarking(const u16 *colorTable, const bool useAntialias);
virtual Render3DError RenderFog(const u8 *densityTable, const u32 color, const u32 offset, const u8 shift, const bool alphaOnly); virtual Render3DError RenderFog(const u8 *densityTable, const u32 color, const u32 offset, const u8 shift, const bool alphaOnly);
virtual Render3DError SetupPolygon(const POLY *thePoly); virtual Render3DError SetupPolygon(const POLY *thePoly);

View File

@ -171,7 +171,7 @@ static const char *GeometryFragShader_150 = {"\
\n\ \n\
outFragColor = newFragColor;\n\ outFragColor = newFragColor;\n\
outFragDepth = vec4( packVec3FromFloat(newFragDepth), float(polyEnableDepthWrite && (newFragColor.a > 0.999 || polySetNewDepthForTranslucent)));\n\ outFragDepth = vec4( packVec3FromFloat(newFragDepth), float(polyEnableDepthWrite && (newFragColor.a > 0.999 || polySetNewDepthForTranslucent)));\n\
outPolyID = vec4(float(polyID)/63.0, float(stateEnableAntialiasing), 0.0, float(newFragColor.a > 0.999));\n\ outPolyID = vec4(float(polyID)/63.0, 0.0, 0.0, float(newFragColor.a > 0.999));\n\
outFogAttributes = vec4( float(polyEnableFog), 0.0, 0.0, float(newFragColor.a > 0.999 || !polyEnableFog));\n\ outFogAttributes = vec4( float(polyEnableFog), 0.0, 0.0, float(newFragColor.a > 0.999 || !polyEnableFog));\n\
gl_FragDepth = newFragDepth;\n\ gl_FragDepth = newFragDepth;\n\
} \n\ } \n\
@ -206,7 +206,6 @@ static const char *EdgeMarkFragShader_150 = {"\
\n\ \n\
in vec2 texCoord[5];\n\ in vec2 texCoord[5];\n\
\n\ \n\
uniform sampler2D texInFragColor;\n\
uniform sampler2D texInFragDepth;\n\ uniform sampler2D texInFragDepth;\n\
uniform sampler2D texInPolyID;\n\ uniform sampler2D texInPolyID;\n\
uniform vec4 stateEdgeColor[8];\n\ uniform vec4 stateEdgeColor[8];\n\
@ -221,9 +220,6 @@ static const char *EdgeMarkFragShader_150 = {"\
\n\ \n\
void main()\n\ void main()\n\
{\n\ {\n\
vec4 inFragColor = texture(texInFragColor, texCoord[0]);\n\
float inFragDepth = unpackFloatFromVec3(texture(texInFragDepth, texCoord[0]).rgb);\n\
\n\
vec4 inPolyIDAttributes[5];\n\ vec4 inPolyIDAttributes[5];\n\
inPolyIDAttributes[0] = texture(texInPolyID, texCoord[0]);\n\ inPolyIDAttributes[0] = texture(texInPolyID, texCoord[0]);\n\
inPolyIDAttributes[1] = texture(texInPolyID, texCoord[1]);\n\ inPolyIDAttributes[1] = texture(texInPolyID, texCoord[1]);\n\
@ -238,13 +234,6 @@ static const char *EdgeMarkFragShader_150 = {"\
polyID[3] = int((inPolyIDAttributes[3].r * 63.0) + 0.5);\n\ polyID[3] = int((inPolyIDAttributes[3].r * 63.0) + 0.5);\n\
polyID[4] = int((inPolyIDAttributes[4].r * 63.0) + 0.5);\n\ polyID[4] = int((inPolyIDAttributes[4].r * 63.0) + 0.5);\n\
\n\ \n\
bool antialias[5];\n\
antialias[0] = bool(inPolyIDAttributes[0].g);\n\
antialias[1] = bool(inPolyIDAttributes[1].g);\n\
antialias[2] = bool(inPolyIDAttributes[2].g);\n\
antialias[3] = bool(inPolyIDAttributes[3].g);\n\
antialias[4] = bool(inPolyIDAttributes[4].g);\n\
\n\
float depth[5];\n\ float depth[5];\n\
depth[0] = unpackFloatFromVec3(texture(texInFragDepth, texCoord[0]).rgb);\n\ depth[0] = unpackFloatFromVec3(texture(texInFragDepth, texCoord[0]).rgb);\n\
depth[1] = unpackFloatFromVec3(texture(texInFragDepth, texCoord[1]).rgb);\n\ depth[1] = unpackFloatFromVec3(texture(texInFragDepth, texCoord[1]).rgb);\n\
@ -252,22 +241,18 @@ static const char *EdgeMarkFragShader_150 = {"\
depth[3] = unpackFloatFromVec3(texture(texInFragDepth, texCoord[3]).rgb);\n\ depth[3] = unpackFloatFromVec3(texture(texInFragDepth, texCoord[3]).rgb);\n\
depth[4] = unpackFloatFromVec3(texture(texInFragDepth, texCoord[4]).rgb);\n\ depth[4] = unpackFloatFromVec3(texture(texInFragDepth, texCoord[4]).rgb);\n\
\n\ \n\
vec4 edgeColor = stateEdgeColor[polyID[0]/8];\n\ vec4 edgeColor = vec4(0.0, 0.0, 0.0, 0.0);\n\
bool doEdgeMark = false;\n\
bool doAntialias = false;\n\
\n\ \n\
for (int i = 1; i < 5; i++)\n\ for (int i = 1; i < 5; i++)\n\
{\n\ {\n\
if (polyID[0] != polyID[i] && depth[0] >= depth[i])\n\ if (polyID[0] != polyID[i] && depth[0] >= depth[i])\n\
{\n\ {\n\
doEdgeMark = true;\n\
edgeColor = stateEdgeColor[polyID[i]/8];\n\ edgeColor = stateEdgeColor[polyID[i]/8];\n\
doAntialias = antialias[i];\n\
break;\n\ break;\n\
}\n\ }\n\
}\n\ }\n\
\n\ \n\
outFragColor = mix(inFragColor, edgeColor, (doEdgeMark) ? ((doAntialias) ? (16.0/31.0) : 1.0) : 0.0);\n\ outFragColor = edgeColor;\n\
}\n\ }\n\
"}; "};
@ -478,7 +463,6 @@ Render3DError OpenGLRenderer_3_2::CreateFBOs()
glGenTextures(1, &OGLRef.texGPolyID); glGenTextures(1, &OGLRef.texGPolyID);
glGenTextures(1, &OGLRef.texGFogAttrID); glGenTextures(1, &OGLRef.texGFogAttrID);
glGenTextures(1, &OGLRef.texGDepthStencilID); glGenTextures(1, &OGLRef.texGDepthStencilID);
glGenTextures(1, &OGLRef.texPostprocessEdgeMarkID);
glGenTextures(1, &OGLRef.texPostprocessFogID); glGenTextures(1, &OGLRef.texPostprocessFogID);
glBindTexture(GL_TEXTURE_2D, OGLRef.texGColorID); glBindTexture(GL_TEXTURE_2D, OGLRef.texGColorID);
@ -517,13 +501,6 @@ Render3DError OpenGLRenderer_3_2::CreateFBOs()
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, GFX3D_FRAMEBUFFER_WIDTH, GFX3D_FRAMEBUFFER_HEIGHT, 0, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, NULL); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, GFX3D_FRAMEBUFFER_WIDTH, GFX3D_FRAMEBUFFER_HEIGHT, 0, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, NULL);
glBindTexture(GL_TEXTURE_2D, OGLRef.texPostprocessEdgeMarkID);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, GFX3D_FRAMEBUFFER_WIDTH, GFX3D_FRAMEBUFFER_HEIGHT, 0, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, NULL);
glBindTexture(GL_TEXTURE_2D, OGLRef.texPostprocessFogID); glBindTexture(GL_TEXTURE_2D, OGLRef.texPostprocessFogID);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
@ -556,7 +533,6 @@ Render3DError OpenGLRenderer_3_2::CreateFBOs()
glDeleteTextures(1, &OGLRef.texGPolyID); glDeleteTextures(1, &OGLRef.texGPolyID);
glDeleteTextures(1, &OGLRef.texGFogAttrID); glDeleteTextures(1, &OGLRef.texGFogAttrID);
glDeleteTextures(1, &OGLRef.texGDepthStencilID); glDeleteTextures(1, &OGLRef.texGDepthStencilID);
glDeleteTextures(1, &OGLRef.texPostprocessEdgeMarkID);
glDeleteTextures(1, &OGLRef.texPostprocessFogID); glDeleteTextures(1, &OGLRef.texPostprocessFogID);
OGLRef.fboRenderID = 0; OGLRef.fboRenderID = 0;
@ -569,8 +545,7 @@ Render3DError OpenGLRenderer_3_2::CreateFBOs()
glReadBuffer(GL_COLOR_ATTACHMENT0); glReadBuffer(GL_COLOR_ATTACHMENT0);
glBindFramebuffer(GL_FRAMEBUFFER, OGLRef.fboPostprocessID); glBindFramebuffer(GL_FRAMEBUFFER, OGLRef.fboPostprocessID);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, OGLRef.texPostprocessEdgeMarkID, 0); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, OGLRef.texPostprocessFogID, 0);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, OGLRef.texPostprocessFogID, 0);
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
{ {
@ -584,7 +559,6 @@ Render3DError OpenGLRenderer_3_2::CreateFBOs()
glDeleteTextures(1, &OGLRef.texGPolyID); glDeleteTextures(1, &OGLRef.texGPolyID);
glDeleteTextures(1, &OGLRef.texGFogAttrID); glDeleteTextures(1, &OGLRef.texGFogAttrID);
glDeleteTextures(1, &OGLRef.texGDepthStencilID); glDeleteTextures(1, &OGLRef.texGDepthStencilID);
glDeleteTextures(1, &OGLRef.texPostprocessEdgeMarkID);
glDeleteTextures(1, &OGLRef.texPostprocessFogID); glDeleteTextures(1, &OGLRef.texPostprocessFogID);
OGLRef.fboRenderID = 0; OGLRef.fboRenderID = 0;
@ -620,7 +594,6 @@ void OpenGLRenderer_3_2::DestroyFBOs()
glDeleteTextures(1, &OGLRef.texGPolyID); glDeleteTextures(1, &OGLRef.texGPolyID);
glDeleteTextures(1, &OGLRef.texGFogAttrID); glDeleteTextures(1, &OGLRef.texGFogAttrID);
glDeleteTextures(1, &OGLRef.texGDepthStencilID); glDeleteTextures(1, &OGLRef.texGDepthStencilID);
glDeleteTextures(1, &OGLRef.texPostprocessEdgeMarkID);
glDeleteTextures(1, &OGLRef.texPostprocessFogID); glDeleteTextures(1, &OGLRef.texPostprocessFogID);
OGLRef.fboRenderID = 0; OGLRef.fboRenderID = 0;
@ -879,48 +852,47 @@ Render3DError OpenGLRenderer_3_2::DownsampleFBO()
return OGLERROR_NOERR; return OGLERROR_NOERR;
} }
Render3DError OpenGLRenderer_3_2::RenderEdgeMarking(const u16 *colorTable) Render3DError OpenGLRenderer_3_2::RenderEdgeMarking(const u16 *colorTable, const bool useAntialias)
{ {
OGLRenderRef &OGLRef = *this->ref; OGLRenderRef &OGLRef = *this->ref;
const GLfloat alpha = (useAntialias) ? (16.0f/31.0f) : 1.0f;
const GLfloat oglColor[4*8] = {divide5bitBy31_LUT[(colorTable[0] ) & 0x001F], const GLfloat oglColor[4*8] = {divide5bitBy31_LUT[(colorTable[0] ) & 0x001F],
divide5bitBy31_LUT[(colorTable[0] >> 5) & 0x001F], divide5bitBy31_LUT[(colorTable[0] >> 5) & 0x001F],
divide5bitBy31_LUT[(colorTable[0] >> 10) & 0x001F], divide5bitBy31_LUT[(colorTable[0] >> 10) & 0x001F],
1.0f, alpha,
divide5bitBy31_LUT[(colorTable[1] ) & 0x001F], divide5bitBy31_LUT[(colorTable[1] ) & 0x001F],
divide5bitBy31_LUT[(colorTable[1] >> 5) & 0x001F], divide5bitBy31_LUT[(colorTable[1] >> 5) & 0x001F],
divide5bitBy31_LUT[(colorTable[1] >> 10) & 0x001F], divide5bitBy31_LUT[(colorTable[1] >> 10) & 0x001F],
1.0f, alpha,
divide5bitBy31_LUT[(colorTable[2] ) & 0x001F], divide5bitBy31_LUT[(colorTable[2] ) & 0x001F],
divide5bitBy31_LUT[(colorTable[2] >> 5) & 0x001F], divide5bitBy31_LUT[(colorTable[2] >> 5) & 0x001F],
divide5bitBy31_LUT[(colorTable[2] >> 10) & 0x001F], divide5bitBy31_LUT[(colorTable[2] >> 10) & 0x001F],
1.0f, alpha,
divide5bitBy31_LUT[(colorTable[3] ) & 0x001F], divide5bitBy31_LUT[(colorTable[3] ) & 0x001F],
divide5bitBy31_LUT[(colorTable[3] >> 5) & 0x001F], divide5bitBy31_LUT[(colorTable[3] >> 5) & 0x001F],
divide5bitBy31_LUT[(colorTable[3] >> 10) & 0x001F], divide5bitBy31_LUT[(colorTable[3] >> 10) & 0x001F],
1.0f, alpha,
divide5bitBy31_LUT[(colorTable[4] ) & 0x001F], divide5bitBy31_LUT[(colorTable[4] ) & 0x001F],
divide5bitBy31_LUT[(colorTable[4] >> 5) & 0x001F], divide5bitBy31_LUT[(colorTable[4] >> 5) & 0x001F],
divide5bitBy31_LUT[(colorTable[4] >> 10) & 0x001F], divide5bitBy31_LUT[(colorTable[4] >> 10) & 0x001F],
1.0f, alpha,
divide5bitBy31_LUT[(colorTable[5] ) & 0x001F], divide5bitBy31_LUT[(colorTable[5] ) & 0x001F],
divide5bitBy31_LUT[(colorTable[5] >> 5) & 0x001F], divide5bitBy31_LUT[(colorTable[5] >> 5) & 0x001F],
divide5bitBy31_LUT[(colorTable[5] >> 10) & 0x001F], divide5bitBy31_LUT[(colorTable[5] >> 10) & 0x001F],
1.0f, alpha,
divide5bitBy31_LUT[(colorTable[6] ) & 0x001F], divide5bitBy31_LUT[(colorTable[6] ) & 0x001F],
divide5bitBy31_LUT[(colorTable[6] >> 5) & 0x001F], divide5bitBy31_LUT[(colorTable[6] >> 5) & 0x001F],
divide5bitBy31_LUT[(colorTable[6] >> 10) & 0x001F], divide5bitBy31_LUT[(colorTable[6] >> 10) & 0x001F],
1.0f, alpha,
divide5bitBy31_LUT[(colorTable[7] ) & 0x001F], divide5bitBy31_LUT[(colorTable[7] ) & 0x001F],
divide5bitBy31_LUT[(colorTable[7] >> 5) & 0x001F], divide5bitBy31_LUT[(colorTable[7] >> 5) & 0x001F],
divide5bitBy31_LUT[(colorTable[7] >> 10) & 0x001F], divide5bitBy31_LUT[(colorTable[7] >> 10) & 0x001F],
1.0f}; alpha};
glBindFramebuffer(GL_FRAMEBUFFER, OGLRef.fboPostprocessID); glBindFramebuffer(GL_FRAMEBUFFER, OGLRef.fboRenderID);
glDrawBuffer(GL_COLOR_ATTACHMENT0); glDrawBuffer(GL_COLOR_ATTACHMENT0);
glReadBuffer(GL_COLOR_ATTACHMENT0);
glUseProgram(OGLRef.programEdgeMarkID); glUseProgram(OGLRef.programEdgeMarkID);
glUniform1i(OGLRef.uniformTexGColor_EdgeMark, OGLTextureUnitID_GColor);
glUniform1i(OGLRef.uniformTexGDepth_EdgeMark, OGLTextureUnitID_GDepth); glUniform1i(OGLRef.uniformTexGDepth_EdgeMark, OGLTextureUnitID_GDepth);
glUniform1i(OGLRef.uniformTexGPolyID_EdgeMark, OGLTextureUnitID_GPolyID); glUniform1i(OGLRef.uniformTexGPolyID_EdgeMark, OGLTextureUnitID_GPolyID);
glUniform2f(OGLRef.uniformFramebufferSize, GFX3D_FRAMEBUFFER_WIDTH, GFX3D_FRAMEBUFFER_HEIGHT); glUniform2f(OGLRef.uniformFramebufferSize, GFX3D_FRAMEBUFFER_WIDTH, GFX3D_FRAMEBUFFER_HEIGHT);
@ -929,15 +901,13 @@ Render3DError OpenGLRenderer_3_2::RenderEdgeMarking(const u16 *colorTable)
glViewport(0, 0, GFX3D_FRAMEBUFFER_WIDTH, GFX3D_FRAMEBUFFER_HEIGHT); glViewport(0, 0, GFX3D_FRAMEBUFFER_WIDTH, GFX3D_FRAMEBUFFER_HEIGHT);
glDisable(GL_DEPTH_TEST); glDisable(GL_DEPTH_TEST);
glDisable(GL_STENCIL_TEST); glDisable(GL_STENCIL_TEST);
glDisable(GL_BLEND); glEnable(GL_BLEND);
glDisable(GL_CULL_FACE); glDisable(GL_CULL_FACE);
glBindBuffer(GL_ARRAY_BUFFER, OGLRef.vboPostprocessVtxID); glBindBuffer(GL_ARRAY_BUFFER, OGLRef.vboPostprocessVtxID);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, OGLRef.iboPostprocessIndexID); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, OGLRef.iboPostprocessIndexID);
glBindVertexArray(OGLRef.vaoPostprocessStatesID); glBindVertexArray(OGLRef.vaoPostprocessStatesID);
glActiveTexture(GL_TEXTURE0 + OGLTextureUnitID_GColor);
glBindTexture(GL_TEXTURE_2D, OGLRef.texGColorID);
glActiveTexture(GL_TEXTURE0 + OGLTextureUnitID_GDepth); glActiveTexture(GL_TEXTURE0 + OGLTextureUnitID_GDepth);
glBindTexture(GL_TEXTURE_2D, OGLRef.texGDepthID); glBindTexture(GL_TEXTURE_2D, OGLRef.texGDepthID);
glActiveTexture(GL_TEXTURE0 + OGLTextureUnitID_GPolyID); glActiveTexture(GL_TEXTURE0 + OGLTextureUnitID_GPolyID);
@ -947,8 +917,6 @@ Render3DError OpenGLRenderer_3_2::RenderEdgeMarking(const u16 *colorTable)
glBindVertexArray(0); glBindVertexArray(0);
this->didRenderEdgeMark = true;
return RENDER3DERROR_NOERR; return RENDER3DERROR_NOERR;
} }
@ -971,8 +939,6 @@ Render3DError OpenGLRenderer_3_2::RenderFog(const u8 *densityTable, const u32 co
const GLfloat oglFogStep = (GLfloat)(0x0400 >> shift) / 32767.0f; const GLfloat oglFogStep = (GLfloat)(0x0400 >> shift) / 32767.0f;
glBindFramebuffer(GL_FRAMEBUFFER, OGLRef.fboPostprocessID); glBindFramebuffer(GL_FRAMEBUFFER, OGLRef.fboPostprocessID);
glDrawBuffer(GL_COLOR_ATTACHMENT1);
glReadBuffer(GL_COLOR_ATTACHMENT1);
glUseProgram(OGLRef.programFogID); glUseProgram(OGLRef.programFogID);
glUniform1i(OGLRef.uniformTexGColor_Fog, OGLTextureUnitID_GColor); glUniform1i(OGLRef.uniformTexGColor_Fog, OGLTextureUnitID_GColor);
glUniform1i(OGLRef.uniformTexGDepth_Fog, OGLTextureUnitID_GDepth); glUniform1i(OGLRef.uniformTexGDepth_Fog, OGLTextureUnitID_GDepth);
@ -994,7 +960,7 @@ Render3DError OpenGLRenderer_3_2::RenderFog(const u8 *densityTable, const u32 co
glBindVertexArray(OGLRef.vaoPostprocessStatesID); glBindVertexArray(OGLRef.vaoPostprocessStatesID);
glActiveTexture(GL_TEXTURE0 + OGLTextureUnitID_GColor); glActiveTexture(GL_TEXTURE0 + OGLTextureUnitID_GColor);
glBindTexture(GL_TEXTURE_2D, (this->didRenderEdgeMark) ? OGLRef.texPostprocessEdgeMarkID : OGLRef.texGColorID); glBindTexture(GL_TEXTURE_2D, OGLRef.texGColorID);
glActiveTexture(GL_TEXTURE0 + OGLTextureUnitID_GDepth); glActiveTexture(GL_TEXTURE0 + OGLTextureUnitID_GDepth);
glBindTexture(GL_TEXTURE_2D, OGLRef.texGDepthID); glBindTexture(GL_TEXTURE_2D, OGLRef.texGDepthID);
glActiveTexture(GL_TEXTURE0 + OGLTextureUnitID_FogAttr); glActiveTexture(GL_TEXTURE0 + OGLTextureUnitID_FogAttr);

View File

@ -78,7 +78,7 @@ protected:
virtual Render3DError DisableVertexAttributes(); virtual Render3DError DisableVertexAttributes();
virtual Render3DError SelectRenderingFramebuffer(); virtual Render3DError SelectRenderingFramebuffer();
virtual Render3DError DownsampleFBO(); virtual Render3DError DownsampleFBO();
virtual Render3DError RenderEdgeMarking(const u16 *colorTable); virtual Render3DError RenderEdgeMarking(const u16 *colorTable, const bool useAntialias);
virtual Render3DError RenderFog(const u8 *densityTable, const u32 color, const u32 offset, const u8 shift, const bool alphaOnly); virtual Render3DError RenderFog(const u8 *densityTable, const u32 color, const u32 offset, const u8 shift, const bool alphaOnly);
virtual Render3DError ClearUsingImage(const u16 *__restrict colorBuffer, const u32 *__restrict depthBuffer, const bool *__restrict fogBuffer, const u8 *__restrict polyIDBuffer); virtual Render3DError ClearUsingImage(const u16 *__restrict colorBuffer, const u32 *__restrict depthBuffer, const bool *__restrict fogBuffer, const u8 *__restrict polyIDBuffer);

View File

@ -1434,9 +1434,6 @@ Render3DError SoftRasterizerRenderer::BeginRender(const GFX3D_State *renderState
} }
} }
this->_framebufferWidth = GFX3D_FRAMEBUFFER_WIDTH;
this->_framebufferHeight = GFX3D_FRAMEBUFFER_HEIGHT;
return RENDER3DERROR_NOERR; return RENDER3DERROR_NOERR;
} }
@ -1468,7 +1465,7 @@ Render3DError SoftRasterizerRenderer::RenderGeometry(const GFX3D_State *renderSt
return RENDER3DERROR_NOERR; return RENDER3DERROR_NOERR;
} }
Render3DError SoftRasterizerRenderer::RenderEdgeMarking(const u16 *colorTable) Render3DError SoftRasterizerRenderer::RenderEdgeMarking(const u16 *colorTable, const bool useAntialias)
{ {
// this looks ok although it's still pretty much a hack, // this looks ok although it's still pretty much a hack,
// it needs to be redone with low-level accuracy at some point, // it needs to be redone with low-level accuracy at some point,
@ -1485,7 +1482,7 @@ Render3DError SoftRasterizerRenderer::RenderEdgeMarking(const u16 *colorTable)
for (size_t i = 0; i < 8; i++) for (size_t i = 0; i < 8; i++)
{ {
u16 col = colorTable[i]; u16 col = colorTable[i];
edgeMarkColors[i].color = RGB15TO5555(col,gfx3d.state.enableAntialiasing ? 0x0F : 0x1F); edgeMarkColors[i].color = RGB15TO5555(col, (useAntialias) ? 0x0F : 0x1F);
edgeMarkColors[i].r = GFX3D_5TO6(edgeMarkColors[i].r); edgeMarkColors[i].r = GFX3D_5TO6(edgeMarkColors[i].r);
edgeMarkColors[i].g = GFX3D_5TO6(edgeMarkColors[i].g); edgeMarkColors[i].g = GFX3D_5TO6(edgeMarkColors[i].g);
edgeMarkColors[i].b = GFX3D_5TO6(edgeMarkColors[i].b); edgeMarkColors[i].b = GFX3D_5TO6(edgeMarkColors[i].b);
@ -1730,14 +1727,6 @@ Render3DError SoftRasterizerRenderer::Render(const GFX3D_State *renderState, con
{ {
Render3DError error = RENDER3DERROR_NOERR; Render3DError error = RENDER3DERROR_NOERR;
if (this->_renderGeometryNeedsFinish)
{
for (size_t i = 0; i < rasterizerCores; i++)
{
rasterizerUnitTask[i].finish();
}
}
error = this->BeginRender(renderState); error = this->BeginRender(renderState);
if (error != RENDER3DERROR_NOERR) if (error != RENDER3DERROR_NOERR)
{ {
@ -1751,6 +1740,7 @@ Render3DError SoftRasterizerRenderer::Render(const GFX3D_State *renderState, con
if (rasterizerCores > 1) if (rasterizerCores > 1)
{ {
this->_enableAntialias = renderState->enableAntialiasing;
this->_enableEdgeMark = renderState->enableEdgeMarking; this->_enableEdgeMark = renderState->enableEdgeMarking;
this->_enableFog = renderState->enableFog; this->_enableFog = renderState->enableFog;
this->_enableFogAlphaOnly = renderState->enableFogAlphaOnly; this->_enableFogAlphaOnly = renderState->enableFogAlphaOnly;
@ -1762,18 +1752,19 @@ Render3DError SoftRasterizerRenderer::Render(const GFX3D_State *renderState, con
} }
else else
{ {
if (this->_enableEdgeMark) this->_renderGeometryNeedsFinish = false;
if (renderState->enableEdgeMarking)
{ {
this->RenderEdgeMarking((const u16 *)(MMU.MMU_MEM[ARMCPU_ARM9][0x40]+0x0330)); this->RenderEdgeMarking((const u16 *)(MMU.MMU_MEM[ARMCPU_ARM9][0x40]+0x0330), renderState->enableAntialiasing);
} }
if (this->_enableFog) if (renderState->enableFog)
{ {
this->RenderFog(MMU.MMU_MEM[ARMCPU_ARM9][0x40]+0x0360, this->_fogColor, this->_fogOffset, this->_fogShift, this->_enableFogAlphaOnly); this->RenderFog(MMU.MMU_MEM[ARMCPU_ARM9][0x40]+0x0360, renderState->fogColor, renderState->fogOffset, renderState->fogShift, renderState->enableFogAlphaOnly);
} }
memcpy(gfx3d_convertedScreen, this->screenColor, this->_framebufferWidth * this->_framebufferHeight * sizeof(FragmentColor)); memcpy(gfx3d_convertedScreen, this->screenColor, this->_framebufferWidth * this->_framebufferHeight * sizeof(FragmentColor));
this->_renderGeometryNeedsFinish = false;
} }
return error; return error;
@ -1795,7 +1786,7 @@ Render3DError SoftRasterizerRenderer::RenderFinish()
if (this->_enableEdgeMark) if (this->_enableEdgeMark)
{ {
this->RenderEdgeMarking((const u16 *)(MMU.MMU_MEM[ARMCPU_ARM9][0x40]+0x0330)); this->RenderEdgeMarking((const u16 *)(MMU.MMU_MEM[ARMCPU_ARM9][0x40]+0x0330), this->_enableAntialias);
} }
if (this->_enableFog) if (this->_enableFog)

View File

@ -56,6 +56,7 @@ class SoftRasterizerRenderer : public Render3D
protected: protected:
GFX3D_Clipper clipper; GFX3D_Clipper clipper;
u8 fogTable[32768]; u8 fogTable[32768];
bool _enableAntialias;
bool _enableEdgeMark; bool _enableEdgeMark;
bool _enableFog; bool _enableFog;
bool _enableFogAlphaOnly; bool _enableFogAlphaOnly;
@ -76,7 +77,7 @@ protected:
// Base rendering methods // Base rendering methods
virtual Render3DError BeginRender(const GFX3D_State *renderState); virtual Render3DError BeginRender(const GFX3D_State *renderState);
virtual Render3DError RenderGeometry(const GFX3D_State *renderState, const VERTLIST *vertList, const POLYLIST *polyList, const INDEXLIST *indexList); virtual Render3DError RenderGeometry(const GFX3D_State *renderState, const VERTLIST *vertList, const POLYLIST *polyList, const INDEXLIST *indexList);
virtual Render3DError RenderEdgeMarking(const u16 *colorTable); virtual Render3DError RenderEdgeMarking(const u16 *colorTable, const bool useAntialias);
virtual Render3DError RenderFog(const u8 *densityTable, const u32 color, const u32 offset, const u8 shift, const bool alphaOnly); virtual Render3DError RenderFog(const u8 *densityTable, const u32 color, const u32 offset, const u8 shift, const bool alphaOnly);
virtual Render3DError UpdateToonTable(const u16 *toonTableBuffer); virtual Render3DError UpdateToonTable(const u16 *toonTableBuffer);

View File

@ -126,7 +126,7 @@ Render3DError Render3D::RenderGeometry(const GFX3D_State *renderState, const VER
return RENDER3DERROR_NOERR; return RENDER3DERROR_NOERR;
} }
Render3DError Render3D::RenderEdgeMarking(const u16 *colorTable) Render3DError Render3D::RenderEdgeMarking(const u16 *colorTable, const bool useAntialias)
{ {
return RENDER3DERROR_NOERR; return RENDER3DERROR_NOERR;
} }
@ -271,7 +271,7 @@ Render3DError Render3D::Render(const GFX3D_State *renderState, const VERTLIST *v
if (renderState->enableEdgeMarking) if (renderState->enableEdgeMarking)
{ {
this->RenderEdgeMarking((const u16 *)(MMU.MMU_MEM[ARMCPU_ARM9][0x40]+0x0330)); this->RenderEdgeMarking((const u16 *)(MMU.MMU_MEM[ARMCPU_ARM9][0x40]+0x0330), renderState->enableAntialiasing);
} }
if (renderState->enableFog) if (renderState->enableFog)

View File

@ -91,7 +91,7 @@ protected:
virtual Render3DError BeginRender(const GFX3D_State *renderState); virtual Render3DError BeginRender(const GFX3D_State *renderState);
virtual Render3DError RenderGeometry(const GFX3D_State *renderState, const VERTLIST *vertList, const POLYLIST *polyList, const INDEXLIST *indexList); virtual Render3DError RenderGeometry(const GFX3D_State *renderState, const VERTLIST *vertList, const POLYLIST *polyList, const INDEXLIST *indexList);
virtual Render3DError RenderEdgeMarking(const u16 *colorTable); virtual Render3DError RenderEdgeMarking(const u16 *colorTable, const bool useAntialias);
virtual Render3DError RenderFog(const u8 *densityTable, const u32 color, const u32 offset, const u8 shift, const bool alphaOnly); virtual Render3DError RenderFog(const u8 *densityTable, const u32 color, const u32 offset, const u8 shift, const bool alphaOnly);
virtual Render3DError EndRender(const u64 frameCount); virtual Render3DError EndRender(const u64 frameCount);