background scene file loading introduces race condition with datamaps
[laserbrain_demo] / src / material.cc
index f893175..6b10534 100644 (file)
@@ -34,13 +34,29 @@ void Material::setup() const
 
 void Material::add_texture(Texture *tex, int type)
 {
-       textures.push_back(tex);
+       if(std::find(textures.begin(), textures.end(), tex) == textures.end()) {
+               textures.push_back(tex);
+       }
 
        if(type != MTL_TEX_UNKNOWN) {
                stdtex[type] = tex;
        }
 }
 
+void Material::remove_texture(Texture *tex)
+{
+       std::vector<Texture*>::iterator it = std::find(textures.begin(), textures.end(), tex);
+       if(it != textures.end()) {
+               textures.erase(it);
+       }
+
+       for(int i=0; i<NUM_MTL_TEXTURES; i++) {
+               if(stdtex[i] == tex) {
+                       stdtex[i] = 0;
+               }
+       }
+}
+
 int mtl_parse_type(const char *str)
 {
        if(strcmp(str, "diffuse") == 0) {