X-Git-Url: https://harrygodden.com/git/?p=vg.git;a=blobdiff_plain;f=vg_loader.h;h=87472b615bb6b08371c63e90f1d93a733a6496f9;hp=f62763d5ca63445115a206cb3fc5d296efefbac0;hb=HEAD;hpb=651edda3736812c89f43c11319c6b485ff14ea19 diff --git a/vg_loader.h b/vg_loader.h index f62763d..ec8fb0d 100644 --- a/vg_loader.h +++ b/vg_loader.h @@ -1,5 +1,6 @@ + /* - * Copyright 2021-2022 (C) Mount0 Software, Harry Godden - All Rights Reserved + * Copyright 2021-2024 (C) Mount0 Software, Harry Godden - All Rights Reserved * ----------------------------------------------------------------------------- * * Splash / load screen @@ -7,118 +8,12 @@ * ----------------------------------------------------------------------------- */ -#ifndef VG_LOADER_H -#define VG_LOADER_H - -#include "common.h" - -VG_STATIC void vg_loader_start( void(*pfn)(void) ); -VG_STATIC void vg_loader_step( void( *fn_load )(void), void( *fn_free )(void) ); +#pragma once -static struct vg_shader _shader_loader = -{ - .name = "[vg] loader", - .link = NULL, - - /* This is the old background shader */ -#if 0 - .vs = - { - .orig_file = NULL, - .static_src = "" - "layout (location=0) in vec2 a_co;" - "out vec2 aUv;" - "void main()" - "{" - "gl_Position = vec4(a_co*2.0-1.0,0.0,1.0);" - "aUv = a_co;" - "}" - }, - .fs = - { - .orig_file = NULL, - .static_src = - - "out vec4 FragColor;" - "uniform float uTime;" - "in vec2 aUv;" - - "void main()" - "{" - "float dither=fract(dot(vec2(171.0,231.0),gl_FragCoord.xy)/71.0)-0.5;" - "float grad = 1.0-(aUv.y*0.5+0.5)*0.5;" - "float fmt1 = step( 0.5, grad+dither );" - - "vec3 col = 0.5+0.5*sin( uTime + aUv.xyx + vec3(0.0,2.0,4.0) );" - - "FragColor = vec4(vec3(0.5,0.5,0.5)*grad*fmt1,1.0);" - "}" - } -#else - - /* This is the new foreground shader */ - - .vs = - { - .orig_file = NULL, - .static_src = "" - "layout (location=0) in vec2 a_co;" - "out vec2 aUv;" - "void main()" - "{" - "gl_Position = vec4(a_co*2.0-1.0,0.0,1.0);" - "aUv = a_co;" - "}" - }, - .fs = - { - .orig_file = NULL, - .static_src = - - "out vec4 FragColor;" - "uniform float uTime;" - "uniform float uRatio;" - "in vec2 aUv;" - - "float eval_zero( vec2 uv )" - "{" - "vec4 vsines = sin( (uTime+uv.y*80.0) * vec4(1.1,2.0234,3.73,2.444) );" - "float gradient = min( uv.y, 0.0 );" - "float offset = vsines.x*vsines.y*vsines.z*vsines.w*gradient;" - - "vec2 vpos = uv + vec2( offset, 0.0 );" - "float dist = dot( vpos, vpos );" - - "float fring = step(0.1*0.1,dist) * step(dist,0.15*0.15);" - "return max( 0.0, fring * 1.0+gradient*6.0 );" - "}" - - "void main()" - "{" - - "vec3 col = 0.5+0.5*sin( uTime + aUv.xyx + vec3(0.0,2.0,4.0) );" - - "vec2 uvx = aUv - vec2( 0.5 );" - "uvx.x *= uRatio;" - "uvx.y *= 0.75;" - - "float zero = eval_zero( uvx );" - - "float dither=fract(dot(vec2(171.0,231.0),gl_FragCoord.xy)/71.0)-0.5;" - "float fmt1 = step( 0.5, zero*zero + dither )*0.8+0.2;" - - "FragColor = vec4(vec3(fmt1),0.8);" - "}" - } - -#endif -}; - -static struct vg_loader +struct vg_loader { /* Shutdown steps */ - struct loader_free_step - { + struct loader_free_step{ void (*fn_free)(void); } step_buffer[16]; @@ -126,153 +21,16 @@ static struct vg_loader GLuint vao, vbo; } -vg_loader; - -VG_STATIC void _vg_loader_init(void) -{ - float quad[] = { 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f, - 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f }; - - glGenVertexArrays( 1, &vg_loader.vao ); - glGenBuffers( 1, &vg_loader.vbo ); - glBindVertexArray( vg_loader.vao ); - glBindBuffer( GL_ARRAY_BUFFER, vg_loader.vbo ); - glBufferData( GL_ARRAY_BUFFER, sizeof(quad), quad, GL_STATIC_DRAW ); - glBindVertexArray( vg_loader.vao ); - glVertexAttribPointer( 0, 2, GL_FLOAT, GL_FALSE, sizeof(float)*2, (void*)0 ); - glEnableVertexAttribArray( 0 ); - - VG_CHECK_GL_ERR(); - - if( !vg_shader_compile( &_shader_loader ) ) - vg_fatal_error( "failed to compile shader" ); -} - -VG_STATIC void _vg_loader_free(void) -{ - vg_info( "vg_loader_free\n" ); - glDeleteVertexArrays( 1, &vg_loader.vao ); - glDeleteBuffers( 1, &vg_loader.vbo ); - - for( int i=0; i %p\n", step->fn_free ); - step->fn_free(); - } - - vg_info( "done\n" ); -} - -VG_STATIC void _vg_render_log(void) -{ - ui_begin( vg.window_x, vg.window_y ); - SDL_AtomicLock( &log_print_sl ); - - int const fh = 14; - int lines_screen_max = ((vg.window_y/fh)-2), - lines_max_draw = VG_MIN( lines_screen_max, vg_list_size(vg_log.buffer) ), - lines_to_draw = VG_MIN( lines_max_draw, vg_log.buffer_line_count ); - - int ptr = vg_log.buffer_line_current; - - vg_uictx.cursor[0] = 0; - vg_uictx.cursor[1] = lines_to_draw*fh; - vg_uictx.cursor[3] = fh; - ui_fill_x(); - - for( int i=0; i