java - about opengles and texture on android -


As we know, OpenGL ES class renderer In 3 function: onDrawFrame, onSurfaceChanged, onSurfaceCreated and we can load the texture in onSurfaceCreated and onDrawFrame . I want to know that I can load the texture before "renderer" . Maybe, I have a square named "map", and I can load the image texture in "map" before making "GLSurfaceView" or "Onsufficient" And the "onDrawFrame" function can load textures before the images.

If someone knows this, please help me.

Thank you!

Not easily but (almost) anything is possible.

The important concept to understand here is that OpenGL calls work on a current reference before you can make OpenCL calls, you have to make a reference and turn it on. . The current reference applies to a thread, so different threads can have current current references. I do not think it is clearly defined that what happens if you try to make OpenGL calls without the current context, but it is definitely not useful. Most likely the result is nothing, or the accident.

GLSurfaceView manages all the complexities of setting references for you, it creates a presentation thread that runs independently from the main thread (UI), creates a reference , And creates the current reference in the rendering thread. Once applicable to your GLSurfaceView.Renderer implementation, you already have an existing reference, and you are ready to make OpenGL calls.

Now, if you want to make OpenGL calls to all those GLSurfaceView before magic, you have to do a lot of things you can do to create your own reference class methods Can call, and turn it on. It's a bit painful, but not very difficult, I do not have a complete code available, but you should be able to find an example or understand it with documentation. You will use methods like eglChooseConfig () , eglCreateContext () , eglMakeCurrent () , and possibly a handful on the way.

Once you work with it, you can make your own OpenGL call to make texture. But unfortunately, this is not the whole story yet.

Once your GLSurfaceView arrives for life, it can share various OpenGL reference resources (such as texture) that will create their own context as usual, but they Do not do this by default because GLSurfaceView does not know anything about the context you've already created, it will not share resources with your reference.

To enable resource sharing, you have to interfere with the creation of the reference by GLSurfaceView you can do it by setEGLContextFactory Code> GLSurfaceView allows you to hook your own reference creation, where you can now create a reference that shares the resource with the reference you made earlier, and for your texture loading is used to.

Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -