X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=render.h;h=22c05726ddd0222a7b567e6b47c1c87ddea18540;hb=859178c6d4b2a9b9a95f8b01b113f589ce0f197f;hp=64cf8f1ecaa432d8f5e2013672b064269f4df26a;hpb=f99902f513b0ad606437bf32de47405dd4ea5f98;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/render.h b/render.h index 64cf8f1..22c0572 100644 --- a/render.h +++ b/render.h @@ -10,39 +10,35 @@ #include "shaders/blit.h" #include "shaders/blitblur.h" #include "shaders/blitcolour.h" +#include "shaders/blit_transition.h" -#if 0 -#include "shaders/standard.h" -#include "shaders/vblend.h" -#endif - -VG_STATIC void render_water_texture( world_instance *world, camera *cam, - int layer_depth ); -VG_STATIC void render_water_surface( world_instance *world, camera *cam ); -VG_STATIC void render_world( world_instance *world, camera *cam, - int layer_depth ); -VG_STATIC void render_world_depth( world_instance *world, camera *cam ); - +#define WORKSHOP_PREVIEW_WIDTH 504 +#define WORKSHOP_PREVIEW_HEIGHT 336 #ifndef RENDER_H #define RENDER_H +static f32 k_render_scale = 1.0f; +static i32 k_blur_effect = 1; +static f32 k_blur_strength = 0.3f; +static f32 k_fov = 0.86f; +static f32 k_cam_height = 0.8f; + typedef struct framebuffer framebuffer; /* * All standard buffers used in rendering */ -VG_STATIC struct pipeline{ +static struct pipeline{ glmesh fsquad; framebuffer *fb_main, *fb_water_reflection, - *fb_water_beneath; + *fb_water_beneath, + *fb_workshop_preview, + *fb_network_status; int ready; - - float view_render_scale, - water_render_scale; } -gpipeline = { .view_render_scale = 1.0f }; +gpipeline; struct framebuffer{ const char *display_name; @@ -58,8 +54,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 +92,7 @@ framebuffers[] = .attachments = { { - "colour", k_framebuffer_attachment_type_colour, + "colour", k_framebuffer_attachment_type_texture, .internalformat = GL_RGB, .format = GL_RGB, @@ -103,7 +100,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 +109,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 +133,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 +158,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,13 +171,50 @@ framebuffers[] = .attachment = GL_DEPTH_STENCIL_ATTACHMENT } } + }, + { + "workshop_preview", + .link = &gpipeline.fb_workshop_preview, + .resolution_div = 0, + .fixed_w = WORKSHOP_PREVIEW_WIDTH, .fixed_h = WORKSHOP_PREVIEW_HEIGHT, + .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 + } + } + }, + { + "network_status_ui", + .link = &gpipeline.fb_network_status, + .resolution_div = 0, + .fixed_w = 128, .fixed_h = 48, + .attachments = + { + { + "colour", k_framebuffer_attachment_type_texture, + .internalformat = GL_RGB, + .format = GL_RGB, + .type = GL_UNSIGNED_BYTE, + .attachment = GL_COLOR_ATTACHMENT0 + } + } } }; /* * Get the current (automatically scaled or fixed) resolution of framebuffer */ -VG_STATIC void render_fb_get_current_res( struct framebuffer *fb, +static void render_fb_get_current_res( struct framebuffer *fb, int *x, int *y ) { if( fb->resolution_div ){ @@ -186,28 +227,33 @@ VG_STATIC void render_fb_get_current_res( struct framebuffer *fb, } } -VG_STATIC void render_fb_inverse_ratio( framebuffer *fb, v2f inverse ) +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 ); + } } /* * Bind framebuffer for drawing to */ -VG_STATIC void render_fb_bind( framebuffer *fb, int use_scaling ) +static void render_fb_bind( framebuffer *fb, int use_scaling ) { int x, y; render_fb_get_current_res( fb, &x, &y ); if( use_scaling ){ - x = gpipeline.view_render_scale*(float)x; - y = gpipeline.view_render_scale*(float)y; + x = k_render_scale*(float)x; + y = k_render_scale*(float)y; x = VG_MAX( 16, x ); y = VG_MAX( 16, y ); @@ -223,13 +269,15 @@ VG_STATIC void render_fb_bind( framebuffer *fb, int use_scaling ) /* * Bind framebuffer attachment's texture */ -VG_STATIC void render_fb_bind_texture( framebuffer *fb, +static void render_fb_bind_texture( framebuffer *fb, int attachment, int slot ) { 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" ); } @@ -247,7 +295,7 @@ VG_STATIC void render_fb_bind_texture( framebuffer *fb, /* * Convert OpenGL attachment ID enum to string */ -VG_STATIC const char *render_fb_attachment_str( GLenum e ) +static const char *render_fb_attachment_str( GLenum e ) { struct { GLenum e; const char *str; } formats[] = @@ -271,7 +319,7 @@ VG_STATIC const char *render_fb_attachment_str( GLenum e ) * Convert OpenGL texture format enums from TexImage2D table 1,2 & * RenderBufferStorage Table 1, into strings */ -VG_STATIC const char *render_fb_format_str( GLenum format ) +static const char *render_fb_format_str( GLenum format ) { struct { GLenum e; const char *str; } formats[] = @@ -366,7 +414,7 @@ VG_STATIC const char *render_fb_format_str( GLenum format ) /* * Bind and allocate texture for framebuffer attachment */ -VG_STATIC void render_fb_allocate_texture( struct framebuffer *fb, +static void render_fb_allocate_texture( struct framebuffer *fb, struct framebuffer_attachment *a ) { int rx, ry; @@ -374,9 +422,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 ); @@ -386,7 +436,7 @@ VG_STATIC void render_fb_allocate_texture( struct framebuffer *fb, /* * Full allocation of a framebuffer */ -VG_STATIC void render_fb_allocate( struct framebuffer *fb ) +static void render_fb_allocate( struct framebuffer *fb ) { glGenFramebuffers( 1, &fb->fb ); glBindFramebuffer( GL_FRAMEBUFFER, fb->fb ); @@ -417,7 +467,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 +480,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,17 +513,16 @@ 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)" ); } } /* * Resize/Update all framebuffers(we know about) */ -VG_STATIC void render_fb_resize(void) +static void render_fb_resize(void) { - if( !gpipeline.ready ) - return; + if( !gpipeline.ready ) return; for( int i=0; i/"all" * arg2: subname /none */ -VG_STATIC int render_framebuffer_control( int argc, char const *argv[] ) +static int render_framebuffer_control( int argc, char const *argv[] ) { if( argc < 2 ){ vg_error( "Usage: fb \"show/hide\" /\"all\" /none\n" ); @@ -693,7 +762,7 @@ VG_STATIC int render_framebuffer_control( int argc, char const *argv[] ) return 0; } -VG_STATIC void render_framebuffer_poll( int argc, char const *argv[] ) +static void render_framebuffer_poll( int argc, char const *argv[] ) { const char *term = argv[argc-1];