From 1f082135633f426e5978d430633128849479c65b Mon Sep 17 00:00:00 2001 From: minggo Date: Fri, 7 Jan 2011 11:27:42 +0800 Subject: [PATCH] HelloWorld runs ok on iphone --- HelloWorld/iphone/AppController.mm | 5 +- .../project.pbxproj.REMOVED.git-id | 2 +- cocos2dx/platform/iphone/CCNS_iphone.mm | 6 +- cocos2dx/platform/iphone/EAGLView.h | 14 +-- cocos2dx/platform/iphone/EAGLView.mm | 4 +- cocos2dx/platform/iphone/ES1Renderer.m | 8 +- .../support/opengl_support/OpenGL_Internal.h | 119 +++++++++++------- 7 files changed, 97 insertions(+), 61 deletions(-) diff --git a/HelloWorld/iphone/AppController.mm b/HelloWorld/iphone/AppController.mm index 3c576ab96c..d58599e7c4 100644 --- a/HelloWorld/iphone/AppController.mm +++ b/HelloWorld/iphone/AppController.mm @@ -41,7 +41,10 @@ EAGLView *__glView = [EAGLView viewWithFrame: [window bounds] pixelFormat: kEAGLColorFormatRGBA8 depthFormat: 0 - preserveBackbuffer: NO]; + preserveBackbuffer: NO + sharegroup:nil + multiSampling:NO + numberOfSamples:0]; [window addSubview: __glView]; [window makeKeyAndVisible]; diff --git a/HelloWorld/iphone/HelloWorld.xcodeproj/project.pbxproj.REMOVED.git-id b/HelloWorld/iphone/HelloWorld.xcodeproj/project.pbxproj.REMOVED.git-id index e030a060f3..5952f60cfb 100644 --- a/HelloWorld/iphone/HelloWorld.xcodeproj/project.pbxproj.REMOVED.git-id +++ b/HelloWorld/iphone/HelloWorld.xcodeproj/project.pbxproj.REMOVED.git-id @@ -1 +1 @@ -821f97de148b8a4f5c67bbdb7751d22f3f9217c4 \ No newline at end of file +c65a3bbae8edd3b2e2ba8e8fac292bf18286a822 \ No newline at end of file diff --git a/cocos2dx/platform/iphone/CCNS_iphone.mm b/cocos2dx/platform/iphone/CCNS_iphone.mm index c054561e77..6d4d7a6cca 100644 --- a/cocos2dx/platform/iphone/CCNS_iphone.mm +++ b/cocos2dx/platform/iphone/CCNS_iphone.mm @@ -21,14 +21,16 @@ 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. ****************************************************************************/ -#include "platform/CCNS.h" + #import #import +#import +#include "platform/CCNS.h" static cocos2d::CGRect static_CCRectFromString(const char* pszContent) { CGRect rect = CGRectFromString([NSString stringWithUTF8String: pszContent]); - cocos2d::CGRect ret(rect.x, rect.y, rect.width, rect.height); + cocos2d::CGRect ret(rect.origin.x, rect.origin.y, rect.size.width, rect.size.height); return ret; } diff --git a/cocos2dx/platform/iphone/EAGLView.h b/cocos2dx/platform/iphone/EAGLView.h index 43a128f436..f58bdfa61c 100755 --- a/cocos2dx/platform/iphone/EAGLView.h +++ b/cocos2dx/platform/iphone/EAGLView.h @@ -89,8 +89,8 @@ Copyright (C) 2008 Apple Inc. All Rights Reserved. CGSize size_; BOOL discardFramebufferSupported_; - //fsaa addition - BOOL multisampling_; + //fsaa addition + BOOL multisampling_; unsigned int requestedSamples_; @private CFMutableDictionaryRef touchesIntergerDict; @@ -102,9 +102,9 @@ Copyright (C) 2008 Apple Inc. All Rights Reserved. /** creates an initializes an EAGLView with a frame, a color buffer format, and 0-bit depth buffer */ + (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; ++ (id) viewWithFrame:(CGRect)frame pixelFormat:(NSString*)format depthFormat:(GLuint)depth; +/** 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; @@ -113,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, 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; +/** 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; diff --git a/cocos2dx/platform/iphone/EAGLView.mm b/cocos2dx/platform/iphone/EAGLView.mm index dbad889be4..98ec572f5c 100755 --- a/cocos2dx/platform/iphone/EAGLView.mm +++ b/cocos2dx/platform/iphone/EAGLView.mm @@ -317,8 +317,10 @@ static cocos2d::CCTouch *s_pTouches[MAX_TOUCHES]; #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__); + } #if COCOS2D_DEBUG CHECK_GL_ERROR(); diff --git a/cocos2dx/platform/iphone/ES1Renderer.m b/cocos2dx/platform/iphone/ES1Renderer.m index 51a27f3985..47ee732b5b 100644 --- a/cocos2dx/platform/iphone/ES1Renderer.m +++ b/cocos2dx/platform/iphone/ES1Renderer.m @@ -1,10 +1,6 @@ -@interface ES1Renderer (private) - -- (GLenum) convertPixelFormat:(int) pixelFormat; - -@end - +#import "ES1Renderer.h" +#import "support/opengl_support/OpenGL_Internal.h" @implementation ES1Renderer @synthesize context=context_; diff --git a/cocos2dx/support/opengl_support/OpenGL_Internal.h b/cocos2dx/support/opengl_support/OpenGL_Internal.h index ee813c860d..24d5fce9a7 100644 --- a/cocos2dx/support/opengl_support/OpenGL_Internal.h +++ b/cocos2dx/support/opengl_support/OpenGL_Internal.h @@ -1,47 +1,80 @@ -/**************************************************************************** -Copyright (c) 2010 cocos2d-x.org +/* + + ===== IMPORTANT ===== + + This is sample code demonstrating API, technology or techniques in development. + Although this sample code has been reviewed for technical accuracy, it is not + final. Apple is supplying this information to help you plan for the adoption of + the technologies and programming interfaces described herein. This information + is subject to change, and software implemented based on this sample code should + be tested with final operating system software and final documentation. Newer + versions of this sample code may be provided with future seeds of the API or + technology. For information about updates to this and other developer + documentation, view the New & Updated sidebars in subsequent documentation + seeds. + + ===================== + + File: OpenGL_Internal.h + Abstract: This file is included for support purposes and isn't necessary for + understanding this sample. + + Version: 1.0 + + Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Inc. + ("Apple") in consideration of your agreement to the following terms, and your + use, installation, modification or redistribution of this Apple software + constitutes acceptance of these terms. If you do not agree with these terms, + please do not use, install, modify or redistribute this Apple software. + + In consideration of your agreement to abide by the following terms, and subject + to these terms, Apple grants you a personal, non-exclusive license, under + Apple's copyrights in this original Apple software (the "Apple Software"), to + use, reproduce, modify and redistribute the Apple Software, with or without + modifications, in source and/or binary forms; provided that if you redistribute + the Apple Software in its entirety and without modifications, you must retain + this notice and the following text and disclaimers in all such redistributions + of the Apple Software. + Neither the name, trademarks, service marks or logos of Apple Inc. may be used + to endorse or promote products derived from the Apple Software without specific + prior written permission from Apple. Except as expressly stated in this notice, + no other rights or licenses, express or implied, are granted by Apple herein, + including but not limited to any patent rights that may be infringed by your + derivative works or by other works in which the Apple Software may be + incorporated. + + The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO + WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED + WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR + PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN + COMBINATION WITH YOUR PRODUCTS. + + IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR + DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF + CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF + APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + Copyright (C) 2008 Apple Inc. All Rights Reserved. + + */ -http://www.cocos2d-x.org +/* Generic error reporting */ +#define REPORT_ERROR(__FORMAT__, ...) printf("%s: %s\n", __FUNCTION__, [[NSString stringWithFormat:__FORMAT__, __VA_ARGS__] UTF8String]) -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: +/* 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__); }) -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. -****************************************************************************/ - -#ifndef __SUPPORT_OPGL_SUPPORT_OPGL_INTERNAL_H__ -#define __SUPPORT_OPGL_SUPPORT_OPGL_INTERNAL_H__ -#include - -/* Generic error reporting */ -#define REPORT_ERROR(__FORMAT__, ...) std::printf("%s: %s\n", __FUNCTION__, __VA_ARGS__) - -/* EAGL and GL functions calling wrappers that log on error */ -#define CALL_EAGL_FUNCTION(__FUNC__, ...) ({ EAGLError __error = __FUNC__( __VA_ARGS__ ); if(__error != kEAGLErrorSuccess) std::printf("%s() called from %s returned error %i\n", #__FUNC__, __FUNCTION__, __error); (__error ? false : true); }) -//#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) std::printf("OpenGL error 0x%04X in %s\n", __error, __FUNCTION__); }) - -/* Optional delegate methods support */ -#ifndef __DELEGATE_IVAR__ -#define __DELEGATE_IVAR__ _delegate -#endif -#ifndef __DELEGATE_METHODS_IVAR__ -#define __DELEGATE_METHODS_IVAR__ _delegateMethods -#endif -#define TEST_DELEGATE_METHOD_BIT(__BIT__) (self->__DELEGATE_METHODS_IVAR__ & (1 << __BIT__)) +/* Optional delegate methods support */ +#ifndef __DELEGATE_IVAR__ +#define __DELEGATE_IVAR__ _delegate +#endif +#ifndef __DELEGATE_METHODS_IVAR__ +#define __DELEGATE_METHODS_IVAR__ _delegateMethods +#endif +#define TEST_DELEGATE_METHOD_BIT(__BIT__) (self->__DELEGATE_METHODS_IVAR__ & (1 << __BIT__)) #define SET_DELEGATE_METHOD_BIT(__BIT__, __NAME__) { if([self->__DELEGATE_IVAR__ respondsToSelector:@selector(__NAME__)]) self->__DELEGATE_METHODS_IVAR__ |= (1 << __BIT__); else self->__DELEGATE_METHODS_IVAR__ &= ~(1 << __BIT__); } - -#endif // __SUPPORT_OPGL_SUPPORT_OPGL_INTERNAL_H__