GLES20在onDrawFrame调用导致长时间延误 [英] GLES20 calls in onDrawFrame causes long delay

查看:2081
本文介绍了GLES20在onDrawFrame调用导致长时间延误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写一个游戏,当onDrawFrame()被调用我更新游戏状态,第一个(游戏逻辑和绘图缓冲区),然后继续做实际的图纸。在摩托G和的Nexus 7的一切工程进展顺利,每个onDrawFrame()调用只需要1-5ms之间。然而,在三星Galaxy S3,90%的时间onDrawFrame()调用花费只要30-50ms的更新。

I have written a game in which when onDrawFrame() is called I update the game state first (game logic and the buffers for drawing) and then proceed to do the actual drawings. On the Moto G and Nexus 7 everything works smoothly and each onDrawFrame() call takes only between 1-5ms. However, on the Samsung Galaxy S3, 90% of the time the onDrawFrame() call takes as long as 30-50ms to update.

进一步调查这个问题我发现这个问题上,我下面附加的第一个渲染方法全在于: -
(编辑:现在该块上glclear();在除去了不必要的呼叫来获取手柄,请参阅评论)

Further investigating the issue I found the problem wholly lies on the first render method which I attach below:- ( the block is now on glclear(); having removed the unnecessary calls to get the handles, please refer to the comments)

public void render(float[] m, FloatBuffer vertex, FloatBuffer texture, ShortBuffer indices, int TextureNumber) {
        GLES20.glVertexAttribPointer(mPositionHandle, 3, GLES20.GL_FLOAT, false, 0, vertex);            
        GLES20.glEnableVertexAttribArray(mPositionHandle);            

        GLES20.glVertexAttribPointer(mTexCoordLoc, 2, GLES20.GL_FLOAT, false, 0, texture);            
        GLES20.glEnableVertexAttribArray(mTexCoordLoc);            

        GLES20.glUniformMatrix4fv(mtrxhandle, 1, false, m, 0);            

        int mSamplerLoc = GLES20.glGetUniformLocation(fhGraphicTools.sp_Image, "s_texture");            

        GLES20.glUniform1i(mSamplerLoc, TextureNumber);            

        GLES20.glDrawElements(GLES20.GL_TRIANGLES, indices.capacity(), GLES20.GL_UNSIGNED_SHORT, indices);            
        // Disable vertex arrays used
        GLES20.glDisableVertexAttribArray(mPositionHandle);            
        GLES20.glDisableVertexAttribArray(mTexCoordLoc);            
    }

上面的方法被称为5次各onDrawFrame()来绘制在不同的纹理地图的东西。 (第4实际上是游戏的背景为1长的长方形)。已经登录花费在code,我发现我对S3具有滞后始终驻留在以下行之一的每一行的时间:

The above method is called 5 times in each onDrawFrame() to draw things on different texture atlas. (the first 4 are actually the game's background which is 1 long rectangle). Having logged the time it takes in each line of the code I found that the lag I am having on the S3 always reside in one of the below lines:

int mPositionHandle = GLES20.glGetAttribLocation(fhGraphicTools.sp_Image, "vPosition");

GLES20.glDrawElements(GLES20.GL_TRIANGLES, indices.capacity(), GLES20.GL_UNSIGNED_SHORT, indices);

滞后只发生在渲染(第一次调用)作为后续调用约需1-2MS每个。我曾尝试禁用第一渲染()调用但随后的第二个这之前只需要1-2MS现已成为滞后的根源,同样的思路下。

The lag only occurs in the first call of render() as the subsequent calls takes about 1-2ms each. I have tried disabling the first render() call but then the second which before only take 1-2ms now become the source of the lag, under the same lines.

有没有人有什么是错在我的code其中S3无法处理的想法?这似乎是S3有问题开始GL在每个onDrawFrame()的调用开始,但为什么会出现这样的行为我百思不得其解。有什么可以做,以减少启动延时?

Does anyone have an idea of what is wrong in my code which the S3 could not handle? It seem that the S3 have problem commencing GL calls at the beginning of each onDrawFrame(), but why is there such behavior is puzzling me. What can be done to decrease the "startup" delay?

在阅读您的耐心非常感谢。

Many thanks for your patience in reading.

编辑code采取Selvin的建议。

Edited code to take Selvin's recommendation.

推荐答案

我有固定的问题,当我提出我的PNG图像文件从/绘制到/绘-nodpi游戏速度回到正常的S3。
我假设由Android进行自动缩放使我提供的坏的大小导致每个onDrawFrame不必要的纹理过滤工作,使通话错过了垂直同步,并给予了glClear出现长时间的延迟,同时等待下一个OpenGL的原始位图垂直同步。如果我错了,还是一个新手,以图形,请大家指正。

I have fixed the issue when I moved all my png image files from /drawable to /drawable-nodpi the game speed goes back to normal on the S3. I assume the auto-scaling done by Android causes the raw bitmap I supplied to opengl in "bad" sizes causing unnecessary texture filtering work on each onDrawFrame, causing the call to miss out vsync and giving a long delay for the glClear while waiting for next vsync. Please correct me if I am wrong, still a newbie to graphics.

这篇关于GLES20在onDrawFrame调用导致长时间延误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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