diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/client/gl/GLStateTracker.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/client/gl/GLStateTracker.kt index 6434f915..20afb172 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/client/gl/GLStateTracker.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/client/gl/GLStateTracker.kt @@ -5,6 +5,11 @@ import org.lwjgl.opengl.GL import org.lwjgl.opengl.GL46.* import ru.dbotthepony.kstarbound.Starbound import ru.dbotthepony.kstarbound.client.freetype.FreeType +import ru.dbotthepony.kstarbound.client.gl.shader.GLShader +import ru.dbotthepony.kstarbound.client.gl.shader.GLShaderProgram +import ru.dbotthepony.kstarbound.client.gl.shader.GLTransformableColorableProgram +import ru.dbotthepony.kstarbound.client.gl.shader.GLTransformableProgram +import ru.dbotthepony.kstarbound.client.gl.vertex.GLAttributeList import ru.dbotthepony.kstarbound.client.gl.vertex.StreamVertexBuilder import ru.dbotthepony.kstarbound.client.gl.vertex.VertexType import ru.dbotthepony.kstarbound.client.render.Box2DRenderer @@ -12,7 +17,6 @@ import ru.dbotthepony.kstarbound.client.render.Font import ru.dbotthepony.kstarbound.client.render.TileRenderers import ru.dbotthepony.kvector.api.IStruct4f import ru.dbotthepony.kvector.matrix.Matrix4fStack -import ru.dbotthepony.kvector.matrix.nfloat.Matrix4f import ru.dbotthepony.kvector.util2d.AABB import ru.dbotthepony.kvector.vector.Color import java.io.FileNotFoundException @@ -59,31 +63,11 @@ private class GLStateGenericTracker(private var value: T, private val lambda: } } -open class GLTransformableProgram(state: GLStateTracker, vararg shaders: GLShader) : GLShaderProgram(state, *shaders) { - init { - link() - } - - val transform = this["_transform"]!! - - init { - transform.set(Matrix4f.IDENTITY) - } -} - -open class GLTransformableColorableProgram(state: GLStateTracker, vararg shaders: GLShader) : GLTransformableProgram(state, *shaders) { - val color = this["_color"]!! - - init { - color.set(Color.WHITE) - } -} - interface GLCleanable : Cleaner.Cleanable { /** * Выставляет флаг на то, что объект был удалён вручную и вызывает clean() */ - fun cleanManual(): Unit + fun cleanManual() } interface GLStreamBuilderList { @@ -144,7 +128,7 @@ class GLStateTracker { var blend by GLStateSwitchTracker(GL_BLEND) var depthTest by GLStateSwitchTracker(GL_DEPTH_TEST) - var VBO: GLVertexBufferObject? = null + var VBO: VertexBufferObject? = null set(value) { ensureSameThread() if (field === value) return @@ -161,7 +145,7 @@ class GLStateTracker { checkForGLError() } - var EBO: GLVertexBufferObject? = null + var EBO: VertexBufferObject? = null set(value) { ensureSameThread() if (field === value) return @@ -178,7 +162,7 @@ class GLStateTracker { checkForGLError() } - var VAO: GLVertexArrayObject? = null + var VAO: VertexArrayObject? = null set(value) { ensureSameThread() if (field === value) return @@ -243,12 +227,12 @@ class GLStateTracker { return GLShaderProgram(this, *shaders) } - fun newVBO(type: VBOType = VBOType.ARRAY): GLVertexBufferObject { - return GLVertexBufferObject(this, type) + fun newVBO(type: VBOType = VBOType.ARRAY): VertexBufferObject { + return VertexBufferObject(this, type) } fun newEBO() = newVBO(VBOType.ELEMENT_ARRAY) - fun newVAO() = GLVertexArrayObject(this) + fun newVAO() = VertexArrayObject(this) fun newTexture(name: String = "") = GLTexture2D(this, name) private val named2DTextures = HashMap() @@ -308,7 +292,7 @@ class GLStateTracker { } } - fun bind(obj: GLVertexBufferObject): GLVertexBufferObject { + fun bind(obj: VertexBufferObject): VertexBufferObject { if (obj.type == VBOType.ARRAY) VBO = obj else @@ -317,7 +301,7 @@ class GLStateTracker { return obj } - fun unbind(obj: GLVertexBufferObject): GLVertexBufferObject { + fun unbind(obj: VertexBufferObject): VertexBufferObject { if (obj.type == VBOType.ARRAY) if (obj == VBO) VBO = null @@ -328,12 +312,12 @@ class GLStateTracker { return obj } - fun bind(obj: GLVertexArrayObject): GLVertexArrayObject { + fun bind(obj: VertexArrayObject): VertexArrayObject { VAO = obj return obj } - fun unbind(obj: GLVertexArrayObject): GLVertexArrayObject { + fun unbind(obj: VertexArrayObject): VertexArrayObject { if (obj == VAO) VAO = null diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/client/gl/GLVertexArrayObject.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/client/gl/VertexArrayObject.kt similarity index 81% rename from src/main/kotlin/ru/dbotthepony/kstarbound/client/gl/GLVertexArrayObject.kt rename to src/main/kotlin/ru/dbotthepony/kstarbound/client/gl/VertexArrayObject.kt index 5634a6ec..4bb0f9ce 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/client/gl/GLVertexArrayObject.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/client/gl/VertexArrayObject.kt @@ -3,7 +3,7 @@ package ru.dbotthepony.kstarbound.client.gl import org.lwjgl.opengl.GL46.* import java.io.Closeable -class GLVertexArrayObject(val state: GLStateTracker) : Closeable { +class VertexArrayObject(val state: GLStateTracker) : Closeable { val pointer = glGenVertexArrays() init { @@ -12,17 +12,17 @@ class GLVertexArrayObject(val state: GLStateTracker) : Closeable { private val cleanable = state.registerCleanable(this, ::glDeleteVertexArrays, "Vertex Array Object", pointer) - fun bind(): GLVertexArrayObject { + fun bind(): VertexArrayObject { check(isValid) { "Tried to use NULL GLVertexArrayObject" } return state.bind(this) } - fun unbind(): GLVertexArrayObject { + fun unbind(): VertexArrayObject { check(isValid) { "Tried to use NULL GLVertexArrayObject" } return state.unbind(this) } - fun attribute(position: Int, size: Int, type: Int, normalize: Boolean, stride: Int, offset: Long = 0L): GLVertexArrayObject { + fun attribute(position: Int, size: Int, type: Int, normalize: Boolean, stride: Int, offset: Long = 0L): VertexArrayObject { check(isValid) { "Tried to use NULL GLVertexArrayObject" } state.ensureSameThread() glVertexAttribPointer(position, size, type, normalize, stride, offset) @@ -30,7 +30,7 @@ class GLVertexArrayObject(val state: GLStateTracker) : Closeable { return this } - fun enableAttribute(position: Int): GLVertexArrayObject { + fun enableAttribute(position: Int): VertexArrayObject { check(isValid) { "Tried to use NULL GLVertexArrayObject" } state.ensureSameThread() glEnableVertexArrayAttrib(pointer, position) diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/client/gl/GLVertexBufferObject.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/client/gl/VertexBufferObject.kt similarity index 77% rename from src/main/kotlin/ru/dbotthepony/kstarbound/client/gl/GLVertexBufferObject.kt rename to src/main/kotlin/ru/dbotthepony/kstarbound/client/gl/VertexBufferObject.kt index ac62cc1d..20afdb19 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/client/gl/GLVertexBufferObject.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/client/gl/VertexBufferObject.kt @@ -5,12 +5,12 @@ import org.lwjgl.system.MemoryUtil import java.io.Closeable import java.nio.ByteBuffer -enum class VBOType(val value: Int) { +enum class VBOType(val glType: Int) { ARRAY(GL_ARRAY_BUFFER), ELEMENT_ARRAY(GL_ELEMENT_ARRAY_BUFFER), } -class GLVertexBufferObject(val state: GLStateTracker, val type: VBOType = VBOType.ARRAY) : Closeable { +class VertexBufferObject(val state: GLStateTracker, val type: VBOType = VBOType.ARRAY) : Closeable { val pointer = glGenBuffers() init { @@ -22,19 +22,19 @@ class GLVertexBufferObject(val state: GLStateTracker, val type: VBOType = VBOTyp val isArray get() = type == VBOType.ARRAY val isElementArray get() = type == VBOType.ELEMENT_ARRAY - fun bind(): GLVertexBufferObject { + fun bind(): VertexBufferObject { check(isValid) { "Tried to use NULL GLVertexBufferObject" } state.bind(this) return this } - fun unbind(): GLVertexBufferObject { + fun unbind(): VertexBufferObject { check(isValid) { "Tried to use NULL GLVertexBufferObject" } state.unbind(this) return this } - fun bufferData(data: ByteBuffer, usage: Int): GLVertexBufferObject { + fun bufferData(data: ByteBuffer, usage: Int): VertexBufferObject { check(isValid) { "Tried to use NULL GLVertexBufferObject" } state.ensureSameThread() glNamedBufferData(pointer, data, usage) @@ -42,7 +42,7 @@ class GLVertexBufferObject(val state: GLStateTracker, val type: VBOType = VBOTyp return this } - fun bufferData(data: ByteBuffer, usage: Int, length: Long): GLVertexBufferObject { + fun bufferData(data: ByteBuffer, usage: Int, length: Long): VertexBufferObject { check(isValid) { "Tried to use NULL GLVertexBufferObject" } state.ensureSameThread() @@ -56,7 +56,7 @@ class GLVertexBufferObject(val state: GLStateTracker, val type: VBOType = VBOTyp return this } - fun bufferData(data: IntArray, usage: Int): GLVertexBufferObject { + fun bufferData(data: IntArray, usage: Int): VertexBufferObject { check(isValid) { "Tried to use NULL GLVertexBufferObject" } state.ensureSameThread() glNamedBufferData(pointer, data, usage) @@ -64,7 +64,7 @@ class GLVertexBufferObject(val state: GLStateTracker, val type: VBOType = VBOTyp return this } - fun bufferData(data: FloatArray, usage: Int): GLVertexBufferObject { + fun bufferData(data: FloatArray, usage: Int): VertexBufferObject { check(isValid) { "Tried to use NULL GLVertexBufferObject" } state.ensureSameThread() glNamedBufferData(pointer, data, usage) @@ -72,7 +72,7 @@ class GLVertexBufferObject(val state: GLStateTracker, val type: VBOType = VBOTyp return this } - fun bufferData(data: DoubleArray, usage: Int): GLVertexBufferObject { + fun bufferData(data: DoubleArray, usage: Int): VertexBufferObject { check(isValid) { "Tried to use NULL GLVertexBufferObject" } state.ensureSameThread() glNamedBufferData(pointer, data, usage) @@ -80,7 +80,7 @@ class GLVertexBufferObject(val state: GLStateTracker, val type: VBOType = VBOTyp return this } - fun bufferData(data: LongArray, usage: Int): GLVertexBufferObject { + fun bufferData(data: LongArray, usage: Int): VertexBufferObject { check(isValid) { "Tried to use NULL GLVertexBufferObject" } state.ensureSameThread() glNamedBufferData(pointer, data, usage) diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/client/gl/shader/Errors.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/client/gl/shader/Errors.kt new file mode 100644 index 00000000..1457f56a --- /dev/null +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/client/gl/shader/Errors.kt @@ -0,0 +1,4 @@ +package ru.dbotthepony.kstarbound.client.gl.shader + +class ShaderCompilationException(reason: String) : RuntimeException(reason) +class ShaderLinkException(reason: String) : RuntimeException(reason) diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/client/gl/GLShader.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/client/gl/shader/GLShader.kt similarity index 88% rename from src/main/kotlin/ru/dbotthepony/kstarbound/client/gl/GLShader.kt rename to src/main/kotlin/ru/dbotthepony/kstarbound/client/gl/shader/GLShader.kt index 5ca447a3..34b4a937 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/client/gl/GLShader.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/client/gl/shader/GLShader.kt @@ -1,11 +1,8 @@ -package ru.dbotthepony.kstarbound.client.gl +package ru.dbotthepony.kstarbound.client.gl.shader -import org.lwjgl.opengl.GL20 import org.lwjgl.opengl.GL46.* +import ru.dbotthepony.kstarbound.client.gl.checkForGLError import java.io.File -import kotlin.RuntimeException - -class ShaderCompilationException(reason: String) : RuntimeException(reason) class GLShader( body: String, diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/client/gl/GLShaderProgram.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/client/gl/shader/GLShaderProgram.kt similarity index 60% rename from src/main/kotlin/ru/dbotthepony/kstarbound/client/gl/GLShaderProgram.kt rename to src/main/kotlin/ru/dbotthepony/kstarbound/client/gl/shader/GLShaderProgram.kt index a4ab9a4f..ec8a4e8d 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/client/gl/GLShaderProgram.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/client/gl/shader/GLShaderProgram.kt @@ -1,70 +1,15 @@ -package ru.dbotthepony.kstarbound.client.gl +package ru.dbotthepony.kstarbound.client.gl.shader import it.unimi.dsi.fastutil.objects.Object2ObjectArrayMap import it.unimi.dsi.fastutil.objects.Object2ObjectFunction import org.lwjgl.opengl.GL46.* +import ru.dbotthepony.kstarbound.client.gl.GLStateTracker import ru.dbotthepony.kvector.api.IFloatMatrix import ru.dbotthepony.kvector.api.IStruct3f import ru.dbotthepony.kvector.api.IStruct4f -import java.nio.ByteBuffer -import java.nio.ByteOrder import java.util.* import kotlin.collections.HashSet -class ShaderLinkException(reason: String) : RuntimeException(reason) - -data class Uniform4f(val x: Float, val y: Float, val z: Float, val w: Float) : IStruct4f -data class Uniform3f(val x: Float, val y: Float, val z: Float) : IStruct3f - -class GLUniformLocation(val program: GLShaderProgram, val name: String, val pointer: Int) { - fun set(value: IStruct4f): GLUniformLocation { - program.state.ensureSameThread() - val (v0, v1, v2, v3) = value - glProgramUniform4f(program.pointer, pointer, v0, v1, v2, v3) - return this - } - - fun set(value: IStruct3f): GLUniformLocation { - program.state.ensureSameThread() - val (v0, v1, v2) = value - glProgramUniform3f(program.pointer, pointer, v0, v1, v2) - return this - } - - fun set(value: Int): GLUniformLocation { - program.state.ensureSameThread() - glProgramUniform1i(program.pointer, pointer, value) - return this - } - - private val buff3x3 by lazy { ByteBuffer.allocateDirect(4 * 3 * 3).also { it.order(ByteOrder.nativeOrder()) }.asFloatBuffer() } - private val buff4x4 by lazy { ByteBuffer.allocateDirect(4 * 4 * 4).also { it.order(ByteOrder.nativeOrder()) }.asFloatBuffer() } - - fun set(value: IFloatMatrix<*>): GLUniformLocation { - program.state.ensureSameThread() - - if (value.rows == 3 && value.columns == 3) { - // Матрица 3x3 - buff3x3.position(0) - value.write(buff3x3) - buff3x3.position(0) - glProgramUniformMatrix3fv(program.pointer, pointer, false, buff3x3) - checkForGLError() - } else if (value.rows == 4 && value.columns == 4) { - // Матрица 4x4 - buff4x4.position(0) - value.write(buff4x4) - buff4x4.position(0) - glProgramUniformMatrix4fv(program.pointer, pointer, false, buff4x4) - checkForGLError() - } else { - throw IllegalArgumentException("Can not use matrix with these dimensions: ${value.columns}x${value.rows}") - } - - return this - } -} - open class GLShaderProgram(val state: GLStateTracker, vararg shaders: GLShader) { val pointer = glCreateProgram() var linked = false diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/client/gl/shader/GLTransformableColorableProgram.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/client/gl/shader/GLTransformableColorableProgram.kt new file mode 100644 index 00000000..e0765a43 --- /dev/null +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/client/gl/shader/GLTransformableColorableProgram.kt @@ -0,0 +1,12 @@ +package ru.dbotthepony.kstarbound.client.gl.shader + +import ru.dbotthepony.kstarbound.client.gl.GLStateTracker +import ru.dbotthepony.kvector.vector.Color + +open class GLTransformableColorableProgram(state: GLStateTracker, vararg shaders: GLShader) : GLTransformableProgram(state, *shaders) { + val color = this["_color"]!! + + init { + color.set(Color.WHITE) + } +} \ No newline at end of file diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/client/gl/shader/GLTransformableProgram.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/client/gl/shader/GLTransformableProgram.kt new file mode 100644 index 00000000..a9803500 --- /dev/null +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/client/gl/shader/GLTransformableProgram.kt @@ -0,0 +1,16 @@ +package ru.dbotthepony.kstarbound.client.gl.shader + +import ru.dbotthepony.kstarbound.client.gl.GLStateTracker +import ru.dbotthepony.kvector.matrix.nfloat.Matrix4f + +open class GLTransformableProgram(state: GLStateTracker, vararg shaders: GLShader) : GLShaderProgram(state, *shaders) { + init { + link() + } + + val transform = this["_transform"]!! + + init { + transform.set(Matrix4f.IDENTITY) + } +} \ No newline at end of file diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/client/gl/shader/GLUniformLocation.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/client/gl/shader/GLUniformLocation.kt new file mode 100644 index 00000000..8c2655b6 --- /dev/null +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/client/gl/shader/GLUniformLocation.kt @@ -0,0 +1,57 @@ +package ru.dbotthepony.kstarbound.client.gl.shader + +import ru.dbotthepony.kstarbound.client.gl.checkForGLError +import ru.dbotthepony.kvector.api.IFloatMatrix +import ru.dbotthepony.kvector.api.IStruct3f +import ru.dbotthepony.kvector.api.IStruct4f +import java.nio.ByteBuffer +import java.nio.ByteOrder + +class GLUniformLocation(val program: GLShaderProgram, val name: String, val pointer: Int) { + fun set(value: IStruct4f): GLUniformLocation { + program.state.ensureSameThread() + val (v0, v1, v2, v3) = value + glProgramUniform4f(program.pointer, pointer, v0, v1, v2, v3) + return this + } + + fun set(value: IStruct3f): GLUniformLocation { + program.state.ensureSameThread() + val (v0, v1, v2) = value + glProgramUniform3f(program.pointer, pointer, v0, v1, v2) + return this + } + + fun set(value: Int): GLUniformLocation { + program.state.ensureSameThread() + glProgramUniform1i(program.pointer, pointer, value) + return this + } + + private val buff3x3 by lazy { ByteBuffer.allocateDirect(4 * 3 * 3).also { it.order(ByteOrder.nativeOrder()) }.asFloatBuffer() } + private val buff4x4 by lazy { ByteBuffer.allocateDirect(4 * 4 * 4).also { it.order(ByteOrder.nativeOrder()) }.asFloatBuffer() } + + fun set(value: IFloatMatrix<*>): GLUniformLocation { + program.state.ensureSameThread() + + if (value.rows == 3 && value.columns == 3) { + // Матрица 3x3 + buff3x3.position(0) + value.write(buff3x3) + buff3x3.position(0) + glProgramUniformMatrix3fv(program.pointer, pointer, false, buff3x3) + checkForGLError() + } else if (value.rows == 4 && value.columns == 4) { + // Матрица 4x4 + buff4x4.position(0) + value.write(buff4x4) + buff4x4.position(0) + glProgramUniformMatrix4fv(program.pointer, pointer, false, buff4x4) + checkForGLError() + } else { + throw IllegalArgumentException("Can not use matrix with these dimensions: ${value.columns}x${value.rows}") + } + + return this + } +} \ No newline at end of file diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/client/gl/vertex/AbstractVertexBuilder.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/client/gl/vertex/AbstractVertexBuilder.kt index 7d69d18c..16223224 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/client/gl/vertex/AbstractVertexBuilder.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/client/gl/vertex/AbstractVertexBuilder.kt @@ -4,9 +4,8 @@ import org.lwjgl.opengl.GL46 import org.lwjgl.opengl.GL46.GL_UNSIGNED_INT import org.lwjgl.opengl.GL46.GL_UNSIGNED_SHORT import org.lwjgl.opengl.GL46.GL_UNSIGNED_BYTE -import ru.dbotthepony.kstarbound.client.gl.GLAttributeList import ru.dbotthepony.kstarbound.client.gl.GLType -import ru.dbotthepony.kstarbound.client.gl.GLVertexBufferObject +import ru.dbotthepony.kstarbound.client.gl.VertexBufferObject import ru.dbotthepony.kstarbound.util.writeLEFloat import ru.dbotthepony.kstarbound.util.writeLEInt import ru.dbotthepony.kstarbound.util.writeLEShort @@ -91,9 +90,9 @@ abstract class AbstractVertexBuilder>( } } - protected abstract fun doUpload(vbo: GLVertexBufferObject, ebo: GLVertexBufferObject, drawType: Int) + protected abstract fun doUpload(vbo: VertexBufferObject, ebo: VertexBufferObject, drawType: Int) - fun upload(vbo: GLVertexBufferObject, ebo: GLVertexBufferObject, drawType: Int = GL46.GL_DYNAMIC_DRAW) { + fun upload(vbo: VertexBufferObject, ebo: VertexBufferObject, drawType: Int = GL46.GL_DYNAMIC_DRAW) { require(vbo.isArray) { "$vbo is not an array" } require(ebo.isElementArray) { "$vbo is not an element array" } diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/client/gl/vertex/DirectVertexBuilder.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/client/gl/vertex/DirectVertexBuilder.kt index b53cd18b..913335dc 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/client/gl/vertex/DirectVertexBuilder.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/client/gl/vertex/DirectVertexBuilder.kt @@ -1,8 +1,7 @@ package ru.dbotthepony.kstarbound.client.gl.vertex import org.lwjgl.opengl.GL46 -import ru.dbotthepony.kstarbound.client.gl.GLAttributeList -import ru.dbotthepony.kstarbound.client.gl.GLVertexBufferObject +import ru.dbotthepony.kstarbound.client.gl.VertexBufferObject import ru.dbotthepony.kstarbound.util.ByteBufferOutputStream open class DirectVertexBuilder>( @@ -34,7 +33,7 @@ open class DirectVertexBuilder>( elementMemory.position = 0 } - override fun doUpload(vbo: GLVertexBufferObject, ebo: GLVertexBufferObject, drawType: Int) { + override fun doUpload(vbo: VertexBufferObject, ebo: VertexBufferObject, drawType: Int) { val vertexPos = vertexMemory.position val elementPos = elementMemory.position diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/client/gl/GLAttributeList.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/client/gl/vertex/GLAttributeList.kt similarity index 87% rename from src/main/kotlin/ru/dbotthepony/kstarbound/client/gl/GLAttributeList.kt rename to src/main/kotlin/ru/dbotthepony/kstarbound/client/gl/vertex/GLAttributeList.kt index 99ea5cb1..c9b1119a 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/client/gl/GLAttributeList.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/client/gl/vertex/GLAttributeList.kt @@ -1,6 +1,8 @@ -package ru.dbotthepony.kstarbound.client.gl +package ru.dbotthepony.kstarbound.client.gl.vertex import com.google.common.collect.ImmutableList +import ru.dbotthepony.kstarbound.client.gl.GLType +import ru.dbotthepony.kstarbound.client.gl.VertexArrayObject /** @@ -45,9 +47,9 @@ class GLAttributeList(builder: Builder) { } /** - * Применяет список атрибутов к заданному [GLVertexArrayObject] (попутно включая или отключая их через [enable]) + * Применяет список атрибутов к заданному [VertexArrayObject] (попутно включая или отключая их через [enable]) */ - fun apply(target: GLVertexArrayObject, enable: Boolean) { + fun apply(target: VertexArrayObject, enable: Boolean) { for (i in attributes.indices) { val value = attributes[i] target.attribute(i, value.glType.logicalSize, value.glType.typeIndentity, false, value.stride, value.offset) diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/client/gl/vertex/HeapVertexBuilder.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/client/gl/vertex/HeapVertexBuilder.kt index 2270c8b0..ad44f588 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/client/gl/vertex/HeapVertexBuilder.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/client/gl/vertex/HeapVertexBuilder.kt @@ -4,12 +4,10 @@ import it.unimi.dsi.fastutil.io.FastByteArrayInputStream import it.unimi.dsi.fastutil.io.FastByteArrayOutputStream import org.lwjgl.opengl.GL11.GL_UNSIGNED_INT import org.lwjgl.opengl.GL11.GL_UNSIGNED_SHORT -import ru.dbotthepony.kstarbound.client.gl.GLAttributeList -import ru.dbotthepony.kstarbound.client.gl.GLVertexBufferObject +import ru.dbotthepony.kstarbound.client.gl.VertexBufferObject import ru.dbotthepony.kstarbound.util.readLEShort import ru.dbotthepony.kstarbound.util.writeLEInt import java.nio.ByteBuffer -import java.nio.ByteOrder /** * Vertex Builder который хранит все данные на куче, при [upload] создаётся [ByteBuffer] вне кучи, @@ -47,7 +45,7 @@ class HeapVertexBuilder( elementMemory.reset() } - override fun doUpload(vbo: GLVertexBufferObject, ebo: GLVertexBufferObject, drawType: Int) { + override fun doUpload(vbo: VertexBufferObject, ebo: VertexBufferObject, drawType: Int) { val vboMemory = ByteBuffer.allocateDirect(vertexMemory.length) vboMemory.put(vertexMemory.array, 0, vertexMemory.length) diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/client/gl/vertex/StreamVertexBuilder.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/client/gl/vertex/StreamVertexBuilder.kt index a5d771d2..9a98664e 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/client/gl/vertex/StreamVertexBuilder.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/client/gl/vertex/StreamVertexBuilder.kt @@ -1,7 +1,6 @@ package ru.dbotthepony.kstarbound.client.gl.vertex import org.lwjgl.opengl.GL46 -import ru.dbotthepony.kstarbound.client.gl.GLAttributeList import ru.dbotthepony.kstarbound.client.gl.GLStateTracker import ru.dbotthepony.kstarbound.client.gl.checkForGLError import java.io.Closeable diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/client/render/ConfiguredShaderProgram.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/client/render/ConfiguredShaderProgram.kt index d7e7dda8..fa2e0a18 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/client/render/ConfiguredShaderProgram.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/client/render/ConfiguredShaderProgram.kt @@ -1,8 +1,8 @@ package ru.dbotthepony.kstarbound.client.render import org.lwjgl.opengl.GL46.* -import ru.dbotthepony.kstarbound.client.gl.GLShaderProgram -import ru.dbotthepony.kstarbound.client.gl.GLVertexArrayObject +import ru.dbotthepony.kstarbound.client.gl.shader.GLShaderProgram +import ru.dbotthepony.kstarbound.client.gl.VertexArrayObject import ru.dbotthepony.kstarbound.client.gl.checkForGLError import ru.dbotthepony.kstarbound.client.gl.vertex.AbstractVertexBuilder import ru.dbotthepony.kvector.api.IFloatMatrix @@ -42,7 +42,7 @@ open class ConfiguredShaderProgram( class ConfiguredStaticMesh( val programState: ConfiguredShaderProgram, val indexCount: Int, - val vao: GLVertexArrayObject, + val vao: VertexArrayObject, val elementIndexType: Int, ) : AutoCloseable { private var onClose = {} diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/client/render/Font.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/client/render/Font.kt index 99fe4414..89cef7ee 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/client/render/Font.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/client/render/Font.kt @@ -6,7 +6,7 @@ import org.lwjgl.opengl.GL46.* import ru.dbotthepony.kstarbound.client.freetype.LoadFlag import ru.dbotthepony.kstarbound.client.gl.* import ru.dbotthepony.kstarbound.client.freetype.struct.FT_Pixel_Mode -import ru.dbotthepony.kstarbound.client.gl.GLAttributeList +import ru.dbotthepony.kstarbound.client.gl.vertex.GLAttributeList import ru.dbotthepony.kstarbound.client.gl.vertex.HeapVertexBuilder import ru.dbotthepony.kstarbound.client.gl.vertex.QuadTransformers import ru.dbotthepony.kstarbound.client.gl.vertex.VertexType @@ -257,9 +257,9 @@ class Font( val advanceX: Float val advanceY: Float - private val vbo: GLVertexBufferObject? // все три указателя должны хранится во избежание утечки - private val ebo: GLVertexBufferObject? // все три указателя должны хранится во избежание утечки - private val vao: GLVertexArrayObject? // все три указателя должны хранится во избежание утечки + private val vbo: VertexBufferObject? // все три указателя должны хранится во избежание утечки + private val ebo: VertexBufferObject? // все три указателя должны хранится во избежание утечки + private val vao: VertexArrayObject? // все три указателя должны хранится во избежание утечки private val indexCount: Int diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/client/render/TileRenderer.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/client/render/TileRenderer.kt index 46e14746..4a9dd224 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/client/render/TileRenderer.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/client/render/TileRenderer.kt @@ -7,7 +7,7 @@ import org.lwjgl.opengl.GL46.* import ru.dbotthepony.kstarbound.PIXELS_IN_STARBOUND_UNITf import ru.dbotthepony.kstarbound.Starbound import ru.dbotthepony.kstarbound.client.gl.* -import ru.dbotthepony.kstarbound.client.gl.GLAttributeList +import ru.dbotthepony.kstarbound.client.gl.vertex.GLAttributeList import ru.dbotthepony.kstarbound.client.gl.vertex.* import ru.dbotthepony.kstarbound.defs.tile.* import ru.dbotthepony.kstarbound.world.TileState