- Applied some parts of Alexey's MacOS patch.

git-svn-id: http://mancubus.net/svn/hosted/gzdoom/trunk@1245 b0f79afe-0144-0410-b225-9a4edf0717df
This commit is contained in:
gez 2011-08-19 20:03:54 +00:00
parent 050233af52
commit 790dfb2ced
13 changed files with 197 additions and 23 deletions

View file

@ -342,7 +342,7 @@ void T_LoadScripts(MapData *map)
// the default translator is being used.
// Custom translators will not be patched.
if ((gameinfo.gametype == GAME_Doom || gameinfo.gametype == GAME_Heretic) && level.info->Translator.IsEmpty() &&
level.maptype == MAPTYPE_DOOM && SimpleLineTranslations[272 - 2*HasScripts].special == FS_Execute)
(level.maptype == MAPTYPE_DOOM) && SimpleLineTranslations[272 - 2*HasScripts].special == FS_Execute)
{
FLineTrans t = SimpleLineTranslations[270];
SimpleLineTranslations[270] = SimpleLineTranslations[272];

View file

@ -44,21 +44,21 @@
#include "i_system.h"
#include "gl/system/gl_cvars.h"
#ifdef unix
#if defined (unix) || defined (__APPLE__)
#include <SDL.h>
#define wglGetProcAddress(x) (*SDL_GL_GetProcAddress)(x)
#endif
static void APIENTRY glBlendEquationDummy (GLenum mode);
#ifndef unix
#if !defined (unix) && !defined (__APPLE__)
PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormatARB; // = (PFNWGLCHOOSEPIXELFORMATARBPROC)wglGetProcAddress("wglChoosePixelFormatARB");
PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribsARB;
#endif
static TArray<FString> m_Extensions;
#ifndef unix
#if !defined (unix) && !defined (__APPLE__)
HWND m_Window;
HDC m_hDC;
HGLRC m_hRC;
@ -77,7 +77,7 @@ int occlusion_type=0;
//
//==========================================================================
#ifndef unix
#if !defined (unix) && !defined (__APPLE__)
static HWND InitDummy()
{
HMODULE g_hInst = GetModuleHandle(NULL);
@ -298,7 +298,7 @@ static void APIENTRY LoadExtensions()
if (strcmp(version, "3.0") >= 0) gl->flags|=RFL_GL_30;
#ifndef unix
#if !defined (unix) && !defined (__APPLE__)
PFNWGLSWAPINTERVALEXTPROC vs = (PFNWGLSWAPINTERVALEXTPROC)wglGetProcAddress("wglSwapIntervalEXT");
if (vs) gl->SetVSync = vs;
#endif
@ -510,7 +510,7 @@ static void APIENTRY PrintStartupLog()
//
//==========================================================================
#ifndef unix
#if !defined (unix) && !defined (__APPLE__)
static bool SetupPixelFormat(HDC hDC, bool allowsoftware, bool nostencil, int multisample)
{
int colorDepth;
@ -745,7 +745,7 @@ static bool SetupPixelFormat(bool allowsoftware, bool nostencil, int multisample
//
//==========================================================================
#ifndef unix
#if !defined (unix) && !defined (__APPLE__)
CVAR(Bool, gl_debug, false, 0)
static bool APIENTRY InitHardware (HWND Window, bool allowsoftware, bool nostencil, int multisample)
@ -806,7 +806,7 @@ static bool APIENTRY InitHardware (bool allowsoftware, bool nostencil, int multi
//
//==========================================================================
#ifndef unix
#if !defined (unix) && !defined (__APPLE__)
static void APIENTRY Shutdown()
{
if (m_hRC)
@ -853,17 +853,21 @@ static bool APIENTRY SetFullscreen(const char *devicename, int w, int h, int bit
static void APIENTRY iSwapBuffers()
{
#ifndef unix
#if !defined (unix) && !defined (__APPLE__)
SwapBuffers(m_hDC);
#else
SDL_GL_SwapBuffers ();
#endif
}
static BOOL APIENTRY SetVSync(int)
static BOOL APIENTRY SetVSync( int vsync )
{
#if defined (__APPLE__)
return kCGLNoError == CGLSetParameter( CGLGetCurrentContext(), kCGLCPSwapInterval, &vsync );
#else // !__APPLE__
// empty placeholder
return false;
#endif // __APPLE__
}
//==========================================================================
@ -982,11 +986,11 @@ void APIENTRY GetContext(RenderContext & gl)
gl.SetTextureMode = SetTextureMode;
gl.PrintStartupLog = PrintStartupLog;
gl.InitHardware = InitHardware;
#ifndef unix
#if !defined (unix) && !defined (__APPLE__)
gl.Shutdown = Shutdown;
#endif
gl.SwapBuffers = iSwapBuffers;
#ifndef unix
#if !defined (unix) && !defined (__APPLE__)
gl.SetFullscreen = SetFullscreen;
#endif
@ -1068,7 +1072,7 @@ void APIENTRY GetContext(RenderContext & gl)
gl.BlendEquation = glBlendEquationDummy;
gl.SetVSync = SetVSync;
#ifndef unix
#if !defined (unix) && !defined (__APPLE__)
ReadInitExtensions();
//GL is not yet inited in UNIX version, read them later in LoadExtensions
#endif

View file

@ -1,6 +1,10 @@
#ifndef R_RENDER
#define R_RENDER
#if defined(__APPLE__)
#define APIENTRY
#endif // __APPLE__
enum RenderFlags
{
RFL_NPOT_TEXTURE=1,
@ -54,7 +58,7 @@ struct RenderContext
void (APIENTRY * SetTextureMode) (int type);
void (APIENTRY * PrintStartupLog) ();
BOOL (APIENTRY * SetVSync) (int on);
#ifndef unix
#if !defined (unix) && !defined (__APPLE__)
bool (APIENTRY * InitHardware) (HWND, bool allowsoftware, bool nostencil, int multisample);
void (APIENTRY * Shutdown) ();
#else

View file

@ -47,7 +47,9 @@
#include <errno.h>
#include <stdarg.h>
#include <signal.h>
#if !defined(__APPLE__)
#include <malloc.h>
#endif
#include <time.h>
#ifdef _MSC_VER
@ -62,9 +64,15 @@
#include <sys/stat.h>
#include <fcntl.h>
#if defined(__APPLE__)
#include <GL/glew.h>
#include <OpenGL/OpenGL.h>
#else // !__APPLE__
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glext.h>
#endif // __APPLE__
#ifdef _WIN32
#define DWORD WINDOWS_DWORD // I don't want to depend on this throughout the GL code!
#include <GL/wglext.h>

View file

@ -50,6 +50,12 @@ inline long long GetClockCycle ()
}
#endif
#if defined (__APPLE__)
typedef cycle_t glcycle_t;
#else // !__APPLE__
class glcycle_t
{
public:
@ -93,6 +99,7 @@ private:
long long Counter;
};
#endif // __APPLE__
extern glcycle_t RenderWall,SetupWall,ClipWall,SplitWall;
extern glcycle_t RenderFlat,SetupFlat;

View file

@ -1078,7 +1078,7 @@ static FString GetCachePath()
FSRef folder;
if (noErr == FSFindFolder(kLocalDomain, kApplicationSupportFolderType, kCreateFolder, &folder) &&
noErr == FSRefMakePath(&folder, (UInt8*)path.GetChars(), PATH_MAX))
noErr == FSRefMakePath(&folder, (UInt8*)pathstr, PATH_MAX))
{
path = pathstr;
}

View file

@ -14,6 +14,9 @@
#ifndef PR_SET_PTRACER
#define PR_SET_PTRACER 0x59616d61
#endif
#else if defined (__APPLE__)
#include <signal.h>
#endif
#endif

View file

@ -251,10 +251,12 @@ void I_ShutdownJoysticks();
int main (int argc, char **argv)
{
#if !defined (__APPLE__)
{
int s[4] = { SIGSEGV, SIGILL, SIGFPE, SIGBUS };
cc_install_handlers(argc, argv, 4, s, "zdoom-crash.log", DoomSpecificInfo);
}
#endif // !__APPLE__
printf(GAMENAME" v%s - SVN revision %s - SDL version\nCompiled on %s\n\n",
DOTVERSIONSTR_NOREV,SVN_REVISION_STRING,__DATE__);
@ -280,6 +282,26 @@ int main (int argc, char **argv)
atterm (SDL_Quit);
SDL_WM_SetCaption (GAMESIG " " DOTVERSIONSTR " (" __DATE__ ")", NULL);
#ifdef __APPLE__
const SDL_VideoInfo* videoInfo = SDL_GetVideoInfo();
if ( NULL != videoInfo )
{
EXTERN_CVAR( Int, vid_defwidth )
EXTERN_CVAR( Int, vid_defheight )
EXTERN_CVAR( Int, vid_defbits )
EXTERN_CVAR( Bool, vid_vsync )
EXTERN_CVAR( Bool, fullscreen )
vid_defwidth = videoInfo->current_w;
vid_defheight = videoInfo->current_h;
vid_defbits = videoInfo->vfmt->BitsPerPixel;
vid_vsync = True;
fullscreen = True;
}
#endif // __APPLE__
try
{

View file

@ -39,6 +39,7 @@
#endif
#ifdef __APPLE__
#include <CoreFoundation/CoreFoundation.h>
#include <mach/mach_init.h>
#include <mach/semaphore.h>
#include <mach/task.h>
@ -381,9 +382,25 @@ void STACK_ARGS I_FatalError (const char *error, ...)
int index;
va_list argptr;
va_start (argptr, error);
index = vsprintf (errortext, error, argptr);
index = vsnprintf (errortext, MAX_ERRORTEXT, error, argptr);
va_end (argptr);
#ifdef __APPLE__
// Close window or exit fullscreen and release mouse capture
SDL_Quit();
const CFStringRef errorString = CFStringCreateWithCStringNoCopy( kCFAllocatorDefault,
errortext, kCFStringEncodingASCII, kCFAllocatorNull );
if ( NULL != errorString )
{
CFOptionFlags dummy;
CFUserNotificationDisplayAlert( 0, kCFUserNotificationStopAlertLevel, NULL, NULL, NULL,
CFSTR( "Error" ), errorString, CFSTR( "Exit" ), NULL, NULL, &dummy );
CFRelease( errorString );
}
#endif // __APPLE__
// Record error to log (if logging)
if (Logfile)
{

View file

@ -95,6 +95,7 @@ static MiniModeInfo WinModes[] =
{ 1280, 720 }, // 16:9
{ 1280, 800 }, // 16:10
{ 1280, 960 },
{ 1344, 756 }, // 16:9
{ 1360, 768 }, // 16:9
{ 1400, 787 }, // 16:9
{ 1400, 875 }, // 16:10
@ -103,10 +104,11 @@ static MiniModeInfo WinModes[] =
{ 1600, 900 }, // 16:9
{ 1600, 1000 }, // 16:10
{ 1600, 1200 },
{ 1680, 1050 },
{ 1920, 1080 },
{ 1920, 1200 },
{ 2054, 1536 }
{ 1680, 1050 }, // 16:10
{ 1920, 1080 }, // 16:9
{ 1920, 1200 }, // 16:10
{ 2054, 1536 },
{ 2560, 1440 } // 16:9
};
// CODE --------------------------------------------------------------------
@ -297,14 +299,29 @@ SDLGLFB::SDLGLFB (void *, int width, int height, int, int, bool fullscreen)
return;
}
Screen = SDL_SetVideoMode (width, height, vid_displaybits,
// Mac OS X version will crash when entering fullscreen mode with BPP <= 8
// Also it may crash with BPP == 16 on some configurations
// It seems 24 and 32 bits are safe values
// So value of vid_displaybits is ignored and hardcoded constant is used instead
Screen = SDL_SetVideoMode (width, height,
#if defined(__APPLE__)
32,
#else // ! __APPLE__
vid_displaybits,
#endif // __APPLE__
SDL_HWSURFACE|SDL_HWPALETTE|SDL_OPENGL | SDL_GL_DOUBLEBUFFER|SDL_ANYFORMAT|
(fullscreen ? SDL_FULLSCREEN : 0));
if (Screen == NULL)
return;
m_supportsGamma = !!SDL_GetGammaRamp(m_origGamma[0], m_origGamma[1], m_origGamma[2]);
m_supportsGamma = -1 != SDL_GetGammaRamp(m_origGamma[0], m_origGamma[1], m_origGamma[2]);
#if defined(__APPLE__)
// Need to set title here because a window is not created yet when calling the same function from main()
SDL_WM_SetCaption( GAMESIG " " DOTVERSIONSTR " (" __DATE__ ")", NULL );
#endif // __APPLE__
}
SDLGLFB::~SDLGLFB ()
@ -385,6 +402,14 @@ bool SDLGLFB::IsValid ()
return DFrameBuffer::IsValid() && Screen != NULL;
}
void SDLGLFB::SetVSync( bool vsync )
{
#if defined (__APPLE__)
const GLint value = vsync ? 1 : 0;
CGLSetParameter( CGLGetCurrentContext(), kCGLCPSwapInterval, &value );
#endif
}
void SDLGLFB::NewRefreshRate ()
{
}

View file

@ -49,6 +49,8 @@ public:
bool IsValid ();
bool IsFullscreen ();
virtual void SetVSync( bool vsync );
void NewRefreshRate ();
friend class SDLGLVideo;

View file

@ -42,6 +42,15 @@
#include "m_swap.h"
#include "sbar.h"
#if defined (__APPLE__)
mach_timebase_info_data_t cycle_t::s_info;
bool cycle_t::s_initialized;
#endif // __APPLE__
FStat *FStat::FirstStat;
FStat::FStat (const char *name)

View file

@ -38,6 +38,77 @@
#ifndef _WIN32
#if defined (__APPLE__)
#include <mach/mach_time.h>
class cycle_t
{
public:
cycle_t()
{
if ( !s_initialized )
{
mach_timebase_info( &s_info );
s_initialized = true;
}
Reset();
}
cycle_t &operator=( const cycle_t &other )
{
if ( &other != this )
{
m_seconds = other.m_seconds;
}
return *this;
}
void Reset()
{
m_seconds = 0;
}
void Clock()
{
m_seconds -= Nanoseconds() * 1e-9;
}
void Unclock()
{
m_seconds += Nanoseconds() * 1e-9;
}
double Time()
{
return m_seconds;
}
double TimeMS()
{
return m_seconds * 1e3;
}
private:
double m_seconds;
static mach_timebase_info_data_t s_info;
static bool s_initialized;
uint64_t Nanoseconds() const
{
return mach_absolute_time() * s_info.numer / s_info.denom;
}
};
#else // !__APPLE__
#ifdef NO_CLOCK_GETTIME
class cycle_t
{
@ -100,6 +171,8 @@ private:
#endif
#endif // __APPLE__
#else
// Windows