Note that there are some explanatory texts on larger screens.

plurals
  1. POPassing GLSurfaceView context to a thread
    text
    copied!<p>I want my GL Renderer to be set to "DIRTY" and use a thread to control the FPS but for some reason the <code>requestRender</code> call seems to be skipped over all together. I have a feeling this could be something to do with the thread not getting the proper context. Does anybody know good practice for passing <code>GLSurfaceView</code> context to other threads?</p> <p>Here is my thread:</p> <pre><code>public class GameLoop extends Thread { private GLSurfaceView myGLSurfaceView; private final static int maxFPS = 30; private final static int maxFrameSkips = 5; private final static int framePeriod = 1000 / maxFPS; public static boolean running; public final static String TAG = "input"; public GameLoop(){ myGLSurfaceView = MyLaunchActivity.getMyGLSurfaceView(); } @Override public void run() { running = MyLaunchActivity.getRunning(); long beginTime; long timeDiff; int sleepTime; int framesSkipped; sleepTime = 0; while (running) { running = MyLaunchActivity.getRunning(); //Log.d(TAG, "gameRunning"); beginTime = System.currentTimeMillis(); framesSkipped = 0; GameLogic.update(); myGLSurfaceView.requestRender(); //Log.d(TAG, "rendered"); timeDiff = System.currentTimeMillis() - beginTime; sleepTime = (int)(framePeriod - timeDiff); if (sleepTime &gt; 0) { try{ Thread.sleep(sleepTime); //Log.d(TAG, "sleeping" + String.valueOf(sleepTime)); }catch(InterruptedException e){} } while(sleepTime &lt; 0 &amp;&amp; framesSkipped &lt; maxFrameSkips){ GameLogic.update(); sleepTime += framePeriod; framesSkipped++; Log.d(TAG, "Frames Skipped"); } } } } </code></pre> <p>And here is the constructor for my surface view ...</p> <pre><code> public MyGLSurfaceView(Context context, AttributeSet attrs){ super(context, attrs); myGLSurfaceRenderer = new MyGLSurfaceRenderer(); setRenderer(myGLSurfaceRenderer); setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY); Log.d(TAG, "GLSurfaceViewed"); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload