OpenGL Renderer: Remove the working depth buffers, and read the default depth/stencil buffer directly.

This commit is contained in:
rogerman 2017-07-31 20:37:20 -07:00
parent 7a018eb9c6
commit fd5d882fe1
3 changed files with 82 additions and 250 deletions

View File

@ -78,7 +78,7 @@ const GLfloat PostprocessVtxBuffer[16] = {-1.0f, -1.0f, 1.0f, -1.0f, 1.0f, 1.
0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f};
const GLubyte PostprocessElementBuffer[6] = {0, 1, 2, 2, 3, 0};
const GLenum RenderDrawList[4] = {GL_COLOR_ATTACHMENT0_EXT, GL_COLOR_ATTACHMENT1_EXT, GL_COLOR_ATTACHMENT2_EXT, GL_COLOR_ATTACHMENT3_EXT};
const GLenum RenderDrawList[3] = {GL_COLOR_ATTACHMENT0_EXT, GL_COLOR_ATTACHMENT1_EXT, GL_COLOR_ATTACHMENT2_EXT};
bool BEGINGL()
{
@ -318,19 +318,11 @@ static const char *fragmentShader_100 = {"\
\n\
uniform bool polyDrawShadow;\n\
\n\
vec3 packVec3FromFloat(const float value)\n\
{\n\
float expandedValue = value * 16777215.0;\n\
vec3 packedValue = vec3( fract(expandedValue/256.0), fract(((expandedValue/256.0) - fract(expandedValue/256.0)) / 256.0), fract(((expandedValue/65536.0) - fract(expandedValue/65536.0)) / 256.0) );\n\
return packedValue;\n\
}\n\
\n\
void main()\n\
{\n\
vec4 newFragColor = vec4(0.0, 0.0, 0.0, 0.0);\n\
vec4 newPolyID = vec4(0.0, 0.0, 0.0, 0.0);\n\
vec4 newFogAttributes = vec4(0.0, 0.0, 0.0, 0.0);\n\
vec4 newFragDepth = vec4(0.0, 0.0, 0.0, 0.0);\n\
\n\
float vertW = (vtxPosition.w == 0.0) ? 0.00000001 : vtxPosition.w;\n\
// hack: when using z-depth, drop some LSBs so that the overworld map in Dragon Quest IV shows up correctly\n\
@ -385,19 +377,13 @@ static const char *fragmentShader_100 = {"\
discard;\n\
}\n\
\n\
if ( (newFragColor.a > 0.999) || polySetNewDepthForTranslucent )\n\
{\n\
newFragDepth = vec4(packVec3FromFloat(newFragDepthValue), 1.0);\n\
}\n\
\n\
newPolyID = vec4( float(polyID)/63.0, float(polyIsWireframe), 0.0, float(newFragColor.a > 0.999) );\n\
newFogAttributes = vec4( float(polyEnableFog), 0.0, 0.0, float((newFragColor.a > 0.999) ? 1.0 : 0.5) );\n\
}\n\
\n\
gl_FragData[0] = newFragColor;\n\
gl_FragData[1] = newFragDepth;\n\
gl_FragData[2] = newPolyID;\n\
gl_FragData[3] = newFogAttributes;\n\
gl_FragData[1] = newPolyID;\n\
gl_FragData[2] = newFogAttributes;\n\
gl_FragDepth = newFragDepthValue;\n\
}\n\
"};
@ -458,12 +444,6 @@ static const char *EdgeMarkFragShader_100 = {"\
uniform vec4 stateEdgeColor[8];\n\
uniform bool isAlphaWriteDisabled;\n\
\n\
float unpackFloatFromVec3(const vec3 value)\n\
{\n\
const vec3 unpackRatio = vec3(256.0, 65536.0, 16777216.0);\n\
return (dot(value, unpackRatio) / 16777215.0);\n\
}\n\
\n\
void main()\n\
{\n\
bool isZeroAlphaPixel = bool(texture2D(texZeroAlphaPixelMask, texCoord[0]).r);\n\
@ -479,11 +459,11 @@ static const char *EdgeMarkFragShader_100 = {"\
isWireframe[0] = bool(polyIDInfo[0].g);\n\
\n\
float depth[5];\n\
depth[0] = unpackFloatFromVec3(texture2D(texInFragDepth, texCoord[0]).rgb);\n\
depth[1] = unpackFloatFromVec3(texture2D(texInFragDepth, texCoord[1]).rgb);\n\
depth[2] = unpackFloatFromVec3(texture2D(texInFragDepth, texCoord[2]).rgb);\n\
depth[3] = unpackFloatFromVec3(texture2D(texInFragDepth, texCoord[3]).rgb);\n\
depth[4] = unpackFloatFromVec3(texture2D(texInFragDepth, texCoord[4]).rgb);\n\
depth[0] = texture2D(texInFragDepth, texCoord[0]).r;\n\
depth[1] = texture2D(texInFragDepth, texCoord[1]).r;\n\
depth[2] = texture2D(texInFragDepth, texCoord[2]).r;\n\
depth[3] = texture2D(texInFragDepth, texCoord[3]).r;\n\
depth[4] = texture2D(texInFragDepth, texCoord[4]).r;\n\
\n\
vec4 newEdgeColor = vec4(0.0, 0.0, 0.0, 0.0);\n\
\n\
@ -545,12 +525,6 @@ static const char *FogFragShader_100 = {"\
uniform float stateFogOffset;\n\
uniform float stateFogStep;\n\
\n\
float unpackFloatFromVec3(const vec3 value)\n\
{\n\
const vec3 unpackRatio = vec3(256.0, 65536.0, 16777216.0);\n\
return (dot(value, unpackRatio) / 16777215.0);\n\
}\n\
\n\
void main()\n\
{\n\
vec4 inFragColor = texture2D(texInFragColor, texCoord);\n\
@ -560,7 +534,7 @@ static const char *FogFragShader_100 = {"\
\n\
if (polyEnableFog)\n\
{\n\
float inFragDepth = unpackFloatFromVec3(texture2D(texInFragDepth, texCoord).rgb);\n\
float inFragDepth = texture2D(texInFragDepth, texCoord).r;\n\
float fogMixWeight = 0.0;\n\
\n\
if (inFragDepth <= min(stateFogOffset + stateFogStep, 1.0))\n\
@ -2054,19 +2028,17 @@ Render3DError OpenGLRenderer_1_2::CreateFBOs()
// Set up FBO render targets
glGenTextures(1, &OGLRef.texCIColorID);
glGenTextures(1, &OGLRef.texCIDepthID);
glGenTextures(1, &OGLRef.texCIFogAttrID);
glGenTextures(1, &OGLRef.texCIPolyID);
glGenTextures(1, &OGLRef.texCIDepthStencilID);
glGenTextures(1, &OGLRef.texGColorID);
glGenTextures(1, &OGLRef.texGDepthID);
glGenTextures(1, &OGLRef.texGFogAttrID);
glGenTextures(1, &OGLRef.texGPolyID);
glGenTextures(1, &OGLRef.texGDepthStencilID);
glGenTextures(1, &OGLRef.texZeroAlphaPixelMaskID);
glActiveTextureARB(GL_TEXTURE0_ARB + OGLTextureUnitID_GColor);
glActiveTextureARB(GL_TEXTURE0_ARB + OGLTextureUnitID_DepthStencil);
glBindTexture(GL_TEXTURE_2D, OGLRef.texGDepthStencilID);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
@ -2075,6 +2047,7 @@ Render3DError OpenGLRenderer_1_2::CreateFBOs()
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_NONE);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH24_STENCIL8_EXT, this->_framebufferWidth, this->_framebufferHeight, 0, GL_DEPTH_STENCIL_EXT, GL_UNSIGNED_INT_24_8_EXT, NULL);
glActiveTextureARB(GL_TEXTURE0_ARB + OGLTextureUnitID_GColor);
glBindTexture(GL_TEXTURE_2D, OGLRef.texGColorID);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
@ -2082,14 +2055,6 @@ Render3DError OpenGLRenderer_1_2::CreateFBOs()
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, this->_framebufferWidth, this->_framebufferHeight, 0, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, NULL);
glActiveTextureARB(GL_TEXTURE0_ARB + OGLTextureUnitID_GDepth);
glBindTexture(GL_TEXTURE_2D, OGLRef.texGDepthID);
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, this->_framebufferWidth, this->_framebufferHeight, 0, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, NULL);
glActiveTextureARB(GL_TEXTURE0_ARB + OGLTextureUnitID_GPolyID);
glBindTexture(GL_TEXTURE_2D, OGLRef.texGPolyID);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
@ -2131,13 +2096,6 @@ Render3DError OpenGLRenderer_1_2::CreateFBOs()
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_NONE);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH24_STENCIL8_EXT, GPU_FRAMEBUFFER_NATIVE_WIDTH, GPU_FRAMEBUFFER_NATIVE_HEIGHT, 0, GL_DEPTH_STENCIL_EXT, GL_UNSIGNED_INT_24_8_EXT, NULL);
glBindTexture(GL_TEXTURE_2D, OGLRef.texCIDepthID);
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, GPU_FRAMEBUFFER_NATIVE_WIDTH, GPU_FRAMEBUFFER_NATIVE_HEIGHT, 0, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, NULL);
glBindTexture(GL_TEXTURE_2D, OGLRef.texCIPolyID);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
@ -2161,9 +2119,8 @@ Render3DError OpenGLRenderer_1_2::CreateFBOs()
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, OGLRef.fboClearImageID);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, OGLRef.texCIColorID, 0);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT1_EXT, GL_TEXTURE_2D, OGLRef.texCIDepthID, 0);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT2_EXT, GL_TEXTURE_2D, OGLRef.texCIPolyID, 0);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT3_EXT, GL_TEXTURE_2D, OGLRef.texCIFogAttrID, 0);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT1_EXT, GL_TEXTURE_2D, OGLRef.texCIPolyID, 0);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT2_EXT, GL_TEXTURE_2D, OGLRef.texCIFogAttrID, 0);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D, OGLRef.texCIDepthStencilID, 0);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_STENCIL_ATTACHMENT_EXT, GL_TEXTURE_2D, OGLRef.texCIDepthStencilID, 0);
@ -2176,12 +2133,10 @@ Render3DError OpenGLRenderer_1_2::CreateFBOs()
glDeleteFramebuffersEXT(1, &OGLRef.fboRenderID);
glDeleteFramebuffersEXT(1, &OGLRef.fboPostprocessID);
glDeleteTextures(1, &OGLRef.texCIColorID);
glDeleteTextures(1, &OGLRef.texCIDepthID);
glDeleteTextures(1, &OGLRef.texCIFogAttrID);
glDeleteTextures(1, &OGLRef.texCIPolyID);
glDeleteTextures(1, &OGLRef.texCIDepthStencilID);
glDeleteTextures(1, &OGLRef.texGColorID);
glDeleteTextures(1, &OGLRef.texGDepthID);
glDeleteTextures(1, &OGLRef.texGPolyID);
glDeleteTextures(1, &OGLRef.texGFogAttrID);
glDeleteTextures(1, &OGLRef.texGDepthStencilID);
@ -2197,7 +2152,7 @@ Render3DError OpenGLRenderer_1_2::CreateFBOs()
if (this->isShaderSupported)
{
glDrawBuffers(4, RenderDrawList);
glDrawBuffers(3, RenderDrawList);
}
else
{
@ -2208,9 +2163,8 @@ Render3DError OpenGLRenderer_1_2::CreateFBOs()
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, OGLRef.fboRenderID);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, OGLRef.texGColorID, 0);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT1_EXT, GL_TEXTURE_2D, OGLRef.texGDepthID, 0);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT2_EXT, GL_TEXTURE_2D, OGLRef.texGPolyID, 0);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT3_EXT, GL_TEXTURE_2D, OGLRef.texGFogAttrID, 0);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT1_EXT, GL_TEXTURE_2D, OGLRef.texGPolyID, 0);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT2_EXT, GL_TEXTURE_2D, OGLRef.texGFogAttrID, 0);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D, OGLRef.texGDepthStencilID, 0);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_STENCIL_ATTACHMENT_EXT, GL_TEXTURE_2D, OGLRef.texGDepthStencilID, 0);
@ -2223,12 +2177,10 @@ Render3DError OpenGLRenderer_1_2::CreateFBOs()
glDeleteFramebuffersEXT(1, &OGLRef.fboRenderID);
glDeleteFramebuffersEXT(1, &OGLRef.fboPostprocessID);
glDeleteTextures(1, &OGLRef.texCIColorID);
glDeleteTextures(1, &OGLRef.texCIDepthID);
glDeleteTextures(1, &OGLRef.texCIFogAttrID);
glDeleteTextures(1, &OGLRef.texCIPolyID);
glDeleteTextures(1, &OGLRef.texCIDepthStencilID);
glDeleteTextures(1, &OGLRef.texGColorID);
glDeleteTextures(1, &OGLRef.texGDepthID);
glDeleteTextures(1, &OGLRef.texGPolyID);
glDeleteTextures(1, &OGLRef.texGFogAttrID);
glDeleteTextures(1, &OGLRef.texGDepthStencilID);
@ -2244,7 +2196,7 @@ Render3DError OpenGLRenderer_1_2::CreateFBOs()
if (this->isShaderSupported)
{
glDrawBuffers(4, RenderDrawList);
glDrawBuffers(3, RenderDrawList);
}
else
{
@ -2267,12 +2219,10 @@ Render3DError OpenGLRenderer_1_2::CreateFBOs()
glDeleteFramebuffersEXT(1, &OGLRef.fboRenderID);
glDeleteFramebuffersEXT(1, &OGLRef.fboPostprocessID);
glDeleteTextures(1, &OGLRef.texCIColorID);
glDeleteTextures(1, &OGLRef.texCIDepthID);
glDeleteTextures(1, &OGLRef.texCIFogAttrID);
glDeleteTextures(1, &OGLRef.texCIPolyID);
glDeleteTextures(1, &OGLRef.texCIDepthStencilID);
glDeleteTextures(1, &OGLRef.texGColorID);
glDeleteTextures(1, &OGLRef.texGDepthID);
glDeleteTextures(1, &OGLRef.texGPolyID);
glDeleteTextures(1, &OGLRef.texGFogAttrID);
glDeleteTextures(1, &OGLRef.texGDepthStencilID);
@ -2310,12 +2260,10 @@ void OpenGLRenderer_1_2::DestroyFBOs()
glDeleteFramebuffersEXT(1, &OGLRef.fboRenderID);
glDeleteFramebuffersEXT(1, &OGLRef.fboPostprocessID);
glDeleteTextures(1, &OGLRef.texCIColorID);
glDeleteTextures(1, &OGLRef.texCIDepthID);
glDeleteTextures(1, &OGLRef.texCIFogAttrID);
glDeleteTextures(1, &OGLRef.texCIPolyID);
glDeleteTextures(1, &OGLRef.texCIDepthStencilID);
glDeleteTextures(1, &OGLRef.texGColorID);
glDeleteTextures(1, &OGLRef.texGDepthID);
glDeleteTextures(1, &OGLRef.texGPolyID);
glDeleteTextures(1, &OGLRef.texGFogAttrID);
glDeleteTextures(1, &OGLRef.texGDepthStencilID);
@ -2334,7 +2282,6 @@ Render3DError OpenGLRenderer_1_2::CreateMultisampledFBO()
// Set up FBO render targets
glGenRenderbuffersEXT(1, &OGLRef.rboMSGColorID);
glGenRenderbuffersEXT(1, &OGLRef.rboMSGDepthID);
glGenRenderbuffersEXT(1, &OGLRef.rboMSGPolyID);
glGenRenderbuffersEXT(1, &OGLRef.rboMSGFogAttrID);
glGenRenderbuffersEXT(1, &OGLRef.rboMSGDepthStencilID);
@ -2347,8 +2294,6 @@ Render3DError OpenGLRenderer_1_2::CreateMultisampledFBO()
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, OGLRef.rboMSGColorID);
glRenderbufferStorageMultisampleEXT(GL_RENDERBUFFER_EXT, maxSamples, GL_RGBA, this->_framebufferWidth, this->_framebufferHeight);
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, OGLRef.rboMSGDepthID);
glRenderbufferStorageMultisampleEXT(GL_RENDERBUFFER_EXT, maxSamples, GL_RGBA, this->_framebufferWidth, this->_framebufferHeight);
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, OGLRef.rboMSGPolyID);
glRenderbufferStorageMultisampleEXT(GL_RENDERBUFFER_EXT, maxSamples, GL_RGBA, this->_framebufferWidth, this->_framebufferHeight);
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, OGLRef.rboMSGFogAttrID);
@ -2361,9 +2306,8 @@ Render3DError OpenGLRenderer_1_2::CreateMultisampledFBO()
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, OGLRef.fboMSIntermediateRenderID);
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_RENDERBUFFER_EXT, OGLRef.rboMSGColorID);
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT1_EXT, GL_RENDERBUFFER_EXT, OGLRef.rboMSGDepthID);
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT2_EXT, GL_RENDERBUFFER_EXT, OGLRef.rboMSGPolyID);
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT3_EXT, GL_RENDERBUFFER_EXT, OGLRef.rboMSGFogAttrID);
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT1_EXT, GL_RENDERBUFFER_EXT, OGLRef.rboMSGPolyID);
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT2_EXT, GL_RENDERBUFFER_EXT, OGLRef.rboMSGFogAttrID);
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, OGLRef.rboMSGDepthStencilID);
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_STENCIL_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, OGLRef.rboMSGDepthStencilID);
@ -2374,7 +2318,6 @@ Render3DError OpenGLRenderer_1_2::CreateMultisampledFBO()
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
glDeleteFramebuffersEXT(1, &OGLRef.fboMSIntermediateRenderID);
glDeleteRenderbuffersEXT(1, &OGLRef.rboMSGColorID);
glDeleteRenderbuffersEXT(1, &OGLRef.rboMSGDepthID);
glDeleteRenderbuffersEXT(1, &OGLRef.rboMSGPolyID);
glDeleteRenderbuffersEXT(1, &OGLRef.rboMSGFogAttrID);
glDeleteRenderbuffersEXT(1, &OGLRef.rboMSGDepthStencilID);
@ -2400,7 +2343,6 @@ void OpenGLRenderer_1_2::DestroyMultisampledFBO()
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
glDeleteFramebuffersEXT(1, &OGLRef.fboMSIntermediateRenderID);
glDeleteRenderbuffersEXT(1, &OGLRef.rboMSGColorID);
glDeleteRenderbuffersEXT(1, &OGLRef.rboMSGDepthID);
glDeleteRenderbuffersEXT(1, &OGLRef.rboMSGPolyID);
glDeleteRenderbuffersEXT(1, &OGLRef.rboMSGFogAttrID);
glDeleteRenderbuffersEXT(1, &OGLRef.rboMSGDepthStencilID);
@ -2923,7 +2865,7 @@ Render3DError OpenGLRenderer_1_2::InitEdgeMarkProgramShaderLocations()
const GLint uniformTexGPolyID = glGetUniformLocation(OGLRef.programEdgeMarkID, "texInPolyID");
const GLint uniformTexZeroAlphaPixelMask = glGetUniformLocation(OGLRef.programEdgeMarkID, "texZeroAlphaPixelMask");
OGLRef.uniformIsAlphaWriteDisabled = glGetUniformLocation(OGLRef.programEdgeMarkID, "isAlphaWriteDisabled");
glUniform1i(uniformTexGDepth, OGLTextureUnitID_GDepth);
glUniform1i(uniformTexGDepth, OGLTextureUnitID_DepthStencil);
glUniform1i(uniformTexGPolyID, OGLTextureUnitID_GPolyID);
glUniform1i(uniformTexZeroAlphaPixelMask, OGLTextureUnitID_ZeroAlphaPixelMask);
glUniform1i(OGLRef.uniformIsAlphaWriteDisabled, GL_FALSE);
@ -2953,7 +2895,7 @@ Render3DError OpenGLRenderer_1_2::InitFogProgramShaderLocations()
const GLint uniformTexGDepth = glGetUniformLocation(OGLRef.programFogID, "texInFragDepth");
const GLint uniformTexGFog = glGetUniformLocation(OGLRef.programFogID, "texInFogAttributes");
glUniform1i(uniformTexGColor, OGLTextureUnitID_GColor);
glUniform1i(uniformTexGDepth, OGLTextureUnitID_GDepth);
glUniform1i(uniformTexGDepth, OGLTextureUnitID_DepthStencil);
glUniform1i(uniformTexGFog, OGLTextureUnitID_FogAttr);
OGLRef.uniformStateEnableFogAlphaOnly = glGetUniformLocation(OGLRef.programFogID, "stateEnableFogAlphaOnly");
@ -3031,7 +2973,6 @@ Render3DError OpenGLRenderer_1_2::UploadClearImage(const u16 *__restrict colorBu
for (size_t i = 0; i < GPU_FRAMEBUFFER_NATIVE_WIDTH * GPU_FRAMEBUFFER_NATIVE_HEIGHT; i++)
{
OGLRef.workingCIDepthStencilBuffer[i] = (depthBuffer[i] << 8) | polyIDBuffer[i];
OGLRef.workingCIDepthBuffer[i] = depthBuffer[i] | 0xFF000000;
OGLRef.workingCIFogAttributesBuffer[i] = (fogBuffer[i]) ? 0xFF0000FF : 0xFF000000;
OGLRef.workingCIPolyIDBuffer[i] = (GLuint)polyIDBuffer[i] | 0xFF000000;
}
@ -3053,9 +2994,6 @@ Render3DError OpenGLRenderer_1_2::UploadClearImage(const u16 *__restrict colorBu
if (this->isShaderSupported)
{
glBindTexture(GL_TEXTURE_2D, OGLRef.texCIDepthID);
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, GPU_FRAMEBUFFER_NATIVE_WIDTH, GPU_FRAMEBUFFER_NATIVE_HEIGHT, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, OGLRef.workingCIDepthBuffer);
glBindTexture(GL_TEXTURE_2D, OGLRef.texCIFogAttrID);
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, GPU_FRAMEBUFFER_NATIVE_WIDTH, GPU_FRAMEBUFFER_NATIVE_HEIGHT, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, OGLRef.workingCIFogAttributesBuffer);
@ -3175,24 +3113,19 @@ Render3DError OpenGLRenderer_1_2::DownsampleFBO()
glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT);
glBlitFramebufferEXT(0, 0, this->_framebufferWidth, this->_framebufferHeight, 0, 0, this->_framebufferWidth, this->_framebufferHeight, GL_COLOR_BUFFER_BIT, GL_NEAREST);
// Blit the working depth buffer
// Blit the polygon ID buffer
glReadBuffer(GL_COLOR_ATTACHMENT1_EXT);
glDrawBuffer(GL_COLOR_ATTACHMENT1_EXT);
glBlitFramebufferEXT(0, 0, this->_framebufferWidth, this->_framebufferHeight, 0, 0, this->_framebufferWidth, this->_framebufferHeight, GL_COLOR_BUFFER_BIT, GL_NEAREST);
// Blit the polygon ID buffer
// Blit the fog buffer
glReadBuffer(GL_COLOR_ATTACHMENT2_EXT);
glDrawBuffer(GL_COLOR_ATTACHMENT2_EXT);
glBlitFramebufferEXT(0, 0, this->_framebufferWidth, this->_framebufferHeight, 0, 0, this->_framebufferWidth, this->_framebufferHeight, GL_COLOR_BUFFER_BIT, GL_NEAREST);
// Blit the fog buffer
glReadBuffer(GL_COLOR_ATTACHMENT3_EXT);
glDrawBuffer(GL_COLOR_ATTACHMENT3_EXT);
glBlitFramebufferEXT(0, 0, this->_framebufferWidth, this->_framebufferHeight, 0, 0, this->_framebufferWidth, this->_framebufferHeight, GL_COLOR_BUFFER_BIT, GL_NEAREST);
// Reset framebuffer targets
glReadBuffer(GL_COLOR_ATTACHMENT0_EXT);
glDrawBuffers(4, RenderDrawList);
glDrawBuffers(3, RenderDrawList);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, OGLRef.fboRenderID);
}
else
@ -3815,28 +3748,23 @@ Render3DError OpenGLRenderer_1_2::ClearUsingImage(const u16 *__restrict colorBuf
if (this->isShaderSupported)
{
// Blit the working depth buffer
// Blit the polygon ID buffer
glReadBuffer(GL_COLOR_ATTACHMENT1_EXT);
glDrawBuffer(GL_COLOR_ATTACHMENT1_EXT);
glBlitFramebufferEXT(0, GPU_FRAMEBUFFER_NATIVE_HEIGHT, GPU_FRAMEBUFFER_NATIVE_WIDTH, 0, 0, 0, this->_framebufferWidth, this->_framebufferHeight, GL_COLOR_BUFFER_BIT, GL_NEAREST);
// Blit the polygon ID buffer
// Blit the fog buffer
glReadBuffer(GL_COLOR_ATTACHMENT2_EXT);
glDrawBuffer(GL_COLOR_ATTACHMENT2_EXT);
glBlitFramebufferEXT(0, GPU_FRAMEBUFFER_NATIVE_HEIGHT, GPU_FRAMEBUFFER_NATIVE_WIDTH, 0, 0, 0, this->_framebufferWidth, this->_framebufferHeight, GL_COLOR_BUFFER_BIT, GL_NEAREST);
// Blit the fog buffer
glReadBuffer(GL_COLOR_ATTACHMENT3_EXT);
glDrawBuffer(GL_COLOR_ATTACHMENT3_EXT);
glBlitFramebufferEXT(0, GPU_FRAMEBUFFER_NATIVE_HEIGHT, GPU_FRAMEBUFFER_NATIVE_WIDTH, 0, 0, 0, this->_framebufferWidth, this->_framebufferHeight, GL_COLOR_BUFFER_BIT, GL_NEAREST);
// Blit the color buffer. Do this last so that color attachment 0 is set to the read FBO.
glReadBuffer(GL_COLOR_ATTACHMENT0_EXT);
glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT);
glBlitFramebufferEXT(0, GPU_FRAMEBUFFER_NATIVE_HEIGHT, GPU_FRAMEBUFFER_NATIVE_WIDTH, 0, 0, 0, this->_framebufferWidth, this->_framebufferHeight, GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT, GL_NEAREST);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, OGLRef.fboRenderID);
glDrawBuffers(4, RenderDrawList);
glDrawBuffers(3, RenderDrawList);
}
else
{
@ -3859,28 +3787,23 @@ Render3DError OpenGLRenderer_1_2::ClearUsingImage(const u16 *__restrict colorBuf
if (this->isShaderSupported)
{
// Blit the working depth buffer
// Blit the polygon ID buffer
glReadBuffer(GL_COLOR_ATTACHMENT1_EXT);
glDrawBuffer(GL_COLOR_ATTACHMENT1_EXT);
glBlitFramebufferEXT(0, 0, this->_framebufferWidth, this->_framebufferHeight, 0, 0, this->_framebufferWidth, this->_framebufferHeight, GL_COLOR_BUFFER_BIT, GL_NEAREST);
// Blit the polygon ID buffer
// Blit the fog buffer
glReadBuffer(GL_COLOR_ATTACHMENT2_EXT);
glDrawBuffer(GL_COLOR_ATTACHMENT2_EXT);
glBlitFramebufferEXT(0, 0, this->_framebufferWidth, this->_framebufferHeight, 0, 0, this->_framebufferWidth, this->_framebufferHeight, GL_COLOR_BUFFER_BIT, GL_NEAREST);
// Blit the fog buffer
glReadBuffer(GL_COLOR_ATTACHMENT3_EXT);
glDrawBuffer(GL_COLOR_ATTACHMENT3_EXT);
glBlitFramebufferEXT(0, 0, this->_framebufferWidth, this->_framebufferHeight, 0, 0, this->_framebufferWidth, this->_framebufferHeight, GL_COLOR_BUFFER_BIT, GL_NEAREST);
// Blit the color and depth buffers. Do this last so that color attachment 0 is set to the read FBO.
glReadBuffer(GL_COLOR_ATTACHMENT0_EXT);
glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT);
glBlitFramebufferEXT(0, 0, this->_framebufferWidth, this->_framebufferHeight, 0, 0, this->_framebufferWidth, this->_framebufferHeight, GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT, GL_NEAREST);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, OGLRef.selectedRenderingFBO);
glDrawBuffers(4, RenderDrawList);
glDrawBuffers(3, RenderDrawList);
}
else
{
@ -3914,19 +3837,15 @@ Render3DError OpenGLRenderer_1_2::ClearUsingValues(const FragmentColor &clearCol
glClearStencil(clearAttributes.opaquePolyID);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
glDrawBuffer(GL_COLOR_ATTACHMENT1_EXT); // texGDepthID
glClearColor((GLfloat)(clearAttributes.depth & 0x000000FF)/255.0f, (GLfloat)((clearAttributes.depth >> 8) & 0x000000FF)/255.0f, (GLfloat)((clearAttributes.depth >> 16) & 0x000000FF)/255.0f, 1.0);
glClear(GL_COLOR_BUFFER_BIT);
glDrawBuffer(GL_COLOR_ATTACHMENT2_EXT); // texGPolyID
glDrawBuffer(GL_COLOR_ATTACHMENT1_EXT); // texGPolyID
glClearColor((GLfloat)clearAttributes.opaquePolyID/63.0f, 0.0, 0.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT);
glDrawBuffer(GL_COLOR_ATTACHMENT3_EXT); // texGFogAttrID
glDrawBuffer(GL_COLOR_ATTACHMENT2_EXT); // texGFogAttrID
glClearColor(clearAttributes.isFogged, 0.0, 0.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT);
glDrawBuffers(4, RenderDrawList);
glDrawBuffers(3, RenderDrawList);
}
else
{
@ -4368,9 +4287,6 @@ Render3DError OpenGLRenderer_1_2::SetFramebufferSize(size_t w, size_t h)
glBindTexture(GL_TEXTURE_2D, OGLRef.texGColorID);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, NULL);
glActiveTextureARB(GL_TEXTURE0_ARB + OGLTextureUnitID_GDepth);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, NULL);
glActiveTextureARB(GL_TEXTURE0_ARB + OGLTextureUnitID_GPolyID);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, NULL);
@ -4387,8 +4303,6 @@ Render3DError OpenGLRenderer_1_2::SetFramebufferSize(size_t w, size_t h)
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, OGLRef.rboMSGColorID);
glRenderbufferStorageMultisampleEXT(GL_RENDERBUFFER_EXT, maxSamples, GL_RGBA, w, h);
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, OGLRef.rboMSGDepthID);
glRenderbufferStorageMultisampleEXT(GL_RENDERBUFFER_EXT, maxSamples, GL_RGBA, w, h);
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, OGLRef.rboMSGPolyID);
glRenderbufferStorageMultisampleEXT(GL_RENDERBUFFER_EXT, maxSamples, GL_RGBA, w, h);
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, OGLRef.rboMSGFogAttrID);

