Commit 23f6ba79 authored by David Gobbi's avatar David Gobbi

Implement multi-sample antialiasing on OS X.

Set the necessary attributes to create a sample buffer for the
OpenGL context of the vtkCocoaRenderWindow.  This allows VTK to
do anti-aliased rendering in the window.  However, multisampling
is turned off by default on OS X because it causes rendering
problems on some Mac models.

Change-Id: I0ff8073e38d8a63e637cfe4e7146e2d1327d65eb
parent 48825a25
......@@ -37,7 +37,6 @@ int TestMultipleRenderers(int , char * [])
{
VTK_CREATE(vtkRenderWindow, renwin);
renwin->SetMultiSamples(4);
renwin->SetSize(800, 640);
VTK_CREATE(vtkRenderWindowInteractor, iren);
......
......@@ -232,7 +232,6 @@ vtkCarbonRenderWindow::vtkCarbonRenderWindow()
this->Internal = new vtkCarbonRenderWindowInternal(this);
this->ApplicationInitialized = 0;
this->ContextId = 0;
this->MultiSamples = 0;
this->WindowId = 0;
this->ParentId = 0;
this->RootWindow = 0;
......
......@@ -56,7 +56,6 @@ vtkCocoaRenderWindow::vtkCocoaRenderWindow()
this->WindowCreated = 0;
this->ViewCreated = 0;
this->MultiSamples = 8;
this->SetWindowName("Visualization Toolkit - Cocoa");
this->CursorHidden = 0;
this->ForceMakeCurrent = 0;
......@@ -728,19 +727,58 @@ void vtkCocoaRenderWindow::CreateAWindow()
//----------------------------------------------------------------------------
void vtkCocoaRenderWindow::CreateGLContext()
{
NSOpenGLPixelFormatAttribute attribs[] =
// keep trying to get different pixelFormats until successful
NSOpenGLPixelFormat* pixelFormat = nil;
while (pixelFormat == nil)
{
NSOpenGLPFAAccelerated,
NSOpenGLPFADepthSize,
(NSOpenGLPixelFormatAttribute)32,
(this->DoubleBuffer != 0) ?
(NSOpenGLPixelFormatAttribute)NSOpenGLPFADoubleBuffer :
(NSOpenGLPixelFormatAttribute)nil,
(NSOpenGLPixelFormatAttribute)nil
};
NSOpenGLPixelFormat* pixelFormat = [[[NSOpenGLPixelFormat alloc]
initWithAttributes:attribs] autorelease];
int i = 0;
NSOpenGLPixelFormatAttribute attribs[20];
attribs[i++] = NSOpenGLPFAAccelerated;
attribs[i++] = NSOpenGLPFADepthSize;
attribs[i++] = (NSOpenGLPixelFormatAttribute)32;
if (this->MultiSamples != 0)
{
attribs[i++] = NSOpenGLPFASampleBuffers;
attribs[i++] = (NSOpenGLPixelFormatAttribute)1;
attribs[i++] = NSOpenGLPFASamples;
attribs[i++] = (NSOpenGLPixelFormatAttribute)(this->MultiSamples);
attribs[i++] = NSOpenGLPFAMultisample;
}
if (this->DoubleBuffer != 0)
{
attribs[i++] = NSOpenGLPFADoubleBuffer;
}
attribs[i++] = (NSOpenGLPixelFormatAttribute)0;
// make sure that size of array was not exceeded
assert(sizeof(NSOpenGLPixelFormatAttribute)*i < sizeof(attribs));
pixelFormat = [[[NSOpenGLPixelFormat alloc]
initWithAttributes:attribs] autorelease];
if (pixelFormat == nil)
{
if (this->MultiSamples == 0)
{
// after trying with no multisamples, we are done
break;
}
else if (this->MultiSamples < 4)
{
// next time try with no multisamples
this->MultiSamples = 0;
}
else
{
this->MultiSamples /= 2;
}
}
}
NSOpenGLContext* context = [[[NSOpenGLContext alloc]
initWithFormat:pixelFormat
shareContext:nil] autorelease];
......
......@@ -39,7 +39,12 @@ vtkCxxSetObjectMacro(vtkOpenGLRenderWindow, HardwareSupport, vtkOpenGLHardwareSu
vtkCxxSetObjectMacro(vtkOpenGLRenderWindow, TextureUnitManager, vtkTextureUnitManager);
// Initialize static member that controls global maximum number of multisamples
// (off by default on Apple because it causes problems on some Mac models).
#if defined(__APPLE__)
static int vtkOpenGLRenderWindowGlobalMaximumNumberOfMultiSamples = 0;
#else
static int vtkOpenGLRenderWindowGlobalMaximumNumberOfMultiSamples = 8;
#endif
// ----------------------------------------------------------------------------
void vtkOpenGLRenderWindow::SetGlobalMaximumNumberOfMultiSamples(int val)
......
......@@ -45,7 +45,6 @@ vtkWin32OpenGLRenderWindow::vtkWin32OpenGLRenderWindow()
this->ApplicationInstance = NULL;
this->Palette = NULL;
this->ContextId = 0;
this->MultiSamples = 8;
this->WindowId = 0;
this->ParentId = 0;
this->NextWindowId = 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment