Skip to content

Commit 57d313a

Browse files
committed
v0.8.3.0 build 13
1 parent 0ea3295 commit 57d313a

29 files changed

+134
-134
lines changed

build.gradle

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ plugins {
44
id 'maven'
55
id 'java'
66
id 'java-library'
7-
id "org.jetbrains.kotlin.jvm" version "1.3.50"
8-
id "com.github.johnrengelman.shadow" version '5.1.0'
7+
id "org.jetbrains.kotlin.jvm" version "1.3.61"
8+
id "com.github.johnrengelman.shadow" version '5.2.0'
99
}
1010

1111
// jitpack
@@ -14,11 +14,11 @@ group = 'com.github.kotlin-graphics'
1414
ext {
1515
moduleName = 'com.github.kotlin_graphics.gli'
1616
kotlin = 'org.jetbrains.kotlin:kotlin'
17-
kotlin_version = '1.3.50'
18-
kotlintest_version = '3.4.0'
19-
glm_version = 'a484ec1181813912c5a69d3a6706a994ca138eff'
20-
unsigned_version = 'c81c2e39fb9e10403650c1b371b8573fc745bfb4'
21-
kool_version = '0ef9ad97d0c709de3cda4d7f05e74bff883b00a6'
17+
kotlin_version = '1.3.61'
18+
kotlintest_version = '3.4.2'
19+
glm_version = '1b4ac18dd1a3c23440d3f33596688aac60bc0141'
20+
unsigned_version = '18131d0fe0b7465a145a4502d31452c5ae0e59a1'
21+
kool_version = 'fcf04b2c03b8949d9d9a8b0a580082e927903510'
2222
lwjgl_version = "3.2.3"
2323
lwjgl_natives = current() == WINDOWS ? "windows" : current() == LINUX ? "linux" : "macos"
2424
}

gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.1-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-6.0.1-all.zip

src/main/kotlin/gli_/Texture.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ open class Texture {
4747
val formatSwizzle = format.formatInfo.swizzles
4848
return with(field) {
4949
Swizzles(
50-
if (r.isChannel()) formatSwizzle[r.i] else r,
51-
if (g.isChannel()) formatSwizzle[g.i] else g,
52-
if (b.isChannel()) formatSwizzle[b.i] else b,
53-
if (a.isChannel()) formatSwizzle[a.i] else a)
50+
if (r.isChannel) formatSwizzle[r.i] else r,
51+
if (g.isChannel) formatSwizzle[g.i] else g,
52+
if (b.isChannel) formatSwizzle[b.i] else b,
53+
if (a.isChannel) formatSwizzle[a.i] else a)
5454
}
5555
}
5656
private set

