@@ -19,15 +19,17 @@ pub trait Target {
1919 /// Writes a single scanline into `self`.
2020 ///
2121 /// Returns count of fragments input and output.
22- fn rasterize < V , Fs > (
22+ fn rasterize < V , U , Fs > (
2323 & mut self ,
2424 scanline : Scanline < V > ,
25+ uniform : U ,
2526 frag_shader : & Fs ,
2627 ctx : & Context ,
2728 ) -> Throughput
2829 where
2930 V : Vary ,
30- Fs : FragmentShader < V > ;
31+ U : Copy ,
32+ Fs : FragmentShader < V , U > ;
3133}
3234
3335/// Framebuffer, combining a color (pixel) buffer and a depth buffer.
@@ -56,23 +58,25 @@ impl<T, B: AsMutSlice2<T>, F> AsMutSlice2<T> for Colorbuf<B, F> {
5658}
5759
5860impl < T : Target > Target for & mut T {
59- fn rasterize < V : Vary , Fs : FragmentShader < V > > (
61+ fn rasterize < V : Vary , U : Copy , Fs : FragmentShader < V , U > > (
6062 & mut self ,
6163 sl : Scanline < V > ,
64+ uni : U ,
6265 fs : & Fs ,
6366 ctx : & Context ,
6467 ) -> Throughput {
65- ( * self ) . rasterize ( sl, fs, ctx)
68+ ( * self ) . rasterize ( sl, uni , fs, ctx)
6669 }
6770}
6871impl < T : Target > Target for & RefCell < T > {
69- fn rasterize < V : Vary , Fs : FragmentShader < V > > (
72+ fn rasterize < V : Vary , U : Copy , Fs : FragmentShader < V , U > > (
7073 & mut self ,
7174 sl : Scanline < V > ,
75+ uni : U ,
7276 fs : & Fs ,
7377 ctx : & Context ,
7478 ) -> Throughput {
75- RefCell :: borrow_mut ( self ) . rasterize ( sl, fs, ctx)
79+ RefCell :: borrow_mut ( self ) . rasterize ( sl, uni , fs, ctx)
7680 }
7781}
7882
@@ -83,14 +87,15 @@ where
8387 Color4 : IntoPixel < u32 , Fmt > ,
8488{
8589 /// Rasterizes `scanline` into this framebuffer.
86- fn rasterize < V : Vary , Fs : FragmentShader < V > > (
90+ fn rasterize < V : Vary , U : Copy , Fs : FragmentShader < V , U > > (
8791 & mut self ,
8892 sl : Scanline < V > ,
93+ uni : U ,
8994 fs : & Fs ,
9095 ctx : & Context ,
9196 ) -> Throughput {
9297 let Self { color_buf, depth_buf } = self ;
93- rasterize_fb ( color_buf, depth_buf, sl, fs, Color4 :: into_pixel, ctx)
98+ rasterize_fb ( color_buf, depth_buf, sl, uni , fs, Color4 :: into_pixel, ctx)
9499 }
95100}
96101
@@ -101,42 +106,46 @@ where
101106{
102107 /// Rasterizes `scanline` into this `u32` color buffer.
103108 /// Does no z-buffering.
104- fn rasterize < V : Vary , Fs : FragmentShader < V > > (
109+ fn rasterize < V : Vary , U : Copy , Fs : FragmentShader < V , U > > (
105110 & mut self ,
106111 sl : Scanline < V > ,
112+ uni : U ,
107113 fs : & Fs ,
108114 ctx : & Context ,
109115 ) -> Throughput {
110- rasterize ( & mut self . buf , sl, fs, Color4 :: into_pixel, ctx)
116+ rasterize ( & mut self . buf , sl, uni , fs, Color4 :: into_pixel, ctx)
111117 }
112118}
113119
114120impl Target for Buf2 < Color4 > {
115- fn rasterize < V : Vary , Fs : FragmentShader < V > > (
121+ fn rasterize < V : Vary , U : Copy , Fs : FragmentShader < V , U > > (
116122 & mut self ,
117123 sl : Scanline < V > ,
124+ uni : U ,
118125 fs : & Fs ,
119126 ctx : & Context ,
120127 ) -> Throughput {
121- rasterize ( self , sl, fs, |c| c, ctx)
128+ rasterize ( self , sl, uni , fs, |c| c, ctx)
122129 }
123130}
124131
125132impl Target for Buf2 < Color3 > {
126- fn rasterize < V : Vary , Fs : FragmentShader < V > > (
133+ fn rasterize < V : Vary , U : Copy , Fs : FragmentShader < V , U > > (
127134 & mut self ,
128135 sl : Scanline < V > ,
136+ uni : U ,
129137 fs : & Fs ,
130138 ctx : & Context ,
131139 ) -> Throughput {
132- rasterize ( self , sl, fs, |c| c. to_rgb ( ) , ctx)
140+ rasterize ( self , sl, uni , fs, |c| c. to_rgb ( ) , ctx)
133141 }
134142}
135143
136- pub fn rasterize < T , V : Vary > (
144+ pub fn rasterize < T , V : Vary , U : Copy > (
137145 buf : & mut impl AsMutSlice2 < T > ,
138146 mut sl : Scanline < V > ,
139- fs : & impl FragmentShader < V > ,
147+ uni : U ,
148+ fs : & impl FragmentShader < V , U > ,
140149 mut conv : impl FnMut ( Color4 ) -> T ,
141150 ctx : & Context ,
142151) -> Throughput {
@@ -148,7 +157,7 @@ pub fn rasterize<T, V: Vary>(
148157 sl. fragments ( )
149158 . zip ( cbuf_span)
150159 . for_each ( |( frag, curr_col) | {
151- if let Some ( new_col) = fs. shade_fragment ( frag)
160+ if let Some ( new_col) = fs. shade_fragment ( frag, uni )
152161 && ctx. color_write
153162 {
154163 io. o += 1 ;
@@ -158,11 +167,12 @@ pub fn rasterize<T, V: Vary>(
158167 io
159168}
160169
161- pub fn rasterize_fb < T , V : Vary > (
170+ pub fn rasterize_fb < T , V : Vary , U : Copy > (
162171 cbuf : & mut impl AsMutSlice2 < T > ,
163172 zbuf : & mut impl AsMutSlice2 < f32 > ,
164173 mut sl : Scanline < V > ,
165- fs : & impl FragmentShader < V > ,
174+ uni : U ,
175+ fs : & impl FragmentShader < V , U > ,
166176 mut conv : impl FnMut ( Color4 ) -> T ,
167177 ctx : & Context ,
168178) -> Throughput {
@@ -180,7 +190,7 @@ pub fn rasterize_fb<T, V: Vary>(
180190 let new_z = frag. pos . z ( ) ;
181191
182192 if ctx. depth_test ( new_z, * curr_z)
183- && let Some ( new_col) = fs. shade_fragment ( frag)
193+ && let Some ( new_col) = fs. shade_fragment ( frag, uni )
184194 {
185195 if ctx. color_write {
186196 io. o += 1 ;
0 commit comments