+
+// Obsolete
+void csr_rt_save_buffers( csr_target *rt, const char *basename, const char *subname )
+{
+ char output[ 512 ];
+
+ float *image = (float *)csr_malloc( 1024*1024*sizeof(float)*3 );
+
+ float contrib = 1.f/(float)rt->num_samples;
+
+ for( int l = 0; l < rt->x; l ++ )
+ {
+ for( int x = 0; x < rt->y; x ++ )
+ {
+ float *dst = &image[ (l*1024+x)*3 ];
+ void *src = rt->colour + ((1023-l)*1024+x) * rt->num_samples * rt->shader->stride;
+
+ v3_muls( (float *)src, contrib, dst );
+
+ for( int j = 1; j < rt->num_samples; j ++ )
+ {
+ v3_muladds( dst, (float *)(src + j*rt->shader->stride), contrib, dst );
+ }
+ }
+ }
+
+ // Save position buffer
+ strcpy( output, basename );
+ strcat( output, "." );
+ strcat( output, subname );
+ strcat( output, "_position.pfm" );
+ csr_32f_write( output, rt->x, rt->y, image );
+
+ free( image );
+}
+
+// Save floating point buffer to tga. Must be in range (0-1)
+// Offset and stride are in bytes
+void csr_rt_save_tga( csr_target *rt, const char *path, u32 offset, u32 nc )
+{
+ u8 *image = (u8 *)csr_malloc( rt->x*rt->y * 4 );
+
+ float contrib = 255.f/(float)rt->num_samples;
+
+ for( int y = 0; y < rt->y; y ++ )
+ {
+ for( int x = 0; x < rt->x; x ++ )
+ {
+ u32 pixel_index = (y*rt->x + x);
+
+ void *src = rt->colour + offset + pixel_index * rt->num_samples * rt->shader->stride;
+ u8 *dst = image + pixel_index*4;
+
+ v4f accum = { 0.f, 0.f, 0.f, 0.f };
+
+ for( int k = 0; k < rt->num_samples; k ++ )
+ {
+ float *src_sample = (float *)(src + k*rt->shader->stride);
+
+ for( int j = 0; j < nc; j ++ )
+ {
+ accum[ j ] += src_sample[ j ] * contrib;
+ }
+ }
+
+ // TODO: Clamp this value
+ dst[0] = accum[0];
+ dst[1] = accum[1];
+ dst[2] = accum[2];
+ dst[3] = accum[3];
+ }
+ }
+
+ csr_tga_write( path, rt->x, rt->y, nc, image );
+ free( image );
+}
+
+#endif