From 07af58c0c23f592469c112dee64e0e51f00d9500 Mon Sep 17 00:00:00 2001 From: huangshiwu Date: Fri, 22 Aug 2014 16:22:16 +0800 Subject: [PATCH] OpenGL context attributions setting revise -2 --- cocos/platform/CCApplicationProtocol.h | 10 ++++++-- cocos/platform/CCGLView.cpp | 11 ++++++--- cocos/platform/CCGLView.h | 7 +++--- cocos/platform/android/CCGLViewImpl.cpp | 5 ---- cocos/platform/android/CCGLViewImpl.h | 4 ---- .../org/cocos2dx/lib/Cocos2dxActivity.java | 24 +++++++++++-------- cocos/platform/android/javaactivity.cpp | 16 ++++++------- cocos/platform/desktop/CCGLViewImpl.cpp | 12 +++++----- cocos/platform/ios/CCGLViewImpl.h | 2 -- cocos/platform/ios/CCGLViewImpl.mm | 15 ++++-------- cocos/platform/linux/CCApplication.cpp | 2 +- cocos/platform/mac/CCApplication.mm | 2 +- cocos/platform/win32/CCApplication.cpp | 2 +- .../proj.ios_mac/ios/AppController.mm | 18 ++++++++------ .../cpp-template-default/src/AppDelegate.cpp | 11 +++++++++ .../cpp-template-default/src/AppDelegate.h | 2 ++ tests/cpp-empty-test/Classes/AppDelegate.cpp | 6 ++--- tests/cpp-empty-test/Classes/AppDelegate.h | 2 +- .../cpp-empty-test/proj.ios/AppController.mm | 2 +- tests/cpp-tests/Classes/AppDelegate.cpp | 10 ++++---- tests/cpp-tests/Classes/AppDelegate.h | 2 +- .../org/cocos2dx/cpp_tests/AppActivity.java | 8 ------- .../proj.ios/Classes/testsAppDelegate.mm | 2 +- .../project/Classes/AppDelegate.cpp | 6 ++--- .../project/Classes/AppDelegate.h | 2 +- .../project/proj.ios/AppController.mm | 10 ++++---- .../lua-tests/project/Classes/AppDelegate.cpp | 6 ++--- tests/lua-tests/project/Classes/AppDelegate.h | 2 +- .../project/proj.ios_mac/ios/AppController.mm | 9 ++++--- 29 files changed, 111 insertions(+), 99 deletions(-) diff --git a/cocos/platform/CCApplicationProtocol.h b/cocos/platform/CCApplicationProtocol.h index 5f4aa94829..2e56e0524d 100644 --- a/cocos/platform/CCApplicationProtocol.h +++ b/cocos/platform/CCApplicationProtocol.h @@ -102,8 +102,14 @@ public: */ virtual void setAnimationInterval(double interval) = 0; - //initialize the OpenGL/OpenGL ES context attribution here for all platforms; - virtual void initContextAttrs() {} + //subclass override the function to set OpenGL context attribution instead of use default value + //and now can only set six attributions:redBits,greenBits,blueBits,alphaBits,depthBits,stencilBits + //default value are(5,6,5,0,16,0), usually use as follows: + /*void AppDelegate::initGLContextAttrs(){ + GLContextAttrs glContextAttrs = {8, 8, 8, 8, 24, 8}; + GLView::setGLContextAttrs(glContextAttrs); + }*/ + virtual void initGLContextAttrs() {} /** @brief Get current language config diff --git a/cocos/platform/CCGLView.cpp b/cocos/platform/CCGLView.cpp index 64d733d804..98ccb9784b 100644 --- a/cocos/platform/CCGLView.cpp +++ b/cocos/platform/CCGLView.cpp @@ -71,11 +71,16 @@ namespace { } //default context attributions are setted as follows -ContextAttrs GLView::_contextAttrs = {5, 6, 5, 0, 16, 0}; +GLContextAttrs GLView::_glContextAttrs = {5, 6, 5, 0, 16, 0}; -void GLView::setContextAttrs(ContextAttrs& contextAttrs) +void GLView::setGLContextAttrs(GLContextAttrs& glContextAttrs) { - _contextAttrs = contextAttrs; + _glContextAttrs = glContextAttrs; +} + +GLContextAttrs GLView::getGLContextAttrs() +{ + return _glContextAttrs; } GLView::GLView() diff --git a/cocos/platform/CCGLView.h b/cocos/platform/CCGLView.h index 1f4b746fe6..f8243770ed 100644 --- a/cocos/platform/CCGLView.h +++ b/cocos/platform/CCGLView.h @@ -64,7 +64,7 @@ enum class ResolutionPolicy UNKNOWN, }; -struct ContextAttrs +struct GLContextAttrs { int redBits; int greenBits; @@ -109,8 +109,9 @@ public: virtual bool windowShouldClose() { return false; }; //static method and member so that we can modify it on all platforms before create OpenGL context - static void setContextAttrs(ContextAttrs& contextAttrs); - static ContextAttrs _contextAttrs; + static void setGLContextAttrs(GLContextAttrs& glContextAttrs); + static GLContextAttrs getGLContextAttrs(); + static GLContextAttrs _glContextAttrs; /** * Polls input events. Subclass must implement methods if platform diff --git a/cocos/platform/android/CCGLViewImpl.cpp b/cocos/platform/android/CCGLViewImpl.cpp index fc5e322305..8431dcdcab 100644 --- a/cocos/platform/android/CCGLViewImpl.cpp +++ b/cocos/platform/android/CCGLViewImpl.cpp @@ -73,11 +73,6 @@ GLViewImpl* GLViewImpl::create(const std::string& viewName) return nullptr; } -ContextAttrs GLViewImpl::getContextAttrs() -{ - return _contextAttrs; -} - GLViewImpl* GLViewImpl::createWithFullScreen(const std::string& viewName) { auto ret = new GLViewImpl(); diff --git a/cocos/platform/android/CCGLViewImpl.h b/cocos/platform/android/CCGLViewImpl.h index 43fae39323..820189e148 100644 --- a/cocos/platform/android/CCGLViewImpl.h +++ b/cocos/platform/android/CCGLViewImpl.h @@ -44,10 +44,6 @@ public: static GLViewImpl* createWithRect(const std::string& viewName, Rect rect, float frameZoomFactor = 1.0f); static GLViewImpl* createWithFullScreen(const std::string& viewName); - //return context attribution to Java class Cocos2dxActivity which really - //create OpenGL ES context on android platform only - static ContextAttrs getContextAttrs(); - bool isOpenGLReady() override; void end() override; void swapBuffers() override; diff --git a/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxActivity.java b/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxActivity.java index 04a53b4e63..1ad24349ab 100644 --- a/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxActivity.java +++ b/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxActivity.java @@ -51,6 +51,7 @@ public abstract class Cocos2dxActivity extends Activity implements Cocos2dxHelpe // =========================================================== private Cocos2dxGLSurfaceView mGLSurfaceView; + private int[] glContextAttrs; private Cocos2dxHandler mHandler; private static Cocos2dxActivity sContext = null; private Cocos2dxVideoHelper mVideoHelper = null; @@ -95,16 +96,16 @@ public abstract class Cocos2dxActivity extends Activity implements Cocos2dxHelpe Cocos2dxHelper.init(this); - int[] OGLCtxattrs = getContextAttrs(); - this.initWithOGLCtxattrs(OGLCtxattrs); + this.glContextAttrs = getGLContextAttrs(); + this.init(); if (mVideoHelper == null) { mVideoHelper = new Cocos2dxVideoHelper(this, mFrameLayout); } } - //native method,call GLViewImpl::getContextAttrs() to get the OpenGL ES context attributions - private static native int[] getContextAttrs(); + //native method,call GLViewImpl::getGLContextAttrs() to get the OpenGL ES context attributions + private static native int[] getGLContextAttrs(); // =========================================================== // Getter & Setter @@ -171,7 +172,7 @@ public abstract class Cocos2dxActivity extends Activity implements Cocos2dxHelpe // =========================================================== // Methods // =========================================================== - public void initWithOGLCtxattrs(int[] OGLCtxattrs) { + public void init() { // FrameLayout ViewGroup.LayoutParams framelayout_params = @@ -191,16 +192,14 @@ public abstract class Cocos2dxActivity extends Activity implements Cocos2dxHelpe mFrameLayout.addView(edittext); // Cocos2dxGLSurfaceView - this.mGLSurfaceView = new Cocos2dxGLSurfaceView(this); - - this.mGLSurfaceView.setEGLConfigChooser(OGLCtxattrs[0], OGLCtxattrs[1],OGLCtxattrs[2],OGLCtxattrs[3],OGLCtxattrs[4],OGLCtxattrs[5]); + this.mGLSurfaceView = this.onCreateView(); // ...add to FrameLayout mFrameLayout.addView(this.mGLSurfaceView); // Switch to supported OpenGL (ARGB888) mode on emulator if (isAndroidEmulator()) - this.mGLSurfaceView.setEGLConfigChooser(8 , 8, 8, 8, 16, 0); + this.mGLSurfaceView.setEGLConfigChooser(8, 8, 8, 8, 16, 0); this.mGLSurfaceView.setCocos2dxRenderer(new Cocos2dxRenderer()); this.mGLSurfaceView.setCocos2dxEditText(edittext); @@ -210,7 +209,12 @@ public abstract class Cocos2dxActivity extends Activity implements Cocos2dxHelpe } public Cocos2dxGLSurfaceView onCreateView() { - return new Cocos2dxGLSurfaceView(this); + Cocos2dxGLSurfaceView glSurfaceView = new Cocos2dxGLSurfaceView(this); + + glSurfaceView.setEGLConfigChooser(this.glContextAttrs[0], this.glContextAttrs[1],this.glContextAttrs[2], + this.glContextAttrs[3],this.glContextAttrs[4],this.glContextAttrs[5]); + + return glSurfaceView; } private final static boolean isAndroidEmulator() { diff --git a/cocos/platform/android/javaactivity.cpp b/cocos/platform/android/javaactivity.cpp index fd43b859df..d5d2f7df69 100644 --- a/cocos/platform/android/javaactivity.cpp +++ b/cocos/platform/android/javaactivity.cpp @@ -81,20 +81,20 @@ void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thi } } -jintArray Java_org_cocos2dx_lib_Cocos2dxActivity_getContextAttrs(JNIEnv* env, jobject thiz) +jintArray Java_org_cocos2dx_lib_Cocos2dxActivity_getGLContextAttrs(JNIEnv* env, jobject thiz) { cocos_android_app_init(env, thiz); - cocos2d::Application::getInstance()->initContextAttrs(); - ContextAttrs _contextAttrs = GLViewImpl::getContextAttrs(); + cocos2d::Application::getInstance()->initGLContextAttrs(); + GLContextAttrs _glContextAttrs = GLView::getGLContextAttrs(); - int tmp[6] = {_contextAttrs.redBits, _contextAttrs.greenBits, _contextAttrs.blueBits, - _contextAttrs.alphaBits, _contextAttrs.depthBits, _contextAttrs.stencilBits}; + int tmp[6] = {_glContextAttrs.redBits, _glContextAttrs.greenBits, _glContextAttrs.blueBits, + _glContextAttrs.alphaBits, _glContextAttrs.depthBits, _glContextAttrs.stencilBits}; - jintArray contextAttrsJava = env->NewIntArray(6); - env->SetIntArrayRegion(contextAttrsJava, 0, 6, tmp); + jintArray glContextAttrsJava = env->NewIntArray(6); + env->SetIntArrayRegion(glContextAttrsJava, 0, 6, tmp); - return contextAttrsJava; + return glContextAttrsJava; } void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeOnSurfaceChanged(JNIEnv* env, jobject thiz, jint w, jint h) diff --git a/cocos/platform/desktop/CCGLViewImpl.cpp b/cocos/platform/desktop/CCGLViewImpl.cpp index ef36d9134a..7ed74f4852 100644 --- a/cocos/platform/desktop/CCGLViewImpl.cpp +++ b/cocos/platform/desktop/CCGLViewImpl.cpp @@ -344,12 +344,12 @@ bool GLViewImpl::initWithRect(const std::string& viewName, Rect rect, float fram _frameZoomFactor = frameZoomFactor; glfwWindowHint(GLFW_RESIZABLE,GL_FALSE); - glfwWindowHint(GLFW_RED_BITS,_contextAttrs.redBits); - glfwWindowHint(GLFW_GREEN_BITS,_contextAttrs.greenBits); - glfwWindowHint(GLFW_BLUE_BITS,_contextAttrs.blueBits); - glfwWindowHint(GLFW_ALPHA_BITS,_contextAttrs.alphaBits); - glfwWindowHint(GLFW_DEPTH_BITS,_contextAttrs.depthBits); - glfwWindowHint(GLFW_STENCIL_BITS,_contextAttrs.stencilBits); + glfwWindowHint(GLFW_RED_BITS,_glContextAttrs.redBits); + glfwWindowHint(GLFW_GREEN_BITS,_glContextAttrs.greenBits); + glfwWindowHint(GLFW_BLUE_BITS,_glContextAttrs.blueBits); + glfwWindowHint(GLFW_ALPHA_BITS,_glContextAttrs.alphaBits); + glfwWindowHint(GLFW_DEPTH_BITS,_glContextAttrs.depthBits); + glfwWindowHint(GLFW_STENCIL_BITS,_glContextAttrs.stencilBits); _mainWindow = glfwCreateWindow(rect.size.width * _frameZoomFactor, rect.size.height * _frameZoomFactor, diff --git a/cocos/platform/ios/CCGLViewImpl.h b/cocos/platform/ios/CCGLViewImpl.h index e3e32c3726..4370151600 100644 --- a/cocos/platform/ios/CCGLViewImpl.h +++ b/cocos/platform/ios/CCGLViewImpl.h @@ -56,8 +56,6 @@ public: static void convertAttrs(); static void* _pixelFormat; static int _depthFormat; - - void setSize(); /** sets the content scale factor */ bool setContentScaleFactor(float contentScaleFactor); diff --git a/cocos/platform/ios/CCGLViewImpl.mm b/cocos/platform/ios/CCGLViewImpl.mm index 376d811e68..2bc9aec8d7 100644 --- a/cocos/platform/ios/CCGLViewImpl.mm +++ b/cocos/platform/ios/CCGLViewImpl.mm @@ -85,11 +85,11 @@ GLViewImpl* GLViewImpl::createWithFullScreen(const std::string& viewName) void GLViewImpl::convertAttrs() { - if(_contextAttrs.redBits==8 && _contextAttrs.greenBits==8 && _contextAttrs.blueBits==8 && _contextAttrs.alphaBits==8) + if(_glContextAttrs.redBits==8 && _glContextAttrs.greenBits==8 && _glContextAttrs.blueBits==8 && _glContextAttrs.alphaBits==8) { _pixelFormat = kEAGLColorFormatRGBA8; } - if(_contextAttrs.depthBits==24 && _contextAttrs.stencilBits==8) + if(_glContextAttrs.depthBits==24 && _glContextAttrs.stencilBits==8) { _depthFormat = GL_DEPTH24_STENCIL8_OES; } @@ -131,8 +131,8 @@ bool GLViewImpl::initWithRect(const std::string& viewName, Rect rect, float fram [eaglview setMultipleTouchEnabled:YES]; - //_screenSize.width = _designResolutionSize.width = [eaglview getWidth]; - //_screenSize.height = _designResolutionSize.height = [eaglview getHeight]; + _screenSize.width = _designResolutionSize.width = [eaglview getWidth]; + _screenSize.height = _designResolutionSize.height = [eaglview getHeight]; // _scaleX = _scaleY = [eaglview contentScaleFactor]; _eaglview = eaglview; @@ -140,13 +140,6 @@ bool GLViewImpl::initWithRect(const std::string& viewName, Rect rect, float fram return true; } -void GLViewImpl::setSize() -{ - CCEAGLView *eaglview = (CCEAGLView*) _eaglview; - _screenSize.width = _designResolutionSize.width = [eaglview getWidth]; - _screenSize.height = _designResolutionSize.height = [eaglview getHeight]; -} - bool GLViewImpl::initWithFullScreen(const std::string& viewName) { CGRect rect = [[UIScreen mainScreen] bounds]; diff --git a/cocos/platform/linux/CCApplication.cpp b/cocos/platform/linux/CCApplication.cpp index d6a0d010e1..c23d0f9883 100644 --- a/cocos/platform/linux/CCApplication.cpp +++ b/cocos/platform/linux/CCApplication.cpp @@ -63,7 +63,7 @@ Application::~Application() int Application::run() { - initContextAttrs(); + initGLContextAttrs(); // Initialize instance and cocos2d. if (! applicationDidFinishLaunching()) { diff --git a/cocos/platform/mac/CCApplication.mm b/cocos/platform/mac/CCApplication.mm index 4f14e09c67..bae4d94522 100644 --- a/cocos/platform/mac/CCApplication.mm +++ b/cocos/platform/mac/CCApplication.mm @@ -64,7 +64,7 @@ Application::~Application() int Application::run() { - initContextAttrs(); + initGLContextAttrs(); if(!applicationDidFinishLaunching()) { return 1; diff --git a/cocos/platform/win32/CCApplication.cpp b/cocos/platform/win32/CCApplication.cpp index 55f0378946..562c7835ed 100644 --- a/cocos/platform/win32/CCApplication.cpp +++ b/cocos/platform/win32/CCApplication.cpp @@ -69,7 +69,7 @@ int Application::run() QueryPerformanceFrequency(&nFreq); QueryPerformanceCounter(&nLast); - initContextAttrs(); + initGLContextAttrs(); // Initialize instance and cocos2d. if (!applicationDidFinishLaunching()) diff --git a/templates/cpp-template-default/proj.ios_mac/ios/AppController.mm b/templates/cpp-template-default/proj.ios_mac/ios/AppController.mm index 897519c84c..9341e9894e 100644 --- a/templates/cpp-template-default/proj.ios_mac/ios/AppController.mm +++ b/templates/cpp-template-default/proj.ios_mac/ios/AppController.mm @@ -38,6 +38,10 @@ static AppDelegate s_sharedApplication; - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { + cocos2d::Application *app = cocos2d::Application::getInstance(); + app->initGLContextAttrs(); + cocos2d::GLViewImpl::convertAttrs(); + // Override point for customization after application launch. // Add the view controller's view to the window and display. @@ -45,12 +49,12 @@ static AppDelegate s_sharedApplication; // Init the CCEAGLView CCEAGLView *eaglView = [CCEAGLView viewWithFrame: [window bounds] - pixelFormat: kEAGLColorFormatRGBA8 - depthFormat: GL_DEPTH24_STENCIL8_OES - preserveBackbuffer: NO - sharegroup: nil - multiSampling: NO - numberOfSamples: 0]; + pixelFormat: (NSString*)cocos2d::GLViewImpl::_pixelFormat + depthFormat: cocos2d::GLViewImpl::_depthFormat + preserveBackbuffer: NO + sharegroup: nil + multiSampling: NO + numberOfSamples: 0 ]; // Use RootViewController manage CCEAGLView _viewController = [[RootViewController alloc] initWithNibName:nil bundle:nil]; @@ -77,7 +81,7 @@ static AppDelegate s_sharedApplication; cocos2d::GLView *glview = cocos2d::GLViewImpl::createWithEAGLView(eaglView); cocos2d::Director::getInstance()->setOpenGLView(glview); - cocos2d::Application::getInstance()->run(); + app->run(); return YES; } diff --git a/templates/cpp-template-default/src/AppDelegate.cpp b/templates/cpp-template-default/src/AppDelegate.cpp index beb7bc9e7a..5171cfd782 100644 --- a/templates/cpp-template-default/src/AppDelegate.cpp +++ b/templates/cpp-template-default/src/AppDelegate.cpp @@ -11,6 +11,17 @@ AppDelegate::~AppDelegate() { } +//if you want a different context,just modify the value of glContextAttrs +//it will takes effect on all platforms +void AppDelegate::initGLContextAttrs() +{ + //set OpenGL context attributions,now can only set six attributions: + //red,green,blue,alpha,depth,stencil + GLContextAttrs glContextAttrs = {8, 8, 8, 8, 24, 8}; + + GLView::setGLContextAttrs(glContextAttrs); +} + bool AppDelegate::applicationDidFinishLaunching() { // initialize director auto director = Director::getInstance(); diff --git a/templates/cpp-template-default/src/AppDelegate.h b/templates/cpp-template-default/src/AppDelegate.h index 18ee8aeb63..625506cc0d 100644 --- a/templates/cpp-template-default/src/AppDelegate.h +++ b/templates/cpp-template-default/src/AppDelegate.h @@ -14,6 +14,8 @@ public: AppDelegate(); virtual ~AppDelegate(); + virtual void initGLContextAttrs(); + /** @brief Implement Director and Scene init code here. @return true Initialize success, app continue. diff --git a/tests/cpp-empty-test/Classes/AppDelegate.cpp b/tests/cpp-empty-test/Classes/AppDelegate.cpp index 1f5b5b799f..b1208d79f5 100644 --- a/tests/cpp-empty-test/Classes/AppDelegate.cpp +++ b/tests/cpp-empty-test/Classes/AppDelegate.cpp @@ -17,11 +17,11 @@ AppDelegate::~AppDelegate() { } -void AppDelegate::initContextAttrs() +void AppDelegate::initGLContextAttrs() { - ContextAttrs contextAttrs = {8, 8, 8, 8, 24, 8}; + GLContextAttrs glContextAttrs = {8, 8, 8, 8, 24, 8}; - GLView::setContextAttrs(contextAttrs); + GLView::setGLContextAttrs(glContextAttrs); } bool AppDelegate::applicationDidFinishLaunching() { diff --git a/tests/cpp-empty-test/Classes/AppDelegate.h b/tests/cpp-empty-test/Classes/AppDelegate.h index 5a7c8e54e3..4d5b8b0d31 100644 --- a/tests/cpp-empty-test/Classes/AppDelegate.h +++ b/tests/cpp-empty-test/Classes/AppDelegate.h @@ -14,7 +14,7 @@ public: AppDelegate(); virtual ~AppDelegate(); - virtual void initContextAttrs(); + virtual void initGLContextAttrs(); /** @brief Implement Director and Scene init code here. diff --git a/tests/cpp-empty-test/proj.ios/AppController.mm b/tests/cpp-empty-test/proj.ios/AppController.mm index d5da4a98be..fb70c76a07 100644 --- a/tests/cpp-empty-test/proj.ios/AppController.mm +++ b/tests/cpp-empty-test/proj.ios/AppController.mm @@ -39,7 +39,7 @@ static AppDelegate s_sharedApplication; - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { cocos2d::Application *app = cocos2d::Application::getInstance(); - app->initContextAttrs(); + app->initGLContextAttrs(); cocos2d::GLViewImpl::convertAttrs(); // Override point for customization after application launch. diff --git a/tests/cpp-tests/Classes/AppDelegate.cpp b/tests/cpp-tests/Classes/AppDelegate.cpp index a6a8cbb8cd..fdfb12d7b8 100644 --- a/tests/cpp-tests/Classes/AppDelegate.cpp +++ b/tests/cpp-tests/Classes/AppDelegate.cpp @@ -43,15 +43,15 @@ AppDelegate::~AppDelegate() cocostudio::ArmatureDataManager::destroyInstance(); } -//if you want a different context,just modify the value of contextAttrs +//if you want a different context,just modify the value of glContextAttrs //it will takes effect on all platforms -void AppDelegate::initContextAttrs() +void AppDelegate::initGLContextAttrs() { - //set OpenGL context attributions + //set OpenGL context attributions,now can only set six attributions: //red,green,blue,alpha,depth,stencil - ContextAttrs contextAttrs = {8, 8, 8, 8, 24, 8}; + GLContextAttrs glContextAttrs = {8, 8, 8, 8, 24, 8}; - GLView::setContextAttrs(contextAttrs); + GLView::setGLContextAttrs(glContextAttrs); } bool AppDelegate::applicationDidFinishLaunching() diff --git a/tests/cpp-tests/Classes/AppDelegate.h b/tests/cpp-tests/Classes/AppDelegate.h index 1594eb8414..7fb3084ad5 100644 --- a/tests/cpp-tests/Classes/AppDelegate.h +++ b/tests/cpp-tests/Classes/AppDelegate.h @@ -39,7 +39,7 @@ public: AppDelegate(); virtual ~AppDelegate(); - virtual void initContextAttrs(); + virtual void initGLContextAttrs(); /** @brief Implement Director and Scene init code here. diff --git a/tests/cpp-tests/proj.android/src/org/cocos2dx/cpp_tests/AppActivity.java b/tests/cpp-tests/proj.android/src/org/cocos2dx/cpp_tests/AppActivity.java index 4934ed0bee..2c1e0e82e7 100644 --- a/tests/cpp-tests/proj.android/src/org/cocos2dx/cpp_tests/AppActivity.java +++ b/tests/cpp-tests/proj.android/src/org/cocos2dx/cpp_tests/AppActivity.java @@ -27,12 +27,4 @@ import org.cocos2dx.lib.Cocos2dxActivity; import org.cocos2dx.lib.Cocos2dxGLSurfaceView; public class AppActivity extends Cocos2dxActivity { - - public Cocos2dxGLSurfaceView onCreateView() { - Cocos2dxGLSurfaceView glSurfaceView = new Cocos2dxGLSurfaceView(this); - // TestCpp should create stencil buffer - glSurfaceView.setEGLConfigChooser(5, 6, 5, 0, 16, 8); - - return glSurfaceView; - } } diff --git a/tests/cpp-tests/proj.ios/Classes/testsAppDelegate.mm b/tests/cpp-tests/proj.ios/Classes/testsAppDelegate.mm index f6b23a9b91..7df7890aa2 100644 --- a/tests/cpp-tests/proj.ios/Classes/testsAppDelegate.mm +++ b/tests/cpp-tests/proj.ios/Classes/testsAppDelegate.mm @@ -42,7 +42,7 @@ static AppDelegate s_sharedApplication; { cocos2d::Application *app = cocos2d::Application::getInstance(); - app->initContextAttrs(); + app->initGLContextAttrs(); cocos2d::GLViewImpl::convertAttrs(); // Override point for customization after application launch. diff --git a/tests/lua-empty-test/project/Classes/AppDelegate.cpp b/tests/lua-empty-test/project/Classes/AppDelegate.cpp index 55cf4845a1..8d0ac6aeb4 100644 --- a/tests/lua-empty-test/project/Classes/AppDelegate.cpp +++ b/tests/lua-empty-test/project/Classes/AppDelegate.cpp @@ -21,11 +21,11 @@ AppDelegate::~AppDelegate() //CCScriptEngineManager::destroyInstance(); } -void AppDelegate::initContextAttrs() +void AppDelegate::initGLContextAttrs() { - ContextAttrs contextAttrs = {8, 8, 8, 8, 24, 8}; + GLContextAttrs glContextAttrs = {8, 8, 8, 8, 24, 8}; - GLView::setContextAttrs(contextAttrs); + GLView::setGLContextAttrs(glContextAttrs); } bool AppDelegate::applicationDidFinishLaunching() diff --git a/tests/lua-empty-test/project/Classes/AppDelegate.h b/tests/lua-empty-test/project/Classes/AppDelegate.h index 568bfb7cc3..41d0b2ca88 100644 --- a/tests/lua-empty-test/project/Classes/AppDelegate.h +++ b/tests/lua-empty-test/project/Classes/AppDelegate.h @@ -14,7 +14,7 @@ public: AppDelegate(); virtual ~AppDelegate(); - virtual void initContextAttrs(); + virtual void initGLContextAttrs(); /** @brief Implement Director and Scene init code here. @return true Initialize success, app continue. diff --git a/tests/lua-empty-test/project/proj.ios/AppController.mm b/tests/lua-empty-test/project/proj.ios/AppController.mm index a4a76d5cc1..7cfd72062b 100644 --- a/tests/lua-empty-test/project/proj.ios/AppController.mm +++ b/tests/lua-empty-test/project/proj.ios/AppController.mm @@ -38,14 +38,17 @@ static AppDelegate s_sharedApplication; - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { - + + cocos2d::Application *app = cocos2d::Application::getInstance(); + app->initGLContextAttrs(); + cocos2d::GLViewImpl::convertAttrs(); // Override point for customization after application launch. // Add the view controller's view to the window and display. window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]]; CCEAGLView *eaglView = [CCEAGLView viewWithFrame: [window bounds] - pixelFormat: kEAGLColorFormatRGBA8 - depthFormat: GL_DEPTH_COMPONENT16 + pixelFormat: (NSString*)cocos2d::GLViewImpl::_pixelFormat + depthFormat: cocos2d::GLViewImpl::_depthFormat preserveBackbuffer: NO sharegroup: nil multiSampling: NO @@ -76,7 +79,6 @@ static AppDelegate s_sharedApplication; cocos2d::GLView *glview = cocos2d::GLViewImpl::createWithEAGLView(eaglView); cocos2d::Director::getInstance()->setOpenGLView(glview); - cocos2d::Application *app = cocos2d::Application::getInstance(); app->run(); return YES; } diff --git a/tests/lua-tests/project/Classes/AppDelegate.cpp b/tests/lua-tests/project/Classes/AppDelegate.cpp index 006dd687a1..a9185b6afe 100644 --- a/tests/lua-tests/project/Classes/AppDelegate.cpp +++ b/tests/lua-tests/project/Classes/AppDelegate.cpp @@ -18,11 +18,11 @@ AppDelegate::~AppDelegate() SimpleAudioEngine::end(); } -void AppDelegate::initContextAttrs() +void AppDelegate::initGLContextAttrs() { - ContextAttrs contextAttrs = {8, 8, 8, 8, 24, 8}; + GLContextAttrs glContextAttrs = {8, 8, 8, 8, 24, 8}; - GLView::setContextAttrs(contextAttrs); + GLView::setGLContextAttrs(glContextAttrs); } bool AppDelegate::applicationDidFinishLaunching() diff --git a/tests/lua-tests/project/Classes/AppDelegate.h b/tests/lua-tests/project/Classes/AppDelegate.h index 90979dea7a..f8fbbdbb39 100644 --- a/tests/lua-tests/project/Classes/AppDelegate.h +++ b/tests/lua-tests/project/Classes/AppDelegate.h @@ -14,7 +14,7 @@ public: AppDelegate(); virtual ~AppDelegate(); - void initContextAttrs(); + void initGLContextAttrs(); /** @brief Implement Director and Scene init code here. @return true Initialize success, app continue. diff --git a/tests/lua-tests/project/proj.ios_mac/ios/AppController.mm b/tests/lua-tests/project/proj.ios_mac/ios/AppController.mm index 3305eb9259..12f7bd601f 100644 --- a/tests/lua-tests/project/proj.ios_mac/ios/AppController.mm +++ b/tests/lua-tests/project/proj.ios_mac/ios/AppController.mm @@ -39,13 +39,16 @@ static AppDelegate s_sharedApplication; - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { + cocos2d::Application *app = cocos2d::Application::getInstance(); + app->initGLContextAttrs(); + cocos2d::GLViewImpl::convertAttrs(); // Override point for customization after application launch. // Add the view controller's view to the window and display. window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]]; CCEAGLView *eaglView = [CCEAGLView viewWithFrame: [window bounds] - pixelFormat: kEAGLColorFormatRGBA8 - depthFormat: GL_DEPTH24_STENCIL8_OES + pixelFormat: (NSString*)cocos2d::GLViewImpl::_pixelFormat + depthFormat: cocos2d::GLViewImpl::_depthFormat preserveBackbuffer: NO sharegroup: nil multiSampling: NO @@ -79,7 +82,7 @@ static AppDelegate s_sharedApplication; cocos2d::GLView *glview = cocos2d::GLViewImpl::createWithEAGLView(eaglView); cocos2d::Director::getInstance()->setOpenGLView(glview); - cocos2d::Application::getInstance()->run(); + app->run(); return YES; }