From a64b9b63e1283cfe37e366de264f10d9e42ecbdb Mon Sep 17 00:00:00 2001 From: Eugene Golushkov Date: Thu, 13 Feb 2025 19:24:18 +0100 Subject: [PATCH] #define OGRE_CURRENT_FUNCTION => __PRETTY_FUNCTION__ or __FUNCSIG__ or __func__ --- OgreMain/include/OgrePlatform.h | 9 ++++++ .../include/OgreGL3PlusPrerequisites.h | 10 ++----- .../GLES2/include/OgreGLES2Prerequisites.h | 7 ++--- .../Vulkan/include/OgreVulkanPrerequisites.h | 28 ++++++------------- .../Tutorial_VulkanExternal.cpp | 28 ++++++------------- 5 files changed, 31 insertions(+), 51 deletions(-) diff --git a/OgreMain/include/OgrePlatform.h b/OgreMain/include/OgrePlatform.h index 19ddbf8bf47..e96090a2cd1 100644 --- a/OgreMain/include/OgrePlatform.h +++ b/OgreMain/include/OgrePlatform.h @@ -218,6 +218,15 @@ THE SOFTWARE. #define OGRE_QUOTE( x ) OGRE_QUOTE_INPLACE( x ) #define OGRE_WARN( x ) message( __FILE__ "(" QUOTE( __LINE__ ) ") : " x "\n" ) +// portable analog of __PRETTY_FUNCTION__, see also BOOST_CURRENT_FUNCTION +#if OGRE_COMPILER == OGRE_COMPILER_GNUC || OGRE_COMPILER == OGRE_COMPILER_CLANG +# define OGRE_CURRENT_FUNCTION __PRETTY_FUNCTION__ +#elif OGRE_COMPILER == OGRE_COMPILER_MSVC || defined( __FUNCSIG__ ) +# define OGRE_CURRENT_FUNCTION __FUNCSIG__ +#else // C++11 +# define OGRE_CURRENT_FUNCTION __func__ +#endif + // For marking functions as deprecated #if __cplusplus >= 201402L || OGRE_COMPILER == OGRE_COMPILER_MSVC && OGRE_COMP_VER >= 1900 # define OGRE_DEPRECATED [[deprecated]] diff --git a/RenderSystems/GL3Plus/include/OgreGL3PlusPrerequisites.h b/RenderSystems/GL3Plus/include/OgreGL3PlusPrerequisites.h index 3d6e4462488..7088443ef80 100644 --- a/RenderSystems/GL3Plus/include/OgreGL3PlusPrerequisites.h +++ b/RenderSystems/GL3Plus/include/OgreGL3PlusPrerequisites.h @@ -104,10 +104,6 @@ namespace Ogre // Convenience macro from ARB_vertex_buffer_object spec #define GL_BUFFER_OFFSET( i ) reinterpret_cast( ( i ) ) -#if OGRE_COMPILER == OGRE_COMPILER_MSVC -# define __PRETTY_FUNCTION__ __FUNCTION__ -#endif - #define ENABLE_GL_CHECK 0 #if ENABLE_GL_CHECK # include "OgreStringVector.h" @@ -141,7 +137,7 @@ namespace Ogre char msgBuf[4096]; \ StringVector tokens = StringUtil::split( #glFunc, "(" ); \ sprintf( msgBuf, "OpenGL error 0x%04X %s in %s at line %i for %s\n", e, errorString, \ - __PRETTY_FUNCTION__, __LINE__, tokens[0].c_str() ); \ + OGRE_CURRENT_FUNCTION, __LINE__, tokens[0].c_str() ); \ LogManager::getSingleton().logMessage( msgBuf, LML_CRITICAL ); \ } \ } @@ -152,10 +148,10 @@ namespace Ogre if( ( e != 0 ) && ( e != EGL_SUCCESS ) ) \ { \ char msgBuf[4096]; \ - sprintf( msgBuf, "EGL error 0x%04X in %s at line %i\n", e, __PRETTY_FUNCTION__, \ + sprintf( msgBuf, "EGL error 0x%04X in %s at line %i\n", e, OGRE_CURRENT_FUNCTION, \ __LINE__ ); \ LogManager::getSingleton().logMessage( msgBuf ); \ - OGRE_EXCEPT( Exception::ERR_INTERNAL_ERROR, msgBuf, __PRETTY_FUNCTION__ ); \ + OGRE_EXCEPT( Exception::ERR_INTERNAL_ERROR, msgBuf, OGRE_CURRENT_FUNCTION ); \ } \ } #else diff --git a/RenderSystems/GLES2/include/OgreGLES2Prerequisites.h b/RenderSystems/GLES2/include/OgreGLES2Prerequisites.h index dff23107974..2a00666093a 100644 --- a/RenderSystems/GLES2/include/OgreGLES2Prerequisites.h +++ b/RenderSystems/GLES2/include/OgreGLES2Prerequisites.h @@ -69,7 +69,6 @@ THE SOFTWARE. #else # if (OGRE_PLATFORM == OGRE_PLATFORM_WIN32) # if !defined( __MINGW32__ ) -# define __PRETTY_FUNCTION__ __FUNCTION__ # ifndef WIN32_LEAN_AND_MEAN # define WIN32_LEAN_AND_MEAN 1 # endif @@ -309,7 +308,7 @@ namespace Ogre { } \ char msgBuf[4096]; \ StringVector tokens = StringUtil::split(#glFunc, "("); \ - sprintf(msgBuf, "OpenGL error 0x%04X %s in %s at line %i for %s\n", e, errorString, __PRETTY_FUNCTION__, __LINE__, tokens[0].c_str()); \ + sprintf(msgBuf, "OpenGL error 0x%04X %s in %s at line %i for %s\n", e, errorString, OGRE_CURRENT_FUNCTION, __LINE__, tokens[0].c_str()); \ LogManager::getSingleton().logMessage(msgBuf); \ } \ } @@ -326,9 +325,9 @@ namespace Ogre { if ((e != 0) && (e != EGL_SUCCESS))\ { \ char msgBuf[4096]; \ - sprintf(msgBuf, "EGL error 0x%04X in %s at line %i\n", e, __PRETTY_FUNCTION__, __LINE__); \ + sprintf(msgBuf, "EGL error 0x%04X in %s at line %i\n", e, OGRE_CURRENT_FUNCTION, __LINE__); \ LogManager::getSingleton().logMessage(msgBuf); \ - OGRE_EXCEPT(Exception::ERR_INTERNAL_ERROR, msgBuf, __PRETTY_FUNCTION__); \ + OGRE_EXCEPT(Exception::ERR_INTERNAL_ERROR, msgBuf, OGRE_CURRENT_FUNCTION); \ } \ } #else diff --git a/RenderSystems/Vulkan/include/OgreVulkanPrerequisites.h b/RenderSystems/Vulkan/include/OgreVulkanPrerequisites.h index 21855c2d6cc..9ce3d4aa776 100644 --- a/RenderSystems/Vulkan/include/OgreVulkanPrerequisites.h +++ b/RenderSystems/Vulkan/include/OgreVulkanPrerequisites.h @@ -151,27 +151,15 @@ namespace Ogre const char *file, long line ); } // namespace Ogre -#if OGRE_COMPILER == OGRE_COMPILER_MSVC -# define checkVkResult( device, result, functionName ) \ - do \ +#define checkVkResult( device, result, functionName ) \ + do \ + { \ + if( result != VK_SUCCESS ) \ { \ - if( result != VK_SUCCESS ) \ - { \ - onVulkanFailure( device, result, functionName " failed", __FUNCSIG__, __FILE__, \ - __LINE__ ); \ - } \ - } while( 0 ) -#else -# define checkVkResult( device, result, functionName ) \ - do \ - { \ - if( result != VK_SUCCESS ) \ - { \ - onVulkanFailure( device, result, functionName " failed", __PRETTY_FUNCTION__, __FILE__, \ - __LINE__ ); \ - } \ - } while( 0 ) -#endif + onVulkanFailure( device, result, functionName " failed", OGRE_CURRENT_FUNCTION, __FILE__, \ + __LINE__ ); \ + } \ + } while( 0 ) #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32 # if !defined( __MINGW32__ ) diff --git a/Samples/2.0/Tutorials/Tutorial_VulkanExternal/Tutorial_VulkanExternal.cpp b/Samples/2.0/Tutorials/Tutorial_VulkanExternal/Tutorial_VulkanExternal.cpp index 904b8f4ca63..08663f4c2ba 100644 --- a/Samples/2.0/Tutorials/Tutorial_VulkanExternal/Tutorial_VulkanExternal.cpp +++ b/Samples/2.0/Tutorials/Tutorial_VulkanExternal/Tutorial_VulkanExternal.cpp @@ -38,27 +38,15 @@ #define MY_VK_EXCEPT( code, num, desc, src ) \ OGRE_EXCEPT( code, desc + ( "\nVkResult = " + std::to_string( num ) ), src ) -#if OGRE_COMPILER == OGRE_COMPILER_MSVC -# define myCheckVkResult( result, functionName ) \ - do \ +#define myCheckVkResult( result, functionName ) \ + do \ + { \ + if( result != VK_SUCCESS ) \ { \ - if( result != VK_SUCCESS ) \ - { \ - MY_VK_EXCEPT( Exception::ERR_RENDERINGAPI_ERROR, result, functionName " failed", \ - __FUNCSIG__ ); \ - } \ - } while( 0 ) -#else -# define myCheckVkResult( result, functionName ) \ - do \ - { \ - if( result != VK_SUCCESS ) \ - { \ - MY_VK_EXCEPT( Exception::ERR_RENDERINGAPI_ERROR, result, functionName " failed", \ - __PRETTY_FUNCTION__ ); \ - } \ - } while( 0 ) -#endif + MY_VK_EXCEPT( Exception::ERR_RENDERINGAPI_ERROR, result, functionName " failed", \ + OGRE_CURRENT_FUNCTION ); \ + } \ + } while( 0 ) /** @brief createVulkanInstance