All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.dsl.compute.SharedMemory.kt Maven / Gradle / Ivy

package org.openrndr.orsl.shadergenerator.phrases.dsl.compute

import org.openrndr.orsl.shadergenerator.compute.ComputeTransformBuilder
import org.openrndr.orsl.shadergenerator.dsl.*
import kotlin.reflect.KProperty

class SharedMemoryVariableProperty(val generator: Generator, val type:String) {
    operator fun provideDelegate(any: Any?, property: KProperty<*>) : SharedMemoryVariableProperty {
        generator.emitPreamble("shared ${type} ${property.name};")
        return this
    }
    operator fun getValue(any: Any?, property: KProperty<*>): Symbol = symbol(property.name, type)

    operator fun setValue(any: Any?, property: KProperty<*>, value: Symbol) {
        activeGenerator().emit("${property.name} = ${value.name};")
    }
}

class SharedMemoryArrayVariableProperty(val generator: Generator, val length: Int, val type:String) {
    operator fun provideDelegate(any: Any?, property: KProperty<*>) : SharedMemoryArrayVariableProperty {
        generator.emitPreamble("shared ${type}[$length] ${property.name};")
        return this
    }

    operator fun getValue(any: Any?, property: KProperty<*>): ArraySymbol {
        return object : ArraySymbol {
            override val name: String
                get() = property.name
            override val length: Int = [email protected]
            override val type = [email protected]
        }
    }



    operator fun setValue(any: Any?, property: KProperty<*>, value: Symbol) {
        activeGenerator().emit("${property.name} = ${value.name};")
    }
}

inline fun  ComputeTransformBuilder.sharedMemoryVariable(): SharedMemoryVariableProperty {
    val glslType = staticType()
    return SharedMemoryVariableProperty(this@sharedMemoryVariable, glslType)
}

inline fun  ComputeTransformBuilder.sharedMemoryArray(length: Int): SharedMemoryArrayVariableProperty {
    val glslType = staticType()
    return SharedMemoryArrayVariableProperty(this@sharedMemoryArray, length, glslType)
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy