From f306caa55b20e873623e58c470b72bb94d105777 Mon Sep 17 00:00:00 2001 From: Rosalie Wanders Date: Fri, 24 May 2024 12:24:18 +0200 Subject: [PATCH] 3rdParty: apply pending patches for mupen64plus-video-GLideN64 --- .../mupen64plus-video-GLideN64/src/Log.cpp | 50 +++++++++++++++++++ .../src/MupenPlusPluginAPI.cpp | 2 +- .../src/PluginAPI.h | 2 +- .../src/Textures.cpp | 4 +- .../src/mupenplus/GLideN64_mupenplus.h | 4 ++ .../src/mupenplus/MupenPlusAPIImpl.cpp | 10 +++- 6 files changed, 65 insertions(+), 7 deletions(-) diff --git a/Source/3rdParty/mupen64plus-video-GLideN64/src/Log.cpp b/Source/3rdParty/mupen64plus-video-GLideN64/src/Log.cpp index 557fc798..94235187 100644 --- a/Source/3rdParty/mupen64plus-video-GLideN64/src/Log.cpp +++ b/Source/3rdParty/mupen64plus-video-GLideN64/src/Log.cpp @@ -13,6 +13,8 @@ #include #include +#ifndef MUPENPLUSAPI // zilmar spec + std::mutex g_logMutex; std::wofstream fileOutput; @@ -113,6 +115,54 @@ void LogDebug(const char* _fileName, int _line, u16 _type, const char* _format, fileOutput.flush(); } +#else // mupen64plus +#include "mupenplus/GLideN64_mupenplus.h" + +void LogDebug(const char* _fileName, int _line, u16 _type, const char* _format, ...) +{ + static const int logLevel[] = { + M64MSG_INFO, + M64MSG_ERROR, + M64MSG_INFO, + M64MSG_WARNING, + M64MSG_VERBOSE, + M64MSG_VERBOSE + }; + + if (CoreDebugCallback == nullptr || + _type > LOG_LEVEL) + { + return; + } + + // initialize use of the variable argument array + va_list vaArgs; + va_start(vaArgs, _format); + + // reliably acquire the size from a copy of + // the variable argument array + // and a functionally reliable call + // to mock the formatting + va_list vaCopy; + va_copy(vaCopy, vaArgs); + const int iLen = std::vsnprintf(NULL, 0, _format, vaCopy); + va_end(vaCopy); + + // return a formatted string without + // risking memory mismanagement + // and without assuming any compiler + // or platform specific behavior + std::vector zc(iLen + 1); + std::vsnprintf(zc.data(), zc.size(), _format, vaArgs); + va_end(vaArgs); + + std::stringstream formatString; + formatString << _fileName << ":" << _line << ", \"" << zc.data() << "\""; + + CoreDebugCallback(CoreDebugCallbackContext, logLevel[_type], formatString.str().c_str()); +} +#endif + #if defined(OS_WINDOWS) && !defined(MINGW) #include "windows/GLideN64_windows.h" void debugPrint(const char * format, ...) { diff --git a/Source/3rdParty/mupen64plus-video-GLideN64/src/MupenPlusPluginAPI.cpp b/Source/3rdParty/mupen64plus-video-GLideN64/src/MupenPlusPluginAPI.cpp index ea777917..01a09902 100644 --- a/Source/3rdParty/mupen64plus-video-GLideN64/src/MupenPlusPluginAPI.cpp +++ b/Source/3rdParty/mupen64plus-video-GLideN64/src/MupenPlusPluginAPI.cpp @@ -32,7 +32,7 @@ EXPORT m64p_error CALL PluginStartup( void (*DebugCallback)(void *, int, const char *) ) { - return api().PluginStartup(CoreLibHandle); + return api().PluginStartup(CoreLibHandle, Context, DebugCallback); } #ifdef M64P_GLIDENUI diff --git a/Source/3rdParty/mupen64plus-video-GLideN64/src/PluginAPI.h b/Source/3rdParty/mupen64plus-video-GLideN64/src/PluginAPI.h index cc6e222e..896c5a29 100644 --- a/Source/3rdParty/mupen64plus-video-GLideN64/src/PluginAPI.h +++ b/Source/3rdParty/mupen64plus-video-GLideN64/src/PluginAPI.h @@ -76,7 +76,7 @@ class PluginAPI void ResizeVideoOutput(int _Width, int _Height); void ReadScreen2(void * _dest, int * _width, int * _height, int _front); - m64p_error PluginStartup(m64p_dynlib_handle _CoreLibHandle); + m64p_error PluginStartup(m64p_dynlib_handle _CoreLibHandle, void * Context, void (*DebugCallback)(void *, int, const char *)); #ifdef M64P_GLIDENUI m64p_error PluginConfig(); #endif // M64P_GLIDENUI diff --git a/Source/3rdParty/mupen64plus-video-GLideN64/src/Textures.cpp b/Source/3rdParty/mupen64plus-video-GLideN64/src/Textures.cpp index 4d4c91a9..753aee98 100644 --- a/Source/3rdParty/mupen64plus-video-GLideN64/src/Textures.cpp +++ b/Source/3rdParty/mupen64plus-video-GLideN64/src/Textures.cpp @@ -1226,10 +1226,8 @@ bool TextureCache::_loadHiresTexture(u32 _tile, CachedTexture *_pTexture, u64 & GHQTexInfo ghqTexInfo; // TODO: fix problem with zero texture dimensions on GLideNHQ side. auto hirestexFound = txfilter_hirestex(_pTexture->crc, _ricecrc, palette, N64FormatSize(_pTexture->format, _pTexture->size), &ghqTexInfo); - if (!hirestexFound) { + if (!hirestexFound && _strongcrc != 0U) { // Texture with RiceCRC was not found. Try alternative CRC. - if (_strongcrc == 0U) - _strongcrc = txfilter_checksum_strong(addr, width, height, _pTexture->size, bpl, paladdr); hirestexFound = txfilter_hirestex(_pTexture->crc, _strongcrc, palette, N64FormatSize(_pTexture->format, _pTexture->size), &ghqTexInfo); } if (hirestexFound && ghqTexInfo.width != 0 && ghqTexInfo.height != 0) { diff --git a/Source/3rdParty/mupen64plus-video-GLideN64/src/mupenplus/GLideN64_mupenplus.h b/Source/3rdParty/mupen64plus-video-GLideN64/src/mupenplus/GLideN64_mupenplus.h index c925d152..ba4bb168 100644 --- a/Source/3rdParty/mupen64plus-video-GLideN64/src/mupenplus/GLideN64_mupenplus.h +++ b/Source/3rdParty/mupen64plus-video-GLideN64/src/mupenplus/GLideN64_mupenplus.h @@ -4,6 +4,7 @@ #include "m64p_common.h" #include "m64p_config.h" #include "m64p_vidext.h" +#include "m64p_frontend.h" #define PLUGIN_VERSION 0x020000 #define VIDEO_PLUGIN_API_VERSION 0x020200 @@ -53,6 +54,9 @@ extern ptr_VidExt_GL_GetDefaultFramebuffer CoreVideo_GL_GetDefaultFramebuffer; extern ptr_PluginGetVersion CoreGetVersion; +extern void* CoreDebugCallbackContext; +extern ptr_DebugCallback CoreDebugCallback; + extern const unsigned int* rdram_size; extern void(*renderCallback)(int); diff --git a/Source/3rdParty/mupen64plus-video-GLideN64/src/mupenplus/MupenPlusAPIImpl.cpp b/Source/3rdParty/mupen64plus-video-GLideN64/src/mupenplus/MupenPlusAPIImpl.cpp index f814d389..d1835c9d 100644 --- a/Source/3rdParty/mupen64plus-video-GLideN64/src/mupenplus/MupenPlusAPIImpl.cpp +++ b/Source/3rdParty/mupen64plus-video-GLideN64/src/mupenplus/MupenPlusAPIImpl.cpp @@ -49,12 +49,18 @@ ptr_VidExt_GL_GetDefaultFramebuffer CoreVideo_GL_GetDefaultFramebuffer = nullptr ptr_PluginGetVersion CoreGetVersion = nullptr; +void* CoreDebugCallbackContext = nullptr; +ptr_DebugCallback CoreDebugCallback = nullptr; + const unsigned int* rdram_size = nullptr; -void(*renderCallback)(int) = nullptr; +void (*renderCallback)(int) = nullptr; -m64p_error PluginAPI::PluginStartup(m64p_dynlib_handle _CoreLibHandle) +m64p_error PluginAPI::PluginStartup(m64p_dynlib_handle _CoreLibHandle, void* Context, void (*DebugCallback)(void *, int, const char *)) { + CoreDebugCallbackContext = Context; + CoreDebugCallback = DebugCallback; + ConfigGetSharedDataFilepath = (ptr_ConfigGetSharedDataFilepath) DLSYM(_CoreLibHandle, "ConfigGetSharedDataFilepath"); ConfigGetUserConfigPath = (ptr_ConfigGetUserConfigPath) DLSYM(_CoreLibHandle, "ConfigGetUserConfigPath"); ConfigGetUserCachePath = (ptr_ConfigGetUserCachePath)DLSYM(_CoreLibHandle, "ConfigGetUserCachePath");