2013-08-16 192 views
3

是否可以在屏幕上同時顯示多個渲染?就像將Android屏幕分成4個象限,並在每個象限上顯示一個立方體?我看到OpenGL的可能性,但這是GLUT,並且是基於Windows的。我正在研究如何爲android做這件事,但我還沒有遇到過任何描述。這是我創建渲染的主要活動。多個OpenGL ES 2 Android渲染

public class MainActivity extends Activity 
{ 

    private MyGLSurfaceView mGLView; 

    @Override 
    public void onCreate(Bundle savedInstanceState) 
    { 
     super.onCreate(savedInstanceState); 

     // Create a GLSurfaceView instance and set it 
     // as the ContentView for this Activity 

     // "this" is the reference to activity 
     mGLView = new MyGLSurfaceView(this); 
     setContentView(mGLView); 
    } 

    @Override 
    protected void onPause() 
    { 
     super.onPause(); 
     // The following call pauses the rendering thread. 
     // If your OpenGL application is memory intensive, 
     // you should consider de-allocating objects that 
     // consume significant memory here. 
     mGLView.onPause(); 
    } 

    @Override 
    protected void onResume() 
    { 
     super.onResume(); 
     // The following call resumes a paused rendering thread. 
     // If you de-allocated graphic objects for onPause() 
     // this is a good place to re-allocate them. 
     mGLView.onResume(); 
    } 
} 

class MyGLSurfaceView extends GLSurfaceView 
{ 

    private final MyGLRenderer mRenderer; 
    Context context; 

    public MyGLSurfaceView(Context context) 
    { 
     super(context); 

     this.context = context; 
     // Create an OpenGL ES 2.0 context. 
     setEGLContextClientVersion(2); 

     // Set the Renderer for drawing on the GLSurfaceView 
     Log.d("Test", "GL initialized"); 
     mRenderer = new MyGLRenderer(context); 
     setRenderer(mRenderer); 

     // Render the view only when there is a change in the drawing data 
     setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY); 
    } 
} 

回答

3

我不明白你爲什麼不能用一個GLSurfaceView做到這一點。通過調用glViewport將場景映射到該象限,可以將屏幕劃分爲四個象限。然後可以調用繪圖函數,然後爲每個後續象限重複。

例子:

glViewport(0, 0, width/2, height/2); 
< render first quadrant > 

glViewport(width/2, 0, width/2, height/2); 
< render second quadrant > 

等等......

1

GLSurfaceView並非設計用來做到這一點,而是可以通過使用TextureView來代替。查看TextureView的在線文檔。最簡單的方法是創建一個單獨的線程,依次渲染每個TextureView。如果你想要同時運行多個OpenGL ES上下文,這要複雜得多,但最近在Khronos.org OpenGL ES論壇上討論過。

+0

是的,我希望同時運行它們。基本上4個渲染器同時運行,每個都在屏幕的象限上。 – Ion

+0

我試過這種方法,但有時會出現腐敗和紋理視圖似乎得到其他紋理視圖紋理而不是實際繪製的紋理。我不認爲TextureView可靠地支持多個實例。 – jjxtra

+1

我與TextureView合作已有兩年了,但我看到Google FINALLY發佈了一些關於它如何在這裏工作的信息:https://source.android.com/devices/graphics/architecture.html – ClayMontgomery