• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
CAOpenGLLayer no Antialiasing?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

CAOpenGLLayer no Antialiasing?


  • Subject: CAOpenGLLayer no Antialiasing?
  • From: Nik Youdale <email@hidden>
  • Date: Sat, 8 Nov 2008 13:13:14 +1100

Hi,

I am having trouble enabling antialiasing in a CAOpenGLLayer subclass. Specifically I am trying to use Multisampling. I have set up the pixel format with multisampling enabled, etc. The same rendering code works in an NSOpenGLView with multisampling setup in the pixel format. (It draws in the CAOpenGLLayer, but sadly no antialiasing).

As far as i can tell, both segments of code (see below) should do exactly the same thing. Is there something obvious i'm missing? Or is it stated somewhere that CAOpenGLLayers don't support multisampling?

Cheers
- Nik




Code for CAOpenGLLayer:

@implementation MyOpenGLLayer

- (id) init
{
	self = [super init];
	if (self != nil) {
		self.needsDisplayOnBoundsChange = YES;
	}
	return self;
}


- (BOOL)isAsynchronous { return YES; }

- (CGLPixelFormatObj)copyCGLPixelFormatForDisplayMask:(uint32_t)mask {
	CGLPixelFormatAttribute attributes[] =
	{
		//kCGLPFADisplayMask, mask,
		kCGLPFAColorSize, 24,
		kCGLPFAAlphaSize, 8,
		kCGLPFADepthSize, 16,
		kCGLPFANoRecovery,
		kCGLPFAMultisample,
		kCGLPFASampleBuffers, 1,
		kCGLPFASamples, 4,
		0
	};
	CGLPixelFormatObj pixelFormatObj = NULL;
	GLint numPixelFormats = 0;
	CGLChoosePixelFormat(attributes, &pixelFormatObj, &numPixelFormats);
	if(pixelFormatObj == NULL)
		NSLog(@"Error: Could not choose pixel format!");
	return pixelFormatObj;
}

- (void)drawInCGLContext:(CGLContextObj)glContext pixelFormat: (CGLPixelFormatObj)pixelFormat forLayerTime: (CFTimeInterval)timeInterval displayTime:(const CVTimeStamp *)timeStamp
{
CGLSetCurrentContext(glContext);

glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);

glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

glEnable(GL_MULTISAMPLE);

glColor4d(1.0, 0.0, 0.0, 1.0);
glBegin(GL_TRIANGLES);
glVertex3f(0.0, 0.0, 0.0);
glVertex3f(0.0, 1.0, 0.0);
glVertex3f(1.0, 0.0, 0.0);
glEnd();

glFlush();
}


@end



Code for NSOpenGLView:

@implementation MyOpenGLView

- (id) initWithFrame: (NSRect) frame
{
NSOpenGLPixelFormatAttribute attribs[] = {
NSOpenGLPFAWindow,
NSOpenGLPFANoRecovery,
NSOpenGLPFASampleBuffers, 1,
NSOpenGLPFASamples, 4,
NSOpenGLPFADoubleBuffer,
NSOpenGLPFAColorSize, 24,
NSOpenGLPFAAlphaSize, 8,
NSOpenGLPFADepthSize, 24,
0
};

NSOpenGLPixelFormat *fmt = [[NSOpenGLPixelFormat alloc] initWithAttributes:attribs];

if (!fmt)
NSLog(@"No OpenGL pixel format");

return self = [super initWithFrame:frame pixelFormat:[fmt autorelease]];
}


- (void)drawRect:(NSRect)rect {
    // Drawing code here.
	glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
	glClear(GL_COLOR_BUFFER_BIT);

	glEnable(GL_MULTISAMPLE);

	glColor4d(1.0, 0.0, 0.0, 1.0);
	glBegin(GL_TRIANGLES);
	glVertex3f(0.0, 0.0, 0.0);
	glVertex3f(0.0, 1.0, 0.0);
	glVertex3f(1.0, 0.0, 0.0);
	glEnd();

	[[self openGLContext] flushBuffer];
}

@end

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: CAOpenGLLayer no Antialiasing?
      • From: David Duncan <email@hidden>
  • Prev by Date: IKImageView disappears while moving it in NSWindow (IB 3.1.1)
  • Next by Date: MVC Question . . .
  • Previous by thread: IKImageView disappears while moving it in NSWindow (IB 3.1.1)
  • Next by thread: Re: CAOpenGLLayer no Antialiasing?
  • Index(es):
    • Date
    • Thread