commonMain.ru.casperix.opengl.renderer.TextureProvider.kt Maven / Gradle / Ivy
package ru.casperix.opengl.renderer
import ru.casperix.opengl.renderer.texture.GLTexture
import ru.casperix.opengl.renderer.texture.GLTexture2D
import ru.casperix.opengl.renderer.texture.GLTexture2DArray
import ru.casperix.opengl.renderer.texture.GLTextureCube
import ru.casperix.renderer.material.Texture
import ru.casperix.renderer.material.Texture2D
import ru.casperix.renderer.material.Texture2DArray
import ru.casperix.renderer.material.TextureCube
class TextureProvider {
private val textureCache = mutableMapOf()
fun getTexture(texture: Texture): GLTexture {
return textureCache.getOrPut(texture) {
when (texture) {
is Texture2D -> GLTexture2D(texture)
is Texture2DArray -> GLTexture2DArray(texture)
is TextureCube -> GLTextureCube(texture)
else -> throw Exception("Unsupported texture type: ${texture::class.simpleName}")
}
}
}
}