A simple and safer AGSL wrapper library for compose functions that is generated by ksp.
AGSL is a shader that defines the behavior of programmable shader objects. When we use the AGSL, passing the raw string directly. It has a potential of runtime crash. Spider will care that situations.
- Add dependency of this library.
build.gradle.kts
plugins {
id("com.google.devtools.ksp").version("1.7.21-1.0.8")
}
android {
sourceSets {
getByName("debug") {
kotlin.srcDirs("build/generated/ksp/debug/kotlin")
}
getByName("release") {
kotlin.srcDirs("build/generated/ksp/release/kotlin")
}
}
}
dependencies {
implementation("net.chigita.spider:spider-annotation:1.0.0-alpha01")
ksp("net.chigita.spider:spider:1.0.0-alpha01")
}
- Prepare
.agsl
file and save inassets
directly.
- Define Compose function that refer to agsl file.
@Composable
fun ShaderBrushExample() {
Box(modifier = Modifier
.drawWithCache {
val shaderBrush = ShaderBrush(shader)
drawRect(shaderBrush)
}.fillMaxSize()
)
}
- Add annotation
@AGSL(file_name)
for the composable function.
@Composable
@AGSL("test")
fun ShaderBrushExample() {
// code snip...
}
- You can refer the
.agsl
asset asRuntimeShader
. This library automatically generatesRememberTestShader
composable function.
@Composable
@AGSL("test")
fun ShaderBrushExample() {
val shader = RememberTestShader()
Box(modifier = Modifier
.drawWithCache {
val shaderBrush = ShaderBrush(shader)
drawRect(shaderBrush)
}.fillMaxSize()
)
}
- Annotation for enum support
- Annotation with args support
- Pre syntax verify support