X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=render.c;h=0050f943f4773cf0ea42b311f8e991bac3ba3956;hb=refs%2Fheads%2Fmenu2;hp=0c6a8f0fe42aae080c26b2a2d94fc6c796b7e19f;hpb=329828f689e880b825b396c7be5b243aad6ae5ea;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/render.c b/render.c index 0c6a8f0..aa0cfab 100644 --- a/render.c +++ b/render.c @@ -43,12 +43,12 @@ static void async_render_init( void *payload, u32 size ) 0.00f,ih, 1.00f,ih, 1.00f,ih+rh, }; - glGenVertexArrays( 1, &gpipeline.fsquad.vao ); - glGenBuffers( 1, &gpipeline.fsquad.vbo ); - glBindVertexArray( gpipeline.fsquad.vao ); - glBindBuffer( GL_ARRAY_BUFFER, gpipeline.fsquad.vbo ); + glGenVertexArrays( 1, &g_render.fsquad.vao ); + glGenBuffers( 1, &g_render.fsquad.vbo ); + glBindVertexArray( g_render.fsquad.vao ); + glBindBuffer( GL_ARRAY_BUFFER, g_render.fsquad.vbo ); glBufferData( GL_ARRAY_BUFFER, sizeof(quad), quad, GL_STATIC_DRAW ); - glBindVertexArray( gpipeline.fsquad.vao ); + glBindVertexArray( g_render.fsquad.vao ); glVertexAttribPointer( 0, 2, GL_FLOAT, GL_FALSE, sizeof(float)*2, (void*)0 ); glEnableVertexAttribArray( 0 ); @@ -56,7 +56,7 @@ static void async_render_init( void *payload, u32 size ) VG_CHECK_GL_ERR(); glBindFramebuffer( GL_FRAMEBUFFER, 0 ); - gpipeline.ready = 1; + g_render.ready = 1; } void render_init(void) @@ -75,10 +75,10 @@ void render_init(void) /* * Main framebuffer */ - gpipeline.fb_main = vg_framebuffer_allocate( alloc, 3, 1 ); - gpipeline.fb_main->display_name = "main"; - gpipeline.fb_main->resolution_div = 1; - gpipeline.fb_main->attachments[0] = (vg_framebuffer_attachment) + g_render.fb_main = vg_framebuffer_allocate( alloc, 3, 1 ); + g_render.fb_main->display_name = "main"; + g_render.fb_main->resolution_div = 1; + g_render.fb_main->attachments[0] = (vg_framebuffer_attachment) { "colour", k_framebuffer_attachment_type_texture, @@ -87,7 +87,7 @@ void render_init(void) .type = GL_UNSIGNED_BYTE, .attachment = GL_COLOR_ATTACHMENT0 }; - gpipeline.fb_main->attachments[1] = (vg_framebuffer_attachment) + g_render.fb_main->attachments[1] = (vg_framebuffer_attachment) { "motion", k_framebuffer_attachment_type_texture, @@ -97,7 +97,7 @@ void render_init(void) .type = GL_FLOAT, .attachment = GL_COLOR_ATTACHMENT1 }; - gpipeline.fb_main->attachments[2] = (vg_framebuffer_attachment) + g_render.fb_main->attachments[2] = (vg_framebuffer_attachment) { "depth_stencil", k_framebuffer_attachment_type_texture_depth, .internalformat = GL_DEPTH24_STENCIL8, @@ -105,15 +105,15 @@ void render_init(void) .type = GL_UNSIGNED_INT_24_8, .attachment = GL_DEPTH_STENCIL_ATTACHMENT }; - vg_framebuffer_create( gpipeline.fb_main ); + vg_framebuffer_create( g_render.fb_main ); /* * Water reflection */ - gpipeline.fb_water_reflection = vg_framebuffer_allocate( alloc, 2, 1 ); - gpipeline.fb_water_reflection->display_name = "water_reflection"; - gpipeline.fb_water_reflection->resolution_div = 2; - gpipeline.fb_water_reflection->attachments[0] = (vg_framebuffer_attachment) + g_render.fb_water_reflection = vg_framebuffer_allocate( alloc, 2, 1 ); + g_render.fb_water_reflection->display_name = "water_reflection"; + g_render.fb_water_reflection->resolution_div = 2; + g_render.fb_water_reflection->attachments[0] = (vg_framebuffer_attachment) { "colour", k_framebuffer_attachment_type_texture, .internalformat = GL_RGB, @@ -121,22 +121,22 @@ void render_init(void) .type = GL_UNSIGNED_BYTE, .attachment = GL_COLOR_ATTACHMENT0 }; - gpipeline.fb_water_reflection->attachments[1] = (vg_framebuffer_attachment) + g_render.fb_water_reflection->attachments[1] = (vg_framebuffer_attachment) { "depth_stencil", k_framebuffer_attachment_type_renderbuffer, .internalformat = GL_DEPTH24_STENCIL8, .attachment = GL_DEPTH_STENCIL_ATTACHMENT }; - vg_framebuffer_create( gpipeline.fb_water_reflection ); + vg_framebuffer_create( g_render.fb_water_reflection ); /* * Thid rendered view from the perspective of the camera, but just * captures stuff thats under the water */ - gpipeline.fb_water_beneath = vg_framebuffer_allocate( alloc, 2, 1 ); - gpipeline.fb_water_beneath->display_name = "water_beneath"; - gpipeline.fb_water_beneath->resolution_div = 2; - gpipeline.fb_water_beneath->attachments[0] = (vg_framebuffer_attachment) + g_render.fb_water_beneath = vg_framebuffer_allocate( alloc, 2, 1 ); + g_render.fb_water_beneath->display_name = "water_beneath"; + g_render.fb_water_beneath->resolution_div = 2; + g_render.fb_water_beneath->attachments[0] = (vg_framebuffer_attachment) { "colour", k_framebuffer_attachment_type_texture, .internalformat = GL_RED, @@ -144,23 +144,23 @@ void render_init(void) .type = GL_UNSIGNED_BYTE, .attachment = GL_COLOR_ATTACHMENT0 }; - gpipeline.fb_water_beneath->attachments[1] = (vg_framebuffer_attachment) + g_render.fb_water_beneath->attachments[1] = (vg_framebuffer_attachment) { "depth_stencil", k_framebuffer_attachment_type_renderbuffer, .internalformat = GL_DEPTH24_STENCIL8, .attachment = GL_DEPTH_STENCIL_ATTACHMENT }; - vg_framebuffer_create( gpipeline.fb_water_beneath ); + vg_framebuffer_create( g_render.fb_water_beneath ); /* * Workshop preview */ - gpipeline.fb_workshop_preview = vg_framebuffer_allocate( alloc, 2, 1 ); - gpipeline.fb_workshop_preview->display_name = "workshop_preview"; - gpipeline.fb_workshop_preview->resolution_div = 0; - gpipeline.fb_workshop_preview->fixed_w = WORKSHOP_PREVIEW_WIDTH; - gpipeline.fb_workshop_preview->fixed_h = WORKSHOP_PREVIEW_HEIGHT; - gpipeline.fb_workshop_preview->attachments[0] = (vg_framebuffer_attachment) + g_render.fb_workshop_preview = vg_framebuffer_allocate( alloc, 2, 1 ); + g_render.fb_workshop_preview->display_name = "workshop_preview"; + g_render.fb_workshop_preview->resolution_div = 0; + g_render.fb_workshop_preview->fixed_w = WORKSHOP_PREVIEW_WIDTH; + g_render.fb_workshop_preview->fixed_h = WORKSHOP_PREVIEW_HEIGHT; + g_render.fb_workshop_preview->attachments[0] = (vg_framebuffer_attachment) { "colour", k_framebuffer_attachment_type_texture, .internalformat = GL_RGB, @@ -168,23 +168,23 @@ void render_init(void) .type = GL_UNSIGNED_BYTE, .attachment = GL_COLOR_ATTACHMENT0 }; - gpipeline.fb_workshop_preview->attachments[1] = (vg_framebuffer_attachment) + g_render.fb_workshop_preview->attachments[1] = (vg_framebuffer_attachment) { "depth_stencil", k_framebuffer_attachment_type_renderbuffer, .internalformat = GL_DEPTH24_STENCIL8, .attachment = GL_DEPTH_STENCIL_ATTACHMENT }; - vg_framebuffer_create( gpipeline.fb_workshop_preview ); + vg_framebuffer_create( g_render.fb_workshop_preview ); /* * Network status */ - gpipeline.fb_network_status = vg_framebuffer_allocate( alloc, 1, 1 ); - gpipeline.fb_network_status->display_name = "network_status_ui"; - gpipeline.fb_network_status->resolution_div = 0; - gpipeline.fb_network_status->fixed_w = 128; - gpipeline.fb_network_status->fixed_h = 48; - gpipeline.fb_network_status->attachments[0] = (vg_framebuffer_attachment) + g_render.fb_network_status = vg_framebuffer_allocate( alloc, 1, 1 ); + g_render.fb_network_status->display_name = "network_status_ui"; + g_render.fb_network_status->resolution_div = 0; + g_render.fb_network_status->fixed_w = 128; + g_render.fb_network_status->fixed_h = 48; + g_render.fb_network_status->attachments[0] = (vg_framebuffer_attachment) { "colour", k_framebuffer_attachment_type_texture, .internalformat = GL_RGB, @@ -192,7 +192,7 @@ void render_init(void) .type = GL_UNSIGNED_BYTE, .attachment = GL_COLOR_ATTACHMENT0 }; - vg_framebuffer_create( gpipeline.fb_network_status ); + vg_framebuffer_create( g_render.fb_network_status ); vg_async_call( async_render_init, NULL, 0 ); } @@ -202,18 +202,59 @@ void render_init(void) */ void render_fsquad(void) { - glBindVertexArray( gpipeline.fsquad.vao ); + glBindVertexArray( g_render.fsquad.vao ); glDrawArrays( GL_TRIANGLES, 0, 6 ); } void render_fsquad1(void) { - glBindVertexArray( gpipeline.fsquad.vao ); + glBindVertexArray( g_render.fsquad.vao ); glDrawArrays( GL_TRIANGLES, 6, 6+6 ); } void render_fsquad2(void) { - glBindVertexArray( gpipeline.fsquad.vao ); + glBindVertexArray( g_render.fsquad.vao ); glDrawArrays( GL_TRIANGLES, 66+6,6 ); } + +void postprocess_to_screen( vg_framebuffer *fb ) +{ + glBindFramebuffer( GL_FRAMEBUFFER, 0 ); + glViewport( 0,0, vg.window_x, vg.window_y ); + + glEnable(GL_BLEND); + glDisable(GL_DEPTH_TEST); + glBlendFunc(GL_ONE_MINUS_DST_ALPHA, GL_DST_ALPHA); + glBlendEquation(GL_FUNC_ADD); + + v2f inverse; + vg_framebuffer_inverse_ratio( fb, inverse ); + + if( k_blur_effect ) + { + shader_blitblur_use(); + shader_blitblur_uTexMain( 0 ); + shader_blitblur_uTexMotion( 1 ); + shader_blitblur_uBlurStrength( k_blur_strength / + (vg.time_frame_delta*60.0) ); + shader_blitblur_uInverseRatio( inverse ); + + inverse[0] -= 0.0001f; + inverse[1] -= 0.0001f; + shader_blitblur_uClampUv( inverse ); + shader_blitblur_uOverrideDir( g_render.blur_override ); + + vg_framebuffer_bind_texture( fb, 0, 0 ); + vg_framebuffer_bind_texture( fb, 1, 1 ); + } + else + { + shader_blit_use(); + shader_blit_uTexMain( 0 ); + shader_blit_uInverseRatio( inverse ); + vg_framebuffer_bind_texture( fb, 0, 0 ); + } + + render_fsquad(); +}