Skip to content

Commit

Permalink
v0.8.3.0 build 13
Browse files Browse the repository at this point in the history
  • Loading branch information
elect86 committed Dec 11, 2019
1 parent 0ea3295 commit 57d313a
Show file tree
Hide file tree
Showing 29 changed files with 134 additions and 134 deletions.
14 changes: 7 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ plugins {
id 'maven'
id 'java'
id 'java-library'
id "org.jetbrains.kotlin.jvm" version "1.3.50"
id "com.github.johnrengelman.shadow" version '5.1.0'
id "org.jetbrains.kotlin.jvm" version "1.3.61"
id "com.github.johnrengelman.shadow" version '5.2.0'
}

// jitpack
Expand All @@ -14,11 +14,11 @@ group = 'com.github.kotlin-graphics'
ext {
moduleName = 'com.github.kotlin_graphics.gli'
kotlin = 'org.jetbrains.kotlin:kotlin'
kotlin_version = '1.3.50'
kotlintest_version = '3.4.0'
glm_version = 'a484ec1181813912c5a69d3a6706a994ca138eff'
unsigned_version = 'c81c2e39fb9e10403650c1b371b8573fc745bfb4'
kool_version = '0ef9ad97d0c709de3cda4d7f05e74bff883b00a6'
kotlin_version = '1.3.61'
kotlintest_version = '3.4.2'
glm_version = '1b4ac18dd1a3c23440d3f33596688aac60bc0141'
unsigned_version = '18131d0fe0b7465a145a4502d31452c5ae0e59a1'
kool_version = 'fcf04b2c03b8949d9d9a8b0a580082e927903510'
lwjgl_version = "3.2.3"
lwjgl_natives = current() == WINDOWS ? "windows" : current() == LINUX ? "linux" : "macos"
}
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.0.1-all.zip
8 changes: 4 additions & 4 deletions src/main/kotlin/gli_/Texture.kt
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ open class Texture {
val formatSwizzle = format.formatInfo.swizzles
return with(field) {
Swizzles(
if (r.isChannel()) formatSwizzle[r.i] else r,
if (g.isChannel()) formatSwizzle[g.i] else g,
if (b.isChannel()) formatSwizzle[b.i] else b,
if (a.isChannel()) formatSwizzle[a.i] else a)
if (r.isChannel) formatSwizzle[r.i] else r,
if (g.isChannel) formatSwizzle[g.i] else g,
if (b.isChannel) formatSwizzle[b.i] else b,
if (a.isChannel) formatSwizzle[a.i] else a)
}
}
private set
Expand Down
14 changes: 6 additions & 8 deletions src/main/kotlin/gli_/detail.kt
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,8 @@ object detail {

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

internal val tableF by lazy {

val table = arrayOf(
internal val tableFormatInfos: Array<FormatInfo> by lazy {
arrayOf(
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,
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,
FormatInfo(2, Vec3i(1, 1, 1), 4, Swizzles(BLUE, GREEN, RED, ALPHA), PACKED16_BIT or NORMALIZED_BIT or UNSIGNED_BIT), //FORMAT_BGRA4_UNORM,
Expand Down Expand Up @@ -296,17 +295,16 @@ object detail {

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,
)

assert(table.size == FORMAT_COUNT, { "GLI error: format descriptor list doesn't match number of supported formats" })

table
.apply {
assert(size == Format.COUNT) { "GLI error: format descriptor list doesn't match number of supported formats" }
}
}

internal val tableS by lazy {

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

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

table
}
Expand Down
43 changes: 19 additions & 24 deletions src/main/kotlin/gli_/dx.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import glm_.i
import glm_.vec4.Vec4i
import gli_.detail.has
import gli_.detail.hasnt
import gli_.get

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

fun translate(format: gli_.Format): dx.Format {
assert(format.i in FORMAT_FIRST.i..FORMAT_LAST.i)
return table[format.i - FORMAT_FIRST.i]
assert(format.isValid)
return table[format]
}

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

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

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

var result = FORMAT_INVALID

for (currentFormat in FORMAT_FIRST..FORMAT_LAST) {
for (currentFormat in gli_.Format.FIRST..gli_.Format.LAST) {

val info = currentFormat.formatInfo

val dxFormat = table[currentFormat.i - FORMAT_FIRST.i]
val dxFormat = table[currentFormat]

if (fourCC == GLI1 && info.flags has detail.Cap.DDS_GLI_EXT_BIT && dxFormat.dxgiFormat.gli == format.gli) {
result = currentFormat.i
break
}
if (fourCC == GLI1 && info.flags has detail.Cap.DDS_GLI_EXT_BIT && dxFormat.dxgiFormat.gli == format.gli)
return currentFormat

if (fourCC == DX10 && info.flags hasnt detail.Cap.DDS_GLI_EXT_BIT && dxFormat.dxgiFormat.dds == format.dds) {
result = currentFormat.i
break
}
if (fourCC == DX10 && info.flags hasnt detail.Cap.DDS_GLI_EXT_BIT && dxFormat.dxgiFormat.dds == format.dds)
return currentFormat
}
return gli_.Format.of(result)
return gli_.Format.UNDEFINED
}

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

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

Format(FOURCC, GLI1, R3G3B2_UNORM_GLI, Vec4i(0x70, 0x38, 0xC0, 0x00)) //FORMAT_RG3B2_UNORM,
)

assert(table.size == FORMAT_COUNT, { "GLI error: format descriptor list doesn't match number of supported formats" })

table
).apply {
assert(size == gli_.Format.COUNT) { "GLI error: format descriptor list doesn't match number of supported formats" }
}
}
}
44 changes: 24 additions & 20 deletions src/main/kotlin/gli_/format.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package gli_

import gli_.detail.Cap.*
import gli_.detail.has
import gli_.detail.tableF
import gli_.detail.tableFormatInfos
import java.nio.ByteBuffer
import java.nio.IntBuffer

Expand Down Expand Up @@ -256,15 +256,21 @@ enum class Format {

RG3B2_UNORM_PACK8;

val i = ordinal // INVALID -> -1
val i = ordinal

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

val isValid get() = this in FORMAT_FIRST..FORMAT_LAST
val isValid: Boolean
get() = this != UNDEFINED

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

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

Expand Down Expand Up @@ -315,8 +321,11 @@ enum class Format {
override fun hasNext() = next < endInclusive
}

override fun contains(value: Format) = value.i in start.i..endInclusive.i
override fun contains(value: Format): Boolean =
value.i in start.i..endInclusive.i
}

operator fun minus(format: Format): Int = i - format.i
}


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

companion object {
infix fun of(i: Int) = values().first { it.i == i }
val FIRST = RED
val LAST = ONE
val CHANNEL_FIRST = RED
val CHANNEL_LAST = ALPHA
val COUNT = LAST.i - FIRST.i + 1
infix fun of(i: Int): Swizzle = values().first { it.i == i }
}

fun isChannel() = this in SWIZZLE_CHANNEL_FIRST..SWIZZLE_CHANNEL_LAST
val isChannel: Boolean
get () = this in CHANNEL_FIRST..CHANNEL_LAST
}

val FORMAT_FIRST = Format.RG4_UNORM_PACK8
val FORMAT_LAST = Format.RG3B2_UNORM_PACK8
val FORMAT_INVALID = -1
val FORMAT_COUNT = FORMAT_LAST.i - FORMAT_FIRST.i + 1

val SWIZZLE_FIRST = Swizzle.RED
val SWIZZLE_LAST = Swizzle.ONE
val SWIZZLE_CHANNEL_FIRST = Swizzle.RED
val SWIZZLE_CHANNEL_LAST = Swizzle.ALPHA
val SWIZZLE_COUNT = SWIZZLE_LAST.i - SWIZZLE_FIRST.i + 1

