我将我的游戏移植到android,并决定使用NativeActivity而不是Java活动和JNI调用(我不避开JNI,只是设置回调会更方便并且opengl上下文创建/破坏纯粹在c/C++中)。保留通过本地代码创建的egl上下文
我知道GLSurfaceView有一个setPreserveEGLContextOnPause函数,但这是Java中的,而不是本机应用程序。创建我用下面的代码方面:
EGLConfig config;
EGLSurface surface;
EGLContext context;
EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
eglInitialize(display, 0, 0);
eglChooseConfig(display, attribs, &config, 1, &numConfigs);
eglGetConfigAttrib(display, config, EGL_NATIVE_VISUAL_ID, &format);
ANativeWindow_setBuffersGeometry(engine->app->window, 0, 0, format);
surface = eglCreateWindowSurface(display, config, engine->app->window, NULL);
const EGLint contextAttribs[] = {
EGL_CONTEXT_CLIENT_VERSION, 2,
EGL_NONE
};
context = eglCreateContext(display, config, NULL, contextAttribs);
if (eglMakeCurrent(display, surface, surface, context) == EGL_FALSE) {
ERR("Unable to eglMakeCurrent");
return -1;
}
我也知道,setPreserveEGLContextOnPause是不是100%可靠的,我应该检查一下东西是手动销毁,但如果它不是 - 我想跳过资产重装部分为了更快的加载。
基本上我想要做的就是使用setPreserveEGLContextOnPause(或者它相当于ndk世界)。可能吗? GLSurfaceView是在android的egl调用的窗帘后面实例化的吗?
感谢您解决问题!我将手动管理我的上下文,然后根据设备功能销毁或保留它。 – 2014-09-19 18:10:36