硬件加速活动 - 如何获取 OpenGL 纹理大小限制?
我正在尝试在 Honeycomb 中启用硬件加速,并在 Canvas 上显示一些位图。 一切正常,但对于大位图(一维>2048),我在日志中收到错误:
OpenGLRenderer:位图太大,无法上传到纹理
我知道这是因为硬件限制,如果启用了硬件加速(通过 View.isHardwareAccelerated() 检查),可以通过减小要显示的最大位图大小来解决此问题。
我的问题是:如何轻松确定硬件可用于位图绘制的最大纹理大小。 2048似乎是我的设备上的限制,但在不同的设备上可能会有所不同。
编辑:我不是在创建 OpenGL 应用程序,只是创建普通应用程序,它可以利用硬件加速。因此我对OpenGL一点也不熟悉,我只是在日志中看到OpenGL相关的错误,并寻求解决它。
I'm trying to enable hw acceleration in Honeycomb, and display some Bitmaps on Canvas.
All works fine, but for large bitmaps (>2048 in one dimension), I get error in log:
OpenGLRenderer: Bitmap too large to be uploaded into a texture
I know this is because of hw limitation, and can work-around it by reducing max bitmap size to be displayed if hw acceleration is enabled (checking by View.isHardwareAccelerated()).
My question is: how to easily determine max texture size available for Bitmap drawing by hardware.
2048 seems to be limit on my device, but it may be different on different ones.
Edit: I'm not creating OpenGL app, just normal app, which can utilize hw acceleration. Thus I'm not familiar with OpenGL at all, I just see OpenGL related error in log, and look to solve it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
目前最小限制为 2048px(即硬件必须支持至少 2048x2048 的纹理。)在 ICS 中,我们将在 Canvas 类上引入一个新的 API,它将为您提供以下信息:
Canvas.getMaximumBitmapWidth()
和Canvas.getMaximumBitmapHeight()
。Currently the minimum limit is 2048px (i.e. the hardware must support textures at least 2048x2048.) In ICS we will introduce a new API on the Canvas class that will give you this information:
Canvas.getMaximumBitmapWidth()
andCanvas.getMaximumBitmapHeight()
.获取最大允许大小的另一种方法是循环遍历所有 EGL10 配置并跟踪最大大小。
根据我的测试,这非常可靠,不需要您创建实例。
就性能而言,这在我的 Note 2 上执行需要 18 毫秒,而在我的 G3 上只需要 4 毫秒。
Another way of getting the maximum allowed size would be to loop through all EGL10 configurations and keep track of the largest size.
From my testing, this is pretty reliable and doesn't require you to create an instance.
Performance-wise, this took 18 milliseconds to execute on my Note 2 and only 4 milliseconds on my G3.
如果您想动态了解设备的纹理大小限制(因为它会根据设备而变化),则必须调用此方法:
并且不要忘记,对于某些设备(例如 Nexus One),纹理大小必须是2的幂!
我知道我的答案是在该主题上次更新之后很长时间......抱歉
If you want to know dynamically the texture size limit of your device (because it's change depending on the device), you have to call this method:
And don't forget that for some device (the Nexus One for example), the texture size must be a power of 2 !
I know my answer comes a long time after the last update of this topic...sorry
根据规范,使用
GL_MAX_TEXTURE_SIZE
调用glGetIntegerv
。http://www.khronos .org/opengles/sdk/docs/man/xhtml/glGet.xml
According to the specification, calling
glGetIntegerv
withGL_MAX_TEXTURE_SIZE
.http://www.khronos.org/opengles/sdk/docs/man/xhtml/glGet.xml