Retain GLUtil.maxTextureSize

This commit is contained in:
arkon 2021-09-05 14:34:54 -04:00
parent ec4e631760
commit ee20787c5e

View File

@ -5,50 +5,43 @@ import javax.microedition.khronos.egl.EGLConfig
import javax.microedition.khronos.egl.EGLContext import javax.microedition.khronos.egl.EGLContext
import kotlin.math.max import kotlin.math.max
class GLUtil private constructor() { object GLUtil {
companion object { val maxTextureSize: Int by lazy {
// Safe minimum default size // Get EGL Display
private const val IMAGE_MAX_BITMAP_DIMENSION = 2048 val egl = EGLContext.getEGL() as EGL10
val display = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY)
val maxTextureSize: Int // Initialise
get() { val version = IntArray(2)
// Get EGL Display egl.eglInitialize(display, version)
val egl = EGLContext.getEGL() as EGL10
val display = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY)
// Initialise // Query total number of configurations
val version = IntArray(2) val totalConfigurations = IntArray(1)
egl.eglInitialize(display, version) egl.eglGetConfigs(display, null, 0, totalConfigurations)
// Query total number of configurations // Query actual list configurations
val totalConfigurations = IntArray(1) val configurationsList = arrayOfNulls<EGLConfig>(totalConfigurations[0])
egl.eglGetConfigs(display, null, 0, totalConfigurations) egl.eglGetConfigs(display, configurationsList, totalConfigurations[0], totalConfigurations)
// Query actual list configurations val textureSize = IntArray(1)
val configurationsList = arrayOfNulls<EGLConfig>(totalConfigurations[0]) var maximumTextureSize = 0
egl.eglGetConfigs(display, configurationsList, totalConfigurations[0], totalConfigurations)
val textureSize = IntArray(1) // Iterate through all the configurations to located the maximum texture size
var maximumTextureSize = 0 for (i in 0 until totalConfigurations[0]) {
// Only need to check for width since opengl textures are always squared
egl.eglGetConfigAttrib(display, configurationsList[i], EGL10.EGL_MAX_PBUFFER_WIDTH, textureSize)
// Iterate through all the configurations to located the maximum texture size // Keep track of the maximum texture size
for (i in 0 until totalConfigurations[0]) { if (maximumTextureSize < textureSize[0]) maximumTextureSize = textureSize[0]
// 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 // Release
if (maximumTextureSize < textureSize[0]) maximumTextureSize = textureSize[0] egl.eglTerminate(display)
}
// Release // Return largest texture size found, or default
egl.eglTerminate(display) max(maximumTextureSize, IMAGE_MAX_BITMAP_DIMENSION)
// Return largest texture size found, or default
return max(maximumTextureSize, IMAGE_MAX_BITMAP_DIMENSION)
}
}
init {
throw InstantiationException("This class is not for instantiation")
} }
} }
// Safe minimum default size
private const val IMAGE_MAX_BITMAP_DIMENSION = 2048