-Material::Texture::Texture(const std::string &fileName) {
- auto path = "models/" + fileName;
- auto provider = CGDataProviderCreateWithFilename(path.c_str());
- std::ifstream file(path);
- long magic;
- file.read((char*)&magic, 8);
- file.close();
+Material::Texture::Texture(const aiString fileName, const aiScene &scene) {
+ glGenTextures(1, &texId);
+ glBindTexture(GL_TEXTURE_2D, texId);
+
+ std::string path;
+ if (fileName.data[0] == '*') {
+ // embedded
+ int embIdx = atoi(&fileName.data[1]);
+ aiTexture *texture = scene.mTextures[embIdx];
+ if (texture->mHeight == 0) {
+ Image img((unsigned char*)texture->pcData, texture->mWidth, texture->achFormatHint);
+ glTexImage2D(GL_TEXTURE_2D, 0, img.internalFormat(), img.width(), img.height(), 0, img.format(), img.type(), img.data());
+ } else {
+ fprintf(stderr, "TODO: handle uncompressed embedded textures");
+ abort();
+ }
+ } else {
+ // not embedded
+ Image img("models/" + std::string(fileName.C_Str()));
+ glTexImage2D(GL_TEXTURE_2D, 0, img.internalFormat(), img.width(), img.height(), 0, img.format(), img.type(), img.data());
+ }