@@ -213,10 +213,7 @@ - (id) initWithFrame:(CGRect)frame pixelFormat:(NSString*)format depthFormat:(GL
213
213
_depthFormat = depth;
214
214
_multiSampling = sampling;
215
215
_preserveBackbuffer = retained;
216
-
217
- GLint maxSamplesAllowed;
218
- glGetIntegerv (GL_MAX_SAMPLES_APPLE, &maxSamplesAllowed);
219
- _msaaSamples = MIN (maxSamplesAllowed, nSamples);
216
+ _msaaSamples = nSamples;
220
217
221
218
// Default to "retina" being enabled.
222
219
self.contentScaleFactor = [UIScreen mainScreen ].scale ;
@@ -281,10 +278,9 @@ -(BOOL) setupSurfaceWithSharegroup:(EAGLSharegroup*)sharegroup
281
278
CCRenderDispatch (NO , ^{
282
279
// Create default framebuffer object. The backing will be allocated for the current layer in -resizeFromLayer
283
280
glGenFramebuffers (1 , &_defaultFramebuffer);
284
-
285
- glGenRenderbuffers (1 , &_colorRenderbuffer);
286
-
287
281
glBindFramebuffer (GL_FRAMEBUFFER, _defaultFramebuffer);
282
+
283
+ glGenRenderbuffers (1 , &_colorRenderbuffer);
288
284
glBindRenderbuffer (GL_RENDERBUFFER, _colorRenderbuffer);
289
285
glFramebufferRenderbuffer (GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, _colorRenderbuffer);
290
286
@@ -313,6 +309,10 @@ - (void) dealloc
313
309
-(void )resizeFromLayer : (CAEAGLLayer *)layer
314
310
{
315
311
CCRenderDispatch (NO , ^{
312
+ GLint maxSamples;
313
+ glGetIntegerv (GL_MAX_SAMPLES_APPLE, &maxSamples);
314
+ GLint msaaSamples = MIN (maxSamples, _msaaSamples);
315
+
316
316
glBindRenderbuffer (GL_RENDERBUFFER, _colorRenderbuffer);
317
317
318
318
// Allocate color buffer backing based on the current layer size
@@ -329,21 +329,19 @@ -(void)resizeFromLayer:(CAEAGLLayer *)layer
329
329
glGenRenderbuffers (1 , &_msaaColorbuffer);
330
330
331
331
glBindRenderbuffer (GL_RENDERBUFFER, _msaaColorbuffer);
332
- glRenderbufferStorageMultisampleAPPLE (GL_RENDERBUFFER, _msaaSamples , [self convertPixelFormat: _pixelFormat] , _backingWidth, _backingHeight);
332
+ glRenderbufferStorageMultisampleAPPLE (GL_RENDERBUFFER, msaaSamples , [self convertPixelFormat: _pixelFormat] , _backingWidth, _backingHeight);
333
333
334
334
glFramebufferRenderbuffer (GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, _msaaColorbuffer);
335
335
}
336
336
337
- CC_CHECK_GL_ERROR_DEBUG ();
338
-
339
337
if (_depthFormat){
340
338
glDeleteRenderbuffers (1 , &_depthBuffer);
341
339
glGenRenderbuffers (1 , &_depthBuffer);
342
340
343
341
glBindRenderbuffer (GL_RENDERBUFFER, _depthBuffer);
344
342
345
343
if (_multiSampling){
346
- glRenderbufferStorageMultisampleAPPLE (GL_RENDERBUFFER, _msaaSamples , _depthFormat,_backingWidth, _backingHeight);
344
+ glRenderbufferStorageMultisampleAPPLE (GL_RENDERBUFFER, msaaSamples , _depthFormat,_backingWidth, _backingHeight);
347
345
} else {
348
346
glRenderbufferStorage (GL_RENDERBUFFER, _depthFormat, _backingWidth, _backingHeight);
349
347
}
@@ -411,11 +409,6 @@ -(void)beginFrame {}
411
409
412
410
-(void )presentFrame
413
411
{
414
- // IMPORTANT:
415
- // - preconditions
416
- // -> _context MUST be the OpenGL context
417
- // -> renderbuffer_ must be the the RENDER BUFFER
418
-
419
412
{
420
413
CCGLViewFence *fence = _fences.lastObject ;
421
414
if (fence.isReady ){
@@ -424,47 +417,33 @@ -(void)presentFrame
424
417
}
425
418
}
426
419
427
- if (_multiSampling)
428
- {
429
- /* Resolve from msaaFramebuffer to resolveFramebuffer */
430
- // glDisable(GL_SCISSOR_TEST);
420
+ if (_multiSampling){
431
421
glBindFramebuffer (GL_READ_FRAMEBUFFER_APPLE, _msaaFramebuffer);
432
422
glBindFramebuffer (GL_DRAW_FRAMEBUFFER_APPLE, _defaultFramebuffer);
433
423
glResolveMultisampleFramebufferAPPLE ();
434
424
}
435
425
436
- if ( _discardFramebufferSupported)
437
- {
438
- if (_multiSampling)
439
- {
440
- if (_depthFormat)
441
- {
426
+ if (_discardFramebufferSupported){
427
+ if (_multiSampling){
428
+ if (_depthFormat){
442
429
GLenum attachments[] = {GL_COLOR_ATTACHMENT0, GL_DEPTH_ATTACHMENT};
443
430
glDiscardFramebufferEXT (GL_READ_FRAMEBUFFER_APPLE, 2 , attachments);
444
- }
445
- else
446
- {
431
+ } else {
447
432
GLenum attachments[] = {GL_COLOR_ATTACHMENT0};
448
433
glDiscardFramebufferEXT (GL_READ_FRAMEBUFFER_APPLE, 1 , attachments);
449
434
}
450
- }
451
-
452
- // not MSAA
453
- else if (_depthFormat ) {
435
+ } else if (_depthFormat){
454
436
GLenum attachments[] = { GL_DEPTH_ATTACHMENT};
455
437
glDiscardFramebufferEXT (GL_FRAMEBUFFER, 1 , attachments);
456
438
}
457
439
}
458
440
459
441
glBindRenderbuffer (GL_RENDERBUFFER, _colorRenderbuffer);
460
-
461
442
if (![_context presentRenderbuffer: GL_RENDERBUFFER]){
462
443
CCLOG (@" cocos2d: Failed to swap renderbuffer in %s \n " , __FUNCTION__);
463
444
}
464
445
465
- // We can safely re-bind the framebuffer here, since this will be the
466
- // 1st instruction of the new main loop
467
- if ( _multiSampling ){
446
+ if (_multiSampling){
468
447
glBindFramebuffer (GL_FRAMEBUFFER, _msaaFramebuffer);
469
448
}
470
449
0 commit comments