All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.ru.casperix.opengl.renderer.TextureProvider.kt Maven / Gradle / Ivy

There is a newer version: 0.11.1
Show newest version
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}")
            }

        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy