Skip to content

Commit

Permalink
⬆️ glm
Browse files Browse the repository at this point in the history
- fixed shl bug while passing the buffer size (operations priority just changed)
- using buffer.rem instead .cap
  • Loading branch information
elect86 committed Jul 2, 2018
1 parent b290f5b commit 0793b6b
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 29 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ dependencies {

implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"

implementation 'com.github.kotlin-graphics:gli:99a9ad38e699d3b7e0c7795b03896e090cf59ab2'
implementation 'com.github.kotlin-graphics:gli:a98fc9b26107ddd654679f0bedf84f3f3aa01443'

//testCompile 'io.kotlintest:kotlintest-runner-junit5:3.0.6'

Expand Down
35 changes: 18 additions & 17 deletions src/main/kotlin/gln/buffer/block.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import glm_.L
import glm_.buffer.adr
import glm_.buffer.cap
import glm_.buffer.pos
import glm_.buffer.rem
import glm_.mat4x4.Mat4
import glm_.set
import glm_.vec4.Vec4
Expand Down Expand Up @@ -53,14 +54,14 @@ inline fun initBuffer(target: Int, block: Buffer.() -> Unit): Int {
}

inline fun initBuffers(buffers: IntBuffer, block: Buffers.() -> Unit) {
GL15.nglGenBuffers(buffers.cap, buffers.adr + buffers.pos shl 2)
GL15.nglGenBuffers(buffers.rem, buffers.adr + buffers.pos * Int.BYTES)
Buffers.buffers = buffers
Buffers.block()
}

inline fun initUniformBuffers(buffers: IntBuffer, block: Buffers.() -> Unit) {
Buffers.target = GL31.GL_UNIFORM_BUFFER
GL15.nglGenBuffers(buffers.cap, buffers.adr + buffers.pos shl 2)
GL15.nglGenBuffers(buffers.rem, buffers.adr + buffers.pos * Int.BYTES)
Buffers.buffers = buffers
Buffers.block()
GL15.glBindBuffer(GL31.GL_UNIFORM_BUFFER, 0)
Expand Down Expand Up @@ -101,11 +102,11 @@ object Buffer {
inline fun data(data: DoubleArray, usage: Int = 0) = GL15.glBufferData(target, data, usage)

inline fun data(data: ByteBuffer, usage: Int = 0) = GL15.nglBufferData(target, data.remaining().L, data.adr + data.pos, usage)
inline fun data(data: ShortBuffer, usage: Int = 0) = GL15.nglBufferData(target, data.remaining().L shl 1, data.adr + data.pos shl 1, usage)
inline fun data(data: IntBuffer, usage: Int = 0) = GL15.nglBufferData(target, data.remaining().L shl 2, data.adr + data.pos shl 2, usage)
inline fun data(data: LongBuffer, usage: Int = 0) = GL15.nglBufferData(target, data.remaining().L shl 3, data.adr + data.pos shl 3, usage)
inline fun data(data: FloatBuffer, usage: Int = 0) = GL15.nglBufferData(target, data.remaining().L shl 2, data.adr + data.pos shl 2, usage)
inline fun data(data: DoubleBuffer, usage: Int = 0) = GL15.nglBufferData(target, data.remaining().L shl 3, data.adr + data.pos shl 3, usage)
inline fun data(data: ShortBuffer, usage: Int = 0) = GL15.nglBufferData(target, data.remaining().L * Short.BYTES, data.adr + data.pos * Short.BYTES, usage)
inline fun data(data: IntBuffer, usage: Int = 0) = GL15.nglBufferData(target, data.remaining().L * Int.BYTES, data.adr + data.pos * Int.BYTES, usage)
inline fun data(data: LongBuffer, usage: Int = 0) = GL15.nglBufferData(target, data.remaining().L * Long.BYTES, data.adr + data.pos * Long.BYTES, usage)
inline fun data(data: FloatBuffer, usage: Int = 0) = GL15.nglBufferData(target, data.remaining().L * Float.BYTES, data.adr + data.pos * Float.BYTES, usage)
inline fun data(data: DoubleBuffer, usage: Int = 0) = GL15.nglBufferData(target, data.remaining().L * Double.BYTES, data.adr + data.pos * Double.BYTES, usage)

inline fun data(size: Int, data: Vec4, usage: Int = 0) {
buf.putFloat(0, data.x).putFloat(Float.BYTES, data.y).putFloat(Float.BYTES * 2, data.z).putFloat(Float.BYTES * 3, data.w)
Expand All @@ -115,18 +116,18 @@ object Buffer {
inline fun data(size: Int, usage: Int = 0) = GL15.nglBufferData(target, size.L, NULL, usage)

inline fun subData(offset: Int, data: ByteBuffer) = GL15.nglBufferSubData(target, offset.L, data.remaining().L, data.adr + data.pos)
inline fun subData(offset: Int, data: ShortBuffer) = GL15.nglBufferSubData(target, offset.L, data.remaining().L shl 1, data.adr + data.pos shl 1)
inline fun subData(offset: Int, data: IntBuffer) = GL15.nglBufferSubData(target, offset.L, data.remaining().L shl 2, data.adr + data.pos shl 2)
inline fun subData(offset: Int, data: LongBuffer) = GL15.nglBufferSubData(target, offset.L, data.remaining().L shl 3, data.adr + data.pos shl 3)
inline fun subData(offset: Int, data: FloatBuffer) = GL15.nglBufferSubData(target, offset.L, data.remaining().L shl 2, data.adr + data.pos shl 2)
inline fun subData(offset: Int, data: DoubleBuffer) = GL15.nglBufferSubData(target, offset.L, data.remaining().L shl 3, data.adr + data.pos shl 3)
inline fun subData(offset: Int, data: ShortBuffer) = GL15.nglBufferSubData(target, offset.L, data.remaining().L * Short.BYTES, data.adr + data.pos * Short.BYTES)
inline fun subData(offset: Int, data: IntBuffer) = GL15.nglBufferSubData(target, offset.L, data.remaining().L * Int.BYTES, data.adr + data.pos * Int.BYTES)
inline fun subData(offset: Int, data: LongBuffer) = GL15.nglBufferSubData(target, offset.L, data.remaining().L * Long.BYTES, data.adr + data.pos * Long.BYTES)
inline fun subData(offset: Int, data: FloatBuffer) = GL15.nglBufferSubData(target, offset.L, data.remaining().L * Float.BYTES, data.adr + data.pos * Float.BYTES)
inline fun subData(offset: Int, data: DoubleBuffer) = GL15.nglBufferSubData(target, offset.L, data.remaining().L * Double.BYTES, data.adr + data.pos * Double.BYTES)

inline fun subData(data: ByteBuffer) = GL15.nglBufferSubData(target, 0L, data.remaining().L, data.adr + data.pos)
inline fun subData(data: ShortBuffer) = GL15.nglBufferSubData(target, 0L, data.remaining().L shl 1, data.adr + data.pos shl 1)
inline fun subData(data: IntBuffer) = GL15.nglBufferSubData(target, 0L, data.remaining().L shl 2, data.adr + data.pos shl 2)
inline fun subData(data: LongBuffer) = GL15.nglBufferSubData(target, 0L, data.remaining().L shl 3, data.adr + data.pos shl 3)
inline fun subData(data: FloatBuffer) = GL15.nglBufferSubData(target, 0L, data.remaining().L shl 2, data.adr + data.pos shl 2)
inline fun subData(data: DoubleBuffer) = GL15.nglBufferSubData(target, 0L, data.remaining().L shl 3, data.adr + data.pos shl 3)
inline fun subData(data: ShortBuffer) = GL15.nglBufferSubData(target, 0L, data.remaining().L * Short.BYTES, data.adr + data.pos * Short.BYTES)
inline fun subData(data: IntBuffer) = GL15.nglBufferSubData(target, 0L, data.remaining().L * Int.BYTES, data.adr + data.pos * Int.BYTES)
inline fun subData(data: LongBuffer) = GL15.nglBufferSubData(target, 0L, data.remaining().L * Long.BYTES, data.adr + data.pos * Long.BYTES)
inline fun subData(data: FloatBuffer) = GL15.nglBufferSubData(target, 0L, data.remaining().L * Float.BYTES, data.adr + data.pos * Float.BYTES)
inline fun subData(data: DoubleBuffer) = GL15.nglBufferSubData(target, 0L, data.remaining().L * Double.BYTES, data.adr + data.pos * Double.BYTES)


// ----- Mat4 -----
Expand Down
6 changes: 3 additions & 3 deletions src/main/kotlin/gln/buffer/buffer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ inline fun glArrayBufferData(size: Int, usage: Int) = GL15.nglBufferData(GL_ARRA
inline fun glArrayBufferData(floats: FloatArray, usage: Int) = GL15.glBufferData(GL_ARRAY_BUFFER, floats, usage)
inline fun glArrayBufferData(floats: FloatBuffer, usage: Int) = GL15.glBufferData(GL_ARRAY_BUFFER, floats, usage)

inline fun glArrayBufferSubData(offset: Int, elements: Int, floats: FloatArray) = JNI.callPPPV(GL.getCapabilities().glBufferSubData, GL_ARRAY_BUFFER, offset.L, (elements shl 2).L, floats)
inline fun glArrayBufferSubData(offset: Int, elements: Int, floats: FloatArray) = JNI.callPPPV(GL.getCapabilities().glBufferSubData, GL_ARRAY_BUFFER, offset.L, (elements * Float.BYTES).L, floats)
inline fun glArrayBufferSubData(floats: FloatArray) = GL15.glBufferSubData(GL_ARRAY_BUFFER, 0L, floats)

inline fun glElementBufferData(size: Int, usage: Int) = GL15.nglBufferData(GL_ELEMENT_ARRAY_BUFFER, size.L, NULL, usage)
Expand All @@ -45,9 +45,9 @@ inline fun glElementBufferData(ints: IntBuffer, usage: Int) = GL15.glBufferData(
inline fun glElementBufferData(shorts: ShortArray, usage: Int) = GL15.glBufferData(GL_ELEMENT_ARRAY_BUFFER, shorts, usage)
inline fun glElementBufferData(shorts: ShortBuffer, usage: Int) = GL15.glBufferData(GL_ELEMENT_ARRAY_BUFFER, shorts, usage)

inline fun glElementBufferSubData(offset: Int, elements: Int, ints: IntArray) = JNI.callPPPV(GL.getCapabilities().glBufferSubData, GL_ARRAY_BUFFER, offset.L, (elements shl 2).L, ints)
inline fun glElementBufferSubData(offset: Int, elements: Int, ints: IntArray) = JNI.callPPPV(GL.getCapabilities().glBufferSubData, GL_ARRAY_BUFFER, offset.L, (elements * Int.BYTES).L, ints)
inline fun glElementBufferSubData(ints: IntArray) = GL15.glBufferSubData(GL_ARRAY_BUFFER, 0L, ints)
inline fun glElementBufferSubData(offset: Int, elements: Int, shorts: ShortArray) = JNI.callPPPV(GL.getCapabilities().glBufferSubData, GL_ARRAY_BUFFER, offset.L, (elements shl 2).L, shorts)
inline fun glElementBufferSubData(offset: Int, elements: Int, shorts: ShortArray) = JNI.callPPPV(GL.getCapabilities().glBufferSubData, GL_ARRAY_BUFFER, offset.L, (elements * Short.BYTES).L, shorts)
inline fun glElementBufferSubData(shorts: ShortArray) = GL15.glBufferSubData(GL_ARRAY_BUFFER, 0L, shorts)

inline fun glUniformBufferData(size: Int, usage: Int) = GL15.nglBufferData(GL_UNIFORM_BUFFER, size.L, NULL, usage)
Expand Down
4 changes: 3 additions & 1 deletion src/main/kotlin/gln/framebuffer/block.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package gln.framebuffer

import glm_.BYTES
import glm_.buffer.adr
import glm_.buffer.cap
import glm_.buffer.pos
import glm_.buffer.rem
import gln.buf
import gln.bufAd
import gln.get
Expand All @@ -26,7 +28,7 @@ inline fun initFramebuffer(block: Framebuffer.() -> Unit): Int {

inline fun initFramebuffers(block: Framebuffers.() -> Unit) = initFramebuffers(framebufferName, block)
inline fun initFramebuffers(framebuffer: IntBuffer, block: Framebuffers.() -> Unit) {
GL30.nglGenFramebuffers(framebuffer.cap, framebuffer.adr + framebuffer.pos shl 2)
GL30.nglGenFramebuffers(framebuffer.rem, framebuffer.adr + framebuffer.pos * Int.BYTES)
Framebuffers.names = framebuffer
Framebuffers.block()
}
Expand Down
5 changes: 4 additions & 1 deletion src/main/kotlin/gln/renderbuffer/block.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package gln.renderbuffer

import glm_.BYTES
import glm_.buffer.adr
import glm_.buffer.cap
import glm_.buffer.pos
import glm_.buffer.rem
import glm_.vec2.Vec2i
import gln.buf
import gln.bufAd
Expand All @@ -12,7 +15,7 @@ import java.nio.IntBuffer

inline fun initRenderbuffers(block: RenderBuffers.() -> Unit) = initRenderbuffers(renderbufferName, block)
inline fun initRenderbuffers(renderbuffers: IntBuffer, block: RenderBuffers.() -> Unit) {
GL30.nglGenRenderbuffers(renderbuffers.cap, renderbuffers.adr + renderbuffers.cap shl 2)
GL30.nglGenRenderbuffers(renderbuffers.rem, renderbuffers.adr + renderbuffers.pos * Int.BYTES)
RenderBuffers.names = renderbuffers
RenderBuffers.block()
}
Expand Down
7 changes: 4 additions & 3 deletions src/main/kotlin/gln/texture/block.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import glm_.BYTES
import glm_.buffer.adr
import glm_.buffer.cap
import glm_.buffer.pos
import glm_.buffer.rem
import glm_.vec2.Vec2i
import glm_.vec3.Vec3i
import gln.buf
Expand Down Expand Up @@ -122,14 +123,14 @@ inline fun initTexture(target: Int, block: Texture.() -> Unit): Int {

inline fun initTextures2d(block: Textures2d.() -> Unit) = initTextures2d(textureName, block)
inline fun initTextures2d(textures: IntBuffer, block: Textures2d.() -> Unit) {
GL11.nglGenTextures(textures.cap, textures.adr + textures.cap shl 2)
GL11.nglGenTextures(textures.rem, textures.adr + textures.pos * Int.BYTES)
Textures2d.names = textures
Textures2d.block()
}

inline fun initTextures(target: Int, block: Textures.() -> Unit) = initTextures(target, textureName, block)
inline fun initTextures(target: Int, textures: IntBuffer, block: Textures.() -> Unit) {
GL11.nglGenTextures(textures.cap, textures.adr + textures.cap shl 2)
GL11.nglGenTextures(textures.rem, textures.adr + textures.pos * Int.BYTES)
Textures.target = target
Textures.names = textures
Textures.block()
Expand Down Expand Up @@ -241,7 +242,7 @@ object Texture2d {
compressedSubImage(level, 0, 0, size.x, size.y, format.i, data)

inline fun compressedSubImage(level: Int, xOffset: Int, yOffset: Int, width: Int, height: Int, format: Int, data: ByteBuffer) =
GL13.nglCompressedTexSubImage2D(GL11.GL_TEXTURE_2D, level, xOffset, yOffset, width, height, format, data.cap, data.adr + data.pos)
GL13.nglCompressedTexSubImage2D(GL11.GL_TEXTURE_2D, level, xOffset, yOffset, width, height, format, data.rem, data.adr + data.pos)

var baseLevel = 0
set(value) {
Expand Down
7 changes: 4 additions & 3 deletions src/main/kotlin/gln/uniformBlock/block.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package gln.uniformBlock
import glm_.BYTES
import glm_.bool
import glm_.buffer.cap
import glm_.buffer.rem
import glm_.glm
import gln.buf
import gln.bufAd
Expand All @@ -18,8 +19,8 @@ object UniformBlock {

inline val name: String
get() {
GL31.nglGetActiveUniformBlockName(programName, blockIndex, buf.cap, bufAd, bufAd + Int.BYTES)
val bytes = ByteArray(buf.getInt(0), { buf[Int.BYTES + it] })
GL31.nglGetActiveUniformBlockName(programName, blockIndex, buf.rem, bufAd, bufAd + Int.BYTES)
val bytes = ByteArray(buf.getInt(0)) { buf[Int.BYTES + it] }
return String(bytes)
}
inline val binding: Int
Expand All @@ -45,7 +46,7 @@ object UniformBlock {
inline val activeUniformsIndices: IntArray
get() {
GL31.nglGetActiveUniformBlockiv(programName, blockIndex, GL31.GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS, bufAd)
return IntArray(glm.min(activeUniforms, 32), { buf.getInt(it * Int.BYTES) })
return IntArray(glm.min(activeUniforms, 32)) { buf.getInt(it * Int.BYTES) }
}
inline val byVertexShader: Boolean
get() {
Expand Down

0 comments on commit 0793b6b

Please sign in to comment.