Ray McCooney
- Forum-Beiträge: 1
20.04.2012, 16:34:04 via Website
20.04.2012 16:34:04 via Website
Hallo Community,
Ich habe eine Frage zu eglSwapBuffers().
Und zwar habe ich ein native-activity in C/C++ und rendere dort eine Szene mit OpenGL. Dies funktioniert fast alles wunderbar. Jedoch habe ich bemerkt, dass in der Funktion eglSwapBuffers(), welche verantwortlich dafür ist, die beiden Framebuffer zu vertauschen, etwa 28-33 Millisekunden vergehen. Mein erster Gedanke war: Klar, der braucht so lange um sich mit dem Display zu synchronisieren. Jedoch wären das bei 60fps etwa maximal 16.6ms.
Ich habe in einem anderen Forum gelesen, dass die gesamten GL-Befehle, die ich pro Frame aufrufe, nur "gesammelt" werden und erst beim eglSwapBuffers() ausgeführt werden. Könnte es damit zu tun haben? Kann ich das ändern? Die Zeit, welche die vorgängigen GL-Befehlen brauchen (Also die Szene rendern), liegt bei etwa 2 Millisekunden höchstens. Es kann doch nicht sein dass ich im eglSwapBuffers() 30 Millisekunden verbrate?
Man könnte jetzt denken: Tja, meine Szene ist einfach zu komplex und zu aufwändig. Jedoch rendert der genau gleiche Code in einem Java (Non-Native) onDrawFrame() flüssig!!!! Es muss also irgendwo in meinem native-activity ein Problem sein. Muss ich evtl. eglSwapBuffers() asynchron aufrufen? Oder muss ich sonst etwas beachten?
Ich habe mich beim Entwickeln des native-activities an das Sample von Google gehalten: http://developer.android.com/reference/android/app/NativeActivity.html
Ich habe bereits versucht, die egl-config zu optimieren, jedoch ohne Erfolg. Meine jetztige egl-config sieht so aus:
Das Device ist ein Samsung Galaxy Tab 10.1 und ich rendere mit OpenGL E.S. 2.0
Mein OpenGL-Init Code sieht so aus:
Hat irgend jemand eine Ahnung?
Ich habe eine Frage zu eglSwapBuffers().
Und zwar habe ich ein native-activity in C/C++ und rendere dort eine Szene mit OpenGL. Dies funktioniert fast alles wunderbar. Jedoch habe ich bemerkt, dass in der Funktion eglSwapBuffers(), welche verantwortlich dafür ist, die beiden Framebuffer zu vertauschen, etwa 28-33 Millisekunden vergehen. Mein erster Gedanke war: Klar, der braucht so lange um sich mit dem Display zu synchronisieren. Jedoch wären das bei 60fps etwa maximal 16.6ms.
Ich habe in einem anderen Forum gelesen, dass die gesamten GL-Befehle, die ich pro Frame aufrufe, nur "gesammelt" werden und erst beim eglSwapBuffers() ausgeführt werden. Könnte es damit zu tun haben? Kann ich das ändern? Die Zeit, welche die vorgängigen GL-Befehlen brauchen (Also die Szene rendern), liegt bei etwa 2 Millisekunden höchstens. Es kann doch nicht sein dass ich im eglSwapBuffers() 30 Millisekunden verbrate?
Man könnte jetzt denken: Tja, meine Szene ist einfach zu komplex und zu aufwändig. Jedoch rendert der genau gleiche Code in einem Java (Non-Native) onDrawFrame() flüssig!!!! Es muss also irgendwo in meinem native-activity ein Problem sein. Muss ich evtl. eglSwapBuffers() asynchron aufrufen? Oder muss ich sonst etwas beachten?
Ich habe mich beim Entwickeln des native-activities an das Sample von Google gehalten: http://developer.android.com/reference/android/app/NativeActivity.html
Ich habe bereits versucht, die egl-config zu optimieren, jedoch ohne Erfolg. Meine jetztige egl-config sieht so aus:
1const EGLint attribs[] = {
2 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
3 EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
4 EGL_ALPHA_SIZE, 0,
5 EGL_BLUE_SIZE, 5,
6 EGL_GREEN_SIZE, 6,
7 EGL_RED_SIZE, 5,
8 EGL_DEPTH_SIZE, 16,
9 EGL_NONE};
2 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
3 EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
4 EGL_ALPHA_SIZE, 0,
5 EGL_BLUE_SIZE, 5,
6 EGL_GREEN_SIZE, 6,
7 EGL_RED_SIZE, 5,
8 EGL_DEPTH_SIZE, 16,
9 EGL_NONE};
Das Device ist ein Samsung Galaxy Tab 10.1 und ich rendere mit OpenGL E.S. 2.0
Mein OpenGL-Init Code sieht so aus:
1bool RenderManager::initEGLWindow() {
2 // initialize OpenGL ES and EGL
3
4 /*
5 * Here specify the attributes of the desired configuration.
6 * Below, we select an EGLConfig with at least 8 bits per color
7 * component compatible with on-screen windows
8 */
9 const EGLint attribs[] = {
10 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
11 EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
12 EGL_ALPHA_SIZE, 0,
13 EGL_BLUE_SIZE, 5,
14 EGL_GREEN_SIZE, 6,
15 EGL_RED_SIZE, 5,
16 EGL_DEPTH_SIZE, 16,
17 EGL_NONE};
18 EGLint w, h, format;
19 EGLint numConfigs;
20 EGLConfig config;
21 EGLSurface surface;
22 EGLContext context;
23
24 EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
25
26 eglInitialize(display, 0, 0);
27
28 eglChooseConfig(display, attribs, &config, 1, &numConfigs);
29
30 eglGetConfigAttrib(display, config, EGL_NATIVE_VISUAL_ID, &format);
31
32 ANativeWindow_setBuffersGeometry(app->window, 0, 0, format);
33
34 static const EGLint contextAttribs[] = {
35 EGL_CONTEXT_CLIENT_VERSION, 2,
36 EGL_NONE
37 };
38
39 surface = eglCreateWindowSurface(display, config, app->window, NULL);
40 context = eglCreateContext(display, config, EGL_NO_CONTEXT, contextAttribs);
41
42 if (eglMakeCurrent(display, surface, surface, context) == EGL_FALSE) {
43 LOGE("Unable to eglMakeCurrent\n");
44 return false;
45 }
46
47 eglQuerySurface(display, surface, EGL_WIDTH, &w);
48 eglQuerySurface(display, surface, EGL_HEIGHT, &h);
49
50 mDisplay = display;
51 mContext = context;
52 mSurface = surface;
53 mScreenWidth = w;
54 mScreenHeight = h;
55
56 // setup the openGL settings
57 setupOGLEnvironment();
58
59 return true;
60}
61
62void RenderManager::setupOGLEnvironment() {
63 // setup default viewport
64 glViewport(0, 0, mScreenWidth, mScreenHeight);
65
66 // setup perspective projection matrix
67 glhPerspectivef2(mPerspectiveMatrix, mFOV, (float)mScreenWidth / (float)mScreenHeight, mZnear, mZfar);
68
69 // setup ortho projection matrix
70 glhOrthof2(mOrthoMatrix, -mScreenWidth/2.0f, mScreenWidth/2.0f, -mScreenHeight/2.0f, mScreenHeight/2.0f, -1.0f, 1.0f);
71
72 glClearColor(0.7f, 0.9f, 1.0f, 1.0f);
73 glClearDepthf(1.0f);
74
75 // depth test is less-equal
76 glEnable(GL_DEPTH_TEST);
77 glDepthFunc(GL_LEQUAL);
78
79 // cull-face is the back face
80 glEnable(GL_CULL_FACE);
81 glCullFace(GL_BACK);
82
83 // one minus alpha blend testing
84 glEnable(GL_BLEND);
85 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
86}
2 // initialize OpenGL ES and EGL
3
4 /*
5 * Here specify the attributes of the desired configuration.
6 * Below, we select an EGLConfig with at least 8 bits per color
7 * component compatible with on-screen windows
8 */
9 const EGLint attribs[] = {
10 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
11 EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
12 EGL_ALPHA_SIZE, 0,
13 EGL_BLUE_SIZE, 5,
14 EGL_GREEN_SIZE, 6,
15 EGL_RED_SIZE, 5,
16 EGL_DEPTH_SIZE, 16,
17 EGL_NONE};
18 EGLint w, h, format;
19 EGLint numConfigs;
20 EGLConfig config;
21 EGLSurface surface;
22 EGLContext context;
23
24 EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
25
26 eglInitialize(display, 0, 0);
27
28 eglChooseConfig(display, attribs, &config, 1, &numConfigs);
29
30 eglGetConfigAttrib(display, config, EGL_NATIVE_VISUAL_ID, &format);
31
32 ANativeWindow_setBuffersGeometry(app->window, 0, 0, format);
33
34 static const EGLint contextAttribs[] = {
35 EGL_CONTEXT_CLIENT_VERSION, 2,
36 EGL_NONE
37 };
38
39 surface = eglCreateWindowSurface(display, config, app->window, NULL);
40 context = eglCreateContext(display, config, EGL_NO_CONTEXT, contextAttribs);
41
42 if (eglMakeCurrent(display, surface, surface, context) == EGL_FALSE) {
43 LOGE("Unable to eglMakeCurrent\n");
44 return false;
45 }
46
47 eglQuerySurface(display, surface, EGL_WIDTH, &w);
48 eglQuerySurface(display, surface, EGL_HEIGHT, &h);
49
50 mDisplay = display;
51 mContext = context;
52 mSurface = surface;
53 mScreenWidth = w;
54 mScreenHeight = h;
55
56 // setup the openGL settings
57 setupOGLEnvironment();
58
59 return true;
60}
61
62void RenderManager::setupOGLEnvironment() {
63 // setup default viewport
64 glViewport(0, 0, mScreenWidth, mScreenHeight);
65
66 // setup perspective projection matrix
67 glhPerspectivef2(mPerspectiveMatrix, mFOV, (float)mScreenWidth / (float)mScreenHeight, mZnear, mZfar);
68
69 // setup ortho projection matrix
70 glhOrthof2(mOrthoMatrix, -mScreenWidth/2.0f, mScreenWidth/2.0f, -mScreenHeight/2.0f, mScreenHeight/2.0f, -1.0f, 1.0f);
71
72 glClearColor(0.7f, 0.9f, 1.0f, 1.0f);
73 glClearDepthf(1.0f);
74
75 // depth test is less-equal
76 glEnable(GL_DEPTH_TEST);
77 glDepthFunc(GL_LEQUAL);
78
79 // cull-face is the back face
80 glEnable(GL_CULL_FACE);
81 glCullFace(GL_BACK);
82
83 // one minus alpha blend testing
84 glEnable(GL_BLEND);
85 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
86}
Hat irgend jemand eine Ahnung?