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_;
GLuint depthFormat_;
BOOL preserveBackbuffer_;
CGSize size_;
BOOL discardFramebufferSupported_;
//fsaa addition
BOOL multisampling_;
unsigned int requestedSamples_;
@private
CFMutableDictionaryRef touchesIntergerDict;
unsigned int indexBitsUsed;
@ -98,6 +103,9 @@ Copyright (C) 2008 Apple Inc. All Rights Reserved.
+ (id) viewWithFrame:(CGRect)frame pixelFormat:(NSString*)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;
/** 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
+(id) sharedEGLView;
@ -105,8 +113,8 @@ Copyright (C) 2008 Apple Inc. All Rights Reserved.
- (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 */
- (id) initWithFrame:(CGRect)frame pixelFormat:(NSString*)format;
/** Initializes an EAGLView with a frame, a color buffer format, and a depth buffer format */
- (id) initWithFrame:(CGRect)frame pixelFormat:(NSString*)format depthFormat:(GLuint)depth preserveBackbuffer:(BOOL)retained;
/** 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 sharegroup:(EAGLSharegroup*)sharegroup multiSampling:(BOOL)sampling numberOfSamples:(unsigned int)nSamples;
/** pixel format: it could be RGBA8 (32-bit) or RGB565 (16-bit) */
@property(nonatomic,readonly) NSString* pixelFormat;
@ -119,6 +127,8 @@ Copyright (C) 2008 Apple Inc. All Rights Reserved.
/** OpenGL context */
@property(nonatomic,readonly) EAGLContext *context;
@property(nonatomic,readwrite) BOOL multiSampling;
@property(readonly) CFMutableDictionaryRef touchesIntergerDict;
@property(readwrite) unsigned int indexBitsUsed;

View File

