zoukankan      html  css  js  c++  java
  • GL线程




    1
    public class MiniLauncher extends AndroidApplication implements MenuActionListener { 2 3 public View glView =null; 4 public DesktopListener mListener; 5 @Override 6 public void onCreate(Bundle savedInstanceState) { 7 8 //得到的是一个surfaceView 9 glView = initializeDesktop(mListener, true); 10 setContentView(glView); 11 12 } 13 14 public View initializeDesktop(DesktopListener listener, 15 boolean useGL2IfAvailable) { 16 17 return initializeForView(listener, config); 18 19 20 21 } 22 }

       以下是gdx自己创建新线程的流程:

     1 AndroidApplication:
     2 
     3 protected AndroidGraphics graphics;
     4 protected ApplicationListener listener;
     5 public View initializeForView (ApplicationListener listener, AndroidApplicationConfiguration config) {
     6     //graphics will create another thread for ui drawing
     7     graphics = new AndroidGraphics(this, config, config.resolutionStrategy == null ? new FillResolutionStrategy()
     8             : config.resolutionStrategy);
     9     this.listener = listener;
    10 }
    11 
    12 AndroidGraphics:
    13 final View view;
    14     public AndroidGraphics (AndroidApplication activity, AndroidApplicationConfiguration config,
    15         ResolutionStrategy resolutionStrategy) {
    16         //thread created here
    17         view = createGLSurfaceView(activity, config.useGL20, resolutionStrategy);    
    18         this.app = activity;
    19     }
    20     
    21     private View createGLSurfaceView (Activity activity, boolean useGL2, final ResolutionStrategy resolutionStrategy) {
    22         GLSurfaceView20 view = new GLSurfaceView20(activity, true,16,0,resolutionStrategy);
    23         view.setRenderer(this);
    24         return view;
    25     }
    26     
    27     @Override
    28     public void onDrawFrame (javax.microedition.khronos.opengles.GL10 gl) {
    29     
    30         //这里的 listener 就是 d3dListener
    31        if (lresume) {
    32            app.listener.resume();
    33        }
    34        if (lrunning) {
    35               app.listener.render();
    36        }
    37        if (lpause) {
    38             app.listener.pause();
    39         }
    40         if (ldestroy) {
    41             app.listener.dispose();
    42         }
    43     
    44     }
    45 GLSurfaceView:
    46 
    47  public void setRenderer(Renderer renderer) {
    48       mGLThread = new GLThread(renderer);
    49       mGLThread.start();
    50  }
    51  
    52   class GLThread extends Thread {
    53     mRenderer = renderer;
    54       public void run() {
    55        guardedRun();
    56     }
    57       
    58     private void guardedRun() throws InterruptedException {
    59          while (true) {
    60          
    61             //mRenderer 就是 graphics
    62             mRenderer.onDrawFrame(gl);
    63          
    64          }
    65        
    66        }
    67   }
  • 相关阅读:
    树莓派4B
    第一个实验-LED灯闪烁
    GPIO
    新建库函数模板
    开发环境搭建
    博弈论
    区间dp
    字典树
    快速排序
    MarkDown
  • 原文地址:https://www.cnblogs.com/mogul/p/2975870.html
Copyright © 2011-2022 走看看