Skip to content

Commit

Permalink
add debug lines
Browse files Browse the repository at this point in the history
  • Loading branch information
mi-sts committed Jun 2, 2024
1 parent 3badddf commit 77fa74c
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 15 deletions.
19 changes: 4 additions & 15 deletions src/main/kotlin/solve/rendering/canvas/OpenGLCanvas.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,7 @@ import com.huskerdev.openglfx.canvas.events.GLReshapeEvent
import com.huskerdev.openglfx.lwjgl.LWJGLExecutor
import org.joml.Vector2i
import org.lwjgl.opengl.GL.createCapabilities
import org.lwjgl.opengl.GL11.GL_ALPHA_TEST
import org.lwjgl.opengl.GL11.GL_BLEND
import org.lwjgl.opengl.GL11.GL_COLOR_BUFFER_BIT
import org.lwjgl.opengl.GL11.GL_DEPTH_BUFFER_BIT
import org.lwjgl.opengl.GL11.GL_DEPTH_TEST
import org.lwjgl.opengl.GL11.GL_LEQUAL
import org.lwjgl.opengl.GL11.GL_ONE_MINUS_SRC_ALPHA
import org.lwjgl.opengl.GL11.GL_PROJECTION
import org.lwjgl.opengl.GL11.GL_SRC_ALPHA
import org.lwjgl.opengl.GL11.glBlendFunc
import org.lwjgl.opengl.GL11.glClear
import org.lwjgl.opengl.GL11.glDepthFunc
import org.lwjgl.opengl.GL11.glEnable
import org.lwjgl.opengl.GL11.glLoadIdentity
import org.lwjgl.opengl.GL11.glMatrixMode
import org.lwjgl.opengl.GL11.*
import org.lwjgl.opengl.GL13.GL_MULTISAMPLE
import solve.rendering.engine.Window
import solve.rendering.engine.utils.minus
Expand All @@ -48,6 +34,7 @@ abstract class OpenGLCanvas {
glEnable(GL_DEPTH_TEST)
glEnable(GL_MULTISAMPLE)
glDepthFunc(GL_LEQUAL)
println("onInit ${glGetError()}")
}

open fun onDispose() { }
Expand All @@ -69,13 +56,15 @@ abstract class OpenGLCanvas {

private fun render(event: GLRenderEvent) {
glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT)
println("render ${glGetError()}")

onDraw(event.delta.toFloat())
}

private fun reshape(event: GLReshapeEvent) {
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
println("reshape ${glGetError()}")

val newWindowSize = Vector2i(event.width, event.height)
normalizeResizedCameraPosition(newWindowSize, window.size)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import kotlinx.coroutines.launch
import org.joml.Matrix4f
import org.joml.Vector2f
import org.joml.Vector2i
import org.lwjgl.opengl.GL11
import org.lwjgl.opengl.GL13.GL_TEXTURE0
import org.lwjgl.opengl.GL13.glActiveTexture
import solve.constants.ShadersFrameFragmentPath
Expand Down Expand Up @@ -103,6 +104,7 @@ class FramesRenderer(
shaderProgram.uploadFloat(TexturesRatioUniformName, framesRatio)
shaderProgram.uploadVector2f(CameraPositionUniformName, getScreenTopLeftGridCellPosition().toFloatVector())
shaderProgram.uploadFloat(FramesSpacingUniformName, FramesSpacing)
println("uploadUniforms ${GL11.glGetError()}")
}

override fun createNewBatch(zIndex: Int) =
Expand All @@ -115,6 +117,7 @@ class FramesRenderer(
}

glActiveTexture(GL_TEXTURE0)
println("updateBatchesData ${GL11.glGetError()}")
bufferFramesArrayTexture?.bind()
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package solve.rendering.engine.core.texture

import org.lwjgl.opengl.GL11
import org.lwjgl.opengl.GL11.GL_TEXTURE_WRAP_S
import org.lwjgl.opengl.GL11.GL_TEXTURE_WRAP_T
import org.lwjgl.opengl.GL11.GL_UNSIGNED_BYTE
Expand Down Expand Up @@ -32,6 +33,7 @@ class ArrayTexture(
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)
glGenerateMipmap(GL_TEXTURE_2D_ARRAY)
println("initializeTextureParams ${GL11.glGetError()}")
}

