diff --git a/HelloWorld/ios/AppController.mm b/HelloWorld/ios/AppController.mm index d0f63ef772..2c1c563acb 100644 --- a/HelloWorld/ios/AppController.mm +++ b/HelloWorld/ios/AppController.mm @@ -45,7 +45,7 @@ static AppDelegate s_sharedApplication; window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]]; EAGLView *__glView = [EAGLView viewWithFrame: [window bounds] pixelFormat: kEAGLColorFormatRGBA8 - depthFormat: GL_DEPTH_COMPONENT16_OES + depthFormat: GL_DEPTH_COMPONENT16 preserveBackbuffer: NO sharegroup:nil multiSampling:NO diff --git a/HelloWorld/ios/HelloWorld.xcodeproj/project.pbxproj.REMOVED.git-id b/HelloWorld/ios/HelloWorld.xcodeproj/project.pbxproj.REMOVED.git-id index 8946e9c740..5d231e1fe2 100644 --- a/HelloWorld/ios/HelloWorld.xcodeproj/project.pbxproj.REMOVED.git-id +++ b/HelloWorld/ios/HelloWorld.xcodeproj/project.pbxproj.REMOVED.git-id @@ -1 +1 @@ -adb49aea78ff4d88fe106fc79ff1b90275efc86a \ No newline at end of file +70c443ceaf43c95b4a380aa01b43a1875462d911 \ No newline at end of file diff --git a/cocos2dx/platform/CCCommon.h b/cocos2dx/platform/CCCommon.h index cafca9864c..452870ae33 100644 --- a/cocos2dx/platform/CCCommon.h +++ b/cocos2dx/platform/CCCommon.h @@ -27,7 +27,7 @@ THE SOFTWARE. #include "CCPlatformMacros.h" -NS_CC_BEGIN; +NS_CC_BEGIN /// The max length of CCLog message. static const int kMaxLogLen = 16*1024; @@ -65,6 +65,6 @@ typedef enum LanguageType kLanguageRussian } ccLanguageType; -NS_CC_END; +NS_CC_END #endif // __CC_COMMON_H__ diff --git a/cocos2dx/platform/CCGL.h b/cocos2dx/platform/CCGL.h index 92715f3722..268ad14b25 100644 --- a/cocos2dx/platform/CCGL.h +++ b/cocos2dx/platform/CCGL.h @@ -40,8 +40,8 @@ THE SOFTWARE. #include "CCCommon.h" #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) -#include "OpenGLES/ES1/gl.h" -#include "OpenGLES/ES1/glext.h" +#include "OpenGLES/ES2/gl.h" +#include "OpenGLES/ES2/glext.h" #endif #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) diff --git a/cocos2dx/platform/CCSAXParser.cpp b/cocos2dx/platform/CCSAXParser.cpp index d29ec06d76..8a1cb35a7c 100644 --- a/cocos2dx/platform/CCSAXParser.cpp +++ b/cocos2dx/platform/CCSAXParser.cpp @@ -21,11 +21,11 @@ THE SOFTWARE. ****************************************************************************/ -#include "CCSAXParser.h" -#include "CCDictionary.h" #include #include #include +#include "CCSAXParser.h" +#include "CCDictionary.h" #include "CCLibxml2.h" #include "CCFileUtils.h" @@ -34,7 +34,6 @@ NS_CC_BEGIN; CCSAXParser::CCSAXParser() { m_pDelegator = NULL; - } CCSAXParser::~CCSAXParser(void) diff --git a/cocos2dx/platform/ios/ES1Renderer.h b/cocos2dx/platform/ios/CCES2Renderer.h similarity index 67% rename from cocos2dx/platform/ios/ES1Renderer.h rename to cocos2dx/platform/ios/CCES2Renderer.h index 39971dd898..7827938725 100644 --- a/cocos2dx/platform/ios/ES1Renderer.h +++ b/cocos2dx/platform/ios/CCES2Renderer.h @@ -2,17 +2,18 @@ * cocos2d for iPhone: http://www.cocos2d-iphone.org * * Copyright (c) 2010 Ricardo Quesada - * + * Copyright (c) 2011 Zynga Inc. + * * 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 @@ -25,41 +26,55 @@ * File autogenerated with Xcode. Adapted for cocos2d needs. */ +// Only compile this code on iOS. These files should NOT be included on your Mac project. +// But in case they are included, it won't be compiled. +#import "CCPlatformMacros.h" +#import "CCESRenderer.h" +#import +#import + +@interface CCES2Renderer : NSObject +{ + // The pixel dimensions of the CAEAGLLayer + GLint backingWidth_; + GLint backingHeight_; + + 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_; -#import "ESRenderer.h" - -#import -#import - -@interface ES1Renderer : NSObject -{ - // The pixel dimensions of the CAEAGLLayer - GLint backingWidth_; - GLint backingHeight_; - - 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_; - - - //buffers for MSAA - GLuint msaaFramebuffer_; - GLuint msaaColorbuffer_; - - EAGLContext *context_; -} - -/** EAGLContext */ -@property (nonatomic,readonly) EAGLContext* context; - -- (BOOL)resizeFromLayer:(CAEAGLLayer *)layer; - + //buffers for MSAA + GLuint msaaFramebuffer_; + GLuint msaaColorbuffer_; + + EAGLContext *context_; +} + +/** Color Renderbuffer */ +@property (nonatomic,readonly) GLuint colorRenderbuffer; + +/** Default Renderbuffer */ +@property (nonatomic,readonly) GLuint defaultFramebuffer; + +/** MSAA Framebuffer */ +@property (nonatomic,readonly) GLuint msaaFramebuffer; + +/** MSAA Color Buffer */ +@property (nonatomic,readonly) GLuint msaaColorbuffer; + +/** EAGLContext */ +@property (nonatomic,readonly) EAGLContext* context; + +- (BOOL)resizeFromLayer:(CAEAGLLayer *)layer; @end + + + diff --git a/cocos2dx/platform/ios/CCES2Renderer.m b/cocos2dx/platform/ios/CCES2Renderer.m new file mode 100644 index 0000000000..61c68fd621 --- /dev/null +++ b/cocos2dx/platform/ios/CCES2Renderer.m @@ -0,0 +1,247 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2011 Ricardo Quesada + * Copyright (c) 2011 Zynga Inc. + * + * 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. + */ + +// Only compile this code on iOS. These files should NOT be included on your Mac project. +// But in case they are included, it won't be compiled. + +#import "CCPlatformMacros.h" +#import "CCES2Renderer.h" +#import "OpenGL_Internal.h" + + +@implementation CCES2Renderer + +@synthesize context=context_; +@synthesize defaultFramebuffer=defaultFramebuffer_; +@synthesize colorRenderbuffer=colorRenderbuffer_; +@synthesize msaaColorbuffer=msaaColorbuffer_; +@synthesize msaaFramebuffer=msaaFramebuffer_; + +// Create an OpenGL ES 2.0 context +- (id) initWithDepthFormat:(unsigned int)depthFormat withPixelFormat:(unsigned int)pixelFormat withSharegroup:(EAGLSharegroup*)sharegroup withMultiSampling:(BOOL) multiSampling withNumberOfSamples:(unsigned int) requestedSamples +{ + self = [super init]; + if (self) + { + if( ! sharegroup ) + context_ = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2]; + else + context_ = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2 sharegroup:sharegroup]; + + if (!context_ || ![EAGLContext setCurrentContext:context_] ) + { + [self release]; + return nil; + } + + depthFormat_ = depthFormat; + pixelFormat_ = pixelFormat; + multiSampling_ = multiSampling; + + // Create default framebuffer object. The backing will be allocated for the current layer in -resizeFromLayer + glGenFramebuffers(1, &defaultFramebuffer_); + NSAssert( defaultFramebuffer_, @"Can't create default frame buffer"); + + glGenRenderbuffers(1, &colorRenderbuffer_); + NSAssert( colorRenderbuffer_, @"Can't create default render buffer"); + + glBindFramebuffer(GL_FRAMEBUFFER, defaultFramebuffer_); + glBindRenderbuffer(GL_RENDERBUFFER, colorRenderbuffer_); + glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, colorRenderbuffer_); + + if (multiSampling_) + { + GLint maxSamplesAllowed; + glGetIntegerv(GL_MAX_SAMPLES_APPLE, &maxSamplesAllowed); + samplesToUse_ = MIN(maxSamplesAllowed,requestedSamples); + + /* Create the MSAA framebuffer (offscreen) */ + glGenFramebuffers(1, &msaaFramebuffer_); + NSAssert( msaaFramebuffer_, @"Can't create default MSAA frame buffer"); + glBindFramebuffer(GL_FRAMEBUFFER, msaaFramebuffer_); + + } + + CHECK_GL_ERROR_DEBUG(); + } + + return self; +} + +- (BOOL)resizeFromLayer:(CAEAGLLayer *)layer +{ + // Allocate color buffer backing based on the current layer size + glBindRenderbuffer(GL_RENDERBUFFER, colorRenderbuffer_); + + if( ! [context_ renderbufferStorage:GL_RENDERBUFFER fromDrawable:layer] ) + { + CCLOG(@"failed to call context"); + } + + glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_WIDTH, &backingWidth_); + glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_HEIGHT, &backingHeight_); + + CCLOG(@"cocos2d: surface size: %dx%d", (int)backingWidth_, (int)backingHeight_); + + if (multiSampling_) + { + if ( msaaColorbuffer_) { + glDeleteRenderbuffers(1, &msaaColorbuffer_); + msaaColorbuffer_ = 0; + } + + /* Create the offscreen MSAA color buffer. + After rendering, the contents of this will be blitted into ColorRenderbuffer */ + + //msaaFrameBuffer needs to be binded + glBindFramebuffer(GL_FRAMEBUFFER, msaaFramebuffer_); + glGenRenderbuffers(1, &msaaColorbuffer_); + NSAssert(msaaFramebuffer_, @"Can't create MSAA color buffer"); + + glBindRenderbuffer(GL_RENDERBUFFER, msaaColorbuffer_); + + glRenderbufferStorageMultisampleAPPLE(GL_RENDERBUFFER, samplesToUse_, pixelFormat_ , backingWidth_, backingHeight_); + + glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, msaaColorbuffer_); + + GLenum error; + if ( (error=glCheckFramebufferStatus(GL_FRAMEBUFFER)) != GL_FRAMEBUFFER_COMPLETE) + { + CCLOG(@"Failed to make complete framebuffer object 0x%X", error); + return NO; + } + } + + CHECK_GL_ERROR(); + + if (depthFormat_) + { + if( ! depthBuffer_ ) { + glGenRenderbuffers(1, &depthBuffer_); + NSAssert(depthBuffer_, @"Can't create depth buffer"); + } + + glBindRenderbuffer(GL_RENDERBUFFER, depthBuffer_); + + if( multiSampling_ ) + glRenderbufferStorageMultisampleAPPLE(GL_RENDERBUFFER, samplesToUse_, depthFormat_,backingWidth_, backingHeight_); + else + glRenderbufferStorage(GL_RENDERBUFFER, depthFormat_, backingWidth_, backingHeight_); + + glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depthBuffer_); + + // bind color buffer + glBindRenderbuffer(GL_RENDERBUFFER, colorRenderbuffer_); + } + + CHECK_GL_ERROR(); + + GLenum error; + if( (error=glCheckFramebufferStatus(GL_FRAMEBUFFER)) != GL_FRAMEBUFFER_COMPLETE) + { + CCLOG(@"Failed to make complete framebuffer object 0x%X", error); + return NO; + } + + return YES; +} + +-(CGSize) backingSize +{ + return CGSizeMake( backingWidth_, backingHeight_); +} + +- (NSString*) description +{ + return [NSString stringWithFormat:@"<%@ = %08X | size = %ix%i>", [self class], self, backingWidth_, backingHeight_]; +} + +- (unsigned int) colorRenderBuffer +{ + return colorRenderbuffer_; +} + +- (unsigned int) defaultFrameBuffer +{ + return defaultFramebuffer_; +} + +- (unsigned int) msaaFrameBuffer +{ + return msaaFramebuffer_; +} + +- (unsigned int) msaaColorBuffer +{ + return msaaColorbuffer_; +} + +- (void)dealloc +{ + CCLOGINFO(@"cocos2d: deallocing %@", self); + + // Tear down GL + if (defaultFramebuffer_) { + glDeleteFramebuffers(1, &defaultFramebuffer_); + defaultFramebuffer_ = 0; + } + + if (colorRenderbuffer_) { + glDeleteRenderbuffers(1, &colorRenderbuffer_); + colorRenderbuffer_ = 0; + } + + if( depthBuffer_ ) { + glDeleteRenderbuffers(1, &depthBuffer_ ); + depthBuffer_ = 0; + } + + if ( msaaColorbuffer_) + { + glDeleteRenderbuffers(1, &msaaColorbuffer_); + msaaColorbuffer_ = 0; + } + + if ( msaaFramebuffer_) + { + glDeleteRenderbuffers(1, &msaaFramebuffer_); + msaaFramebuffer_ = 0; + } + + // Tear down context + if ([EAGLContext currentContext] == context_) + [EAGLContext setCurrentContext:nil]; + + [context_ release]; + context_ = nil; + + [super dealloc]; +} + +@end + diff --git a/cocos2dx/platform/ios/ESRenderer.h b/cocos2dx/platform/ios/CCESRenderer.h similarity index 87% rename from cocos2dx/platform/ios/ESRenderer.h rename to cocos2dx/platform/ios/CCESRenderer.h index 2874cdc7df..b299a51d0e 100644 --- a/cocos2dx/platform/ios/ESRenderer.h +++ b/cocos2dx/platform/ios/CCESRenderer.h @@ -2,17 +2,18 @@ * cocos2d for iPhone: http://www.cocos2d-iphone.org * * Copyright (c) 2010 Ricardo Quesada - * + * Copyright (c) 2011 Zynga Inc. + * * 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 @@ -25,22 +26,26 @@ * File autogenerated with Xcode. Adapted for cocos2d needs. */ -#import - -#import -#import - -@protocol ESRenderer - -- (id) initWithDepthFormat:(unsigned int)depthFormat withPixelFormat:(unsigned int)pixelFormat withSharegroup:(EAGLSharegroup*)sharegroup withMultiSampling:(BOOL) multiSampling withNumberOfSamples:(unsigned int) requestedSamples; - -- (BOOL) resizeFromLayer:(CAEAGLLayer *)layer; - -- (EAGLContext*) context; -- (CGSize) backingSize; - -- (unsigned int) colorRenderBuffer; -- (unsigned int) defaultFrameBuffer; -- (unsigned int) msaaFrameBuffer; -- (unsigned int) msaaColorBuffer; +// Only compile this code on iOS. These files should NOT be included on your Mac project. +// But in case they are included, it won't be compiled. +#import "CCPlatformMacros.h" +#import + +#import +#import + +@protocol CCESRenderer + +- (id) initWithDepthFormat:(unsigned int)depthFormat withPixelFormat:(unsigned int)pixelFormat withSharegroup:(EAGLSharegroup*)sharegroup withMultiSampling:(BOOL) multiSampling withNumberOfSamples:(unsigned int) requestedSamples; + +- (BOOL) resizeFromLayer:(CAEAGLLayer *)layer; + +- (EAGLContext*) context; +- (CGSize) backingSize; + +- (unsigned int) colorRenderBuffer; +- (unsigned int) defaultFrameBuffer; +- (unsigned int) msaaFrameBuffer; +- (unsigned int) msaaColorBuffer; @end + diff --git a/cocos2dx/platform/ios/CCFileUtils_ios.mm b/cocos2dx/platform/ios/CCFileUtils_ios.mm index 7cf845d352..b23e3135b0 100644 --- a/cocos2dx/platform/ios/CCFileUtils_ios.mm +++ b/cocos2dx/platform/ios/CCFileUtils_ios.mm @@ -39,8 +39,8 @@ THE SOFTWARE. using namespace cocos2d; -static void static_addValueToCCDict(id key, id value, CCDictionary* pDict); -static void static_addItemToCCArray(id item, CCMutableArray *pArray); +static void static_addValueToCCDict(id key, id value, CCDictionary* pDict); +static void static_addItemToCCArray(id item, CCArray* pArray); static const char *static_ccRemoveHDSuffixFromFile( const char *pszPath) { @@ -142,7 +142,7 @@ static const char* static_fullPathFromRelativePath(const char *pszRelativePath) return [fullpath UTF8String]; } -static void static_addItemToCCArray(id item, CCMutableArray *pArray) +static void static_addItemToCCArray(id item, CCArray *pArray) { // add string value into array if ([item isKindOfClass:[NSString class]]) { @@ -165,7 +165,7 @@ static void static_addItemToCCArray(id item, CCMutableArray *pArray) // add dictionary value into array if ([item isKindOfClass:[NSDictionary class]]) { - CCDictionary* pDictItem = new CCDictionary(); + CCDictionary* pDictItem = new CCDictionary(); for (id subKey in [item allKeys]) { id subValue = [item objectForKey:subKey]; static_addValueToCCDict(subKey, subValue, pDictItem); @@ -177,7 +177,8 @@ static void static_addItemToCCArray(id item, CCMutableArray *pArray) // add array value into array if ([item isKindOfClass:[NSArray class]]) { - CCMutableArray *pArrayItem = new CCMutableArray(); + CCArray *pArrayItem = new CCArray(); + pArrayItem->init(); for (id subItem in item) { static_addItemToCCArray(subItem, pArrayItem); } @@ -187,7 +188,7 @@ static void static_addItemToCCArray(id item, CCMutableArray *pArray) } } -static void static_addValueToCCDict(id key, id value, CCDictionary* pDict) +static void static_addValueToCCDict(id key, id value, CCDictionary* pDict) { // the key must be a string CCAssert([key isKindOfClass:[NSString class]], "The key should be a string!"); @@ -195,12 +196,12 @@ static void static_addValueToCCDict(id key, id value, CCDictionary* pSubDict = new CCDictionary(); + CCDictionary* pSubDict = new CCDictionary(); for (id subKey in [value allKeys]) { id subValue = [value objectForKey:subKey]; static_addValueToCCDict(subKey, subValue, pSubDict); } - pDict->setObject(pSubDict, pKey); + pDict->setObject(pSubDict, pKey.c_str()); pSubDict->release(); return; } @@ -209,7 +210,7 @@ static void static_addValueToCCDict(id key, id value, CCDictionarysetObject(pValue, pKey); + pDict->setObject(pValue, pKey.c_str()); pValue->release(); return; } @@ -219,18 +220,19 @@ static void static_addValueToCCDict(id key, id value, CCDictionarysetObject(pValue, pKey); + pDict->setObject(pValue, pKey.c_str()); pValue->release(); return; } // the value is a array if ([value isKindOfClass:[NSArray class]]) { - CCMutableArray *pArray = new CCMutableArray(); + CCArray *pArray = new CCArray(); + pArray->init(); for (id item in value) { static_addItemToCCArray(item, pArray); } - pDict->setObject(pArray, pKey); + pDict->setObject(pArray, pKey.c_str()); pArray->release(); return; } @@ -293,20 +295,20 @@ namespace cocos2d { return pRet->m_sString.c_str(); } - CCDictionary *CCFileUtils::dictionaryWithContentsOfFile(const char *pFileName) + CCDictionary *CCFileUtils::dictionaryWithContentsOfFile(const char *pFileName) { - CCDictionary *ret = dictionaryWithContentsOfFileThreadSafe(pFileName); + CCDictionary *ret = dictionaryWithContentsOfFileThreadSafe(pFileName); ret->autorelease(); return ret; } - CCDictionary *CCFileUtils::dictionaryWithContentsOfFileThreadSafe(const char *pFileName) + CCDictionary *CCFileUtils::dictionaryWithContentsOfFileThreadSafe(const char *pFileName) { NSString* pPath = [NSString stringWithUTF8String:pFileName]; NSDictionary* pDict = [NSDictionary dictionaryWithContentsOfFile:pPath]; - CCDictionary* pRet = new CCDictionary(); + CCDictionary* pRet = new CCDictionary(); for (id key in [pDict allKeys]) { id value = [pDict objectForKey:key]; static_addValueToCCDict(key, value, pRet); diff --git a/cocos2dx/platform/ios/EAGLView.h b/cocos2dx/platform/ios/EAGLView.h index a8be2da169..f5d4da43ab 100755 --- a/cocos2dx/platform/ios/EAGLView.h +++ b/cocos2dx/platform/ios/EAGLView.h @@ -64,11 +64,11 @@ Copyright (C) 2008 Apple Inc. All Rights Reserved. #import #import #import -#import -#import +#import +#import #import -#import "ESRenderer.h" +#import "CCESRenderer.h" //CLASS INTERFACE: @@ -79,7 +79,7 @@ Copyright (C) 2008 Apple Inc. All Rights Reserved. */ @interface EAGLView : UIView { - id renderer_; + id renderer_; EAGLContext *context_; // weak ref NSString *pixelformat_; diff --git a/cocos2dx/platform/ios/EAGLView.mm b/cocos2dx/platform/ios/EAGLView.mm index c0aabb21b7..295332cff1 100755 --- a/cocos2dx/platform/ios/EAGLView.mm +++ b/cocos2dx/platform/ios/EAGLView.mm @@ -64,7 +64,7 @@ Copyright (C) 2008 Apple Inc. All Rights Reserved. #import #import "EAGLView.h" -#import "ES1Renderer.h" +#import "CCES2Renderer.h" #import "CCDirector.h" #import "CCSet.h" #import "CCTouch.h" @@ -247,19 +247,23 @@ static cocos2d::CCTouch *s_pTouches[MAX_TOUCHES]; pixelformat_, kEAGLDrawablePropertyColorFormat, nil]; - renderer_ = [[ES1Renderer alloc] initWithDepthFormat:depthFormat_ + renderer_ = [[CCES2Renderer alloc] initWithDepthFormat:depthFormat_ withPixelFormat:[self convertPixelFormat:pixelformat_] withSharegroup:sharegroup withMultiSampling:multiSampling_ withNumberOfSamples:requestedSamples_]; + + NSAssert(renderer_, @"OpenGL ES 2.O is required."); if (!renderer_) return NO; context_ = [renderer_ context]; - [context_ renderbufferStorage:GL_RENDERBUFFER_OES fromDrawable:eaglLayer]; + //discardFramebufferSupported_ = [[CCConfiguration sharedConfiguration] supportsDiscardFramebuffer]; + CHECK_GL_ERROR_DEBUG(); + return YES; } @@ -301,8 +305,8 @@ static cocos2d::CCTouch *s_pTouches[MAX_TOUCHES]; { /* Resolve from msaaFramebuffer to resolveFramebuffer */ //glDisable(GL_SCISSOR_TEST); - glBindFramebufferOES(GL_READ_FRAMEBUFFER_APPLE, [renderer_ msaaFrameBuffer]); - glBindFramebufferOES(GL_DRAW_FRAMEBUFFER_APPLE, [renderer_ defaultFrameBuffer]); + glBindFramebuffer(GL_READ_FRAMEBUFFER_APPLE, [renderer_ msaaFrameBuffer]); + glBindFramebuffer(GL_DRAW_FRAMEBUFFER_APPLE, [renderer_ defaultFrameBuffer]); glResolveMultisampleFramebufferAPPLE(); } @@ -312,29 +316,29 @@ static cocos2d::CCTouch *s_pTouches[MAX_TOUCHES]; { if (depthFormat_) { - GLenum attachments[] = {GL_COLOR_ATTACHMENT0_OES, GL_DEPTH_ATTACHMENT_OES}; + GLenum attachments[] = {GL_COLOR_ATTACHMENT0, GL_DEPTH_ATTACHMENT}; glDiscardFramebufferEXT(GL_READ_FRAMEBUFFER_APPLE, 2, attachments); } else { - GLenum attachments[] = {GL_COLOR_ATTACHMENT0_OES}; + GLenum attachments[] = {GL_COLOR_ATTACHMENT0}; glDiscardFramebufferEXT(GL_READ_FRAMEBUFFER_APPLE, 1, attachments); } - glBindRenderbufferOES(GL_RENDERBUFFER_OES, [renderer_ colorRenderBuffer]); + glBindRenderbuffer(GL_RENDERBUFFER, [renderer_ colorRenderBuffer]); } // not MSAA else if (depthFormat_ ) { - GLenum attachments[] = { GL_DEPTH_ATTACHMENT_OES}; - glDiscardFramebufferEXT(GL_FRAMEBUFFER_OES, 1, attachments); + GLenum attachments[] = { GL_DEPTH_ATTACHMENT}; + glDiscardFramebufferEXT(GL_FRAMEBUFFER, 1, attachments); } } #endif // __IPHONE_4_0 - if(![context_ presentRenderbuffer:GL_RENDERBUFFER_OES]) + if(![context_ presentRenderbuffer:GL_RENDERBUFFER]) { // CCLOG(@"cocos2d: Failed to swap renderbuffer in %s\n", __FUNCTION__); } @@ -346,7 +350,7 @@ static cocos2d::CCTouch *s_pTouches[MAX_TOUCHES]; // 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]); + glBindFramebuffer(GL_FRAMEBUFFER, [renderer_ msaaFrameBuffer]); } - (unsigned int) convertPixelFormat:(NSString*) pixelFormat @@ -356,7 +360,7 @@ static cocos2d::CCTouch *s_pTouches[MAX_TOUCHES]; if([pixelFormat isEqualToString:@"EAGLColorFormat565"]) - pFormat = GL_RGB565_OES; + pFormat = GL_RGB565; else pFormat = GL_RGBA8_OES; diff --git a/cocos2dx/platform/ios/ES1Renderer.m b/cocos2dx/platform/ios/ES1Renderer.m deleted file mode 100644 index 152329b3ce..0000000000 --- a/cocos2dx/platform/ios/ES1Renderer.m +++ /dev/null @@ -1,215 +0,0 @@ - -#import "ES1Renderer.h" -#import "OpenGL_Internal.h" -@implementation ES1Renderer - -@synthesize context=context_; - -- (id) initWithDepthFormat:(unsigned int)depthFormat withPixelFormat:(unsigned int)pixelFormat withSharegroup:(EAGLSharegroup*)sharegroup withMultiSampling:(BOOL) multiSampling withNumberOfSamples:(unsigned int) requestedSamples -{ - if ((self = [super init])) - { - if ( sharegroup == nil ) - { - context_ = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES1]; - } - else - { - context_ = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES1 sharegroup:sharegroup]; - } - - if (!context_ || ![EAGLContext setCurrentContext:context_]) - { - [self release]; - return nil; - } - - // Create default framebuffer object. The backing will be allocated for the current layer in -resizeFromLayer - glGenFramebuffersOES(1, &defaultFramebuffer_); - NSAssert( defaultFramebuffer_, @"Can't create default frame buffer"); - glGenRenderbuffersOES(1, &colorRenderbuffer_); - NSAssert( colorRenderbuffer_, @"Can't create default render buffer"); - - glBindFramebufferOES(GL_FRAMEBUFFER_OES, defaultFramebuffer_); - glBindRenderbufferOES(GL_RENDERBUFFER_OES, colorRenderbuffer_); - glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, colorRenderbuffer_); - - depthFormat_ = depthFormat; - - if( depthFormat_ ) { -// glGenRenderbuffersOES(1, &depthBuffer_); -// glBindRenderbufferOES(GL_RENDERBUFFER_OES, depthBuffer_); -// glRenderbufferStorageOES(GL_RENDERBUFFER_OES, depthFormat_, 100, 100); -// glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_DEPTH_ATTACHMENT_OES, GL_RENDERBUFFER_OES, depthBuffer_); - - // default buffer -// 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(); - } - - return self; -} - -- (BOOL)resizeFromLayer:(CAEAGLLayer *)layer -{ - // Allocate color buffer backing based on the current layer size - - glBindRenderbufferOES(GL_RENDERBUFFER_OES, colorRenderbuffer_); - - if (![context_ renderbufferStorage:GL_RENDERBUFFER_OES fromDrawable:layer]) - { - /*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_);*/ - - if (multiSampling_) - { - if ( msaaColorbuffer_) - { - glDeleteRenderbuffersOES(1, &msaaColorbuffer_); - msaaColorbuffer_ = 0; - } - - /* 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_); - 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));*/ - return NO; - } - - CHECK_GL_ERROR(); - - return YES; -} - --(CGSize) backingSize -{ - return CGSizeMake( backingWidth_, backingHeight_); -} - -- (NSString*) description -{ - return [NSString stringWithFormat:@"<%@ = %08X | size = %ix%i>", [self class], self, backingWidth_, backingHeight_]; -} - - -- (void)dealloc -{ - /*CCLOGINFO(@"cocos2d: deallocing %@", self);*/ - - // Tear down GL - if(defaultFramebuffer_) - { - glDeleteFramebuffersOES(1, &defaultFramebuffer_); - defaultFramebuffer_ = 0; - } - - if(colorRenderbuffer_) - { - glDeleteRenderbuffersOES(1, &colorRenderbuffer_); - colorRenderbuffer_ = 0; - } - - if( depthBuffer_ ) - { - glDeleteRenderbuffersOES(1, &depthBuffer_); - 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]; - - [context_ release]; - context_ = nil; - - [super dealloc]; -} - -- (unsigned int) colorRenderBuffer -{ - return colorRenderbuffer_; -} - -- (unsigned int) defaultFrameBuffer -{ - return defaultFramebuffer_; -} - -- (unsigned int) msaaFrameBuffer -{ - return msaaFramebuffer_; -} - -- (unsigned int) msaaColorBuffer -{ - return msaaColorbuffer_; -} - -@end \ No newline at end of file diff --git a/cocos2dx/platform/ios/OpenGL_Internal.h b/cocos2dx/platform/ios/OpenGL_Internal.h index 4789683a9b..82dc47321c 100755 --- a/cocos2dx/platform/ios/OpenGL_Internal.h +++ b/cocos2dx/platform/ios/OpenGL_Internal.h @@ -67,7 +67,13 @@ Copyright (C) 2008 Apple Inc. All Rights Reserved. /* EAGL and GL functions calling wrappers that log on error */ #define CALL_EAGL_FUNCTION(__FUNC__, ...) ({ EAGLError __error = __FUNC__( __VA_ARGS__ ); if(__error != kEAGLErrorSuccess) printf("%s() called from %s returned error %i\n", #__FUNC__, __FUNCTION__, __error); (__error ? NO : YES); }) //#define CHECK_GL_ERROR() ({ GLenum __error = glGetError(); if(__error) printf("OpenGL error 0x%04X in %s\n", __error, __FUNCTION__); (__error ? NO : YES); }) -#define CHECK_GL_ERROR() ({ GLenum __error = glGetError(); if(__error) printf("OpenGL error 0x%04X in %s\n", __error, __FUNCTION__); }) +#define CHECK_GL_ERROR() ({ GLenum __error = glGetError(); if(__error) printf("OpenGL error 0x%04X in %s %d\n", __error, __FUNCTION__, __LINE__); }) + +#if DEBUG +#define CHECK_GL_ERROR_DEBUG() ({ GLenum __error = glGetError(); if(__error) printf("OpenGL error 0x%04X in %s %d\n", __error, __FUNCTION__, __LINE__); }) +#else +#define CHECK_GL_ERROR_DEBUG() +#endif /* Optional delegate methods support */ #ifndef __DELEGATE_IVAR__ diff --git a/tests/test.ios/test.xcodeproj/project.pbxproj.REMOVED.git-id b/tests/test.ios/test.xcodeproj/project.pbxproj.REMOVED.git-id index 3d9f9b6be1..757b3ef382 100644 --- a/tests/test.ios/test.xcodeproj/project.pbxproj.REMOVED.git-id +++ b/tests/test.ios/test.xcodeproj/project.pbxproj.REMOVED.git-id @@ -1 +1 @@ -dcf8ba0491db5fef75efe24f9e2c9fdf07364507 \ No newline at end of file +d699146e57dd79e6ba761d8748b5d01d4eb283ce \ No newline at end of file