1
0
mirror of https://github.com/blawar/GLideN64.git synced 2024-06-25 05:49:34 +00:00

Code cleanup: fix issues in GLideN64 found by static code analyser.

This commit is contained in:
Sergey Lipskiy 2017-11-18 22:07:27 +07:00
parent 67f72e86e5
commit 26623cec1f
21 changed files with 107 additions and 68 deletions

View File

@ -26,7 +26,7 @@ public:
private:
ColorBufferToRDRAM();
ColorBufferToRDRAM(const ColorBufferToRDRAM &);
ColorBufferToRDRAM(const ColorBufferToRDRAM &) = delete;
virtual ~ColorBufferToRDRAM();
CachedTexture * m_pTexture;

View File

@ -26,7 +26,7 @@ public:
private:
RDRAMtoColorBuffer();
RDRAMtoColorBuffer(const RDRAMtoColorBuffer &);
RDRAMtoColorBuffer(const RDRAMtoColorBuffer &) = delete;
void reset();

View File

@ -93,7 +93,7 @@
struct CombinerOp
{
int op;
int op = LOAD;
int param1 = -1;
int param2 = -1;
int param3 = -1;
@ -145,7 +145,7 @@ private:
, m_shadersLoaded(0)
, m_configOptionsBitSet(0)
, m_pCurrent(nullptr) {}
CombinerInfo(const CombinerInfo &);
CombinerInfo(const CombinerInfo &) = delete;
void _saveShadersStorage() const;
bool _loadShadersStorage();

View File

@ -140,6 +140,11 @@ bool Debugger::TriInfo::isInside(long x, long y) const
Debugger::Debugger()
{
m_triSel = m_triangles.end();
m_startTexRow[0] = m_startTexRow[1] = 0;
for (u32 i = 0; i < 2; ++i) {
m_selectedTexPos[i].col = 0;
m_selectedTexPos[i].row = 0;
}
}
Debugger::~Debugger()

View File

@ -60,6 +60,8 @@ private:
, a(_v.a)
, s0(_v.s)
, t0(_v.t)
, s1(_v.s)
, t1(_v.t)
, modify(_v.modify)
{}
@ -73,7 +75,9 @@ private:
, s1(_v.s1)
, t1(_v.t1)
, modify(0)
{}
{
r = g = b = a = 0.0f;
}
};
struct TriInfo {
@ -169,10 +173,10 @@ private:
bool m_bDebugMode = false;
bool m_bCapture = false;
long m_clickX;
long m_clickY;
long m_clickX = 0;
long m_clickY = 0;
u32 m_tmu;
u32 m_tmu = 0;
u32 m_startTexRow[2];
TexInfos m_texturesToDisplay[2];
struct {

View File

@ -63,7 +63,7 @@ public:
private:
DepthBufferList();
DepthBufferList(const DepthBufferList &);
DepthBufferList(const DepthBufferList &) = delete;
~DepthBufferList();
void _createScreenSizeBuffer(u32 _address);

View File

@ -223,8 +223,6 @@ void Rasterize(vertexi * vtx, int vertices, int dzdx)
trueZ = z / 8192;
if (trueZ < 0)
trueZ = 0;
else if (trueZ > 0x3FFFF)
trueZ = 0x3FFFF;
encodedZ = zLUT[trueZ];
idx = (shift + x) ^ 1;
if (encodedZ < destptr[idx])

View File

@ -30,14 +30,29 @@
using namespace std;
using namespace graphics;
FrameBuffer::FrameBuffer() :
m_startAddress(0), m_endAddress(0), m_size(0), m_width(0), m_height(0), m_validityChecked(0),
m_scale(0),
m_copiedToRdram(false), m_fingerprint(false), m_cleared(false), m_changed(false), m_cfb(false),
m_isDepthBuffer(false), m_isPauseScreen(false), m_isOBScreen(false), m_isMainBuffer(false), m_readable(false),
m_loadType(LOADTYPE_BLOCK), m_pDepthBuffer(nullptr),
m_pResolveTexture(nullptr), m_resolved(false),
m_pSubTexture(nullptr)
FrameBuffer::FrameBuffer()
: m_startAddress(0)
, m_endAddress(0)
, m_size(0)
, m_width(0)
, m_height(0)
, m_validityChecked(0)
, m_scale(0)
, m_copiedToRdram(false)
, m_fingerprint(false)
, m_cleared(false)
, m_changed(false)
, m_cfb(false)
, m_isDepthBuffer(false)
, m_isPauseScreen(false)
, m_isOBScreen(false)
, m_isMainBuffer(false)
, m_readable(false)
, m_loadType(LOADTYPE_BLOCK)
, m_pDepthBuffer(nullptr)
, m_pResolveTexture(nullptr)
, m_resolved(false)
, m_pSubTexture(nullptr)
{
m_loadTileOrigin.uls = m_loadTileOrigin.ult = 0;
m_pTexture = textureCache().addFrameBufferTexture(config.video.multisampling != 0);

View File

@ -65,8 +65,11 @@ struct FrameBuffer
private:
struct {
u32 fillcolor;
s32 ulx, uly, lrx, lry;
u32 fillcolor = 0;
s32 ulx = 0;
s32 uly = 0;
s32 lrx = 0;
s32 lry = 0;
} m_clearParams;
void _initTexture(u16 _width, u16 _height, u16 _format, u16 _size, CachedTexture *_pTexture);
@ -108,8 +111,8 @@ public:
static FrameBufferList & get();
private:
FrameBufferList() : m_pCurrent(nullptr), m_pCopy(nullptr) {}
FrameBufferList(const FrameBufferList &);
FrameBufferList() : m_pCurrent(nullptr), m_pCopy(nullptr), m_prevColorImageHeight(0) {}
FrameBufferList(const FrameBufferList &) = delete;
void removeIntersections();

View File

@ -100,8 +100,7 @@ bool DisplayWindowWindows::_start()
if (wglGetExtensionsStringARB != NULL) {
const char * wglextensions = wglGetExtensionsStringARB(hDC);
if (strstr(wglextensions, "WGL_ARB_create_context") != nullptr &&
strstr(wglextensions, "WGL_ARB_create_context_profile") != nullptr) {
if (strstr(wglextensions, "WGL_ARB_create_context_profile") != nullptr) {
PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribsARB =
(PFNWGLCREATECONTEXTATTRIBSARBPROC)wglGetProcAddress("wglCreateContextAttribsARB");

View File

@ -27,10 +27,14 @@
using namespace graphics;
GraphicsDrawer::GraphicsDrawer()
: m_modifyVertices(0)
: m_drawingState(DrawingState::Non)
, m_dmaVerticesNum(0)
, m_modifyVertices(0)
, m_maxLineWidth(1.0f)
, m_bImageTexture(false)
, m_bFlatColors(false)
{
memset(m_rect, 0, sizeof(m_rect));
}
GraphicsDrawer::~GraphicsDrawer()
@ -1305,7 +1309,7 @@ void GraphicsDrawer::drawTexturedRect(const TexturedRectParams & _params)
if (wnd.isAdjustScreen() &&
(_params.forceAjustScale ||
((gDP.colorImage.width > VI.width * 98 / 100) && (_params.lrx - _params.ulx < VI.width * 9 / 10))))
((gDP.colorImage.width > VI.width * 98 / 100) && ((u32)(_params.lrx - _params.ulx) < VI.width * 9 / 10))))
{
const float scale = wnd.getAdjustScale();
for (u32 i = 0; i < 4; ++i)

View File

@ -190,8 +190,8 @@ private:
struct {
std::array<SPVertex, VERTBUFF_SIZE> vertices;
std::array<u8, ELEMBUFF_SIZE> elements;
u32 num;
int maxElement;
u32 num = 0;
int maxElement = 0;
} triangles;
std::vector<SPVertex> m_dmaVertices;

View File

@ -27,7 +27,11 @@ NoiseTexture g_noiseTexture;
NoiseTexture::NoiseTexture()
: m_DList(0)
, m_currTex(0)
, m_prevTex(0)
{
for (u32 i = 0; i < m_prevTex; ++i)
m_pTexture[i] = nullptr;
}
static

View File

@ -18,7 +18,6 @@ public:
private:
CachedTexture * m_pTexture;
u32 m_tlut_tex;
std::unique_ptr<graphics::PixelWriteBuffer> m_pbuf;
u32 m_paletteCRC256;
};

View File

@ -94,7 +94,7 @@ private:
: m_pRspThread(NULL), m_pCommand(nullptr)
#endif
{}
PluginAPI(const PluginAPI &);
PluginAPI(const PluginAPI &) = delete;
void _initiateGFX(const GFX_INFO & _gfxInfo) const;

View File

@ -152,7 +152,6 @@ FrameBuffer * PostProcessor::doGammaCorrection(FrameBuffer * _pBuffer)
copyParams.dstY0 = 0;
copyParams.dstX1 = pDstTex->realWidth;
copyParams.dstY1 = pDstTex->realHeight;
copyParams.dstHeight = pDstTex->realHeight;
copyParams.dstWidth = pDstTex->realWidth;
copyParams.dstHeight = pDstTex->realHeight;
copyParams.tex[0] = m_pTextureOriginal;
@ -191,7 +190,6 @@ FrameBuffer * PostProcessor::doOrientationCorrection(FrameBuffer * _pBuffer)
copyParams.dstY0 = 0;
copyParams.dstX1 = pDstTex->realWidth;
copyParams.dstY1 = pDstTex->realHeight;
copyParams.dstHeight = pDstTex->realHeight;
copyParams.dstWidth = pDstTex->realWidth;
copyParams.dstHeight = pDstTex->realHeight;
copyParams.tex[0] = m_pTextureOriginal;

View File

@ -24,7 +24,7 @@ public:
private:
PostProcessor();
PostProcessor(const PostProcessor & _other);
PostProcessor(const PostProcessor & _other) = delete;
void _createResultBuffer(const FrameBuffer * _pMainBuffer);
void _initGammaCorrection();

View File

@ -209,8 +209,8 @@ bool getFontFileName(char * _strName)
return true;
}
FT_Library ft;
FT_Face face;
FT_Library g_ft;
FT_Face g_face;
void TextDrawer::init()
{
@ -222,19 +222,19 @@ void TextDrawer::init()
return;
/* Initialize the FreeType2 library */
if (FT_Init_FreeType(&ft)) {
if (FT_Init_FreeType(&g_ft)) {
fprintf(stderr, "Could not init freetype library\n");
return;
}
/* Load a font */
if (FT_New_Face(ft, fontfilename, 0, &face)) {
if (FT_New_Face(g_ft, fontfilename, 0, &g_face)) {
fprintf(stderr, "Could not open font %s\n", fontfilename);
return;
}
/* Create texture atlas for selected font size */
m_atlas.reset(new Atlas(face, config.font.size));
m_atlas.reset(new Atlas(g_face, config.font.size));
m_program.reset(gfxContext.createTextDrawerShader());
}
@ -243,8 +243,8 @@ void TextDrawer::destroy()
{
m_atlas.reset();
m_program.reset();
FT_Done_Face(face);
FT_Done_FreeType(ft);
FT_Done_Face(g_face);
FT_Done_FreeType(g_ft);
}
/**

View File

@ -802,10 +802,14 @@ void TextureCache::_loadBackground(CachedTexture *pTexture)
bpl = gSP.bgImage.width << gSP.bgImage.size >> 1;
numBytes = bpl * gSP.bgImage.height;
pSwapped = (u8*)malloc(numBytes);
assert(pSwapped != nullptr);
if (pSwapped == nullptr)
return;
UnswapCopyWrap(RDRAM, gSP.bgImage.address, pSwapped, 0, RDRAMSize, numBytes);
pDest = (u32*)malloc(pTexture->textureBytes);
assert(pDest != nullptr);
if (pDest == nullptr) {
free(pSwapped);
return;
}
clampSClamp = pTexture->width - 1;
clampTClamp = pTexture->height - 1;
@ -1376,15 +1380,15 @@ void TextureCache::_updateBackground()
Texture_Locations::iterator locations_iter = m_lruTextureLocations.find(crc);
if (locations_iter != m_lruTextureLocations.end()) {
Textures::iterator iter = locations_iter->second;
CachedTexture & current = *iter;
CachedTexture & currentTex = *iter;
m_textures.splice(m_textures.begin(), m_textures, iter);
assert(current.width == gSP.bgImage.width);
assert(current.height == gSP.bgImage.height);
assert(current.format == gSP.bgImage.format);
assert(current.size == gSP.bgImage.size);
assert(currentTex.width == gSP.bgImage.width);
assert(currentTex.height == gSP.bgImage.height);
assert(currentTex.format == gSP.bgImage.format);
assert(currentTex.size == gSP.bgImage.size);
activateTexture(0, &current);
activateTexture(0, &currentTex);
m_hits++;
return;
}
@ -1484,8 +1488,10 @@ void TextureCache::update(u32 _t)
if (gDP.otherMode.textureLOD == G_TL_LOD && gSP.texture.level == 0 && !currentCombiner()->usesLOD() && _t == 1) {
current[1] = current[0];
activateTexture(_t, current[_t]);
return;
if (current[1] != nullptr) {
activateTexture(1, current[1]);
return;
}
}
if (gSP.texture.tile == 7 &&
@ -1522,21 +1528,21 @@ void TextureCache::update(u32 _t)
Texture_Locations::iterator locations_iter = m_lruTextureLocations.find(crc);
if (locations_iter != m_lruTextureLocations.end()) {
Textures::iterator iter = locations_iter->second;
CachedTexture & current = *iter;
CachedTexture & currentTex = *iter;
if (current.width == sizes.width && current.height == sizes.height) {
if (currentTex.width == sizes.width && currentTex.height == sizes.height) {
m_textures.splice(m_textures.begin(), m_textures, iter);
assert(current.format == pTile->format);
assert(current.size == pTile->size);
assert(currentTex.format == pTile->format);
assert(currentTex.size == pTile->size);
activateTexture(_t, &current);
activateTexture(_t, &currentTex);
m_hits++;
return;
}
m_cachedBytes -= current.textureBytes;
gfxContext.deleteTexture(current.name);
m_cachedBytes -= currentTex.textureBytes;
gfxContext.deleteTexture(currentTex.name);
m_lruTextureLocations.erase(locations_iter);
m_textures.erase(iter);
}

View File

@ -64,13 +64,20 @@ struct TextureCache
static TextureCache & get();
private:
TextureCache() : m_pDummy(nullptr), m_hits(0), m_misses(0), m_cachedBytes(0), m_curUnpackAlignment(4), m_toggleDumpTex(false)
TextureCache()
: m_pDummy(nullptr)
, m_pMSDummy(nullptr)
, m_hits(0)
, m_misses(0)
, m_cachedBytes(0)
, m_curUnpackAlignment(4)
, m_toggleDumpTex(false)
{
current[0] = nullptr;
current[1] = nullptr;
CRC_Init();
}
TextureCache(const TextureCache &);
TextureCache(const TextureCache &) = delete;
void _checkCacheSize();
CachedTexture * _addTexture(u32 _crc32);
@ -93,7 +100,6 @@ private:
CachedTexture * m_pDummy;
CachedTexture * m_pMSDummy;
u32 m_hits, m_misses;
u32 m_maxBytes;
u32 m_cachedBytes;
s32 m_curUnpackAlignment;
bool m_toggleDumpTex;

View File

@ -1033,8 +1033,7 @@ void gDPLLETriangle(u32 _w1, u32 _w2, int _shade, int _texture, int _zbuffer, u3
j = ym-yh;
if (j > 0) {
int dx = (xleft-xright)>>16;
if ((!flip && xleft < xright) ||
(flip/* && xleft > xright*/))
if ((!flip && xleft < xright) || (flip/* && xleft > xright*/))
{
if (_shade != 0) {
vtx->r = CSCALE(r+drdx*dx);
@ -1052,8 +1051,7 @@ void gDPLLETriangle(u32 _w1, u32 _w2, int _shade, int _texture, int _zbuffer, u3
vtx->w = WSCALE(w+dwdx*dx);
++vtx;
}
if ((!flip/* && xleft < xright*/) ||
(flip && xleft > xright))
if ((!flip/* && xleft < xright*/) || (/*flip &&*/ xleft > xright))
{
if (_shade != 0) {
vtx->r = CSCALE(r);
@ -1073,7 +1071,7 @@ void gDPLLETriangle(u32 _w1, u32 _w2, int _shade, int _texture, int _zbuffer, u3
}
xleft += xleft_inc*j; xright += xright_inc*j;
s += dsde*j; t += dtde*j;
if (w + dwde*j) w += dwde*j;
if (w + dwde*j != 0) w += dwde*j;
else w += dwde*(j-1);
r += drde*j; g += dgde*j; b += dbde*j; a += dade*j;
z += dzde*j;
@ -1106,7 +1104,7 @@ void gDPLLETriangle(u32 _w1, u32 _w2, int _shade, int _texture, int _zbuffer, u3
++vtx;
}
if ((!flip/* && xleft <= xright*/) ||
(flip && xleft >= xright))
(/*flip && */xleft >= xright))
{
if (_shade != 0) {
vtx->r = CSCALE(r);
@ -1169,7 +1167,7 @@ void gDPLLETriangle(u32 _w1, u32 _w2, int _shade, int _texture, int _zbuffer, u3
++vtx;
}
if ((!flip/* && xleft <= xright*/) ||
(flip && xleft >= xright))
(/*flip &&*/ xleft >= xright))
{
if (_shade != 0) {
vtx->r = CSCALE(r);