issue #1056: Added gles2.0 support for ios platform.

This commit is contained in:
James Chen 2012-03-21 10:05:23 +08:00
parent 7c0af610ff
commit 321771a7ea
14 changed files with 381 additions and 318 deletions

View File

@ -45,7 +45,7 @@ static AppDelegate s_sharedApplication;
window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]]; window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]];
EAGLView *__glView = [EAGLView viewWithFrame: [window bounds] EAGLView *__glView = [EAGLView viewWithFrame: [window bounds]
pixelFormat: kEAGLColorFormatRGBA8 pixelFormat: kEAGLColorFormatRGBA8
depthFormat: GL_DEPTH_COMPONENT16_OES depthFormat: GL_DEPTH_COMPONENT16
preserveBackbuffer: NO preserveBackbuffer: NO
sharegroup:nil sharegroup:nil
multiSampling:NO multiSampling:NO

View File

@ -1 +1 @@
adb49aea78ff4d88fe106fc79ff1b90275efc86a 70c443ceaf43c95b4a380aa01b43a1875462d911

View File

@ -27,7 +27,7 @@ THE SOFTWARE.
#include "CCPlatformMacros.h" #include "CCPlatformMacros.h"
NS_CC_BEGIN; NS_CC_BEGIN
/// The max length of CCLog message. /// The max length of CCLog message.
static const int kMaxLogLen = 16*1024; static const int kMaxLogLen = 16*1024;
@ -65,6 +65,6 @@ typedef enum LanguageType
kLanguageRussian kLanguageRussian
} ccLanguageType; } ccLanguageType;
NS_CC_END; NS_CC_END
#endif // __CC_COMMON_H__ #endif // __CC_COMMON_H__

View File

@ -40,8 +40,8 @@ THE SOFTWARE.
#include "CCCommon.h" #include "CCCommon.h"
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
#include "OpenGLES/ES1/gl.h" #include "OpenGLES/ES2/gl.h"
#include "OpenGLES/ES1/glext.h" #include "OpenGLES/ES2/glext.h"
#endif #endif
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)

View File

@ -21,11 +21,11 @@
THE SOFTWARE. THE SOFTWARE.
****************************************************************************/ ****************************************************************************/
#include "CCSAXParser.h"
#include "CCDictionary.h"
#include <libxml/parser.h> #include <libxml/parser.h>
#include <libxml/tree.h> #include <libxml/tree.h>
#include <libxml/xmlmemory.h> #include <libxml/xmlmemory.h>
#include "CCSAXParser.h"
#include "CCDictionary.h"
#include "CCLibxml2.h" #include "CCLibxml2.h"
#include "CCFileUtils.h" #include "CCFileUtils.h"
@ -34,7 +34,6 @@ NS_CC_BEGIN;
CCSAXParser::CCSAXParser() CCSAXParser::CCSAXParser()
{ {
m_pDelegator = NULL; m_pDelegator = NULL;
} }
CCSAXParser::~CCSAXParser(void) CCSAXParser::~CCSAXParser(void)

View File

@ -2,17 +2,18 @@
* cocos2d for iPhone: http://www.cocos2d-iphone.org * cocos2d for iPhone: http://www.cocos2d-iphone.org
* *
* Copyright (c) 2010 Ricardo Quesada * Copyright (c) 2010 Ricardo Quesada
* * Copyright (c) 2011 Zynga Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights * in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is * copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions: * furnished to do so, subject to the following conditions:
* *
* The above copyright notice and this permission notice shall be included in * The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software. * all copies or substantial portions of the Software.
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@ -25,41 +26,55 @@
* File autogenerated with Xcode. Adapted for cocos2d needs. * 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 <OpenGLES/ES2/gl.h>
#import <OpenGLES/ES2/glext.h>
@interface CCES2Renderer : NSObject <CCESRenderer>
{
// 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" //buffers for MSAA
GLuint msaaFramebuffer_;
#import <OpenGLES/ES1/gl.h> GLuint msaaColorbuffer_;
#import <OpenGLES/ES1/glext.h>
EAGLContext *context_;
@interface ES1Renderer : NSObject <ESRenderer> }
{
// The pixel dimensions of the CAEAGLLayer /** Color Renderbuffer */
GLint backingWidth_; @property (nonatomic,readonly) GLuint colorRenderbuffer;
GLint backingHeight_;
/** Default Renderbuffer */
unsigned int samplesToUse_; @property (nonatomic,readonly) GLuint defaultFramebuffer;
BOOL multiSampling_;
/** MSAA Framebuffer */
unsigned int depthFormat_; @property (nonatomic,readonly) GLuint msaaFramebuffer;
unsigned int pixelFormat_;
/** MSAA Color Buffer */
// The OpenGL ES names for the framebuffer and renderbuffer used to render to this view @property (nonatomic,readonly) GLuint msaaColorbuffer;
GLuint defaultFramebuffer_;
GLuint colorRenderbuffer_; /** EAGLContext */
GLuint depthBuffer_; @property (nonatomic,readonly) EAGLContext* context;
- (BOOL)resizeFromLayer:(CAEAGLLayer *)layer;
//buffers for MSAA
GLuint msaaFramebuffer_;
GLuint msaaColorbuffer_;
EAGLContext *context_;
}
/** EAGLContext */
@property (nonatomic,readonly) EAGLContext* context;
- (BOOL)resizeFromLayer:(CAEAGLLayer *)layer;
@end @end

