Android,触摸屏时 jni 中的 openGL 滞后

发布于 2024-10-21 04:34:38 字数 277 浏览 2 评论 0原文

我目前正在 Android 平台上测试我的游戏所需的所有功能。我只修改了 hello-gl2 示例代码,并在两个渲染通道中添加了一些纹理、VBO、FBO 和简单着色器。

问题是,当我让应用程序在不触摸屏幕的情况下运行时,我的帧速率约为 35-45 fps。但如果我开始连续触摸屏幕,渲染就会开始滞后!那么这是一个问题吗,因为输入和渲染位于同一个线程中(正如 a 所认为的那样?),是否有可能修复?如果我不能解决这个延迟问题,我的游戏可能就无法运行得足够好,无法玩。 (有一些繁重的渲染内容)

//提前致谢!

I am currently testing out all the features that a need in my game on the Android platform. I have only modified the hello-gl2 sample code, and added some textures, VBO's, FBO's and simple shaders in two rendering passes.

The thing is that when I let the app run with out touching the screen, i have about 35-45 fps. But if I start touching the screen continuously, the rendering starts to lag! So is this a problem because input and rendering is in the same thread (as a thinks it is?), is it even possible to fix? If I can't fix that lag, my game is probably not going to run good enough to bee playable. (Is has some heavy rendering stuff)

//Thanks in advance!

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

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

发布评论

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

评论(1

栀梦 2024-10-28 04:34:38

我对 Android 开发相当陌生,但发现触摸处理程序也非常滞后。默认示例是更新一个对象,并且经常这样做 - 这肯定会让垃圾收集器生气。我设法通过调用 'Thread.sleep(10);' 让它以不那么滞后的方式执行在运行函数内。

我想用对象的循环缓冲区替换“新的可运行”会提高性能,但我还没有对此进行研究。我认为触摸事件似乎发生在单独的线程上,这可能会导致复杂化。

Override public boolean onTouchEvent(final MotionEvent event)
    {
        queueEvent(


        new Runnable()
        {
            public void run()
            {

                int action = event.getAction();
                //do your handling here
                try
                {
                    Thread.sleep(10);
                } catch (InterruptedException e)
                {

                    e.printStackTrace();
                } 

            }
        });
        return true;
    }

I'm fairly new to android development but found the touch handler to be very laggy also. The default sample is newing up an object and doing this quite a lot - this is bound to make the garbage collector angry. I managed to get it to perform in a less laggy way by calling 'Thread.sleep(10);' inside the run function.

I imagine that replacing the 'new Runnable' with a circular buffer of objects would improve performance but I haven't investigated this yet. I'm the touch events seem to occur on a seperate thread and this may cause complications.

Override public boolean onTouchEvent(final MotionEvent event)
    {
        queueEvent(


        new Runnable()
        {
            public void run()
            {

                int action = event.getAction();
                //do your handling here
                try
                {
                    Thread.sleep(10);
                } catch (InterruptedException e)
                {

                    e.printStackTrace();
                } 

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