diff --git a/kool-core/src/commonMain/kotlin/de/fabmax/kool/modules/ksl/blocks/CameraData.kt b/kool-core/src/commonMain/kotlin/de/fabmax/kool/modules/ksl/blocks/CameraData.kt index f66cafa3b..ef71eaf65 100644 --- a/kool-core/src/commonMain/kotlin/de/fabmax/kool/modules/ksl/blocks/CameraData.kt +++ b/kool-core/src/commonMain/kotlin/de/fabmax/kool/modules/ksl/blocks/CameraData.kt @@ -2,11 +2,7 @@ package de.fabmax.kool.modules.ksl.blocks import de.fabmax.kool.modules.ksl.KslShaderListener import de.fabmax.kool.modules.ksl.lang.* -import de.fabmax.kool.pipeline.BindGroupScope -import de.fabmax.kool.pipeline.BufferPosition -import de.fabmax.kool.pipeline.ShaderBase -import de.fabmax.kool.pipeline.UniformBufferLayout -import de.fabmax.kool.pipeline.DrawCommand +import de.fabmax.kool.pipeline.* import de.fabmax.kool.util.positioned fun KslProgram.cameraData(): CameraData { @@ -72,9 +68,8 @@ class CameraData(program: KslProgram) : KslDataBlock, KslShaderListener { } override fun onUpdate(cmd: DrawCommand) { - val pipeline = cmd.pipeline ?: return val bindingLayout = uboLayout ?: return - val viewData = cmd.queue.view.viewPipelineData.getPipelineDataUpdating(pipeline, bindingLayout.bindingIndex) ?: return + val viewData = cmd.queue.view.viewPipelineData.getPipelineDataUpdating(cmd.pipeline, bindingLayout.bindingIndex) ?: return val q = cmd.queue val vp = q.view.viewport diff --git a/kool-core/src/commonMain/kotlin/de/fabmax/kool/modules/ksl/blocks/MeshMatrixData.kt b/kool-core/src/commonMain/kotlin/de/fabmax/kool/modules/ksl/blocks/MeshMatrixData.kt index e1f942c19..2d8d24352 100644 --- a/kool-core/src/commonMain/kotlin/de/fabmax/kool/modules/ksl/blocks/MeshMatrixData.kt +++ b/kool-core/src/commonMain/kotlin/de/fabmax/kool/modules/ksl/blocks/MeshMatrixData.kt @@ -7,7 +7,6 @@ import de.fabmax.kool.math.toMutableMat4f import de.fabmax.kool.modules.ksl.KslShaderListener import de.fabmax.kool.modules.ksl.lang.* import de.fabmax.kool.pipeline.* -import de.fabmax.kool.pipeline.DrawCommand fun KslProgram.mvpMatrix(): MvpMatrixData { return (dataBlocks.find { it is MvpMatrixData } as? MvpMatrixData) ?: MvpMatrixData(this) @@ -57,8 +56,6 @@ class MvpMatrixData(program: KslProgram) : MeshMatrixData(program, "uMvpMat") { private val tmpMat4f = MutableMat4f() override fun onUpdate(cmd: DrawCommand) { - val pipeline = cmd.pipeline ?: return - // Do not use getPipelineDataUpdating() here: MVP matrix needs to be always updated, in case this mesh / // pipeline combination is drawn in multiple views with different view matrices. // @@ -66,7 +63,7 @@ class MvpMatrixData(program: KslProgram) : MeshMatrixData(program, "uMvpMat") { // views. This is currently the case but might change in future. In that case, using a precomputed MVP matrix // would not be possible anymore (work around: use separate model and view matrices and multiply them in // the vertex shader) - val uboData = cmd.mesh.meshPipelineData.getPipelineData(pipeline) + val uboData = cmd.mesh.meshPipelineData.getPipelineData(cmd.pipeline) if (cmd.queue.isDoublePrecision) { cmd.queue.viewProjMatD.mul(cmd.modelMatD, tmpMat4d) @@ -88,9 +85,8 @@ class ModelMatrixData(program: KslProgram) : MeshMatrixData(program, "uModelMat" private val tmpMat4f = MutableMat4f() override fun onUpdate(cmd: DrawCommand) { - val pipeline = cmd.pipeline ?: return val bindingLayout = uboLayout ?: return - val uboData = cmd.mesh.meshPipelineData.getPipelineDataUpdating(pipeline, bindingLayout.bindingIndex) ?: return + val uboData = cmd.mesh.meshPipelineData.getPipelineDataUpdating(cmd.pipeline, bindingLayout.bindingIndex) ?: return if (cmd.queue.isDoublePrecision) { cmd.modelMatD.toMutableMat4f(tmpMat4f) diff --git a/kool-core/src/commonMain/kotlin/de/fabmax/kool/modules/ksl/blocks/SceneLightData.kt b/kool-core/src/commonMain/kotlin/de/fabmax/kool/modules/ksl/blocks/SceneLightData.kt index 3627bf33c..53b855ade 100644 --- a/kool-core/src/commonMain/kotlin/de/fabmax/kool/modules/ksl/blocks/SceneLightData.kt +++ b/kool-core/src/commonMain/kotlin/de/fabmax/kool/modules/ksl/blocks/SceneLightData.kt @@ -2,11 +2,7 @@ package de.fabmax.kool.modules.ksl.blocks import de.fabmax.kool.modules.ksl.KslShaderListener import de.fabmax.kool.modules.ksl.lang.* -import de.fabmax.kool.pipeline.BindGroupScope -import de.fabmax.kool.pipeline.BufferPosition -import de.fabmax.kool.pipeline.ShaderBase -import de.fabmax.kool.pipeline.UniformBufferLayout -import de.fabmax.kool.pipeline.DrawCommand +import de.fabmax.kool.pipeline.* import de.fabmax.kool.util.positioned import kotlin.math.min @@ -51,9 +47,8 @@ class SceneLightData(program: KslProgram, val maxLightCount: Int) : KslDataBlock } override fun onUpdate(cmd: DrawCommand) { - val pipeline = cmd.pipeline ?: return val bindingLayout = uboLayout ?: return - val viewData = cmd.queue.view.viewPipelineData.getPipelineDataUpdating(pipeline, bindingLayout.bindingIndex) ?: return + val viewData = cmd.queue.view.viewPipelineData.getPipelineDataUpdating(cmd.pipeline, bindingLayout.bindingIndex) ?: return val ubo = viewData.uniformBufferBindingData(bindingLayout.bindingIndex) val lighting = cmd.queue.renderPass.lighting diff --git a/kool-core/src/commonMain/kotlin/de/fabmax/kool/pipeline/DepthMapPass.kt b/kool-core/src/commonMain/kotlin/de/fabmax/kool/pipeline/DepthMapPass.kt index 989ed4382..0995ea1b3 100644 --- a/kool-core/src/commonMain/kotlin/de/fabmax/kool/pipeline/DepthMapPass.kt +++ b/kool-core/src/commonMain/kotlin/de/fabmax/kool/pipeline/DepthMapPass.kt @@ -36,22 +36,28 @@ open class DepthMapPass( } protected open fun setupDrawCommand(cmd: DrawCommand, updateEvent: UpdateEvent) { - cmd.pipeline = getDepthPipeline(cmd.mesh, updateEvent) + val pipeline = getDepthPipeline(cmd.mesh, updateEvent) + if (pipeline == null) { + cmd.isActive = false + } else { + cmd.pipeline = pipeline + } } protected open fun getDepthPipeline(mesh: Mesh, updateEvent: UpdateEvent): DrawPipeline? { - if (!mesh.geometry.hasAttribute(Attribute.POSITIONS)) { - return null - } return shadowPipelines.getOrPut(mesh.id) { val depthShader = mesh.depthShader ?: mesh.depthShaderConfig?.let { cfg -> DepthShader(cfg.copy(outputLinearDepth = false, outputNormals = false)) } ?: defaultDepthShader(mesh, updateEvent) - depthShader.getOrCreatePipeline(mesh, updateEvent) + depthShader?.getOrCreatePipeline(mesh, updateEvent) } } - private fun defaultDepthShader(mesh: Mesh, updateEvent: UpdateEvent): DepthShader { + private fun defaultDepthShader(mesh: Mesh, updateEvent: UpdateEvent): DepthShader? { + if (!mesh.geometry.hasAttribute(Attribute.POSITIONS)) { + return null + } + val cfg = DepthShader.Config.forMesh(mesh, getMeshCullMethod(mesh, updateEvent)) val key = DepthShaderKey( vertexLayout = mesh.geometry.vertexAttributes, @@ -101,18 +107,19 @@ class NormalLinearDepthMapPass( } override fun getDepthPipeline(mesh: Mesh, updateEvent: UpdateEvent): DrawPipeline? { - if (!mesh.geometry.hasAttribute(Attribute.POSITIONS) || !mesh.geometry.hasAttribute(Attribute.NORMALS)) { - return null - } return shadowPipelines.getOrPut(mesh.id) { val depthShader = mesh.normalLinearDepthShader ?: mesh.depthShaderConfig?.let { cfg -> DepthShader(cfg.copy(outputLinearDepth = true, outputNormals = true)) } ?: defaultDepthShader(mesh, updateEvent) - depthShader.getOrCreatePipeline(mesh, updateEvent) + depthShader?.getOrCreatePipeline(mesh, updateEvent) } } - private fun defaultDepthShader(mesh: Mesh, updateEvent: UpdateEvent): DepthShader { + private fun defaultDepthShader(mesh: Mesh, updateEvent: UpdateEvent): DepthShader? { + if (!mesh.geometry.hasAttribute(Attribute.POSITIONS) || !mesh.geometry.hasAttribute(Attribute.NORMALS)) { + return null + } + val cfg = DepthShader.Config.forMesh(mesh, getMeshCullMethod(mesh, updateEvent)).copy( outputLinearDepth = true, outputNormals = true diff --git a/kool-core/src/commonMain/kotlin/de/fabmax/kool/pipeline/DrawCommand.kt b/kool-core/src/commonMain/kotlin/de/fabmax/kool/pipeline/DrawCommand.kt index 26e3a08e7..48998a1a8 100644 --- a/kool-core/src/commonMain/kotlin/de/fabmax/kool/pipeline/DrawCommand.kt +++ b/kool-core/src/commonMain/kotlin/de/fabmax/kool/pipeline/DrawCommand.kt @@ -5,7 +5,7 @@ import de.fabmax.kool.math.Mat4f import de.fabmax.kool.scene.Mesh import de.fabmax.kool.scene.geometry.IndexedVertexList -class DrawCommand(val queue: DrawQueue, mesh: Mesh) { +class DrawCommand(val queue: DrawQueue, mesh: Mesh, var pipeline: DrawPipeline) { var mesh: Mesh = mesh private set @@ -13,7 +13,8 @@ class DrawCommand(val queue: DrawQueue, mesh: Mesh) { private set var geometry: IndexedVertexList = mesh.geometry - var pipeline: DrawPipeline? = null + + var isActive = true /** * Single precision model matrix of this command's [mesh]. @@ -25,10 +26,11 @@ class DrawCommand(val queue: DrawQueue, mesh: Mesh) { */ val modelMatD: Mat4d get() = mesh.modelMatD - fun setup(mesh: Mesh, drawGroupId: Int, updateEvent: RenderPass.UpdateEvent) { + fun setup(mesh: Mesh, pipeline: DrawPipeline, drawGroupId: Int) { this.mesh = mesh + this.pipeline = pipeline this.drawGroupId = drawGroupId geometry = mesh.geometry - pipeline = mesh.getOrCreatePipeline(updateEvent) + isActive = true } } \ No newline at end of file diff --git a/kool-core/src/commonMain/kotlin/de/fabmax/kool/pipeline/DrawQueue.kt b/kool-core/src/commonMain/kotlin/de/fabmax/kool/pipeline/DrawQueue.kt index d6b7c92d8..bd3c5c17f 100644 --- a/kool-core/src/commonMain/kotlin/de/fabmax/kool/pipeline/DrawQueue.kt +++ b/kool-core/src/commonMain/kotlin/de/fabmax/kool/pipeline/DrawQueue.kt @@ -115,13 +115,13 @@ class DrawQueue(val renderPass: RenderPass, val view: RenderPass.View) { return prevQueue } - fun addMesh(mesh: Mesh, updateEvent: RenderPass.UpdateEvent): DrawCommand { + fun addMesh(mesh: Mesh, pipeline: DrawPipeline): DrawCommand { val cmd = if (commandPool.isNotEmpty()) { commandPool.removeAt(commandPool.lastIndex) } else { - DrawCommand(this, mesh) + DrawCommand(this, mesh, pipeline) } - cmd.setup(mesh, drawGroupId, updateEvent) + cmd.setup(mesh, pipeline, drawGroupId) getOrderedQueue().commands.add(cmd) return cmd } diff --git a/kool-core/src/commonMain/kotlin/de/fabmax/kool/pipeline/backend/gl/CompiledDrawShader.kt b/kool-core/src/commonMain/kotlin/de/fabmax/kool/pipeline/backend/gl/CompiledDrawShader.kt index f81023a02..4fe059c22 100644 --- a/kool-core/src/commonMain/kotlin/de/fabmax/kool/pipeline/backend/gl/CompiledDrawShader.kt +++ b/kool-core/src/commonMain/kotlin/de/fabmax/kool/pipeline/backend/gl/CompiledDrawShader.kt @@ -1,10 +1,6 @@ package de.fabmax.kool.pipeline.backend.gl -import de.fabmax.kool.pipeline.DrawPipeline -import de.fabmax.kool.pipeline.InputRate -import de.fabmax.kool.pipeline.PipelineBackend -import de.fabmax.kool.pipeline.VertexLayout -import de.fabmax.kool.pipeline.DrawCommand +import de.fabmax.kool.pipeline.* import de.fabmax.kool.scene.Mesh import de.fabmax.kool.scene.geometry.PrimitiveType @@ -98,7 +94,6 @@ class CompiledDrawShader(val pipeline: DrawPipeline, program: GlProgram, backend } fun bindMesh(cmd: DrawCommand): DrawInfo { - val pipeline = cmd.pipeline!! val geom = getOrCreateGpuGeometry(cmd) users.add(cmd.mesh.id) diff --git a/kool-core/src/commonMain/kotlin/de/fabmax/kool/pipeline/backend/gl/GlRenderPass.kt b/kool-core/src/commonMain/kotlin/de/fabmax/kool/pipeline/backend/gl/GlRenderPass.kt index 2a05c8a79..a9e341d54 100644 --- a/kool-core/src/commonMain/kotlin/de/fabmax/kool/pipeline/backend/gl/GlRenderPass.kt +++ b/kool-core/src/commonMain/kotlin/de/fabmax/kool/pipeline/backend/gl/GlRenderPass.kt @@ -76,12 +76,12 @@ abstract class GlRenderPass(val backend: RenderBackendGl) { } } - cmd.pipeline?.let { pipeline -> + if (cmd.isActive) { val drawInfo = backend.shaderMgr.bindDrawShader(cmd) val isValid = cmd.geometry.numIndices > 0 && drawInfo.isValid && drawInfo.numIndices > 0 if (isValid) { - GlState.setupPipelineAttribs(pipeline, view.renderPass.isReverseDepth, gl) + GlState.setupPipelineAttribs(cmd.pipeline, view.renderPass.isReverseDepth, gl) val insts = cmd.mesh.instances if (insts == null) { diff --git a/kool-core/src/commonMain/kotlin/de/fabmax/kool/pipeline/backend/gl/ShaderManager.kt b/kool-core/src/commonMain/kotlin/de/fabmax/kool/pipeline/backend/gl/ShaderManager.kt index c28f9e881..cbe56b093 100644 --- a/kool-core/src/commonMain/kotlin/de/fabmax/kool/pipeline/backend/gl/ShaderManager.kt +++ b/kool-core/src/commonMain/kotlin/de/fabmax/kool/pipeline/backend/gl/ShaderManager.kt @@ -12,8 +12,7 @@ class ShaderManager(val backend: RenderBackendGl) { private val glComputePrograms = mutableMapOf() fun bindDrawShader(cmd: DrawCommand): CompiledDrawShader.DrawInfo { - val pipeline = checkNotNull(cmd.pipeline) - val shader = pipeline.getCompiledShader() + val shader = cmd.pipeline.getCompiledShader() val current = boundShader as? CompiledDrawShader if (shader.program != current?.program) { diff --git a/kool-core/src/commonMain/kotlin/de/fabmax/kool/pipeline/deferred/DeferredCamData.kt b/kool-core/src/commonMain/kotlin/de/fabmax/kool/pipeline/deferred/DeferredCamData.kt index cd50912e9..b743fa0a6 100644 --- a/kool-core/src/commonMain/kotlin/de/fabmax/kool/pipeline/deferred/DeferredCamData.kt +++ b/kool-core/src/commonMain/kotlin/de/fabmax/kool/pipeline/deferred/DeferredCamData.kt @@ -2,11 +2,7 @@ package de.fabmax.kool.pipeline.deferred import de.fabmax.kool.modules.ksl.KslShaderListener import de.fabmax.kool.modules.ksl.lang.* -import de.fabmax.kool.pipeline.BindGroupScope -import de.fabmax.kool.pipeline.BufferPosition -import de.fabmax.kool.pipeline.ShaderBase -import de.fabmax.kool.pipeline.UniformBufferLayout -import de.fabmax.kool.pipeline.DrawCommand +import de.fabmax.kool.pipeline.* import de.fabmax.kool.util.positioned fun KslProgram.deferredCameraData(): DeferredCamData { @@ -56,12 +52,11 @@ class DeferredCamData(program: KslProgram) : KslDataBlock, KslShaderListener { val q = cmd.queue val vp = q.view.viewport val cam = q.view.camera - val pipeline = cmd.pipeline val bindingLayout = uboLayout - if (pipeline != null && bindingLayout != null) { + if (bindingLayout != null) { val uboData = cmd.queue.view.viewPipelineData - .getPipelineData(pipeline) + .getPipelineData(cmd.pipeline) .uniformBufferBindingData(bindingLayout.bindingIndex) uboData.isBufferDirty = true diff --git a/kool-core/src/commonMain/kotlin/de/fabmax/kool/pipeline/deferred/PbrLightingPass.kt b/kool-core/src/commonMain/kotlin/de/fabmax/kool/pipeline/deferred/PbrLightingPass.kt index 51d2167cd..482502b2a 100644 --- a/kool-core/src/commonMain/kotlin/de/fabmax/kool/pipeline/deferred/PbrLightingPass.kt +++ b/kool-core/src/commonMain/kotlin/de/fabmax/kool/pipeline/deferred/PbrLightingPass.kt @@ -26,7 +26,10 @@ class PbrLightingPass(pipeline: DeferredPipeline, suffix: String, val materialPa scene.mainRenderPass.onAfterCollectDrawCommands += { ev -> if (isEnabled) { for (i in materialPass.alphaMeshes.indices) { - scene.mainRenderPass.screenView.drawQueue.addMesh(materialPass.alphaMeshes[i], ev) + val mesh = materialPass.alphaMeshes[i] + mesh.getOrCreatePipeline(ev)?.let { pipeline -> + scene.mainRenderPass.screenView.drawQueue.addMesh(mesh, pipeline) + } } } } diff --git a/kool-core/src/commonMain/kotlin/de/fabmax/kool/scene/Mesh.kt b/kool-core/src/commonMain/kotlin/de/fabmax/kool/scene/Mesh.kt index 79a25c1d3..a3f6292e7 100644 --- a/kool-core/src/commonMain/kotlin/de/fabmax/kool/scene/Mesh.kt +++ b/kool-core/src/commonMain/kotlin/de/fabmax/kool/scene/Mesh.kt @@ -228,7 +228,10 @@ open class Mesh( } rayTest.onMeshDataChanged(this) } - updateEvent.view.drawQueue.addMesh(this, updateEvent) + + getOrCreatePipeline(updateEvent)?.let { pipeline -> + updateEvent.view.drawQueue.addMesh(this, pipeline) + } } companion object { diff --git a/kool-core/src/desktopMain/kotlin/de/fabmax/kool/pipeline/backend/vk/VkRenderBackend.kt b/kool-core/src/desktopMain/kotlin/de/fabmax/kool/pipeline/backend/vk/VkRenderBackend.kt index a8ada8bc0..9f192f58f 100644 --- a/kool-core/src/desktopMain/kotlin/de/fabmax/kool/pipeline/backend/vk/VkRenderBackend.kt +++ b/kool-core/src/desktopMain/kotlin/de/fabmax/kool/pipeline/backend/vk/VkRenderBackend.kt @@ -349,7 +349,7 @@ class VkRenderBackend(val ctx: Lwjgl3Context) : RenderBackendJvm { var prevPipeline = 0L drawQueue.forEach { cmd -> val pipelineCfg = cmd.pipeline - if (!cmd.mesh.geometry.isEmpty() && pipelineCfg != null) { + if (!cmd.mesh.geometry.isEmpty()) { pipelineCfg.update(cmd) if (!sys.pipelineManager.hasPipeline(pipelineCfg, renderPass.vkRenderPass)) { diff --git a/kool-core/src/desktopMain/kotlin/de/fabmax/kool/pipeline/backend/vk/pipeline/DescriptorObject.kt b/kool-core/src/desktopMain/kotlin/de/fabmax/kool/pipeline/backend/vk/pipeline/DescriptorObject.kt index f0bc5b913..b3e409f23 100644 --- a/kool-core/src/desktopMain/kotlin/de/fabmax/kool/pipeline/backend/vk/pipeline/DescriptorObject.kt +++ b/kool-core/src/desktopMain/kotlin/de/fabmax/kool/pipeline/backend/vk/pipeline/DescriptorObject.kt @@ -59,7 +59,7 @@ class UboDescriptor(binding: Int, graphicsPipeline: GraphicsPipeline, private va } override fun update(cmd: DrawCommand, sys: VkSystem) { - val hostBuffer = cmd.pipeline!!.pipelineData.uniformBufferBindingData(binding).buffer as MixedBufferImpl + val hostBuffer = cmd.pipeline.pipelineData.uniformBufferBindingData(binding).buffer as MixedBufferImpl hostBuffer.useRaw { host -> buffer.mapped { put(host) } } @@ -85,7 +85,7 @@ class SamplerDescriptor private constructor(binding: Int, private val sampler: T override fun setDescriptorSet(stack: MemoryStack, vkWriteDescriptorSet: VkWriteDescriptorSet, dstSet: Long, cmd: DrawCommand) { stack.apply { - val textures = sampler.getTextures(cmd.pipeline!!.pipelineData) + val textures = sampler.getTextures(cmd.pipeline.pipelineData) val imageInfo = callocVkDescriptorImageInfoN(sampler.arraySize) { for (i in 0 until sampler.arraySize) { this[i].apply { @@ -118,7 +118,7 @@ class SamplerDescriptor private constructor(binding: Int, private val sampler: T } } - val textures = sampler.getTextures(cmd.pipeline!!.pipelineData) + val textures = sampler.getTextures(cmd.pipeline.pipelineData) var allValid = true if (boundTex.size != sampler.arraySize) { diff --git a/kool-core/src/jsMain/kotlin/de/fabmax/kool/pipeline/backend/webgpu/WgpuPipelineManager.kt b/kool-core/src/jsMain/kotlin/de/fabmax/kool/pipeline/backend/webgpu/WgpuPipelineManager.kt index 1d50a7e9d..1f2a1b5f3 100644 --- a/kool-core/src/jsMain/kotlin/de/fabmax/kool/pipeline/backend/webgpu/WgpuPipelineManager.kt +++ b/kool-core/src/jsMain/kotlin/de/fabmax/kool/pipeline/backend/webgpu/WgpuPipelineManager.kt @@ -9,9 +9,8 @@ class WgpuPipelineManager(val backend: RenderBackendWebGpu) { private val computeShaderModules = mutableMapOf() fun bindDrawPipeline(cmd: DrawCommand, passEncoderState: RenderPassEncoderState<*>): Boolean { - val drawPipeline = cmd.pipeline!! - val gpuPipeline = drawPipeline.getWgpuPipeline() - drawPipeline.update(cmd) + val gpuPipeline = cmd.pipeline.getWgpuPipeline() + cmd.pipeline.update(cmd) return gpuPipeline.bind(cmd, passEncoderState) } diff --git a/kool-core/src/jsMain/kotlin/de/fabmax/kool/pipeline/backend/webgpu/WgpuRenderPass.kt b/kool-core/src/jsMain/kotlin/de/fabmax/kool/pipeline/backend/webgpu/WgpuRenderPass.kt index 3b0730772..73c1f478e 100644 --- a/kool-core/src/jsMain/kotlin/de/fabmax/kool/pipeline/backend/webgpu/WgpuRenderPass.kt +++ b/kool-core/src/jsMain/kotlin/de/fabmax/kool/pipeline/backend/webgpu/WgpuRenderPass.kt @@ -98,7 +98,7 @@ abstract class WgpuRenderPass( } } - val isCmdValid = cmd.pipeline != null && cmd.geometry.numIndices > 0 + val isCmdValid = cmd.isActive && cmd.geometry.numIndices > 0 if (isCmdValid && backend.pipelineManager.bindDrawPipeline(cmd, passEncoderState)) { val insts = cmd.mesh.instances if (insts == null) { diff --git a/kool-editor/src/commonMain/kotlin/de/fabmax/kool/editor/overlays/SelectionOverlay.kt b/kool-editor/src/commonMain/kotlin/de/fabmax/kool/editor/overlays/SelectionOverlay.kt index 1155c880e..787f5d44a 100644 --- a/kool-editor/src/commonMain/kotlin/de/fabmax/kool/editor/overlays/SelectionOverlay.kt +++ b/kool-editor/src/commonMain/kotlin/de/fabmax/kool/editor/overlays/SelectionOverlay.kt @@ -107,11 +107,12 @@ class SelectionOverlay(editor: KoolEditor) : Node("Selection overlay") { } private fun setupDrawCommand(i: Int, cmd: DrawCommand, updateEvent: UpdateEvent) { - cmd.pipeline = null + cmd.isActive = false if (cmd.mesh in meshSelection) { getPipeline(cmd.mesh, updateEvent)?.let { (shader, pipeline) -> shader.color = selectionColors[i % selectionColors.size] cmd.pipeline = pipeline + cmd.isActive = true } } }