Skip to content
This repository has been archived by the owner on Aug 12, 2022. It is now read-only.

Commit

Permalink
Fix Static shader batch fails after delete then upload
Browse files Browse the repository at this point in the history
Closes #257
  • Loading branch information
nbilyk committed Feb 19, 2020
1 parent 4c227e8 commit 672a621
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package com.acornui.component.drawing

import com.acornui.collection.forEach2
import com.acornui.component.*
import com.acornui.di.Context
import com.acornui.di.ContextImpl
Expand Down Expand Up @@ -224,7 +223,7 @@ class StaticMesh(
textures.forEach {
it.refInc()
}
oldTextures.forEach2 {
oldTextures.forEach {
it.refDec()
}
oldTextures.clear()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ open class ShaderBatchImpl(
*/
constructor(gl: CachedGl20, isDynamic: Boolean = true) : this(gl.wrapped, isDynamic)

init {
require(gl !is CachedGl20) { "ShaderBatchImpl requires either the unwrapped Gl20 instance or use the CachedGl20 constructor" }
}

override val vertexAttributes: VertexAttributes = standardVertexAttributes

/**
Expand Down Expand Up @@ -178,15 +182,19 @@ open class ShaderBatchImpl(
flush()
gl.bindBuffer(Gl20.ARRAY_BUFFER, vertexComponentsBuffer)
gl.bindBuffer(Gl20.ELEMENT_ARRAY_BUFFER, indicesBuffer)
indices.mark()
indices.flip()
gl.bufferData(Gl20.ELEMENT_ARRAY_BUFFER, indices.limit shl 1, usage) // Allocate
gl.bufferDatasv(Gl20.ELEMENT_ARRAY_BUFFER, indices, usage) // Upload
indices.reset()

vertexComponents.mark()
vertexComponents.flip()
gl.bufferData(Gl20.ARRAY_BUFFER, vertexComponents.limit shl 2, usage) // Allocate
gl.bufferDatafv(Gl20.ARRAY_BUFFER, vertexComponents, usage) // Upload
gl.bindBuffer(Gl20.ARRAY_BUFFER, null)
gl.bindBuffer(Gl20.ELEMENT_ARRAY_BUFFER, null)
vertexComponents.reset()
}

/**
Expand Down

0 comments on commit 672a621

Please sign in to comment.