Render3D: Make the _isSamplingEnabled flag universal for all 3D renderers.

Also update the OpenGL renderer to use the new flag.
This commit is contained in:
rogerman 2016-11-29 16:49:52 -08:00
parent 032622e817
commit 1368b2d5c7
8 changed files with 43 additions and 37 deletions

View File

@ -1320,6 +1320,8 @@ OpenGLTexture* OpenGLRenderer::GetLoadedTextureFromPolygon(const POLY &thePoly,
const NDSTextureFormat packFormat = theTexture->GetPackFormat();
const bool isTextureEnabled = ( (packFormat != TEXMODE_NONE) && enableTexturing );
theTexture->SetSamplingEnabled(isTextureEnabled);
if (theTexture->IsLoadNeeded() && isTextureEnabled)
{
theTexture->SetUseDeposterize(this->_textureDeposterize);
@ -2729,7 +2731,7 @@ Render3DError OpenGLRenderer_1_2::RenderGeometry(const GFX3D_State &renderState,
u32 lastViewport = firstPoly.viewport;
this->SetupPolygon(firstPoly);
this->SetupTexture(firstPoly, 0, renderState.enableTexturing);
this->SetupTexture(firstPoly, 0);
this->SetupViewport(lastViewport);
GLsizei vertIndexCount = 0;
@ -2752,7 +2754,7 @@ Render3DError OpenGLRenderer_1_2::RenderGeometry(const GFX3D_State &renderState,
{
lastTexParams = thePoly.texParam;
lastTexPalette = thePoly.texPalette;
this->SetupTexture(thePoly, i, renderState.enableTexturing);
this->SetupTexture(thePoly, i);
}
// Set up the viewport if it changed
@ -3052,19 +3054,22 @@ Render3DError OpenGLRenderer_1_2::SetupPolygon(const POLY &thePoly)
return OGLERROR_NOERR;
}
Render3DError OpenGLRenderer_1_2::SetupTexture(const POLY &thePoly, size_t polyRenderIndex, bool enableTexturing)
Render3DError OpenGLRenderer_1_2::SetupTexture(const POLY &thePoly, size_t polyRenderIndex)
{
OpenGLTexture *theTexture = this->_textureList[polyRenderIndex];
const NDSTextureFormat packFormat = theTexture->GetPackFormat();
const OGLRenderRef &OGLRef = *this->ref;
glBindTexture(GL_TEXTURE_2D, theTexture->GetID());
// Check if we need to use textures
if (packFormat == TEXMODE_NONE || !enableTexturing)
if (!theTexture->IsSamplingEnabled())
{
if (this->isShaderSupported)
{
glUniform1i(OGLRef.uniformPolyEnableTexture, GL_FALSE);
glUniform1i(OGLRef.uniformTexSingleBitAlpha, GL_FALSE);
glUniform2f(OGLRef.uniformPolyTexScale, theTexture->GetInvWidth(), theTexture->GetInvHeight());
}
else
{
@ -3091,7 +3096,6 @@ Render3DError OpenGLRenderer_1_2::SetupTexture(const POLY &thePoly, size_t polyR
glScalef(theTexture->GetInvWidth(), theTexture->GetInvHeight(), 1.0f);
}
glBindTexture(GL_TEXTURE_2D, theTexture->GetID());
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, (texParams.enableRepeatS ? (texParams.enableMirroredRepeatS ? OGLRef.stateTexMirroredRepeat : GL_REPEAT) : GL_CLAMP_TO_EDGE));
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, (texParams.enableRepeatT ? (texParams.enableMirroredRepeatT ? OGLRef.stateTexMirroredRepeat : GL_REPEAT) : GL_CLAMP_TO_EDGE));
@ -4644,14 +4648,17 @@ Render3DError OpenGLRenderer_2_0::SetupPolygon(const POLY &thePoly)
return OGLERROR_NOERR;
}
Render3DError OpenGLRenderer_2_0::SetupTexture(const POLY &thePoly, size_t polyRenderIndex, bool enableTexturing)
Render3DError OpenGLRenderer_2_0::SetupTexture(const POLY &thePoly, size_t polyRenderIndex)
{
OpenGLTexture *theTexture = this->_textureList[polyRenderIndex];
const NDSTextureFormat packFormat = theTexture->GetPackFormat();
const OGLRenderRef &OGLRef = *this->ref;
glBindTexture(GL_TEXTURE_2D, theTexture->GetID());
glUniform2f(OGLRef.uniformPolyTexScale, theTexture->GetInvWidth(), theTexture->GetInvHeight());
// Check if we need to use textures
if (packFormat == TEXMODE_NONE || !enableTexturing)
if (!theTexture->IsSamplingEnabled())
{
glUniform1i(OGLRef.uniformPolyEnableTexture, GL_FALSE);
glUniform1i(OGLRef.uniformTexSingleBitAlpha, GL_FALSE);
@ -4662,9 +4669,7 @@ Render3DError OpenGLRenderer_2_0::SetupTexture(const POLY &thePoly, size_t polyR
glUniform1i(OGLRef.uniformPolyEnableTexture, GL_TRUE);
glUniform1i(OGLRef.uniformTexSingleBitAlpha, (packFormat != TEXMODE_A3I5 && packFormat != TEXMODE_A5I3) ? GL_TRUE : GL_FALSE);
glUniform2f(OGLRef.uniformPolyTexScale, theTexture->GetInvWidth(), theTexture->GetInvHeight());
glBindTexture(GL_TEXTURE_2D, theTexture->GetID());
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, (texParams.enableRepeatS ? (texParams.enableMirroredRepeatS ? GL_MIRRORED_REPEAT : GL_REPEAT) : GL_CLAMP_TO_EDGE));
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, (texParams.enableRepeatT ? (texParams.enableMirroredRepeatT ? GL_MIRRORED_REPEAT : GL_REPEAT) : GL_CLAMP_TO_EDGE));

View File

@ -733,7 +733,7 @@ protected:
virtual void SetPolygonIndex(const size_t index);
virtual Render3DError SetupPolygon(const POLY &thePoly);
virtual Render3DError SetupTexture(const POLY &thePoly, size_t polyRenderIndex, bool enableTexturing);
virtual Render3DError SetupTexture(const POLY &thePoly, size_t polyRenderIndex);
virtual Render3DError SetupViewport(const u32 viewportValue);
public:
@ -806,7 +806,7 @@ protected:
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 SetupTexture(const POLY &thePoly, size_t polyRenderIndex, bool enableTexturing);
virtual Render3DError SetupTexture(const POLY &thePoly, size_t polyRenderIndex);
};
class OpenGLRenderer_2_1 : public OpenGLRenderer_2_0

View File

@ -1429,7 +1429,7 @@ Render3DError OpenGLRenderer_3_2::BeginRender(const GFX3D &engine)
const PolygonAttributes polyAttr = thePoly->getAttributes();
const PolygonTexParams texParams = thePoly->getTexParams();
polyStates[i].enableTexture = (packFormat != TEXMODE_NONE && engine.renderState.enableTexturing) ? GL_TRUE : GL_FALSE;
polyStates[i].enableTexture = (this->_textureList[i]->IsSamplingEnabled()) ? GL_TRUE : GL_FALSE;
polyStates[i].enableFog = (polyAttr.enableRenderFog && !(polyAttr.polygonMode == POLYGON_MODE_SHADOW && polyAttr.polygonID == 0)) ? GL_TRUE : GL_FALSE;
polyStates[i].enableDepthWrite = !(polyAttr.polygonMode == POLYGON_MODE_SHADOW && polyAttr.polygonID == 0) ? GL_TRUE : GL_FALSE;
polyStates[i].setNewDepthForTranslucent = (polyAttr.enableAlphaDepthWrite) ? GL_TRUE : GL_FALSE;
@ -1685,19 +1685,20 @@ Render3DError OpenGLRenderer_3_2::SetupPolygon(const POLY &thePoly)
return OGLERROR_NOERR;
}
Render3DError OpenGLRenderer_3_2::SetupTexture(const POLY &thePoly, size_t polyRenderIndex, bool enableTexturing)
Render3DError OpenGLRenderer_3_2::SetupTexture(const POLY &thePoly, size_t polyRenderIndex)
{
OpenGLTexture *theTexture = this->_textureList[polyRenderIndex];
glBindTexture(GL_TEXTURE_2D, theTexture->GetID());
// Check if we need to use textures
if (theTexture->GetPackFormat() == TEXMODE_NONE || !enableTexturing)
if (!theTexture->IsSamplingEnabled())
{
return OGLERROR_NOERR;
}
PolygonTexParams texParams = thePoly.getTexParams();
glBindTexture(GL_TEXTURE_2D, theTexture->GetID());
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, (texParams.enableRepeatS ? (texParams.enableMirroredRepeatS ? GL_MIRRORED_REPEAT : GL_REPEAT) : GL_CLAMP_TO_EDGE));
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, (texParams.enableRepeatT ? (texParams.enableMirroredRepeatT ? GL_MIRRORED_REPEAT : GL_REPEAT) : GL_CLAMP_TO_EDGE));

View File

@ -98,7 +98,7 @@ protected:
virtual void SetPolygonIndex(const size_t index);
virtual Render3DError SetupPolygon(const POLY &thePoly);
virtual Render3DError SetupTexture(const POLY &thePoly, size_t polyRenderIndex, bool enableTexturing);
virtual Render3DError SetupTexture(const POLY &thePoly, size_t polyRenderIndex);
virtual Render3DError SetFramebufferSize(size_t w, size_t h);
public:

View File

@ -348,7 +348,7 @@ public:
SoftRasterizerTexture *theTexture = this->_softRender->_textureList[polyRenderIndex];
this->currentTexture = theTexture;
if (!theTexture->IsRenderEnabled())
if (!theTexture->IsSamplingEnabled())
{
return RENDER3DERROR_NOERR;
}
@ -403,7 +403,7 @@ public:
FORCEINLINE void shade(const PolygonMode polygonMode, const FragmentColor src, FragmentColor &dst, const float texCoordU, const float texCoordV)
{
static const FragmentColor colorWhite = MakeFragmentColor(0x3F, 0x3F, 0x3F, 0x1F);
const FragmentColor mainTexColor = (this->currentTexture->IsRenderEnabled()) ? sample(texCoordU, texCoordV) : colorWhite;
const FragmentColor mainTexColor = (this->currentTexture->IsSamplingEnabled()) ? sample(texCoordU, texCoordV) : colorWhite;
switch (polygonMode)
{
@ -428,7 +428,7 @@ public:
case POLYGON_MODE_DECAL:
{
if (this->currentTexture->IsRenderEnabled())
if (this->currentTexture->IsSamplingEnabled())
{
dst.r = decal_table[mainTexColor.a][mainTexColor.r][src.r];
dst.g = decal_table[mainTexColor.a][mainTexColor.g][src.g];
@ -1080,7 +1080,6 @@ SoftRasterizerTexture::SoftRasterizerTexture(u32 texAttributes, u32 palAttribute
_renderHeightMask = _renderHeight - 1;
_renderWidthShift = 0;
_renderWrapMode = 0;
_renderEnabled = false;
_deposterizeSrcSurface.Surface = (unsigned char *)_unpackData;
@ -1227,16 +1226,6 @@ void SoftRasterizerTexture::SetRenderWrapMode(u32 texParam)
this->_renderWrapMode = (texParam >> 16) & 0x0F;
}
bool SoftRasterizerTexture::IsRenderEnabled() const
{
return this->_renderEnabled;
}
void SoftRasterizerTexture::SetRenderEnabled(bool isEnabled)
{
this->_renderEnabled = isEnabled;
}
FORCEINLINE void SoftRasterizerTexture::GetRenderSamplerCoordinates(s32 &iu, s32 &iv) const
{
switch (this->_renderWrapMode)
@ -2012,7 +2001,7 @@ SoftRasterizerTexture* SoftRasterizerRenderer::GetLoadedTextureFromPolygon(const
const NDSTextureFormat packFormat = theTexture->GetPackFormat();
const bool isTextureEnabled = ( (packFormat != TEXMODE_NONE) && enableTexturing );
theTexture->SetRenderEnabled(isTextureEnabled);
theTexture->SetSamplingEnabled(isTextureEnabled);
if (theTexture->IsLoadNeeded() && isTextureEnabled)
{

View File

@ -63,8 +63,6 @@ protected:
u32 _renderWidthShift;
u8 _renderWrapMode;
bool _renderEnabled;
public:
SoftRasterizerTexture(u32 texAttributes, u32 palAttributes);
virtual ~SoftRasterizerTexture();
@ -81,8 +79,6 @@ public:
u32 GetRenderWidthShift() const;
u8 GetRenderWrapMode() const;
void SetRenderWrapMode(u32 texParam);
bool IsRenderEnabled() const;
void SetRenderEnabled(bool isEnabled);
void GetRenderSamplerCoordinates(s32 &iu, s32 &iv) const;

View File

@ -195,6 +195,7 @@ void FragmentAttributesBuffer::SetAll(const FragmentAttributes &attr)
Render3DTexture::Render3DTexture(u32 texAttributes, u32 palAttributes) : TextureStore(texAttributes, palAttributes)
{
_isSamplingEnabled = true;
_useDeposterize = false;
_scalingFactor = 1;
@ -224,6 +225,16 @@ void Render3DTexture::_Upscale(const u32 *__restrict src, u32 *__restrict dst)
}
}
bool Render3DTexture::IsSamplingEnabled() const
{
return this->_isSamplingEnabled;
}
void Render3DTexture::SetSamplingEnabled(bool isEnabled)
{
this->_isSamplingEnabled = isEnabled;
}
bool Render3DTexture::IsUsingDeposterize() const
{
return this->_useDeposterize;
@ -607,7 +618,7 @@ Render3DError Render3D::SetupPolygon(const POLY &thePoly)
return RENDER3DERROR_NOERR;
}
Render3DError Render3D::SetupTexture(const POLY &thePoly, size_t polyRenderIndex, bool enableTexturing)
Render3DError Render3D::SetupTexture(const POLY &thePoly, size_t polyRenderIndex)
{
return RENDER3DERROR_NOERR;
}

View File

@ -117,6 +117,7 @@ struct Render3DDeviceInfo
class Render3DTexture : public TextureStore
{
protected:
bool _isSamplingEnabled;
bool _useDeposterize;
size_t _scalingFactor;
SSurface _deposterizeSrcSurface;
@ -126,6 +127,9 @@ protected:
public:
Render3DTexture(u32 texAttributes, u32 palAttributes);
bool IsSamplingEnabled() const;
void SetSamplingEnabled(bool isEnabled);
bool IsUsingDeposterize() const;
void SetUseDeposterize(bool willDeposterize);
@ -175,7 +179,7 @@ protected:
virtual Render3DError ClearUsingValues(const FragmentColor &clearColor6665, const FragmentAttributes &clearAttributes) const;
virtual Render3DError SetupPolygon(const POLY &thePoly);
virtual Render3DError SetupTexture(const POLY &thePoly, size_t polyRenderIndex, bool enableTexturing);
virtual Render3DError SetupTexture(const POLY &thePoly, size_t polyRenderIndex);
virtual Render3DError SetupViewport(const u32 viewportValue);
public: