Skip to content

Commit aec8e61

Browse files
author
Your Name
committed
Change buffer upload logic
1 parent 26ba2ba commit aec8e61

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

worldwind/src/commonMain/kotlin/earth/worldwind/render/RenderContext.kt

+5-2
Original file line numberDiff line numberDiff line change
@@ -340,8 +340,11 @@ open class RenderContext {
340340
} else null
341341
}
342342

343-
fun offerBufferUpload(buffer : GLBufferObject, array: NumericArray) {
344-
uploadQueue?.queueBufferUpload(buffer, array)
343+
fun offerGLBufferUpload(key: Any, array: NumericArray) {
344+
renderResourceCache[key].also {
345+
uploadQueue?.queueBufferUpload(it as GLBufferObject, array)
346+
renderResourceCache.updateSize(key, array.byteCount)
347+
}
345348
}
346349

347350
fun offerBackgroundDrawable(drawable: Drawable) {

worldwind/src/commonMain/kotlin/earth/worldwind/shape/Path.kt

+12-8
Original file line numberDiff line numberDiff line change
@@ -103,18 +103,20 @@ open class Path @JvmOverloads constructor(
103103
// Assemble the drawable's OpenGL vertex buffer object.
104104
drawState.tmpVertexBuffer = rc.getGLBufferObject(vertexBufferKey) {
105105
GLBufferObject(GL_ARRAY_BUFFER, 0)
106-
}.also { if(reassembleGeometry) rc.offerBufferUpload(it, NumericArray.Floats(vertexArray)) }
106+
}
107+
if(reassembleGeometry) { rc.offerGLBufferUpload(vertexBufferKey, NumericArray.Floats(vertexArray)) }
107108

108109
// Assemble the drawable's OpenGL element buffer object.
109110
drawState.tmpElementBuffer = rc.getGLBufferObject(elementBufferKey) {
110111
GLBufferObject(GL_ELEMENT_ARRAY_BUFFER, 0)
111-
}.also { if(reassembleGeometry) {
112+
}
113+
if(reassembleGeometry) {
112114
val array = IntArray(outlineElements.size + verticalElements.size)
113115
var index = 0
114116
for (element in outlineElements) array[index++] = element
115117
for (element in verticalElements) array[index++] = element
116-
rc.offerBufferUpload(it, NumericArray.Ints(array))
117-
} }
118+
rc.offerGLBufferUpload(elementBufferKey, NumericArray.Ints(array))
119+
}
118120

119121
// Configure the drawable to use the outline texture when drawing the outline.
120122
if (activeAttributes.isDrawOutline) {
@@ -178,17 +180,19 @@ open class Path @JvmOverloads constructor(
178180
// Assemble the drawable's OpenGL vertex buffer object.
179181
drawStateExtrusion.tmpVertexBuffer = rc.getGLBufferObject(extrudeVertexBufferKey) {
180182
GLBufferObject(GL_ARRAY_BUFFER, 0)
181-
}.also { if(reassembleGeometry) rc.offerBufferUpload(it, NumericArray.Floats(extrudeVertexArray)) }
183+
}
184+
if (reassembleGeometry) { rc.offerGLBufferUpload(extrudeVertexBufferKey, NumericArray.Floats(extrudeVertexArray)) }
182185

183186
// Assemble the drawable's OpenGL element buffer object.
184187
drawStateExtrusion.tmpElementBuffer = rc.getGLBufferObject(extrudeElementBufferKey) {
185188
GLBufferObject(GL_ELEMENT_ARRAY_BUFFER, 0)
186-
}.also { if(reassembleGeometry) {
189+
}
190+
if (reassembleGeometry) {
187191
val array = IntArray(interiorElements.size)
188192
var index = 0
189193
for (element in interiorElements) array[index++] = element
190-
rc.offerBufferUpload(it, NumericArray.Ints(array))
191-
} }
194+
rc.offerGLBufferUpload(extrudeElementBufferKey, NumericArray.Ints(array))
195+
}
192196

193197
drawStateExtrusion.color(if (rc.isPickMode) pickColor else activeAttributes.interiorColor)
194198
drawStateExtrusion.opacity(if (rc.isPickMode) 1f else rc.currentLayer.opacity)

0 commit comments

Comments
 (0)