From 3291cdf978a092dc80dc208804eaa5eac46ebcb5 Mon Sep 17 00:00:00 2001 From: hymei Date: Wed, 23 Feb 2022 20:04:52 +0800 Subject: [PATCH] osx : fix syscalls --- appframework/glmrendererinfo_osx.mm | 14 +++++------ appframework/sdlmgr.cpp | 2 ++ datamodel/clipboardmanager.cpp | 2 +- engine/filesystem_engine.cpp | 1 - engine/sys_mainwind.cpp | 2 +- public/tier0/protected_things.h | 13 +++++----- public/tier1/rangecheckedvar.h | 2 +- public/togl/linuxwin/glfuncs.h | 2 ++ public/togl/rendermechanism.h | 4 ++++ togl/linuxwin/cglmprogram.cpp | 9 +++---- togl/linuxwin/glmgr.cpp | 25 ++++++++++++++----- togl/linuxwin/glmgr_flush.inl | 5 ++-- togl/linuxwin/glmgrbasics.cpp | 4 +++- togl/linuxwin/intelglmallocworkaround.cpp | 29 ++++++++++++++++++++++- vgui2/src/system_posix.cpp | 8 +++++++ vguimatsurface/MatSystemSurface.h | 2 +- 16 files changed, 92 insertions(+), 32 deletions(-) diff --git a/appframework/glmrendererinfo_osx.mm b/appframework/glmrendererinfo_osx.mm index fbaf3150..a36f6249 100644 --- a/appframework/glmrendererinfo_osx.mm +++ b/appframework/glmrendererinfo_osx.mm @@ -206,7 +206,7 @@ GLMRendererInfo::GLMRendererInfo( GLMRendererInfoFields *info ) kCGLPFADoubleBuffer, kCGLPFANoRecovery, kCGLPFAAccelerated, kCGLPFADepthSize, 0, kCGLPFAColorSize, 32, - kCGLPFARendererID, info->m_rendererID, + kCGLPFARendererID, (unsigned int)info->m_rendererID, 0 }; @@ -859,7 +859,7 @@ void GLMDisplayDB::PopulateRenderers( void ) { // grab the OS version - long vMajor = 0; long vMinor = 0; long vMinorMinor = 0; + SInt32 vMajor = 0; SInt32 vMinor = 0; SInt32 vMinorMinor = 0; OSStatus gestalt_err = 0; gestalt_err = Gestalt(gestaltSystemVersionMajor, &vMajor); @@ -1374,7 +1374,7 @@ bool GLMDisplayDB::GetModeInfo( int rendererIndex, int displayIndex, int modeInd { int modeIndex=0; number = (CFNumberRef)CFDictionaryGetValue(curModeDict, kCGDisplayMode); - CFNumberGetValue(number, kCFNumberLongType, &modeIndex); + CFNumberGetValue(number, kCFNumberIntType, &modeIndex); // grab the width and height, I am unclear on whether this is the displayed FB width or the display device width. int screenWidth=0; @@ -1382,11 +1382,11 @@ bool GLMDisplayDB::GetModeInfo( int rendererIndex, int displayIndex, int modeInd int refreshHz=0; number = (CFNumberRef)CFDictionaryGetValue(curModeDict, kCGDisplayWidth); - CFNumberGetValue(number, kCFNumberLongType, &screenWidth); + CFNumberGetValue(number, kCFNumberIntType, &screenWidth); number = (CFNumberRef)CFDictionaryGetValue(curModeDict, kCGDisplayHeight); - CFNumberGetValue(number, kCFNumberLongType, &screenHeight); + CFNumberGetValue(number, kCFNumberIntType, &screenHeight); number = (CFNumberRef)CFDictionaryGetValue(curModeDict, kCGDisplayRefreshRate); - CFNumberGetValue(number, kCFNumberLongType, &refreshHz); + CFNumberGetValue(number, kCFNumberIntType, &refreshHz); GLMPRINTF(( "-D- GLMDisplayDB::GetModeInfo sees mode-index=%d, width=%d, height=%d on CGID %08x (display index %d on rendererindex %d)", modeIndex, @@ -1574,7 +1574,7 @@ void GLMDisplayInfo::PopulateModes( void ) void GLMDisplayInfo::Dump( int which ) { - GLMPRINTF(("\n #%d: GLMDisplayInfo @ %08x, cg-id=%08x display-mask=%08x pixwidth=%d pixheight=%d", which, (int)this, m_info.m_cgDisplayID, m_info.m_glDisplayMask, m_info.m_displayPixelWidth, m_info.m_displayPixelHeight )); + GLMPRINTF(("\n #%d: GLMDisplayInfo @ %08x, cg-id=%08x display-mask=%08x pixwidth=%d pixheight=%d", which, (int)(intp)this, m_info.m_cgDisplayID, m_info.m_glDisplayMask, m_info.m_displayPixelWidth, m_info.m_displayPixelHeight )); FOR_EACH_VEC( *m_modes, i ) { diff --git a/appframework/sdlmgr.cpp b/appframework/sdlmgr.cpp index 20a299c2..e8e5a388 100644 --- a/appframework/sdlmgr.cpp +++ b/appframework/sdlmgr.cpp @@ -19,7 +19,9 @@ #include "tier1/utllinkedlist.h" #include "tier1/convar.h" +#ifdef TOGLES #include +#endif // NOTE: This has to be the last file included! (turned off below, since this is included like a header) #include "tier0/memdbgon.h" diff --git a/datamodel/clipboardmanager.cpp b/datamodel/clipboardmanager.cpp index 5ffa5335..cb2d5a9d 100644 --- a/datamodel/clipboardmanager.cpp +++ b/datamodel/clipboardmanager.cpp @@ -8,7 +8,7 @@ #include "datamodel.h" #include "tier1/KeyValues.h" -#ifndef _LINUX +#ifdef _WIN32 #define USE_WINDOWS_CLIPBOARD #endif diff --git a/engine/filesystem_engine.cpp b/engine/filesystem_engine.cpp index e0944f85..35fd1081 100644 --- a/engine/filesystem_engine.cpp +++ b/engine/filesystem_engine.cpp @@ -8,7 +8,6 @@ #include "quakedef.h" // for MAX_OSPATH #include #include -#include #include "filesystem.h" #include "bitmap/tgawriter.h" #include diff --git a/engine/sys_mainwind.cpp b/engine/sys_mainwind.cpp index f454c2fc..21cb9487 100644 --- a/engine/sys_mainwind.cpp +++ b/engine/sys_mainwind.cpp @@ -1566,7 +1566,7 @@ void *CGame::GetMainWindowPlatformSpecificHandle( void ) #ifdef OSX id nsWindow = (id)pInfo.info.cocoa.window; SEL selector = sel_registerName("windowRef"); - id windowRef = objc_msgSend( nsWindow, selector ); + id windowRef = ((id(*)(id, SEL))objc_msgSend)( nsWindow, selector ); return windowRef; #else // Not used on Linux. diff --git a/public/tier0/protected_things.h b/public/tier0/protected_things.h index 8cbfa929..4d67e377 100644 --- a/public/tier0/protected_things.h +++ b/public/tier0/protected_things.h @@ -144,14 +144,15 @@ #define timeGetTime timeGetTime__USE_VCR_MODE #if defined( clock ) #undef clock - #endif - #define time time__USE_VCR_MODE + #endif + // MoeMod : breaks system header + //#define time time__USE_VCR_MODE - #if defined( recvfrom ) - #undef recvfrom - #endif - #define recvfrom recvfrom__USE_VCR_MODE + //#if defined( recvfrom ) + // #undef recvfrom + //#endif + //#define recvfrom recvfrom__USE_VCR_MODE #if defined( GetCursorPos ) diff --git a/public/tier1/rangecheckedvar.h b/public/tier1/rangecheckedvar.h index 52313f82..258f5fc3 100644 --- a/public/tier1/rangecheckedvar.h +++ b/public/tier1/rangecheckedvar.h @@ -34,7 +34,7 @@ inline void RangeCheck( const T &value, int minValue, int maxValue ) if ( ThreadInMainThread() && g_bDoRangeChecks ) { // Ignore the min/max stuff for now.. just make sure it's not a NAN. - Assert( _finite( value ) ); + Assert( IsFinite( value ) ); } #endif } diff --git a/public/togl/linuxwin/glfuncs.h b/public/togl/linuxwin/glfuncs.h index f543b4af..a141887b 100644 --- a/public/togl/linuxwin/glfuncs.h +++ b/public/togl/linuxwin/glfuncs.h @@ -116,6 +116,8 @@ GL_FUNC_VOID(OpenGL,true,glUniform1iARB,(GLint a,GLint b),(a,b)) GL_FUNC_VOID(OpenGL,true,glUniform4fv,(GLint a,GLsizei b,const GLfloat *c),(a,b,c)) GL_FUNC(OpenGL,true,GLboolean,glUnmapBuffer,(GLenum a),(a)) GL_FUNC_VOID(OpenGL,true,glUseProgram,(GLuint a),(a)) +GL_FUNC_VOID(OpenGL,true,glUseProgramObjectARB,(GLhandleARB a),(a)) +GL_FUNC_VOID(OpenGL,true,glValidateProgramARB,(GLhandleARB a),(a)) GL_FUNC_VOID(OpenGL,true,glVertex3f,(GLfloat a,GLfloat b,GLfloat c),(a,b,c)) GL_FUNC_VOID(OpenGL,true,glVertexAttribPointer,(GLuint a,GLint b,GLenum c,GLboolean d,GLsizei e,const GLvoid *f),(a,b,c,d,e,f)) GL_FUNC_VOID(OpenGL,true,glViewport,(GLint a,GLint b,GLsizei c,GLsizei d),(a,b,c,d)) diff --git a/public/togl/rendermechanism.h b/public/togl/rendermechanism.h index 374ccaa9..252095af 100644 --- a/public/togl/rendermechanism.h +++ b/public/togl/rendermechanism.h @@ -34,8 +34,12 @@ #undef PROTECTED_THINGS_ENABLE +#ifdef OSX +#include +#else #include #include +#endif #include "tier0/basetypes.h" #include "tier0/platform.h" diff --git a/togl/linuxwin/cglmprogram.cpp b/togl/linuxwin/cglmprogram.cpp index 8c0103b3..00109113 100644 --- a/togl/linuxwin/cglmprogram.cpp +++ b/togl/linuxwin/cglmprogram.cpp @@ -157,7 +157,8 @@ CGLMProgram::~CGLMProgram( ) GLMShaderDesc *glslDesc = &m_descs[kGLMGLSL]; if (glslDesc->m_object.glsl) { - gGL->glDeleteShader( (uint)glslDesc->m_object.glsl ); // why do I need a cast here again ? + //gGL->glDeleteShader( (uint)glslDesc->m_object.glsl ); // why do I need a cast here again ? + gGL->glDeleteObjectARB( glslDesc->m_object.glsl ); // because you call the wrong api glslDesc->m_object.glsl = 0; } @@ -814,7 +815,7 @@ void CGLMProgram::LogSlow( EGLMProgramLang lang ) m_type==kGLMVertexProgram ? "VS" : "FS", this, lang==kGLMGLSL ? "GLSL" : "ARB", - (int)(lang==kGLMGLSL ? (int)desc->m_object.glsl : (int)desc->m_object.arb), + (int)(lang==kGLMGLSL ? (intp)desc->m_object.glsl : (int)desc->m_object.arb), m_text ); #endif @@ -828,7 +829,7 @@ void CGLMProgram::LogSlow( EGLMProgramLang lang ) m_type==kGLMVertexProgram ? "VS" : "FS", this, lang==kGLMGLSL ? "GLSL" : "ARB", - (int)(lang==kGLMGLSL ? (int)desc->m_object.glsl : (int)desc->m_object.arb), + (int)(lang==kGLMGLSL ? (intp)desc->m_object.glsl : (int)desc->m_object.arb), desc->m_slowMark+1 ); } @@ -984,7 +985,7 @@ bool CGLMShaderPair::ValidateProgramPair() if (m_valid) { - gGL->glUseProgram( m_program ); + gGL->glUseProgramObjectARB( m_program ); m_ctx->NewLinkedProgram(); diff --git a/togl/linuxwin/glmgr.cpp b/togl/linuxwin/glmgr.cpp index 61fc979d..b97e6cf2 100644 --- a/togl/linuxwin/glmgr.cpp +++ b/togl/linuxwin/glmgr.cpp @@ -670,7 +670,7 @@ void GLMContext::DumpCaps( void ) #define dumpfield_hex( fff ) printf( "\n %-30s : 0x%08x", #fff, (int) m_caps.fff ) #define dumpfield_str( fff ) printf( "\n %-30s : %s", #fff, m_caps.fff ) - printf("\n-------------------------------- context caps for context %08x", (uint)this); + printf("\n-------------------------------- context caps for context %p", this); dumpfield( m_fullscreen ); dumpfield( m_accelerated ); @@ -1745,8 +1745,9 @@ void GLMContext::PreloadTex( CGLMTex *tex, bool force ) } } - gGL->glUseProgram( (GLuint)preloadPair->m_program ); - + gGL->glUseProgramObjectARB( preloadPair->m_program ); + //gGL->glUseProgram( (GLuint)preloadPair->m_program ); + m_pBoundPair = preloadPair; m_bDirtyPrograms = true; @@ -1793,7 +1794,7 @@ void GLMContext::PreloadTex( CGLMTex *tex, bool force ) gGL->glEnableVertexAttribArray( 0 ); - gGL->glVertexAttribPointer( 0, 3, GL_FLOAT, 0, 0, posns ); + gGL->glVertexAttribPointer( 0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), posns ); gGL->glDrawRangeElements( GL_TRIANGLES, 0, 2, 3, GL_UNSIGNED_SHORT, indices); @@ -2701,6 +2702,10 @@ GLMContext::GLMContext( IDirect3DDevice9 *pDevice, GLMDisplayParams *params ) // debug state m_debugFrameIndex = -1; + +#if defined( OSX ) && defined( GLMDEBUG ) + memset( m_boundProgram , 0, sizeof( m_boundProgram ) ); +#endif #if GLMDEBUG // ####################################################################################### @@ -5202,11 +5207,11 @@ void GLMContext::DrawRangeElements(GLenum mode, GLuint start, GLuint end, GLsize if ( pIndexBuf->m_bPseudo ) { // you have to pass actual address, not offset - indicesActual = (void*)( (int)indicesActual + (int)pIndexBuf->m_pPseudoBuf ); + indicesActual = (void*)( (intp)indicesActual + (intp)pIndexBuf->m_pPseudoBuf ); } if (pIndexBuf->m_bUsingPersistentBuffer) { - indicesActual = (void*)( (int)indicesActual + (int)pIndexBuf->m_nPersistentBufferStartOffset ); + indicesActual = (void*)( (intp)indicesActual + (intp)pIndexBuf->m_nPersistentBufferStartOffset ); } #if GLMDEBUG @@ -5244,7 +5249,11 @@ void GLMContext::DrawRangeElements(GLenum mode, GLuint start, GLuint end, GLsize } else { +#if defined( OSX ) + // MoeMod: TOGL IS NOT USING m_boundProgram THIS AT ALL +#else AssertOnce(!"drawing with no vertex program bound"); +#endif } if (m_boundProgram[kGLMFragmentProgram]) @@ -5253,7 +5262,11 @@ void GLMContext::DrawRangeElements(GLenum mode, GLuint start, GLuint end, GLsize } else { +#if defined( OSX ) + // MoeMod: TOGL IS NOT USING m_boundProgram THIS AT ALL +#else AssertOnce(!"drawing with no fragment program bound"); +#endif } #endif diff --git a/togl/linuxwin/glmgr_flush.inl b/togl/linuxwin/glmgr_flush.inl index fcddd616..75325947 100644 --- a/togl/linuxwin/glmgr_flush.inl +++ b/togl/linuxwin/glmgr_flush.inl @@ -196,7 +196,8 @@ FORCEINLINE void GLMContext::FlushDrawStates( uint nStartIndex, uint nEndIndex, } } - gGL->glUseProgram( (GLuint)pNewPair->m_program ); + gGL->glUseProgramObjectARB(pNewPair->m_program); + //gGL->glUseProgram( (GLuint)pNewPair->m_program ); GL_BATCH_PERF( m_FlushStats.m_nTotalProgramPairChanges++; ) @@ -563,7 +564,7 @@ FORCEINLINE void GLMContext::FlushDrawStates( uint nStartIndex, uint nEndIndex, SetBufAndVertexAttribPointer( nIndex, pBuf->GetHandle(), pStream->m_stride, pDeclElem->m_gldecl.m_datatype, pDeclElem->m_gldecl.m_normalized, pDeclElem->m_gldecl.m_nCompCount, - reinterpret_cast< const GLvoid * >( reinterpret_cast< int >( pBuf->m_pPseudoBuf ) + nBufOffset ), + reinterpret_cast< const GLvoid * >( reinterpret_cast< intp >( pBuf->m_pPseudoBuf ) + nBufOffset ), pBuf->m_nRevision ); if ( !( m_lastKnownVertexAttribMask & nMask ) ) diff --git a/togl/linuxwin/glmgrbasics.cpp b/togl/linuxwin/glmgrbasics.cpp index adf60714..7a02f7f3 100644 --- a/togl/linuxwin/glmgrbasics.cpp +++ b/togl/linuxwin/glmgrbasics.cpp @@ -4243,7 +4243,9 @@ CGLMEditableTextItem::~CGLMEditableTextItem( ) if (m_mirror) { - free( m_mirror ); + //free( m_mirror ); + // MoeMod : should be delete here + delete m_mirror; } } diff --git a/togl/linuxwin/intelglmallocworkaround.cpp b/togl/linuxwin/intelglmallocworkaround.cpp index efe0e0ad..a0ab852b 100644 --- a/togl/linuxwin/intelglmallocworkaround.cpp +++ b/togl/linuxwin/intelglmallocworkaround.cpp @@ -27,6 +27,9 @@ // memdbgon -must- be the last include file in a .cpp file. #include "tier0/memdbgon.h" +// MoeMod : ARM Mac doesnt need this workround +#if (defined(__i386__) || defined(__x86_64__)) + IntelGLMallocWorkaround* IntelGLMallocWorkaround::s_pWorkaround = NULL; void *IntelGLMallocWorkaround::ZeroingAlloc(size_t size) @@ -68,4 +71,28 @@ bool IntelGLMallocWorkaround::Enable() } return true; -} \ No newline at end of file +} + +#else +IntelGLMallocWorkaround* IntelGLMallocWorkaround::s_pWorkaround = NULL; + +void *IntelGLMallocWorkaround::ZeroingAlloc(size_t size) +{ + return nullptr; +} + +IntelGLMallocWorkaround* IntelGLMallocWorkaround::Get() +{ + if (!s_pWorkaround) + { + s_pWorkaround = new IntelGLMallocWorkaround(); + } + + return s_pWorkaround; +} + +bool IntelGLMallocWorkaround::Enable() +{ + return true; +} +#endif \ No newline at end of file diff --git a/vgui2/src/system_posix.cpp b/vgui2/src/system_posix.cpp index 251cbb2d..349165b2 100644 --- a/vgui2/src/system_posix.cpp +++ b/vgui2/src/system_posix.cpp @@ -30,6 +30,8 @@ #ifdef OSX #include +#include +#include #elif defined(LINUX) #include #endif @@ -583,8 +585,14 @@ int CSystem::GetAvailableDrives(char *buf, int bufLen) //----------------------------------------------------------------------------- double CSystem::GetFreeDiskSpace(const char *path) { +#if __DARWIN_ONLY_64_BIT_INO_T + // MoeMod: newer macOS only support 64bit, so no statfs64 is provided + struct statfs buf; + int ret = statfs( path, &buf ); +#else struct statfs64 buf; int ret = statfs64( path, &buf ); +#endif if ( ret < 0 ) return 0.0; return (double) ( buf.f_bsize * buf.f_bfree ); diff --git a/vguimatsurface/MatSystemSurface.h b/vguimatsurface/MatSystemSurface.h index 5be5bf3f..33889513 100644 --- a/vguimatsurface/MatSystemSurface.h +++ b/vguimatsurface/MatSystemSurface.h @@ -556,7 +556,7 @@ private: int m_nFullscreenViewportHeight; ITexture *m_pFullscreenRenderTarget; -#ifdef LINUX +#if defined(LINUX) || defined(OSX) struct font_entry { void *data;