Skip to content

Commit e473df4

Browse files
committed
More CCGLView cleanup.
1 parent ea53e27 commit e473df4

File tree

3 files changed

+25
-28
lines changed

3 files changed

+25
-28
lines changed

CCRendererGLSupport.m

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -374,13 +374,11 @@ -(void)bind
374374

375375
-(void)syncWithView:(CC_VIEW<CCDirectorView> *)view;
376376
{
377-
#warning TODO this won't work for Mac. Need to expand the view protocol.
378377
CCGLView *glView = (CCGLView *)view;
379378
self.sizeInPixels = CC_SIZE_SCALE(view.bounds.size, view.contentScaleFactor);
380379
self.contentScale = view.contentScaleFactor;
381380

382-
#warning TODO does this need to handle MSAA specially?
383-
_fbo = glView.defaultFramebuffer;
381+
_fbo = glView.fbo;
384382
}
385383

386384
@end

cocos2d/Platforms/iOS/CCGLView.h

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -102,20 +102,6 @@ Copyright (C) 2008 Apple Inc. All Rights Reserved.
102102
- Possible values: 0 to glGetIntegerv(GL_MAX_SAMPLES_APPLE)
103103
*/
104104
@interface CCGLView : UIView <CCDirectorView>
105-
{
106-
EAGLContext *_context;
107-
108-
NSString *_pixelFormat;
109-
GLuint _depthFormat;
110-
BOOL _preserveBackbuffer;
111-
112-
CGSize _size;
113-
BOOL _discardFramebufferSupported;
114-
115-
//fsaa addition
116-
BOOL _multisampling;
117-
unsigned int _requestedSamples;
118-
}
119105

120106
/** creates an initializes an CCGLView with a frame and 0-bit depth buffer, and a RGB565 color buffer. */
121107
+ (id) viewWithFrame:(CGRect)frame;
@@ -146,7 +132,7 @@ Copyright (C) 2008 Apple Inc. All Rights Reserved.
146132

147133
@property(nonatomic,readwrite) BOOL multiSampling;
148134

149-
@property(nonatomic, readonly) GLuint defaultFramebuffer;
135+
@property(nonatomic, readonly) GLuint fbo;
150136

151137
@end
152138

cocos2d/Platforms/iOS/CCGLView.m

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,16 @@ -(BOOL)isComplete
148148
@end
149149

150150
@implementation CCGLView {
151-
CCTouchEvent* _touchEvent;
151+
CCTouchEvent* _touchEvent;
152152
NSMutableArray *_fences;
153153

154+
EAGLContext *_context;
155+
156+
NSString *_pixelFormat;
157+
GLuint _depthFormat;
158+
BOOL _preserveBackbuffer;
159+
BOOL _discardFramebufferSupported;
160+
154161
GLuint _depthBuffer;
155162
GLuint _colorRenderbuffer;
156163
GLuint _defaultFramebuffer;
@@ -205,9 +212,12 @@ - (id) initWithFrame:(CGRect)frame pixelFormat:(NSString*)format depthFormat:(GL
205212
_pixelFormat = format;
206213
_depthFormat = depth;
207214
_multiSampling = sampling;
208-
_requestedSamples = nSamples;
209215
_preserveBackbuffer = retained;
210216

217+
GLint maxSamplesAllowed;
218+
glGetIntegerv(GL_MAX_SAMPLES_APPLE, &maxSamplesAllowed);
219+
_msaaSamples = MIN(maxSamplesAllowed, nSamples);
220+
211221
// Default to "retina" being enabled.
212222
self.contentScaleFactor = [UIScreen mainScreen].scale;
213223

@@ -236,8 +246,7 @@ -(id) initWithCoder:(NSCoder *)aDecoder
236246
_pixelFormat = kEAGLColorFormatRGB565;
237247
_depthFormat = 0; // GL_DEPTH_COMPONENT24;
238248
_multiSampling= NO;
239-
_requestedSamples = 0;
240-
_size = [eaglLayer bounds].size;
249+
_msaaSamples = 0;
241250

242251
if( ! [self setupSurfaceWithSharegroup:nil] ) {
243252
return nil;
@@ -280,10 +289,6 @@ -(BOOL) setupSurfaceWithSharegroup:(EAGLSharegroup*)sharegroup
280289
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, _colorRenderbuffer);
281290

282291
if (_multiSampling){
283-
GLint maxSamplesAllowed;
284-
glGetIntegerv(GL_MAX_SAMPLES_APPLE, &maxSamplesAllowed);
285-
_msaaSamples = MIN(maxSamplesAllowed, _requestedSamples);
286-
287292
/* Create the MSAA framebuffer (offscreen) */
288293
glGenFramebuffers(1, &_msaaFramebuffer);
289294
glBindFramebuffer(GL_FRAMEBUFFER, _msaaFramebuffer);
@@ -359,11 +364,10 @@ -(void)resizeFromLayer:(CAEAGLLayer *)layer
359364
- (void) layoutSubviews
360365
{
361366
[self resizeFromLayer:(CAEAGLLayer*)self.layer];
362-
_size = CGSizeMake( _backingWidth, _backingHeight);
363367

364368
// Issue #914 #924
365369
CCDirector *director = [CCDirector sharedDirector];
366-
[director reshapeProjection:_size];
370+
[director reshapeProjection:CGSizeMake( _backingWidth, _backingHeight)];
367371

368372
// Avoid flicker. Issue #350
369373
// Only draw if there is something to draw, otherwise it actually creates a flicker of the current glClearColor
@@ -477,6 +481,15 @@ -(void)presentFrame
477481
CC_CHECK_GL_ERROR_DEBUG();
478482
}
479483

484+
-(GLuint)fbo
485+
{
486+
if(_multiSampling){
487+
return _msaaFramebuffer;
488+
} else {
489+
return _defaultFramebuffer;
490+
}
491+
}
492+
480493
-(GLenum)convertPixelFormat:(NSString*)pixelFormat
481494
{
482495
if([pixelFormat isEqualToString:@"EAGLColorFormat565"]){

0 commit comments

Comments
 (0)