All Downloads are FREE. Search and download functionalities are using the official Maven repository.
Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
commonMain.ru.casperix.opengl.renderer.texture.GLTextureCube.kt Maven / Gradle / Ivy
package ru.casperix.opengl.renderer.texture
import ru.casperix.opengl.core.*
import ru.casperix.opengl.renderer.texture.GLTexture.Companion.asGLMagFilter
import ru.casperix.opengl.renderer.texture.GLTexture.Companion.asGLMinFilter
import ru.casperix.opengl.renderer.texture.GLTexture.Companion.asGLWrap
import ru.casperix.renderer.material.TextureCube
import ru.casperix.renderer.pixel_map.PixelMap
class GLTextureCube(val texture: TextureCube) : GLTexture {
val handle = glGenTexture()
// constructor(colorProvider: ColorCube) : this(colorProvider.minX, colorProvider.maxX, colorProvider.minY, colorProvider.maxY, colorProvider.minZ, colorProvider.maxZ)
init {
glBindTexture(GL_TEXTURE_CUBE_MAP, handle)
texture.apply {
loadFace(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, minX)
loadFace(GL_TEXTURE_CUBE_MAP_POSITIVE_X, maxX)
loadFace(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, minY)
loadFace(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, maxY)
loadFace(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, minZ)
loadFace(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, maxZ)
}
texture.config.apply {
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, asGLWrap(uWrap))
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, asGLWrap(vWrap))
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, asGLWrap(wWrap))
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, asGLMinFilter(minFilter, useMipMap))
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, asGLMagFilter(magFilter, useMipMap))
}
}
override fun dispose() {
glDeleteTexture(handle)
}
private fun loadFace(key: Int, pixelMap: PixelMap) {
glTexImage2D(
key,
0,
GL_RGBA,
pixelMap.width,
pixelMap.height,
0,
GL_RGBA,
GL_UNSIGNED_BYTE,
pixelMap.bytes.data.toByteArray()
)
}
override fun bind(channel: Int) {
glActiveTexture(GL_TEXTURE0 + channel)
glBindTexture(GL_TEXTURE_CUBE_MAP, handle)
}
}