model.cpp
// Checks all material textures of a given type and loads the textures if they're not loaded yet.
// The required info is returned as a Texture struct.
Checks all material textures of a given type and loads the textures if they're not loaded yet.
The required info is returned as a Texture struct.
Checks all material textures of a given type and loads the textures if they ' re not loaded yet . The required info is returned as a Texture struct .
vector<Texture> Model::loadMaterialTextures(aiMaterial *mat, aiTextureType type, string typeName)
{
    vector<Texture> textures;
    for (GLuint i = 0; i < mat->GetTextureCount(type); i++)
    {
        aiString str;
        mat->GetTexture(type, i, &str);
        GLboolean skip = false;
        for (GLuint j = 0; j < textures_loaded.size(); j++)
        {
            if (textures_loaded[j].path == str)
            {
                textures.push_back(textures_loaded[j]);
                skip = true; 
                break;
            }
        }
        if (!skip)
        { 
            Texture texture;
            texture.id = TextureFromFile(str.C_Str(), this->directory);
            texture.type = typeName;
            texture.path = str;
            textures.push_back(texture);
            this->textures_loaded.push_back(
                    texture); 
        }
    }
    return textures;
}
vector < Texture > Model :: loadMaterialTextures ( aiMaterial * mat , aiTextureType type , string typeName ) { vector < Texture > textures ; for ( GLuint i = 0 ; i < mat -> GetTextureCount ( type ) ; i ++ ) { aiString str ; mat -> GetTexture ( type , i , & str ) ; GLboolean skip = false ; for ( GLuint j = 0 ; j < textures_loaded . size ( ) ; j ++ ) { if ( textures_loaded [ j ] . path == str ) { textures . push_back ( textures_loaded [ j ] ) ; skip = true ; break ; } } if ( ! skip ) { Texture texture ; texture . id = TextureFromFile ( str . C_Str ( ) , this -> directory ) ; texture . type = typeName ; texture . path = str ; textures . push_back ( texture ) ; this -> textures_loaded . push_back ( texture ) ; } } return textures ; }
Checks all material textures of a given type and loads the textures if they're not loaded yet.
Checks all material textures of a given type and loads the textures if they ' re not loaded yet .
// Check if texture was loaded before and if so, continue to next iteration: skip loading a new texture // A texture with the same filepath has already been loaded, continue to next one. (optimization) // If texture hasn't been loaded already, load it // Store it as texture loaded for entire model, to ensure we won't unnecessary load duplicate textures.