datamap object passed around while loading
[laserbrain_demo] / src / texture.cc
index dddc0d1..3aebec3 100644 (file)
@@ -1,9 +1,11 @@
 #include <math.h>
 #include <assert.h>
 #include "texture.h"
+#include "datamap.h"
 #include "image.h"
 #include "opengl.h"
 #include "imago2.h"
+#include "logger.h"
 
 static int glifmt_from_ifmt(unsigned int ifmt);
 static int glfmt_from_ifmt(unsigned int ifmt);
@@ -148,7 +150,7 @@ void Texture::bind(int tex_unit) const
 void Texture::create(int xsz, int ysz, TextureType textype, unsigned int ifmt)
 {
        if(textype == TEX_CUBE && xsz != ysz) {
-               fprintf(stderr, "trying to create cubemap with different width and height (%dx%d)\n", xsz, ysz);
+               error_log("trying to create cubemap with different width and height (%dx%d)\n", xsz, ysz);
                return;
        }
 
@@ -200,7 +202,6 @@ void Texture::create_default(TextureType type)
                                pixels += 4;
                        }
                }
-               default_img->save("/tmp/foo.png");
        }
 
        switch(type) {
@@ -321,12 +322,12 @@ bool Texture::load(const char *fname)
 {
        Image img;
        if(!img.load(fname)) {
-               fprintf(stderr, "failed to load 2D texture: %s\n", fname);
+               error_log("failed to load 2D texture: %s\n", fname);
                return false;
        }
        set_image(img);
 
-       printf("loaded 2D texture: %s\n", fname);
+       info_log("loaded 2D texture: %s\n", fname);
        return true;
 }
 
@@ -467,17 +468,26 @@ TextureSet::TextureSet()
 {
 }
 
-Texture *TextureSet::get_texture(const char *name, TextureType type) const
+Texture *TextureSet::get_texture(const char *name, TextureType type, const DataMap *dmap) const
 {
-       std::map<std::string, Texture*>::const_iterator iter = data.find(name);
+       char *fname;
+       int nsize = dmap ? dmap->path_size(name) : 0;
+       if(nsize) {
+               fname = (char*)alloca(nsize);
+               dmap->lookup(name, fname, nsize);
+       } else {
+               fname = (char*)name;
+       }
+
+       std::map<std::string, Texture*>::const_iterator iter = data.find(fname);
        if(iter != data.end()) {
                return iter->second;
        }
 
        Texture *res = create();
-       data[name] = res;
+       data[fname] = res;
        res->create_default(type);
-       resman_lookup(rman, name, res);
+       resman_lookup(rman, fname, res);
        return res;
 }