OpenGL Renderer:
- Clear the stencil buffer with a value of 0 instead of with the polygon ID.
This commit is contained in:
parent
f48ed9fb89
commit
8f38fb38e8
|
@ -1749,24 +1749,24 @@ Render3DError OpenGLRenderer_1_2::UploadToonTable(const u16 *toonTableBuffer)
|
|||
return OGLERROR_NOERR;
|
||||
}
|
||||
|
||||
Render3DError OpenGLRenderer_1_2::UploadClearImage(const u16 *__restrict colorBuffer, const u32 *__restrict depthStencilBuffer, const bool *__restrict fogBuffer)
|
||||
Render3DError OpenGLRenderer_1_2::UploadClearImage(const u16 *__restrict colorBuffer, const u32 *__restrict depthBuffer, const bool *__restrict fogBuffer, const u8 *__restrict polyIDBuffer)
|
||||
{
|
||||
OGLRenderRef &OGLRef = *this->ref;
|
||||
|
||||
static GLuint depth[GFX3D_FRAMEBUFFER_WIDTH * GFX3D_FRAMEBUFFER_HEIGHT];
|
||||
static GLuint polyID[GFX3D_FRAMEBUFFER_WIDTH * GFX3D_FRAMEBUFFER_HEIGHT];
|
||||
static GLuint fogAttributes[GFX3D_FRAMEBUFFER_WIDTH * GFX3D_FRAMEBUFFER_HEIGHT];
|
||||
static GLuint polyID[GFX3D_FRAMEBUFFER_WIDTH * GFX3D_FRAMEBUFFER_HEIGHT];
|
||||
|
||||
for (size_t i = 0; i < GFX3D_FRAMEBUFFER_WIDTH * GFX3D_FRAMEBUFFER_HEIGHT; i++)
|
||||
{
|
||||
depth[i] = clearImageDepthStencilBuffer[i] >> 8;
|
||||
polyID[i] = (depthStencilBuffer[i] & 0x0000003F) | 0xFF000000;
|
||||
depth[i] = depthBuffer[i] | 0xFF000000;
|
||||
fogAttributes[i] = (fogBuffer[i]) ? 0xFF0000FF : 0xFF000000;
|
||||
polyID[i] = (GLuint)polyIDBuffer[i] | 0xFF000000;
|
||||
}
|
||||
|
||||
glActiveTextureARB(GL_TEXTURE0_ARB + OGLTextureUnitID_GColor);
|
||||
glBindTexture(GL_TEXTURE_2D, OGLRef.texGDepthStencilID);
|
||||
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, GFX3D_FRAMEBUFFER_WIDTH, GFX3D_FRAMEBUFFER_HEIGHT, GL_DEPTH_STENCIL_EXT, GL_UNSIGNED_INT_24_8_EXT, depthStencilBuffer);
|
||||
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, GFX3D_FRAMEBUFFER_WIDTH, GFX3D_FRAMEBUFFER_HEIGHT, GL_DEPTH_STENCIL_EXT, GL_UNSIGNED_INT_24_8_EXT, depthBuffer);
|
||||
glBindTexture(GL_TEXTURE_2D, OGLRef.texGColorID);
|
||||
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, GFX3D_FRAMEBUFFER_WIDTH, GFX3D_FRAMEBUFFER_HEIGHT, GL_RGBA, GL_UNSIGNED_SHORT_1_5_5_5_REV, colorBuffer);
|
||||
|
||||
|
@ -2255,7 +2255,7 @@ Render3DError OpenGLRenderer_1_2::UpdateToonTable(const u16 *toonTableBuffer)
|
|||
return OGLERROR_NOERR;
|
||||
}
|
||||
|
||||
Render3DError OpenGLRenderer_1_2::ClearUsingImage(const u16 *__restrict colorBuffer, const u32 *__restrict depthStencilBuffer, const bool *__restrict fogBuffer)
|
||||
Render3DError OpenGLRenderer_1_2::ClearUsingImage(const u16 *__restrict colorBuffer, const u32 *__restrict depthBuffer, const bool *__restrict fogBuffer, const u8 *__restrict polyIDBuffer)
|
||||
{
|
||||
if (!this->isFBOSupported)
|
||||
{
|
||||
|
@ -2264,7 +2264,7 @@ Render3DError OpenGLRenderer_1_2::ClearUsingImage(const u16 *__restrict colorBuf
|
|||
|
||||
OGLRenderRef &OGLRef = *this->ref;
|
||||
|
||||
this->UploadClearImage(colorBuffer, depthStencilBuffer, fogBuffer);
|
||||
this->UploadClearImage(colorBuffer, depthBuffer, fogBuffer, polyIDBuffer);
|
||||
|
||||
if (this->isMultisampledFBOSupported && OGLRef.selectedRenderingFBO == OGLRef.fboMSIntermediateRenderID)
|
||||
{
|
||||
|
@ -2282,7 +2282,7 @@ Render3DError OpenGLRenderer_1_2::ClearUsingImage(const u16 *__restrict colorBuf
|
|||
// We do this because glBlitFramebufferEXT() for GL_STENCIL_BUFFER_BIT has been tested
|
||||
// to be unsupported on ATI/AMD GPUs running in compatibility mode. So we do the separate
|
||||
// glClear() for GL_STENCIL_BUFFER_BIT to keep these GPUs working.
|
||||
glClearStencil(depthStencilBuffer[0] & 0x3F);
|
||||
glClearStencil(0);
|
||||
glClear(GL_STENCIL_BUFFER_BIT);
|
||||
|
||||
// Blit the working depth buffer
|
||||
|
@ -2316,7 +2316,7 @@ Render3DError OpenGLRenderer_1_2::ClearUsingValues(const u8 r, const u8 g, const
|
|||
glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT); // texGColorID
|
||||
glClearColor(divide5bitBy31_LUT[r], divide5bitBy31_LUT[g], divide5bitBy31_LUT[b], divide5bitBy31_LUT[a]);
|
||||
glClearDepth((GLclampd)clearDepth / (GLclampd)0x00FFFFFF);
|
||||
glClearStencil(clearPolyID);
|
||||
glClearStencil(0);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
||||
|
||||
glDrawBuffer(GL_COLOR_ATTACHMENT1_EXT); // texGDepthID
|
||||
|
@ -2337,7 +2337,7 @@ Render3DError OpenGLRenderer_1_2::ClearUsingValues(const u8 r, const u8 g, const
|
|||
{
|
||||
glClearColor(divide5bitBy31_LUT[r], divide5bitBy31_LUT[g], divide5bitBy31_LUT[b], divide5bitBy31_LUT[a]);
|
||||
glClearDepth((GLclampd)clearDepth / (GLclampd)0x00FFFFFF);
|
||||
glClearStencil(clearPolyID);
|
||||
glClearStencil(0);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
||||
}
|
||||
|
||||
|
@ -2633,24 +2633,24 @@ Render3DError OpenGLRenderer_1_3::UploadToonTable(const u16 *toonTableBuffer)
|
|||
return OGLERROR_NOERR;
|
||||
}
|
||||
|
||||
Render3DError OpenGLRenderer_1_3::UploadClearImage(const u16 *__restrict colorBuffer, const u32 *__restrict depthStencilBuffer, const bool *__restrict fogBuffer)
|
||||
Render3DError OpenGLRenderer_1_3::UploadClearImage(const u16 *__restrict colorBuffer, const u32 *__restrict depthBuffer, const bool *__restrict fogBuffer, const u8 *__restrict polyIDBuffer)
|
||||
{
|
||||
OGLRenderRef &OGLRef = *this->ref;
|
||||
|
||||
static GLuint depth[GFX3D_FRAMEBUFFER_WIDTH * GFX3D_FRAMEBUFFER_HEIGHT];
|
||||
static GLuint polyID[GFX3D_FRAMEBUFFER_WIDTH * GFX3D_FRAMEBUFFER_HEIGHT];
|
||||
static GLuint fogAttributes[GFX3D_FRAMEBUFFER_WIDTH * GFX3D_FRAMEBUFFER_HEIGHT];
|
||||
static GLuint polyID[GFX3D_FRAMEBUFFER_WIDTH * GFX3D_FRAMEBUFFER_HEIGHT];
|
||||
|
||||
for (size_t i = 0; i < GFX3D_FRAMEBUFFER_WIDTH * GFX3D_FRAMEBUFFER_HEIGHT; i++)
|
||||
{
|
||||
depth[i] = (depthStencilBuffer[i] >> 8) | 0xFF000000;
|
||||
polyID[i] = (depthStencilBuffer[i] & 0x0000003F) | 0xFF000000;
|
||||
depth[i] = depthBuffer[i] | 0xFF000000;
|
||||
fogAttributes[i] = (fogBuffer[i]) ? 0xFF0000FF : 0xFF000000;
|
||||
polyID[i] = (GLuint)polyIDBuffer[i] | 0xFF000000;
|
||||
}
|
||||
|
||||
glActiveTexture(GL_TEXTURE0 + OGLTextureUnitID_GColor);
|
||||
glBindTexture(GL_TEXTURE_2D, OGLRef.texGDepthStencilID);
|
||||
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, GFX3D_FRAMEBUFFER_WIDTH, GFX3D_FRAMEBUFFER_HEIGHT, GL_DEPTH_STENCIL_EXT, GL_UNSIGNED_INT_24_8_EXT, depthStencilBuffer);
|
||||
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, GFX3D_FRAMEBUFFER_WIDTH, GFX3D_FRAMEBUFFER_HEIGHT, GL_DEPTH_STENCIL_EXT, GL_UNSIGNED_INT_24_8_EXT, depthBuffer);
|
||||
glBindTexture(GL_TEXTURE_2D, OGLRef.texGColorID);
|
||||
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, GFX3D_FRAMEBUFFER_WIDTH, GFX3D_FRAMEBUFFER_HEIGHT, GL_RGBA, GL_UNSIGNED_SHORT_1_5_5_5_REV, colorBuffer);
|
||||
|
||||
|
|
|
@ -495,7 +495,7 @@ protected:
|
|||
virtual Render3DError CreateToonTable() = 0;
|
||||
virtual Render3DError DestroyToonTable() = 0;
|
||||
virtual Render3DError UploadToonTable(const u16 *toonTableBuffer) = 0;
|
||||
virtual Render3DError UploadClearImage(const u16 *__restrict colorBuffer, const u32 *__restrict depthStencilBuffer, const bool *__restrict fogBuffer) = 0;
|
||||
virtual Render3DError UploadClearImage(const u16 *__restrict colorBuffer, const u32 *__restrict depthBuffer, const bool *__restrict fogBuffer, const u8 *__restrict polyIDBuffer) = 0;
|
||||
|
||||
virtual void GetExtensionSet(std::set<std::string> *oglExtensionSet) = 0;
|
||||
virtual Render3DError ExpandFreeTextures() = 0;
|
||||
|
@ -551,7 +551,7 @@ protected:
|
|||
virtual Render3DError CreateToonTable();
|
||||
virtual Render3DError DestroyToonTable();
|
||||
virtual Render3DError UploadToonTable(const u16 *toonTableBuffer);
|
||||
virtual Render3DError UploadClearImage(const u16 *__restrict colorBuffer, const u32 *__restrict depthStencilBuffer, const bool *__restrict fogBuffer);
|
||||
virtual Render3DError UploadClearImage(const u16 *__restrict colorBuffer, const u32 *__restrict depthBuffer, const bool *__restrict fogBuffer, const u8 *__restrict polyIDBuffer);
|
||||
|
||||
virtual void GetExtensionSet(std::set<std::string> *oglExtensionSet);
|
||||
virtual Render3DError ExpandFreeTextures();
|
||||
|
@ -569,7 +569,7 @@ protected:
|
|||
|
||||
virtual Render3DError UpdateToonTable(const u16 *toonTableBuffer);
|
||||
|
||||
virtual Render3DError ClearUsingImage(const u16 *__restrict colorBuffer, const u32 *__restrict depthStencilBuffer, const bool *__restrict fogBuffer);
|
||||
virtual Render3DError ClearUsingImage(const u16 *__restrict colorBuffer, const u32 *__restrict depthBuffer, const bool *__restrict fogBuffer, const u8 *__restrict polyIDBuffer);
|
||||
virtual Render3DError ClearUsingValues(const u8 r, const u8 g, const u8 b, const u8 a, const u32 clearDepth, const u8 clearPolyID, const bool enableFog) const;
|
||||
|
||||
virtual Render3DError SetupPolygon(const POLY *thePoly);
|
||||
|
@ -591,7 +591,7 @@ class OpenGLRenderer_1_3 : public OpenGLRenderer_1_2
|
|||
{
|
||||
protected:
|
||||
virtual Render3DError UploadToonTable(const u16 *toonTableBuffer);
|
||||
virtual Render3DError UploadClearImage(const u16 *__restrict colorBuffer, const u32 *__restrict depthStencilBuffer, const bool *__restrict fogBuffer);
|
||||
virtual Render3DError UploadClearImage(const u16 *__restrict colorBuffer, const u32 *__restrict depthBuffer, const bool *__restrict fogBuffer, const u8 *__restrict polyIDBuffer);
|
||||
};
|
||||
|
||||
class OpenGLRenderer_1_4 : public OpenGLRenderer_1_3
|
||||
|
|
|
@ -1007,11 +1007,11 @@ Render3DError OpenGLRenderer_3_2::RenderFog(const u8 *densityTable, const u32 co
|
|||
return OGLERROR_NOERR;
|
||||
}
|
||||
|
||||
Render3DError OpenGLRenderer_3_2::ClearUsingImage(const u16 *__restrict colorBuffer, const u32 *__restrict depthStencilBuffer, const bool *__restrict fogBuffer)
|
||||
Render3DError OpenGLRenderer_3_2::ClearUsingImage(const u16 *__restrict colorBuffer, const u32 *__restrict depthBuffer, const bool *__restrict fogBuffer, const u8 *__restrict polyIDBuffer)
|
||||
{
|
||||
OGLRenderRef &OGLRef = *this->ref;
|
||||
|
||||
this->UploadClearImage(colorBuffer, depthStencilBuffer, fogBuffer);
|
||||
this->UploadClearImage(colorBuffer, depthBuffer, fogBuffer, polyIDBuffer);
|
||||
|
||||
if (OGLRef.selectedRenderingFBO == OGLRef.fboMSIntermediateRenderID)
|
||||
{
|
||||
|
|
|
@ -81,7 +81,7 @@ protected:
|
|||
virtual Render3DError RenderEdgeMarking(const u16 *colorTable);
|
||||
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 depthStencilBuffer, const bool *__restrict fogBuffer);
|
||||
virtual Render3DError ClearUsingImage(const u16 *__restrict colorBuffer, const u32 *__restrict depthBuffer, const bool *__restrict fogBuffer, const u8 *__restrict polyIDBuffer);
|
||||
|
||||
public:
|
||||
~OpenGLRenderer_3_2();
|
||||
|
|
|
@ -1654,7 +1654,7 @@ Render3DError SoftRasterizerRenderer::UpdateToonTable(const u16 *toonTableBuffer
|
|||
return RENDER3DERROR_NOERR;
|
||||
}
|
||||
|
||||
Render3DError SoftRasterizerRenderer::ClearUsingImage(const u16 *__restrict colorBuffer, const u32 *__restrict depthStencilBuffer, const bool *__restrict fogBuffer)
|
||||
Render3DError SoftRasterizerRenderer::ClearUsingImage(const u16 *__restrict colorBuffer, const u32 *__restrict depthBuffer, const bool *__restrict fogBuffer, const u8 *__restrict polyIDBuffer)
|
||||
{
|
||||
// The clear image buffer is y-flipped, so we need to flip it back to normal here.
|
||||
for (size_t y = 0; y < this->_framebufferHeight; y++)
|
||||
|
@ -1666,8 +1666,8 @@ Render3DError SoftRasterizerRenderer::ClearUsingImage(const u16 *__restrict colo
|
|||
|
||||
((u32 *)this->screenColor)[iw] = RGB15TO6665(colorBuffer[ir] & 0x7FFF, (colorBuffer[ir] >> 15) * 31);
|
||||
screenAttributes[iw].isFogged = fogBuffer[ir];
|
||||
screenAttributes[iw].depth = (depthStencilBuffer[ir] & 0xFFFFFF00) >> 8;
|
||||
screenAttributes[iw].opaquePolyID = depthStencilBuffer[ir] & 0x000000FF;
|
||||
screenAttributes[iw].depth = depthBuffer[ir];
|
||||
screenAttributes[iw].opaquePolyID = polyIDBuffer[ir];
|
||||
screenAttributes[iw].translucentPolyID = kUnsetTranslucentPolyID;
|
||||
screenAttributes[iw].isTranslucentPoly = false;
|
||||
screenAttributes[iw].stencil = 0;
|
||||
|
|
|
@ -81,7 +81,7 @@ protected:
|
|||
|
||||
virtual Render3DError UpdateToonTable(const u16 *toonTableBuffer);
|
||||
|
||||
virtual Render3DError ClearUsingImage(const u16 *__restrict colorBuffer, const u32 *__restrict depthStencilBuffer, const bool *__restrict fogBuffer);
|
||||
virtual Render3DError ClearUsingImage(const u16 *__restrict colorBuffer, const u32 *__restrict depthBuffer, const bool *__restrict fogBuffer, const u8 *__restrict polyIDBuffer);
|
||||
virtual Render3DError ClearUsingValues(const u8 r, const u8 g, const u8 b, const u8 a, const u32 clearDepth, const u8 clearPolyID, const bool enableFog) const;
|
||||
|
||||
public:
|
||||
|
|
|
@ -194,9 +194,10 @@ Render3DError Render3D::ClearFramebuffer(const GFX3D_State *renderState)
|
|||
|
||||
//this is tested quite well in the sonic chronicles main map mode
|
||||
//where depth values are used for trees etc you can walk behind
|
||||
this->clearImageDepthStencilBuffer[dd] = dsDepthToD24S8_LUT[clearDepthBuffer[adr] & 0x7FFF] | polyID;
|
||||
this->clearImageDepthBuffer[dd] = dsDepthToD24S8_LUT[clearDepthBuffer[adr] & 0x7FFF];
|
||||
|
||||
this->clearImageFogBuffer[dd] = BIT15(clearDepthBuffer[adr]);
|
||||
this->clearImagePolyIDBuffer[dd] = polyID;
|
||||
|
||||
dd++;
|
||||
}
|
||||
|
@ -204,7 +205,7 @@ Render3DError Render3D::ClearFramebuffer(const GFX3D_State *renderState)
|
|||
dd -= GFX3D_FRAMEBUFFER_WIDTH * 2;
|
||||
}
|
||||
|
||||
error = this->ClearUsingImage(this->clearImageColor16Buffer, this->clearImageDepthStencilBuffer, this->clearImageFogBuffer);
|
||||
error = this->ClearUsingImage(this->clearImageColor16Buffer, this->clearImageDepthBuffer, this->clearImageFogBuffer, this->clearImagePolyIDBuffer);
|
||||
if (error != RENDER3DERROR_NOERR)
|
||||
{
|
||||
error = this->ClearUsingValues(clearColor.r, clearColor.g, clearColor.b, clearColor.a, renderState->clearDepth, polyID, enableFog);
|
||||
|
@ -218,7 +219,7 @@ Render3DError Render3D::ClearFramebuffer(const GFX3D_State *renderState)
|
|||
return error;
|
||||
}
|
||||
|
||||
Render3DError Render3D::ClearUsingImage(const u16 *__restrict colorBuffer, const u32 *__restrict depthStencilBuffer, const bool *__restrict fogBuffer)
|
||||
Render3DError Render3D::ClearUsingImage(const u16 *__restrict colorBuffer, const u32 *__restrict depthBuffer, const bool *__restrict fogBuffer, const u8 *__restrict polyIDBuffer)
|
||||
{
|
||||
return RENDER3DERROR_NOERR;
|
||||
}
|
||||
|
@ -246,7 +247,9 @@ Render3DError Render3D::SetupViewport(const u32 viewportValue)
|
|||
Render3DError Render3D::Reset()
|
||||
{
|
||||
memset(this->clearImageColor16Buffer, 0, sizeof(this->clearImageColor16Buffer));
|
||||
memset(this->clearImageDepthStencilBuffer, 0, sizeof(this->clearImageDepthStencilBuffer));
|
||||
memset(this->clearImageDepthBuffer, 0, sizeof(this->clearImageDepthBuffer));
|
||||
memset(this->clearImagePolyIDBuffer, 0, sizeof(this->clearImagePolyIDBuffer));
|
||||
memset(this->clearImageFogBuffer, 0, sizeof(this->clearImageFogBuffer));
|
||||
|
||||
return RENDER3DERROR_NOERR;
|
||||
}
|
||||
|
|
|
@ -85,8 +85,9 @@ class Render3D
|
|||
{
|
||||
protected:
|
||||
CACHE_ALIGN u16 clearImageColor16Buffer[GFX3D_FRAMEBUFFER_WIDTH * GFX3D_FRAMEBUFFER_HEIGHT];
|
||||
CACHE_ALIGN u32 clearImageDepthStencilBuffer[GFX3D_FRAMEBUFFER_WIDTH * GFX3D_FRAMEBUFFER_HEIGHT];
|
||||
CACHE_ALIGN u32 clearImageDepthBuffer[GFX3D_FRAMEBUFFER_WIDTH * GFX3D_FRAMEBUFFER_HEIGHT];
|
||||
CACHE_ALIGN bool clearImageFogBuffer[GFX3D_FRAMEBUFFER_WIDTH * GFX3D_FRAMEBUFFER_HEIGHT];
|
||||
CACHE_ALIGN u8 clearImagePolyIDBuffer[GFX3D_FRAMEBUFFER_WIDTH * GFX3D_FRAMEBUFFER_HEIGHT];
|
||||
|
||||
virtual Render3DError BeginRender(const GFX3D_State *renderState);
|
||||
virtual Render3DError RenderGeometry(const GFX3D_State *renderState, const VERTLIST *vertList, const POLYLIST *polyList, const INDEXLIST *indexList);
|
||||
|
@ -97,7 +98,7 @@ protected:
|
|||
virtual Render3DError UpdateToonTable(const u16 *toonTableBuffer);
|
||||
|
||||
virtual Render3DError ClearFramebuffer(const GFX3D_State *renderState);
|
||||
virtual Render3DError ClearUsingImage(const u16 *__restrict colorBuffer, const u32 *__restrict depthStencilBuffer, const bool *__restrict fogBuffer);
|
||||
virtual Render3DError ClearUsingImage(const u16 *__restrict colorBuffer, const u32 *__restrict depthBuffer, const bool *__restrict fogBuffer, const u8 *__restrict polyIDBuffer);
|
||||
virtual Render3DError ClearUsingValues(const u8 r, const u8 g, const u8 b, const u8 a, const u32 clearDepth, const u8 clearPolyID, const bool enableFog) const;
|
||||
|
||||
virtual Render3DError SetupPolygon(const POLY *thePoly);
|
||||
|
|
Loading…
Reference in New Issue