When I rotate my device and my app recieves APP_CMD_CONFIG_CHANGED
, I attempt to update my OpenGL viewport with the following:
EGLint width;
EGLint height;
eglQuerySurface(display,surface,EGL_WIDTH,&width);
eglQuerySurface(display,surface,EGL_HEIGHT,&height);
glViewport(0,0,width,height);
MY_LOG_MACRO2("New window size: %d x %d",width,height);
This works about 20% of the time. The other 80% of the time the width and height are the previous values. In other words, most of the time when I turn my device to landscape mode, the portrait size is logged. And when I go back to portrait, the landscape size is logged.
I haven't had much luck with getting the size from the ANativeWindow
either.
What should I be doing to get correct window size after rotation?
Update:
By waiting a few frames after APP_CMD_CONFIG_CHANGED
, the size is always correct. Querying the size every frame, without regard for APP_CMD_CONFIG_CHANGED
, and checking if it has changed seems to work as well but feels wrong.