From a9409092147f3e158cc7b73fcf01e7f7d53d5434 Mon Sep 17 00:00:00 2001 From: Giuseppe Barbieri Date: Mon, 26 Nov 2018 21:34:43 +0100 Subject: [PATCH] v0.4.6 - replaced Error by Exception - removed deprecated - Jigsaw support - kotlin 1.3.10 --- build.gradle | 13 +++++++++-- src/main/kotlin/gln/buffer/buffer.kt | 2 +- src/main/kotlin/gln/cap/caps.kt | 4 ++-- src/main/kotlin/gln/debug/debug.kt | 2 +- src/main/kotlin/gln/enums.kt | 2 +- src/main/kotlin/gln/framebuffer/block.kt | 2 +- src/main/kotlin/gln/gl11i.kt | 2 +- src/main/kotlin/gln/gl15i.kt | 4 ++-- src/main/kotlin/gln/gl20i.kt | 4 +++- src/main/kotlin/gln/gln.kt | 10 ++++---- src/main/kotlin/gln/object/buffer.kt | 3 --- src/main/kotlin/gln/object/program.kt | 3 --- src/main/kotlin/gln/object/query.kt | 6 ----- src/main/kotlin/gln/object/shader.kt | 21 ++++++++--------- src/main/kotlin/gln/object/texture.kt | 3 --- src/main/kotlin/gln/program/block.kt | 2 +- src/main/kotlin/gln/program/program.kt | 29 +++++++++--------------- src/main/kotlin/gln/uniform/uniform.kt | 4 ++-- 18 files changed, 51 insertions(+), 65 deletions(-) diff --git a/build.gradle b/build.gradle index a3a4e53..3ace074 100644 --- a/build.gradle +++ b/build.gradle @@ -9,9 +9,11 @@ group = 'com.github.kotlin-graphics' apply plugin: 'com.github.johnrengelman.shadow' +ext.moduleName = 'com.github.kotlin_graphics.gln' + buildscript { - ext.kotlinVersion = '1.3.0' + ext.kotlinVersion = '1.3.10' repositories { jcenter() // shadow @@ -33,7 +35,7 @@ dependencies { implementation "$kotlin-stdlib:$kotlinVersion" implementation "$kotlin-reflect:$kotlinVersion" - implementation 'com.github.kotlin-graphics:gli:9776ae45a3' + implementation 'com.github.kotlin-graphics:gli:332f512955594fc59b011a1b6e29a138fe3fc789' //testCompile 'io.kotlintest:kotlintest-runner-junit5:3.0.6' @@ -81,4 +83,11 @@ compileKotlin { artifacts { archives sourcesJar // archives javadocJar +} + +jar { + inputs.property("moduleName", moduleName) + manifest { + attributes('Automatic-Module-Name': moduleName) + } } \ No newline at end of file diff --git a/src/main/kotlin/gln/buffer/buffer.kt b/src/main/kotlin/gln/buffer/buffer.kt index 2867dab..a0ca0cc 100644 --- a/src/main/kotlin/gln/buffer/buffer.kt +++ b/src/main/kotlin/gln/buffer/buffer.kt @@ -115,7 +115,7 @@ sealed class BufferTarget(val i: Int) { GL_TEXTURE_BUFFER -> BufferTarget2.Texture GL_TRANSFORM_FEEDBACK_BUFFER -> BufferTarget2.Transform GL_UNIFORM_BUFFER -> BufferTarget2.Uniform - else -> throw Error() + else -> throw Exception() } } } diff --git a/src/main/kotlin/gln/cap/caps.kt b/src/main/kotlin/gln/cap/caps.kt index 97c48d7..2c644db 100644 --- a/src/main/kotlin/gln/cap/caps.kt +++ b/src/main/kotlin/gln/cap/caps.kt @@ -5,7 +5,7 @@ import glm_.vec3.Vec3i import gln.* import kool.cap import kool.free -import kool.intBufferBig +import kool.IntBuffer import org.lwjgl.opengl.ATITextureCompression3DC.GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI import org.lwjgl.opengl.EXTTextureCompressionLATC.* import org.lwjgl.opengl.EXTTextureCompressionS3TC.* @@ -1120,7 +1120,7 @@ class Caps(profile: Profile) { inner class Formats { private val compressed by lazy { - val buffer = intBufferBig(limits.NUM_COMPRESSED_TEXTURE_FORMATS) + val buffer = IntBuffer(limits.NUM_COMPRESSED_TEXTURE_FORMATS) glGetIntegerv(GL_COMPRESSED_TEXTURE_FORMATS, buffer) (0 until buffer.cap).map { buffer[it] }.also { buffer.free() diff --git a/src/main/kotlin/gln/debug/debug.kt b/src/main/kotlin/gln/debug/debug.kt index ff095c8..84d15e7 100644 --- a/src/main/kotlin/gln/debug/debug.kt +++ b/src/main/kotlin/gln/debug/debug.kt @@ -72,7 +72,7 @@ fun glDebugMessageCallback(callback: (source: GlDebugSource, type: GlDebugType, // OpenGL43 -> GL43::nglDebugMessageControl // GL_KHR_debug -> KHRDebug::nglDebugMessageControl // GL_ARB_debug_output -> ARBDebugOutput::nglDebugMessageControlARB -// else -> throw Error() +// else -> throw Exception() // // if (caps.GL_AMD_debug_output) // // AMDDebugOutput.glDebugMessageEnableAMD(GL11.GL_DONT_CARE, GL11.GL_DONT_CARE, GL43.GL_DEBUG_SEVERITY_NOTIFICATION, 0, false) // } diff --git a/src/main/kotlin/gln/enums.kt b/src/main/kotlin/gln/enums.kt index f3e9ae4..f39c4fe 100644 --- a/src/main/kotlin/gln/enums.kt +++ b/src/main/kotlin/gln/enums.kt @@ -986,7 +986,7 @@ inline class DataType(val i: Int) { GL11.GL_3_BYTES -> Vec3b.size GL11.GL_4_BYTES -> Vec4b.size GL11.GL_DOUBLE -> Double.BYTES - else -> throw Error() + else -> throw Exception() } } diff --git a/src/main/kotlin/gln/framebuffer/block.kt b/src/main/kotlin/gln/framebuffer/block.kt index b00f7ad..4c27042 100644 --- a/src/main/kotlin/gln/framebuffer/block.kt +++ b/src/main/kotlin/gln/framebuffer/block.kt @@ -127,7 +127,7 @@ fun checkFramebuffer(location: String = "", throws: Boolean = true): Boolean { else -> throw IllegalStateException() }}" if(throws) - throw Error(message) + throw Exception(message) else System.err.println(message) false diff --git a/src/main/kotlin/gln/gl11i.kt b/src/main/kotlin/gln/gl11i.kt index 2767272..71a49e2 100644 --- a/src/main/kotlin/gln/gl11i.kt +++ b/src/main/kotlin/gln/gl11i.kt @@ -530,7 +530,7 @@ interface gl11i { * * @see Reference Page */ - infix fun genTextures(count: Int): GLtextures = GLtextures(intBufferBig(count).apply { GL11C.nglGenTextures(rem, adr) }) + infix fun genTextures(count: Int): GLtextures = GLtextures(IntBuffer(count).apply { GL11C.nglGenTextures(rem, adr) }) /** * Returns n previously unused texture names in textures. These names are marked as used, for the purposes of GenTextures only, but they acquire texture diff --git a/src/main/kotlin/gln/gl15i.kt b/src/main/kotlin/gln/gl15i.kt index d8473bb..f435378 100644 --- a/src/main/kotlin/gln/gl15i.kt +++ b/src/main/kotlin/gln/gl15i.kt @@ -7,7 +7,7 @@ package gln import glm_.L import kool.adr -import kool.intBufferBig +import kool.IntBuffer import kool.rem import kool.remSize import gln.`object`.GlBuffer @@ -316,7 +316,7 @@ interface gl15i { * * @see Reference Page */ - infix fun genQueries(count: Int): GlQueries = GlQueries(intBufferBig(count).apply { GL15C.nglGenQueries(rem, adr) }) + infix fun genQueries(count: Int): GlQueries = GlQueries(IntBuffer(count).apply { GL15C.nglGenQueries(rem, adr) }) /** * Generates query object names. diff --git a/src/main/kotlin/gln/gl20i.kt b/src/main/kotlin/gln/gl20i.kt index 10af0f0..e1f1f88 100644 --- a/src/main/kotlin/gln/gl20i.kt +++ b/src/main/kotlin/gln/gl20i.kt @@ -27,7 +27,9 @@ import glm_.vec4.Vec4 import glm_.vec4.Vec4d import glm_.vec4.Vec4i import glm_.vec4.Vec4s +import gln.`object`.GLshaders import gln.`object`.GlProgram +import gln.`object`.GlShader import gln.glf.VertexAttribute import kool.* import org.lwjgl.opengl.* @@ -514,7 +516,7 @@ interface gl20i { infix fun getAttachedShaders(program: GlProgram): GLshaders = stak { val maxCount = program.attachedShadersCount - val shaders = intBufferBig(maxCount) + val shaders = IntBuffer(maxCount) GL20C.nglGetAttachedShaders(program.i, maxCount, NULL, shaders.adr) GLshaders(shaders) } diff --git a/src/main/kotlin/gln/gln.kt b/src/main/kotlin/gln/gln.kt index caa6ea2..0e1f895 100644 --- a/src/main/kotlin/gln/gln.kt +++ b/src/main/kotlin/gln/gln.kt @@ -18,9 +18,9 @@ import java.nio.ByteBuffer import java.nio.IntBuffer import java.nio.ShortBuffer -@Deprecated("use appBuffer instead") +@Deprecated("use kool instead") val buf: ByteBuffer = MemoryUtil.memAlloc(256) -@Deprecated("use appBuffer instead") +@Deprecated("use kool instead") val bufAd = buf.adr operator fun IntBuffer.get(e: Enum<*>) = get(e.ordinal) @@ -81,7 +81,7 @@ fun checkError(location: String = "", throws: Boolean = true): Boolean { else -> throw IllegalStateException() } if (throws) - throw Error("OpenGL Error ($message) at $location") + throw Exception("OpenGL Error ($message) at $location") else System.err.println(message) false @@ -89,7 +89,7 @@ fun checkError(location: String = "", throws: Boolean = true): Boolean { } } -val VERSION = "0.4.5" +val VERSION = "0.4.6" fun main(args: Array) { @@ -114,5 +114,5 @@ val Buffer.glType: Int is ByteBuffer -> GL11C.GL_UNSIGNED_BYTE is ShortBuffer -> GL11C.GL_UNSIGNED_SHORT is IntBuffer -> GL11C.GL_UNSIGNED_INT - else -> throw Error("unsupported") + else -> throw Exception("unsupported") } \ No newline at end of file diff --git a/src/main/kotlin/gln/object/buffer.kt b/src/main/kotlin/gln/object/buffer.kt index 27b1b18..3a3174a 100644 --- a/src/main/kotlin/gln/object/buffer.kt +++ b/src/main/kotlin/gln/object/buffer.kt @@ -13,9 +13,6 @@ import java.nio.Buffer import java.nio.ByteBuffer import java.nio.IntBuffer -@Deprecated("This class was renamed to GlBuffer", ReplaceWith("GlBuffer", "gln.`object`")) -typealias GLbuffer = GlBuffer // TODO remove - object GlBuffer { var i = 0 diff --git a/src/main/kotlin/gln/object/program.kt b/src/main/kotlin/gln/object/program.kt index 0290fb8..7526c6d 100644 --- a/src/main/kotlin/gln/object/program.kt +++ b/src/main/kotlin/gln/object/program.kt @@ -7,9 +7,6 @@ import org.lwjgl.opengl.* import org.lwjgl.system.MemoryStack.stackGet import java.lang.Exception -@Deprecated("This class was renamed to GlProgram", ReplaceWith("GlProgram", "gln.`object`")) -typealias GLprogram = GlProgram // TODO remove - inline class GlProgram(val i: Int) { // --- [ glDeleteProgram ] --- diff --git a/src/main/kotlin/gln/object/query.kt b/src/main/kotlin/gln/object/query.kt index 2bae6d3..0aa4b91 100644 --- a/src/main/kotlin/gln/object/query.kt +++ b/src/main/kotlin/gln/object/query.kt @@ -8,9 +8,6 @@ import org.lwjgl.opengl.GL15C import org.lwjgl.opengl.GL20C import java.nio.IntBuffer -@Deprecated("This class was renamed to GlQuery", ReplaceWith("GlQuery", "gln.`object`")) -typealias GLquery = GlQuery // TODO remove - inline class GlQuery(val i: Int) { // --- [ glBeginQuery ] --- @@ -33,9 +30,6 @@ inline class GlQuery(val i: Int) { get() = GL20C.glIsQuery(i) } -@Deprecated("This class was renamed to GlQueries", ReplaceWith("GlQueries", "gln.`object`")) -typealias GLqueries = GlQueries // TODO remove - inline class GlQueries(val i: IntBuffer) { inline val rem: Int diff --git a/src/main/kotlin/gln/object/shader.kt b/src/main/kotlin/gln/object/shader.kt index 8c1c584..d3d4412 100644 --- a/src/main/kotlin/gln/object/shader.kt +++ b/src/main/kotlin/gln/object/shader.kt @@ -1,15 +1,12 @@ -package gln +package gln.`object` import glm_.bool +import gln.ShaderType +import gln.gl20 import org.lwjgl.opengl.* import java.io.* import java.nio.IntBuffer -@Deprecated("This class was renamed to GlShader", ReplaceWith("GlShader", "gln.`object`")) -typealias GLshader = GlShader // TODO remove - -// TODO stop throwing Error and change to some exception type - inline class GlShader(val i: Int) { // --- [ glDeleteShader ] --- @@ -70,7 +67,7 @@ inline class GlShader(val i: Int) { compile() if(!compileStatus) - throw Error(infoLog) + throw Exception(infoLog) } fun createFromSource(sourceText: Array, type: ShaderType) = create(type).apply { @@ -79,7 +76,7 @@ inline class GlShader(val i: Int) { compile() if(!compileStatus) - throw Error(infoLog) + throw Exception(infoLog) } fun createFromPath(path: String, transform: ((String) -> String)? = null): GlShader { @@ -98,13 +95,13 @@ inline class GlShader(val i: Int) { } try { - return GlShader.createFromSource(transform?.invoke(source) ?: source, ShaderType(path.type)) + return createFromSource(transform?.invoke(source) ?: source, ShaderType(path.type)) } catch (err: Exception) { - throw Error("Compiler failure in ${path.substringAfterLast('/')} shader: ${err.message}") + throw Exception("Compiler failure in ${path.substringAfterLast('/')} shader: ${err.message}") } } - fun createShaderFromPath(context: Class<*>, path: String): Int { + fun createFromPath(context: Class<*>, path: String): Int { val shader = GL20.glCreateShader(path.type) @@ -157,7 +154,7 @@ inline class GlShader(val i: Int) { "geom" -> GL32.GL_GEOMETRY_SHADER "frag" -> GL20.GL_FRAGMENT_SHADER "comp" -> GL43.GL_COMPUTE_SHADER - else -> throw Error("invalid shader extension") + else -> throw Exception("invalid shader extension") } } } diff --git a/src/main/kotlin/gln/object/texture.kt b/src/main/kotlin/gln/object/texture.kt index 64c5eb8..6b45ca8 100644 --- a/src/main/kotlin/gln/object/texture.kt +++ b/src/main/kotlin/gln/object/texture.kt @@ -53,9 +53,6 @@ import org.lwjgl.opengl.* // get() = RECTANGLE //} -@Deprecated("This class was renamed to GlTexture", ReplaceWith("GlTexture", "gln.`object`")) -typealias GLtexture = GlTexture // TODO remove - interface GlTexture { val i: Int diff --git a/src/main/kotlin/gln/program/block.kt b/src/main/kotlin/gln/program/block.kt index 4e560db..25eb2af 100644 --- a/src/main/kotlin/gln/program/block.kt +++ b/src/main/kotlin/gln/program/block.kt @@ -71,7 +71,7 @@ object ProgramUse { set(value) = GL20.glUniform1i(uniform, value) var String.unitE: Enum<*> - get() = throw Error() + get() = throw Exception() set(value) = GL20.glUniform1i(uniform, value.ordinal) diff --git a/src/main/kotlin/gln/program/program.kt b/src/main/kotlin/gln/program/program.kt index 011afc5..880ac1a 100644 --- a/src/main/kotlin/gln/program/program.kt +++ b/src/main/kotlin/gln/program/program.kt @@ -3,12 +3,10 @@ package gln.program import glm_.bool -import gln.GlShader +import gln.`object`.GlShader import gln.ShaderType import gln.get import org.lwjgl.opengl.* -import java.io.File -import java.io.InputStreamReader import kotlin.properties.Delegates @@ -154,6 +152,16 @@ open class GlslProgram( val infoLog: String get() = GL20.glGetProgramInfoLog(name) + + fun use() = GL20.glUseProgram(name) + fun unuse() = GL20.glUseProgram(0) + + fun use(block: () -> R): R { + use() + return block().also { unuse() } + } + + companion object { @JvmStatic @@ -362,7 +370,6 @@ open class GlslProgram( return program } - // fun fromSources(vertSrc: Array, fragSrc: Array, geomSrc: Array? = null): GlslProgram { // // val program = GlslProgram() @@ -385,20 +392,6 @@ open class GlslProgram( // return program // } - - // TODO remove deprecated - @Throws(Error::class) - @Deprecated("Moved to GlShader companion", ReplaceWith("GlShader.createFromSource(source, ShaderType(type))")) - fun createShaderFromSource(source: String, type: Int): GlShader = GlShader.createFromSource(source, ShaderType(type)) - - @Throws(Error::class) - @Deprecated("Moved to GlShader companion", ReplaceWith("GlShader.createFromSource(source, ShaderType(type))")) - fun createShaderFromSource(source: Array, type: Int): GlShader = GlShader.createFromSource(source, ShaderType(type)) - - @Throws(Exception::class) - @Deprecated("Moved to GlShader companion", ReplaceWith("GlShader.createFromPath(path, transform)")) - fun createShaderFromPath(path: String, transform: ((String) -> String)? = null): GlShader = GlShader.createFromPath(path, transform) - private val shaderExtensions = arrayOf(".vert", ".tesc", ".tese", ".geom", ".frag", ".comp") } } \ No newline at end of file diff --git a/src/main/kotlin/gln/uniform/uniform.kt b/src/main/kotlin/gln/uniform/uniform.kt index 91f5656..2e27fa3 100644 --- a/src/main/kotlin/gln/uniform/uniform.kt +++ b/src/main/kotlin/gln/uniform/uniform.kt @@ -79,7 +79,7 @@ fun glUniform(location: Int, floats: FloatArray) = when(floats.size){ 2 -> GL20C.glUniform2f(location, floats[0], floats[1]) 3 -> GL20C.glUniform3f(location, floats[0], floats[1], floats[2]) 4 -> GL20C.glUniform4f(location, floats[0], floats[1], floats[2], floats[3]) - else -> throw Error() + else -> throw Exception() } fun glUniform(location: Int, ints: IntArray) = when(ints.size){ @@ -87,7 +87,7 @@ fun glUniform(location: Int, ints: IntArray) = when(ints.size){ 2 -> GL20C.glUniform2i(location, ints[0], ints[1]) 3 -> GL20C.glUniform3i(location, ints[0], ints[1], ints[2]) 4 -> GL20C.glUniform4i(location, ints[0], ints[1], ints[2], ints[3]) - else -> throw Error() + else -> throw Exception() }