Android:OpenGL 重新加载纹理

发布于 2025-01-02 11:37:23 字数 1078 浏览 3 评论 0原文

我正在尝试在我的应用程序中添加一个加载屏幕,因为加载纹理需要一些时间。这就是我之前所做的...

 public void onSurfaceCreated(GL10 gl, EGLConfig config) {         
         super.onSurfaceCreated(gl, config);
         if(firstTimeCreate) {
             load();            //load settings
             Assets.LoadTextures(this);
             firstTimeCreate = false;} 
          else {
            //When screen is resumed....
            Assets.reloadTextures();}

这样,在应用程序恢复后,else 语句将生效并重新加载所有内容...我尝试将其适应于此

else {
            //When screen is resumed....
            Thread aThread = new Thread()
            {
                public void run(){
                    boolean once = true;
                    while(once)
                    {
                        Assets.reloadTexutres();
                        once = false;
                    }
                }
            };
            aThread.start();
        }

但是现在看来 OpenGL 无法将纹理绑定为屏幕是白色的。向这个方法添加线程会出现什么问题?在让 OpenGL 开始尝试渲染之前,我是否需要等待所有纹理加载完毕,如果是这样,我如何加载一个纹理,然后呈现一个加载屏幕,直到其余部分完成?

谢谢

I am trying to add a loading screen into my app as it takes some time to load off of the textures. This is what I was doing before...

 public void onSurfaceCreated(GL10 gl, EGLConfig config) {         
         super.onSurfaceCreated(gl, config);
         if(firstTimeCreate) {
             load();            //load settings
             Assets.LoadTextures(this);
             firstTimeCreate = false;} 
          else {
            //When screen is resumed....
            Assets.reloadTextures();}

This way after the app was resumed the else statement would take effect and reload everything...I tried to adapt it to this

else {
            //When screen is resumed....
            Thread aThread = new Thread()
            {
                public void run(){
                    boolean once = true;
                    while(once)
                    {
                        Assets.reloadTexutres();
                        once = false;
                    }
                }
            };
            aThread.start();
        }

However it just seems now that OpenGL cant bind the textures as the screen is white. What is going wrong by adding a thread to this method? Do I need to wait for all the textures to load before I let OpenGL start to try and render, if so how can I load one and then present a loading screen until the rest are done?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

命比纸薄 2025-01-09 11:37:23

OpenGL ES 上下文被分配给一个线程。因此,如果您想在一个线程中创建上下文并在另一个线程中使用它,您应该调用 eglMakeCurrent(...) 函数。

OpenGL ES context is assigned to a thread. So, if you want to create context in one thread and use it in another thread, you should call eglMakeCurrent(...) function.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文