fun uploadTexture(textureData: Texture2DData, layerIndex: Int) {
Expand All @@ -53,6 +55,7 @@ class ArrayTexture(
GL_UNSIGNED_BYTE,
textureData.data
)
println("uploadTexture ${GL11.glGetError()}")
}

override fun initializeTexture() {
Expand All @@ -68,5 +71,6 @@ class ArrayTexture(
GL_UNSIGNED_BYTE,
null as ByteBuffer?
)
println("initializeTexture ${GL11.glGetError()}")
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package solve.rendering.engine.core.texture

import org.joml.Vector2f
import org.lwjgl.opengl.GL11
import org.lwjgl.opengl.GL11.GL_LINEAR
import org.lwjgl.opengl.GL11.GL_NEAREST
import org.lwjgl.opengl.GL11.GL_TEXTURE_MAG_FILTER
Expand Down Expand Up @@ -39,10 +40,12 @@ abstract class Texture(private val filterType: TextureFilterType = TextureFilter

fun bind() {
glBindTexture(textureOpenGLType, textureID)
println("bind ${GL11.glGetError()}")
}

fun unbind() {
glBindTexture(textureOpenGLType, 0)
println("unbind ${GL11.glGetError()}")
}

fun bindToSlot(unit: Int) {
Expand All @@ -52,18 +55,22 @@ abstract class Texture(private val filterType: TextureFilterType = TextureFilter
}

glActiveTexture(GL_TEXTURE0 + unit)
println("bindToSlot ${GL11.glGetError()}")
glBindTexture(textureOpenGLType, textureID)
println("bindToSlot ${GL11.glGetError()}")
}

fun delete() {
glDeleteTextures(textureID)
println("delete ${GL11.glGetError()}")
}

protected fun initialize() {
bind()
initializeTexture()
initializeTextureFilterParams()
initializeTextureParams()
println("initialize ${GL11.glGetError()}")
}

override fun equals(other: Any?): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import org.joml.Vector3i
import org.joml.Vector4f
import org.joml.Vector4i
import org.lwjgl.BufferUtils
import org.lwjgl.opengl.GL11.glGetError
import org.lwjgl.opengl.GL20.GL_COMPILE_STATUS
import org.lwjgl.opengl.GL20.GL_FALSE
import org.lwjgl.opengl.GL20.GL_INFO_LOG_LENGTH
Expand Down Expand Up @@ -69,6 +70,7 @@ class ShaderProgram {

fun link() {
glLinkProgram(shaderProgramID)
println("link ${glGetError()}")

val linkStatus = glGetProgrami(shaderProgramID, GL_LINK_STATUS)
if (linkStatus == GL_FALSE) {
Expand All @@ -91,6 +93,7 @@ class ShaderProgram {
}

glUseProgram(shaderProgramID)
println("use ${glGetError()}")
isUsed = true
}

Expand All @@ -100,24 +103,28 @@ class ShaderProgram {
}

glUseProgram(GL_FALSE)
println("detach ${glGetError()}")
isUsed = false
}

fun delete() {
detach()
if (shaderProgramID != GL_FALSE) {
glDeleteProgram(shaderProgramID)
println("delete ${glGetError()}")
}
}

fun uploadInt(variableName: String, value: Int) {
val variableLocation = getVariableLocationWithUse(variableName)
glUniform1i(variableLocation, value)
println("uploadInt ${glGetError()}")
}

fun uploadFloat(variableName: String, value: Float) {
val variableLocation = getVariableLocationWithUse(variableName)
glUniform1f(variableLocation, value)
println("uploadFloat ${glGetError()}")
}

fun uploadVector2f(variableName: String, vector: Vector2f) {
Expand Down

0 comments on commit 77fa74c

Please sign in to comment.