HW accelerated activity - how to get OpenGL texture size limit?

后端 未结 4 493
时光取名叫无心
时光取名叫无心 2020-11-27 13:23

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:

4条回答
  •  悲&欢浪女
    2020-11-27 14:11

    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.

提交回复
热议问题