{
vg_acquire_thread_sync();
-#if 0
vg_function_push( (struct vg_cmd)
{
- .name = "shaders",
+ .name = "reload_shaders",
.function = vg_shaders_live_recompile
});
-#endif
vg_shaders_compile();
vg_release_thread_sync();
SDL_WINDOWPOS_UNDEFINED,
vg.window_x, vg.window_y,
- SDL_WINDOW_FULLSCREEN |
+ SDL_WINDOW_FULLSCREEN_DESKTOP |
SDL_WINDOW_OPENGL |
SDL_WINDOW_INPUT_GRABBED )))
{
/* Warnings */
strcat( cmd,
- " -Wall -ferror-limit=0\\\n"
+ " -Wall\\\n"
" -Wno-unused-function -Wno-unused-variable\\\n"
" -Wno-unused-command-line-argument -Wno-unused-but-set-variable\\\n"
);
static void parse_uniform_name( char *start, struct uniform *uf )
{
uf->array = 0;
+ int type_set = 0;
+
for( int i=0;; i++ )
{
if( start[i] == '\0' )
if( start[i] == ' ' )
{
start[i] = '\0';
- strncpy( uf->type, start, sizeof(uf->type) );
+
+ if( !type_set )
+ {
+ strncpy( uf->type, start, sizeof(uf->type) );
+ type_set = 1;
+ }
start = start+i+1;
i=0;
}
else
{
fprintf( header, "{\n"
- ".static_src = \n" );
+ ".orig_file = \"%s\",\n"
+ ".static_src = \n",
+ name );
char *cur = full, *start = full;
while( 1 )
for( int i=0; i<vg_shaderbuild.uniform_count; i++ )
{
struct uniform *uf = &vg_shaderbuild.uniform_buffer[i];
- if( uf->array ) continue;
+ if( uf->array )
+ continue;
for( int j=0; j<vg_list_size(types); j ++ )
{
int persistent; /* Should this var be stored to cfg/auto.conf? */
}
- vars[ 64 ];
+ vars[ 128 ];
struct vg_cmd
{
{
SDL_GameControllerButton gamepad_id;
SDL_Keycode keyboard_id;
+ int mouse_id;
int value, prev;
}
button;
bind->axis.keyboard_negative = -1;
bind->button.gamepad_id = -1;
bind->button.keyboard_id = -1;
+ bind->button.mouse_id = -1;
}
VG_STATIC struct input_binding *vg_create_named_input( const char *name,
bind->axis.keyboard_negative = -1;
bind->button.gamepad_id = -1;
bind->button.keyboard_id = -1;
+ bind->button.mouse_id = -1;
return bind;
}
{k_input_type_gamepad_button, "gp-dpad-left", SDL_CONTROLLER_BUTTON_DPAD_LEFT},
{k_input_type_gamepad_button,"gp-dpad-right",SDL_CONTROLLER_BUTTON_DPAD_RIGHT},
{k_input_type_gamepad_button, "gp-dpad-up", SDL_CONTROLLER_BUTTON_DPAD_UP},
- {k_input_type_gamepad_button, "\2gp-menu", SDL_CONTROLLER_BUTTON_BACK}
+ {k_input_type_gamepad_button, "\2gp-menu", SDL_CONTROLLER_BUTTON_BACK},
+
+ {k_input_type_mouse_button, "mouse1", SDL_BUTTON_LEFT },
+ {k_input_type_mouse_button, "mouse2", SDL_BUTTON_RIGHT }
};
VG_STATIC const char *vg_input_to_str( u32 input, enum input_type input_type )
vg_info( " keyboard_id: %s\n",
vg_input_to_str(bind->button.keyboard_id,
k_input_type_keyboard_key));
+ vg_info( " mouse_id: %s\n",
+ vg_input_to_str(bind->button.mouse_id,
+ k_input_type_mouse_button));
}
}
if( type == k_input_type_keyboard_key )
bind->button.keyboard_id = id;
+ else if( type == k_input_type_mouse_button )
+ bind->button.mouse_id = id;
else if( type == k_input_type_gamepad_button )
bind->button.gamepad_id = id;
else
vg_input.controller_buttons[ bind->button.gamepad_id ];
if( bind->button.keyboard_id != -1 )
+ {
bind->button.value |= vg_getkey( bind->button.keyboard_id );
+ }
+
+ if( bind->button.mouse_id != -1 )
+ {
+ if( SDL_GetMouseState(NULL, NULL) &
+ SDL_BUTTON( bind->button.mouse_id ) )
+ bind->button.value |= 1;
+ }
}
else if( bind->type == k_input_type_axis )
{
vg_line2( from, to, colour, colour );
}
+VG_STATIC void line_tangent_basis( v3f n, v3f tx, v3f ty )
+{
+ /* Compute tangent basis (box2d) */
+ if( fabsf( n[0] ) >= 0.57735027f )
+ {
+ tx[0] = n[1];
+ tx[1] = -n[0];
+ tx[2] = 0.0f;
+ }
+ else
+ {
+ tx[0] = 0.0f;
+ tx[1] = n[2];
+ tx[2] = -n[1];
+ }
+
+ v3_normalize( tx );
+ v3_cross( n, tx, ty );
+}
+
+VG_STATIC void vg_line_arrow( line_co co, line_co dir, float size, u32 colour )
+{
+ v3f p1, tx, ty, p2, p3;
+ v3_muladds( co, dir, size, p1 );
+ line_tangent_basis( dir, tx, ty );
+
+ v3_muladds( p1, dir, -size * 0.125f, p2 );
+ v3_muladds( p2, ty, size * 0.125f, p3 );
+ v3_muladds( p2, ty, -size * 0.125f, p2 );
+
+ vg_line( co, p1, colour );
+ vg_line( p1, p2, colour );
+ vg_line( p1, p3, colour );
+}
+
VG_STATIC void vg_line_boxf( boxf box, u32 colour )
{
v3f p000, p001, p010, p011, p100, p101, p110, p111;
#define KCYN "\x1B[36m"
#define KWHT "\x1B[37m"
+#define PRINTF_v2f( V2 ) "%.2f %.2f\n", V2[0], V2[1]
+#define PRINTF_v3f( V3 ) "%.2f %.2f %.2f\n", V3[0], V3[1], V3[2]
+#define PRINTF_v4f( V4 ) "%.2f %.2f %.2f %.2f\n", V4[0], V4[1], V4[2], V4[3]
+
#ifdef VG_GAME
static SDL_SpinLock log_print_sl;
#endif
return 1;
}
+static int plane_segment( v4f plane, v3f a, v3f b, v3f co )
+{
+ float d0 = v3_dot( a, plane ) - plane[3],
+ d1 = v3_dot( b, plane ) - plane[3];
+
+ if( d0*d1 < 0.0f )
+ {
+ float tot = 1.0f/( fabsf(d0)+fabsf(d1) );
+
+ v3_muls( a, fabsf(d1) * tot, co );
+ v3_muladds( co, b, fabsf(d0) * tot, co );
+ return 1;
+ }
+
+ return 0;
+}
static inline double plane_polarity( double p[4], double a[3] )
{
}
}
+static void q_mulv( v4f q, v3f v, v3f d )
+{
+ v3f v1, v2;
+
+ v3_muls( q, 2.0f*v3_dot(q,v), v1 );
+ v3_muls( v, q[3]*q[3] - v3_dot(q,q), v2 );
+ v3_add( v1, v2, v1 );
+ v3_cross( q, v, v2 );
+ v3_muls( v2, 2.0f*q[3], v2 );
+ v3_add( v1, v2, d );
+}
+
enum contact_type
{
k_contact_type_default,
return v3_length2( v0 );
}
+VG_STATIC int point_inside_aabb( boxf box, v3f point )
+{
+ if((point[0]<=box[1][0]) && (point[1]<=box[1][1]) && (point[2]<=box[1][2]) &&
+ (point[0]>=box[0][0]) && (point[1]>=box[0][1]) && (point[2]>=box[0][2]) )
+ return 1;
+ else
+ return 0;
+}
+
VG_STATIC void closest_point_aabb( v3f p, boxf box, v3f dest )
{
v3_maxv( p, box[0], dest );
#include "vg/vg.h"
#include "vg/vg_platform.h"
-#if 0
#define STB_INCLUDE_IMPLEMENTATION
#define STB_INCLUDE_LINE_GLSL
#define STB_MALLOC vg_alloc
#define STB_FREE vg_free
#define STB_REALLOC vg_realloc
-#include "stb/stb_include.h"
-#endif
+#include "submodules/stb/stb_include.h"
const char *vg_shader_gl_ver = "#version 330 core\n";
VG_STATIC int vg_shader_compile( struct vg_shader *shader )
{
- vg_info( "Compile shader '%s'\n", shader->name );
-
GLuint program, vert, frag;
- const char *svs, *sfs;
- char *avs, *afs;
- int static_src = 1;
-
/* If we are compiling this again, we obviously need to try to take the src
* from the disk instead.
*
* Only do this if we have filenames set on the shader, so engine shaders
* dont have to do it (text.. etc).
*/
+
+ int use_source_files = 0;
if( shader->compiled )
{
if( shader->vs.orig_file && shader->fs.orig_file )
- static_src = 0;
- else return 1;
+ {
+ use_source_files = 1;
+ }
+ else
+ {
+ vg_warn( "No source files for shader '%s'\n", shader->name );
+ return 1;
+ }
}
- if( static_src )
- {
- svs = shader->vs.static_src;
- sfs = shader->fs.static_src;
- }
- else
- {
- vg_fatal_exit_loop( "Unimplemented" );
+ vg_info( "Compile shader '%s'\n", shader->name );
-#if 0
+ if( use_source_files )
+ {
char error[260];
char path[260];
- strcpy( path, shader->vs.orig_file );
- avs = stb_include_file( path, "", "../../shaders", error );
- strcpy( path, shader->fs.orig_file );
- afs = stb_include_file( path, "", "../../shaders", error );
+ strcpy( path, "../../" );
+ strcat( path, shader->vs.orig_file );
+ char *vertex_src = stb_include_file( path, "", "../../shaders", error );
+
+ strcpy( path, "../../" );
+ strcat( path, shader->fs.orig_file );
+ char *fragment_src = stb_include_file( path, "", "../../shaders", error );
- if( !avs || !afs )
+ if( !vertex_src || !fragment_src )
{
vg_error( "Could not find shader source files (%s)\n",
- shader->vs.orig_file );
+ shader->vs.orig_file );
- vg_free( avs );
- vg_free( afs );
+ free( vertex_src );
+ free( fragment_src );
return 0;
}
- svs = avs;
- sfs = afs;
-#endif
+ vert = vg_shader_subshader( vertex_src, GL_VERTEX_SHADER );
+ frag = vg_shader_subshader( fragment_src, GL_FRAGMENT_SHADER );
+
+ free( vertex_src );
+ free( fragment_src );
}
-
- vert = vg_shader_subshader( svs, GL_VERTEX_SHADER );
- frag = vg_shader_subshader( sfs, GL_FRAGMENT_SHADER );
-
-#if 0
- if( !static_src )
+ else
{
- free( avs );
- free( afs );
+ vert = vg_shader_subshader( shader->vs.static_src, GL_VERTEX_SHADER );
+ frag = vg_shader_subshader( shader->fs.static_src, GL_FRAGMENT_SHADER );
}
-#endif
-
+
if( !vert || !frag )
return 0;