Skip to content

Commit 6625958

Browse files
committed
🚧 Added GTX_texture
g-truc/glm@5cf8765
1 parent c6fb6db commit 6625958

29 files changed

+199
-118
lines changed

src/main/kotlin/glm_/func/common/func_common.kt

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import kotlin.math.absoluteValue
2121
import kotlin.math.sign
2222
import kotlin.math.ceil as _ceil
2323
import kotlin.math.floor as _floor
24+
import kotlin.math.max as _max
25+
import kotlin.math.min as _min
2426
import kotlin.math.round as _round
2527

2628

@@ -76,19 +78,19 @@ interface func_common {
7678
// TODO modf
7779

7880

79-
fun min(a: Float, b: Float) = if(b < a) b else a
80-
fun min(a: Double, b: Double) = if(b < a) b else a
81-
fun min(a: Byte, b: Byte) = if(b < a) b else a
82-
fun min(a: Int, b: Int) = if(b < a) b else a
83-
fun min(a: Long, b: Long) = if(b < a) b else a
84-
fun min(a: Short, b: Short) = if(b < a) b else a
81+
fun min(a: Float, b: Float) = _min(a, b)
82+
fun min(a: Double, b: Double) = _min(a, b)
83+
fun min(a: Byte, b: Byte) = _min(a.i, b.i).b
84+
fun min(a: Int, b: Int) = _min(a, b)
85+
fun min(a: Long, b: Long) = _min(a, b)
86+
fun min(a: Short, b: Short) = _min(a.i, b.i).s
8587

86-
fun max(a: Float, b: Float) = if(a < b) b else a
87-
fun max(a: Double, b: Double) = if(a < b) b else a
88-
fun max(a: Byte, b: Byte) = if(a < b) b else a
89-
fun max(a: Int, b: Int) = if(a < b) b else a
90-
fun max(a: Long, b: Long) = if(a < b) b else a
91-
fun max(a: Short, b: Short) = if(a < b) b else a
88+
fun max(a: Float, b: Float) = _max(a, b)
89+
fun max(a: Double, b: Double) = _max(a, b)
90+
fun max(a: Byte, b: Byte) = _max(a.i, b.i).b
91+
fun max(a: Int, b: Int) = _max(a, b)
92+
fun max(a: Long, b: Long) = _max(a, b)
93+
fun max(a: Short, b: Short) = _max(a.i, b.i).s
9294

9395

9496
fun clamp(a: Float, min: Float, max: Float) = min(max(a, min), max)

src/main/kotlin/glm_/glm.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ object glm :
7070
gtxQuaternion,
7171
gtxMatrixDecompose,
7272
gtxInteger,
73-
gtxFastTrigonometry {
73+
gtxFastTrigonometry,
74+
gtxTexture {
7475

7576
@JvmField
7677
val detail = Detail
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package glm_.gtx
2+
3+
import glm_.glm
4+
import glm_.glm.compMax
5+
import glm_.vec1.Vec1i
6+
import glm_.vec2.Vec2i
7+
import glm_.vec3.Vec3i
8+
9+
interface gtxTexture {
10+
11+
fun levels(extent: Vec1i) = glm.log2(compMax(extent)) + 1
12+
fun levels(extent: Vec2i) = glm.log2(compMax(extent)) + 1
13+
fun levels(extent: Vec3i) = glm.log2(compMax(extent)) + 1
14+
15+
fun levels(extent: Int) = Vec1i(extent).x
16+
}

src/main/kotlin/glm_/quat/Quat.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@ class Quat(w: Float, x: Float, y: Float, z: Float) : QuatT<Float>(w, x, y, z) {
3232
var realPart = normUnormV + (u dot v)
3333
val w: Vec3
3434

35-
if (realPart < 1e-6f * normUnormV) {
35+
w = if (realPart < 1e-6f * normUnormV) {
3636
/* If u and v are exactly opposite, rotate 180 degrees around an arbitrary orthogonal axis.
3737
Axis normalisation can happen later, when we normalise the quaternion. */
3838
realPart = 0f
39-
w = if (abs(u.x) > abs(u.z)) Vec3(-u.y, u.x, 0f) else Vec3(0f, -u.z, u.y)
39+
if (abs(u.x) > abs(u.z)) Vec3(-u.y, u.x, 0f) else Vec3(0f, -u.z, u.y)
4040
} else // Otherwise, build quaternion the standard way.
41-
w = u cross v
41+
u cross v
4242

4343
put(Quat(realPart, w.x, w.y, w.z).normalizeAssign())
4444
}

src/test/kotlin/glm_/coreMat4.kt

Lines changed: 0 additions & 73 deletions
This file was deleted.

src/test/kotlin/glm_/gtxExteriorProduct.kt renamed to src/test/kotlin/glm_/gtx/testGtxExteriorProduct.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
package glm_
1+
package glm_.gtx
22

3+
import glm_.glm
34
import glm_.vec2.Vec2
45
import io.kotlintest.matchers.shouldBe
56
import io.kotlintest.specs.StringSpec
67

7-
class gtxExteriorProduct : StringSpec() {
8+
class testGtxExteriorProduct : StringSpec() {
89

910
init {
1011
"cross" {

src/test/kotlin/glm_/gtxFastTrigonometry.kt renamed to src/test/kotlin/glm_/gtx/testGtxFastTrigonometry.kt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
package glm_
1+
package glm_.gtx
22

33
import glm_.func.rad
4+
import glm_.glm
45
import glm_.glm.HPIf
56
import glm_.glm.PI2f
67
import glm_.glm.PIf
@@ -21,7 +22,7 @@ import io.kotlintest.matchers.shouldBe
2122
import io.kotlintest.specs.StringSpec
2223
import kotlin.system.measureNanoTime
2324

24-
class gtxFastTrigonometry : StringSpec() {
25+
class testGtxFastTrigonometry : StringSpec() {
2526

2627
init {
2728

@@ -204,7 +205,7 @@ object taylorCos {
204205

205206
val time = measureNanoTime {
206207
for(i in 0 until samples)
207-
results[i] = taylorCos.fastCosDeterminisctic(angleShift + Vec4(begin + steps * i))
208+
results[i] = fastCosDeterminisctic(angleShift + Vec4(begin + steps * i))
208209
}
209210

210211
println("fastCosDeterminisctic $time ns")
@@ -261,7 +262,7 @@ object taylorCos {
261262

262263
val time = measureNanoTime {
263264
for (i in 0 until samples)
264-
results[i] = taylorCos.fastRefCos(angleShift + Vec4(begin + steps * i))
265+
results[i] = fastRefCos(angleShift + Vec4(begin + steps * i))
265266
}
266267

267268
println("fastCosRef $time ns")
@@ -327,7 +328,7 @@ object taylorCos {
327328
val radAngle = modAngle.rad
328329
val cos0 = cos(radAngle)
329330

330-
val cos1 = taylorCos.fastRefCos(Vec1(radAngle)).x
331+
val cos1 = fastRefCos(Vec1(radAngle)).x
331332
(glm.abs(cos1 - cos0) < 0.1f) shouldBe true
332333

333334
//float const Cos2 = taylorCos::fastCosNew(glm::fvec1(radAngle)).x;

src/test/kotlin/glm_/gtxInteger.kt renamed to src/test/kotlin/glm_/gtx/testGtxInteger.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1-
package glm_
1+
package glm_.gtx
22

3+
import glm_.d
4+
import glm_.glm
5+
import glm_.i
6+
import glm_.msb
37
import io.kotlintest.matchers.shouldBe
48
import io.kotlintest.specs.StringSpec
59

6-
class gtxInteger : StringSpec() {
10+
class testGtxInteger : StringSpec() {
711

812
init {
913
"nlz" {

src/test/kotlin/glm_/gtx_intersect.kt renamed to src/test/kotlin/glm_/gtx/testGtxIntersect.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
package glm_
1+
package glm_.gtx
22

3+
import glm_.glm
34
import glm_.glm.epsilonF
45
import glm_.vec2.Vec2
56
import glm_.vec3.Vec3
67
import io.kotlintest.matchers.shouldBe
78
import io.kotlintest.specs.StringSpec
89

9-
class gtx_intersect : StringSpec() {
10+
class testGtxIntersect : StringSpec() {
1011

1112
init {
1213

src/test/kotlin/glm_/gtxMatrixDecompose.kt renamed to src/test/kotlin/glm_/gtx/testGtxMatrixDecompose.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
package glm_
1+
package glm_.gtx
22

3+
import glm_.glm
34
import glm_.mat4x4.Mat4
45
import glm_.quat.Quat
56
import glm_.vec3.Vec3
67
import glm_.vec4.Vec4
78
import io.kotlintest.specs.StringSpec
89

9-
class gtxMatrixDecompose : StringSpec() {
10+
class testGtxMatrixDecompose : StringSpec() {
1011

1112
init {
1213

0 commit comments

Comments
 (0)