diff --git a/stepmania/src/arch/LowLevelWindow/LowLevelWindow_Cocoa.h b/stepmania/src/arch/LowLevelWindow/LowLevelWindow_Cocoa.h index 2fabd38d30..f8a3250d78 100644 --- a/stepmania/src/arch/LowLevelWindow/LowLevelWindow_Cocoa.h +++ b/stepmania/src/arch/LowLevelWindow/LowLevelWindow_Cocoa.h @@ -4,10 +4,7 @@ #include "LowLevelWindow.h" #include "RageDisplay.h" -#ifndef __OBJC__ -typedef void *id; -#endif - +typedef struct objc_object *id; typedef const struct __CFDictionary *CFDictionaryRef; class LowLevelWindow_Cocoa : public LowLevelWindow @@ -15,6 +12,7 @@ class LowLevelWindow_Cocoa : public LowLevelWindow VideoModeParams m_CurrentParams; id m_Window; id m_Context; + id m_BGContext; CFDictionaryRef m_CurrentDisplayMode; public: @@ -27,6 +25,11 @@ public: void Update(); const VideoModeParams &GetActualVideoModeParams() const { return m_CurrentParams; } + + bool SupportsThreadedRendering() { return m_BGContext; } + void BeginConcurrentRendering(); + void EndConcurrentRendering(); + private: void ShutDownFullScreen(); int ChangeDisplayMode( const VideoModeParams& p ); diff --git a/stepmania/src/arch/LowLevelWindow/LowLevelWindow_Cocoa.mm b/stepmania/src/arch/LowLevelWindow/LowLevelWindow_Cocoa.mm index 6275a54336..62811c00ea 100644 --- a/stepmania/src/arch/LowLevelWindow/LowLevelWindow_Cocoa.mm +++ b/stepmania/src/arch/LowLevelWindow/LowLevelWindow_Cocoa.mm @@ -73,7 +73,7 @@ public: @end -LowLevelWindow_Cocoa::LowLevelWindow_Cocoa() : m_Context(nil), m_CurrentDisplayMode(NULL) +LowLevelWindow_Cocoa::LowLevelWindow_Cocoa() : m_Context(nil), m_BGContext(nil), m_CurrentDisplayMode(NULL) { POOL; NSRect rect = { {0, 0}, {0, 0} }; @@ -218,6 +218,14 @@ CString LowLevelWindow_Cocoa::TryVideoMode( const VideoModeParams& p, bool& newD m_Context = newContext; newDeviceOut = !bShared; m_CurrentParams.bpp = p.bpp; + [m_BGContext release]; + m_BGContext = CreateOGLContext( p.bpp, true, m_Context, bShared ); + + if( m_BGContext && !bShared ) + { + [m_BGContext release]; + m_BGContext = nil; + } } SMMainThread *mt = [[SMMainThread alloc] init]; @@ -259,6 +267,14 @@ CString LowLevelWindow_Cocoa::TryVideoMode( const VideoModeParams& p, bool& newD m_Context = newContext; newDeviceOut = !bShared; m_CurrentParams.bpp = p.bpp; + [m_BGContext release]; + m_BGContext = CreateOGLContext( p.bpp, false, m_Context, bShared ); + + if( m_BGContext && !bShared ) + { + [m_BGContext release]; + m_BGContext = nil; + } } [m_Context setFullScreen]; @@ -393,7 +409,8 @@ void LowLevelWindow_Cocoa::GetDisplayResolutions( DisplayResolutions &dr ) const void LowLevelWindow_Cocoa::SwapBuffers() { - [m_Context flushBuffer]; + // XXX don't use Obj-C here, use CG. + [[NSOpenGLContext currentContext] flushBuffer]; } void LowLevelWindow_Cocoa::Update() @@ -410,3 +427,20 @@ void LowLevelWindow_Cocoa::Update() [m_Context update]; DISPLAY->ResolutionChanged(); } + +void LowLevelWindow_Cocoa::BeginConcurrentRendering() +{ + LOG->Trace( __func__ ); + if( m_CurrentParams.windowed ) + [m_BGContext setView:[m_Window contentView]]; + else + [m_BGContext setFullScreen]; + [m_BGContext makeCurrentContext]; +} + +void LowLevelWindow_Cocoa::EndConcurrentRendering() +{ + LOG->Trace( __func__ ); + [NSOpenGLContext clearCurrentContext]; + [m_BGContext clearDrawable]; +}