2013-08-16 156 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