Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mi-sts committed Nov 19, 2023
1 parent d8785d8 commit ae76a86
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class FramesRenderer(
get() = (frames.count().toFloat() / gridWidth).ceilToInt()
private var buffersSize = defaultBuffersSize

private lateinit var bufferFramesArrayTexture: ArrayTexture
private var bufferFramesArrayTexture: ArrayTexture? = null

private var frames = emptyList<VisualizationFrame>()
private var framesWidth = 1
Expand Down Expand Up @@ -99,15 +99,19 @@ class FramesRenderer(
if (frames.isEmpty())
return

if (needToReinitializeBuffers) {
initializeTexturesBuffers(frames)
needToReinitializeBuffers = false
}
if (needToReinitializeBuffers)
reinitializeBuffers()

uploadLoadedFramesToBuffers()
updateBuffersTextures()
}

private fun reinitializeBuffers() {
bufferFramesArrayTexture?.delete()
initializeTexturesBuffers(frames)
needToReinitializeBuffers = false
}

private fun changeSceneFrames(frames: List<VisualizationFrame>) {
if (frames.isEmpty()) {
return
Expand All @@ -119,7 +123,7 @@ class FramesRenderer(

private fun uploadLoadedFramesToBuffers() {
bufferFramesToUpload.toList().forEach { frame ->
bufferFramesArrayTexture.uploadTexture(frame.textureData, frame.bufferIndex)
bufferFramesArrayTexture?.uploadTexture(frame.textureData, frame.bufferIndex)
bufferFramesToUpload.remove(frame)
Texture2D.freeData(frame.textureData)
}
Expand Down Expand Up @@ -222,7 +226,8 @@ class FramesRenderer(
framesHeight = firstTextureData.height
framesChannelsType = firstTextureData.channelsType

bufferFramesArrayTexture = ArrayTexture(framesWidth, framesHeight, framesChannelsType, maxBatchSize)
bufferFramesArrayTexture =
ArrayTexture(framesWidth, framesHeight, framesChannelsType, buffersSize.x * buffersSize.y)

uploadInitialFramesToBuffer()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package solve.rendering.engine.rendering.texture

import org.lwjgl.opengl.GL11.glBindTexture
import org.lwjgl.opengl.GL11.glDeleteTextures
import org.lwjgl.opengl.GL11.glGenTextures
import org.lwjgl.opengl.GL13
import org.lwjgl.opengl.GL13.GL_TEXTURE0
Expand Down Expand Up @@ -38,6 +39,10 @@ abstract class Texture {
glBindTexture(textureOpenGLType, textureID)
}

fun delete() {
glDeleteTextures(textureID)
}

protected fun initialize() {
bind()
initializeTexture()
Expand Down

0 comments on commit ae76a86

Please sign in to comment.