X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=vg_shader.h;h=6537ec9c659064c42f4ca86a6c82627209cef962;hb=76d234b7dc5e6500e8a54009b367e7620f11ef97;hp=2ee1ef4f457143f7acbd73d92787f5639071d679;hpb=a7938c00a8c486ad0e2a765c3092017487ba761e;p=vg.git diff --git a/vg_shader.h b/vg_shader.h index 2ee1ef4..6537ec9 100644 --- a/vg_shader.h +++ b/vg_shader.h @@ -7,14 +7,12 @@ #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"; @@ -42,7 +40,7 @@ struct } static vg_shaders; -VG_STATIC GLuint vg_shader_subshader( const char *src, GLint gliShaderType ) +static GLuint vg_shader_subshader( const char *src, GLint gliShaderType ) { GLint shader = glCreateShader( gliShaderType ); @@ -71,73 +69,69 @@ VG_STATIC GLuint vg_shader_subshader( const char *src, GLint gliShaderType ) return shader; } -VG_STATIC int vg_shader_compile( struct vg_shader *shader ) +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). */ - if( shader->compiled ) - { - if( shader->vs.orig_file && shader->fs.orig_file ) - static_src = 0; - else return 1; - } - if( static_src ) - { - svs = shader->vs.static_src; - sfs = shader->fs.static_src; + int use_source_files = 0; + if( shader->compiled ){ + if( shader->vs.orig_file && shader->fs.orig_file ){ + use_source_files = 1; + } + else { + vg_warn( "No source files for shader '%s'\n", shader->name ); + return 1; + } } - else - { - vg_fatal_exit_loop( "Unimplemented" ); -#if 0 + vg_info( "Compile shader '%s'\n", shader->name ); + + 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 ); - - if( !avs || !afs ) - { - vg_error( "Could not find shader source files (%s)\n", - shader->vs.orig_file ); + strcpy( path, "../../" ); + strcat( path, shader->vs.orig_file ); + char *vertex_src = stb_include_file( path, "", "../../shaders", error ); - vg_free( avs ); - vg_free( afs ); - return 0; + strcpy( path, "../../" ); + strcat( path, shader->fs.orig_file ); + char *fragment_src = stb_include_file( path, "", "../../shaders", error ); + + if( !vertex_src || !fragment_src ){ + const char *errstr = "Could not find shader source files (%s)\n"; + if( shader->compiled ){ + vg_warn( errstr, shader->vs.orig_file ); + free( vertex_src ); + free( fragment_src ); + return 1; + } + else{ + vg_error( errstr, shader->vs.orig_file ); + 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 ) - { - free( avs ); - free( afs ); + else{ + 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; @@ -173,7 +167,7 @@ VG_STATIC int vg_shader_compile( struct vg_shader *shader ) return 1; } -VG_STATIC void vg_free_shader( struct vg_shader *shader ) +static void vg_free_shader( struct vg_shader *shader ) { if( shader->compiled ) { @@ -182,20 +176,19 @@ VG_STATIC void vg_free_shader( struct vg_shader *shader ) } } -VG_STATIC void vg_shaders_compile(void) +static void vg_shaders_compile(void) { vg_info( "Compiling shaders\n" ); - for( int i=0; icompiled = 0; shader->id = 0; /* TODO: make this an error shader */