View File

@ -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

View File

@ -2,17 +2,18 @@
* cocos2d for iPhone: http://www.cocos2d-iphone.org * cocos2d for iPhone: http://www.cocos2d-iphone.org
* *
* Copyright (c) 2010 Ricardo Quesada * Copyright (c) 2010 Ricardo Quesada
* * Copyright (c) 2011 Zynga Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights * in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is * copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions: * furnished to do so, subject to the following conditions:
* *
* The above copyright notice and this permission notice shall be included in * The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software. * all copies or substantial portions of the Software.
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@ -25,22 +26,26 @@
* File autogenerated with Xcode. Adapted for cocos2d needs. * File autogenerated with Xcode. Adapted for cocos2d needs.
*/ */
#import <QuartzCore/QuartzCore.h> // 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 <OpenGLES/EAGL.h> #import "CCPlatformMacros.h"
#import <OpenGLES/EAGLDrawable.h> #import <QuartzCore/QuartzCore.h>
@protocol ESRenderer <NSObject> #import <OpenGLES/EAGL.h>
#import <OpenGLES/EAGLDrawable.h>
- (id) initWithDepthFormat:(unsigned int)depthFormat withPixelFormat:(unsigned int)pixelFormat withSharegroup:(EAGLSharegroup*)sharegroup withMultiSampling:(BOOL) multiSampling withNumberOfSamples:(unsigned int) requestedSamples;
@protocol CCESRenderer <NSObject>
- (BOOL) resizeFromLayer:(CAEAGLLayer *)layer;
- (id) initWithDepthFormat:(unsigned int)depthFormat withPixelFormat:(unsigned int)pixelFormat withSharegroup:(EAGLSharegroup*)sharegroup withMultiSampling:(BOOL) multiSampling withNumberOfSamples:(unsigned int) requestedSamples;
- (EAGLContext*) context;
- (CGSize) backingSize; - (BOOL) resizeFromLayer:(CAEAGLLayer *)layer;
- (unsigned int) colorRenderBuffer; - (EAGLContext*) context;
- (unsigned int) defaultFrameBuffer; - (CGSize) backingSize;
- (unsigned int) msaaFrameBuffer;
- (unsigned int) msaaColorBuffer; - (unsigned int) colorRenderBuffer;
- (unsigned int) defaultFrameBuffer;
- (unsigned int) msaaFrameBuffer;
- (unsigned int) msaaColorBuffer;
@end @end

View File

