+ if( attachment->purpose == k_framebuffer_attachment_type_texture )
+ colour_attachments[ colour_count ++ ] = attachment->attachment;
+ }
+ }
+
+ glDrawBuffers( colour_count, colour_attachments );
+
+ /*
+ * Check result
+ */
+ GLenum result = glCheckFramebufferStatus( GL_FRAMEBUFFER );
+
+ if( result == GL_FRAMEBUFFER_COMPLETE ){
+ /*
+ * Attatch to gpipeline
+ */
+ if( fb->link )
+ *fb->link = fb;
+
+ vg_success( " status: complete\n" );
+ vg_info( "}\n" );
+ }
+ else{
+ if( result == GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT )
+ vg_error( " status: Incomplete attachment" );
+ else if( result == GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT )
+ vg_error( " status: Missing attachment" );
+ else if( result == GL_FRAMEBUFFER_UNSUPPORTED )
+ vg_error( " status: Unsupported framebuffer format" );
+ else
+ vg_error( " status: Generic Error" );
+
+ vg_info( "}\n" );
+ vg_fatal_error( "Incomplete framebuffer (see logs)" );
+ }
+}
+
+/*
+ * Resize/Update all framebuffers(we know about)
+ */
+static void render_fb_resize(void)
+{
+ if( !gpipeline.ready ) return;
+
+ for( int i=0; i<vg_list_size(framebuffers); i++ ){
+ struct framebuffer *fb = &framebuffers[i];
+ for( int j=0; j<vg_list_size(fb->attachments); j++ ){
+ struct framebuffer_attachment *attachment = &fb->attachments[j];
+ render_fb_allocate_texture( fb, attachment );
+ }
+ }
+}
+
+static int render_framebuffer_control( int argc, char const *argv[] );
+static void render_framebuffer_poll( int argc, char const *argv[] );
+
+static void async_render_init( void *payload, u32 size )
+{
+ /*
+ * Complete Framebuffers
+ */
+ for( int i=0; i<vg_list_size(framebuffers); i++ ){
+ struct framebuffer *fb = &framebuffers[i];
+ render_fb_allocate( fb );
+ }
+
+ f32 rh = 0x1p-4f, ih = 0.3f;
+
+ float quad[] = {
+ 0.00f,0.00f, 1.00f,1.00f, 0.00f,1.00f, /* fsquad */
+ 0.00f,0.00f, 1.00f,0.00f, 1.00f,1.00f,
+
+ 0.00f,0.00f, 1.00f,rh, 0.00f,rh, /* fsquad1 */
+ 0.00f,0.00f, 1.00f,0.00f, 1.00f,rh,
+
+ /* 9x9 debug grid */
+ /* row0 */
+ 0.00f,0.00f, 0.30f,0.30f, 0.00f,0.30f,
+ 0.00f,0.00f, 0.30f,0.00f, 0.30f,0.30f,
+ 0.30f,0.00f, 0.60f,0.30f, 0.30f,0.30f,
+ 0.30f,0.00f, 0.60f,0.00f, 0.60f,0.30f,
+ 0.60f,0.00f, 0.90f,0.30f, 0.60f,0.30f,
+ 0.60f,0.00f, 0.90f,0.00f, 0.90f,0.30f,
+ /* row1 */
+ 0.00f,0.30f, 0.30f,0.60f, 0.00f,0.60f,
+ 0.00f,0.30f, 0.30f,0.30f, 0.30f,0.60f,
+ 0.30f,0.30f, 0.60f,0.60f, 0.30f,0.60f,
+ 0.30f,0.30f, 0.60f,0.30f, 0.60f,0.60f,
+ 0.60f,0.30f, 0.90f,0.60f, 0.60f,0.60f,
+ 0.60f,0.30f, 0.90f,0.30f, 0.90f,0.60f,
+ /* row2 */
+ 0.00f,0.60f, 0.30f,0.90f, 0.00f,0.90f,
+ 0.00f,0.60f, 0.30f,0.60f, 0.30f,0.90f,
+ 0.30f,0.60f, 0.60f,0.90f, 0.30f,0.90f,
+ 0.30f,0.60f, 0.60f,0.60f, 0.60f,0.90f,
+ 0.60f,0.60f, 0.90f,0.90f, 0.60f,0.90f,
+ 0.60f,0.60f, 0.90f,0.60f, 0.90f,0.90f,
+
+ 0.00f,ih, 1.00f,ih+rh, 0.00f,ih+rh, /* fsquad2 */
+ 0.00f,ih, 1.00f,ih, 1.00f,ih+rh,
+ };
+
+ vg_console_reg_cmd( "fb", render_framebuffer_control,
+ render_framebuffer_poll );
+ glGenVertexArrays( 1, &gpipeline.fsquad.vao );
+ glGenBuffers( 1, &gpipeline.fsquad.vbo );
+ glBindVertexArray( gpipeline.fsquad.vao );
+ glBindBuffer( GL_ARRAY_BUFFER, gpipeline.fsquad.vbo );
+ glBufferData( GL_ARRAY_BUFFER, sizeof(quad), quad, GL_STATIC_DRAW );
+ glBindVertexArray( gpipeline.fsquad.vao );
+ glVertexAttribPointer( 0, 2, GL_FLOAT, GL_FALSE,
+ sizeof(float)*2, (void*)0 );
+ glEnableVertexAttribArray( 0 );
+
+ VG_CHECK_GL_ERR();
+
+ glBindFramebuffer( GL_FRAMEBUFFER, 0 );
+ gpipeline.ready = 1;
+}
+
+static void render_init(void)
+{
+ vg_console_reg_var( "blur_strength", &k_blur_strength, k_var_dtype_f32, 0 );
+ vg_console_reg_var( "render_scale", &k_render_scale,
+ k_var_dtype_f32, VG_VAR_PERSISTENT );
+ vg_console_reg_var( "fov", &k_fov, k_var_dtype_f32, VG_VAR_PERSISTENT );
+ vg_console_reg_var( "cam_height", &k_cam_height,
+ k_var_dtype_f32, VG_VAR_PERSISTENT );
+ vg_console_reg_var( "blur_effect", &k_blur_effect,
+ k_var_dtype_i32, VG_VAR_PERSISTENT );
+
+
+ shader_blit_register();
+ shader_blitblur_register();
+ shader_blitcolour_register();
+ shader_blit_transition_register();
+
+ vg_async_call( async_render_init, NULL, 0 );
+}
+
+/*
+ * Utility
+ */
+static void render_fsquad(void)
+{
+ glBindVertexArray( gpipeline.fsquad.vao );
+ glDrawArrays( GL_TRIANGLES, 0, 6 );
+}
+
+static void render_fsquad1(void)
+{
+ glBindVertexArray( gpipeline.fsquad.vao );
+ glDrawArrays( GL_TRIANGLES, 6, 6 );