From 1f3b4583dad36fa78d2c499c9575482f17a29b19 Mon Sep 17 00:00:00 2001 From: exstrim401 Date: Sun, 20 Nov 2022 15:00:44 +0200 Subject: [PATCH] macOS build support --- appframework/wscript | 6 +- engine/host_saverestore.cpp | 2 +- engine/wscript | 15 +- filesystem/filesystem_async.cpp | 2 +- game/client/particlemgr.cpp | 2 +- launcher/wscript | 2 + materialsystem/cmaterialsystem.cpp | 2 +- mathlib/3dnow.cpp | 2 +- public/tier0/platform.h | 2 +- public/togl/linuxwin/cglmtex.h | 6 +- public/togl/linuxwin/glfuncs.h | 2 +- public/togl/linuxwin/glmgr.h | 4 +- public/togles/linuxwin/glfuncs.h | 2 +- public/togles/linuxwin/glmgr.h | 4 +- public/vstdlib/jobthread.h | 2 +- replay/shared_replaycontext.cpp | 2 +- scripts/waifulib/compiler_optimizations.py | 3 +- tier0/dbg.cpp | 2 +- tier1/mempool.cpp | 4 + tier1/wscript | 2 + togl/linuxwin/cglmtex.cpp | 186 ++++++++------------- togl/linuxwin/dxabstract.cpp | 12 +- togl/linuxwin/glmgr.cpp | 4 +- togl/wscript | 10 +- togles/linuxwin/dxabstract.cpp | 2 +- togles/linuxwin/glmgr.cpp | 4 +- togles/wscript | 7 +- utils/vtex/vtex.cpp | 4 + vgui2/src/wscript | 2 + video/wscript | 2 + vstdlib/jobthread.cpp | 2 +- vstdlib/wscript | 2 + wscript | 40 ++++- 33 files changed, 190 insertions(+), 155 deletions(-) diff --git a/appframework/wscript b/appframework/wscript index 29822a4b..f8a11243 100755 --- a/appframework/wscript +++ b/appframework/wscript @@ -18,13 +18,17 @@ def build(bld): source = [ 'AppSystemGroup.cpp', '../public/filesystem_init.cpp', -# 'glmrendererinfo_osx.mm' [$OSXALL] ] if bld.env.SDL: source += [ 'sdlmgr.cpp' ] + + if bld.env.DEST_OS == 'darwin': + source += [ + 'glmrendererinfo_osx.mm' + ] if bld.env.DEST_OS == 'win32': source += [ diff --git a/engine/host_saverestore.cpp b/engine/host_saverestore.cpp index 6e1afa9f..881044f4 100644 --- a/engine/host_saverestore.cpp +++ b/engine/host_saverestore.cpp @@ -3286,7 +3286,7 @@ void CSaveRestore::Init( void ) threadPoolStartParams.bUseAffinityTable = true; } - g_pSaveThread = CreateThreadPool(); + g_pSaveThread = CreateThreadPool1(); g_pSaveThread->Start( threadPoolStartParams, "SaveJob" ); } diff --git a/engine/wscript b/engine/wscript index ba8e6c25..ddeb8276 100755 --- a/engine/wscript +++ b/engine/wscript @@ -15,6 +15,9 @@ def configure(conf): if conf.options.DEDICATED: conf.define('SWDS', 1) conf.define('NO_STEAM', 1) + else: + if conf.env.DEST_OS == 'darwin': + conf.define('HAVE_OPENAL', 1) conf.env.append_unique('DEFINES',[ '__USEA3D', @@ -204,9 +207,17 @@ def build(bld): if bld.env.SDL: source += [ - 'audio/snd_dev_sdl.cpp', #[$SDL && !$OSXALL] 'audio/voice_record_sdl.cpp' #[$OSXALL||$LINUXALL] ] + if bld.env.DEST_OS != "darwin": + source += ['audio/snd_dev_sdl.cpp'] + + if bld.env.DEST_OS == 'darwin': + source += [ + 'audio/snd_dev_openal.cpp', # [$OSXALL] + 'audio/snd_dev_mac_audioqueue.cpp',# [$OSXALL] + 'audio/voice_record_mac_audioqueue.cpp', #[$OSXALL] + ] if bld.env.DEST_OS == 'win32': source += [ @@ -352,6 +363,8 @@ def build(bld): libs += ['SSL', 'CRYPTO'] # android curl was built with openssl elif bld.env.DEST_OS == 'win32': libs += ['USER32', 'WINMM', 'WININET', 'DSOUND', 'DXGUID', 'GDI32', 'bzip2'] + elif bld.env.DEST_OS == 'darwin': + libs += ['COREAUDIO', 'AUDIOTOOLBOX', 'SYSTEMCONFIGURATION'] install_path = bld.env.LIBDIR diff --git a/filesystem/filesystem_async.cpp b/filesystem/filesystem_async.cpp index adce661c..2b164ac0 100644 --- a/filesystem/filesystem_async.cpp +++ b/filesystem/filesystem_async.cpp @@ -663,7 +663,7 @@ void CBaseFileSystem::InitAsync() if ( VCRGetMode() == VCR_Disabled ) { // create the i/o thread pool - m_pThreadPool = CreateThreadPool(); + m_pThreadPool = CreateThreadPool1(); ThreadPoolStartParams_t params; params.iThreadPriority = 0; diff --git a/game/client/particlemgr.cpp b/game/client/particlemgr.cpp index 246a8a78..8b203e4c 100644 --- a/game/client/particlemgr.cpp +++ b/game/client/particlemgr.cpp @@ -1087,7 +1087,7 @@ bool CParticleMgr::Init(unsigned long count, IMaterialSystem *pMaterials) if ( IsX360() ) { //m_pThreadPool[0] = CreateThreadPool(); - m_pThreadPool[1] = CreateThreadPool(); + m_pThreadPool[1] = CreateThreadPool1(); ThreadPoolStartParams_t startParams; startParams.nThreads = 3; diff --git a/launcher/wscript b/launcher/wscript index 8bd7dad3..84292b63 100755 --- a/launcher/wscript +++ b/launcher/wscript @@ -45,6 +45,8 @@ def build(bld): if bld.env.DEST_OS == 'win32': libs += ['USER32', 'OLE32', 'SHELL32'] + elif bld.env.DEST_OS == 'darwin': + libs += ['FOUNDATION', 'APPKIT', 'IOKIT'] install_path = bld.env.LIBDIR diff --git a/materialsystem/cmaterialsystem.cpp b/materialsystem/cmaterialsystem.cpp index a3c1c233..bab51f3b 100644 --- a/materialsystem/cmaterialsystem.cpp +++ b/materialsystem/cmaterialsystem.cpp @@ -3567,7 +3567,7 @@ IThreadPool *CMaterialSystem::CreateMatQueueThreadPool() // that only the threadpool threads should execute these jobs. startParams.bExecOnThreadPoolThreadsOnly = true; - m_pMatQueueThreadPool = CreateThreadPool(); + m_pMatQueueThreadPool = CreateThreadPool1(); m_pMatQueueThreadPool->Start( startParams, "MatQueue" ); } diff --git a/mathlib/3dnow.cpp b/mathlib/3dnow.cpp index db17c8c1..a37d9bdd 100644 --- a/mathlib/3dnow.cpp +++ b/mathlib/3dnow.cpp @@ -16,7 +16,7 @@ // memdbgon must be the last include file in a .cpp file!!! #include "tier0/memdbgon.h" -#if !defined(COMPILER_MSVC64) && !defined(LINUX) +#if !defined(COMPILER_MSVC64) && !defined(LINUX) && !defined(OSX) // Implement for 64-bit Windows if needed. // Clang hits "fatal error: error in backend:" and other errors when trying // to compile the inline assembly below. 3DNow support is highly unlikely to diff --git a/public/tier0/platform.h b/public/tier0/platform.h index 07a3d661..2ae632b8 100644 --- a/public/tier0/platform.h +++ b/public/tier0/platform.h @@ -1038,7 +1038,7 @@ inline T QWordSwapC( T dw ) // The typically used methods. //------------------------------------- -#if (defined(__i386__) || defined(__amd64__) || (defined(__arm__) && defined(ANDROID))) && !defined(VALVE_LITTLE_ENDIAN) +#if (defined(__i386__) || defined(__amd64__) || defined(__arm__) || defined(__aarch64__)) && !defined(VALVE_LITTLE_ENDIAN) #define VALVE_LITTLE_ENDIAN 1 #endif diff --git a/public/togl/linuxwin/cglmtex.h b/public/togl/linuxwin/cglmtex.h index 7c1e4172..55321316 100644 --- a/public/togl/linuxwin/cglmtex.h +++ b/public/togl/linuxwin/cglmtex.h @@ -126,7 +126,6 @@ enum EGLMTexFlags kGLMTexMultisampled = 0x40, // has an RBO backing it. Cannot combine with Mipped, MippedAuto. One slice maximum, only targeting GL_TEXTURE_2D. // actually not 100% positive on the mipmapping, the RBO itself can't be mipped, but the resulting texture could // have mipmaps generated. - kGLMTexDynamic = 0x80 }; //=============================================================================== @@ -205,7 +204,6 @@ struct GLMTexLockParams // tells GLM to force re-read of the texels back from GL // i.e. "I know I stepped on those texels with a draw or blit - the GLM copy is stale" bool m_readback; - bool m_readonly; }; struct GLMTexLockDesc @@ -487,7 +485,7 @@ protected: int CalcSliceIndex( int face, int mip ); void CalcTexelDataOffsetAndStrides( int sliceIndex, int x, int y, int z, int *offsetOut, int *yStrideOut, int *zStrideOut ); - GLubyte *ReadTexels( GLMTexLockDesc *desc, bool readWholeSlice=true, bool readOnly=false ); + void ReadTexels( GLMTexLockDesc *desc, bool readWholeSlice=true ); void WriteTexels( GLMTexLockDesc *desc, bool writeWholeSlice=true, bool noDataWrite=false ); // last param lets us send NULL data ptr (only legal with uncompressed formats, beware) // this helps out ResetSRGB. @@ -507,8 +505,6 @@ protected: // noWrite means send NULL for texel source addresses instead of actual data - ideal for RT's GLuint m_texName; // name of this texture in the context - GLuint m_pbo; - GLubyte *m_mapped; GLenum m_texGLTarget; uint m_nSamplerType; // SAMPLER_2D, etc. diff --git a/public/togl/linuxwin/glfuncs.h b/public/togl/linuxwin/glfuncs.h index a141887b..2a69416f 100644 --- a/public/togl/linuxwin/glfuncs.h +++ b/public/togl/linuxwin/glfuncs.h @@ -63,7 +63,7 @@ GL_FUNC_VOID(OpenGL,true,glDrawArrays,(GLenum a,GLint b,GLsizei c),(a,b,c)) GL_FUNC_VOID(OpenGL,true,glDrawBuffer,(GLenum a),(a)) GL_FUNC_VOID(OpenGL,true,glDrawBuffers,(GLsizei a,const GLenum *b),(a,b)) GL_FUNC_VOID(OpenGL,true,glDrawRangeElements,(GLenum a,GLuint b,GLuint c,GLsizei d,GLenum e,const GLvoid *f),(a,b,c,d,e,f)) -#ifndef OSX // 10.6/GL 2.1 compatability +#if 1 //ifndef OSX // 10.6/GL 2.1 compatability GL_FUNC_VOID(OpenGL,true,glDrawRangeElementsBaseVertex,(GLenum a,GLuint b,GLuint c,GLsizei d,GLenum e,const GLvoid *f, GLenum g),(a,b,c,d,e,f,g)) #endif GL_FUNC_VOID(OpenGL,true,glEnable,(GLenum a),(a)) diff --git a/public/togl/linuxwin/glmgr.h b/public/togl/linuxwin/glmgr.h index 8cde5a92..a81ca036 100644 --- a/public/togl/linuxwin/glmgr.h +++ b/public/togl/linuxwin/glmgr.h @@ -1451,7 +1451,7 @@ class GLMContext void FlushDrawStatesNoShaders(); // drawing -#ifndef OSX +#if 1 //ifndef OSX FORCEINLINE void DrawRangeElements( GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices, uint baseVertex, CGLMBuffer *pIndexBuf ); void DrawRangeElementsNonInline( GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices, uint baseVertex, CGLMBuffer *pIndexBuf ); #else @@ -1911,7 +1911,7 @@ class GLMContext CTSQueue m_DeleteTextureQueue; }; -#ifndef OSX +#if 1 //ifndef OSX FORCEINLINE void GLMContext::DrawRangeElements( GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices, uint baseVertex, CGLMBuffer *pIndexBuf ) { diff --git a/public/togles/linuxwin/glfuncs.h b/public/togles/linuxwin/glfuncs.h index a8046ef9..b7b9bad0 100644 --- a/public/togles/linuxwin/glfuncs.h +++ b/public/togles/linuxwin/glfuncs.h @@ -66,7 +66,7 @@ GL_FUNC_VOID(OpenGL,true,glWaitSync,(GLsync a, GLbitfield b, GLuint64 c),(a,b,c) GL_FUNC_VOID(OpenGL,true,glDeleteSync,(GLsync a),(a)) GL_FUNC(OpenGL,true,GLsync,glFenceSync,(GLenum a, GLbitfield b),(a,b)) -#ifndef OSX // 10.6/GL 2.1 compatability +#if 1 //ifndef OSX // 10.6/GL 2.1 compatability GL_FUNC_VOID(OpenGL,true,glDrawRangeElementsBaseVertex,(GLenum a,GLuint b,GLuint c,GLsizei d,GLenum e,const GLvoid *f, GLenum g),(a,b,c,d,e,f,g)) #endif GL_FUNC_VOID(OpenGL,true,glEnable,(GLenum a),(a)) diff --git a/public/togles/linuxwin/glmgr.h b/public/togles/linuxwin/glmgr.h index cd02464f..111d8501 100644 --- a/public/togles/linuxwin/glmgr.h +++ b/public/togles/linuxwin/glmgr.h @@ -1365,7 +1365,7 @@ class GLMContext void FlushDrawStatesNoShaders(); // drawing -#ifndef OSX +#if 1 //ifndef OSX FORCEINLINE void DrawRangeElements( GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices, uint baseVertex, CGLMBuffer *pIndexBuf ); void DrawRangeElementsNonInline( GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices, uint baseVertex, CGLMBuffer *pIndexBuf ); #else @@ -1815,7 +1815,7 @@ class GLMContext CTSQueue m_DeleteTextureQueue; }; -#ifndef OSX +#if 1 //ifndef OSX FORCEINLINE void GLMContext::DrawRangeElements( GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices, uint baseVertex, CGLMBuffer *pIndexBuf ) { diff --git a/public/vstdlib/jobthread.h b/public/vstdlib/jobthread.h index 05798a2c..bfc06e6f 100644 --- a/public/vstdlib/jobthread.h +++ b/public/vstdlib/jobthread.h @@ -419,7 +419,7 @@ public: //----------------------------------------------------------------------------- -JOB_INTERFACE IThreadPool *CreateThreadPool(); +JOB_INTERFACE IThreadPool *CreateThreadPool1(); JOB_INTERFACE void DestroyThreadPool( IThreadPool *pPool ); //------------------------------------- diff --git a/replay/shared_replaycontext.cpp b/replay/shared_replaycontext.cpp index 3199c3d9..20551c1d 100644 --- a/replay/shared_replaycontext.cpp +++ b/replay/shared_replaycontext.cpp @@ -75,7 +75,7 @@ bool CSharedReplayContext::InitThreadPool() { // Create thread pool Log( "Replay: Creating thread pool..." ); - IThreadPool *pThreadPool = CreateThreadPool(); + IThreadPool *pThreadPool = CreateThreadPool1(); if ( !pThreadPool ) { Log( "failed!\n" ); diff --git a/scripts/waifulib/compiler_optimizations.py b/scripts/waifulib/compiler_optimizations.py index 94f10ae9..c2a6841d 100644 --- a/scripts/waifulib/compiler_optimizations.py +++ b/scripts/waifulib/compiler_optimizations.py @@ -35,6 +35,7 @@ VALID_BUILD_TYPES = ['fastnative', 'fast', 'release', 'debug', 'nooptimize', 'sa LINKFLAGS = { 'common': { 'msvc': ['/DEBUG'], # always create PDB, doesn't affect result binaries + 'clang': ['-fvisibility=hidden'], 'gcc': ['-Wl,--no-undefined'], 'owcc': ['-Wl,option stack=512k', '-fvisibility=hidden'] }, @@ -48,7 +49,7 @@ CFLAGS = { 'common': { # disable thread-safe local static initialization for C++11 code, as it cause crashes on Windows XP 'msvc': ['/D_USING_V110_SDK71_', '/Zi', '/FS', '/Zc:threadSafeInit-'], - 'clang': ['-fno-strict-aliasing'], + 'clang': ['-fno-strict-aliasing', '-fvisibility=hidden'], 'gcc': ['-g0', '-fno-strict-aliasing', '-fvisibility=hidden'], 'owcc': ['-fno-short-enum', '-ffloat-store', '-g0'] }, diff --git a/tier0/dbg.cpp b/tier0/dbg.cpp index 519a0f05..84da0471 100644 --- a/tier0/dbg.cpp +++ b/tier0/dbg.cpp @@ -439,7 +439,7 @@ static SpewRetval_t _SpewMessage( SpewType_t spewType, const char *pGroupName, i /* direct it to the appropriate target(s) */ SpewRetval_t ret; - assert( g_pSpewInfo == (void*)NULL ); + assert( (void*)g_pSpewInfo == (void*)NULL ); SpewInfo_t spewInfo = { pColor, diff --git a/tier1/mempool.cpp b/tier1/mempool.cpp index fcfb22f7..9260b90f 100644 --- a/tier1/mempool.cpp +++ b/tier1/mempool.cpp @@ -12,8 +12,12 @@ #include "tier1/strtools.h" #ifndef _PS3 +#ifdef _OSX +#include +#else #include #endif +#endif // Should be last include #include "tier0/memdbgon.h" diff --git a/tier1/wscript b/tier1/wscript index 66c29ae4..0a5f684b 100755 --- a/tier1/wscript +++ b/tier1/wscript @@ -84,6 +84,8 @@ def build(bld): libs = [] if bld.env.DEST_OS == 'win32': libs += ['RPCRT4'] + elif bld.env.DEST_OS == "darwin": + libs += ['ICONV'] bld.stlib( source = source, diff --git a/togl/linuxwin/cglmtex.cpp b/togl/linuxwin/cglmtex.cpp index 54ceb48e..30eb9e46 100644 --- a/togl/linuxwin/cglmtex.cpp +++ b/togl/linuxwin/cglmtex.cpp @@ -763,17 +763,6 @@ CGLMTex::CGLMTex( GLMContext *ctx, GLMTexLayout *layout, uint levels, const char m_pBlitSrcFBO = NULL; m_pBlitDstFBO = NULL; - m_mapped = NULL; - m_pbo = 0; - - if( m_layout->m_key.m_texFlags & kGLMTexDynamic ) - { - gGL->glGenBuffersARB(1, &m_pbo); - gGL->glBindBufferARB(GL_PIXEL_UNPACK_BUFFER, m_pbo); - gGL->glBufferDataARB(GL_PIXEL_UNPACK_BUFFER, m_layout->m_storageTotalSize, 0, GL_STATIC_DRAW); - gGL->glBindBufferARB(GL_PIXEL_UNPACK_BUFFER, 0); - } - // Sense whether to try and apply client storage upon teximage/subimage. // This should only be true if we're running on OSX 10.6 or it was explicitly // enabled with -gl_texclientstorage on the command line. @@ -837,7 +826,8 @@ CGLMTex::CGLMTex( GLMContext *ctx, GLMTexLayout *layout, uint levels, const char if ( !(layout->m_key.m_texFlags & kGLMTexRenderable) && m_texClientStorage ) { m_backing = (char *)malloc( m_layout->m_storageTotalSize ); - + memset( m_backing, 0, m_layout->m_storageTotalSize ); + // track bytes allocated for non-RT's int formindex = sEncodeLayoutAsIndex( &layout->m_key ); @@ -1049,10 +1039,7 @@ CGLMTex::~CGLMTex( ) free( m_debugLabel ); m_debugLabel = NULL; } - - if( m_pbo ) - gGL->glDeleteBuffersARB( 1, &m_pbo ); - + m_ctx = NULL; } @@ -1117,11 +1104,10 @@ void CGLMTex::CalcTexelDataOffsetAndStrides( int sliceIndex, int x, int y, int z *zStrideOut = zStride; } -GLubyte *CGLMTex::ReadTexels( GLMTexLockDesc *desc, bool readWholeSlice, bool readOnly ) +void CGLMTex::ReadTexels( GLMTexLockDesc *desc, bool readWholeSlice ) { GLMRegion readBox; - GLubyte* data = NULL; - + if (readWholeSlice) { readBox.xmin = readBox.ymin = readBox.zmin = 0; @@ -1134,7 +1120,7 @@ GLubyte *CGLMTex::ReadTexels( GLMTexLockDesc *desc, bool readWholeSlice, bool re { readBox = desc->m_req.m_region; } - + CGLMTex *pPrevTex = m_ctx->m_samplers[0].m_pBoundTex; m_ctx->BindTexToTMU( this, 0 ); // SelectTMU(n) is a side effect @@ -1146,52 +1132,46 @@ GLubyte *CGLMTex::ReadTexels( GLMTexLockDesc *desc, bool readWholeSlice, bool re GLMTexFormatDesc *format = m_layout->m_format; GLenum target = m_layout->m_key.m_texGLTarget; - - if( readOnly ) + + void *sliceAddress = m_backing + m_layout->m_slices[ desc->m_sliceIndex ].m_storageOffset; // this would change for PBO + //int sliceSize = m_layout->m_slices[ desc->m_sliceIndex ].m_storageSize; + + // interestingly enough, we can use the same path for both 2D and 3D fetch + + switch( target ) { - data = (GLubyte*)(m_backing + m_layout->m_slices[ desc->m_sliceIndex ].m_storageOffset); // this would change for PBO - //int sliceSize = m_layout->m_slices[ desc->m_sliceIndex ].m_storageSize; + case GL_TEXTURE_CUBE_MAP: - // interestingly enough, we can use the same path for both 2D and 3D fetch - - switch( target ) + // adjust target to steer to the proper face, then fall through to the 2D texture path. + target = GL_TEXTURE_CUBE_MAP_POSITIVE_X + desc->m_req.m_face; + + case GL_TEXTURE_2D: + case GL_TEXTURE_3D: { - case GL_TEXTURE_CUBE_MAP: - - // adjust target to steer to the proper face, then fall through to the 2D texture path. - target = GL_TEXTURE_CUBE_MAP_POSITIVE_X + desc->m_req.m_face; - case GL_TEXTURE_2D: - case GL_TEXTURE_3D: + // check compressed or not + if (format->m_chunkSize != 1) { - // check compressed or not - if (format->m_chunkSize != 1) - { - // compressed path - // http://www.opengl.org/sdk/docs/man/xhtml/glGetCompressedTexImage.xml - gGL->glGetCompressedTexImage( target, // target + // compressed path + // http://www.opengl.org/sdk/docs/man/xhtml/glGetCompressedTexImage.xml + + gGL->glGetCompressedTexImage( target, // target desc->m_req.m_mip, // level - data ); // destination - } - else - { - // uncompressed path - // http://www.opengl.org/sdk/docs/man/xhtml/glGetTexImage.xml - gGL->glGetTexImage( target, // target + sliceAddress ); // destination + } + else + { + // uncompressed path + // http://www.opengl.org/sdk/docs/man/xhtml/glGetTexImage.xml + + gGL->glGetTexImage( target, // target desc->m_req.m_mip, // level format->m_glDataFormat, // dataformat format->m_glDataType, // datatype - data ); // destination - } + sliceAddress ); // destination } - break; } + break; } - else - { - gGL->glBindBufferARB(GL_PIXEL_UNPACK_BUFFER, m_pbo); - data = (GLubyte*)gGL->glMapBufferRange(GL_PIXEL_UNPACK_BUFFER, 0, m_layout->m_slices[ desc->m_sliceIndex ].m_storageSize, GL_MAP_WRITE_BIT | GL_MAP_UNSYNCHRONIZED_BIT); - } - } else { @@ -1199,8 +1179,6 @@ GLubyte *CGLMTex::ReadTexels( GLMTexLockDesc *desc, bool readWholeSlice, bool re } m_ctx->BindTexToTMU( pPrevTex, 0 ); - - return data; } // TexSubImage should work properly on every driver stack and GPU--enabling by default. @@ -1255,14 +1233,8 @@ void CGLMTex::WriteTexels( GLMTexLockDesc *desc, bool writeWholeSlice, bool noDa GLenum glDataFormat = format->m_glDataFormat; // this could change if expansion kicks in GLenum glDataType = format->m_glDataType; - GLMTexLayoutSlice *slice = &m_layout->m_slices[ desc->m_sliceIndex ]; - - void *sliceAddress = NULL; - - if( m_mapped ) - sliceAddress = m_mapped; - else if( m_backing ) - sliceAddress = m_backing + slice->m_storageOffset; + GLMTexLayoutSlice *slice = &m_layout->m_slices[ desc->m_sliceIndex ]; + void *sliceAddress = m_backing ? (m_backing + slice->m_storageOffset) : NULL; // this would change for PBO // allow use of subimage if the target is texture2D and it has already been teximage'd bool mayUseSubImage = false; @@ -1309,7 +1281,7 @@ void CGLMTex::WriteTexels( GLMTexLockDesc *desc, bool writeWholeSlice, bool noDa gGL->glTexParameteri( target, GL_TEXTURE_BASE_LEVEL, desc->m_req.m_mip); } - if (needsExpand && !m_mapped) + if (needsExpand) { int expandSize = 0; @@ -1389,13 +1361,12 @@ void CGLMTex::WriteTexels( GLMTexLockDesc *desc, bool writeWholeSlice, bool noDa { // go subimage2D if it's a replacement, not a creation - if( !m_mapped ) - { - gGL->glPixelStorei( GL_UNPACK_ROW_LENGTH, slice->m_xSize ); // in pixels - gGL->glPixelStorei( GL_UNPACK_SKIP_PIXELS, writeBox.xmin ); // in pixels - gGL->glPixelStorei( GL_UNPACK_SKIP_ROWS, writeBox.ymin ); // in pixels - gGL->glTexSubImage2D( target, + gGL->glPixelStorei( GL_UNPACK_ROW_LENGTH, slice->m_xSize ); // in pixels + gGL->glPixelStorei( GL_UNPACK_SKIP_PIXELS, writeBox.xmin ); // in pixels + gGL->glPixelStorei( GL_UNPACK_SKIP_ROWS, writeBox.ymin ); // in pixels + + gGL->glTexSubImage2D( target, desc->m_req.m_mip, // level writeBox.xmin, // xoffset into dest writeBox.ymin, // yoffset into dest @@ -1404,25 +1375,25 @@ void CGLMTex::WriteTexels( GLMTexLockDesc *desc, bool writeWholeSlice, bool noDa glDataFormat, // format glDataType, // type sliceAddress // data (will be offsetted by the SKIP_PIXELS and SKIP_ROWS - let GL do the math to find the first source texel) - ); + ); - gGL->glPixelStorei( GL_UNPACK_ROW_LENGTH, 0 ); - gGL->glPixelStorei( GL_UNPACK_SKIP_PIXELS, 0 ); - gGL->glPixelStorei( GL_UNPACK_SKIP_ROWS, 0 ); - } - else - { - gGL->glTexSubImage2D( target, - desc->m_req.m_mip, // level - writeBox.xmin, // xoffset into dest - writeBox.ymin, // yoffset into dest - writeBox.xmax - writeBox.xmin, // width (was slice->m_xSize) - writeBox.ymax - writeBox.ymin, // height (was slice->m_ySize) - glDataFormat, // format - glDataType, // type - 0 - ); - } + gGL->glPixelStorei( GL_UNPACK_ROW_LENGTH, 0 ); + gGL->glPixelStorei( GL_UNPACK_SKIP_PIXELS, 0 ); + gGL->glPixelStorei( GL_UNPACK_SKIP_ROWS, 0 ); + + /* + //http://www.opengl.org/sdk/docs/man/xhtml/glTexSubImage2D.xml + glTexSubImage2D( target, + desc->m_req.m_mip, // level + 0, // xoffset + 0, // yoffset + slice->m_xSize, // width + slice->m_ySize, // height + glDataFormat, // format + glDataType, // type + sliceAddress // data + ); + */ } else { @@ -1485,6 +1456,8 @@ void CGLMTex::WriteTexels( GLMTexLockDesc *desc, bool writeWholeSlice, bool noDa } else { + // uncompressed path + // http://www.opengl.org/sdk/docs/man/xhtml/glTexImage3D.xml gGL->glTexImage3D( target, // target desc->m_req.m_mip, // level intformat, // internalformat @@ -1567,11 +1540,11 @@ void CGLMTex::Lock( GLMTexLockParams *params, char** addressOut, int* yStrideOut unStoragePow2 |= unStoragePow2 >> 8; unStoragePow2 |= unStoragePow2 >> 16; unStoragePow2++; - m_backing = (char *)malloc( unStoragePow2 ); + m_backing = (char *)calloc( unStoragePow2, 1 ); } else { - m_backing = (char *)malloc( m_layout->m_storageTotalSize ); + m_backing = (char *)calloc( m_layout->m_storageTotalSize, 1 ); } // clear the kSliceStorageValid bit on all slices @@ -1666,18 +1639,14 @@ void CGLMTex::Lock( GLMTexLockParams *params, char** addressOut, int* yStrideOut desc->m_sliceRegionOffset = offsetInSlice + desc->m_sliceBaseOffset; - if ( copyout && ( (m_layout->m_key.m_texFlags & kGLMTexDynamic) || params->m_readonly ) ) + if (copyout) { - *addressOut = (char*)ReadTexels( desc, true, params->m_readonly ); - - if( params->m_readonly == false ) - m_mapped = (GLubyte*)*addressOut; - } - else - { - *addressOut = m_backing + desc->m_sliceRegionOffset; - } - + // read the whole slice + // (odds are we'll never request anything but a whole slice to be read..) + ReadTexels( desc, true ); + } // this would be a good place to fill with scrub value if in debug... + + *addressOut = m_backing + desc->m_sliceRegionOffset; *yStrideOut = yStride; *zStrideOut = zStride; @@ -1763,16 +1732,7 @@ void CGLMTex::Unlock( GLMTexLockParams *params ) // fullyDirty |= (m_sliceFlags[ desc->m_sliceIndex ] & kSliceStorageValid); - if( m_layout->m_key.m_texFlags & kGLMTexDynamic && m_mapped ) - { - gGL->glUnmapBuffer(GL_PIXEL_UNPACK_BUFFER); - - WriteTexels( desc, fullyDirty ); - m_mapped = NULL; - gGL->glBindBufferARB(GL_PIXEL_UNPACK_BUFFER, 0); - } - else - WriteTexels( desc, fullyDirty ); + WriteTexels( desc, fullyDirty ); // logical place to trigger preloading // only do it for an RT tex, if it is not yet attached to any FBO. diff --git a/togl/linuxwin/dxabstract.cpp b/togl/linuxwin/dxabstract.cpp index 8e6bdac9..e637cf1e 100644 --- a/togl/linuxwin/dxabstract.cpp +++ b/togl/linuxwin/dxabstract.cpp @@ -404,7 +404,7 @@ HRESULT IDirect3DDevice9::CreateTexture(UINT Width,UINT Height,UINT Levels,DWORD if (Usage & D3DUSAGE_DYNAMIC) { - key.m_texFlags |= kGLMTexDynamic; + // GLMPRINTF(("-X- DYNAMIC tex usage ignored..")); //FIXME } if (Usage & D3DUSAGE_TEXTURE_SRGB) @@ -617,7 +617,7 @@ HRESULT IDirect3DDevice9::CreateCubeTexture(UINT EdgeLength,UINT Levels,DWORD Us if (Usage & D3DUSAGE_DYNAMIC) { - key.m_texFlags |= kGLMTexDynamic; + //GLMPRINTF(("-X- DYNAMIC tex usage ignored..")); //FIXME } if (Usage & D3DUSAGE_TEXTURE_SRGB) @@ -823,7 +823,7 @@ HRESULT IDirect3DDevice9::CreateVolumeTexture(UINT Width,UINT Height,UINT Depth, if (Usage & D3DUSAGE_DYNAMIC) { - key.m_texFlags |= kGLMTexDynamic; + GLMPRINTF(("-X- DYNAMIC tex usage ignored..")); //FIXME } if (Usage & D3DUSAGE_TEXTURE_SRGB) @@ -1040,9 +1040,7 @@ HRESULT IDirect3DSurface9::LockRect(D3DLOCKED_RECT* pLockedRect,CONST RECT* pRec // smells like readback, force texel readout lockreq.m_readback = true; } - - lockreq.m_readonly = (Flags & D3DLOCK_READONLY) ? true : false; - + char *lockAddress; int yStride; int zStride; @@ -5329,7 +5327,7 @@ HRESULT IDirect3DDevice9::DrawPrimitiveUP(D3DPRIMITIVETYPE PrimitiveType,UINT Pr // [in] Number of primitives to render. The number of vertices used is a function of the primitive count and the primitive type. The maximum number of primitives allowed is determined by checking the MaxPrimitiveCount member of the D3DCAPS9 structure. // BE VERY CAREFUL what you do in this function. It's extremely hot, and calling the wrong GL API's in here will crush perf. on NVidia threaded drivers. -#ifndef OSX +#if 1 //ifndef OSX HRESULT IDirect3DDevice9::DrawIndexedPrimitive( D3DPRIMITIVETYPE Type, INT BaseVertexIndex, UINT MinVertexIndex, UINT NumVertices, UINT startIndex, UINT primCount ) { diff --git a/togl/linuxwin/glmgr.cpp b/togl/linuxwin/glmgr.cpp index cfe84114..745862b1 100644 --- a/togl/linuxwin/glmgr.cpp +++ b/togl/linuxwin/glmgr.cpp @@ -2812,6 +2812,7 @@ GLMContext::GLMContext( IDirect3DDevice9 *pDevice, GLMDisplayParams *params ) } } +/* if ( m_caps.m_badDriver108Intel ) { // this way we have something to look for in terminal spew if users report issues related to this in the future. @@ -2821,6 +2822,7 @@ GLMContext::GLMContext( IDirect3DDevice9 *pDevice, GLMDisplayParams *params ) Warning( "Unable to enable OSX 10.8 / Intel HD4000 workaround, there might be crashes.\n" ); } } +*/ #endif // also, set the remote convar "gl_can_query_fast" to 1 if perf package present, else 0. @@ -5080,7 +5082,7 @@ static inline uint GetDataTypeSizeInBytes( GLenum dataType ) return 0; } -#ifndef OSX +#if 1 //ifndef OS void GLMContext::DrawRangeElementsNonInline( GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices, uint baseVertex, CGLMBuffer *pIndexBuf ) { diff --git a/togl/wscript b/togl/wscript index ab31edfe..9d55d56d 100755 --- a/togl/wscript +++ b/togl/wscript @@ -23,9 +23,6 @@ def build(bld): 'linuxwin/glentrypoints.cpp', 'linuxwin/glmgr.cpp', 'linuxwin/glmgrbasics.cpp', - #'linuxwin/glmgrcocoa.mm', [$OSXALL] - #'linuxwin/intelglmallocworkaround.cpp', [$OSXALL] - #'linuxwin/mach_override.c', [$OSXALL] 'linuxwin/cglmtex.cpp', 'linuxwin/cglmfbo.cpp', 'linuxwin/cglmprogram.cpp', @@ -33,6 +30,10 @@ def build(bld): 'linuxwin/cglmquery.cpp', 'linuxwin/asanstubs.cpp' ] + if bld.env.DEST_OS == "darwin": + source += [ + 'linuxwin/glmgrcocoa.mm', + ] includes = [ '.', @@ -45,6 +46,9 @@ def build(bld): libs = ['tier0','tier1','tier2','vstdlib','mathlib'] + if bld.env.DEST_OS == "darwin": + libs += ["OPENGL", "CARBON"] + install_path = bld.env.LIBDIR bld.shlib( diff --git a/togles/linuxwin/dxabstract.cpp b/togles/linuxwin/dxabstract.cpp index 4b2e7cf9..1f22da17 100644 --- a/togles/linuxwin/dxabstract.cpp +++ b/togles/linuxwin/dxabstract.cpp @@ -5326,7 +5326,7 @@ HRESULT IDirect3DDevice9::DrawPrimitiveUP(D3DPRIMITIVETYPE PrimitiveType,UINT Pr // [in] Number of primitives to render. The number of vertices used is a function of the primitive count and the primitive type. The maximum number of primitives allowed is determined by checking the MaxPrimitiveCount member of the D3DCAPS9 structure. // BE VERY CAREFUL what you do in this function. It's extremely hot, and calling the wrong GL API's in here will crush perf. on NVidia threaded drivers. -#ifndef OSX +#if 1 //ifndef OSX HRESULT IDirect3DDevice9::DrawIndexedPrimitive( D3DPRIMITIVETYPE Type, INT BaseVertexIndex, UINT MinVertexIndex, UINT NumVertices, UINT startIndex, UINT primCount ) { diff --git a/togles/linuxwin/glmgr.cpp b/togles/linuxwin/glmgr.cpp index e7c9338f..302090cf 100644 --- a/togles/linuxwin/glmgr.cpp +++ b/togles/linuxwin/glmgr.cpp @@ -2692,6 +2692,7 @@ GLMContext::GLMContext( IDirect3DDevice9 *pDevice, GLMDisplayParams *params ) } } +/* if ( m_caps.m_badDriver108Intel ) { // this way we have something to look for in terminal spew if users report issues related to this in the future. @@ -2701,6 +2702,7 @@ GLMContext::GLMContext( IDirect3DDevice9 *pDevice, GLMDisplayParams *params ) Warning( "Unable to enable OSX 10.8 / Intel HD4000 workaround, there might be crashes.\n" ); } } +*/ #endif // also, set the remote convar "gl_can_query_fast" to 1 if perf package present, else 0. @@ -4899,7 +4901,7 @@ static inline uint GetDataTypeSizeInBytes( GLenum dataType ) return 0; } -#ifndef OSX +#if 1 //ifndef OSX void GLMContext::DrawRangeElementsNonInline( GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices, uint baseVertex, CGLMBuffer *pIndexBuf ) { diff --git a/togles/wscript b/togles/wscript index bc796860..0fedceaa 100755 --- a/togles/wscript +++ b/togles/wscript @@ -23,7 +23,6 @@ def build(bld): 'linuxwin/glentrypoints.cpp', 'linuxwin/glmgr.cpp', 'linuxwin/glmgrbasics.cpp', - #'linuxwin/glmgrcocoa.mm', [$OSXALL] #'linuxwin/intelglmallocworkaround.cpp', [$OSXALL] #'linuxwin/mach_override.c', [$OSXALL] 'linuxwin/cglmtex.cpp', @@ -35,6 +34,9 @@ def build(bld): 'linuxwin/decompress.c' ] + if bld.env.DEST_OS == "darwin": + source += ['linuxwin/glmgrcocoa.mm'] + includes = [ '.', '../public', @@ -46,6 +48,9 @@ def build(bld): libs = ['tier0','tier1','tier2','vstdlib','mathlib'] + if bld.env.DEST_OS == "darwin": + libs += ["OPENGL", "CARBON"] + install_path = bld.env.LIBDIR bld.shlib( diff --git a/utils/vtex/vtex.cpp b/utils/vtex/vtex.cpp index d09a32d2..65e41e2f 100644 --- a/utils/vtex/vtex.cpp +++ b/utils/vtex/vtex.cpp @@ -7,7 +7,11 @@ #include #include +#ifdef OSX +#include +#else #include +#endif #include #include "tier1/strtools.h" #include diff --git a/vgui2/src/wscript b/vgui2/src/wscript index 0d7f67a7..b4063e14 100644 --- a/vgui2/src/wscript +++ b/vgui2/src/wscript @@ -62,6 +62,8 @@ def build(bld): if bld.env.DEST_OS == 'win32': libs += ['USER32', 'IMM32', 'GDI32', 'SHELL32', 'OLE32', 'SHLWAPI', 'vgui_surfacelib', 'WINMM'] + elif bld.env.DEST_OS == 'darwin': + libs += ['APPLICATIONSERVICES'] install_path = bld.env.LIBDIR diff --git a/video/wscript b/video/wscript index e6b1beea..87a8c326 100755 --- a/video/wscript +++ b/video/wscript @@ -34,6 +34,8 @@ def build(bld): if bld.env.DEST_OS == 'win32': libs += ['USER32'] + elif bld.env.DEST_OS == 'darwin': + libs += ['COREGRAPHICS'] install_path = bld.env.LIBDIR diff --git a/vstdlib/jobthread.cpp b/vstdlib/jobthread.cpp index 922b770f..add54c5e 100644 --- a/vstdlib/jobthread.cpp +++ b/vstdlib/jobthread.cpp @@ -285,7 +285,7 @@ private: //----------------------------------------------------------------------------- -JOB_INTERFACE IThreadPool *CreateThreadPool() +JOB_INTERFACE IThreadPool *CreateThreadPool1() { return new CThreadPool; } diff --git a/vstdlib/wscript b/vstdlib/wscript index 57a63633..ea3322a4 100755 --- a/vstdlib/wscript +++ b/vstdlib/wscript @@ -51,6 +51,8 @@ def build(bld): if bld.env.DEST_OS == 'android': libs += ['ANDROID_SUPPORT'] + elif bld.env.DEST_OS == 'darwin': + libs += ['ICONV', 'COREFOUNDATION', 'CORESERVICES'] install_path = bld.env.LIBDIR diff --git a/wscript b/wscript index 53e1ef1d..2cdb8021 100644 --- a/wscript +++ b/wscript @@ -212,6 +212,14 @@ def define_platform(conf): '_ALLOW_MSC_VER_MISMATCH', 'NO_X360_XDK' ]) + elif conf.env.DEST_OS == 'darwin': + conf.env.append_unique('DEFINES', [ + 'OSX=1', '_OSX=1', + 'POSIX=1', '_POSIX=1', 'PLATFORM_POSIX=1', + 'GNUC', + 'NO_HOOK_MALLOC', + '_DLL_EXT=.dylib' + ]) if conf.options.DEBUG_ENGINE: conf.env.append_unique('DEFINES', [ @@ -302,8 +310,7 @@ def configure(conf): conf.env.BIT32_MANDATORY = not conf.options.ALLOW64 if conf.env.BIT32_MANDATORY: Logs.info('WARNING: will build engine for 32-bit target') - - conf.load('force_32bit') + conf.load('force_32bit') if conf.options.DISABLE_WARNS: compiler_optional_flags = ['-w'] @@ -353,7 +360,7 @@ def configure(conf): ] flags += ['-funwind-tables', '-fvisibility=default'] - elif conf.env.COMPILER_CC != 'msvc': + elif conf.env.COMPILER_CC not in ['msvc', 'clang']: flags += ['-march=native'] if conf.env.DEST_CPU in ['x86', 'x86_64']: @@ -444,7 +451,10 @@ def configure(conf): else: conf.check_pkg('freetype2', 'FT2', FT2_CHECK) conf.check_pkg('fontconfig', 'FC', FC_CHECK) - conf.check_cfg(package='openal', uselib_store='OPENAL', args=['--cflags', '--libs']) + if conf.env.DEST_OS == "darwin": + conf.env.FRAMEWORK_OPENAL = "OpenAL" + else: + conf.check_cfg(package='openal', uselib_store='OPENAL', args=['--cflags', '--libs']) conf.check_cfg(package='libjpeg', uselib_store='JPEG', args=['--cflags', '--libs']) conf.check_cfg(package='libpng', uselib_store='PNG', args=['--cflags', '--libs']) conf.check_cfg(package='libcurl', uselib_store='CURL', args=['--cflags', '--libs']) @@ -466,6 +476,21 @@ def configure(conf): conf.check(lib='android_support', uselib_store='ANDROID_SUPPORT') conf.check(lib='opus', uselib_store='OPUS') + if conf.env.DEST_OS == "darwin": + conf.check(lib='iconv', uselib_store='ICONV') + conf.env.FRAMEWORK_APPKIT = "AppKit" + conf.env.FRAMEWORK_IOKIT = "IOKit" + conf.env.FRAMEWORK_FOUNDATION = "Foundation" + conf.env.FRAMEWORK_COREFOUNDATION = "CoreFoundation" + conf.env.FRAMEWORK_COREGRAPHICS = "CoreGraphics" + conf.env.FRAMEWORK_OPENGL = "OpenGL" + conf.env.FRAMEWORK_CARBON = "Carbon" + conf.env.FRAMEWORK_APPLICATIONSERVICES = "ApplicationServices" + conf.env.FRAMEWORK_CORESERVICES = "CoreServices" + conf.env.FRAMEWORK_COREAUDIO = "CoreAudio" + conf.env.FRAMEWORK_AUDIOTOOLBOX = "AudioToolbox" + conf.env.FRAMEWORK_SYSTEMCONFIGURATION = "SystemConfiguration" + if conf.env.DEST_OS != 'win32': conf.check_cc(lib='dl', mandatory=False) conf.check_cc(lib='bz2', mandatory=False) @@ -535,6 +560,13 @@ def configure(conf): else: conf.add_subproject(projects['game']) +from waflib import TaskGen +@TaskGen.extension('.mm') +def m_hook(self, node): + """Alias .mm files to be compiled the same as .cpp files, gcc will do the right thing.""" + return self.create_compiled_task('cxx', node) + + def build(bld): os.environ["CCACHE_DIR"] = os.path.abspath('.ccache/'+bld.env.COMPILER_CC+'/'+bld.env.DEST_OS+'/'+bld.env.DEST_CPU)