What is different between this:
queueEvent(new Runnable(){
@Override
public void run() {
mRenderer.method();
}});
And this:
mRenderer.method();
And what is better for OpenGL FPS?
A GLSurfaceView provides the following features: Manages a surface, which is a special piece of memory that can be composited into the Android view system. Manages an EGL display, which enables OpenGL to render into a surface. Accepts a user-provided Renderer object that does the actual rendering.
In order to draw graphics with OpenGL ES in your Android application, you must create a view container for them. One of the more straight-forward ways to do this is to implement both a GLSurfaceView and a GLSurfaceView. Renderer . A GLSurfaceView is a view container for graphics drawn with OpenGL and GLSurfaceView.
GLSurfaceView
creates a separate rendering thread. In OpenGL, you need a current context for making any OpenGL calls. The "current context" state is per thread. GLSurfaceView
creates an OpenGL context for you, and makes it current for any of the GLSurfaceView.Renderer
overrides you implement. So as long as you make OpenGL calls in those methods, you don't have to worry about any of that, it just works like pure magic (well, it's not really magic, but hides a lot of complexity).
Based on this, you can't make OpenGL calls from the UI thread without jumping through hoops. So simply calling a method on the Renderer
in something that is e.g. triggered by user input, and then making OpenGL calls in that method, will fail. Beyond that, even if you don't make OpenGL calls in the method, you have to worry about thread safety if the method accesses/modifies member variables of the Renderer
that are also used by the rendering thread.
Using queueEvent()
provides a convenient way of executing a method in the rendering thread. So you don't have to worry about thread safety of Renderer
member variables, because all access will happen in the rendering thread.
I believe you might also be able to make OpenGL calls in that method if you submit it through queueEvent()
. But I'm not totally sure if the OpenGL context is always current in the rendering thread, or if that's only guaranteed while the Renderer
method overrides are called. It's much more typically to just change state in the Renderer
in response to user input, and then use that new state in your override of Renderer.onDrawFrame()
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With