finish up plugin architecture
[csRadar.git] / ext_csr_free.c
1 // Copyright (C) 2021 Harry Godden (hgn)
2
3 // Basic buffers-only version of csRadar
4 //=======================================================================================================================
5
6 #include "csRadar.h"
7
8 // GBuffer shader
9 void frag_gbuffer( void *dest, vmf_vert tri[3], float bca, float bcb, float bcc );
10 void frag_gbuffer_clear( void *dest );
11
12 csr_shader shader_gbuffer =
13 {
14 .stride = sizeof(float)*8, // (origin) x,y, (actual height) z
15 .frag = frag_gbuffer,
16 .clear = frag_gbuffer_clear
17 };
18
19 // Main drawing function
20 void draw_buffers( csr_api *api, int bounds_only );
21
22 // Extension implementation
23 // =========================================================================================================
24
25 // API ENTRY
26 void csr_ext_main( csr_api *api )
27 {
28 if( !csr_init( api ) )
29 return;
30
31 csr_create_target( &api->target, api->resolution, api->resolution, api->sampling_mode, &shader_gbuffer );
32 csr_rt_clear( &api->target );
33
34 // Compute bounds, collect models
35 draw_buffers( api, 1 );
36 csr_auto_fit( &api->target, api->padding );
37 vmf_load_models( api->map );
38
39 // Draw everything
40 draw_buffers( api, 0 );
41 }
42
43 void csr_ext_exit( csr_api *api )
44 {
45 csr_rt_free( &api->target );
46 }
47
48 void draw_buffers( csr_api *api, int bounds_only )
49 {
50 csr_filter filter = { .compute_bounds_only = bounds_only };
51 vmf_map *map = api->map;
52
53 if( api->num_strings == 1 )
54 {
55 // Draw everything
56 csr_vmf_render( &api->target, map, map->root, &filter, NULL, NULL );
57
58 if( !bounds_only )
59 {
60 csr_rt_save_buffers( &api->target, api->output_path, "all" );
61 }
62 }
63 else
64 {
65 // Draw groups
66 for( int i = 1; i < api->num_strings; i ++ )
67 {
68 filter.visgroup = api->strings[ i ];
69 csr_vmf_render( &api->target, map, map->root, &filter, NULL, NULL );
70
71 if( !bounds_only )
72 {
73 csr_rt_save_buffers( &api->target, api->output_path, api->strings[i] );
74 //csr_rt_save_c32f( ... );
75 //csr_rt_save_tga( ... );
76
77 // tar_write_dds( ... );
78
79 csr_rt_clear( &api->target );
80 }
81 }
82 }
83 }
84
85 void frag_gbuffer( void *dest, vmf_vert tri[3], float bca, float bcb, float bcc )
86 {
87 float *dest_colour = (float *)dest;
88
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 );
92
93 // TODO: Normal map
94 }
95
96 void frag_gbuffer_clear( void *dest )
97 {
98 float *dest_colour = (float *)dest;
99 v3_zero( dest_colour );
100 }