heebie
[vg.git] / vg_shader.h
index 2ee1ef4f457143f7acbd73d92787f5639071d679..50e8bd0e291589a17d32b17fe1c11f0038e9234e 100644 (file)
@@ -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";
 
@@ -73,71 +71,66 @@ VG_STATIC GLuint vg_shader_subshader( const char *src, GLint gliShaderType )
 
 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;