有关opengles和质地上的android [英] about opengles and texture on android

查看:177
本文介绍了有关opengles和质地上的android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我们所知,在的OpenGL ES 在Android上类渲染有3个功能:onDrawFrame,onSurfaceChanged, onSurfaceCreated。 我们可以载入纹理在 onSurfaceCreated onDrawFrame 。 我想知道在渲染之前,我可以载入纹理 .Likely,我有一类名为地图,并且我可以加载图像纹理在地图创建了GLSurfaceView之前。或功能之前,我可以加载图像质感的onSurfaceCreatedonDrawFrame

As we know,in the OpenGL ES the class Renderer on android has 3 function:onDrawFrame, onSurfaceChanged, onSurfaceCreated. and we can load the texture in the onSurfaceCreated and onDrawFrame. I want to know can i load the texture before the "Renderer".Likely, I have a class named "Map",and can i load the images texture in the "Map" before the "GLSurfaceView" created. or can i load the images texture before the function "onSurfaceCreated" and "onDrawFrame".

如果有人知道,请帮助我。

if someone know it,please help me.

谢谢!

推荐答案

不容易。但(几乎)一切皆有可能。

Not easily. But (almost) anything is possible.

要了解这里的关键概念是OpenGL调用上的目前的情况下进行操作。之前,你可以做任何OpenGL调用,你需要创建一个环境,并使其电流。上下文是当前适用于一个线程,因此不同的线程可以有不同的当前上下文。我不认为这是明确的,如果你试图做,而不必当前上下文OpenGL调用会发生什么,但可以肯定的是没有任何用处。最可能的结果是什么都没有,或者崩溃。

The critical concept to understand here is that OpenGL calls operate on a current context. Before you can make any OpenGL calls, you need to create a context, and make it current. The context being current applies to a thread, so different threads can have different current contexts. I don't think it's clearly defined what happens if you attempt to make OpenGL calls without having a current context, but it certainly isn't anything useful. The most likely outcomes would be nothing at all, or a crash.

GLSurfaceView 处理所有的设定背景为你的复杂性。它创建一个独立于主(UI)线程运行的渲染线程,创建一个环境,使在渲染线程上下文中的电流。一旦调用你的 GLSurfaceView.Renderer 实施办法,你已经有了一个目前的情况下,你就可以让OpenGL调用。

GLSurfaceView handles all of the complexity of setting up contexts for you. It creates a rendering thread that runs independently from the main (UI) thread, creates a context, and makes that context current in the rendering thread. Once methods on your GLSurfaceView.Renderer implementation are invoked, you already have a current context, and you're ready to make OpenGL calls.

现在,如果你想使之前所有这一切 GLSurfaceView 奇迹发生了,你必须做大量的这个自己OpenGL调用。您可以拨打 EGL14 类的方法来创建自己的背景,和使其电流。这是轻微的疼痛,但并不是非常困难。我没有完全code方便,但你应该能够要么找到的例子,或者弄明白的文档。你会使用诸如 eglChooseConfig() eglCreateContext() eglMakeCurrent(),大概一个多极少数的道路上。

Now, if you want to make OpenGL calls before all of that GLSurfaceView magic happens, you have to do a lot of this yourself. You can call methods of the EGL14 class to create your own context, and make it current. It's slightly painful, but not terribly difficult. I don't have full code handy, but you should be able to either find examples, or figure it out from documentation. You will use methods like eglChooseConfig(), eglCreateContext(), eglMakeCurrent(), and probably a handful more on the way.

一旦你做完这些,你可以让你的OpenGL创建纹理等电话,但遗憾的是,这并不是故事的全部呢。

Once you're done with that, you can make your OpenGL calls for creating textures, etc. But unfortunately, that's not the whole story yet.

在你的 GLSurfaceView 来生活,它会创建自己的上下文如常。不同的OpenGL上下文可以共享的资源(如纹理),但他们不这样做,默认情况下。由于 GLSurfaceView 一无所知您已经创建的情况下,也不会与你的情况下共享资源。

Once your GLSurfaceView comes to life, it will create its own context as usual. Different OpenGL contexts can share resources (like textures), but they don't do that by default. Since GLSurfaceView knows nothing about the context you already created, it won't share resources with your context.

要实现资源共享,必须通过 GLSurfaceView 干涉创建上下文。您可以使用 setEGLContextFactory 办法做到这一点。这允许您关联自己的上下文创建了 GLSurfaceView ,您现在可以创建一个背景下,共享资源与先前创建的背景下,并用于纹理加载

To enable resource sharing, you have to interfere in the creation of the context by GLSurfaceView. You can do this with the setEGLContextFactory method. This allows you to hook up your own context creation for the GLSurfaceView, where you can now create a context that shares resources with the context you created earlier, and used for your texture loading.

这篇关于有关opengles和质地上的android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