@ -39,8 +39,8 @@ THE SOFTWARE.
using namespace cocos2d; using namespace cocos2d;
static void static_addValueToCCDict(id key, id value, CCDictionary<std::string, CCObject*>* pDict); static void static_addValueToCCDict(id key, id value, CCDictionary* pDict);
static void static_addItemToCCArray(id item, CCMutableArray<CCObject*> *pArray); static void static_addItemToCCArray(id item, CCArray* pArray);
static const char *static_ccRemoveHDSuffixFromFile( const char *pszPath) static const char *static_ccRemoveHDSuffixFromFile( const char *pszPath)
{ {
@ -142,7 +142,7 @@ static const char* static_fullPathFromRelativePath(const char *pszRelativePath)
return [fullpath UTF8String]; return [fullpath UTF8String];
} }
static void static_addItemToCCArray(id item, CCMutableArray<CCObject*> *pArray) static void static_addItemToCCArray(id item, CCArray *pArray)
{ {
// add string value into array // add string value into array
if ([item isKindOfClass:[NSString class]]) { if ([item isKindOfClass:[NSString class]]) {
@ -165,7 +165,7 @@ static void static_addItemToCCArray(id item, CCMutableArray<CCObject*> *pArray)
// add dictionary value into array // add dictionary value into array
if ([item isKindOfClass:[NSDictionary class]]) { if ([item isKindOfClass:[NSDictionary class]]) {
CCDictionary<std::string, CCObject*>* pDictItem = new CCDictionary<std::string, CCObject*>(); CCDictionary* pDictItem = new CCDictionary();
for (id subKey in [item allKeys]) { for (id subKey in [item allKeys]) {
id subValue = [item objectForKey:subKey]; id subValue = [item objectForKey:subKey];
static_addValueToCCDict(subKey, subValue, pDictItem); static_addValueToCCDict(subKey, subValue, pDictItem);
@ -177,7 +177,8 @@ static void static_addItemToCCArray(id item, CCMutableArray<CCObject*> *pArray)
// add array value into array // add array value into array
if ([item isKindOfClass:[NSArray class]]) { if ([item isKindOfClass:[NSArray class]]) {
CCMutableArray<CCObject*> *pArrayItem = new CCMutableArray<CCObject*>(); CCArray *pArrayItem = new CCArray();
pArrayItem->init();
for (id subItem in item) { for (id subItem in item) {
static_addItemToCCArray(subItem, pArrayItem); static_addItemToCCArray(subItem, pArrayItem);
} }
@ -187,7 +188,7 @@ static void static_addItemToCCArray(id item, CCMutableArray<CCObject*> *pArray)
} }
} }
static void static_addValueToCCDict(id key, id value, CCDictionary<std::string, CCObject*>* pDict) static void static_addValueToCCDict(id key, id value, CCDictionary* pDict)
{ {
// the key must be a string // the key must be a string
CCAssert([key isKindOfClass:[NSString class]], "The key should 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<std::string,
// the value is a new dictionary // the value is a new dictionary
if ([value isKindOfClass:[NSDictionary class]]) { if ([value isKindOfClass:[NSDictionary class]]) {
CCDictionary<std::string, CCObject*>* pSubDict = new CCDictionary<std::string, CCObject*>(); CCDictionary* pSubDict = new CCDictionary();
for (id subKey in [value allKeys]) { for (id subKey in [value allKeys]) {
id subValue = [value objectForKey:subKey]; id subValue = [value objectForKey:subKey];
static_addValueToCCDict(subKey, subValue, pSubDict); static_addValueToCCDict(subKey, subValue, pSubDict);
} }
pDict->setObject(pSubDict, pKey); pDict->setObject(pSubDict, pKey.c_str());
pSubDict->release(); pSubDict->release();
return; return;
} }
@ -209,7 +210,7 @@ static void static_addValueToCCDict(id key, id value, CCDictionary<std::string,
if ([value isKindOfClass:[NSString class]]) { if ([value isKindOfClass:[NSString class]]) {
CCString* pValue = new CCString([value UTF8String]); CCString* pValue = new CCString([value UTF8String]);
pDict->setObject(pValue, pKey); pDict->setObject(pValue, pKey.c_str());
pValue->release(); pValue->release();
return; return;
} }
@ -219,18 +220,19 @@ static void static_addValueToCCDict(id key, id value, CCDictionary<std::string,
NSString* pStr = [value stringValue]; NSString* pStr = [value stringValue];
CCString* pValue = new CCString([pStr UTF8String]); CCString* pValue = new CCString([pStr UTF8String]);
pDict->setObject(pValue, pKey); pDict->setObject(pValue, pKey.c_str());
pValue->release(); pValue->release();
return; return;
} }
// the value is a array // the value is a array
if ([value isKindOfClass:[NSArray class]]) { if ([value isKindOfClass:[NSArray class]]) {
CCMutableArray<CCObject*> *pArray = new CCMutableArray<CCObject*>(); CCArray *pArray = new CCArray();
pArray->init();
for (id item in value) { for (id item in value) {
static_addItemToCCArray(item, pArray); static_addItemToCCArray(item, pArray);
} }
pDict->setObject(pArray, pKey); pDict->setObject(pArray, pKey.c_str());
pArray->release(); pArray->release();
return; return;
} }
@ -293,20 +295,20 @@ namespace cocos2d {
return pRet->m_sString.c_str(); return pRet->m_sString.c_str();
} }
CCDictionary<std::string, CCObject*> *CCFileUtils::dictionaryWithContentsOfFile(const char *pFileName) CCDictionary *CCFileUtils::dictionaryWithContentsOfFile(const char *pFileName)
{ {
CCDictionary<std::string, CCObject*> *ret = dictionaryWithContentsOfFileThreadSafe(pFileName); CCDictionary *ret = dictionaryWithContentsOfFileThreadSafe(pFileName);
ret->autorelease(); ret->autorelease();
return ret; return ret;
} }
CCDictionary<std::string, CCObject*> *CCFileUtils::dictionaryWithContentsOfFileThreadSafe(const char *pFileName) CCDictionary *CCFileUtils::dictionaryWithContentsOfFileThreadSafe(const char *pFileName)
{ {
NSString* pPath = [NSString stringWithUTF8String:pFileName]; NSString* pPath = [NSString stringWithUTF8String:pFileName];
NSDictionary* pDict = [NSDictionary dictionaryWithContentsOfFile:pPath]; NSDictionary* pDict = [NSDictionary dictionaryWithContentsOfFile:pPath];
CCDictionary<std::string, CCObject*>* pRet = new CCDictionary<std::string, CCObject*>(); CCDictionary* pRet = new CCDictionary();
for (id key in [pDict allKeys]) { for (id key in [pDict allKeys]) {
id value = [pDict objectForKey:key]; id value = [pDict objectForKey:key];
static_addValueToCCDict(key, value, pRet); static_addValueToCCDict(key, value, pRet);

View File

@ -64,11 +64,11 @@ Copyright (C) 2008 Apple Inc. All Rights Reserved.
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
#import <OpenGLES/EAGL.h> #import <OpenGLES/EAGL.h>
#import <OpenGLES/EAGLDrawable.h> #import <OpenGLES/EAGLDrawable.h>
#import <OpenGLES/ES1/gl.h> #import <OpenGLES/ES2/gl.h>
#import <OpenGLES/ES1/glext.h> #import <OpenGLES/ES2/glext.h>
#import <CoreFoundation/CoreFoundation.h> #import <CoreFoundation/CoreFoundation.h>
#import "ESRenderer.h" #import "CCESRenderer.h"
//CLASS INTERFACE: //CLASS INTERFACE:
@ -79,7 +79,7 @@ Copyright (C) 2008 Apple Inc. All Rights Reserved.
*/ */
@interface EAGLView : UIView <UIKeyInput, UITextInput> @interface EAGLView : UIView <UIKeyInput, UITextInput>
{ {
id <ESRenderer> renderer_; id <CCESRenderer> renderer_;
EAGLContext *context_; // weak ref EAGLContext *context_; // weak ref
NSString *pixelformat_; NSString *pixelformat_;

View File

@ -64,7 +64,7 @@ Copyright (C) 2008 Apple Inc. All Rights Reserved.
#import <QuartzCore/QuartzCore.h> #import <QuartzCore/QuartzCore.h>
#import "EAGLView.h" #import "EAGLView.h"
#import "ES1Renderer.h" #import "CCES2Renderer.h"
#import "CCDirector.h" #import "CCDirector.h"
#import "CCSet.h" #import "CCSet.h"
#import "CCTouch.h" #import "CCTouch.h"
@ -247,19 +247,23 @@ static cocos2d::CCTouch *s_pTouches[MAX_TOUCHES];
pixelformat_, kEAGLDrawablePropertyColorFormat, nil]; pixelformat_, kEAGLDrawablePropertyColorFormat, nil];
renderer_ = [[ES1Renderer alloc] initWithDepthFormat:depthFormat_ renderer_ = [[CCES2Renderer alloc] initWithDepthFormat:depthFormat_
withPixelFormat:[self convertPixelFormat:pixelformat_] withPixelFormat:[self convertPixelFormat:pixelformat_]
withSharegroup:sharegroup withSharegroup:sharegroup
withMultiSampling:multiSampling_ withMultiSampling:multiSampling_
withNumberOfSamples:requestedSamples_]; withNumberOfSamples:requestedSamples_];
NSAssert(renderer_, @"OpenGL ES 2.O is required.");
if (!renderer_) if (!renderer_)
return NO; return NO;
context_ = [renderer_ context]; context_ = [renderer_ context];
[context_ renderbufferStorage:GL_RENDERBUFFER_OES fromDrawable:eaglLayer];
//discardFramebufferSupported_ = [[CCConfiguration sharedConfiguration] supportsDiscardFramebuffer]; //discardFramebufferSupported_ = [[CCConfiguration sharedConfiguration] supportsDiscardFramebuffer];
CHECK_GL_ERROR_DEBUG();
return YES; return YES;
} }
@ -301,8 +305,8 @@ static cocos2d::CCTouch *s_pTouches[MAX_TOUCHES];
{ {
/* Resolve from msaaFramebuffer to resolveFramebuffer */ /* Resolve from msaaFramebuffer to resolveFramebuffer */
//glDisable(GL_SCISSOR_TEST); //glDisable(GL_SCISSOR_TEST);
glBindFramebufferOES(GL_READ_FRAMEBUFFER_APPLE, [renderer_ msaaFrameBuffer]); glBindFramebuffer(GL_READ_FRAMEBUFFER_APPLE, [renderer_ msaaFrameBuffer]);
glBindFramebufferOES(GL_DRAW_FRAMEBUFFER_APPLE, [renderer_ defaultFrameBuffer]); glBindFramebuffer(GL_DRAW_FRAMEBUFFER_APPLE, [renderer_ defaultFrameBuffer]);
glResolveMultisampleFramebufferAPPLE(); glResolveMultisampleFramebufferAPPLE();
} }
@ -312,29 +316,29 @@ static cocos2d::CCTouch *s_pTouches[MAX_TOUCHES];
{ {
if (depthFormat_) 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); glDiscardFramebufferEXT(GL_READ_FRAMEBUFFER_APPLE, 2, attachments);
} }
else else
{ {
GLenum attachments[] = {GL_COLOR_ATTACHMENT0_OES}; GLenum attachments[] = {GL_COLOR_ATTACHMENT0};
glDiscardFramebufferEXT(GL_READ_FRAMEBUFFER_APPLE, 1, attachments); glDiscardFramebufferEXT(GL_READ_FRAMEBUFFER_APPLE, 1, attachments);
} }
glBindRenderbufferOES(GL_RENDERBUFFER_OES, [renderer_ colorRenderBuffer]); glBindRenderbuffer(GL_RENDERBUFFER, [renderer_ colorRenderBuffer]);
} }
// not MSAA // not MSAA
else if (depthFormat_ ) { else if (depthFormat_ ) {
GLenum attachments[] = { GL_DEPTH_ATTACHMENT_OES}; GLenum attachments[] = { GL_DEPTH_ATTACHMENT};
glDiscardFramebufferEXT(GL_FRAMEBUFFER_OES, 1, attachments); glDiscardFramebufferEXT(GL_FRAMEBUFFER, 1, attachments);
} }
} }
#endif // __IPHONE_4_0 #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__); // 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 // We can safely re-bind the framebuffer here, since this will be the
// 1st instruction of the new main loop // 1st instruction of the new main loop
if( multiSampling_ ) if( multiSampling_ )
glBindFramebufferOES(GL_FRAMEBUFFER_OES, [renderer_ msaaFrameBuffer]); glBindFramebuffer(GL_FRAMEBUFFER, [renderer_ msaaFrameBuffer]);
} }
- (unsigned int) convertPixelFormat:(NSString*) pixelFormat - (unsigned int) convertPixelFormat:(NSString*) pixelFormat
@ -356,7 +360,7 @@ static cocos2d::CCTouch *s_pTouches[MAX_TOUCHES];
if([pixelFormat isEqualToString:@"EAGLColorFormat565"]) if([pixelFormat isEqualToString:@"EAGLColorFormat565"])
pFormat = GL_RGB565_OES; pFormat = GL_RGB565;
else else
pFormat = GL_RGBA8_OES; pFormat = GL_RGBA8_OES;

View File

@ -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

View File

@ -67,7 +67,13 @@ Copyright (C) 2008 Apple Inc. All Rights Reserved.
/* EAGL and GL functions calling wrappers that log on error */ /* 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 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__); (__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 */ /* Optional delegate methods support */
#ifndef __DELEGATE_IVAR__ #ifndef __DELEGATE_IVAR__

View File

@ -1 +1 @@
dcf8ba0491db5fef75efe24f9e2c9fdf07364507 d699146e57dd79e6ba761d8748b5d01d4eb283ce