硬件加速活动 - 如何获取 OpenGL 纹理大小限制?

发布于 2024-12-04 11:19:24 字数 397 浏览 2 评论 0原文

我正在尝试在 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 技术交流群。

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

发布评论

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

评论(4

倾城泪 2024-12-11 11:19:24

目前最小限制为 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() and Canvas.getMaximumBitmapHeight().

婴鹅 2024-12-11 11:19:24

获取最大允许大小的另一种方法是循环遍历所有 EGL10 配置并跟踪最大大小。

public static int getMaxTextureSize() {
    // Safe minimum default size
    final int IMAGE_MAX_BITMAP_DIMENSION = 2048;

    // Get EGL Display
    EGL10 egl = (EGL10) EGLContext.getEGL();
    EGLDisplay display = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);

    // Initialise
    int[] version = new int[2];
    egl.eglInitialize(display, version);

    // Query total number of configurations
    int[] totalConfigurations = new int[1];
    egl.eglGetConfigs(display, null, 0, totalConfigurations);

    // Query actual list configurations
    EGLConfig[] configurationsList = new EGLConfig[totalConfigurations[0]];
    egl.eglGetConfigs(display, configurationsList, totalConfigurations[0], totalConfigurations);

    int[] textureSize = new int[1];
    int maximumTextureSize = 0;

    // Iterate through all the configurations to located the maximum texture size
    for (int i = 0; i < totalConfigurations[0]; i++) {
        // Only need to check for width since opengl textures are always squared
        egl.eglGetConfigAttrib(display, configurationsList[i], EGL10.EGL_MAX_PBUFFER_WIDTH, textureSize);

        // Keep track of the maximum texture size
        if (maximumTextureSize < textureSize[0])
            maximumTextureSize = textureSize[0];
    }

    // Release
    egl.eglTerminate(display);

    // Return largest texture size found, or default
    return Math.max(maximumTextureSize, IMAGE_MAX_BITMAP_DIMENSION);
}

根据我的测试,这非常可靠,不需要您创建实例。
就性能而言,这在我的 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.

public static int getMaxTextureSize() {
    // Safe minimum default size
    final int IMAGE_MAX_BITMAP_DIMENSION = 2048;

    // Get EGL Display
    EGL10 egl = (EGL10) EGLContext.getEGL();
    EGLDisplay display = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);

    // Initialise
    int[] version = new int[2];
    egl.eglInitialize(display, version);

    // Query total number of configurations
    int[] totalConfigurations = new int[1];
    egl.eglGetConfigs(display, null, 0, totalConfigurations);

    // Query actual list configurations
    EGLConfig[] configurationsList = new EGLConfig[totalConfigurations[0]];
    egl.eglGetConfigs(display, configurationsList, totalConfigurations[0], totalConfigurations);

    int[] textureSize = new int[1];
    int maximumTextureSize = 0;

    // Iterate through all the configurations to located the maximum texture size
    for (int i = 0; i < totalConfigurations[0]; i++) {
        // Only need to check for width since opengl textures are always squared
        egl.eglGetConfigAttrib(display, configurationsList[i], EGL10.EGL_MAX_PBUFFER_WIDTH, textureSize);

        // Keep track of the maximum texture size
        if (maximumTextureSize < textureSize[0])
            maximumTextureSize = textureSize[0];
    }

    // Release
    egl.eglTerminate(display);

    // Return largest texture size found, or default
    return Math.max(maximumTextureSize, IMAGE_MAX_BITMAP_DIMENSION);
}

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.

心头的小情儿 2024-12-11 11:19:24

如果您想动态了解设备的纹理大小限制(因为它会根据设备而变化),则必须调用此方法:

int[] maxTextureSize = new int[1];
gl.glGetIntegerv(GL10.GL_MAX_TEXTURE_SIZE, maxTextureSize, 0);

并且不要忘记,对于某些设备(例如 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:

int[] maxTextureSize = new int[1];
gl.glGetIntegerv(GL10.GL_MAX_TEXTURE_SIZE, maxTextureSize, 0);

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

樱花落人离去 2024-12-11 11:19:24

根据规范,使用GL_MAX_TEXTURE_SIZE调用glGetIntegerv

GL_MAX_TEXTURE_SIZE 参数返回一个值。该值给出了 GL 可以处理的最大纹理的粗略估计。该值必须至少为 64。

http://www.khronos .org/opengles/sdk/docs/man/xhtml/glGet.xml

According to the specification, calling glGetIntegerv with GL_MAX_TEXTURE_SIZE.

GL_MAX_TEXTURE_SIZE params returns one value. The value gives a rough estimate of the largest texture that the GL can handle. The value must be at least 64.

http://www.khronos.org/opengles/sdk/docs/man/xhtml/glGet.xml

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