@@ -27,12 +27,12 @@ existing renderer dispatch pipeline.
2727
2828### 1. Add ` CustomShader ` struct to ` styles.v ` (after Gradient)
2929
30- ``` v
30+ ``` v ignore
3131pub struct CustomShader {
3232pub:
33- fs_glsl string // GLSL 330 fragment source
34- fs_metal string // MSL fragment source
35- uniforms [16]f32 // User data passed via tm matrix
33+ fs_glsl string // GLSL 330 fragment source
34+ fs_metal string // MSL fragment source
35+ uniforms [16]f32 // User data passed via tm matrix
3636}
3737```
3838
@@ -88,9 +88,9 @@ struct with `u0..u3` float4 fields.
8888### 5. Pipeline creation + draw function in ` shaders.v `
8989
9090** Hash function:**
91- ``` v
91+ ``` v ignore
9292fn shader_cache_key(shader &CustomShader) u64 {
93- return shader.fs_glsl.hash()
93+ return shader.fs_glsl.hash()
9494}
9595```
9696
@@ -116,32 +116,29 @@ fn shader_cache_key(shader &CustomShader) u64 {
116116### 6. Add renderer struct + dispatch in ` render.v `
117117
118118** New struct:**
119- ``` v
119+ ``` v ignore
120120struct DrawCustomShader {
121- x f32
122- y f32
123- w f32
124- h f32
125- radius f32
126- custom_shader &CustomShader
121+ x f32
122+ y f32
123+ w f32
124+ h f32
125+ radius f32
126+ custom_shader &CustomShader
127127}
128128```
129129
130130** Add ` | DrawCustomShader ` ** to the ` Renderer ` sum type (line ~ 130).
131131
132132** Add match arm** in ` renderer_draw ` (line ~ 238):
133- ``` v
134- DrawCustomShader {
135- draw_custom_shader_rect(renderer.x, renderer.y, renderer.w,
136- renderer.h, renderer.radius, renderer.custom_shader,
137- mut window)
138- }
133+ ``` v ignore
134+ DrawCustomShader{draw_custom_shader_rect(renderer.x, renderer.y, renderer.w, renderer.h,
135+ renderer.radius, renderer.custom_shader, mut window)}
139136```
140137
141138** Add dispatch** in ` render_container ` — insert before the gradient
142139check (line 356). Custom shader takes priority over gradient/blur:
143140
144- ``` v
141+ ``` v ignore
145142if shape.custom_shader != unsafe { nil } {
146143 window.renderers << DrawCustomShader{
147144 x: shape.x
@@ -161,7 +158,7 @@ custom-shader views can still have drop shadows.
161158### 7. Add pipeline cache to ` Window ` in ` window.v `
162159
163160Add to ` mut: ` section (line ~ 51, after ` gradient_pip_init ` ):
164- ``` v
161+ ``` v ignore
165162custom_shader_pips map[u64]sgl.Pipeline
166163```
167164
@@ -220,4 +217,4 @@ if (frag_color.a < 0.0) { frag_color += texture(tex, uv); }
220217- Should framework auto-inject time into a reserved uniform slot,
221218 or leave all 16 to user?
222219- Should border/stroke rendering work with custom shaders?
223- - Pipeline cache eviction needed, or unbounded map acceptable?
220+ - Pipeline cache eviction needed, or unbounded map acceptable?
0 commit comments