X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=render.h;h=41aeef241ef529b7bc33522f8cb1dea880b3d067;hb=a99e5f5d5c16a3e865796a96ad648e3c570d32ac;hp=64cf8f1ecaa432d8f5e2013672b064269f4df26a;hpb=f99902f513b0ad606437bf32de47405dd4ea5f98;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/render.h b/render.h index 64cf8f1..41aeef2 100644 --- a/render.h +++ b/render.h @@ -36,7 +36,8 @@ VG_STATIC struct pipeline{ framebuffer *fb_main, *fb_water_reflection, - *fb_water_beneath; + *fb_water_beneath, + *fb_workshop_preview; int ready; float view_render_scale, @@ -58,8 +59,9 @@ struct framebuffer{ enum framebuffer_attachment_type{ k_framebuffer_attachment_type_none, - k_framebuffer_attachment_type_colour, - k_framebuffer_attachment_type_renderbuffer + k_framebuffer_attachment_type_texture, + k_framebuffer_attachment_type_renderbuffer, + k_framebuffer_attachment_type_texture_depth } purpose; @@ -95,7 +97,7 @@ framebuffers[] = .attachments = { { - "colour", k_framebuffer_attachment_type_colour, + "colour", k_framebuffer_attachment_type_texture, .internalformat = GL_RGB, .format = GL_RGB, @@ -103,7 +105,7 @@ framebuffers[] = .attachment = GL_COLOR_ATTACHMENT0 }, { - "motion", k_framebuffer_attachment_type_colour, + "motion", k_framebuffer_attachment_type_texture, .quality = k_framebuffer_quality_high_only, .internalformat = GL_RG16F, @@ -112,9 +114,16 @@ framebuffers[] = .attachment = GL_COLOR_ATTACHMENT1 }, { +#if 0 "depth_stencil", k_framebuffer_attachment_type_renderbuffer, .internalformat = GL_DEPTH24_STENCIL8, +#else + "depth_stencil", k_framebuffer_attachment_type_texture_depth, + .internalformat = GL_DEPTH24_STENCIL8, + .format = GL_DEPTH_STENCIL, + .type = GL_UNSIGNED_INT_24_8, +#endif .attachment = GL_DEPTH_STENCIL_ATTACHMENT } } @@ -129,7 +138,7 @@ framebuffers[] = .attachments = { { - "colour", k_framebuffer_attachment_type_colour, + "colour", k_framebuffer_attachment_type_texture, .internalformat = GL_RGB, .format = GL_RGB, .type = GL_UNSIGNED_BYTE, @@ -154,7 +163,7 @@ framebuffers[] = .attachments = { { - "colour", k_framebuffer_attachment_type_colour, + "colour", k_framebuffer_attachment_type_texture, .internalformat = GL_RED, .format = GL_RED, .type = GL_UNSIGNED_BYTE, @@ -167,6 +176,27 @@ framebuffers[] = .attachment = GL_DEPTH_STENCIL_ATTACHMENT } } + }, + { + "workshop_preview", + .link = &gpipeline.fb_workshop_preview, + .resolution_div = 0, + .fixed_w = 504, .fixed_h = 336, + .attachments = + { + { + "colour", k_framebuffer_attachment_type_texture, + .internalformat = GL_RGB, + .format = GL_RGB, + .type = GL_UNSIGNED_BYTE, + .attachment = GL_COLOR_ATTACHMENT0 + }, + { + "depth_stencil", k_framebuffer_attachment_type_renderbuffer, + .internalformat = GL_DEPTH24_STENCIL8, + .attachment = GL_DEPTH_STENCIL_ATTACHMENT + } + } } }; @@ -188,13 +218,18 @@ VG_STATIC void render_fb_get_current_res( struct framebuffer *fb, VG_STATIC void render_fb_inverse_ratio( framebuffer *fb, v2f inverse ) { - int x, y; - render_fb_get_current_res( fb, &x, &y ); + if( fb ){ + int x, y; + render_fb_get_current_res( fb, &x, &y ); - v2f render = { fb->render_w, fb->render_h }, - original = { x, y }; + v2f render = { fb->render_w, fb->render_h }, + original = { x, y }; - v2_div( render, original, inverse ); + v2_div( render, original, inverse ); + } + else{ + v2_div( (v2f){1.0f,1.0f}, (v2f){ vg.window_x, vg.window_y }, inverse ); + } } /* @@ -228,8 +263,10 @@ VG_STATIC void render_fb_bind_texture( framebuffer *fb, { struct framebuffer_attachment *at = &fb->attachments[attachment]; - if( at->purpose != k_framebuffer_attachment_type_colour ){ - vg_fatal_exit_loop( "illegal operation: bind non-colour framebuffer" + if( (at->purpose != k_framebuffer_attachment_type_texture) && + (at->purpose != k_framebuffer_attachment_type_texture_depth) ) + { + vg_fatal_error( "illegal operation: bind non-texture framebuffer" " attachment to texture slot" ); } @@ -374,9 +411,11 @@ VG_STATIC void render_fb_allocate_texture( struct framebuffer *fb, if( a->purpose == k_framebuffer_attachment_type_renderbuffer ){ glBindRenderbuffer( GL_RENDERBUFFER, a->id ); - glRenderbufferStorage( GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, rx, ry ); + glRenderbufferStorage( GL_RENDERBUFFER, a->internalformat, rx, ry ); } - else if( a->purpose == k_framebuffer_attachment_type_colour ){ + else if( a->purpose == k_framebuffer_attachment_type_texture || + a->purpose == k_framebuffer_attachment_type_texture_depth ) + { glBindTexture( GL_TEXTURE_2D, a->id ); glTexImage2D( GL_TEXTURE_2D, 0, a->internalformat, rx, ry, 0, a->format, a->type, NULL ); @@ -417,7 +456,9 @@ VG_STATIC void render_fb_allocate( struct framebuffer *fb ) GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, attachment->id ); } - else if( attachment->purpose == k_framebuffer_attachment_type_colour ){ + else if( attachment->purpose == k_framebuffer_attachment_type_texture || + attachment->purpose == k_framebuffer_attachment_type_texture_depth ) + { glGenTextures( 1, &attachment->id ); render_fb_allocate_texture( fb, attachment ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); @@ -428,7 +469,8 @@ VG_STATIC void render_fb_allocate( struct framebuffer *fb ) glFramebufferTexture2D( GL_FRAMEBUFFER, attachment->attachment, GL_TEXTURE_2D, attachment->id, 0 ); - colour_attachments[ colour_count ++ ] = attachment->attachment; + if( attachment->purpose == k_framebuffer_attachment_type_texture ) + colour_attachments[ colour_count ++ ] = attachment->attachment; } } @@ -460,7 +502,7 @@ VG_STATIC void render_fb_allocate( struct framebuffer *fb ) vg_error( " status: Generic Error" ); vg_info( "}\n" ); - vg_fatal_exit_loop( "Incomplete framebuffer (see logs)" ); + vg_fatal_error( "Incomplete framebuffer (see logs)" ); } } @@ -483,16 +525,23 @@ VG_STATIC void render_fb_resize(void) VG_STATIC int render_framebuffer_control( int argc, char const *argv[] ); VG_STATIC void render_framebuffer_poll( int argc, char const *argv[] ); -VG_STATIC void render_init_fs_quad(void) + +VG_STATIC void async_render_init( void *payload, u32 size ) { - vg_info( "[render] Allocate quad\n" ); + /* + * Complete Framebuffers + */ + for( int i=0; i