medium sized dollop
[vg.git] / src / vg / vg_tex.h
index 71c79c0105a422ff0233d601e7c69d143f08f493..9e0c56f6e18bebb8551edaa7add1ab586759dd3b 100644 (file)
@@ -2,10 +2,14 @@
 #ifndef VG_TEX_H
 #define VG_TEX_H
 
+#include "vg/vg.h"
+#include "vg/vg_log.h"
+
 #define VG_TEXTURE_NO_MIP      0x1
 #define VG_TEXTURE_REPEAT      0x2
 #define VG_TEXTURE_CLAMP       0x4
 #define VG_TEXTURE_NEAREST     0x8
+#define VG_TEXTURE_ALLOCATED_INTERNAL 0x10
 
 struct vg_tex2d
 {
@@ -21,6 +25,12 @@ struct vg_sprite
 
 static void vg_tex2d_bind( vg_tex2d *tex, u32 id )
 {
+   if( !(tex->flags & VG_TEXTURE_ALLOCATED_INTERNAL) )
+   {
+      vg_error( "Tried to use '%s' while unloaded!\n", tex->path );
+      return;
+   }
+
        glActiveTexture( GL_TEXTURE0 + id );
        glBindTexture( GL_TEXTURE_2D, tex->name );
 }
@@ -101,7 +111,7 @@ static GLuint vg_tex2d_rgba( const char *path )
 
 static void vg_tex2d_init( vg_tex2d *textures[], int num )
 {
-       for( int i = 0; i < num; i ++ )
+       for( int i=0; i<num; i ++ )
        {
                vg_tex2d *tex = textures[i];
                tex->name = vg_tex2d_rgba( tex->path );
@@ -127,6 +137,8 @@ static void vg_tex2d_init( vg_tex2d *textures[], int num )
                        vg_tex2d_clamp();
                else
                        vg_tex2d_repeat();
+
+      tex->flags |= VG_TEXTURE_ALLOCATED_INTERNAL;
        }
 }