Update SFContext according to the new contexts system
This commit is contained in:
parent
9e2e349043
commit
71469f1815
@ -42,10 +42,18 @@ typedef NSOpenGLContext* NSOpenGLContextRef;
|
|||||||
@class NSAutoreleasePool;
|
@class NSAutoreleasePool;
|
||||||
typedef NSAutoreleasePool* NSAutoreleasePoolRef;
|
typedef NSAutoreleasePool* NSAutoreleasePoolRef;
|
||||||
|
|
||||||
|
@class NSOpenGLView;
|
||||||
|
typedef NSOpenGLView* NSOpenGLViewRef;
|
||||||
|
|
||||||
|
@class NSWindow;
|
||||||
|
typedef NSWindow* NSWindowRef;
|
||||||
|
|
||||||
#else // If C++
|
#else // If C++
|
||||||
|
|
||||||
typedef void* NSOpenGLContextRef;
|
typedef void* NSOpenGLContextRef;
|
||||||
typedef void* NSAutoreleasePoolRef;
|
typedef void* NSAutoreleasePoolRef;
|
||||||
|
typedef void* NSOpenGLViewRef;
|
||||||
|
typedef void* NSWindowRef;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -72,14 +80,26 @@ public:
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Create a new context attached to a window
|
/// \brief Create a new context attached to a window
|
||||||
///
|
///
|
||||||
/// \param shared Context to share the new one with (can be NULL)
|
/// \param shared Context to share the new one with
|
||||||
/// \param owner Pointer to the owner window
|
|
||||||
/// \param bitsPerPixel Pixel depth (in bits per pixel)
|
|
||||||
/// \param settings Creation parameters
|
/// \param settings Creation parameters
|
||||||
|
/// \param owner Pointer to the owner window
|
||||||
|
/// \param bitsPerPixel Pixel depth, in bits per pixel
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
SFContext(SFContext* shared, const WindowImpl* owner,
|
SFContext(SFContext* shared, const ContextSettings& settings,
|
||||||
unsigned int bitsPerPixel, const ContextSettings& settings);
|
const WindowImpl* owner, unsigned int bitsPerPixel);
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
/// \brief Create a new context that embeds its own rendering target
|
||||||
|
///
|
||||||
|
/// \param shared Context to share the new one with
|
||||||
|
/// \param settings Creation parameters
|
||||||
|
/// \param width Back buffer width, in pixels
|
||||||
|
/// \param height Back buffer height, in pixels
|
||||||
|
///
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
SFContext(SFContext* shared, const ContextSettings& settings,
|
||||||
|
unsigned int width, unsigned int height);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Destructor
|
/// \brief Destructor
|
||||||
@ -133,8 +153,10 @@ private:
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Member data
|
// Member data
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
NSOpenGLContextRef myContext; ///< OpenGL context
|
NSOpenGLContextRef myContext; ///< OpenGL context.
|
||||||
NSAutoreleasePoolRef myPool; ///< Memory manager for this class.
|
NSAutoreleasePoolRef myPool; ///< Memory manager for this class.
|
||||||
|
NSOpenGLViewRef myView; ///< Only for offscreen context.
|
||||||
|
NSWindowRef myWindow; ///< Only for offscreen context.
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace priv
|
} // namespace priv
|
||||||
|
@ -51,6 +51,7 @@ namespace priv
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
SFContext::SFContext(SFContext* shared)
|
SFContext::SFContext(SFContext* shared)
|
||||||
|
: myView(0), myWindow(0)
|
||||||
{
|
{
|
||||||
myPool = [[NSAutoreleasePool alloc] init];
|
myPool = [[NSAutoreleasePool alloc] init];
|
||||||
|
|
||||||
@ -63,8 +64,9 @@ SFContext::SFContext(SFContext* shared)
|
|||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
SFContext::SFContext(SFContext* shared, const WindowImpl* owner,
|
SFContext::SFContext(SFContext* shared, const ContextSettings& settings,
|
||||||
unsigned int bitsPerPixel, const ContextSettings& settings)
|
const WindowImpl* owner, unsigned int bitsPerPixel)
|
||||||
|
: myView(0), myWindow(0)
|
||||||
{
|
{
|
||||||
myPool = [[NSAutoreleasePool alloc] init];
|
myPool = [[NSAutoreleasePool alloc] init];
|
||||||
|
|
||||||
@ -80,16 +82,43 @@ SFContext::SFContext(SFContext* shared, const WindowImpl* owner,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
SFContext::SFContext(SFContext* shared, const ContextSettings& settings,
|
||||||
|
unsigned int width, unsigned int height)
|
||||||
|
: myView(0), myWindow(0)
|
||||||
|
{
|
||||||
|
// Ensure the process is setup in order to create a valid window.
|
||||||
|
WindowImplCocoa::SetUpProcess();
|
||||||
|
|
||||||
|
myPool = [[NSAutoreleasePool alloc] init];
|
||||||
|
|
||||||
|
// Create the context.
|
||||||
|
CreateContext(shared, VideoMode::GetDesktopMode().BitsPerPixel, settings);
|
||||||
|
|
||||||
|
// Create a dummy window/view pair (hidden) and asign it our context.
|
||||||
|
myWindow = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, width, height)
|
||||||
|
styleMask:NSBorderlessWindowMask
|
||||||
|
backing:NSBackingStoreBuffered
|
||||||
|
defer:NO]; // Don't defer it!
|
||||||
|
myView = [[NSOpenGLView alloc] initWithFrame:NSMakeRect(0, 0, width, height)];
|
||||||
|
[myWindow setContentView:myView];
|
||||||
|
[myView setOpenGLContext:myContext];
|
||||||
|
[myContext setView:myView];
|
||||||
|
|
||||||
|
// Activate the context
|
||||||
|
SetActive(true);
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
SFContext::~SFContext()
|
SFContext::~SFContext()
|
||||||
{
|
{
|
||||||
[myContext clearDrawable];
|
[myContext clearDrawable];
|
||||||
[myContext release];
|
[myContext release];
|
||||||
[myPool drain]; // [A]
|
|
||||||
|
|
||||||
/*
|
[myView release]; // Might be nil but we don't care.
|
||||||
* [A] : Produce sometimes "*** attempt to pop an unknown autorelease pool"
|
[myWindow release]; // Idem.
|
||||||
*/
|
|
||||||
|
[myPool drain]; // Produce sometimes "*** attempt to pop an unknown autorelease pool"
|
||||||
|
// This is not a real issue : http://stackoverflow.com/questions/3484888/nsautoreleasepool-question
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -132,8 +161,8 @@ void SFContext::CreateContext(SFContext* shared,
|
|||||||
attrs.reserve(20); // max attributs (estimation).
|
attrs.reserve(20); // max attributs (estimation).
|
||||||
|
|
||||||
// These casts are safe. C++ is much more strict than Obj-C.
|
// These casts are safe. C++ is much more strict than Obj-C.
|
||||||
attrs.push_back(NSOpenGLPFAClosestPolicy);
|
|
||||||
|
|
||||||
|
attrs.push_back(NSOpenGLPFAClosestPolicy);
|
||||||
attrs.push_back(NSOpenGLPFADoubleBuffer);
|
attrs.push_back(NSOpenGLPFADoubleBuffer);
|
||||||
|
|
||||||
if (bitsPerPixel > 24) {
|
if (bitsPerPixel > 24) {
|
||||||
@ -162,7 +191,7 @@ void SFContext::CreateContext(SFContext* shared,
|
|||||||
// Create the pixel pormat.
|
// Create the pixel pormat.
|
||||||
NSOpenGLPixelFormat* pixFmt = [[NSOpenGLPixelFormat alloc] initWithAttributes:&attrs[0]];
|
NSOpenGLPixelFormat* pixFmt = [[NSOpenGLPixelFormat alloc] initWithAttributes:&attrs[0]];
|
||||||
|
|
||||||
if(pixFmt == nil) {
|
if (pixFmt == nil) {
|
||||||
sf::Err() << "Error. Unable to find a suitable pixel format." << std::endl;
|
sf::Err() << "Error. Unable to find a suitable pixel format." << std::endl;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -174,6 +203,10 @@ void SFContext::CreateContext(SFContext* shared,
|
|||||||
myContext = [[NSOpenGLContext alloc] initWithFormat:pixFmt
|
myContext = [[NSOpenGLContext alloc] initWithFormat:pixFmt
|
||||||
shareContext:sharedContext];
|
shareContext:sharedContext];
|
||||||
|
|
||||||
|
if (myContext == nil) {
|
||||||
|
sf::Err() << "Error. Unable to create the context." << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
// Free up.
|
// Free up.
|
||||||
[pixFmt release];
|
[pixFmt release];
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user