X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=render.h;h=e7220b0935a92f3a105eb8382bb8cd9345bfc1ba;hb=e126d5b471eb17ec9e0f0391cc7488b45f213b0d;hp=374cc06a0343590958e271bb0dea9c6d3bd92ff2;hpb=191bf91146eb7e3ac15fb18de6e7267d1cd686af;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/render.h b/render.h index 374cc06..e7220b0 100644 --- a/render.h +++ b/render.h @@ -5,17 +5,23 @@ #include "common.h" #include "model.h" #include "camera.h" +#include "world.h" #include "shaders/blit.h" #include "shaders/blitblur.h" +#include "shaders/blitcolour.h" + +#if 0 #include "shaders/standard.h" #include "shaders/vblend.h" +#endif -VG_STATIC void render_water_texture( camera *cam ); -VG_STATIC void render_water_surface( camera *cam ); -VG_STATIC void render_world( camera *cam ); -VG_STATIC void shader_link_standard_ub( GLuint shader, int texture_id ); -VG_STATIC void render_world_depth( camera *cam ); +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 ); #ifndef RENDER_H #define RENDER_H @@ -31,28 +37,9 @@ VG_STATIC struct pipeline glmesh fsquad; framebuffer *fb_main, - *fb_heightmap, *fb_water_reflection, *fb_water_beneath; - /* STD140 */ - struct ub_world_lighting - { - /* v3f (padded) */ - v4f g_light_colours[3], - g_light_directions[3], - g_ambient_colour; - - v4f g_water_plane, - g_depth_bounds; - - float g_water_fog; - int g_light_count; - int g_light_preview; - int g_shadow_samples; - } - ub_world_lighting; - struct light_widget { int enabled; @@ -62,8 +49,6 @@ VG_STATIC struct pipeline widgets[3]; float shadow_spread, shadow_length; - GLuint ubo_world_lighting, - ubo_world; int ready; } @@ -89,11 +74,6 @@ gpipeline = }, .shadow_spread = 0.65f, .shadow_length = 9.50f, - - .ub_world_lighting = - { - .g_ambient_colour = { 0.09f, 0.03f, 0.07f } - } }; struct framebuffer @@ -172,36 +152,13 @@ framebuffers[] = } } }, - { - /* - * A ortho projection of the world, used for shadows and ocean colouring. - * Note: it does not have a render buffer attachement because it's - * intended to be drawn to in a MAX blending mode - */ - "heightmap", - .link = &gpipeline.fb_heightmap, - .fixed_w = 1024, - .fixed_h = 1024, - - .attachments = - { - { - "depth", k_framebuffer_attachment_type_colour, - - .internalformat = GL_R32F, - .format = GL_RED, - .type = GL_FLOAT, - .attachment = GL_COLOR_ATTACHMENT0 - } - } - }, { /* * Second rendered view from the perspective of the water reflection */ "water_reflection", .link = &gpipeline.fb_water_reflection, - .resolution_div = 3, + .resolution_div = 2, .attachments = { { @@ -226,13 +183,13 @@ framebuffers[] = */ "water_beneath", .link = &gpipeline.fb_water_beneath, - .resolution_div = 4, + .resolution_div = 2, .attachments = { { "colour", k_framebuffer_attachment_type_colour, - .internalformat = GL_RGBA, - .format = GL_RGBA, + .internalformat = GL_RED, + .format = GL_RED, .type = GL_UNSIGNED_BYTE, .attachment = GL_COLOR_ATTACHMENT0 }, @@ -297,51 +254,6 @@ VG_STATIC void render_fb_bind_texture( framebuffer *fb, /* * Shaders */ -VG_STATIC void shader_link_standard_ub( GLuint shader, int texture_id ) -{ - GLuint idx = glGetUniformBlockIndex( shader, "ub_world_lighting" ); - glUniformBlockBinding( shader, idx, 0 ); - - render_fb_bind_texture( gpipeline.fb_heightmap, 0, texture_id ); - glUniform1i( glGetUniformLocation( shader, "g_world_depth" ), texture_id ); -} - -VG_STATIC void render_update_lighting_ub(void) -{ - struct ub_world_lighting *winf = &gpipeline.ub_world_lighting; - int c = 0; - - for( int i=0; i<3; i++ ) - { - struct light_widget *lw = &gpipeline.widgets[i]; - - if( lw->enabled ) - { - float pitch = lw->dir[0], - yaw = lw->dir[1], - xz = cosf( pitch ); - - v3_copy( (v3f){ xz*cosf(yaw), sinf(pitch), xz*sinf(yaw) }, - winf->g_light_directions[c] ); - v3_copy( lw->colour, winf->g_light_colours[c] ); - - c ++; - } - } - - winf->g_light_count = c; - winf->g_light_directions[0][3] = gpipeline.shadow_length; - winf->g_light_colours[0][3] = gpipeline.shadow_spread; - - if( vg.quality_profile == k_quality_profile_low ) - winf->g_shadow_samples = 0; - else - winf->g_shadow_samples = 8; - - glBindBuffer( GL_UNIFORM_BUFFER, gpipeline.ubo_world_lighting ); - glBufferSubData( GL_UNIFORM_BUFFER, 0, sizeof(struct ub_world_lighting), - &gpipeline.ub_world_lighting ); -} #define FB_FORMAT_STR( E ) { E, #E }, @@ -592,6 +504,7 @@ 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_info( "[render] Allocate quad\n" ); @@ -631,7 +544,8 @@ VG_STATIC void render_init_fs_quad(void) vg_function_push( (struct vg_cmd) { .name = "fb", - .function = render_framebuffer_control + .function = render_framebuffer_control, + .poll_suggest = render_framebuffer_poll }); glGenVertexArrays( 1, &gpipeline.fsquad.vao ); @@ -647,27 +561,11 @@ VG_STATIC void render_init_fs_quad(void) VG_CHECK_GL_ERR(); } -VG_STATIC void render_init_uniform_buffers(void) -{ - vg_info( "[render] Allocate uniform buffer\n" ); - - glGenBuffers( 1, &gpipeline.ubo_world_lighting ); - glBindBuffer( GL_UNIFORM_BUFFER, gpipeline.ubo_world_lighting ); - glBufferData( GL_UNIFORM_BUFFER, sizeof(struct ub_world_lighting), - NULL, GL_DYNAMIC_DRAW ); - - render_update_lighting_ub(); - glBindBufferBase( GL_UNIFORM_BUFFER, 0, gpipeline.ubo_world_lighting ); - - VG_CHECK_GL_ERR(); -} - VG_STATIC void render_init(void) { shader_blit_register(); shader_blitblur_register(); - shader_standard_register(); - shader_vblend_register(); + shader_blitcolour_register(); vg_acquire_thread_sync(); { @@ -681,7 +579,6 @@ VG_STATIC void render_init(void) } render_init_fs_quad(); - render_init_uniform_buffers(); glBindFramebuffer( GL_FRAMEBUFFER, 0 ); gpipeline.ready = 1; @@ -832,4 +729,54 @@ VG_STATIC int render_framebuffer_control( int argc, char const *argv[] ) return 0; } +VG_STATIC void render_framebuffer_poll( int argc, char const *argv[] ) +{ + const char *term = argv[argc-1]; + + if( argc == 1 ) + { + console_suggest_score_text( "show", term, 0 ); + console_suggest_score_text( "hide", term, 0 ); + } + else if( argc == 2 ) + { + console_suggest_score_text( "all", term, 0 ); + + for( int i=0; idisplay_name, term, 0 ); + } + } + else if( argc == 3 ) + { + int modify_all = 0; + + if( !strcmp( argv[1], "all" ) ) + modify_all = 1; + + for( int i=0; iattachments); j++ ) + { + struct framebuffer_attachment *at = &fb->attachments[j]; + + if( at->purpose == k_framebuffer_attachment_type_none ) + continue; + + if( modify_all ) + { + console_suggest_score_text( at->display_name, term, 0 ); + } + else if( !strcmp( fb->display_name, argv[1] ) ) + { + console_suggest_score_text( at->display_name, term, 0 ); + } + } + } + } +} + #endif /* RENDER_H */