1 // Copyright (C) 2021 Harry Godden (hgn)
3 // Basic buffers-only version of csRadar
4 //=======================================================================================================================
9 void frag_gbuffer( void *dest
, vmf_vert tri
[3], float bca
, float bcb
, float bcc
);
10 void frag_gbuffer_clear( void *dest
);
12 csr_shader shader_gbuffer
=
14 .stride
= sizeof(float)*8, // (origin) x,y, (actual height) z
16 .clear
= frag_gbuffer_clear
19 // Main drawing function
20 void draw_buffers( csr_api
*api
, int bounds_only
);
22 // Extension implementation
23 // =========================================================================================================
26 void csr_ext_main( csr_api
*api
)
28 if( !csr_init( api
) )
31 csr_create_target( &api
->target
, api
->resolution
, api
->resolution
, api
->sampling_mode
, &shader_gbuffer
);
32 csr_rt_clear( &api
->target
);
34 // Compute bounds, collect models
35 draw_buffers( api
, 1 );
36 csr_auto_fit( &api
->target
, api
->padding
);
37 vmf_load_models( api
->map
);
40 draw_buffers( api
, 0 );
43 void csr_ext_exit( csr_api
*api
)
45 csr_rt_free( &api
->target
);
48 void draw_buffers( csr_api
*api
, int bounds_only
)
50 csr_filter filter
= { .compute_bounds_only
= bounds_only
};
51 vmf_map
*map
= api
->map
;
53 if( api
->num_strings
== 1 )
56 csr_vmf_render( &api
->target
, map
, map
->root
, &filter
, NULL
, NULL
);
60 csr_rt_save_buffers( &api
->target
, api
->output_path
, "all" );
66 for( int i
= 1; i
< api
->num_strings
; i
++ )
68 filter
.visgroup
= api
->strings
[ i
];
69 csr_vmf_render( &api
->target
, map
, map
->root
, &filter
, NULL
, NULL
);
73 csr_rt_save_buffers( &api
->target
, api
->output_path
, api
->strings
[i
] );
74 //csr_rt_save_c32f( ... );
75 //csr_rt_save_tga( ... );
77 // tar_write_dds( ... );
79 csr_rt_clear( &api
->target
);
85 void frag_gbuffer( void *dest
, vmf_vert tri
[3], float bca
, float bcb
, float bcc
)
87 float *dest_colour
= (float *)dest
;
89 v3_muls( tri
[0].co
, bca
, dest_colour
);
90 v3_muladds( dest_colour
, tri
[1].co
, bcb
, dest_colour
);
91 v3_muladds( dest_colour
, tri
[2].co
, bcc
, dest_colour
);
96 void frag_gbuffer_clear( void *dest
)
98 float *dest_colour
= (float *)dest
;
99 v3_zero( dest_colour
);