forked from Mirrors/openclonk
Mac: Cocoa: Multisampling
parent
89a59b5453
commit
acf5480ac9
|
@ -31,6 +31,7 @@
|
|||
- (void) showCursor;
|
||||
- (void) hideCursor;
|
||||
- (BOOL) shouldHideMouseCursor;
|
||||
+ (CGDirectDisplayID) displayID;
|
||||
|
||||
@property(readwrite, retain) NSOpenGLContext* context;
|
||||
@end
|
||||
|
|
|
@ -375,6 +375,83 @@ int32_t mouseButtonFromEvent(NSEvent* event, DWORD& modifierFlags)
|
|||
[context update];
|
||||
}
|
||||
|
||||
+ (CGDirectDisplayID) displayID
|
||||
{
|
||||
return (CGDirectDisplayID)[[[[[NSApp keyWindow] screen] deviceDescription] valueForKey:@"NSScreenNumber"] intValue];
|
||||
}
|
||||
|
||||
+ (void) enumerateMultiSamples:(std::vector<int>&)samples
|
||||
{
|
||||
CGDirectDisplayID displayID = self.displayID;
|
||||
CGOpenGLDisplayMask displayMask = CGDisplayIDToOpenGLDisplayMask(displayID);
|
||||
int numRenderers = 0;
|
||||
CGLRendererInfoObj obj = NULL;
|
||||
GLint sampleModes;
|
||||
|
||||
CGLQueryRendererInfo(displayMask, &obj, &numRenderers);
|
||||
CGLDescribeRenderer(obj, 0, kCGLRPSampleModes, &sampleModes);
|
||||
CGLDestroyRendererInfo(obj);
|
||||
|
||||
if (sampleModes & kCGLMultisampleBit)
|
||||
{
|
||||
samples.push_back(1);
|
||||
samples.push_back(2);
|
||||
samples.push_back(4);
|
||||
}
|
||||
}
|
||||
|
||||
+ (void) setSurfaceBackingSizeOf:(NSOpenGLContext*) context width:(int)wdt height:(int)hgt
|
||||
{
|
||||
if (context && !Application.isEditor)
|
||||
{
|
||||
// Make back buffer size fixed ( http://developer.apple.com/library/mac/#documentation/GraphicsImaging/Conceptual/OpenGL-MacProgGuide/opengl_contexts/opengl_contexts.html )
|
||||
GLint dim[2] = {wdt, hgt};
|
||||
CGLContextObj ctx = (CGLContextObj)context.CGLContextObj;
|
||||
CGLSetParameter(ctx, kCGLCPSurfaceBackingSize, dim);
|
||||
CGLEnable (ctx, kCGLCESurfaceBackingSize);
|
||||
}
|
||||
}
|
||||
|
||||
static NSOpenGLContext* MainContext;
|
||||
|
||||
+ (NSOpenGLContext*) mainContext
|
||||
{
|
||||
return MainContext;
|
||||
}
|
||||
|
||||
+ (NSOpenGLContext*) createContext:(CStdGLCtx*) pMainCtx
|
||||
{
|
||||
std::vector<NSOpenGLPixelFormatAttribute> attribs;
|
||||
attribs.push_back(NSOpenGLPFADepthSize);
|
||||
attribs.push_back(16);
|
||||
if (!Application.isEditor && Config.Graphics.MultiSampling > 0)
|
||||
{
|
||||
std::vector<int> samples;
|
||||
[self enumerateMultiSamples:samples];
|
||||
if (!samples.empty())
|
||||
{
|
||||
attribs.push_back(NSOpenGLPFAMultisample);
|
||||
attribs.push_back(NSOpenGLPFASampleBuffers);
|
||||
attribs.push_back(1);
|
||||
attribs.push_back(NSOpenGLPFASamples);
|
||||
attribs.push_back(Config.Graphics.MultiSampling);
|
||||
}
|
||||
}
|
||||
attribs.push_back(NSOpenGLPFANoRecovery);
|
||||
//attribs.push_back(NSOpenGLPFADoubleBuffer);
|
||||
attribs.push_back(NSOpenGLPFAWindow);
|
||||
attribs.push_back(0);
|
||||
NSOpenGLPixelFormat* format = [[[NSOpenGLPixelFormat alloc] initWithAttributes:&attribs[0]] autorelease];
|
||||
|
||||
NSOpenGLContext* result = [[NSOpenGLContext alloc] initWithFormat:format shareContext:pMainCtx ? (NSOpenGLContext*)pMainCtx->GetNativeCtx() : nil];
|
||||
[self setSurfaceBackingSizeOf:result width:Config.Graphics.ResX height:Config.Graphics.ResY];
|
||||
if (!MainContext)
|
||||
{
|
||||
MainContext = result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation ClonkEditorOpenGLView
|
||||
|
@ -396,14 +473,14 @@ int32_t mouseButtonFromEvent(NSEvent* event, DWORD& modifierFlags)
|
|||
|
||||
@end
|
||||
|
||||
// Implementation of some CStdGLCtx methods - fits here, more or less
|
||||
#pragma mark CStdGLCtx: Initialization
|
||||
|
||||
void* CStdGLCtx::GetNativeCtx()
|
||||
{
|
||||
return ctx;
|
||||
}
|
||||
|
||||
CStdGLCtx::CStdGLCtx(): pWindow(0), ctx(nil), cx(0), cy(0) {}
|
||||
CStdGLCtx::CStdGLCtx(): pWindow(0), ctx(nil) {}
|
||||
|
||||
void CStdGLCtx::Clear()
|
||||
{
|
||||
|
@ -414,29 +491,26 @@ void CStdGLCtx::Clear()
|
|||
ctx = nil;
|
||||
}
|
||||
pWindow = 0;
|
||||
cx = cy = 0;
|
||||
}
|
||||
|
||||
NSOpenGLContext* CreateCocoaContext(CStdGLCtx* pMainCtx, NSOpenGLPixelFormat* format)
|
||||
void CStdWindow::EnumerateMultiSamples(std::vector<int>& samples) const
|
||||
{
|
||||
if (!format)
|
||||
{
|
||||
NSOpenGLPixelFormatAttribute attrs[] = {
|
||||
NSOpenGLPFADepthSize, 16,
|
||||
0
|
||||
};
|
||||
format = [[[NSOpenGLPixelFormat alloc] initWithAttributes:attrs] autorelease];
|
||||
}
|
||||
NSOpenGLContext* result = [[NSOpenGLContext alloc] initWithFormat:format shareContext:pMainCtx ? (NSOpenGLContext*)pMainCtx->GetNativeCtx() : nil];
|
||||
if (!Application.isEditor)
|
||||
{
|
||||
// Make back buffer size fixed ( http://developer.apple.com/library/mac/#documentation/GraphicsImaging/Conceptual/OpenGL-MacProgGuide/opengl_contexts/opengl_contexts.html )
|
||||
GLint dim[2] = {Config.Graphics.ResX, Config.Graphics.ResY};
|
||||
CGLContextObj ctx = (CGLContextObj)result.CGLContextObj;
|
||||
CGLSetParameter(ctx, kCGLCPSurfaceBackingSize, dim);
|
||||
CGLEnable (ctx, kCGLCESurfaceBackingSize);
|
||||
}
|
||||
return result;
|
||||
[ClonkOpenGLView enumerateMultiSamples:samples];
|
||||
}
|
||||
|
||||
bool CStdApp::SetVideoMode(unsigned int iXRes, unsigned int iYRes, unsigned int iColorDepth, unsigned int iMonitor, bool fFullScreen)
|
||||
{
|
||||
pWindow->SetSize(iXRes, iYRes);
|
||||
ClonkWindowController* controller = (ClonkWindowController*)pWindow->GetController();
|
||||
[controller setFullscreen:fFullScreen];
|
||||
NSWindow* window = controller.window;
|
||||
[window center];
|
||||
[window setContentMinSize:NSMakeSize(iXRes, iYRes)];
|
||||
[window setContentMaxSize:NSMakeSize(iXRes, iYRes)];
|
||||
if (!fFullScreen)
|
||||
[window makeKeyAndOrderFront:nil];
|
||||
OnResolutionChanged(iXRes, iYRes);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CStdGLCtx::Init(CStdWindow * pWindow, CStdApp *)
|
||||
|
@ -447,7 +521,7 @@ bool CStdGLCtx::Init(CStdWindow * pWindow, CStdApp *)
|
|||
this->pWindow = pWindow;
|
||||
// Create Context with sharing (if this is the main context, our ctx will be 0, so no sharing)
|
||||
// try direct rendering first
|
||||
NSOpenGLContext* ctx = CreateCocoaContext(pGL->pMainCtx, nil);//[NSOpenGLView defaultPixelFormat]);
|
||||
NSOpenGLContext* ctx = [ClonkOpenGLView createContext:pGL->pMainCtx];
|
||||
this->ctx = (void*)ctx;
|
||||
// No luck at all?
|
||||
if (!Select(true)) return pGL->Error(" gl: Unable to select context");
|
||||
|
@ -467,6 +541,8 @@ bool CStdGLCtx::Init(CStdWindow * pWindow, CStdApp *)
|
|||
return true;
|
||||
}
|
||||
|
||||
#pragma mark CStdGLCtx: Select/Deselect
|
||||
|
||||
bool CStdGLCtx::Select(bool verbose)
|
||||
{
|
||||
if (ctx)
|
||||
|
@ -491,26 +567,6 @@ void CStdGLCtx::Deselect()
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
bool CStdGLCtx::UpdateSize()
|
||||
{
|
||||
// safety
|
||||
if (!pWindow) return false;
|
||||
// get size
|
||||
RECT rc;
|
||||
pWindow->GetSize(&rc);
|
||||
int width = rc.right - rc.left, height = rc.bottom - rc.top;
|
||||
// assign if different
|
||||
if (cx!=width || cy!=height)
|
||||
{
|
||||
cx=width; cy=height;
|
||||
if (pGL) pGL->UpdateClipper();
|
||||
}
|
||||
// success
|
||||
return true;
|
||||
}
|
||||
*/
|
||||
|
||||
bool CStdGLCtx::PageFlip()
|
||||
{
|
||||
// flush GL buffer
|
||||
|
@ -520,6 +576,8 @@ bool CStdGLCtx::PageFlip()
|
|||
return true;
|
||||
}
|
||||
|
||||
#pragma mark CStdGLCtx: Gamma
|
||||
|
||||
namespace
|
||||
{
|
||||
class GammaRampConversionTable
|
||||
|
@ -554,7 +612,7 @@ bool CStdGL::ApplyGammaRamp(_D3DGAMMARAMP& ramp, bool fForce)
|
|||
g[i] = GammaRampConversionTable::singleton.green[ramp.green[i]];
|
||||
b[i] = GammaRampConversionTable::singleton.blue[ramp.blue[i]];
|
||||
}
|
||||
CGSetDisplayTransferByTable((CGDirectDisplayID)[[[[[NSApp keyWindow] screen] deviceDescription] valueForKey:@"NSScreenNumber"] intValue], 256, r, g, b);
|
||||
CGSetDisplayTransferByTable(ClonkOpenGLView.displayID, 256, r, g, b);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ bool CStdApp::Copy(const StdStrBuf & text, bool fClipboard)
|
|||
NSString* string = [NSString stringWithCString:text.getData() encoding:NSUTF8StringEncoding];
|
||||
if (![pasteboard setString:string forType:NSStringPboardType])
|
||||
{
|
||||
NSLog(@"Writing to Cocoa pasteboard failed");
|
||||
Log("Writing to Cocoa pasteboard failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
@ -155,21 +155,6 @@ bool CStdApp::GetIndexedDisplayMode(int32_t iIndex, int32_t *piXRes, int32_t *pi
|
|||
return good_index;
|
||||
}
|
||||
|
||||
bool CStdApp::SetVideoMode(unsigned int iXRes, unsigned int iYRes, unsigned int iColorDepth, unsigned int iMonitor, bool fFullScreen)
|
||||
{
|
||||
pWindow->SetSize(iXRes, iYRes);
|
||||
ClonkWindowController* controller = (ClonkWindowController*)pWindow->GetController();
|
||||
[controller setFullscreen:fFullScreen];
|
||||
NSWindow* window = controller.window;
|
||||
[window center];
|
||||
[window setContentMinSize:NSMakeSize(iXRes, iYRes)];
|
||||
[window setContentMaxSize:NSMakeSize(iXRes, iYRes)];
|
||||
if (!fFullScreen)
|
||||
[window makeKeyAndOrderFront:nil];
|
||||
OnResolutionChanged(iXRes, iYRes);
|
||||
return true;
|
||||
}
|
||||
|
||||
void CStdApp::RestoreVideoMode()
|
||||
{
|
||||
}
|
||||
|
|
|
@ -133,6 +133,11 @@ void CStdWindow::RequestUpdate()
|
|||
[ctrler.openGLView display];
|
||||
}
|
||||
|
||||
bool CStdWindow::ReInit(CStdApp* pApp)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
int K_F1 = 122 + CocoaKeycodeOffset;
|
||||
int K_F2 = 120 + CocoaKeycodeOffset;
|
||||
int K_F3 = 99 + CocoaKeycodeOffset;
|
||||
|
|
Loading…
Reference in New Issue