View File

@ -295,7 +295,7 @@ enum OGLTextureUnitID
OGLTextureUnitID_FinalColor = 1,
OGLTextureUnitID_ToonTable,
OGLTextureUnitID_GColor,
OGLTextureUnitID_GDepth,
OGLTextureUnitID_DepthStencil,
OGLTextureUnitID_GPolyID,
OGLTextureUnitID_ZeroAlphaPixelMask,
OGLTextureUnitID_FogAttr,
@ -418,13 +418,11 @@ struct OGLRenderRef
// FBO
GLuint texCIColorID;
GLuint texCIDepthID;
GLuint texCIFogAttrID;
GLuint texCIPolyID;
GLuint texCIDepthStencilID;
GLuint texGColorID;
GLuint texGDepthID;
GLuint texGFogAttrID;
GLuint texGPolyID;
GLuint texZeroAlphaPixelMaskID;
@ -432,7 +430,6 @@ struct OGLRenderRef
GLuint texFinalColorID;
GLuint rboMSGColorID;
GLuint rboMSGDepthID;
GLuint rboMSGPolyID;
GLuint rboMSGFogAttrID;
GLuint rboMSGDepthStencilID;
@ -506,7 +503,6 @@ struct OGLRenderRef
// Client-side Buffers
GLfloat *color4fBuffer;
GLushort *vertIndexBuffer;
CACHE_ALIGN GLuint workingCIDepthBuffer[GPU_FRAMEBUFFER_NATIVE_WIDTH * GPU_FRAMEBUFFER_NATIVE_HEIGHT];
CACHE_ALIGN GLuint workingCIDepthStencilBuffer[GPU_FRAMEBUFFER_NATIVE_WIDTH * GPU_FRAMEBUFFER_NATIVE_HEIGHT];
CACHE_ALIGN GLuint workingCIFogAttributesBuffer[GPU_FRAMEBUFFER_NATIVE_WIDTH * GPU_FRAMEBUFFER_NATIVE_HEIGHT];
CACHE_ALIGN GLuint workingCIPolyIDBuffer[GPU_FRAMEBUFFER_NATIVE_WIDTH * GPU_FRAMEBUFFER_NATIVE_HEIGHT];
@ -528,7 +524,7 @@ extern GPU3DInterface gpu3Dgl;
extern GPU3DInterface gpu3DglOld;
extern GPU3DInterface gpu3Dgl_3_2;
extern const GLenum RenderDrawList[4];
extern const GLenum RenderDrawList[3];
extern CACHE_ALIGN const GLfloat divide5bitBy31_LUT[32];
extern CACHE_ALIGN const GLfloat divide6bitBy63_LUT[64];
extern const GLfloat PostprocessVtxBuffer[16];

