From 281b63a537cec48760c324e3c992ac2dd0bcf971 Mon Sep 17 00:00:00 2001 From: Logan McNaughton Date: Fri, 15 Jan 2021 21:54:59 +0000 Subject: [PATCH] update gliden64 --- .../src/BufferCopy/ColorBufferToRDRAM.cpp | 15 --- GLideN64/src/DisplayWindow.cpp | 6 +- .../GLSL/glsl_CombinerProgramBuilder.cpp | 16 +++- .../GLSL/glsl_SpecialShadersFactory.cpp | 6 ++ GLideN64/src/osal/CMakeLists.txt | 2 +- GLideN64/src/osal/osal_keys_linux.c | 3 +- GLideN64/src/uCodes/F5Indi_Naboo.cpp | 92 +++++++++---------- 7 files changed, 71 insertions(+), 69 deletions(-) diff --git a/GLideN64/src/BufferCopy/ColorBufferToRDRAM.cpp b/GLideN64/src/BufferCopy/ColorBufferToRDRAM.cpp index 464ed43..1102b82 100644 --- a/GLideN64/src/BufferCopy/ColorBufferToRDRAM.cpp +++ b/GLideN64/src/BufferCopy/ColorBufferToRDRAM.cpp @@ -320,30 +320,15 @@ void ColorBufferToRDRAM::_copy(u32 _startAddress, u32 _endAddress, bool _sync) if (m_pCurFrameBuffer->m_size == G_IM_SIZ_32b) { u32 *ptr_src = (u32*)pPixels; u32 *ptr_dst = (u32*)(RDRAM + _startAddress); - - if (!FBInfo::fbInfo.isSupported() && config.frameBufferEmulation.copyFromRDRAM != 0) { - memset(ptr_dst, 0, numPixels * 4); - } - writeToRdram(ptr_src, ptr_dst, &ColorBufferToRDRAM::_RGBAtoRGBA32, 0, 0, width, height, numPixels, _startAddress, m_pCurFrameBuffer->m_startAddress, m_pCurFrameBuffer->m_size); } else if (m_pCurFrameBuffer->m_size == G_IM_SIZ_16b) { u32 *ptr_src = (u32*)pPixels; u16 *ptr_dst = (u16*)(RDRAM + _startAddress); m_blueNoiseIdx++; - - if (!FBInfo::fbInfo.isSupported() && config.frameBufferEmulation.copyFromRDRAM != 0) { - memset(ptr_dst, 0, numPixels * 2); - } - writeToRdram(ptr_src, ptr_dst, &ColorBufferToRDRAM::_RGBAtoRGBA16, 0, 1, width, height, numPixels, _startAddress, m_pCurFrameBuffer->m_startAddress, m_pCurFrameBuffer->m_size); } else if (m_pCurFrameBuffer->m_size == G_IM_SIZ_8b) { u8 *ptr_src = (u8*)pPixels; u8 *ptr_dst = RDRAM + _startAddress; - - if (!FBInfo::fbInfo.isSupported() && config.frameBufferEmulation.copyFromRDRAM != 0) { - memset(ptr_dst, 0, numPixels); - } - writeToRdram(ptr_src, ptr_dst, &ColorBufferToRDRAM::_RGBAtoR8, 0, 3, width, height, numPixels, _startAddress, m_pCurFrameBuffer->m_startAddress, m_pCurFrameBuffer->m_size); } diff --git a/GLideN64/src/DisplayWindow.cpp b/GLideN64/src/DisplayWindow.cpp index 96e95e5..b5e7325 100644 --- a/GLideN64/src/DisplayWindow.cpp +++ b/GLideN64/src/DisplayWindow.cpp @@ -8,6 +8,10 @@ #include "PluginAPI.h" #include "FrameBuffer.h" +#ifdef min +#undef min +#endif + bool DisplayWindow::start() { if (!_start()) @@ -79,7 +83,7 @@ void DisplayWindow::saveBufferContent(graphics::ObjectHandle _fbo, CachedTexture std::wstring pluginPath(m_strScreenDirectory); if (pluginPath.back() != L'/') pluginPath += L'/'; - ::wcsncpy(m_strScreenDirectory, pluginPath.c_str(), pluginPath.length() + 1); + ::wcsncpy(m_strScreenDirectory, pluginPath.c_str(), std::min(size_t(PLUGIN_PATH_SIZE), pluginPath.length() + 1)); } _saveBufferContent(_fbo, _pTexture); } diff --git a/GLideN64/src/Graphics/OpenGLContext/GLSL/glsl_CombinerProgramBuilder.cpp b/GLideN64/src/Graphics/OpenGLContext/GLSL/glsl_CombinerProgramBuilder.cpp index 62350b4..75cde79 100644 --- a/GLideN64/src/Graphics/OpenGLContext/GLSL/glsl_CombinerProgramBuilder.cpp +++ b/GLideN64/src/Graphics/OpenGLContext/GLSL/glsl_CombinerProgramBuilder.cpp @@ -244,6 +244,9 @@ public: "#else \n" "# define IN attribute \n" "# define OUT varying \n" + "#ifndef GL_FRAGMENT_PRECISION_HIGH \n" + "# define highp mediump \n" + "#endif \n" "#endif // __VERSION \n" ; } @@ -350,7 +353,7 @@ public: " else \n" " vShadeColor.rgb = vec3(fp); \n" " } \n" - " vBaryCoords = vec4(aBaryCoords, 1.0 - aBaryCoords.x - aBaryCoords.y, 0.5f); \n" + " vBaryCoords = vec4(aBaryCoords, 1.0 - aBaryCoords.x - aBaryCoords.y, 0.5); \n" ; } }; @@ -410,7 +413,7 @@ public: " else \n" " vShadeColor.rgb = vec3(fp); \n" " } \n" - " vBaryCoords = vec4(aBaryCoords, 1.0 - aBaryCoords.x - aBaryCoords.y, 0.5f); \n" + " vBaryCoords = vec4(aBaryCoords, 1.0 - aBaryCoords.x - aBaryCoords.y, 0.5); \n" ; } }; @@ -472,7 +475,7 @@ public: " gl_Position = aRectPosition; \n" " vShadeColor = uRectColor; \n" " vShadeColorNoperspective = uRectColor; \n" - " vBaryCoords = vec4(aBaryCoords, vec2(1.0f) - aBaryCoords);\n" + " vBaryCoords = vec4(aBaryCoords, vec2(1.0) - aBaryCoords);\n" ; } }; @@ -519,6 +522,9 @@ public: "#else \n" "# define IN varying \n" "# define OUT \n" + "#ifndef GL_FRAGMENT_PRECISION_HIGH \n" + "# define highp mediump \n" + "#endif \n" "#endif // __VERSION __ \n" ; } else if (_glinfo.isGLESX) { @@ -940,7 +946,7 @@ public: "highp vec2 tcData1[5]; \n" "uniform lowp int uCvgDest; \n" "uniform lowp int uBlendAlphaMode; \n" - "lowp float cvg;" + "lowp float cvg; \n" ; if (config.generalEmulation.enableLegacyBlending != 0) { @@ -2826,7 +2832,7 @@ graphics::CombinerProgram * CombinerProgramBuilder::buildCombinerProgram(Combine if (g_cycleType <= G_CYC_2CYCLE && m_useCoverage) m_shaderCoverage->write(ssShader); else - ssShader << "cvg = 1.0f; \n" << std::endl; + ssShader << "cvg = 1.0; \n" << std::endl; if (bUseTextures) { diff --git a/GLideN64/src/Graphics/OpenGLContext/GLSL/glsl_SpecialShadersFactory.cpp b/GLideN64/src/Graphics/OpenGLContext/GLSL/glsl_SpecialShadersFactory.cpp index 92c05da..508b965 100644 --- a/GLideN64/src/Graphics/OpenGLContext/GLSL/glsl_SpecialShadersFactory.cpp +++ b/GLideN64/src/Graphics/OpenGLContext/GLSL/glsl_SpecialShadersFactory.cpp @@ -148,6 +148,9 @@ namespace glsl { "#else \n" "# define IN varying \n" "# define OUT \n" + "#ifndef GL_FRAGMENT_PRECISION_HIGH \n" + "# define highp mediump \n" + "#endif \n" "#endif // __VERSION __ \n" "lowp vec4 uTestColor = vec4(4.0/255.0, 2.0/255.0, 1.0/255.0, 0.0); \n" "uniform lowp int uEnableAlphaTest; \n" @@ -218,6 +221,9 @@ namespace glsl { "#else \n" "# define IN varying \n" "# define OUT \n" + "#ifndef GL_FRAGMENT_PRECISION_HIGH \n" + "# define highp mediump \n" + "#endif \n" "#endif // __VERSION __ \n" "lowp vec4 uTestColor = vec4(4.0/255.0, 2.0/255.0, 1.0/255.0, 0.0); \n" "uniform lowp int uEnableAlphaTest; \n" diff --git a/GLideN64/src/osal/CMakeLists.txt b/GLideN64/src/osal/CMakeLists.txt index 9543c03..ef8c620 100644 --- a/GLideN64/src/osal/CMakeLists.txt +++ b/GLideN64/src/osal/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 2.6) +cmake_minimum_required(VERSION 3.9) project( osal ) diff --git a/GLideN64/src/osal/osal_keys_linux.c b/GLideN64/src/osal/osal_keys_linux.c index 8293a67..fd310a0 100644 --- a/GLideN64/src/osal/osal_keys_linux.c +++ b/GLideN64/src/osal/osal_keys_linux.c @@ -118,7 +118,8 @@ EXPORT void CALL osal_keys_init() /* check if file_name contains kbd */ if (strstr(file_name, "kbd") != NULL) { /* follow symlink and get full path */ - realpath(file_name, real_file_name); + if (realpath(file_name, real_file_name) == NULL) + continue; /* attempt to open the file */ kbd_file = l_Keyboards[kbd_index].file = fopen(real_file_name, "r"); diff --git a/GLideN64/src/uCodes/F5Indi_Naboo.cpp b/GLideN64/src/uCodes/F5Indi_Naboo.cpp index 93b682e..428cdfc 100644 --- a/GLideN64/src/uCodes/F5Indi_Naboo.cpp +++ b/GLideN64/src/uCodes/F5Indi_Naboo.cpp @@ -231,7 +231,7 @@ void F5INDI_Lighting_Overlay1(u32 _w0, u32 _w1) u32 D = (_SHIFTR(*V, 24, 8) * P1) >> 16; u32 E = (_SHIFTR(*V, 16, 8) * P1) >> 16; u32 F = (_SHIFTR(*V, 8, 8) * P1) >> 16; - u32 J = (_SHIFTR(factors[j], 0, 8) * data[3 ^ 3]) >> 8; + u32 J = (_SHIFTR(factors[j], 0, 8) * data[0x3 ^ 3]) >> 8; if (*light == 4) { *dst = J; @@ -243,9 +243,9 @@ void F5INDI_Lighting_Overlay1(u32 _w0, u32 _w1) *dst = std::min(*dst + D, 0xFFU); dst++; } else { - D += (_SHIFTR(factors[j], 24, 8) * data[0 ^ 3]) >> 8; - E += (_SHIFTR(factors[j], 16, 8) * data[1 ^ 3]) >> 8; - F += (_SHIFTR(factors[j], 8, 8) * data[2 ^ 3]) >> 8; + D += (_SHIFTR(factors[j], 24, 8) * data[0x0 ^ 3]) >> 8; + E += (_SHIFTR(factors[j], 16, 8) * data[0x1 ^ 3]) >> 8; + F += (_SHIFTR(factors[j], 8, 8) * data[0x2 ^ 3]) >> 8; *dst = J; dst++; *dst = std::min(F >> 1, 0xFFU); @@ -476,9 +476,9 @@ const SWVertex * F5INDI_LoadVtx(u32 _w0, u32 _w1, std::vector & _vres) const u32 base_addr = *CAST_DMEM(const u32*, 0x154); u32 * pres = reinterpret_cast(_vres.data()); const u16* v0_data = CAST_DMEM(const u16*, 0x128); - const u16 X0 = v0_data[0 ^ 1]; - const u16 Y0 = v0_data[1 ^ 1]; - const u16 Z0 = v0_data[2 ^ 1]; + const u16 X0 = v0_data[0x0 ^ 1]; + const u16 Y0 = v0_data[0x1 ^ 1]; + const u16 Z0 = v0_data[0x2 ^ 1]; for (u32 i = 0; i < count; ++i) { const u32 rdram_addr = dmem_data[i ^ 1] * 6 + base_addr; const u16* rdram_data = CAST_RDRAM(const u16*, (rdram_addr & 0x00FFFFF8)); @@ -499,17 +499,17 @@ const SWVertex * F5INDI_AdjustVtx(u32 _w0, u32 _w1, std::vector & _vre if (*CAST_DMEM(const u64*, 0x128) == 0) return CAST_DMEM(const SWVertex*, dmem_addr); const u16* v0_data = CAST_DMEM(const u16*, 0x128); - const u16 X0 = v0_data[0 ^ 1]; - const u16 Y0 = v0_data[1 ^ 1]; - const u16 Z0 = v0_data[2 ^ 1]; + const u16 X0 = v0_data[0x0 ^ 1]; + const u16 Y0 = v0_data[0x1 ^ 1]; + const u16 Z0 = v0_data[0x2 ^ 1]; const u32 count = _SHIFTR(_w1, 24, 7); _vres.resize(count); u32 * pres = reinterpret_cast(_vres.data()); const u16* dmem_data = CAST_DMEM(const u16*, dmem_addr); for (u32 i = 0; i < count; ++i) { - const u16 X = dmem_data[0 ^ 1] + X0; - const u16 Y = dmem_data[1 ^ 1] + Y0; - const u16 Z = dmem_data[2 ^ 1] + Z0; + const u16 X = dmem_data[0x0 ^ 1] + X0; + const u16 Y = dmem_data[0x1 ^ 1] + Y0; + const u16 Z = dmem_data[0x2 ^ 1] + Z0; *pres++ = (X << 16) | Y; *pres++ = Z << 16; dmem_data += 4; @@ -624,15 +624,15 @@ void F5INDI_CalcST(const u32* params, u32 * _st) for (u32 i = 0; i < num; ++i) { const u32 idx = _SHIFTR(params[i + 4], 0, 8); const s16 * coords = CAST_DMEM(const s16*, 0x170 + idx); - s16 X = coords[0 ^ 1]; - s16 Y = coords[1 ^ 1]; - s16 Z = coords[2 ^ 1]; + s16 X = coords[0x0 ^ 1]; + s16 Y = coords[0x1 ^ 1]; + s16 Z = coords[0x2 ^ 1]; s32 X1 = X * mtx[0 + 4 * 0] + Y * mtx[0 + 4 * 1] + Z * mtx[0 + 4 * 2] + mtx[0 + 4 * 3]; s32 Y1 = X * mtx[1 + 4 * 0] + Y * mtx[1 + 4 * 1] + Z * mtx[1 + 4 * 2] + mtx[1 + 4 * 3]; s32 Z1 = X * mtx[2 + 4 * 0] + Y * mtx[2 + 4 * 1] + Z * mtx[2 + 4 * 2] + mtx[2 + 4 * 3]; - X1 -= static_cast(static_cast(subs[0 ^ 1]) << 16); - Y1 -= static_cast(static_cast(subs[1 ^ 1]) << 16); - Z1 -= static_cast(static_cast(subs[2 ^ 1]) << 16); + X1 -= static_cast(static_cast(subs[0x0 ^ 1]) << 16); + Y1 -= static_cast(static_cast(subs[0x1 ^ 1]) << 16); + Z1 -= static_cast(static_cast(subs[0x2 ^ 1]) << 16); u64 X2 = static_cast(X1); u64 X2_2 = (X2 * X2) >> 16; u64 Y2 = static_cast(Y1); @@ -647,8 +647,8 @@ void F5INDI_CalcST(const u32* params, u32 * _st) D = 0xFFFFFFFF / (D * 0x300); u32 V = static_cast((D * X2) >> 16); u32 W = static_cast((D * Y2) >> 16); - u32 S = (V * muls[0 ^ 1]) >> 16; - u32 T = (W * muls[1 ^ 1]) >> 16; + u32 S = (V * muls[0x0 ^ 1]) >> 16; + u32 T = (W * muls[0x1 ^ 1]) >> 16; _st[i] = (S << 16) | T; } } @@ -865,22 +865,22 @@ void F5INDI_GenParticlesVertices() while (U != 0) { SWVertex * vertex = CAST_DMEM(SWVertex*, vtxAddr); u16* light = CAST_DMEM(u16*, lightAddr); - u16 F = (((light[0 ^ 1] << 12) + light[1 ^ 1] * corrector) << 4) >> 16; + u16 F = (((light[0x0 ^ 1] << 12) + light[0x1 ^ 1] * corrector) << 4) >> 16; bool endCycle = false; if ((M & 0x2000) == 0) { // Step 2 s16 F1; do { - F = (((light[0 ^ 1] << 12) + light[1 ^ 1] * corrector) << 4) >> 16; + F = (((light[0x0 ^ 1] << 12) + light[0x1 ^ 1] * corrector) << 4) >> 16; F1 = F + 0xF000; if (F1 < 0) { - light[0 ^ 1] = F; + light[0x0 ^ 1] = F; if ((M & 0x40) != 0) vertex->flag = (((F >> 4)&0xFC) << 8) | (vertex->flag & 0xFF); if ((M & 0x20) != 0) vertex->flag = ((F >> 4) & 0xFC) | (vertex->flag & 0xFF00); } else { - light[0 ^ 1] = 0U; + light[0x0 ^ 1] = 0U; if ((M & 0x4000) != 0) { //const u32 dpc_clock = *REG.DPC_CLOCK; const u32 dpc_clock = static_cast(time(NULL)) - dpc_clock0; @@ -1461,7 +1461,7 @@ void F5Naboo_PrepareAndDrawTriangle(const u32 _vert[3], GraphicsDrawer & _drawer const u16 A = _SHIFTR(*CAST_DMEM(const u32*, 0x100), 8, 16); const u8 B = *(DMEM + (0x103 ^ 3)); const u32 C = A | B; - CAST_DMEM(u16*, 0x100)[0^1] = C; + CAST_DMEM(u16*, 0x100)[0x0 ^ 1] = C; auto doCommands = [](u32 addr) { @@ -1567,11 +1567,11 @@ void F5Naboo_DrawPolygons() vtxIdx[i] = (vtxAddr - 0x600) / 40; SPVertex & vtx = drawer.getVertex(vtxIdx[i]); u8* color = DMEM + 0x0B78 + idxs[i] * 2 + (data.HH & 0xFFF); - vtx.r = _FIXED2FLOATCOLOR(color[0 ^ 3], 8); - vtx.g = _FIXED2FLOATCOLOR(color[1 ^ 3], 8); - vtx.b = _FIXED2FLOATCOLOR(color[2 ^ 3], 8); - vtx.a = _FIXED2FLOATCOLOR(color[3 ^ 3], 8); - alphaSum += color[3 ^ 3]; + vtx.r = _FIXED2FLOATCOLOR(color[0x0 ^ 3], 8); + vtx.g = _FIXED2FLOATCOLOR(color[0x1 ^ 3], 8); + vtx.b = _FIXED2FLOATCOLOR(color[0x2 ^ 3], 8); + vtx.a = _FIXED2FLOATCOLOR(color[0x3 ^ 3], 8); + alphaSum += color[0x3 ^ 3]; } if (data.HH == 0) { *CAST_DMEM(u32*, 0x100) = 0; @@ -1594,7 +1594,7 @@ void F5Naboo_DrawPolygons() for (u32 i = 0; i < 3; ++i) { u32 offset = 0xB00 + idxs[i] * 2 + (data.HH & 0xFFF); u8* color = DMEM + offset; - alphas[i] = color[3 ^ 3]; + alphas[i] = color[0x3 ^ 3]; alphaSum2 += alphas[i]; } if (alphaSum2 == 0) { @@ -1875,9 +1875,9 @@ void F5Naboo_GenVertices0C() // Step 10 const u16* v0_data = CAST_DMEM(const u16*, 0x128); - const u16 X0 = v0_data[0 ^ 1]; - const u16 Y0 = v0_data[1 ^ 1]; - const u16 Z0 = v0_data[2 ^ 1]; + const u16 X0 = v0_data[0x0 ^ 1]; + const u16 Y0 = v0_data[0x1 ^ 1]; + const u16 Z0 = v0_data[0x2 ^ 1]; const bool needAdjustVertices = (X0 | Y0 | Z0) != 0; auto processVertices = [&](u32 _param, u32 _dmemSrcAddr, u32 _dstOffset) { @@ -1909,10 +1909,10 @@ void F5Naboo_GenVertices0C() NabooData & data = getNabooData(); u8* params8 = RDRAM + RSP.PC[RSP.PCi]; u16* params16 = reinterpret_cast(params8); - data.AA = params16[6 ^ 1]; - data.BB = params16[7 ^ 1]; - data.CC = params8[1 ^ 3]; - data.TT = params8[5 ^ 3]; + data.AA = params16[0x6 ^ 1]; + data.BB = params16[0x7 ^ 1]; + data.CC = params8[0x1 ^ 3]; + data.TT = params8[0x5 ^ 3]; data.EE = dmemSrcAddr; data.HH = _SHIFTR(*CAST_DMEM(const u32*, 0xDB8), 16, 16); data.DD = 0; @@ -2114,9 +2114,9 @@ void F5Naboo_GenVertices09() // Step 9 const u16* v0_data = CAST_DMEM(const u16*, 0x128); - const u16 X0 = v0_data[0 ^ 1]; - const u16 Y0 = v0_data[1 ^ 1]; - const u16 Z0 = v0_data[2 ^ 1]; + const u16 X0 = v0_data[0x0 ^ 1]; + const u16 Y0 = v0_data[0x1 ^ 1]; + const u16 Z0 = v0_data[0x2 ^ 1]; const bool needAdjustVertices = (X0 | Y0 | Z0) != 0; auto processVertices = [&](u32 _param, u32 _dmemSrcAddr, u32 _dstOffset) { @@ -2148,10 +2148,10 @@ void F5Naboo_GenVertices09() NabooData & data = getNabooData(); u8* params8 = RDRAM + RSP.PC[RSP.PCi]; u16* params16 = reinterpret_cast(params8); - data.AA = params16[6 ^ 1]; - data.BB = params16[7 ^ 1]; - data.CC = params8[1 ^ 3]; - data.TT = params8[5 ^ 3]; + data.AA = params16[0x6 ^ 1]; + data.BB = params16[0x7 ^ 1]; + data.CC = params8[0x1 ^ 3]; + data.TT = params8[0x5 ^ 3]; data.EE = dmemSrcAddr; data.HH = _SHIFTR(*CAST_DMEM(const u32*, 0xDB8), 16, 16); data.DD = 0;