How to get an EGL display/context to a specific GLSurfaceView

独自空忆成欢 提交于 2019-12-03 13:56:58

问题


This is a follow up to my original Question, which was probably too broad (whereas this one is probably too specific but maybe I can apply Newton's Method).

My specific situation is: OpenGL ES 2.0, on Android, using only Java (no JNI/Native code).

I am trying to understand how EGL and Android's GLES implimentation work together (or don't). I am having trouble because the EGL interface(API) does not seem well suited to Android's Java centric, Activity based OS.

As a specific example: I have subclassed GLSurfaceView and create an instance using an XML layout and then use findViewById() to retrieve a reference. Using this approach I have the textured triangle example working (GLES 2.0 on Android 2.2, API level 8). This example does not use EGL. As a learning exercise I wanted to re-write it using EGL.

All the examples I can find use eglGetDisplay() and eglInitialize(), and create a context in puff of greasy black smoke. None of the examples, references and questions I have found apply specifically to ES2.0/EGL/Android/Java. Am I completely missing something? This question is related (I think) but does not have any responses and the example used in the ES 2.0 Programming Guide is a stand alone C implementation.


回答1:


There is nothing Android specific to EGL really. When you create an EGL window surface (eglCreateWindowSurface) you give it a Surface or a SurfaceHolder (which a SurfaceView will give you.) This means you can pretty much copy/paste an EGL example from C, C++ or any other language and have it work on Android in minutes. That's how I do it ;-)

Update: I just read your other message. You need EGL to initialize a GLES context.



来源:https://stackoverflow.com/questions/6510964/how-to-get-an-egl-display-context-to-a-specific-glsurfaceview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!