+struct csr_filter
+{
+ const char *visgroup; // Limit to this visgroup only
+ const char *classname; // Limit to this exact classname. will not draw world
+
+ int compute_bounds_only;
+};
+
+enum EMSAA
+{
+ k_EMSAA_none,
+ k_EMSAA_2x2,
+ k_EMSAA_RGSS,
+ k_EMSAA_8R
+};
+
+#ifdef CSR_EXECUTABLE
+
+// MSAA patterns
+v2f csr_msaa_1[] =
+{
+ {0.f, 0.f}
+};
+
+// XX
+// XX
+v2f csr_msaa_2x2[] =
+{
+ { 0x0.4p0f, 0x0.4p0f },
+ { 0x0.4p0f, -0x0.4p0f },
+ { -0x0.4p0f, -0x0.4p0f },
+ { -0x0.4p0f, 0x0.4p0f }
+};
+
+// X
+// X
+// X
+// X
+v2f csr_msaa_2x2rgss[] =
+{
+ { 0x0.2p0f, 0x0.6p0f },
+ { -0x0.6p0f, 0x0.2p0f },
+ { -0x0.2p0f, -0x0.6p0f },
+ { 0x0.6p0f, -0x0.2p0f }
+};
+
+// X
+// X
+// X
+// X
+// X
+// X
+// X
+// X
+v2f csr_msaa_8rook[] =
+{
+ { 0x0.1p0f, 0x0.7p0f },
+ { 0x0.5p0f, 0x0.1p0f },
+ { 0x0.7p0f, -0x0.3p0f },
+ { 0x0.3p0f, -0x0.5p0f },
+ { -0x0.1p0f, -0x0.7p0f },
+ { -0x0.5p0f, -0x0.1p0f },
+ { -0x0.7p0f, 0x0.3p0f },
+ { -0x0.3p0f, 0x0.5p0f }
+};
+
+
+void csr_create_target( csr_target *rt, u32 x, u32 y, EMSAA aa, csr_shader *shader )
+{
+ rt->x = x;
+ rt->y = y;
+
+ switch( aa )
+ {
+ default:
+ case k_EMSAA_none:
+ rt->num_samples = 1;
+ rt->sample_src = csr_msaa_1;
+ break;
+
+ case k_EMSAA_2x2:
+ rt->num_samples = 4;
+ rt->sample_src = csr_msaa_2x2;
+ break;
+
+ case k_EMSAA_RGSS:
+ rt->num_samples = 4;
+ rt->sample_src = csr_msaa_2x2rgss;
+ break;
+
+ case k_EMSAA_8R:
+ rt->num_samples = 8;
+ rt->sample_src = csr_msaa_8rook;
+ break;
+ }
+
+ rt->shader = shader;
+ rt->depth = (float *)csr_malloc( x*y*rt->num_samples * sizeof(float) );
+ rt->colour = csr_malloc( x * y * rt->shader->stride * rt->num_samples );
+
+ v3_fill( rt->bounds[0], INFINITY );
+ v3_fill( rt->bounds[1], -INFINITY );
+}
+
+void csr_update_subsamples( csr_target *rt )
+{
+ float range_x = (rt->bounds[1][0]-rt->bounds[0][0]);
+ float range_y = (rt->bounds[1][1]-rt->bounds[0][1]);
+
+ v2f pixel_size = { range_x/(float)rt->x, range_y/(float)rt->y };
+
+ for( int i = 0; i < rt->num_samples; i ++ )
+ {
+ v2_mul( rt->sample_src[i], pixel_size, rt->subsamples[i] );
+ }
+}
+
+void csr_rt_free( csr_target *rt )
+{
+ free( rt->depth );
+ free( rt->colour );
+}
+