@ -77,7 +77,8 @@ static EAGLView *view;
static cocos2d::CCTouch *s_pTouches[MAX_TOUCHES];
@interface EAGLView (Private)
-(BOOL) setupSurface;
- (BOOL) setupSurfaceWithSharegroup:(EAGLSharegroup*)sharegroup;
- (unsigned int) convertPixelFormat:(NSString*) pixelFormat;
@end
@implementation EAGLView
@ -87,6 +88,7 @@ static cocos2d::CCTouch *s_pTouches[MAX_TOUCHES];
@synthesize context=context_;
@synthesize touchesIntergerDict;
@synthesize indexBitsUsed;
@synthesize multiSampling=multiSampling_;
+ (Class) layerClass
{
@ -95,17 +97,22 @@ static cocos2d::CCTouch *s_pTouches[MAX_TOUCHES];
+ (id) viewWithFrame:(CGRect)frame
{
return [[[self alloc] initWithFrame:frame] autorelease];
return [[[[self alloc] init] initWithFrame:frame] autorelease];
}
+ (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
@ -122,12 +129,12 @@ static cocos2d::CCTouch *s_pTouches[MAX_TOUCHES];
- (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
{
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
@ -136,9 +143,11 @@ static cocos2d::CCTouch *s_pTouches[MAX_TOUCHES];
{
pixelformat_ = format;
depthFormat_ = depth;
size_ = frame.size;
multiSampling_ = sampling;
requestedSamples_ = nSamples;
preserveBackbuffer_ = retained;
if( ! [self setupSurface] ) {
if( ! [self setupSurfaceWithSharegroup:sharegroup] ) {
[self release];
return nil;
}
@ -152,13 +161,15 @@ static cocos2d::CCTouch *s_pTouches[MAX_TOUCHES];
{
if( (self = [super initWithCoder:aDecoder]) ) {
CAEAGLLayer *eaglLayer = (CAEAGLLayer*)[self layer];
CAEAGLLayer* eaglLayer = (CAEAGLLayer*)[self layer];
pixelformat_ = kEAGLColorFormatRGB565;
depthFormat_ = 0; // GL_DEPTH_COMPONENT24_OES;
multiSampling_= NO;
requestedSamples_ = 0;
size_ = [eaglLayer bounds].size;
if( ! [self setupSurface] ) {
if( ! [self setupSurfaceWithSharegroup:nil] ) {
[self release];
return nil;
}
@ -209,17 +220,21 @@ static cocos2d::CCTouch *s_pTouches[MAX_TOUCHES];
indexBitsUsed &= temp;
}
-(BOOL) setupSurface
-(BOOL) setupSurfaceWithSharegroup:(EAGLSharegroup*)sharegroup
{
CAEAGLLayer *eaglLayer = (CAEAGLLayer *)self.layer;
eaglLayer.opaque = YES;
eaglLayer.drawableProperties = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:FALSE], kEAGLDrawablePropertyRetainedBacking,
[NSNumber numberWithBool:preserveBackbuffer_], kEAGLDrawablePropertyRetainedBacking,
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_)
return NO;
@ -233,7 +248,7 @@ static cocos2d::CCTouch *s_pTouches[MAX_TOUCHES];
- (void) dealloc
{
CFRelease(touchesIntergerDict);
CFRelease(touchesIntergerDict);
[renderer_ release];
[super dealloc];
}
@ -241,9 +256,19 @@ static cocos2d::CCTouch *s_pTouches[MAX_TOUCHES];
- (void) layoutSubviews
{
[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
@ -251,21 +276,72 @@ static cocos2d::CCTouch *s_pTouches[MAX_TOUCHES];
// IMPORTANT:
// - preconditions
// -> context_ MUST be the OpenGL context
// -> renderBuffer_ must be the the RENDER BUFFER
// -> renderbuffer_ must be the the RENDER BUFFER
#ifdef __IPHONE_4_0
if( discardFramebufferSupported_ && depthFormat_ ) {
GLenum attachments[] = { GL_DEPTH_ATTACHMENT_OES };
glDiscardFramebufferEXT(GL_FRAMEBUFFER_OES, 1, attachments);
if (multiSampling_)
{
/* 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
//if(![context_ presentRenderbuffer:GL_RENDERBUFFER_OES])
//CCLOG(@"cocos2d: Failed to swap renderbuffer in %s\n", __FUNCTION__);
[context_ presentRenderbuffer:GL_RENDERBUFFER_OES];
// if(![context_ presentRenderbuffer:GL_RENDERBUFFER_OES])
// CCLOG(@"cocos2d: Failed to swap renderbuffer in %s\n", __FUNCTION__);
#if COCOS2D_DEBUG
CHECK_GL_ERROR();
#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

View File

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

View File

@ -1,45 +1,26 @@
/*
* 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.
*/
@interface ES1Renderer (private)
- (GLenum) convertPixelFormat:(int) pixelFormat;
@end
#import "ES1Renderer.h"
#import "OpenGL_Internal.h"
//#import "ccMacros.h"
@implementation ES1Renderer
@synthesize context=context_;
// Create an OpenGL ES 1.1 context
- (id)initWithDepthFormat:(GLuint)depthFormat
- (id) initWithDepthFormat:(unsigned int)depthFormat withPixelFormat:(unsigned int)pixelFormat withSharegroup:(EAGLSharegroup*)sharegroup withMultiSampling:(BOOL) multiSampling withNumberOfSamples:(unsigned int) requestedSamples
{
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_])
{
@ -69,6 +50,20 @@
// 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();
}
@ -83,33 +78,59 @@
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_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_ )
glGenRenderbuffersOES(1, &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_);
// bind color buffer
glBindRenderbufferOES(GL_RENDERBUFFER_OES, colorRenderbuffer_);
}
glBindFramebufferOES(GL_FRAMEBUFFER_OES, defaultFramebuffer_);
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;
}
CHECK_GL_ERROR();
return YES;
}
@ -123,9 +144,10 @@
return [NSString stringWithFormat:@"<%@ = %08X | size = %ix%i>", [self class], self, backingWidth_, backingHeight_];
}
- (void)dealloc
{
//CCLOGINFO(@"cocos2d: deallocing %@", self);
/*CCLOGINFO(@"cocos2d: deallocing %@", self);*/
// Tear down GL
if(defaultFramebuffer_)
@ -146,6 +168,18 @@
depthBuffer_ = 0;
}
if ( msaaColorbuffer_)
{
glDeleteRenderbuffersOES(1, &msaaColorbuffer_);
msaaColorbuffer_ = 0;
}
if ( msaaFramebuffer_)
{
glDeleteRenderbuffersOES(1, &msaaFramebuffer_);
msaaFramebuffer_ = 0;
}
// Tear down context
if ([EAGLContext currentContext] == context_)
[EAGLContext setCurrentContext:nil];
@ -156,4 +190,24 @@
[super dealloc];
}
- (unsigned int) colorRenderBuffer
{
return colorRenderbuffer_;
}
- (unsigned int) defaultFrameBuffer
{
return defaultFramebuffer_;
}
- (unsigned int) msaaFrameBuffer
{
return msaaFramebuffer_;
}
- (unsigned int) msaaColorBuffer
{
return msaaColorbuffer_;
}
@end

View File

@ -32,11 +32,15 @@
@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;
-(CGSize) backingSize;
- (EAGLContext*) context;
- (CGSize) backingSize;
- (unsigned int) colorRenderBuffer;
- (unsigned int) defaultFrameBuffer;
- (unsigned int) msaaFrameBuffer;
- (unsigned int) msaaColorBuffer;
@end