data class Swizzles(var r: Swizzle, var g: Swizzle, var b: Swizzle, var a: Swizzle) {
constructor(x: Int, y: Int, z: Int, w: Int) : this(Swizzle.of(x), Swizzle.of(y), Swizzle.of(z), Swizzle.of(w))
constructor(x: Int, y: Int, z: Int, w: Int) : this(Swizzle of x, Swizzle of y, Swizzle of z, Swizzle of w)
constructor(swizzle: Swizzle) : this(swizzle, swizzle, swizzle, swizzle)
constructor(swizzles: Swizzles) : this(swizzles.r, swizzles.g, swizzles.b, swizzles.a)
constructor() : this(Swizzle.RED, Swizzle.GREEN, Swizzle.BLUE, Swizzle.ALPHA)
Expand Down
53 changes: 27 additions & 26 deletions src/main/kotlin/gli_/gl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ object gl {
updateTable()
}

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

fun translate(target: gli_.Target) = tableT[target.i]
fun translate(target: gli_.Target): Target = tableTargets[target.i]

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

assert(format in FORMAT_FIRST..FORMAT_LAST)
assert(format.isValid)

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

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

private val tableT by lazy {
val table = arrayOf(
gl.Target._1D,
gl.Target._1D_ARRAY,
gl.Target._2D,
gl.Target._2D_ARRAY,
gl.Target._3D,
gl.Target.RECT,
gl.Target.RECT_ARRAY,
gl.Target.CUBE,
gl.Target.CUBE_ARRAY)

assert(table.size == TARGET_COUNT, { "GLI error: target descriptor list doesn't match number of supported targets" })

table
private val tableTargets: Array<Target> by lazy {
arrayOf(
Target._1D,
Target._1D_ARRAY,
Target._2D,
Target._2D_ARRAY,
Target._3D,
Target.RECT,
Target.RECT_ARRAY,
Target.CUBE,
Target.CUBE_ARRAY)
.apply {
assert(size == gli_.Target.COUNT) { "GLI error: target descriptor list doesn't match number of supported targets" }
}
}

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

infix fun to(buffer: ByteBuffer):ByteBuffer = buffer.putInt(0, r.i).putInt(1, g.i).putInt(2, b.i).putInt(3, a.i)
infix fun to(buffer: ByteBuffer): ByteBuffer = buffer.putInt(0, r.i).putInt(1, g.i).putInt(2, b.i).putInt(3, a.i)
infix fun to(intBuffer: IntBuffer): IntBuffer = intBuffer.put(0, r.i).put(1, g.i).put(2, b.i).put(3, a.i)
}

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

private lateinit var tableF: Array<FormatDesc>
private lateinit var tableFormatDesc: Array<FormatDesc>

fun updateTable() {

Expand Down Expand Up @@ -462,7 +463,7 @@ object gl {

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

tableF = arrayOf(
tableFormatDesc = arrayOf(
FormatDesc(RG4_EXT, RG, UINT8_RG4_REV_GTC, 0), //FORMAT_R4G4_UNORM,
FormatDesc(RGBA4, RGBA, UINT16_RGBA4_REV, 0), //FORMAT_RGBA4_UNORM,
FormatDesc(RGBA4, RGBA, UINT16_RGBA4, FORMAT_PROPERTY_BGRA_TYPE_BIT), //FORMAT_BGRA4_UNORM,
Expand Down Expand Up @@ -704,6 +705,6 @@ object gl {

FormatDesc(RG3B2, RGB, UINT8_RG3B2_REV, 0) //FORMAT_RG3B2_UNORM,
)
.apply { assert(size == FORMAT_COUNT, { "GLI error: format descriptor list doesn't match number of supported formats" }) }
.apply { assert(size == gli_.Format.COUNT) { "GLI error: format descriptor list doesn't match number of supported formats" } }
}
}
12 changes: 7 additions & 5 deletions src/main/kotlin/gli_/gli.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@ object gli :
LINEAR;

val i = ordinal - 1
}

val FILTER_FIRST = Filter.NEAREST
val FILTER_LAST = Filter.LINEAR
val FILTER_COUNT = FILTER_LAST.i - FILTER_FIRST.i + 1
companion object {
val FIRST = NEAREST
val LAST = LINEAR
val COUNT = LAST.i - FIRST.i + 1
}
}
}


Expand All @@ -54,5 +56,5 @@ const val GLI_VERSION_MAJOR = 0
const val GLI_VERSION_MINOR = 8
const val GLI_VERSION_PATCH = 3
const val GLI_VERSION_REVISION = 0
const val GLI_VERSION_BUILD = 12
const val GLI_VERSION_BUILD = 13
const val GLI_VERSION = GLI_VERSION_MAJOR * 1_000 + GLI_VERSION_MINOR * 100 + GLI_VERSION_PATCH * 10 + GLI_VERSION_REVISION + GLI_VERSION_BUILD / 10f
2 changes: 1 addition & 1 deletion src/main/kotlin/gli_/loadKtx.kt
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ interface loadKtx {
gl.InternalFormat.of(header.glInternalFormat),
gl.ExternalFormat.of(header.glFormat),
gl.TypeFormat.of(header.glType))
assert(format != Format.UNDEFINED)
assert(format.isValid)

val blockSize = format.blockSize

Expand Down
5 changes: 4 additions & 1 deletion src/main/kotlin/gli_/misc.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,7 @@ fun flipY(buffer: ByteArray, width: Int, height: Int) : ByteBuffer {
result.pos = 0

return result
}
}

operator fun Array<dx.Format>.get(index: Format): dx.Format =
get(index.i - Format.FIRST.i)
Loading

0 comments on commit 57d313a

Please sign in to comment.