1
0
mirror of https://github.com/blawar/GLideN64.git synced 2024-07-02 09:03:37 +00:00

Code refactoring: fix issues found by static code analizer.

This commit is contained in:
Sergey Lipskiy 2018-04-19 20:02:52 +07:00
parent 638149fb5c
commit 75ea06cec7
7 changed files with 37 additions and 27 deletions

View File

@ -307,7 +307,8 @@ void ColorBufferToRDRAM::_copy(u32 _startAddress, u32 _endAddress, bool _sync)
u32 ColorBufferToRDRAM::_getRealWidth(u32 _viWidth)
{
u32 index = 0;
while(index < m_allowedRealWidths.size() && _viWidth > m_allowedRealWidths[index])
const u32 maxIndex = m_allowedRealWidths.size() - 1;
while (index < maxIndex && _viWidth > m_allowedRealWidths[index])
{
++index;
}

View File

@ -207,30 +207,30 @@ void RDRAMtoColorBuffer::copyFromRDRAM(u32 _address, bool _bCFB)
m_pTexture->width = width;
m_pTexture->height = height;
u32 * dst = nullptr;
u32 * pDst = nullptr;
std::unique_ptr<u8[]> dstData;
//If not using float, the initial coversion will already be correct
if (fbTexFormats.colorType == datatype::FLOAT) {
const u32 initialDataSize = width*height * 4;
dstData = std::unique_ptr<u8[]>(new u8[initialDataSize]);
dst = reinterpret_cast<u32*>(dstData.get());
pDst = reinterpret_cast<u32*>(dstData.get());
} else {
dst = reinterpret_cast<u32*>(m_pbuf);
pDst = reinterpret_cast<u32*>(m_pbuf);
}
bool bCopy;
if (m_vecAddress.empty()) {
if (m_pCurBuffer->m_size == G_IM_SIZ_16b)
bCopy = _copyBufferFromRdram<u16>(address, dst, RGBA16ToABGR32, 1, x0, y0, width, height, _bCFB);
bCopy = _copyBufferFromRdram<u16>(address, pDst, RGBA16ToABGR32, 1, x0, y0, width, height, _bCFB);
else
bCopy = _copyBufferFromRdram<u32>(address, dst, RGBA32ToABGR32, 0, x0, y0, width, height, _bCFB);
bCopy = _copyBufferFromRdram<u32>(address, pDst, RGBA32ToABGR32, 0, x0, y0, width, height, _bCFB);
}
else {
if (m_pCurBuffer->m_size == G_IM_SIZ_16b)
bCopy = _copyPixelsFromRdram<u16>(address, m_vecAddress, dst, RGBA16ToABGR32, 1, width, height, _bCFB);
bCopy = _copyPixelsFromRdram<u16>(address, m_vecAddress, pDst, RGBA16ToABGR32, 1, width, height, _bCFB);
else
bCopy = _copyPixelsFromRdram<u32>(address, m_vecAddress, dst, RGBA32ToABGR32, 0, width, height, _bCFB);
bCopy = _copyPixelsFromRdram<u32>(address, m_vecAddress, pDst, RGBA32ToABGR32, 0, width, height, _bCFB);
}
//Convert integer format to float

View File

@ -679,7 +679,7 @@ public:
void update(bool _force) override
{
int clampMode;
int clampMode = -1;
switch (gfxContext.getClampMode())
{
case graphics::ClampMode::ClippingEnabled:

View File

@ -372,7 +372,7 @@ void TextDrawer::getTextSize(const char *_pText, float & _w, float & _h) const
DisplayWindow & wnd = DisplayWindow::get();
const float sx = 2.0f / wnd.getWidth();
const float sy = 2.0f / wnd.getHeight();
float bw, bh = 0;
float bw = 0, bh = 0;
for (const u8 *p = (const u8 *)_pText; *p; ++p) {
bw = m_atlas->c[*p].bw * sx;

View File

@ -504,16 +504,16 @@ void TextureCache::init()
m_pMSDummy = addFrameBufferTexture(true); // we don't want to remove dummy texture
_initDummyTexture(m_pMSDummy);
Context::InitTextureParams params;
params.handle = m_pMSDummy->name;
params.mipMapLevel = 0;
params.msaaLevel = config.video.multisampling;
params.width = m_pMSDummy->realWidth;
params.height = m_pMSDummy->realHeight;
params.format = colorFormat::RGBA;
params.internalFormat = gfxContext.convertInternalTextureFormat(u32(internalcolorFormat::RGBA8));
params.dataType = datatype::UNSIGNED_BYTE;
gfxContext.init2DTexture(params);
Context::InitTextureParams msParams;
msParams.handle = m_pMSDummy->name;
msParams.mipMapLevel = 0;
msParams.msaaLevel = config.video.multisampling;
msParams.width = m_pMSDummy->realWidth;
msParams.height = m_pMSDummy->realHeight;
msParams.format = colorFormat::RGBA;
msParams.internalFormat = gfxContext.convertInternalTextureFormat(u32(internalcolorFormat::RGBA8));
msParams.dataType = datatype::UNSIGNED_BYTE;
gfxContext.init2DTexture(msParams);
activateMSDummy(0);
activateMSDummy(1);
@ -763,7 +763,8 @@ void TextureCache::_loadBackground(CachedTexture *pTexture)
if (_loadHiresBackground(pTexture))
return;
u32 *pDest;
u32 *pDest = nullptr;
u16 *pDest16 = nullptr;
u8 *pSwapped, *pSrc;
u32 numBytes, bpl;
@ -799,6 +800,7 @@ void TextureCache::_loadBackground(CachedTexture *pTexture)
free(pSwapped);
return;
}
pDest16 = reinterpret_cast<u16*>(pDest);
clampSClamp = pTexture->width - 1;
clampTClamp = pTexture->height - 1;
@ -813,9 +815,9 @@ void TextureCache::_loadBackground(CachedTexture *pTexture)
tx = min(x, (u32)clampSClamp);
if (glInternalFormat == internalcolorFormat::RGBA8)
((u32*)pDest)[j++] = GetTexel((u64*)pSrc, tx, 0, pTexture->palette);
pDest[j++] = GetTexel((u64*)pSrc, tx, 0, pTexture->palette);
else
((u16*)pDest)[j++] = GetTexel((u64*)pSrc, tx, 0, pTexture->palette);
pDest16[j++] = static_cast<u16>(GetTexel((u64*)pSrc, tx, 0, pTexture->palette));
}
}

View File

@ -117,10 +117,13 @@ void T3DUX_LoadObject(u32 pstate, u32 pvtx, u32 ptri, u32 pcol)
gSP.texture.scales = 1.0f;
gSP.texture.scalet = 1.0f;
const u32 w0 = ostate->othermode0;
const u32 w1 = ostate->othermode1;
gDPSetOtherMode( _SHIFTR( w0, 0, 24 ), // mode0
w1 ); // mode1
{
const u32 w0 = ostate->othermode0;
const u32 w1 = ostate->othermode1;
gDPSetOtherMode(
_SHIFTR(w0, 0, 24), // mode0
w1); // mode1
}
if ((ostate->matrixFlag & 1) == 0) //load matrix
gSPForceMatrix(pstate + sizeof(T3DUXState));

View File

@ -479,6 +479,10 @@ void ZSortBOSS_TransposeMTX( u32, u32 _w1 )
case 0x8b0:
mtx = (M44*)gSP.matrix.combined;
break;
default:
assert(false);
return;
}
memcpy(m, mtx, 64);