MCPcopy Create free account
hub / github.com/OpenEndedGroup/Field2 / TextureArray

Class TextureArray

src/main/java/field/graphics/TextureArray.kt:17–137  ·  view source on GitHub ↗

* This is a brief partial attempt to write a texture array, designed, currently, to */

Source from the content-addressed store, hash-verified

15 * This is a brief partial attempt to write a texture array, designed, currently, to
16 */
17class TextureArray(var unit: Int, val w: Int, val h: Int, val d: Int, val source: ByteBuffer) : BaseScene<TextureArray.State>(), Perform, OffersUniform<Int> {
18 inner class State : Modifiable() {
19 var name = -1
20 }
21
22 override fun perform0(): Boolean {
23 val s: TextureArray.State = GraphicsContext.get(this)
24 GL13.glActiveTexture(GL13.GL_TEXTURE0 + unit)
25 GL11.glBindTexture(GL_TEXTURE_2D_ARRAY, s.name)
26 return true
27 }
28
29 override fun setup(): State {
30 val s: TextureArray.State = State()
31 s.name = GL11.glGenTextures()
32 GL13.glActiveTexture(GL13.GL_TEXTURE0 + unit)
33 GL11.glBindTexture(GL_TEXTURE_2D_ARRAY, s.name)
34
35 GL11.glTexParameteri(GL_TEXTURE_2D_ARRAY, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR)
36 GL11.glTexParameteri(GL_TEXTURE_2D_ARRAY, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR)
37 GL11.glTexParameteri(GL_TEXTURE_2D_ARRAY, GL11.GL_TEXTURE_WRAP_S, GL12.GL_CLAMP_TO_EDGE)
38 GL11.glTexParameteri(GL_TEXTURE_2D_ARRAY, GL11.GL_TEXTURE_WRAP_T, GL12.GL_CLAMP_TO_EDGE)
39
40 GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1)
41 GL11.glPixelStorei(GL11.GL_UNPACK_ROW_LENGTH, w);
42
43 ARBTextureStorage.glTexStorage3D(GL_TEXTURE_2D_ARRAY, 1, GL11.GL_RGBA8, w, h, d)
44 glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, 0, w, h, d, GL11.GL_RGB, GL11.GL_UNSIGNED_BYTE, source)
45
46 return s
47 }
48
49 override fun getPasses(): IntArray {
50 return intArrayOf(-1)
51 }
52
53 override fun deallocate(s: State) {
54 GL11.glDeleteTextures(s!!.name)
55 }
56
57 override fun getUniform(): Int {
58 return unit
59 }
60
61 companion object {
62
63 @JvmStatic
64 val dirCache = HashMap<String, TextureArray?>()
65
66 @JvmStatic
67 @JvmOverloads
68 // because of the way that this rewrites the unit of a, potentially already loaded, texture list this isn't very useful outside of the context of Trace
69 fun fromDirectory(unit: Int, fn: String, maxNum: Int = -1, loadEvery: Int = 1): TextureArray? {
70
71 val uu = dirCache.computeIfAbsent(fn + " " + maxNum) {
72 var jj = File(fn).listFiles(FilenameFilter { dir, name ->
73 name.endsWith(".jpg") && !name.startsWith(".")
74 }) ?: return@computeIfAbsent null

Callers 2

fromDirectoryMethod · 0.85
fromFileMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected