OpenGL context attributions setting revise -2

This commit is contained in:
huangshiwu 2014-08-22 16:22:16 +08:00
parent 7f57d15cb3
commit 07af58c0c2
29 changed files with 111 additions and 99 deletions

View File

@ -102,8 +102,14 @@ public:
*/ */
virtual void setAnimationInterval(double interval) = 0; virtual void setAnimationInterval(double interval) = 0;
//initialize the OpenGL/OpenGL ES context attribution here for all platforms; //subclass override the function to set OpenGL context attribution instead of use default value
virtual void initContextAttrs() {} //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 @brief Get current language config

View File

@ -71,11 +71,16 @@ namespace {
} }
//default context attributions are setted as follows //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() GLView::GLView()

View File

@ -64,7 +64,7 @@ enum class ResolutionPolicy
UNKNOWN, UNKNOWN,
}; };
struct ContextAttrs struct GLContextAttrs
{ {
int redBits; int redBits;
int greenBits; int greenBits;
@ -109,8 +109,9 @@ public:
virtual bool windowShouldClose() { return false; }; virtual bool windowShouldClose() { return false; };
//static method and member so that we can modify it on all platforms before create OpenGL context //static method and member so that we can modify it on all platforms before create OpenGL context
static void setContextAttrs(ContextAttrs& contextAttrs); static void setGLContextAttrs(GLContextAttrs& glContextAttrs);
static ContextAttrs _contextAttrs; static GLContextAttrs getGLContextAttrs();
static GLContextAttrs _glContextAttrs;
/** /**
* Polls input events. Subclass must implement methods if platform * Polls input events. Subclass must implement methods if platform

View File

@ -73,11 +73,6 @@ GLViewImpl* GLViewImpl::create(const std::string& viewName)
return nullptr; return nullptr;
} }
ContextAttrs GLViewImpl::getContextAttrs()
{
return _contextAttrs;
}
GLViewImpl* GLViewImpl::createWithFullScreen(const std::string& viewName) GLViewImpl* GLViewImpl::createWithFullScreen(const std::string& viewName)
{ {
auto ret = new GLViewImpl(); auto ret = new GLViewImpl();

View File

@ -44,10 +44,6 @@ public:
static GLViewImpl* createWithRect(const std::string& viewName, Rect rect, float frameZoomFactor = 1.0f); static GLViewImpl* createWithRect(const std::string& viewName, Rect rect, float frameZoomFactor = 1.0f);
static GLViewImpl* createWithFullScreen(const std::string& viewName); 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; bool isOpenGLReady() override;
void end() override; void end() override;
void swapBuffers() override; void swapBuffers() override;

View File

@ -51,6 +51,7 @@ public abstract class Cocos2dxActivity extends Activity implements Cocos2dxHelpe
// =========================================================== // ===========================================================
private Cocos2dxGLSurfaceView mGLSurfaceView; private Cocos2dxGLSurfaceView mGLSurfaceView;
private int[] glContextAttrs;
private Cocos2dxHandler mHandler; private Cocos2dxHandler mHandler;
private static Cocos2dxActivity sContext = null; private static Cocos2dxActivity sContext = null;
private Cocos2dxVideoHelper mVideoHelper = null; private Cocos2dxVideoHelper mVideoHelper = null;
@ -95,16 +96,16 @@ public abstract class Cocos2dxActivity extends Activity implements Cocos2dxHelpe
Cocos2dxHelper.init(this); Cocos2dxHelper.init(this);
int[] OGLCtxattrs = getContextAttrs(); this.glContextAttrs = getGLContextAttrs();
this.initWithOGLCtxattrs(OGLCtxattrs); this.init();
if (mVideoHelper == null) { if (mVideoHelper == null) {
mVideoHelper = new Cocos2dxVideoHelper(this, mFrameLayout); mVideoHelper = new Cocos2dxVideoHelper(this, mFrameLayout);
} }
} }
//native method,call GLViewImpl::getContextAttrs() to get the OpenGL ES context attributions //native method,call GLViewImpl::getGLContextAttrs() to get the OpenGL ES context attributions
private static native int[] getContextAttrs(); private static native int[] getGLContextAttrs();
// =========================================================== // ===========================================================
// Getter & Setter // Getter & Setter
@ -171,7 +172,7 @@ public abstract class Cocos2dxActivity extends Activity implements Cocos2dxHelpe
// =========================================================== // ===========================================================
// Methods // Methods
// =========================================================== // ===========================================================
public void initWithOGLCtxattrs(int[] OGLCtxattrs) { public void init() {
// FrameLayout // FrameLayout
ViewGroup.LayoutParams framelayout_params = ViewGroup.LayoutParams framelayout_params =
@ -191,16 +192,14 @@ public abstract class Cocos2dxActivity extends Activity implements Cocos2dxHelpe
mFrameLayout.addView(edittext); mFrameLayout.addView(edittext);
// Cocos2dxGLSurfaceView // Cocos2dxGLSurfaceView
this.mGLSurfaceView = new Cocos2dxGLSurfaceView(this); this.mGLSurfaceView = this.onCreateView();
this.mGLSurfaceView.setEGLConfigChooser(OGLCtxattrs[0], OGLCtxattrs[1],OGLCtxattrs[2],OGLCtxattrs[3],OGLCtxattrs[4],OGLCtxattrs[5]);
// ...add to FrameLayout // ...add to FrameLayout
mFrameLayout.addView(this.mGLSurfaceView); mFrameLayout.addView(this.mGLSurfaceView);
// Switch to supported OpenGL (ARGB888) mode on emulator // Switch to supported OpenGL (ARGB888) mode on emulator
if (isAndroidEmulator()) 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.setCocos2dxRenderer(new Cocos2dxRenderer());
this.mGLSurfaceView.setCocos2dxEditText(edittext); this.mGLSurfaceView.setCocos2dxEditText(edittext);
@ -210,7 +209,12 @@ public abstract class Cocos2dxActivity extends Activity implements Cocos2dxHelpe
} }
public Cocos2dxGLSurfaceView onCreateView() { 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() { private final static boolean isAndroidEmulator() {

View File

@ -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); cocos_android_app_init(env, thiz);
cocos2d::Application::getInstance()->initContextAttrs(); cocos2d::Application::getInstance()->initGLContextAttrs();
ContextAttrs _contextAttrs = GLViewImpl::getContextAttrs(); GLContextAttrs _glContextAttrs = GLView::getGLContextAttrs();
int tmp[6] = {_contextAttrs.redBits, _contextAttrs.greenBits, _contextAttrs.blueBits, int tmp[6] = {_glContextAttrs.redBits, _glContextAttrs.greenBits, _glContextAttrs.blueBits,
_contextAttrs.alphaBits, _contextAttrs.depthBits, _contextAttrs.stencilBits}; _glContextAttrs.alphaBits, _glContextAttrs.depthBits, _glContextAttrs.stencilBits};
jintArray contextAttrsJava = env->NewIntArray(6); jintArray glContextAttrsJava = env->NewIntArray(6);
env->SetIntArrayRegion(contextAttrsJava, 0, 6, tmp); 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) void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeOnSurfaceChanged(JNIEnv* env, jobject thiz, jint w, jint h)

View File

@ -344,12 +344,12 @@ bool GLViewImpl::initWithRect(const std::string& viewName, Rect rect, float fram
_frameZoomFactor = frameZoomFactor; _frameZoomFactor = frameZoomFactor;
glfwWindowHint(GLFW_RESIZABLE,GL_FALSE); glfwWindowHint(GLFW_RESIZABLE,GL_FALSE);
glfwWindowHint(GLFW_RED_BITS,_contextAttrs.redBits); glfwWindowHint(GLFW_RED_BITS,_glContextAttrs.redBits);
glfwWindowHint(GLFW_GREEN_BITS,_contextAttrs.greenBits); glfwWindowHint(GLFW_GREEN_BITS,_glContextAttrs.greenBits);
glfwWindowHint(GLFW_BLUE_BITS,_contextAttrs.blueBits); glfwWindowHint(GLFW_BLUE_BITS,_glContextAttrs.blueBits);
glfwWindowHint(GLFW_ALPHA_BITS,_contextAttrs.alphaBits); glfwWindowHint(GLFW_ALPHA_BITS,_glContextAttrs.alphaBits);
glfwWindowHint(GLFW_DEPTH_BITS,_contextAttrs.depthBits); glfwWindowHint(GLFW_DEPTH_BITS,_glContextAttrs.depthBits);
glfwWindowHint(GLFW_STENCIL_BITS,_contextAttrs.stencilBits); glfwWindowHint(GLFW_STENCIL_BITS,_glContextAttrs.stencilBits);
_mainWindow = glfwCreateWindow(rect.size.width * _frameZoomFactor, _mainWindow = glfwCreateWindow(rect.size.width * _frameZoomFactor,
rect.size.height * _frameZoomFactor, rect.size.height * _frameZoomFactor,

View File

@ -56,8 +56,6 @@ public:
static void convertAttrs(); static void convertAttrs();
static void* _pixelFormat; static void* _pixelFormat;
static int _depthFormat; static int _depthFormat;
void setSize();
/** sets the content scale factor */ /** sets the content scale factor */
bool setContentScaleFactor(float contentScaleFactor); bool setContentScaleFactor(float contentScaleFactor);

View File

@ -85,11 +85,11 @@ GLViewImpl* GLViewImpl::createWithFullScreen(const std::string& viewName)
void GLViewImpl::convertAttrs() 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; _pixelFormat = kEAGLColorFormatRGBA8;
} }
if(_contextAttrs.depthBits==24 && _contextAttrs.stencilBits==8) if(_glContextAttrs.depthBits==24 && _glContextAttrs.stencilBits==8)
{ {
_depthFormat = GL_DEPTH24_STENCIL8_OES; _depthFormat = GL_DEPTH24_STENCIL8_OES;
} }
@ -131,8 +131,8 @@ bool GLViewImpl::initWithRect(const std::string& viewName, Rect rect, float fram
[eaglview setMultipleTouchEnabled:YES]; [eaglview setMultipleTouchEnabled:YES];
//_screenSize.width = _designResolutionSize.width = [eaglview getWidth]; _screenSize.width = _designResolutionSize.width = [eaglview getWidth];
//_screenSize.height = _designResolutionSize.height = [eaglview getHeight]; _screenSize.height = _designResolutionSize.height = [eaglview getHeight];
// _scaleX = _scaleY = [eaglview contentScaleFactor]; // _scaleX = _scaleY = [eaglview contentScaleFactor];
_eaglview = eaglview; _eaglview = eaglview;
@ -140,13 +140,6 @@ bool GLViewImpl::initWithRect(const std::string& viewName, Rect rect, float fram
return true; 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) bool GLViewImpl::initWithFullScreen(const std::string& viewName)
{ {
CGRect rect = [[UIScreen mainScreen] bounds]; CGRect rect = [[UIScreen mainScreen] bounds];

View File

@ -63,7 +63,7 @@ Application::~Application()
int Application::run() int Application::run()
{ {
initContextAttrs(); initGLContextAttrs();
// Initialize instance and cocos2d. // Initialize instance and cocos2d.
if (! applicationDidFinishLaunching()) if (! applicationDidFinishLaunching())
{ {

View File

@ -64,7 +64,7 @@ Application::~Application()
int Application::run() int Application::run()
{ {
initContextAttrs(); initGLContextAttrs();
if(!applicationDidFinishLaunching()) if(!applicationDidFinishLaunching())
{ {
return 1; return 1;

View File

@ -69,7 +69,7 @@ int Application::run()
QueryPerformanceFrequency(&nFreq); QueryPerformanceFrequency(&nFreq);
QueryPerformanceCounter(&nLast); QueryPerformanceCounter(&nLast);
initContextAttrs(); initGLContextAttrs();
// Initialize instance and cocos2d. // Initialize instance and cocos2d.
if (!applicationDidFinishLaunching()) if (!applicationDidFinishLaunching())

View File

@ -38,6 +38,10 @@ static AppDelegate s_sharedApplication;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { - (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. // Override point for customization after application launch.
// Add the view controller's view to the window and display. // Add the view controller's view to the window and display.
@ -45,12 +49,12 @@ static AppDelegate s_sharedApplication;
// Init the CCEAGLView // Init the CCEAGLView
CCEAGLView *eaglView = [CCEAGLView viewWithFrame: [window bounds] CCEAGLView *eaglView = [CCEAGLView viewWithFrame: [window bounds]
pixelFormat: kEAGLColorFormatRGBA8 pixelFormat: (NSString*)cocos2d::GLViewImpl::_pixelFormat
depthFormat: GL_DEPTH24_STENCIL8_OES depthFormat: cocos2d::GLViewImpl::_depthFormat
preserveBackbuffer: NO preserveBackbuffer: NO
sharegroup: nil sharegroup: nil
multiSampling: NO multiSampling: NO
numberOfSamples: 0]; numberOfSamples: 0 ];
// Use RootViewController manage CCEAGLView // Use RootViewController manage CCEAGLView
_viewController = [[RootViewController alloc] initWithNibName:nil bundle:nil]; _viewController = [[RootViewController alloc] initWithNibName:nil bundle:nil];
@ -77,7 +81,7 @@ static AppDelegate s_sharedApplication;
cocos2d::GLView *glview = cocos2d::GLViewImpl::createWithEAGLView(eaglView); cocos2d::GLView *glview = cocos2d::GLViewImpl::createWithEAGLView(eaglView);
cocos2d::Director::getInstance()->setOpenGLView(glview); cocos2d::Director::getInstance()->setOpenGLView(glview);
cocos2d::Application::getInstance()->run(); app->run();
return YES; return YES;
} }

View File

@ -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() { bool AppDelegate::applicationDidFinishLaunching() {
// initialize director // initialize director
auto director = Director::getInstance(); auto director = Director::getInstance();

View File

@ -14,6 +14,8 @@ public:
AppDelegate(); AppDelegate();
virtual ~AppDelegate(); virtual ~AppDelegate();
virtual void initGLContextAttrs();
/** /**
@brief Implement Director and Scene init code here. @brief Implement Director and Scene init code here.
@return true Initialize success, app continue. @return true Initialize success, app continue.

View File

@ -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() { bool AppDelegate::applicationDidFinishLaunching() {

View File

@ -14,7 +14,7 @@ public:
AppDelegate(); AppDelegate();
virtual ~AppDelegate(); virtual ~AppDelegate();
virtual void initContextAttrs(); virtual void initGLContextAttrs();
/** /**
@brief Implement Director and Scene init code here. @brief Implement Director and Scene init code here.

View File

@ -39,7 +39,7 @@ static AppDelegate s_sharedApplication;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
cocos2d::Application *app = cocos2d::Application::getInstance(); cocos2d::Application *app = cocos2d::Application::getInstance();
app->initContextAttrs(); app->initGLContextAttrs();
cocos2d::GLViewImpl::convertAttrs(); cocos2d::GLViewImpl::convertAttrs();
// Override point for customization after application launch. // Override point for customization after application launch.

View File

@ -43,15 +43,15 @@ AppDelegate::~AppDelegate()
cocostudio::ArmatureDataManager::destroyInstance(); 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 //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 //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() bool AppDelegate::applicationDidFinishLaunching()

View File

@ -39,7 +39,7 @@ public:
AppDelegate(); AppDelegate();
virtual ~AppDelegate(); virtual ~AppDelegate();
virtual void initContextAttrs(); virtual void initGLContextAttrs();
/** /**
@brief Implement Director and Scene init code here. @brief Implement Director and Scene init code here.

View File

@ -27,12 +27,4 @@ import org.cocos2dx.lib.Cocos2dxActivity;
import org.cocos2dx.lib.Cocos2dxGLSurfaceView; import org.cocos2dx.lib.Cocos2dxGLSurfaceView;
public class AppActivity extends Cocos2dxActivity { 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;
}
} }

View File

@ -42,7 +42,7 @@ static AppDelegate s_sharedApplication;
{ {
cocos2d::Application *app = cocos2d::Application::getInstance(); cocos2d::Application *app = cocos2d::Application::getInstance();
app->initContextAttrs(); app->initGLContextAttrs();
cocos2d::GLViewImpl::convertAttrs(); cocos2d::GLViewImpl::convertAttrs();
// Override point for customization after application launch. // Override point for customization after application launch.

View File

@ -21,11 +21,11 @@ AppDelegate::~AppDelegate()
//CCScriptEngineManager::destroyInstance(); //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() bool AppDelegate::applicationDidFinishLaunching()

View File

@ -14,7 +14,7 @@ public:
AppDelegate(); AppDelegate();
virtual ~AppDelegate(); virtual ~AppDelegate();
virtual void initContextAttrs(); virtual void initGLContextAttrs();
/** /**
@brief Implement Director and Scene init code here. @brief Implement Director and Scene init code here.
@return true Initialize success, app continue. @return true Initialize success, app continue.

View File

@ -38,14 +38,17 @@
static AppDelegate s_sharedApplication; static AppDelegate s_sharedApplication;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { - (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. // Override point for customization after application launch.
// Add the view controller's view to the window and display. // Add the view controller's view to the window and display.
window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]]; window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]];
CCEAGLView *eaglView = [CCEAGLView viewWithFrame: [window bounds] CCEAGLView *eaglView = [CCEAGLView viewWithFrame: [window bounds]
pixelFormat: kEAGLColorFormatRGBA8 pixelFormat: (NSString*)cocos2d::GLViewImpl::_pixelFormat
depthFormat: GL_DEPTH_COMPONENT16 depthFormat: cocos2d::GLViewImpl::_depthFormat
preserveBackbuffer: NO preserveBackbuffer: NO
sharegroup: nil sharegroup: nil
multiSampling: NO multiSampling: NO
@ -76,7 +79,6 @@ static AppDelegate s_sharedApplication;
cocos2d::GLView *glview = cocos2d::GLViewImpl::createWithEAGLView(eaglView); cocos2d::GLView *glview = cocos2d::GLViewImpl::createWithEAGLView(eaglView);
cocos2d::Director::getInstance()->setOpenGLView(glview); cocos2d::Director::getInstance()->setOpenGLView(glview);
cocos2d::Application *app = cocos2d::Application::getInstance();
app->run(); app->run();
return YES; return YES;
} }

View File

@ -18,11 +18,11 @@ AppDelegate::~AppDelegate()
SimpleAudioEngine::end(); 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() bool AppDelegate::applicationDidFinishLaunching()

View File

@ -14,7 +14,7 @@ public:
AppDelegate(); AppDelegate();
virtual ~AppDelegate(); virtual ~AppDelegate();
void initContextAttrs(); void initGLContextAttrs();
/** /**
@brief Implement Director and Scene init code here. @brief Implement Director and Scene init code here.
@return true Initialize success, app continue. @return true Initialize success, app continue.

View File

@ -39,13 +39,16 @@ static AppDelegate s_sharedApplication;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { - (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. // Override point for customization after application launch.
// Add the view controller's view to the window and display. // Add the view controller's view to the window and display.
window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]]; window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]];
CCEAGLView *eaglView = [CCEAGLView viewWithFrame: [window bounds] CCEAGLView *eaglView = [CCEAGLView viewWithFrame: [window bounds]
pixelFormat: kEAGLColorFormatRGBA8 pixelFormat: (NSString*)cocos2d::GLViewImpl::_pixelFormat
depthFormat: GL_DEPTH24_STENCIL8_OES depthFormat: cocos2d::GLViewImpl::_depthFormat
preserveBackbuffer: NO preserveBackbuffer: NO
sharegroup: nil sharegroup: nil
multiSampling: NO multiSampling: NO
@ -79,7 +82,7 @@ static AppDelegate s_sharedApplication;
cocos2d::GLView *glview = cocos2d::GLViewImpl::createWithEAGLView(eaglView); cocos2d::GLView *glview = cocos2d::GLViewImpl::createWithEAGLView(eaglView);
cocos2d::Director::getInstance()->setOpenGLView(glview); cocos2d::Director::getInstance()->setOpenGLView(glview);
cocos2d::Application::getInstance()->run(); app->run();
return YES; return YES;
} }