mirror of
https://github.com/blawar/GLideN64.git
synced 2024-07-04 10:03:36 +00:00
Code refactor. add calcShiftScaleS and calcShiftScaleT
Remove code duplication.
This commit is contained in:
parent
9ebb11f37b
commit
46c58576e2
|
@ -499,19 +499,8 @@ CachedTexture * FrameBuffer::getTexture(u32 _t)
|
||||||
pTexture->scaleS = m_scale / static_cast<f32>(pTexture->width);
|
pTexture->scaleS = m_scale / static_cast<f32>(pTexture->width);
|
||||||
pTexture->scaleT = m_scale / static_cast<f32>(pTexture->height);
|
pTexture->scaleT = m_scale / static_cast<f32>(pTexture->height);
|
||||||
|
|
||||||
if (gSP.textureTile[_t]->shifts > 10)
|
pTexture->shiftScaleS = calcShiftScaleS(*gSP.textureTile[_t]);
|
||||||
pTexture->shiftScaleS = static_cast<f32>(1 << (16 - gSP.textureTile[_t]->shifts));
|
pTexture->shiftScaleT = calcShiftScaleT(*gSP.textureTile[_t]);
|
||||||
else if (gSP.textureTile[_t]->shifts > 0)
|
|
||||||
pTexture->shiftScaleS = 1.0f / static_cast<f32>(1 << gSP.textureTile[_t]->shifts);
|
|
||||||
else
|
|
||||||
pTexture->shiftScaleS = 1.0f;
|
|
||||||
|
|
||||||
if (gSP.textureTile[_t]->shiftt > 10)
|
|
||||||
pTexture->shiftScaleT = static_cast<f32>(1 << (16 - gSP.textureTile[_t]->shiftt));
|
|
||||||
else if (gSP.textureTile[_t]->shiftt > 0)
|
|
||||||
pTexture->shiftScaleT = 1.0f / static_cast<f32>(1 << gSP.textureTile[_t]->shiftt);
|
|
||||||
else
|
|
||||||
pTexture->shiftScaleT = 1.0f;
|
|
||||||
|
|
||||||
return pTexture;
|
return pTexture;
|
||||||
}
|
}
|
||||||
|
|
|
@ -274,8 +274,8 @@ public:
|
||||||
aTexSize[t][0] = pTexture->width * pTexture->hdRatioS;
|
aTexSize[t][0] = pTexture->width * pTexture->hdRatioS;
|
||||||
aTexSize[t][1] = pTexture->height * pTexture->hdRatioT;
|
aTexSize[t][1] = pTexture->height * pTexture->hdRatioT;
|
||||||
|
|
||||||
aShiftScale[t][0] = pTile->shifts > 10 ? static_cast<f32>(1 << (16 - pTile->shifts)) : 1.0f / static_cast<f32>(1 << pTile->shifts);
|
aShiftScale[t][0] = calcShiftScaleS(*pTile);
|
||||||
aShiftScale[t][1] = pTile->shiftt > 10 ? static_cast<f32>(1 << (16 - pTile->shiftt)) : 1.0f / static_cast<f32>(1 << pTile->shiftt);
|
aShiftScale[t][1] = calcShiftScaleT(*pTile);
|
||||||
|
|
||||||
if (pTile->textureMode != TEXTUREMODE_BGIMAGE && pTile->textureMode != TEXTUREMODE_FRAMEBUFFER_BG) {
|
if (pTile->textureMode != TEXTUREMODE_BGIMAGE && pTile->textureMode != TEXTUREMODE_FRAMEBUFFER_BG) {
|
||||||
aTexOffset[t][0] = pTile->fuls;
|
aTexOffset[t][0] = pTile->fuls;
|
||||||
|
|
|
@ -78,33 +78,18 @@ public:
|
||||||
float tcbounds[2][4] = {};
|
float tcbounds[2][4] = {};
|
||||||
if (useTexCoordBounds) {
|
if (useTexCoordBounds) {
|
||||||
f32 uls, lrs, ult, lrt, S, T, shiftScaleS, shiftScaleT;
|
f32 uls, lrs, ult, lrt, S, T, shiftScaleS, shiftScaleT;
|
||||||
s16 shiftedS, shiftedT;
|
|
||||||
u32 shifts, shiftt;
|
|
||||||
for (int t = 0; t < 2; t++) {
|
for (int t = 0; t < 2; t++) {
|
||||||
const CachedTexture * _pTexture = textureCache().current[t];
|
const CachedTexture * _pTexture = textureCache().current[t];
|
||||||
const gDPTile * _pTile = gSP.textureTile[t];
|
const gDPTile * _pTile = gSP.textureTile[t];
|
||||||
if (_pTexture != nullptr && _pTile != nullptr){
|
if (_pTexture != nullptr && _pTile != nullptr) {
|
||||||
if (_pTile->shifts > 10) {
|
s16 shiftedS = gDP.lastTexRectInfo.s;
|
||||||
shifts = 16 - _pTile->shifts;
|
shiftScaleS = calcShiftScaleS(*_pTile, &shiftedS);
|
||||||
shiftedS = static_cast<s16>(gDP.lastTexRectInfo.s << shifts);
|
|
||||||
shiftScaleS = static_cast<f32>(1 << shifts);
|
|
||||||
} else {
|
|
||||||
shifts = _pTile->shifts;
|
|
||||||
shiftedS = static_cast<s16>(gDP.lastTexRectInfo.s >> shifts);
|
|
||||||
shiftScaleS = 1.0f / static_cast<f32>(1 << shifts);
|
|
||||||
}
|
|
||||||
if (_pTile->shiftt > 10) {
|
|
||||||
shiftt = 16 - _pTile->shiftt;
|
|
||||||
shiftedT = static_cast<s16>(gDP.lastTexRectInfo.t << shiftt);
|
|
||||||
shiftScaleT = static_cast<f32>(1 << shiftt);
|
|
||||||
} else {
|
|
||||||
shiftt = _pTile->shiftt;
|
|
||||||
shiftedT = static_cast<s16>(gDP.lastTexRectInfo.t >> shiftt);
|
|
||||||
shiftScaleT = 1.0f / static_cast<f32>(1 << shiftt);
|
|
||||||
}
|
|
||||||
|
|
||||||
S = _FIXED2FLOAT(shiftedS, 5);
|
S = _FIXED2FLOAT(shiftedS, 5);
|
||||||
|
|
||||||
|
s16 shiftedT = gDP.lastTexRectInfo.t;
|
||||||
|
shiftScaleT = calcShiftScaleT(*_pTile, &shiftedT);
|
||||||
T = _FIXED2FLOAT(shiftedT, 5);
|
T = _FIXED2FLOAT(shiftedT, 5);
|
||||||
|
|
||||||
uls = S + (ceilf(gDP.lastTexRectInfo.ulx) - gDP.lastTexRectInfo.ulx) * gDP.lastTexRectInfo.dsdx * shiftScaleS;
|
uls = S + (ceilf(gDP.lastTexRectInfo.ulx) - gDP.lastTexRectInfo.ulx) * gDP.lastTexRectInfo.dsdx * shiftScaleS;
|
||||||
lrs = S + (ceilf(gDP.lastTexRectInfo.lrx) - gDP.lastTexRectInfo.ulx - 1.0f) * gDP.lastTexRectInfo.dsdx * shiftScaleS;
|
lrs = S + (ceilf(gDP.lastTexRectInfo.lrx) - gDP.lastTexRectInfo.ulx - 1.0f) * gDP.lastTexRectInfo.dsdx * shiftScaleS;
|
||||||
ult = T + (ceilf(gDP.lastTexRectInfo.uly) - gDP.lastTexRectInfo.uly) * gDP.lastTexRectInfo.dtdy * shiftScaleT;
|
ult = T + (ceilf(gDP.lastTexRectInfo.uly) - gDP.lastTexRectInfo.uly) * gDP.lastTexRectInfo.dtdy * shiftScaleT;
|
||||||
|
|
|
@ -1283,28 +1283,12 @@ void GraphicsDrawer::drawTexturedRect(const TexturedRectParams & _params)
|
||||||
f32 shiftScaleT = 1.0f;
|
f32 shiftScaleT = 1.0f;
|
||||||
|
|
||||||
s16 S = _params.s;
|
s16 S = _params.s;
|
||||||
if (gSP.textureTile[t]->shifts > 10) {
|
shiftScaleS = calcShiftScaleS(*gSP.textureTile[t], &S);
|
||||||
const u32 shifts = 16 - gSP.textureTile[t]->shifts;
|
|
||||||
S = static_cast<s16>(S << shifts);
|
|
||||||
shiftScaleS = static_cast<f32>(1 << shifts);
|
|
||||||
} else if (gSP.textureTile[t]->shifts > 0) {
|
|
||||||
const u32 shifts = gSP.textureTile[t]->shifts;
|
|
||||||
S = static_cast<s16>(S >> shifts);
|
|
||||||
shiftScaleS /= static_cast<f32>(1 << shifts);
|
|
||||||
}
|
|
||||||
const f32 uls = _FIXED2FLOAT(S, 5);
|
const f32 uls = _FIXED2FLOAT(S, 5);
|
||||||
const f32 lrs = uls + offsetX * shiftScaleS;
|
const f32 lrs = uls + offsetX * shiftScaleS;
|
||||||
|
|
||||||
s16 T = _params.t;
|
s16 T = _params.t;
|
||||||
if (gSP.textureTile[t]->shiftt > 10) {
|
shiftScaleT = calcShiftScaleT(*gSP.textureTile[t], &T);
|
||||||
const u32 shiftt = 16 - gSP.textureTile[t]->shiftt;
|
|
||||||
T = static_cast<s16>(T << shiftt);
|
|
||||||
shiftScaleT = static_cast<f32>(1 << shiftt);
|
|
||||||
} else if (gSP.textureTile[t]->shiftt > 0) {
|
|
||||||
const u32 shiftt = gSP.textureTile[t]->shiftt;
|
|
||||||
T = static_cast<s16>(T >> shiftt);
|
|
||||||
shiftScaleT /= static_cast<f32>(1 << shiftt);
|
|
||||||
}
|
|
||||||
const f32 ult = _FIXED2FLOAT(T, 5);
|
const f32 ult = _FIXED2FLOAT(T, 5);
|
||||||
const f32 lrt = ult + offsetY * shiftScaleT;
|
const f32 lrt = ult + offsetY * shiftScaleT;
|
||||||
|
|
||||||
|
|
|
@ -1915,7 +1915,8 @@ void TextureCache::update(u32 _t)
|
||||||
|
|
||||||
void getTextureShiftScale(u32 t, const TextureCache & cache, f32 & shiftScaleS, f32 & shiftScaleT)
|
void getTextureShiftScale(u32 t, const TextureCache & cache, f32 & shiftScaleS, f32 & shiftScaleT)
|
||||||
{
|
{
|
||||||
if (gSP.textureTile[t]->textureMode != TEXTUREMODE_NORMAL) {
|
gDPTile & tile = *gSP.textureTile[t];
|
||||||
|
if (tile.textureMode != TEXTUREMODE_NORMAL) {
|
||||||
shiftScaleS = cache.current[t]->shiftScaleS;
|
shiftScaleS = cache.current[t]->shiftScaleS;
|
||||||
shiftScaleT = cache.current[t]->shiftScaleT;
|
shiftScaleT = cache.current[t]->shiftScaleT;
|
||||||
return;
|
return;
|
||||||
|
@ -1924,15 +1925,8 @@ void getTextureShiftScale(u32 t, const TextureCache & cache, f32 & shiftScaleS,
|
||||||
if (gDP.otherMode.textureLOD == G_TL_LOD && gSP.texture.level == 0 && !currentCombiner()->usesLOD())
|
if (gDP.otherMode.textureLOD == G_TL_LOD && gSP.texture.level == 0 && !currentCombiner()->usesLOD())
|
||||||
t = 0;
|
t = 0;
|
||||||
|
|
||||||
if (gSP.textureTile[t]->shifts > 10)
|
shiftScaleS = calcShiftScaleS(tile);
|
||||||
shiftScaleS = (f32)(1 << (16 - gSP.textureTile[t]->shifts));
|
shiftScaleT = calcShiftScaleT(tile);
|
||||||
else if (gSP.textureTile[t]->shifts > 0)
|
|
||||||
shiftScaleS /= (f32)(1 << gSP.textureTile[t]->shifts);
|
|
||||||
|
|
||||||
if (gSP.textureTile[t]->shiftt > 10)
|
|
||||||
shiftScaleT = (f32)(1 << (16 - gSP.textureTile[t]->shiftt));
|
|
||||||
else if (gSP.textureTile[t]->shiftt > 0)
|
|
||||||
shiftScaleT /= (f32)(1 << gSP.textureTile[t]->shiftt);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool needReplaceTex1ByTex0()
|
bool needReplaceTex1ByTex0()
|
||||||
|
|
32
src/gDP.cpp
32
src/gDP.cpp
|
@ -43,6 +43,38 @@ bool isDepthCompareEnabled()
|
||||||
((gSP.geometryMode & G_ZBUFFER) || gDP.otherMode.depthSource == G_ZS_PRIM);
|
((gSP.geometryMode & G_ZBUFFER) || gDP.otherMode.depthSource == G_ZS_PRIM);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
f32 calcShiftScaleS(const gDPTile & _tile, s16 * _s)
|
||||||
|
{
|
||||||
|
if (_tile.shifts > 10) {
|
||||||
|
const u32 shifts = 16 - _tile.shifts;
|
||||||
|
if (_s != nullptr)
|
||||||
|
*_s = static_cast<s16>(*_s << shifts);
|
||||||
|
return static_cast<f32>(1 << shifts);
|
||||||
|
} else if (_tile.shifts > 0) {
|
||||||
|
const u32 shifts = _tile.shifts;
|
||||||
|
if (_s != nullptr)
|
||||||
|
*_s = static_cast<s16>(*_s >> shifts);
|
||||||
|
return 1.0f / static_cast<f32>(1 << shifts);
|
||||||
|
}
|
||||||
|
return 1.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
f32 calcShiftScaleT(const gDPTile & _tile, s16 * _t)
|
||||||
|
{
|
||||||
|
if (_tile.shiftt > 10) {
|
||||||
|
const u32 shiftt = 16 - _tile.shiftt;
|
||||||
|
if (_t != nullptr)
|
||||||
|
*_t = static_cast<s16>(*_t << shiftt);
|
||||||
|
return static_cast<f32>(1 << shiftt);
|
||||||
|
} else if (_tile.shiftt > 0) {
|
||||||
|
const u32 shiftt = _tile.shiftt;
|
||||||
|
if (_t != nullptr)
|
||||||
|
*_t = static_cast<s16>(*_t >> shiftt);
|
||||||
|
return 1.0f / static_cast<f32>(1 << shiftt);
|
||||||
|
}
|
||||||
|
return 1.0f;
|
||||||
|
}
|
||||||
|
|
||||||
void gDPSetOtherMode( u32 mode0, u32 mode1 )
|
void gDPSetOtherMode( u32 mode0, u32 mode1 )
|
||||||
{
|
{
|
||||||
gDP.otherMode.h = mode0;
|
gDP.otherMode.h = mode0;
|
||||||
|
|
|
@ -329,4 +329,7 @@ void gDPTriShadeTxtrZ( u32 w0, u32 w1 );
|
||||||
bool isCurrentColorImageDepthImage();
|
bool isCurrentColorImageDepthImage();
|
||||||
bool isDepthCompareEnabled();
|
bool isDepthCompareEnabled();
|
||||||
|
|
||||||
|
f32 calcShiftScaleS(const gDPTile & _tile, s16 * _s = nullptr);
|
||||||
|
f32 calcShiftScaleT(const gDPTile & _tile, s16 * _t = nullptr);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue
Block a user