X-Git-Url: https://git.lukelau.me/?p=opengl.git;a=blobdiff_plain;f=material.cpp;h=32bf9e0fef2d9b609265955a1c455cc64ef99fef;hp=c059226009dfeef2e328238bb50a3286d0bcc47f;hb=99d2b81ce5567869469fe2e55722cc212370c7db;hpb=d381f617bef400fc157edf782008cafb018ed594 diff --git a/material.cpp b/material.cpp index c059226..32bf9e0 100644 --- a/material.cpp +++ b/material.cpp @@ -1,5 +1,6 @@ #include "material.hpp" #include "image.hpp" +#include Material::Material(const aiMaterial &ai, const aiScene &scene, GLuint progId): progId(progId) { aiString name; @@ -17,11 +18,15 @@ Material::Material(const aiMaterial &ai, const aiScene &scene, GLuint progId): p normal = new Texture(path, scene); path = ""; - ai.GetTexture(AI_MATKEY_GLTF_PBRMETALLICROUGHNESS_METALLICROUGHNESS_TEXTURE, 0, &path); + ai.GetTexture(AI_MATKEY_GLTF_PBRMETALLICROUGHNESS_METALLICROUGHNESS_TEXTURE, &path); metallicRoughness = new Texture(path, scene); path = ""; ai.GetTexture(aiTextureType_LIGHTMAP, 0, &path); + if (path == aiString("")) { + fprintf(stderr, "Material %s does not have an AO map", name.C_Str()); + abort(); + } ambientOcclusion = new Texture(path, scene); } @@ -36,7 +41,7 @@ Material::Texture::Texture(const aiString fileName, const aiScene &scene) { int embIdx = atoi(&fileName.data[1]); aiTexture *texture = scene.mTextures[embIdx]; if (texture->mHeight == 0) { - Image img((unsigned char*)texture->pcData, texture->mWidth); + 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");