View File

@ -191,23 +191,14 @@ static const char *GeometryFragShader_150 = {"\
uniform int polyIndex;\n\
\n\
out vec4 outFragColor;\n\
out vec4 outFragDepth;\n\
out vec4 outPolyID;\n\
out vec4 outFogAttributes;\n\
\n\
vec3 packVec3FromFloat(const float value)\n\
{\n\
float expandedValue = value * 16777215.0;\n\
vec3 packedValue = vec3( fract(expandedValue/256.0), fract(((expandedValue/256.0) - fract(expandedValue/256.0)) / 256.0), fract(((expandedValue/65536.0) - fract(expandedValue/65536.0)) / 256.0) );\n\
return packedValue;\n\
}\n\
\n\
void main()\n\
{\n\
vec4 newFragColor = vec4(0.0, 0.0, 0.0, 0.0);\n\
vec4 newPolyID = vec4(0.0, 0.0, 0.0, 0.0);\n\
vec4 newFogAttributes = vec4(0.0, 0.0, 0.0, 0.0);\n\
vec4 newFragDepth = vec4(0.0, 0.0, 0.0, 0.0);\n\
\n\
float vertW = (vtxPosition.w == 0.0) ? 0.00000001 : vtxPosition.w;\n\
// hack: when using z-depth, drop some LSBs so that the overworld map in Dragon Quest IV shows up correctly\n\
@ -269,17 +260,11 @@ static const char *GeometryFragShader_150 = {"\
discard;\n\
}\n\
\n\
if ( (newFragColor.a > 0.999) || bool(polySetNewDepthForTranslucent) )\n\
{\n\
newFragDepth = vec4(packVec3FromFloat(newFragDepthValue), 1.0);\n\
}\n\
\n\
newPolyID = vec4( float(polyID)/63.0, float(polyIsWireframe == 1u), 0.0, float(newFragColor.a > 0.999) );\n\
newFogAttributes = vec4( float(polyEnableFog), 0.0, 0.0, float((newFragColor.a > 0.999) ? 1.0 : 0.5) );\n\
}\n\
\n\
outFragColor = newFragColor;\n\
outFragDepth = newFragDepth;\n\
outPolyID = newPolyID;\n\
outFogAttributes = newFogAttributes;\n\
gl_FragDepth = newFragDepthValue;\n\
@ -389,12 +374,6 @@ static const char *EdgeMarkFragShader_150 = {"\
\n\
out vec4 outFragColor;\n\
\n\
float unpackFloatFromVec3(const vec3 value)\n\
{\n\
const vec3 unpackRatio = vec3(256.0, 65536.0, 16777216.0);\n\
return (dot(value, unpackRatio) / 16777215.0);\n\
}\n\
\n\
void main()\n\
{\n\
bool isZeroAlphaPixel = bool(texture(texZeroAlphaPixelMask, texCoord[0]).r);\n\
@ -410,11 +389,11 @@ static const char *EdgeMarkFragShader_150 = {"\
isWireframe[0] = bool(polyIDInfo[0].g);\n\
\n\
float depth[5];\n\
depth[0] = unpackFloatFromVec3(texture(texInFragDepth, texCoord[0]).rgb);\n\
depth[1] = unpackFloatFromVec3(texture(texInFragDepth, texCoord[1]).rgb);\n\
depth[2] = unpackFloatFromVec3(texture(texInFragDepth, texCoord[2]).rgb);\n\
depth[3] = unpackFloatFromVec3(texture(texInFragDepth, texCoord[3]).rgb);\n\
depth[4] = unpackFloatFromVec3(texture(texInFragDepth, texCoord[4]).rgb);\n\
depth[0] = texture(texInFragDepth, texCoord[0]).r;\n\
depth[1] = texture(texInFragDepth, texCoord[1]).r;\n\
depth[2] = texture(texInFragDepth, texCoord[2]).r;\n\
depth[3] = texture(texInFragDepth, texCoord[3]).r;\n\
depth[4] = texture(texInFragDepth, texCoord[4]).r;\n\
\n\
vec4 newEdgeColor = vec4(0.0, 0.0, 0.0, 0.0);\n\
\n\
@ -496,12 +475,6 @@ static const char *FogFragShader_150 = {"\
\n\
out vec4 outFragColor;\n\
\n\
float unpackFloatFromVec3(const vec3 value)\n\
{\n\
const vec3 unpackRatio = vec3(256.0, 65536.0, 16777216.0);\n\
return (dot(value, unpackRatio) / 16777215.0);\n\
}\n\
\n\
void main()\n\
{\n\
vec4 inFragColor = texture(texInFragColor, texCoord);\n\
@ -511,7 +484,7 @@ static const char *FogFragShader_150 = {"\
\n\
if (polyEnableFog)\n\
{\n\
float inFragDepth = unpackFloatFromVec3(texture(texInFragDepth, texCoord).rgb);\n\
float inFragDepth = texture(texInFragDepth, texCoord).r;\n\
float fogMixWeight = 0.0;\n\
\n\
if (inFragDepth <= min(state.fogOffset + state.fogStep, 1.0))\n\
@ -602,6 +575,7 @@ OpenGLRenderer_3_2::~OpenGLRenderer_3_2()
Render3DError OpenGLRenderer_3_2::InitExtensions()
{
OGLRenderRef &OGLRef = *this->ref;
Render3DError error = OGLERROR_NOERR;
// Get OpenGL extensions
@ -623,6 +597,16 @@ Render3DError OpenGLRenderer_3_2::InitExtensions()
// Initialize OpenGL
this->InitTables();
glGenTextures(1, &OGLRef.texFinalColorID);
glActiveTexture(GL_TEXTURE0 + OGLTextureUnitID_FinalColor);
glBindTexture(GL_TEXTURE_2D, OGLRef.texFinalColorID);
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, this->_framebufferWidth, this->_framebufferHeight, 0, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, NULL);
glActiveTexture(GL_TEXTURE0);
// Load and create shaders. Return on any error, since v3.2 Core Profile makes shaders mandatory.
this->isShaderSupported = true;
@ -751,7 +735,7 @@ Render3DError OpenGLRenderer_3_2::InitEdgeMarkProgramShaderLocations()
const GLint uniformTexGPolyID = glGetUniformLocation(OGLRef.programEdgeMarkID, "texInPolyID");
const GLint uniformTexZeroAlphaPixelMask = glGetUniformLocation(OGLRef.programEdgeMarkID, "texZeroAlphaPixelMask");
OGLRef.uniformIsAlphaWriteDisabled = glGetUniformLocation(OGLRef.programEdgeMarkID, "isAlphaWriteDisabled");
glUniform1i(uniformTexGDepth, OGLTextureUnitID_GDepth);
glUniform1i(uniformTexGDepth, OGLTextureUnitID_DepthStencil);
glUniform1i(uniformTexGPolyID, OGLTextureUnitID_GPolyID);
glUniform1i(uniformTexZeroAlphaPixelMask, OGLTextureUnitID_ZeroAlphaPixelMask);
glUniform1i(OGLRef.uniformIsAlphaWriteDisabled, GL_FALSE);
@ -782,7 +766,7 @@ Render3DError OpenGLRenderer_3_2::InitFogProgramShaderLocations()
const GLint uniformTexGDepth = glGetUniformLocation(OGLRef.programFogID, "texInFragDepth");
const GLint uniformTexGFog = glGetUniformLocation(OGLRef.programFogID, "texInFogAttributes");
glUniform1i(uniformTexGColor, OGLTextureUnitID_GColor);
glUniform1i(uniformTexGDepth, OGLTextureUnitID_GDepth);
glUniform1i(uniformTexGDepth, OGLTextureUnitID_DepthStencil);
glUniform1i(uniformTexGFog, OGLTextureUnitID_FogAttr);
return OGLERROR_NOERR;
@ -824,28 +808,17 @@ Render3DError OpenGLRenderer_3_2::CreateFBOs()
// Set up FBO render targets
glGenTextures(1, &OGLRef.texCIColorID);
glGenTextures(1, &OGLRef.texCIDepthID);
glGenTextures(1, &OGLRef.texCIFogAttrID);
glGenTextures(1, &OGLRef.texCIPolyID);
glGenTextures(1, &OGLRef.texCIDepthStencilID);
glGenTextures(1, &OGLRef.texFinalColorID);
glGenTextures(1, &OGLRef.texGColorID);
glGenTextures(1, &OGLRef.texGDepthID);
glGenTextures(1, &OGLRef.texGFogAttrID);
glGenTextures(1, &OGLRef.texGPolyID);
glGenTextures(1, &OGLRef.texGDepthStencilID);
glGenTextures(1, &OGLRef.texZeroAlphaPixelMaskID);
glActiveTexture(GL_TEXTURE0 + OGLTextureUnitID_FinalColor);
glBindTexture(GL_TEXTURE_2D, OGLRef.texFinalColorID);
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, this->_framebufferWidth, this->_framebufferHeight, 0, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, NULL);
glActiveTexture(GL_TEXTURE0 + OGLTextureUnitID_GColor);
glActiveTexture(GL_TEXTURE0 + OGLTextureUnitID_DepthStencil);
glBindTexture(GL_TEXTURE_2D, OGLRef.texGDepthStencilID);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
@ -854,6 +827,7 @@ Render3DError OpenGLRenderer_3_2::CreateFBOs()
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_NONE);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH24_STENCIL8, this->_framebufferWidth, this->_framebufferHeight, 0, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, NULL);
glActiveTexture(GL_TEXTURE0 + OGLTextureUnitID_GColor);
glBindTexture(GL_TEXTURE_2D, OGLRef.texGColorID);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
@ -861,14 +835,6 @@ Render3DError OpenGLRenderer_3_2::CreateFBOs()
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, this->_framebufferWidth, this->_framebufferHeight, 0, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, NULL);
glActiveTexture(GL_TEXTURE0 + OGLTextureUnitID_GDepth);
glBindTexture(GL_TEXTURE_2D, OGLRef.texGDepthID);
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, this->_framebufferWidth, this->_framebufferHeight, 0, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, NULL);
glActiveTexture(GL_TEXTURE0 + OGLTextureUnitID_GPolyID);
glBindTexture(GL_TEXTURE_2D, OGLRef.texGPolyID);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
@ -910,13 +876,6 @@ Render3DError OpenGLRenderer_3_2::CreateFBOs()
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_NONE);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH24_STENCIL8, GPU_FRAMEBUFFER_NATIVE_WIDTH, GPU_FRAMEBUFFER_NATIVE_HEIGHT, 0, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, NULL);
glBindTexture(GL_TEXTURE_2D, OGLRef.texCIDepthID);
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, GPU_FRAMEBUFFER_NATIVE_WIDTH, GPU_FRAMEBUFFER_NATIVE_HEIGHT, 0, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, NULL);
glBindTexture(GL_TEXTURE_2D, OGLRef.texCIPolyID);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
@ -940,9 +899,8 @@ Render3DError OpenGLRenderer_3_2::CreateFBOs()
glBindFramebuffer(GL_FRAMEBUFFER, OGLRef.fboClearImageID);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, OGLRef.texCIColorID, 0);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, OGLRef.texCIDepthID, 0);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT2, GL_TEXTURE_2D, OGLRef.texCIPolyID, 0);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT3, GL_TEXTURE_2D, OGLRef.texCIFogAttrID, 0);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, OGLRef.texCIPolyID, 0);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT2, GL_TEXTURE_2D, OGLRef.texCIFogAttrID, 0);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_TEXTURE_2D, OGLRef.texCIDepthStencilID, 0);
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
@ -954,12 +912,10 @@ Render3DError OpenGLRenderer_3_2::CreateFBOs()
glDeleteFramebuffers(1, &OGLRef.fboRenderID);
glDeleteFramebuffers(1, &OGLRef.fboPostprocessID);
glDeleteTextures(1, &OGLRef.texCIColorID);
glDeleteTextures(1, &OGLRef.texCIDepthID);
glDeleteTextures(1, &OGLRef.texCIFogAttrID);
glDeleteTextures(1, &OGLRef.texCIPolyID);
glDeleteTextures(1, &OGLRef.texCIDepthStencilID);
glDeleteTextures(1, &OGLRef.texGColorID);
glDeleteTextures(1, &OGLRef.texGDepthID);
glDeleteTextures(1, &OGLRef.texGPolyID);
glDeleteTextures(1, &OGLRef.texGFogAttrID);
glDeleteTextures(1, &OGLRef.texGDepthStencilID);
@ -972,14 +928,13 @@ Render3DError OpenGLRenderer_3_2::CreateFBOs()
return OGLERROR_FBO_CREATE_ERROR;
}
glDrawBuffers(4, RenderDrawList);
glDrawBuffers(3, RenderDrawList);
glReadBuffer(GL_COLOR_ATTACHMENT0);
glBindFramebuffer(GL_FRAMEBUFFER, OGLRef.fboRenderID);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, OGLRef.texGColorID, 0);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, OGLRef.texGDepthID, 0);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT2, GL_TEXTURE_2D, OGLRef.texGPolyID, 0);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT3, GL_TEXTURE_2D, OGLRef.texGFogAttrID, 0);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, OGLRef.texGPolyID, 0);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT2, GL_TEXTURE_2D, OGLRef.texGFogAttrID, 0);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_TEXTURE_2D, OGLRef.texGDepthStencilID, 0);
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
@ -991,12 +946,10 @@ Render3DError OpenGLRenderer_3_2::CreateFBOs()
glDeleteFramebuffers(1, &OGLRef.fboRenderID);
glDeleteFramebuffers(1, &OGLRef.fboPostprocessID);
glDeleteTextures(1, &OGLRef.texCIColorID);
glDeleteTextures(1, &OGLRef.texCIDepthID);
glDeleteTextures(1, &OGLRef.texCIFogAttrID);
glDeleteTextures(1, &OGLRef.texCIPolyID);
glDeleteTextures(1, &OGLRef.texCIDepthStencilID);
glDeleteTextures(1, &OGLRef.texGColorID);
glDeleteTextures(1, &OGLRef.texGDepthID);
glDeleteTextures(1, &OGLRef.texGPolyID);
glDeleteTextures(1, &OGLRef.texGFogAttrID);
glDeleteTextures(1, &OGLRef.texGDepthStencilID);
@ -1009,7 +962,7 @@ Render3DError OpenGLRenderer_3_2::CreateFBOs()
return OGLERROR_FBO_CREATE_ERROR;
}
glDrawBuffers(4, RenderDrawList);
glDrawBuffers(3, RenderDrawList);
glReadBuffer(GL_COLOR_ATTACHMENT0);
glBindFramebuffer(GL_FRAMEBUFFER, OGLRef.fboPostprocessID);
@ -1026,12 +979,10 @@ Render3DError OpenGLRenderer_3_2::CreateFBOs()
glDeleteFramebuffers(1, &OGLRef.fboRenderID);
glDeleteFramebuffers(1, &OGLRef.fboPostprocessID);
glDeleteTextures(1, &OGLRef.texCIColorID);
glDeleteTextures(1, &OGLRef.texCIDepthID);
glDeleteTextures(1, &OGLRef.texCIFogAttrID);
glDeleteTextures(1, &OGLRef.texCIPolyID);
glDeleteTextures(1, &OGLRef.texCIDepthStencilID);
glDeleteTextures(1, &OGLRef.texGColorID);
glDeleteTextures(1, &OGLRef.texGDepthID);
glDeleteTextures(1, &OGLRef.texGPolyID);
glDeleteTextures(1, &OGLRef.texGFogAttrID);
glDeleteTextures(1, &OGLRef.texGDepthStencilID);
@ -1068,12 +1019,10 @@ void OpenGLRenderer_3_2::DestroyFBOs()
glDeleteFramebuffers(1, &OGLRef.fboRenderID);
glDeleteFramebuffers(1, &OGLRef.fboPostprocessID);
glDeleteTextures(1, &OGLRef.texCIColorID);
glDeleteTextures(1, &OGLRef.texCIDepthID);
glDeleteTextures(1, &OGLRef.texCIFogAttrID);
glDeleteTextures(1, &OGLRef.texCIPolyID);
glDeleteTextures(1, &OGLRef.texCIDepthStencilID);
glDeleteTextures(1, &OGLRef.texGColorID);
glDeleteTextures(1, &OGLRef.texGDepthID);
glDeleteTextures(1, &OGLRef.texGPolyID);
glDeleteTextures(1, &OGLRef.texGFogAttrID);
glDeleteTextures(1, &OGLRef.texGDepthStencilID);
@ -1107,15 +1056,12 @@ Render3DError OpenGLRenderer_3_2::CreateMultisampledFBO()
// Set up FBO render targets
glGenRenderbuffers(1, &OGLRef.rboMSGColorID);
glGenRenderbuffers(1, &OGLRef.rboMSGDepthID);
glGenRenderbuffers(1, &OGLRef.rboMSGPolyID);
glGenRenderbuffers(1, &OGLRef.rboMSGFogAttrID);
glGenRenderbuffers(1, &OGLRef.rboMSGDepthStencilID);
glBindRenderbuffer(GL_RENDERBUFFER, OGLRef.rboMSGColorID);
glRenderbufferStorageMultisample(GL_RENDERBUFFER, maxSamples, GL_RGBA, this->_framebufferWidth, this->_framebufferHeight);
glBindRenderbuffer(GL_RENDERBUFFER, OGLRef.rboMSGDepthID);
glRenderbufferStorageMultisample(GL_RENDERBUFFER, maxSamples, GL_RGBA, this->_framebufferWidth, this->_framebufferHeight);
glBindRenderbuffer(GL_RENDERBUFFER, OGLRef.rboMSGPolyID);
glRenderbufferStorageMultisample(GL_RENDERBUFFER, maxSamples, GL_RGBA, this->_framebufferWidth, this->_framebufferHeight);
glBindRenderbuffer(GL_RENDERBUFFER, OGLRef.rboMSGFogAttrID);
@ -1128,9 +1074,8 @@ Render3DError OpenGLRenderer_3_2::CreateMultisampledFBO()
glBindFramebuffer(GL_FRAMEBUFFER, OGLRef.fboMSIntermediateRenderID);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, OGLRef.rboMSGColorID);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_RENDERBUFFER, OGLRef.rboMSGDepthID);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT2, GL_RENDERBUFFER, OGLRef.rboMSGPolyID);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT3, GL_RENDERBUFFER, OGLRef.rboMSGFogAttrID);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_RENDERBUFFER, OGLRef.rboMSGPolyID);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT2, GL_RENDERBUFFER, OGLRef.rboMSGFogAttrID);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, OGLRef.rboMSGDepthStencilID);
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
@ -1140,7 +1085,6 @@ Render3DError OpenGLRenderer_3_2::CreateMultisampledFBO()
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glDeleteFramebuffers(1, &OGLRef.fboMSIntermediateRenderID);
glDeleteRenderbuffers(1, &OGLRef.rboMSGColorID);
glDeleteRenderbuffers(1, &OGLRef.rboMSGDepthID);
glDeleteRenderbuffers(1, &OGLRef.rboMSGPolyID);
glDeleteRenderbuffers(1, &OGLRef.rboMSGFogAttrID);
glDeleteRenderbuffers(1, &OGLRef.rboMSGDepthStencilID);
@ -1168,7 +1112,6 @@ void OpenGLRenderer_3_2::DestroyMultisampledFBO()
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glDeleteFramebuffers(1, &OGLRef.fboMSIntermediateRenderID);
glDeleteRenderbuffers(1, &OGLRef.rboMSGColorID);
glDeleteRenderbuffers(1, &OGLRef.rboMSGDepthID);
glDeleteRenderbuffers(1, &OGLRef.rboMSGPolyID);
glDeleteRenderbuffers(1, &OGLRef.rboMSGFogAttrID);
glDeleteRenderbuffers(1, &OGLRef.rboMSGDepthStencilID);
@ -1247,9 +1190,8 @@ Render3DError OpenGLRenderer_3_2::InitGeometryProgramBindings()
glBindAttribLocation(OGLRef.programGeometryID, OGLVertexAttributeID_TexCoord0, "inTexCoord0");
glBindAttribLocation(OGLRef.programGeometryID, OGLVertexAttributeID_Color, "inColor");
glBindFragDataLocation(OGLRef.programGeometryID, 0, "outFragColor");
glBindFragDataLocation(OGLRef.programGeometryID, 1, "outFragDepth");
glBindFragDataLocation(OGLRef.programGeometryID, 2, "outPolyID");
glBindFragDataLocation(OGLRef.programGeometryID, 3, "outFogAttributes");
glBindFragDataLocation(OGLRef.programGeometryID, 1, "outPolyID");
glBindFragDataLocation(OGLRef.programGeometryID, 2, "outFogAttributes");
return OGLERROR_NOERR;
}
@ -1363,24 +1305,19 @@ Render3DError OpenGLRenderer_3_2::DownsampleFBO()
glDrawBuffer(GL_COLOR_ATTACHMENT0);
glBlitFramebuffer(0, 0, this->_framebufferWidth, this->_framebufferHeight, 0, 0, this->_framebufferWidth, this->_framebufferHeight, GL_COLOR_BUFFER_BIT, GL_NEAREST);
// Blit the working depth buffer
// Blit the polygon ID buffer
glReadBuffer(GL_COLOR_ATTACHMENT1);
glDrawBuffer(GL_COLOR_ATTACHMENT1);
glBlitFramebuffer(0, 0, this->_framebufferWidth, this->_framebufferHeight, 0, 0, this->_framebufferWidth, this->_framebufferHeight, GL_COLOR_BUFFER_BIT, GL_NEAREST);
// Blit the polygon ID buffer
// Blit the fog buffer
glReadBuffer(GL_COLOR_ATTACHMENT2);
glDrawBuffer(GL_COLOR_ATTACHMENT2);
glBlitFramebuffer(0, 0, this->_framebufferWidth, this->_framebufferHeight, 0, 0, this->_framebufferWidth, this->_framebufferHeight, GL_COLOR_BUFFER_BIT, GL_NEAREST);
// Blit the fog buffer
glReadBuffer(GL_COLOR_ATTACHMENT3);
glDrawBuffer(GL_COLOR_ATTACHMENT3);
glBlitFramebuffer(0, 0, this->_framebufferWidth, this->_framebufferHeight, 0, 0, this->_framebufferWidth, this->_framebufferHeight, GL_COLOR_BUFFER_BIT, GL_NEAREST);
// Reset framebuffer targets
glReadBuffer(GL_COLOR_ATTACHMENT0);
glDrawBuffers(4, RenderDrawList);
glDrawBuffers(3, RenderDrawList);
glBindFramebuffer(GL_FRAMEBUFFER, OGLRef.fboRenderID);
}
@ -1692,28 +1629,23 @@ Render3DError OpenGLRenderer_3_2::ClearUsingImage(const u16 *__restrict colorBuf
glBindFramebuffer(GL_READ_FRAMEBUFFER, OGLRef.fboClearImageID);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, OGLRef.fboRenderID);
// Blit the working depth buffer
// Blit the polygon ID buffer
glReadBuffer(GL_COLOR_ATTACHMENT1);
glDrawBuffer(GL_COLOR_ATTACHMENT1);
glBlitFramebuffer(0, GPU_FRAMEBUFFER_NATIVE_HEIGHT, GPU_FRAMEBUFFER_NATIVE_WIDTH, 0, 0, 0, this->_framebufferWidth, this->_framebufferHeight, GL_COLOR_BUFFER_BIT, GL_NEAREST);
// Blit the polygon ID buffer
// Blit the fog buffer
glReadBuffer(GL_COLOR_ATTACHMENT2);
glDrawBuffer(GL_COLOR_ATTACHMENT2);
glBlitFramebuffer(0, GPU_FRAMEBUFFER_NATIVE_HEIGHT, GPU_FRAMEBUFFER_NATIVE_WIDTH, 0, 0, 0, this->_framebufferWidth, this->_framebufferHeight, GL_COLOR_BUFFER_BIT, GL_NEAREST);
// Blit the fog buffer
glReadBuffer(GL_COLOR_ATTACHMENT3);
glDrawBuffer(GL_COLOR_ATTACHMENT3);
glBlitFramebuffer(0, GPU_FRAMEBUFFER_NATIVE_HEIGHT, GPU_FRAMEBUFFER_NATIVE_WIDTH, 0, 0, 0, this->_framebufferWidth, this->_framebufferHeight, GL_COLOR_BUFFER_BIT, GL_NEAREST);
// Blit the color and depth/stencil buffers. Do this last so that color attachment 0 is set to the read FBO.
glReadBuffer(GL_COLOR_ATTACHMENT0);
glDrawBuffer(GL_COLOR_ATTACHMENT0);
glBlitFramebuffer(0, GPU_FRAMEBUFFER_NATIVE_HEIGHT, GPU_FRAMEBUFFER_NATIVE_WIDTH, 0, 0, 0, this->_framebufferWidth, this->_framebufferHeight, GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT, GL_NEAREST);
glBindFramebuffer(GL_FRAMEBUFFER, OGLRef.fboRenderID);
glDrawBuffers(4, RenderDrawList);
glDrawBuffers(3, RenderDrawList);
OGLRef.selectedRenderingFBO = (CommonSettings.GFX3D_Renderer_Multisample) ? OGLRef.fboMSIntermediateRenderID : OGLRef.fboRenderID;
if (OGLRef.selectedRenderingFBO == OGLRef.fboMSIntermediateRenderID)
@ -1721,28 +1653,23 @@ Render3DError OpenGLRenderer_3_2::ClearUsingImage(const u16 *__restrict colorBuf
glBindFramebuffer(GL_READ_FRAMEBUFFER, OGLRef.fboRenderID);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, OGLRef.selectedRenderingFBO);
// Blit the working depth buffer
// Blit the polygon ID buffer
glReadBuffer(GL_COLOR_ATTACHMENT1);
glDrawBuffer(GL_COLOR_ATTACHMENT1);
glBlitFramebuffer(0, 0, this->_framebufferWidth, this->_framebufferHeight, 0, 0, this->_framebufferWidth, this->_framebufferHeight, GL_COLOR_BUFFER_BIT, GL_NEAREST);
// Blit the polygon ID buffer
// Blit the fog buffer
glReadBuffer(GL_COLOR_ATTACHMENT2);
glDrawBuffer(GL_COLOR_ATTACHMENT2);
glBlitFramebuffer(0, 0, this->_framebufferWidth, this->_framebufferHeight, 0, 0, this->_framebufferWidth, this->_framebufferHeight, GL_COLOR_BUFFER_BIT, GL_NEAREST);
// Blit the fog buffer
glReadBuffer(GL_COLOR_ATTACHMENT3);
glDrawBuffer(GL_COLOR_ATTACHMENT3);
glBlitFramebuffer(0, 0, this->_framebufferWidth, this->_framebufferHeight, 0, 0, this->_framebufferWidth, this->_framebufferHeight, GL_COLOR_BUFFER_BIT, GL_NEAREST);
// Blit the color and depth/stencil buffers. Do this last so that color attachment 0 is set to the read FBO.
glReadBuffer(GL_COLOR_ATTACHMENT0);
glDrawBuffer(GL_COLOR_ATTACHMENT0);
glBlitFramebuffer(0, 0, this->_framebufferWidth, this->_framebufferHeight, 0, 0, this->_framebufferWidth, this->_framebufferHeight, GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT, GL_NEAREST);
glBindFramebuffer(GL_FRAMEBUFFER, OGLRef.selectedRenderingFBO);
glDrawBuffers(4, RenderDrawList);
glDrawBuffers(3, RenderDrawList);
}
return OGLERROR_NOERR;
@ -1751,21 +1678,19 @@ Render3DError OpenGLRenderer_3_2::ClearUsingImage(const u16 *__restrict colorBuf
Render3DError OpenGLRenderer_3_2::ClearUsingValues(const FragmentColor &clearColor6665, const FragmentAttributes &clearAttributes) const
{
OGLRenderRef &OGLRef = *this->ref;
OGLRef.selectedRenderingFBO = (CommonSettings.GFX3D_Renderer_Multisample) ? OGLRef.fboMSIntermediateRenderID : OGLRef.fboRenderID;
OGLRef.selectedRenderingFBO = (CommonSettings.GFX3D_Renderer_Multisample && this->isMultisampledFBOSupported) ? OGLRef.fboMSIntermediateRenderID : OGLRef.fboRenderID;
glBindFramebuffer(GL_FRAMEBUFFER, OGLRef.selectedRenderingFBO);
glReadBuffer(GL_COLOR_ATTACHMENT0);
glDrawBuffers(4, RenderDrawList);
glDrawBuffers(3, RenderDrawList);
const GLfloat oglColor[4] = {divide6bitBy63_LUT[clearColor6665.r], divide6bitBy63_LUT[clearColor6665.g], divide6bitBy63_LUT[clearColor6665.b], divide5bitBy31_LUT[clearColor6665.a]};
const GLfloat oglDepth[4] = {(GLfloat)(clearAttributes.depth & 0x000000FF)/255.0f, (GLfloat)((clearAttributes.depth >> 8) & 0x000000FF)/255.0f, (GLfloat)((clearAttributes.depth >> 16) & 0x000000FF)/255.0f, 1.0};
const GLfloat oglPolyID[4] = {(GLfloat)clearAttributes.opaquePolyID/63.0f, 0.0f, 0.0f, 1.0f};
const GLfloat oglFogAttr[4] = {(GLfloat)clearAttributes.isFogged, 0.0f, 0.0f, 1.0f};
glClearBufferfi(GL_DEPTH_STENCIL, 0, (GLfloat)clearAttributes.depth / (GLfloat)0x00FFFFFF, clearAttributes.opaquePolyID);
glClearBufferfv(GL_COLOR, 0, oglColor); // texGColorID
glClearBufferfv(GL_COLOR, 1, oglDepth); // texGDepthID
glClearBufferfv(GL_COLOR, 2, oglPolyID); // texGPolyID
glClearBufferfv(GL_COLOR, 3, oglFogAttr); // texGFogAttrID
glClearBufferfv(GL_COLOR, 1, oglPolyID); // texGPolyID
glClearBufferfv(GL_COLOR, 2, oglFogAttr); // texGFogAttrID
return OGLERROR_NOERR;
}
@ -1898,13 +1823,12 @@ Render3DError OpenGLRenderer_3_2::SetFramebufferSize(size_t w, size_t h)
glBindTexture(GL_TEXTURE_2D, OGLRef.texFinalColorID);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, NULL);
glActiveTexture(GL_TEXTURE0 + OGLTextureUnitID_GColor);
glActiveTexture(GL_TEXTURE0 + OGLTextureUnitID_DepthStencil);
glBindTexture(GL_TEXTURE_2D, OGLRef.texGDepthStencilID);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH24_STENCIL8, w, h, 0, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, NULL);
glBindTexture(GL_TEXTURE_2D, OGLRef.texGColorID);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, NULL);
glActiveTexture(GL_TEXTURE0 + OGLTextureUnitID_GDepth);
glActiveTexture(GL_TEXTURE0 + OGLTextureUnitID_GColor);
glBindTexture(GL_TEXTURE_2D, OGLRef.texGColorID);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, NULL);
glActiveTexture(GL_TEXTURE0 + OGLTextureUnitID_GPolyID);
@ -1922,8 +1846,6 @@ Render3DError OpenGLRenderer_3_2::SetFramebufferSize(size_t w, size_t h)
glBindRenderbuffer(GL_RENDERBUFFER, OGLRef.rboMSGColorID);
glRenderbufferStorageMultisample(GL_RENDERBUFFER, maxSamples, GL_RGBA, w, h);
glBindRenderbuffer(GL_RENDERBUFFER, OGLRef.rboMSGDepthID);
glRenderbufferStorageMultisample(GL_RENDERBUFFER, maxSamples, GL_RGBA, w, h);
glBindRenderbuffer(GL_RENDERBUFFER, OGLRef.rboMSGPolyID);
glRenderbufferStorageMultisample(GL_RENDERBUFFER, maxSamples, GL_RGBA, w, h);
glBindRenderbuffer(GL_RENDERBUFFER, OGLRef.rboMSGFogAttrID);