src/main/kotlin/gli_/detail.kt

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,8 @@ object detail {
5252

5353
class FormatInfo(val blockSize: Int, val blockExtend: Vec3i, val component: Int, val swizzles: Swizzles, val flags: Int)
5454

55-
internal val tableF by lazy {
56-
57-
val table = arrayOf(
55+
internal val tableFormatInfos: Array<FormatInfo> by lazy {
56+
arrayOf(
5857
FormatInfo(1, Vec3i(1, 1, 1), 2, Swizzles(RED, GREEN, ZERO, ONE), PACKED8_BIT or NORMALIZED_BIT or UNSIGNED_BIT or DDS_GLI_EXT_BIT), //FORMAT_R4G4_UNORM,
5958
FormatInfo(2, Vec3i(1, 1, 1), 4, Swizzles(RED, GREEN, BLUE, ALPHA), PACKED16_BIT or NORMALIZED_BIT or UNSIGNED_BIT or DDS_GLI_EXT_BIT), //FORMAT_RGBA4_UNORM,
6059
FormatInfo(2, Vec3i(1, 1, 1), 4, Swizzles(BLUE, GREEN, RED, ALPHA), PACKED16_BIT or NORMALIZED_BIT or UNSIGNED_BIT), //FORMAT_BGRA4_UNORM,
@@ -296,17 +295,16 @@ object detail {
296295

297296
FormatInfo(1, Vec3i(1, 1, 1), 3, Swizzles(RED, GREEN, BLUE, ONE), PACKED8_BIT or NORMALIZED_BIT or UNSIGNED_BIT or DDS_GLI_EXT_BIT) //FORMAT_RG3B2_UNORM_PACK8,
298297
)
299-
300-
assert(table.size == FORMAT_COUNT, { "GLI error: format descriptor list doesn't match number of supported formats" })
301-
302-
table
298+
.apply {
299+
assert(size == Format.COUNT) { "GLI error: format descriptor list doesn't match number of supported formats" }
300+
}
303301
}
304302

305303
internal val tableS by lazy {
306304

307305
val table = arrayOf(gl.Swizzle.RED, gl.Swizzle.GREEN, gl.Swizzle.BLUE, gl.Swizzle.ALPHA, gl.Swizzle.ZERO, gl.Swizzle.ONE)
308306

309-
assert(table.size == SWIZZLE_COUNT, { "GLI error: swizzle descriptor list doesn't match number of supported swizzles" })
307+
assert(table.size == Swizzle.COUNT) { "GLI error: swizzle descriptor list doesn't match number of supported swizzles" }
310308

311309
table
312310
}

src/main/kotlin/gli_/dx.kt

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import glm_.i
88
import glm_.vec4.Vec4i
99
import gli_.detail.has
1010
import gli_.detail.hasnt
11+
import gli_.get
1112

1213
/**
1314
* Created by elect on 02/04/17.
@@ -17,36 +18,32 @@ import gli_.detail.hasnt
1718
object dx {
1819

1920
fun translate(format: gli_.Format): dx.Format {
20-
assert(format.i in FORMAT_FIRST.i..FORMAT_LAST.i)
21-
return table[format.i - FORMAT_FIRST.i]
21+
assert(format.isValid)
22+
return table[format]
2223
}
2324

24-
fun find(fourCC: D3dfmt) = gli_.Format.of((FORMAT_FIRST.i..FORMAT_LAST.i)
25-
.firstOrNull { table[it - FORMAT_FIRST.i].d3DFormat == fourCC } ?: FORMAT_INVALID)
25+
fun find(fourCC: D3dfmt): gli_.Format =
26+
(gli_.Format.FIRST..gli_.Format.LAST)
27+
.firstOrNull { table[it].d3DFormat == fourCC }
28+
?: gli_.Format.UNDEFINED
2629

2730
fun find(fourCC: D3dfmt, format: DxgiFormat): gli_.Format {
2831

2932
assert(fourCC == DX10 || fourCC == GLI1)
3033

31-
var result = FORMAT_INVALID
32-
33-
for (currentFormat in FORMAT_FIRST..FORMAT_LAST) {
34+
for (currentFormat in gli_.Format.FIRST..gli_.Format.LAST) {
3435

3536
val info = currentFormat.formatInfo
3637

37-
val dxFormat = table[currentFormat.i - FORMAT_FIRST.i]
38+
val dxFormat = table[currentFormat]
3839

39-
if (fourCC == GLI1 && info.flags has detail.Cap.DDS_GLI_EXT_BIT && dxFormat.dxgiFormat.gli == format.gli) {
40-
result = currentFormat.i
41-
break
42-
}
40+
if (fourCC == GLI1 && info.flags has detail.Cap.DDS_GLI_EXT_BIT && dxFormat.dxgiFormat.gli == format.gli)
41+
return currentFormat
4342

44-
if (fourCC == DX10 && info.flags hasnt detail.Cap.DDS_GLI_EXT_BIT && dxFormat.dxgiFormat.dds == format.dds) {
45-
result = currentFormat.i
46-
break
47-
}
43+
if (fourCC == DX10 && info.flags hasnt detail.Cap.DDS_GLI_EXT_BIT && dxFormat.dxgiFormat.dds == format.dds)
44+
return currentFormat
4845
}
49-
return gli_.Format.of(result)
46+
return gli_.Format.UNDEFINED
5047
}
5148

5249
fun isDdsExt(target: Target, format: gli_.Format): Boolean {
@@ -519,8 +516,8 @@ object dx {
519516
: this(ddPixelFormat, d3DFormat, DxgiFormat(dxgiFormatGLI), mask)
520517
}
521518

522-
private val table by lazy {
523-
val table = arrayOf(
519+
private val table: Array<Format> by lazy {
520+
arrayOf(
524521
Format(FOURCC, GLI1, RG4_UNORM_GLI, Vec4i(0x000F, 0x00F0, 0x0000, 0x0000)), //FORMAT_RG4_UNORM,
525522
Format(FOURCC, GLI1, RGBA4_UNORM_GLI, Vec4i(0x000F, 0x00F0, 0x0F00, 0xF000)), //FORMAT_RGBA4_UNORM,
526523
Format(FOURCC, A4R4G4B4, B4G4R4A4_UNORM, Vec4i(0x0F00, 0x00F0, 0x000F, 0xF000)), //FORMAT_BGRA4_UNORM,
@@ -761,10 +758,8 @@ object dx {
761758
Format(FOURCC, DX10, B8G8R8X8_UNORM_SRGB, Vec4i(0x00FF0000, 0x0000FF00, 0x000000FF, 0x00000000)), //FORMAT_BGR8_SRGB_PACK32,
762759

763760
Format(FOURCC, GLI1, R3G3B2_UNORM_GLI, Vec4i(0x70, 0x38, 0xC0, 0x00)) //FORMAT_RG3B2_UNORM,
764-
)
765-
766-
assert(table.size == FORMAT_COUNT, { "GLI error: format descriptor list doesn't match number of supported formats" })
767-
768-
table
761+
).apply {
762+
assert(size == gli_.Format.COUNT) { "GLI error: format descriptor list doesn't match number of supported formats" }
763+
}
769764
}
770765
}

src/main/kotlin/gli_/format.kt

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package gli_
22

33
import gli_.detail.Cap.*
44
import gli_.detail.has
5-
import gli_.detail.tableF
5+
import gli_.detail.tableFormatInfos
66
import java.nio.ByteBuffer
77
import java.nio.IntBuffer
88

@@ -256,15 +256,21 @@ enum class Format {
256256

257257
RG3B2_UNORM_PACK8;
258258

259-
val i = ordinal // INVALID -> -1
259+
val i = ordinal
260260

261261
companion object {
262-
infix fun of(i: Int) = values().find { it.i == i } ?: UNDEFINED
262+
val FIRST: Format = RG4_UNORM_PACK8
263+
val LAST: Format = RG3B2_UNORM_PACK8
264+
val COUNT = LAST.i - FIRST.i + 1
265+
infix fun of(i: Int): Format = values().find { it.i == i } ?: UNDEFINED
263266
}
264267

265-
val isValid get() = this in FORMAT_FIRST..FORMAT_LAST
268+
val isValid: Boolean
269+
get() = this != UNDEFINED
266270

267-
val formatInfo by lazy { tableF[i - FORMAT_FIRST.i] }
271+
/** *get_format_info */
272+
val formatInfo: detail.FormatInfo
273+
get() = tableFormatInfos[i - FIRST.i].also { assert(isValid) }
268274

269275
val bitsPerPixel by lazy { formatInfo.blockSize * 8 / (formatInfo.blockExtend.x * formatInfo.blockExtend.y * formatInfo.blockExtend.z) }
270276

@@ -315,8 +321,11 @@ enum class Format {
315321
override fun hasNext() = next < endInclusive
316322
}
317323

318-
override fun contains(value: Format) = value.i in start.i..endInclusive.i
324+
override fun contains(value: Format): Boolean =
325+
value.i in start.i..endInclusive.i
319326
}
327+
328+
operator fun minus(format: Format): Int = i - format.i
320329
}
321330

322331

@@ -332,25 +341,20 @@ enum class Swizzle {
332341
val i = ordinal
333342

334343
companion object {
335-
infix fun of(i: Int) = values().first { it.i == i }
344+
val FIRST = RED
345+
val LAST = ONE
346+
val CHANNEL_FIRST = RED
347+
val CHANNEL_LAST = ALPHA
348+
val COUNT = LAST.i - FIRST.i + 1
349+
infix fun of(i: Int): Swizzle = values().first { it.i == i }
336350
}
337351

338-
fun isChannel() = this in SWIZZLE_CHANNEL_FIRST..SWIZZLE_CHANNEL_LAST
352+
val isChannel: Boolean
353+
get () = this in CHANNEL_FIRST..CHANNEL_LAST
339354
}
340355

341-
val FORMAT_FIRST = Format.RG4_UNORM_PACK8
342-
val FORMAT_LAST = Format.RG3B2_UNORM_PACK8
343-
val FORMAT_INVALID = -1
344-
val FORMAT_COUNT = FORMAT_LAST.i - FORMAT_FIRST.i + 1
345-
346-
val SWIZZLE_FIRST = Swizzle.RED
347-
val SWIZZLE_LAST = Swizzle.ONE
348-
val SWIZZLE_CHANNEL_FIRST = Swizzle.RED
349-
val SWIZZLE_CHANNEL_LAST = Swizzle.ALPHA
350-
val SWIZZLE_COUNT = SWIZZLE_LAST.i - SWIZZLE_FIRST.i + 1
351-
352356
data class Swizzles(var r: Swizzle, var g: Swizzle, var b: Swizzle, var a: Swizzle) {
353-
constructor(x: Int, y: Int, z: Int, w: Int) : this(Swizzle.of(x), Swizzle.of(y), Swizzle.of(z), Swizzle.of(w))
357+
constructor(x: Int, y: Int, z: Int, w: Int) : this(Swizzle of x, Swizzle of y, Swizzle of z, Swizzle of w)
354358
constructor(swizzle: Swizzle) : this(swizzle, swizzle, swizzle, swizzle)
355359
constructor(swizzles: Swizzles) : this(swizzles.r, swizzles.g, swizzles.b, swizzles.a)
356360
constructor() : this(Swizzle.RED, Swizzle.GREEN, Swizzle.BLUE, Swizzle.ALPHA)

src/main/kotlin/gli_/gl.kt

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@ object gl {
2727
updateTable()
2828
}
2929

30-
fun translate(texture: Texture) = translate(texture.target) to translate(texture.format, texture.swizzles)
30+
fun translate(texture: Texture): Pair<Target, Format> = translate(texture.target) to translate(texture.format, texture.swizzles)
3131

32-
fun translate(target: gli_.Target) = tableT[target.i]
32+
fun translate(target: gli_.Target): Target = tableTargets[target.i]
3333

3434
fun translate(format: gli_.Format, swizzles: gli_.Swizzles): Format {
3535

36-
assert(format in FORMAT_FIRST..FORMAT_LAST)
36+
assert(format.isValid)
3737

38-
val formatDesc = tableF[format.i - FORMAT_FIRST.i]
38+
val formatDesc = tableFormatDesc[format - gli_.Format.FIRST]
3939

4040
return Format(formatDesc.internal, formatDesc.external, formatDesc.type, computeSwizzle(formatDesc, swizzles))
4141
}
@@ -54,26 +54,27 @@ object gl {
5454
fun find(internalFormat: InternalFormat, externalFormat: ExternalFormat, type: TypeFormat): gli_.Format {
5555
/* Important, filter internalFormat by i, because some values may be double, such as:
5656
Internal.LUMINANCE8 has same value of Internal.L8 */
57-
val format = tableF.find { it.internal.i == internalFormat.i && it.external == externalFormat && it.type == type }
58-
return if (format == null) gli_.Format.UNDEFINED
59-
else gli_.Format.of(tableF.indexOf(format) + 1) // +1 to offset UNDEFINED
57+
val format = tableFormatDesc.find { it.internal.i == internalFormat.i && it.external == externalFormat && it.type == type }
58+
return when (format) {
59+
null -> gli_.Format.UNDEFINED
60+
else -> gli_.Format.of(tableFormatDesc.indexOf(format) + gli_.Format.FIRST.i) // +FIRST to offset UNDEFINED
61+
}
6062
}
6163

62-
private val tableT by lazy {
63-
val table = arrayOf(
64-
gl.Target._1D,
65-
gl.Target._1D_ARRAY,
66-
gl.Target._2D,
67-
gl.Target._2D_ARRAY,
68-
gl.Target._3D,
69-
gl.Target.RECT,
70-
gl.Target.RECT_ARRAY,
71-
gl.Target.CUBE,
72-
gl.Target.CUBE_ARRAY)
73-
74-
assert(table.size == TARGET_COUNT, { "GLI error: target descriptor list doesn't match number of supported targets" })
75-
76-
table
64+
private val tableTargets: Array<Target> by lazy {
65+
arrayOf(
66+
Target._1D,
67+
Target._1D_ARRAY,
68+
Target._2D,
69+
Target._2D_ARRAY,
70+
Target._3D,
71+
Target.RECT,
72+
Target.RECT_ARRAY,
73+
Target.CUBE,
74+
Target.CUBE_ARRAY)
75+
.apply {
76+
assert(size == gli_.Target.COUNT) { "GLI error: target descriptor list doesn't match number of supported targets" }
77+
}
7778
}
7879

7980
private class FormatDesc(val internal: InternalFormat, val external: ExternalFormat, val type: TypeFormat, val properties: Int)
@@ -426,13 +427,13 @@ object gl {
426427
else -> throw Error()
427428
}
428429

429-
infix fun to(buffer: ByteBuffer):ByteBuffer = buffer.putInt(0, r.i).putInt(1, g.i).putInt(2, b.i).putInt(3, a.i)
430+
infix fun to(buffer: ByteBuffer): ByteBuffer = buffer.putInt(0, r.i).putInt(1, g.i).putInt(2, b.i).putInt(3, a.i)
430431
infix fun to(intBuffer: IntBuffer): IntBuffer = intBuffer.put(0, r.i).put(1, g.i).put(2, b.i).put(3, a.i)
431432
}
432433

433434
class Format(val internal: InternalFormat, val external: ExternalFormat, val type: TypeFormat, val swizzles: Swizzles)
434435

435-
private lateinit var tableF: Array<FormatDesc>
436+
private lateinit var tableFormatDesc: Array<FormatDesc>
436437

437438
fun updateTable() {
438439

@@ -462,7 +463,7 @@ object gl {
462463

463464
val typeF16 = if (profile == Profile.ES20) TypeFormat.F16_OES else TypeFormat.F16
464465

465-
tableF = arrayOf(
466+
tableFormatDesc = arrayOf(
466467
FormatDesc(RG4_EXT, RG, UINT8_RG4_REV_GTC, 0), //FORMAT_R4G4_UNORM,
467468
FormatDesc(RGBA4, RGBA, UINT16_RGBA4_REV, 0), //FORMAT_RGBA4_UNORM,
468469
FormatDesc(RGBA4, RGBA, UINT16_RGBA4, FORMAT_PROPERTY_BGRA_TYPE_BIT), //FORMAT_BGRA4_UNORM,
@@ -704,6 +705,6 @@ object gl {
704705

705706
FormatDesc(RG3B2, RGB, UINT8_RG3B2_REV, 0) //FORMAT_RG3B2_UNORM,
706707
)
707-
.apply { assert(size == FORMAT_COUNT, { "GLI error: format descriptor list doesn't match number of supported formats" }) }
708+
.apply { assert(size == gli_.Format.COUNT) { "GLI error: format descriptor list doesn't match number of supported formats" } }
708709
}
709710
}

src/main/kotlin/gli_/gli.kt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,13 @@ object gli :
3131
LINEAR;
3232

3333
val i = ordinal - 1
34-
}
3534

36-
val FILTER_FIRST = Filter.NEAREST
37-
val FILTER_LAST = Filter.LINEAR
38-
val FILTER_COUNT = FILTER_LAST.i - FILTER_FIRST.i + 1
35+
companion object {
36+
val FIRST = NEAREST
37+
val LAST = LINEAR
38+
val COUNT = LAST.i - FIRST.i + 1
39+
}
40+
}
3941
}
4042

4143

@@ -54,5 +56,5 @@ const val GLI_VERSION_MAJOR = 0
5456
const val GLI_VERSION_MINOR = 8
5557
const val GLI_VERSION_PATCH = 3
5658
const val GLI_VERSION_REVISION = 0
57-
const val GLI_VERSION_BUILD = 12
59+
const val GLI_VERSION_BUILD = 13
5860
const val GLI_VERSION = GLI_VERSION_MAJOR * 1_000 + GLI_VERSION_MINOR * 100 + GLI_VERSION_PATCH * 10 + GLI_VERSION_REVISION + GLI_VERSION_BUILD / 10f

src/main/kotlin/gli_/loadKtx.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ interface loadKtx {
6363
gl.InternalFormat.of(header.glInternalFormat),
6464
gl.ExternalFormat.of(header.glFormat),
6565
gl.TypeFormat.of(header.glType))
66-
assert(format != Format.UNDEFINED)
66+
assert(format.isValid)
6767

6868
val blockSize = format.blockSize
6969

src/main/kotlin/gli_/misc.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,7 @@ fun flipY(buffer: ByteArray, width: Int, height: Int) : ByteBuffer {
3333
result.pos = 0
3434

3535
return result
36-
}
36+
}
37+
38+
operator fun Array<dx.Format>.get(index: Format): dx.Format =
39+
get(index.i - Format.FIRST.i)

0 commit comments

Comments
 (0)