Skip to content

chigichan24/Spider

Repository files navigation

Spider (Under Construction)

A simple and safer AGSL wrapper library for compose functions that is generated by ksp.

logo

Background

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.

Usage

  1. 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")
}
  1. Prepare .agsl file and save in assets directly.
logo
  1. Define Compose function that refer to agsl file.
@Composable
fun ShaderBrushExample() {
    Box(modifier = Modifier
        .drawWithCache {
            val shaderBrush = ShaderBrush(shader)
            drawRect(shaderBrush)
        }.fillMaxSize()
    )
}
  1. Add annotation @AGSL(file_name) for the composable function.
@Composable
@AGSL("test")
fun ShaderBrushExample() {
    // code snip...
}
  1. You can refer the .agsl asset as RuntimeShader. This library automatically generates RememberTestShader composable function.
@Composable
@AGSL("test")
fun ShaderBrushExample() {
    val shader = RememberTestShader()
    Box(modifier = Modifier
        .drawWithCache {
            val shaderBrush = ShaderBrush(shader)
            drawRect(shaderBrush)
        }.fillMaxSize()
    )
}

Plan

  • Annotation for enum support
  • Annotation with args support
  • Pre syntax verify support

About

AGSL wrapper library that made by ksp

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages