update some files in platfomr/iphone to 0.99.5

This commit is contained in:
minggo 2010-12-30 14:22:25 +08:00
parent da00d82117
commit 88de01d915
5 changed files with 418 additions and 267 deletions

View File

@ -84,9 +84,14 @@ Copyright (C) 2008 Apple Inc. All Rights Reserved.
NSString *pixelformat_; NSString *pixelformat_;
GLuint depthFormat_; GLuint depthFormat_;
BOOL preserveBackbuffer_;
CGSize size_; CGSize size_;
BOOL discardFramebufferSupported_; BOOL discardFramebufferSupported_;
//fsaa addition
BOOL multisampling_;
unsigned int requestedSamples_;
@private @private
CFMutableDictionaryRef touchesIntergerDict; CFMutableDictionaryRef touchesIntergerDict;
unsigned int indexBitsUsed; unsigned int indexBitsUsed;
@ -98,6 +103,9 @@ Copyright (C) 2008 Apple Inc. All Rights Reserved.
+ (id) viewWithFrame:(CGRect)frame pixelFormat:(NSString*)format; + (id) viewWithFrame:(CGRect)frame pixelFormat:(NSString*)format;
/** creates an initializes an EAGLView with a frame, a color buffer format, and a depth buffer format */ /** creates an initializes an EAGLView with a frame, a color buffer format, and a depth buffer format */
+ (id) viewWithFrame:(CGRect)frame pixelFormat:(NSString*)format depthFormat:(GLuint)depth preserveBackbuffer:(BOOL)retained; + (id) viewWithFrame:(CGRect)frame pixelFormat:(NSString*)format depthFormat:(GLuint)depth preserveBackbuffer:(BOOL)retained;
/** creates an initializes an EAGLView with a frame, a color buffer format, a depth buffer format, a sharegroup, and multisamping */
+ (id) viewWithFrame:(CGRect)frame pixelFormat:(NSString*)format depthFormat:(GLuint)depth preserveBackbuffer:(BOOL)retained sharegroup:(EAGLSharegroup*)sharegroup multiSampling:(BOOL)multisampling numberOfSamples:(unsigned int)samples;
// get the view object // get the view object
+(id) sharedEGLView; +(id) sharedEGLView;
@ -105,8 +113,8 @@ Copyright (C) 2008 Apple Inc. All Rights Reserved.
- (id) initWithFrame:(CGRect)frame; //These also set the current context - (id) initWithFrame:(CGRect)frame; //These also set the current context
/** Initializes an EAGLView with a frame, a color buffer format, and 0-bit depth buffer */ /** Initializes an EAGLView with a frame, a color buffer format, and 0-bit depth buffer */
- (id) initWithFrame:(CGRect)frame pixelFormat:(NSString*)format; - (id) initWithFrame:(CGRect)frame pixelFormat:(NSString*)format;
/** Initializes an EAGLView with a frame, a color buffer format, and a depth buffer format */ /** Initializes an EAGLView with a frame, a color buffer format, a depth buffer format, a sharegroup and multisampling support */
- (id) initWithFrame:(CGRect)frame pixelFormat:(NSString*)format depthFormat:(GLuint)depth preserveBackbuffer:(BOOL)retained; - (id) initWithFrame:(CGRect)frame pixelFormat:(NSString*)format depthFormat:(GLuint)depth preserveBackbuffer:(BOOL)retained sharegroup:(EAGLSharegroup*)sharegroup multiSampling:(BOOL)sampling numberOfSamples:(unsigned int)nSamples;
/** pixel format: it could be RGBA8 (32-bit) or RGB565 (16-bit) */ /** pixel format: it could be RGBA8 (32-bit) or RGB565 (16-bit) */
@property(nonatomic,readonly) NSString* pixelFormat; @property(nonatomic,readonly) NSString* pixelFormat;
@ -119,6 +127,8 @@ Copyright (C) 2008 Apple Inc. All Rights Reserved.
/** OpenGL context */ /** OpenGL context */
@property(nonatomic,readonly) EAGLContext *context; @property(nonatomic,readonly) EAGLContext *context;
@property(nonatomic,readwrite) BOOL multiSampling;
@property(readonly) CFMutableDictionaryRef touchesIntergerDict; @property(readonly) CFMutableDictionaryRef touchesIntergerDict;
@property(readwrite) unsigned int indexBitsUsed; @property(readwrite) unsigned int indexBitsUsed;

View File

@ -77,7 +77,8 @@ static EAGLView *view;
static cocos2d::CCTouch *s_pTouches[MAX_TOUCHES]; static cocos2d::CCTouch *s_pTouches[MAX_TOUCHES];
@interface EAGLView (Private) @interface EAGLView (Private)
-(BOOL) setupSurface; - (BOOL) setupSurfaceWithSharegroup:(EAGLSharegroup*)sharegroup;
- (unsigned int) convertPixelFormat:(NSString*) pixelFormat;
@end @end
@implementation EAGLView @implementation EAGLView
@ -87,6 +88,7 @@ static cocos2d::CCTouch *s_pTouches[MAX_TOUCHES];
@synthesize context=context_; @synthesize context=context_;
@synthesize touchesIntergerDict; @synthesize touchesIntergerDict;
@synthesize indexBitsUsed; @synthesize indexBitsUsed;
@synthesize multiSampling=multiSampling_;
+ (Class) layerClass + (Class) layerClass
{ {
@ -95,17 +97,22 @@ static cocos2d::CCTouch *s_pTouches[MAX_TOUCHES];
+ (id) viewWithFrame:(CGRect)frame + (id) viewWithFrame:(CGRect)frame
{ {
return [[[self alloc] initWithFrame:frame] autorelease]; return [[[[self alloc] init] initWithFrame:frame] autorelease];
} }
+ (id) viewWithFrame:(CGRect)frame pixelFormat:(NSString*)format + (id) viewWithFrame:(CGRect)frame pixelFormat:(NSString*)format
{ {
return [[[self alloc] initWithFrame:frame pixelFormat:format] autorelease]; return [[[[self alloc] init] initWithFrame:frame pixelFormat:format] autorelease];
} }
+ (id) viewWithFrame:(CGRect)frame pixelFormat:(NSString*)format depthFormat:(GLuint)depth preserveBackbuffer:(BOOL)retained + (id) viewWithFrame:(CGRect)frame pixelFormat:(NSString*)format depthFormat:(GLuint)depth
{ {
return [[[[self alloc] init]initWithFrame:frame pixelFormat:format depthFormat:depth preserveBackbuffer:retained] autorelease]; return [[[[self alloc] init] initWithFrame:frame pixelFormat:format depthFormat:depth preserveBackbuffer:NO sharegroup:nil multiSampling:NO numberOfSamples:0] autorelease];
}
+ (id) viewWithFrame:(CGRect)frame pixelFormat:(NSString*)format depthFormat:(GLuint)depth preserveBackbuffer:(BOOL)retained sharegroup:(EAGLSharegroup*)sharegroup multiSampling:(BOOL)multisampling numberOfSamples:(unsigned int)samples
{
return [[[[self alloc] init] initWithFrame:frame pixelFormat:format depthFormat:depth preserveBackbuffer:retained sharegroup:sharegroup multiSampling:multisampling numberOfSamples:samples] autorelease];
} }
+ (id) sharedEGLView + (id) sharedEGLView
@ -122,12 +129,12 @@ static cocos2d::CCTouch *s_pTouches[MAX_TOUCHES];
- (id) initWithFrame:(CGRect)frame - (id) initWithFrame:(CGRect)frame
{ {
return [self initWithFrame:frame pixelFormat:kEAGLColorFormatRGB565 depthFormat:0 preserveBackbuffer:NO]; return [self initWithFrame:frame pixelFormat:kEAGLColorFormatRGB565 depthFormat:0 preserveBackbuffer:NO sharegroup:nil multiSampling:NO numberOfSamples:0];
} }
- (id) initWithFrame:(CGRect)frame pixelFormat:(NSString*)format - (id) initWithFrame:(CGRect)frame pixelFormat:(NSString*)format
{ {
return [self initWithFrame:frame pixelFormat:format depthFormat:0 preserveBackbuffer:NO]; return [self initWithFrame:frame pixelFormat:format depthFormat:0 preserveBackbuffer:NO sharegroup:nil multiSampling:NO numberOfSamples:0];
} }
- (id) initWithFrame:(CGRect)frame pixelFormat:(NSString*)format depthFormat:(GLuint)depth preserveBackbuffer:(BOOL)retained - (id) initWithFrame:(CGRect)frame pixelFormat:(NSString*)format depthFormat:(GLuint)depth preserveBackbuffer:(BOOL)retained
@ -136,9 +143,11 @@ static cocos2d::CCTouch *s_pTouches[MAX_TOUCHES];
{ {
pixelformat_ = format; pixelformat_ = format;
depthFormat_ = depth; depthFormat_ = depth;
size_ = frame.size; multiSampling_ = sampling;
requestedSamples_ = nSamples;
preserveBackbuffer_ = retained;
if( ! [self setupSurface] ) { if( ! [self setupSurfaceWithSharegroup:sharegroup] ) {
[self release]; [self release];
return nil; return nil;
} }
@ -152,13 +161,15 @@ static cocos2d::CCTouch *s_pTouches[MAX_TOUCHES];
{ {
if( (self = [super initWithCoder:aDecoder]) ) { if( (self = [super initWithCoder:aDecoder]) ) {
CAEAGLLayer *eaglLayer = (CAEAGLLayer*)[self layer]; CAEAGLLayer* eaglLayer = (CAEAGLLayer*)[self layer];
pixelformat_ = kEAGLColorFormatRGB565; pixelformat_ = kEAGLColorFormatRGB565;
depthFormat_ = 0; // GL_DEPTH_COMPONENT24_OES; depthFormat_ = 0; // GL_DEPTH_COMPONENT24_OES;
multiSampling_= NO;
requestedSamples_ = 0;
size_ = [eaglLayer bounds].size; size_ = [eaglLayer bounds].size;
if( ! [self setupSurface] ) { if( ! [self setupSurfaceWithSharegroup:nil] ) {
[self release]; [self release];
return nil; return nil;
} }
@ -209,17 +220,21 @@ static cocos2d::CCTouch *s_pTouches[MAX_TOUCHES];
indexBitsUsed &= temp; indexBitsUsed &= temp;
} }
-(BOOL) setupSurface -(BOOL) setupSurfaceWithSharegroup:(EAGLSharegroup*)sharegroup
{ {
CAEAGLLayer *eaglLayer = (CAEAGLLayer *)self.layer; CAEAGLLayer *eaglLayer = (CAEAGLLayer *)self.layer;
eaglLayer.opaque = YES; eaglLayer.opaque = YES;
eaglLayer.drawableProperties = [NSDictionary dictionaryWithObjectsAndKeys: eaglLayer.drawableProperties = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:FALSE], kEAGLDrawablePropertyRetainedBacking, [NSNumber numberWithBool:preserveBackbuffer_], kEAGLDrawablePropertyRetainedBacking,
pixelformat_, kEAGLDrawablePropertyColorFormat, nil]; pixelformat_, kEAGLDrawablePropertyColorFormat, nil];
renderer_ = [[ES1Renderer alloc] initWithDepthFormat:depthFormat_]; renderer_ = [[ES1Renderer alloc] initWithDepthFormat:depthFormat_
withPixelFormat:[self convertPixelFormat:pixelformat_]
withSharegroup:sharegroup
withMultiSampling:multiSampling_
withNumberOfSamples:requestedSamples_];
if (!renderer_) if (!renderer_)
return NO; return NO;
@ -233,7 +248,7 @@ static cocos2d::CCTouch *s_pTouches[MAX_TOUCHES];
- (void) dealloc - (void) dealloc
{ {
CFRelease(touchesIntergerDict); CFRelease(touchesIntergerDict);
[renderer_ release]; [renderer_ release];
[super dealloc]; [super dealloc];
} }
@ -241,9 +256,19 @@ static cocos2d::CCTouch *s_pTouches[MAX_TOUCHES];
- (void) layoutSubviews - (void) layoutSubviews
{ {
[renderer_ resizeFromLayer:(CAEAGLLayer*)self.layer]; [renderer_ resizeFromLayer:(CAEAGLLayer*)self.layer];
size_ = [renderer_ backingSize]; size_ = [renderer_ backingSize];
cocos2d::CCDirector::sharedDirector()->recalculateProjectionAndEAGLViewSize(); // Issue #914 #924
// CCDirector *director = [CCDirector sharedDirector];
// [director reshapeProjection:size_];
cocos2d::CGSize size;
size.width = size_.width;
size.height = size_.height;
cocos2d::CCDirector::sharedDirector()->reshapeProjection(size);
// Avoid flicker. Issue #350
//[director performSelectorOnMainThread:@selector(drawScene) withObject:nil waitUntilDone:YES];
cocos2d::CCDirector::sharedDirector()->drawScene();
} }
- (void) swapBuffers - (void) swapBuffers
@ -251,21 +276,72 @@ static cocos2d::CCTouch *s_pTouches[MAX_TOUCHES];
// IMPORTANT: // IMPORTANT:
// - preconditions // - preconditions
// -> context_ MUST be the OpenGL context // -> context_ MUST be the OpenGL context
// -> renderBuffer_ must be the the RENDER BUFFER // -> renderbuffer_ must be the the RENDER BUFFER
#ifdef __IPHONE_4_0 #ifdef __IPHONE_4_0
if( discardFramebufferSupported_ && depthFormat_ ) {
GLenum attachments[] = { GL_DEPTH_ATTACHMENT_OES }; if (multiSampling_)
glDiscardFramebufferEXT(GL_FRAMEBUFFER_OES, 1, attachments); {
/* Resolve from msaaFramebuffer to resolveFramebuffer */
//glDisable(GL_SCISSOR_TEST);
glBindFramebufferOES(GL_READ_FRAMEBUFFER_APPLE, [renderer_ msaaFrameBuffer]);
glBindFramebufferOES(GL_DRAW_FRAMEBUFFER_APPLE, [renderer_ defaultFrameBuffer]);
glResolveMultisampleFramebufferAPPLE();
} }
if( discardFramebufferSupported_)
{
if (multiSampling_)
{
if (depthFormat_)
{
GLenum attachments[] = {GL_COLOR_ATTACHMENT0_OES, GL_DEPTH_ATTACHMENT_OES};
glDiscardFramebufferEXT(GL_READ_FRAMEBUFFER_APPLE, 2, attachments);
}
else
{
GLenum attachments[] = {GL_COLOR_ATTACHMENT0_OES};
glDiscardFramebufferEXT(GL_READ_FRAMEBUFFER_APPLE, 1, attachments);
}
glBindRenderbufferOES(GL_RENDERBUFFER_OES, [renderer_ colorRenderBuffer]);
}
// not MSAA
else if (depthFormat_ ) {
GLenum attachments[] = { GL_DEPTH_ATTACHMENT_OES};
glDiscardFramebufferEXT(GL_FRAMEBUFFER_OES, 1, attachments);
}
}
#endif // __IPHONE_4_0 #endif // __IPHONE_4_0
//if(![context_ presentRenderbuffer:GL_RENDERBUFFER_OES]) // if(![context_ presentRenderbuffer:GL_RENDERBUFFER_OES])
//CCLOG(@"cocos2d: Failed to swap renderbuffer in %s\n", __FUNCTION__); // CCLOG(@"cocos2d: Failed to swap renderbuffer in %s\n", __FUNCTION__);
[context_ presentRenderbuffer:GL_RENDERBUFFER_OES];
#if COCOS2D_DEBUG #if COCOS2D_DEBUG
CHECK_GL_ERROR(); CHECK_GL_ERROR();
#endif #endif
// We can safely re-bind the framebuffer here, since this will be the
// 1st instruction of the new main loop
if( multiSampling_ )
glBindFramebufferOES(GL_FRAMEBUFFER_OES, [renderer_ msaaFrameBuffer]);
}
- (unsigned int) convertPixelFormat:(NSString*) pixelFormat
{
// define the pixel format
GLenum pFormat;
if([pixelFormat isEqualToString:@"EAGLColorFormat565"])
pFormat = GL_RGB565_OES;
else
pFormat = GL_RGBA8_OES;
return pFormat;
} }
#pragma mark EAGLView - Point conversion #pragma mark EAGLView - Point conversion

View File

@ -34,19 +34,26 @@
@interface ES1Renderer : NSObject <ESRenderer> @interface ES1Renderer : NSObject <ESRenderer>
{ {
// The pixel dimensions of the CAEAGLLayer // The pixel dimensions of the CAEAGLLayer
GLint backingWidth_; GLint backingWidth_;
GLint backingHeight_; GLint backingHeight_;
// The OpenGL ES names for the framebuffer and renderbuffer used to render to this view unsigned int samplesToUse_;
GLuint defaultFramebuffer_; BOOL multiSampling_;
unsigned int depthFormat_;
unsigned int pixelFormat_;
// The OpenGL ES names for the framebuffer and renderbuffer used to render to this view
GLuint defaultFramebuffer_;
GLuint colorRenderbuffer_; GLuint colorRenderbuffer_;
GLuint depthBuffer_; GLuint depthBuffer_;
unsigned int depthFormat_;
//buffers for MSAA
GLuint msaaFramebuffer_;
GLuint msaaColorbuffer_;
@public
EAGLContext *context_; EAGLContext *context_;
} }

View File

@ -1,45 +1,26 @@
/* @interface ES1Renderer (private)
* cocos2d for iPhone: http://www.cocos2d-iphone.org
*
* Copyright (c) 2010 Ricardo Quesada
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*
* File autogenerated with Xcode. Adapted for cocos2d needs.
*/
- (GLenum) convertPixelFormat:(int) pixelFormat;
@end
#import "ES1Renderer.h"
#import "OpenGL_Internal.h"
//#import "ccMacros.h"
@implementation ES1Renderer @implementation ES1Renderer
@synthesize context=context_; @synthesize context=context_;
// Create an OpenGL ES 1.1 context - (id) initWithDepthFormat:(unsigned int)depthFormat withPixelFormat:(unsigned int)pixelFormat withSharegroup:(EAGLSharegroup*)sharegroup withMultiSampling:(BOOL) multiSampling withNumberOfSamples:(unsigned int) requestedSamples
- (id)initWithDepthFormat:(GLuint)depthFormat
{ {
if ((self = [super init])) if ((self = [super init]))
{ {
context_ = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES1]; if ( sharegroup == nil )
{
context_ = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES1];
}
else
{
context_ = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES1 sharegroup:sharegroup];
}
if (!context_ || ![EAGLContext setCurrentContext:context_]) if (!context_ || ![EAGLContext setCurrentContext:context_])
{ {
@ -69,6 +50,20 @@
// glBindRenderbufferOES(GL_RENDERBUFFER_OES, colorRenderbuffer_); // glBindRenderbufferOES(GL_RENDERBUFFER_OES, colorRenderbuffer_);
} }
pixelFormat_ = pixelFormat;
multiSampling_ = multiSampling;
if (multiSampling_)
{
GLint maxSamplesAllowed;
glGetIntegerv(GL_MAX_SAMPLES_APPLE, &maxSamplesAllowed);
samplesToUse_ = MIN(maxSamplesAllowed,requestedSamples);
/* Create the MSAA framebuffer (offscreen) */
glGenFramebuffersOES(1, &msaaFramebuffer_);
glBindFramebufferOES(GL_FRAMEBUFFER_OES, msaaFramebuffer_);
}
CHECK_GL_ERROR(); CHECK_GL_ERROR();
} }
@ -83,33 +78,59 @@
if (![context_ renderbufferStorage:GL_RENDERBUFFER_OES fromDrawable:layer]) if (![context_ renderbufferStorage:GL_RENDERBUFFER_OES fromDrawable:layer])
{ {
//CCLOG(@"failed to call context"); /*CCLOG(@"failed to call context"); */
} }
glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_WIDTH_OES, &backingWidth_); glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_WIDTH_OES, &backingWidth_);
glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_HEIGHT_OES, &backingHeight_); glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_HEIGHT_OES, &backingHeight_);
//CCLOG(@"cocos2d: surface size: %dx%d", (int)backingWidth_, (int)backingHeight_); /*CCLOG(@"cocos2d: surface size: %dx%d", (int)backingWidth_, (int)backingHeight_);*/
if (depthFormat_) { if (multiSampling_)
{
/* Create the offscreen MSAA color buffer.
After rendering, the contents of this will be blitted into ColorRenderbuffer */
//msaaFrameBuffer needs to be binded
glBindFramebufferOES(GL_FRAMEBUFFER_OES, msaaFramebuffer_);
glGenRenderbuffersOES(1, &msaaColorbuffer_);
glBindRenderbufferOES(GL_RENDERBUFFER_OES, msaaColorbuffer_);
glRenderbufferStorageMultisampleAPPLE(GL_RENDERBUFFER_OES, samplesToUse_,pixelFormat_ , backingWidth_, backingHeight_);
glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, msaaColorbuffer_);
if (glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES) != GL_FRAMEBUFFER_COMPLETE_OES)
{
/*CCLOG(@"Failed to make complete framebuffer object %x", glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES));*/
return NO;
}
}
if (depthFormat_)
{
if( ! depthBuffer_ ) if( ! depthBuffer_ )
glGenRenderbuffersOES(1, &depthBuffer_); glGenRenderbuffersOES(1, &depthBuffer_);
glBindRenderbufferOES(GL_RENDERBUFFER_OES, depthBuffer_); glBindRenderbufferOES(GL_RENDERBUFFER_OES, depthBuffer_);
glRenderbufferStorageOES(GL_RENDERBUFFER_OES, depthFormat_, backingWidth_, backingHeight_); if( multiSampling_ )
glRenderbufferStorageMultisampleAPPLE(GL_RENDERBUFFER_OES, samplesToUse_, depthFormat_,backingWidth_, backingHeight_);
else
glRenderbufferStorageOES(GL_RENDERBUFFER_OES, depthFormat_, backingWidth_, backingHeight_);
glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_DEPTH_ATTACHMENT_OES, GL_RENDERBUFFER_OES, depthBuffer_); glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_DEPTH_ATTACHMENT_OES, GL_RENDERBUFFER_OES, depthBuffer_);
// bind color buffer // bind color buffer
glBindRenderbufferOES(GL_RENDERBUFFER_OES, colorRenderbuffer_); glBindRenderbufferOES(GL_RENDERBUFFER_OES, colorRenderbuffer_);
} }
glBindFramebufferOES(GL_FRAMEBUFFER_OES, defaultFramebuffer_);
if (glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES) != GL_FRAMEBUFFER_COMPLETE_OES) if (glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES) != GL_FRAMEBUFFER_COMPLETE_OES)
{ {
//CCLOG(@"Failed to make complete framebuffer object %x", glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES)); /*CCLOG(@"Failed to make complete framebuffer object %x", glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES));*/
return NO; return NO;
} }
CHECK_GL_ERROR();
return YES; return YES;
} }
@ -123,9 +144,10 @@
return [NSString stringWithFormat:@"<%@ = %08X | size = %ix%i>", [self class], self, backingWidth_, backingHeight_]; return [NSString stringWithFormat:@"<%@ = %08X | size = %ix%i>", [self class], self, backingWidth_, backingHeight_];
} }
- (void)dealloc - (void)dealloc
{ {
//CCLOGINFO(@"cocos2d: deallocing %@", self); /*CCLOGINFO(@"cocos2d: deallocing %@", self);*/
// Tear down GL // Tear down GL
if(defaultFramebuffer_) if(defaultFramebuffer_)
@ -146,6 +168,18 @@
depthBuffer_ = 0; depthBuffer_ = 0;
} }
if ( msaaColorbuffer_)
{
glDeleteRenderbuffersOES(1, &msaaColorbuffer_);
msaaColorbuffer_ = 0;
}
if ( msaaFramebuffer_)
{
glDeleteRenderbuffersOES(1, &msaaFramebuffer_);
msaaFramebuffer_ = 0;
}
// Tear down context // Tear down context
if ([EAGLContext currentContext] == context_) if ([EAGLContext currentContext] == context_)
[EAGLContext setCurrentContext:nil]; [EAGLContext setCurrentContext:nil];
@ -156,4 +190,24 @@
[super dealloc]; [super dealloc];
} }
- (unsigned int) colorRenderBuffer
{
return colorRenderbuffer_;
}
- (unsigned int) defaultFrameBuffer
{
return defaultFramebuffer_;
}
- (unsigned int) msaaFrameBuffer
{
return msaaFramebuffer_;
}
- (unsigned int) msaaColorBuffer
{
return msaaColorbuffer_;
}
@end @end

View File

@ -32,11 +32,15 @@
@protocol ESRenderer <NSObject> @protocol ESRenderer <NSObject>
-(id) initWithDepthFormat:(unsigned int)depthFormat; - (id) initWithDepthFormat:(unsigned int)depthFormat withPixelFormat:(unsigned int)pixelFormat withSharegroup:(EAGLSharegroup*)sharegroup withMultiSampling:(BOOL) multiSampling withNumberOfSamples:(unsigned int) requestedSamples;
- (BOOL)resizeFromLayer:(CAEAGLLayer *)layer; - (BOOL) resizeFromLayer:(CAEAGLLayer *)layer;
-(EAGLContext*) context; - (EAGLContext*) context;
-(CGSize) backingSize; - (CGSize) backingSize;
- (unsigned int) colorRenderBuffer;
- (unsigned int) defaultFrameBuffer;
- (unsigned int) msaaFrameBuffer;
- (unsigned int) msaaColorBuffer;
@end @end