From 78c89fbbfd228d7e98e26b2fd21c6bd5e7101913 Mon Sep 17 00:00:00 2001 From: Sergey Lipskiy Date: Thu, 12 Nov 2020 18:15:33 +0700 Subject: [PATCH] Fix some of PVS-Studio warnings. --- src/Debugger.cpp | 1 - src/GBI.cpp | 5 +-- src/Graphics/FramebufferTextureFormats.h | 3 -- .../ThreadedOpenGl/opengl_Wrapper.cpp | 36 +++++-------------- ...opengl_BufferManipulationObjectFactory.cpp | 35 +++--------------- .../OpenGLContext/opengl_CachedFunctions.h | 1 + src/gDP.cpp | 3 -- src/uCodes/F5Indi_Naboo.cpp | 3 +- src/uCodes/ZSortBOSS.cpp | 14 ++++---- 9 files changed, 25 insertions(+), 76 deletions(-) diff --git a/src/Debugger.cpp b/src/Debugger.cpp index d55091a3..48379cb3 100644 --- a/src/Debugger.cpp +++ b/src/Debugger.cpp @@ -258,7 +258,6 @@ void Debugger::_fillTriInfo(TriInfo & _info) _info.fill_color = gDP.fillColor; _info.blend_color = gDP.blendColor; _info.env_color = gDP.envColor; - _info.fill_color = gDP.fillColor; _info.prim_color = gDP.primColor; _info.primDepthZ = gDP.primDepth.z; _info.primDepthDeltaZ = gDP.primDepth.deltaZ; diff --git a/src/GBI.cpp b/src/GBI.cpp index 0109a28f..87c5af84 100644 --- a/src/GBI.cpp +++ b/src/GBI.cpp @@ -199,6 +199,7 @@ void GBIInfo::_makeCurrent(MicrocodeInfo * _pCurrent) switch (m_pCurrent->type) { case F3D: + case Turbo3D: F3D_Init(); m_hwlSupported = true; break; @@ -262,10 +263,6 @@ void GBIInfo::_makeCurrent(MicrocodeInfo * _pCurrent) F3DAM_Init(); m_hwlSupported = true; break; - case Turbo3D: - F3D_Init(); - m_hwlSupported = true; - break; case ZSortp: ZSort_Init(); m_hwlSupported = true; diff --git a/src/Graphics/FramebufferTextureFormats.h b/src/Graphics/FramebufferTextureFormats.h index 709f3974..c15b6295 100644 --- a/src/Graphics/FramebufferTextureFormats.h +++ b/src/Graphics/FramebufferTextureFormats.h @@ -37,9 +37,6 @@ namespace graphics { u32 noiseFormatBytes; virtual ~FramebufferTextureFormats() {} - - protected: - virtual void init() = 0; }; } diff --git a/src/Graphics/OpenGLContext/ThreadedOpenGl/opengl_Wrapper.cpp b/src/Graphics/OpenGLContext/ThreadedOpenGl/opengl_Wrapper.cpp index fe9a9dd1..5527ad3c 100644 --- a/src/Graphics/OpenGLContext/ThreadedOpenGl/opengl_Wrapper.cpp +++ b/src/Graphics/OpenGLContext/ThreadedOpenGl/opengl_Wrapper.cpp @@ -1576,43 +1576,29 @@ namespace opengl { switch (format) { case GL_RED: + case GL_RED_INTEGER: + case GL_STENCIL_INDEX: + case GL_DEPTH_COMPONENT: + case GL_LUMINANCE: components = 1; break; case GL_RG: + case GL_RG_INTEGER: + case GL_DEPTH_STENCIL: components = 2; break; case GL_RGB: case GL_BGR: - components = 3; - break; - case GL_RGBA: - case GL_BGRA: - components = 4; - break; - case GL_RED_INTEGER: - components = 1; - break; - case GL_RG_INTEGER: - components = 2; - break; case GL_RGB_INTEGER: case GL_BGR_INTEGER: components = 3; break; + case GL_RGBA: + case GL_BGRA: case GL_RGBA_INTEGER: case GL_BGRA_INTEGER: components = 4; break; - case GL_STENCIL_INDEX: - case GL_DEPTH_COMPONENT: - components = 1; - break; - case GL_DEPTH_STENCIL: - components = 2; - break; - case GL_LUMINANCE: - components = 1; - break; default: components = -1; } @@ -1625,15 +1611,11 @@ namespace opengl { break; case GL_UNSIGNED_SHORT: case GL_SHORT: + case GL_HALF_FLOAT: bytesPerPixel = components * 2; break; case GL_UNSIGNED_INT: case GL_INT: - bytesPerPixel = components * 4; - break; - case GL_HALF_FLOAT: - bytesPerPixel = components * 2; - break; case GL_FLOAT: bytesPerPixel = components * 4; break; diff --git a/src/Graphics/OpenGLContext/opengl_BufferManipulationObjectFactory.cpp b/src/Graphics/OpenGLContext/opengl_BufferManipulationObjectFactory.cpp index 8f0b78f8..da2fcd04 100644 --- a/src/Graphics/OpenGLContext/opengl_BufferManipulationObjectFactory.cpp +++ b/src/Graphics/OpenGLContext/opengl_BufferManipulationObjectFactory.cpp @@ -251,21 +251,14 @@ struct FramebufferTextureFormatsGLES2 : public graphics::FramebufferTextureForma return _glinfo.isGLES2; } - FramebufferTextureFormatsGLES2(const GLInfo & _glinfo): - m_glinfo(_glinfo) - { - init(); - } - -protected: - void init() override + FramebufferTextureFormatsGLES2(const GLInfo & _glinfo) { monochromeInternalFormat = GL_RGB; monochromeFormat = GL_RGB; monochromeType = GL_UNSIGNED_SHORT_5_6_5; monochromeFormatBytes = 2; - if (Utils::isExtensionSupported(m_glinfo, "GL_OES_depth_texture")) { + if (Utils::isExtensionSupported(_glinfo, "GL_OES_depth_texture")) { depthInternalFormat = GL_DEPTH_COMPONENT; depthFormatBytes = 4; } else { @@ -276,7 +269,7 @@ protected: depthFormat = GL_DEPTH_COMPONENT; depthType = GL_UNSIGNED_INT; - if (Utils::isExtensionSupported(m_glinfo, "GL_OES_rgb8_rgba8")) { + if (Utils::isExtensionSupported(_glinfo, "GL_OES_rgb8_rgba8")) { colorInternalFormat = GL_RGBA; colorFormat = GL_RGBA; colorType = GL_UNSIGNED_BYTE; @@ -294,9 +287,6 @@ protected: noiseType = GL_UNSIGNED_BYTE; noiseFormatBytes = 1; } - -private: - const GLInfo & m_glinfo; }; struct FramebufferTextureFormatsGLES3 : public graphics::FramebufferTextureFormats @@ -305,16 +295,9 @@ struct FramebufferTextureFormatsGLES3 : public graphics::FramebufferTextureForma return _glinfo.isGLESX && !_glinfo.isGLES2; } - FramebufferTextureFormatsGLES3(const GLInfo & _glinfo): - m_glinfo(_glinfo) + FramebufferTextureFormatsGLES3(const GLInfo & _glinfo) { - init(); - } - -protected: - void init() override - { - if (m_glinfo.renderer == Renderer::Adreno530) { + if (_glinfo.renderer == Renderer::Adreno530) { colorInternalFormat = GL_RGBA32F; colorFormat = GL_RGBA; colorType = GL_FLOAT; @@ -361,8 +344,6 @@ protected: noiseType = GL_UNSIGNED_BYTE; noiseFormatBytes = 1; } - - const GLInfo & m_glinfo; }; struct FramebufferTextureFormatsOpenGL : public graphics::FramebufferTextureFormats @@ -372,12 +353,6 @@ struct FramebufferTextureFormatsOpenGL : public graphics::FramebufferTextureForm } FramebufferTextureFormatsOpenGL() - { - init(); - } - -protected: - void init() override { colorInternalFormat = GL_RGBA8; colorFormat = GL_RGBA; diff --git a/src/Graphics/OpenGLContext/opengl_CachedFunctions.h b/src/Graphics/OpenGLContext/opengl_CachedFunctions.h index 2afa4079..12e1aa9f 100644 --- a/src/Graphics/OpenGLContext/opengl_CachedFunctions.h +++ b/src/Graphics/OpenGLContext/opengl_CachedFunctions.h @@ -191,6 +191,7 @@ namespace opengl { class CachedVertexAttribArray { public: + CachedVertexAttribArray() = default; void enableVertexAttribArray(u32 _index, bool _enable); void reset(); diff --git a/src/gDP.cpp b/src/gDP.cpp index f0f79657..750842f8 100644 --- a/src/gDP.cpp +++ b/src/gDP.cpp @@ -1644,9 +1644,6 @@ void LLETriangle::draw(bool _shade, bool _texture, bool _zbuffer, u32 * _pData) if (_zbuffer) gSP.geometryMode |= G_ZBUFFER; - if (vtxCount < 3) - return; - GraphicsDrawer & drawer = dwnd().getDrawer(); for (u32 i = 0; i < vtxCount - 2; ++i) { diff --git a/src/uCodes/F5Indi_Naboo.cpp b/src/uCodes/F5Indi_Naboo.cpp index d7405d06..93b682ed 100644 --- a/src/uCodes/F5Indi_Naboo.cpp +++ b/src/uCodes/F5Indi_Naboo.cpp @@ -2277,7 +2277,8 @@ void F5INDI_MoveWord(u32 _w0, u32 _w1) static void F5INDI_SetOtherMode(u32 w0, u32 w1) { - u32 mask = (s32)0x80000000 >> _SHIFTR(w0, 0, 5); + //u32 mask = (s32)0x80000000 >> _SHIFTR(w0, 0, 5); // unspecified behaviour + u32 mask = static_cast(s32(0x80000000) / (1 << _SHIFTR(w0, 0, 5))); mask >>= _SHIFTR(w0, 8, 5); const u32 A0 = _SHIFTR(w0, 16, 3); diff --git a/src/uCodes/ZSortBOSS.cpp b/src/uCodes/ZSortBOSS.cpp index 8625812e..8b0d5611 100644 --- a/src/uCodes/ZSortBOSS.cpp +++ b/src/uCodes/ZSortBOSS.cpp @@ -127,7 +127,7 @@ void StoreMatrix( f32 mtx[4][4], u32 address ) s16 integer[4][4]; u16 fraction[4][4]; } *n64Mat = (struct _N64Matrix *)&RDRAM[address]; - + for (u32 i = 0; i < 4; i++) { for (u32 j = 0; j < 4; j++) { const auto element = GetIntMatrixElement(mtx[i][j]); @@ -509,8 +509,6 @@ void ZSortBOSS_Lighting( u32 _w0, u32 _w1 ) tdest >>= 1; u32 r4 = _w0 << 7; - assert(r4 >= 0); - u32 r9 = DMEM[0x944]; assert(r9 == 0); @@ -540,11 +538,11 @@ void ZSortBOSS_Lighting( u32 _w0, u32 _w1 ) //DMEM[(cdest++)^3] = (u8)(vtx.g * 255.0f); //DMEM[(cdest++)^3] = (u8)(vtx.b * 255.0f); //DMEM[(cdest++)^3] = (u8)(vtx.a * 255.0f); - + ((s16*)DMEM)[(tdest++)^1] = (s16)vtx.s; ((s16*)DMEM)[(tdest++)^1] = (s16)vtx.t; } - + LOG(LOG_VERBOSE, "ZSortBOSS_Lighting (0x%08x, 0x%08x)", _w0, _w1); } @@ -784,7 +782,8 @@ void ZSortBOSS_UpdateMask( u32 _w0, u32 _w1 ) void ZSortBOSS_SetOtherMode_L( u32 _w0, u32 _w1 ) { - u32 mask = (s32)0x80000000 >> (_w0 & 0x1f); + //u32 mask = (s32)0x80000000 >> (_w0 & 0x1f); // unspecified behaviour + u32 mask = static_cast(s32(0x80000000) / (1 << (_w0 & 0x1f))); mask >>= (_w0 >> 8) & 0x1f; gDP.otherMode.l = (gDP.otherMode.l & ~mask) | _w1; @@ -799,7 +798,8 @@ void ZSortBOSS_SetOtherMode_L( u32 _w0, u32 _w1 ) void ZSortBOSS_SetOtherMode_H( u32 _w0, u32 _w1 ) { - u32 mask = (s32)0x80000000 >> (_w0 & 0x1f); + //u32 mask = (s32)0x80000000 >> (_w0 & 0x1f); // unspecified behaviour + u32 mask = static_cast(s32(0x80000000) / (1 << (_w0 & 0x1f))); mask >>= (_w0 >> 8) & 0x1f; gDP.otherMode.h = (gDP.otherMode.h & ~mask) | _w1;