Android OpenGL: GLSurfaceView.Renderer.onDrawFrame() called twice at startup
up vote
0
down vote
favorite
I have a simple Android application which uses OpenGL (via GLSurfaceView).
Code is below:
public class MainActivity extends Activity
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(new MyGLSurfaceView(this));
class MyGLSurfaceView extends GLSurfaceView implements GLSurfaceView.Renderer
MyGLSurfaceView(Context context)
super(context);
setEGLContextClientVersion(2); // OpenGL ES 2.0
setRenderer(this); // callbacks go to this class
setRenderMode(RENDERMODE_WHEN_DIRTY); // draw on request
public void onSurfaceChanged(GL10 gl, int width, int height)
public void onSurfaceCreated(GL10 gl, EGLConfig config)
public void onDrawFrame(GL10 gl)
/* if (startup) do_only_once(); */
try Thread.sleep(250); catch (Exception ignored)
At the application startup onDrawFrame() (of GLSurfaceView.Renderer) called twice most of times.
As far as I know, onSurfaceChanged() (of GLSurfaceView.Renderer) should call onDrawFrame(), but I don't understand why it happens several times.
I would like to compute and draw some "background" objects, that should be done only once. I use setRenderMode(RENDERMODE_WHEN_DIRTY). But onDrawFrame() is still called several times. How can I make it to be called only once? What is the reason of such repetitive calling?
Adding Logging for these functions (and also some default Activity callbacks) in the start and the end of each will result in output below. Activity lifecycle seems to work fine:
// Example of function with Logging:
protected void onCreate(Bundle savedInstanceState)
Log.d("__DEBUG__", "onCreate() ");
super.onCreate(savedInstanceState);
setContentView(new MyGLSurfaceView(this));
Log.d("__DEBUG__", "onCreate() ");
22:12:46.361 __DEBUG__: onCreate()
22:12:46.376 __DEBUG__: MyGLSurfaceView()
22:12:46.376 __DEBUG__: MyGLSurfaceView()
22:12:46.430 __DEBUG__: onCreate()
22:12:46.431 __DEBUG__: onStart()
22:12:46.431 __DEBUG__: onStart()
22:12:46.432 __DEBUG__: onResume()
22:12:46.433 __DEBUG__: onResume()
22:12:46.498 __DEBUG__: onSurfaceCreated()
22:12:46.498 __DEBUG__: onSurfaceCreated()
22:12:46.498 __DEBUG__: onSurfaceChanged()
22:12:46.498 __DEBUG__: onSurfaceChanged()
22:12:46.498 __DEBUG__: onDrawFrame()
22:12:46.748 __DEBUG__: onDrawFrame()
22:12:46.754 __DEBUG__: onDrawFrame()
22:12:47.004 __DEBUG__: onDrawFrame()
android opengl-es glsurfaceview
|
show 1 more comment
up vote
0
down vote
favorite
I have a simple Android application which uses OpenGL (via GLSurfaceView).
Code is below:
public class MainActivity extends Activity
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(new MyGLSurfaceView(this));
class MyGLSurfaceView extends GLSurfaceView implements GLSurfaceView.Renderer
MyGLSurfaceView(Context context)
super(context);
setEGLContextClientVersion(2); // OpenGL ES 2.0
setRenderer(this); // callbacks go to this class
setRenderMode(RENDERMODE_WHEN_DIRTY); // draw on request
public void onSurfaceChanged(GL10 gl, int width, int height)
public void onSurfaceCreated(GL10 gl, EGLConfig config)
public void onDrawFrame(GL10 gl)
/* if (startup) do_only_once(); */
try Thread.sleep(250); catch (Exception ignored)
At the application startup onDrawFrame() (of GLSurfaceView.Renderer) called twice most of times.
As far as I know, onSurfaceChanged() (of GLSurfaceView.Renderer) should call onDrawFrame(), but I don't understand why it happens several times.
I would like to compute and draw some "background" objects, that should be done only once. I use setRenderMode(RENDERMODE_WHEN_DIRTY). But onDrawFrame() is still called several times. How can I make it to be called only once? What is the reason of such repetitive calling?
Adding Logging for these functions (and also some default Activity callbacks) in the start and the end of each will result in output below. Activity lifecycle seems to work fine:
// Example of function with Logging:
protected void onCreate(Bundle savedInstanceState)
Log.d("__DEBUG__", "onCreate() ");
super.onCreate(savedInstanceState);
setContentView(new MyGLSurfaceView(this));
Log.d("__DEBUG__", "onCreate() ");
22:12:46.361 __DEBUG__: onCreate()
22:12:46.376 __DEBUG__: MyGLSurfaceView()
22:12:46.376 __DEBUG__: MyGLSurfaceView()
22:12:46.430 __DEBUG__: onCreate()
22:12:46.431 __DEBUG__: onStart()
22:12:46.431 __DEBUG__: onStart()
22:12:46.432 __DEBUG__: onResume()
22:12:46.433 __DEBUG__: onResume()
22:12:46.498 __DEBUG__: onSurfaceCreated()
22:12:46.498 __DEBUG__: onSurfaceCreated()
22:12:46.498 __DEBUG__: onSurfaceChanged()
22:12:46.498 __DEBUG__: onSurfaceChanged()
22:12:46.498 __DEBUG__: onDrawFrame()
22:12:46.748 __DEBUG__: onDrawFrame()
22:12:46.754 __DEBUG__: onDrawFrame()
22:12:47.004 __DEBUG__: onDrawFrame()
android opengl-es glsurfaceview
Possible duplicate of Is it normal for the "activity.onCreate()" method to be called multiple times
– muradm
Nov 11 at 20:03
@muradm, my Activity.onCreate() works fine (called only once, according to Log), the question is about GLSurfaceView lifecycle.
– DualGlad
Nov 11 at 20:09
According to log everything is called twice. And yourGLSurfaceView
is initialized withinonCreate()
method. So if it is called twice, thenonCreate()
is called twice. Otherwise you are initializingGLSurfaceView
also somewhere else, which is not illustrated in code snippets.
– muradm
Nov 11 at 20:15
@muradm, for logging I used "func_name() " at the beginning ot func_name() and "func_name() " at the end of it. It shows that new onDrawFrame() is called only after the end of previous one.
– DualGlad
Nov 11 at 20:27
@muradm, added an example of Logging. Each function should be printed 2 times
– DualGlad
Nov 11 at 20:33
|
show 1 more comment
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have a simple Android application which uses OpenGL (via GLSurfaceView).
Code is below:
public class MainActivity extends Activity
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(new MyGLSurfaceView(this));
class MyGLSurfaceView extends GLSurfaceView implements GLSurfaceView.Renderer
MyGLSurfaceView(Context context)
super(context);
setEGLContextClientVersion(2); // OpenGL ES 2.0
setRenderer(this); // callbacks go to this class
setRenderMode(RENDERMODE_WHEN_DIRTY); // draw on request
public void onSurfaceChanged(GL10 gl, int width, int height)
public void onSurfaceCreated(GL10 gl, EGLConfig config)
public void onDrawFrame(GL10 gl)
/* if (startup) do_only_once(); */
try Thread.sleep(250); catch (Exception ignored)
At the application startup onDrawFrame() (of GLSurfaceView.Renderer) called twice most of times.
As far as I know, onSurfaceChanged() (of GLSurfaceView.Renderer) should call onDrawFrame(), but I don't understand why it happens several times.
I would like to compute and draw some "background" objects, that should be done only once. I use setRenderMode(RENDERMODE_WHEN_DIRTY). But onDrawFrame() is still called several times. How can I make it to be called only once? What is the reason of such repetitive calling?
Adding Logging for these functions (and also some default Activity callbacks) in the start and the end of each will result in output below. Activity lifecycle seems to work fine:
// Example of function with Logging:
protected void onCreate(Bundle savedInstanceState)
Log.d("__DEBUG__", "onCreate() ");
super.onCreate(savedInstanceState);
setContentView(new MyGLSurfaceView(this));
Log.d("__DEBUG__", "onCreate() ");
22:12:46.361 __DEBUG__: onCreate()
22:12:46.376 __DEBUG__: MyGLSurfaceView()
22:12:46.376 __DEBUG__: MyGLSurfaceView()
22:12:46.430 __DEBUG__: onCreate()
22:12:46.431 __DEBUG__: onStart()
22:12:46.431 __DEBUG__: onStart()
22:12:46.432 __DEBUG__: onResume()
22:12:46.433 __DEBUG__: onResume()
22:12:46.498 __DEBUG__: onSurfaceCreated()
22:12:46.498 __DEBUG__: onSurfaceCreated()
22:12:46.498 __DEBUG__: onSurfaceChanged()
22:12:46.498 __DEBUG__: onSurfaceChanged()
22:12:46.498 __DEBUG__: onDrawFrame()
22:12:46.748 __DEBUG__: onDrawFrame()
22:12:46.754 __DEBUG__: onDrawFrame()
22:12:47.004 __DEBUG__: onDrawFrame()
android opengl-es glsurfaceview
I have a simple Android application which uses OpenGL (via GLSurfaceView).
Code is below:
public class MainActivity extends Activity
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(new MyGLSurfaceView(this));
class MyGLSurfaceView extends GLSurfaceView implements GLSurfaceView.Renderer
MyGLSurfaceView(Context context)
super(context);
setEGLContextClientVersion(2); // OpenGL ES 2.0
setRenderer(this); // callbacks go to this class
setRenderMode(RENDERMODE_WHEN_DIRTY); // draw on request
public void onSurfaceChanged(GL10 gl, int width, int height)
public void onSurfaceCreated(GL10 gl, EGLConfig config)
public void onDrawFrame(GL10 gl)
/* if (startup) do_only_once(); */
try Thread.sleep(250); catch (Exception ignored)
At the application startup onDrawFrame() (of GLSurfaceView.Renderer) called twice most of times.
As far as I know, onSurfaceChanged() (of GLSurfaceView.Renderer) should call onDrawFrame(), but I don't understand why it happens several times.
I would like to compute and draw some "background" objects, that should be done only once. I use setRenderMode(RENDERMODE_WHEN_DIRTY). But onDrawFrame() is still called several times. How can I make it to be called only once? What is the reason of such repetitive calling?
Adding Logging for these functions (and also some default Activity callbacks) in the start and the end of each will result in output below. Activity lifecycle seems to work fine:
// Example of function with Logging:
protected void onCreate(Bundle savedInstanceState)
Log.d("__DEBUG__", "onCreate() ");
super.onCreate(savedInstanceState);
setContentView(new MyGLSurfaceView(this));
Log.d("__DEBUG__", "onCreate() ");
22:12:46.361 __DEBUG__: onCreate()
22:12:46.376 __DEBUG__: MyGLSurfaceView()
22:12:46.376 __DEBUG__: MyGLSurfaceView()
22:12:46.430 __DEBUG__: onCreate()
22:12:46.431 __DEBUG__: onStart()
22:12:46.431 __DEBUG__: onStart()
22:12:46.432 __DEBUG__: onResume()
22:12:46.433 __DEBUG__: onResume()
22:12:46.498 __DEBUG__: onSurfaceCreated()
22:12:46.498 __DEBUG__: onSurfaceCreated()
22:12:46.498 __DEBUG__: onSurfaceChanged()
22:12:46.498 __DEBUG__: onSurfaceChanged()
22:12:46.498 __DEBUG__: onDrawFrame()
22:12:46.748 __DEBUG__: onDrawFrame()
22:12:46.754 __DEBUG__: onDrawFrame()
22:12:47.004 __DEBUG__: onDrawFrame()
android opengl-es glsurfaceview
android opengl-es glsurfaceview
edited Nov 11 at 21:13
Nicol Bolas
280k33461633
280k33461633
asked Nov 11 at 19:53
DualGlad
12
12
Possible duplicate of Is it normal for the "activity.onCreate()" method to be called multiple times
– muradm
Nov 11 at 20:03
@muradm, my Activity.onCreate() works fine (called only once, according to Log), the question is about GLSurfaceView lifecycle.
– DualGlad
Nov 11 at 20:09
According to log everything is called twice. And yourGLSurfaceView
is initialized withinonCreate()
method. So if it is called twice, thenonCreate()
is called twice. Otherwise you are initializingGLSurfaceView
also somewhere else, which is not illustrated in code snippets.
– muradm
Nov 11 at 20:15
@muradm, for logging I used "func_name() " at the beginning ot func_name() and "func_name() " at the end of it. It shows that new onDrawFrame() is called only after the end of previous one.
– DualGlad
Nov 11 at 20:27
@muradm, added an example of Logging. Each function should be printed 2 times
– DualGlad
Nov 11 at 20:33
|
show 1 more comment
Possible duplicate of Is it normal for the "activity.onCreate()" method to be called multiple times
– muradm
Nov 11 at 20:03
@muradm, my Activity.onCreate() works fine (called only once, according to Log), the question is about GLSurfaceView lifecycle.
– DualGlad
Nov 11 at 20:09
According to log everything is called twice. And yourGLSurfaceView
is initialized withinonCreate()
method. So if it is called twice, thenonCreate()
is called twice. Otherwise you are initializingGLSurfaceView
also somewhere else, which is not illustrated in code snippets.
– muradm
Nov 11 at 20:15
@muradm, for logging I used "func_name() " at the beginning ot func_name() and "func_name() " at the end of it. It shows that new onDrawFrame() is called only after the end of previous one.
– DualGlad
Nov 11 at 20:27
@muradm, added an example of Logging. Each function should be printed 2 times
– DualGlad
Nov 11 at 20:33
Possible duplicate of Is it normal for the "activity.onCreate()" method to be called multiple times
– muradm
Nov 11 at 20:03
Possible duplicate of Is it normal for the "activity.onCreate()" method to be called multiple times
– muradm
Nov 11 at 20:03
@muradm, my Activity.onCreate() works fine (called only once, according to Log), the question is about GLSurfaceView lifecycle.
– DualGlad
Nov 11 at 20:09
@muradm, my Activity.onCreate() works fine (called only once, according to Log), the question is about GLSurfaceView lifecycle.
– DualGlad
Nov 11 at 20:09
According to log everything is called twice. And your
GLSurfaceView
is initialized within onCreate()
method. So if it is called twice, then onCreate()
is called twice. Otherwise you are initializing GLSurfaceView
also somewhere else, which is not illustrated in code snippets.– muradm
Nov 11 at 20:15
According to log everything is called twice. And your
GLSurfaceView
is initialized within onCreate()
method. So if it is called twice, then onCreate()
is called twice. Otherwise you are initializing GLSurfaceView
also somewhere else, which is not illustrated in code snippets.– muradm
Nov 11 at 20:15
@muradm, for logging I used "func_name() " at the beginning ot func_name() and "func_name() " at the end of it. It shows that new onDrawFrame() is called only after the end of previous one.
– DualGlad
Nov 11 at 20:27
@muradm, for logging I used "func_name() " at the beginning ot func_name() and "func_name() " at the end of it. It shows that new onDrawFrame() is called only after the end of previous one.
– DualGlad
Nov 11 at 20:27
@muradm, added an example of Logging. Each function should be printed 2 times
– DualGlad
Nov 11 at 20:33
@muradm, added an example of Logging. Each function should be printed 2 times
– DualGlad
Nov 11 at 20:33
|
show 1 more comment
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53252604%2fandroid-opengl-glsurfaceview-renderer-ondrawframe-called-twice-at-startup%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Possible duplicate of Is it normal for the "activity.onCreate()" method to be called multiple times
– muradm
Nov 11 at 20:03
@muradm, my Activity.onCreate() works fine (called only once, according to Log), the question is about GLSurfaceView lifecycle.
– DualGlad
Nov 11 at 20:09
According to log everything is called twice. And your
GLSurfaceView
is initialized withinonCreate()
method. So if it is called twice, thenonCreate()
is called twice. Otherwise you are initializingGLSurfaceView
also somewhere else, which is not illustrated in code snippets.– muradm
Nov 11 at 20:15
@muradm, for logging I used "func_name() " at the beginning ot func_name() and "func_name() " at the end of it. It shows that new onDrawFrame() is called only after the end of previous one.
– DualGlad
Nov 11 at 20:27
@muradm, added an example of Logging. Each function should be printed 2 times
– DualGlad
Nov 11 at 20:33