diff --git a/experimental/README.md b/experimental/README.md index 99378ce..a0603af 100644 --- a/experimental/README.md +++ b/experimental/README.md @@ -6,11 +6,21 @@ * C++-11 compiler +## How to build + +``` +$ premak5 gmake +``` + ## Compile options * zstd compressed .obj support. `--with-zstd` premake option. * gzip compressed .obj support. `--with-zlib` premake option. +## Notes on AMD GPU + Linux + +You may need to link with libdrm(`-ldrm`). + ## Licenses * lfpAlloc : MIT license. diff --git a/tiny_obj_loader.h b/tiny_obj_loader.h index ac1421e..a6c4a02 100644 --- a/tiny_obj_loader.h +++ b/tiny_obj_loader.h @@ -57,6 +57,9 @@ namespace tinyobj { #if __has_warning("-Wzero-as-null-pointer-constant") #pragma clang diagnostic ignored "-Wzero-as-null-pointer-constant" #endif + +#pragma clang diagnostic ignored "-Wpadded" + #endif // https://en.wikipedia.org/wiki/Wavefront_.obj_file says ... @@ -369,6 +372,7 @@ void LoadMtl(std::map *material_map, #include #include #include +#include #include #include @@ -866,22 +870,22 @@ static bool ParseTextureNameAndOption(std::string *texname, } else { texopt->imfchan = 'm'; } - texopt->bump_multiplier = 1.0f; + texopt->bump_multiplier = static_cast(1.0); texopt->clamp = false; texopt->blendu = true; texopt->blendv = true; - texopt->sharpness = 1.0f; - texopt->brightness = 0.0f; - texopt->contrast = 1.0f; - texopt->origin_offset[0] = 0.0f; - texopt->origin_offset[1] = 0.0f; - texopt->origin_offset[2] = 0.0f; - texopt->scale[0] = 1.0f; - texopt->scale[1] = 1.0f; - texopt->scale[2] = 1.0f; - texopt->turbulence[0] = 0.0f; - texopt->turbulence[1] = 0.0f; - texopt->turbulence[2] = 0.0f; + texopt->sharpness = static_cast(1.0); + texopt->brightness = static_cast(0.0); + texopt->contrast = static_cast(1.0); + texopt->origin_offset[0] = static_cast(0.0); + texopt->origin_offset[1] = static_cast(0.0); + texopt->origin_offset[2] = static_cast(0.0); + texopt->scale[0] = static_cast(1.0); + texopt->scale[1] = static_cast(1.0); + texopt->scale[2] = static_cast(1.0); + texopt->turbulence[0] = static_cast(0.0); + texopt->turbulence[1] = static_cast(0.0); + texopt->turbulence[2] = static_cast(0.0); texopt->type = TEXTURE_TYPE_NONE; const char *token = linebuf; // Assume line ends with NULL @@ -967,24 +971,24 @@ static void InitMaterial(material_t *material) { material->reflection_texname = ""; material->alpha_texname = ""; for (int i = 0; i < 3; i++) { - material->ambient[i] = 0.f; - material->diffuse[i] = 0.f; - material->specular[i] = 0.f; - material->transmittance[i] = 0.f; - material->emission[i] = 0.f; + material->ambient[i] = static_cast(0.0); + material->diffuse[i] = static_cast(0.0); + material->specular[i] = static_cast(0.0); + material->transmittance[i] = static_cast(0.0); + material->emission[i] = static_cast(0.0); } material->illum = 0; - material->dissolve = 1.f; - material->shininess = 1.f; - material->ior = 1.f; + material->dissolve = static_cast(1.0); + material->shininess = static_cast(1.0); + material->ior = static_cast(1.0); - material->roughness = 0.f; - material->metallic = 0.f; - material->sheen = 0.f; - material->clearcoat_thickness = 0.f; - material->clearcoat_roughness = 0.f; - material->anisotropy_rotation = 0.f; - material->anisotropy = 0.f; + material->roughness = static_cast(0.0); + material->metallic = static_cast(0.0); + material->sheen = static_cast(0.0); + material->clearcoat_thickness = static_cast(0.0); + material->clearcoat_roughness = static_cast(0.0); + material->anisotropy_rotation = static_cast(0.0); + material->anisotropy = static_cast(0.0); material->roughness_texname = ""; material->metallic_texname = ""; material->sheen_texname = ""; @@ -995,8 +999,9 @@ static void InitMaterial(material_t *material) { } // code from https://wrf.ecse.rpi.edu//Research/Short_Notes/pnpoly.html -static int pnpoly(int nvert, float *vertx, float *verty, float testx, - float testy) { +template +static int pnpoly(int nvert, T *vertx, T *verty, T testx, + T testy) { int i, j, c = 0; for (i = 0, j = nvert - 1; i < nvert; j = i++) { if (((verty[i] > testy) != (verty[j] > testy)) && @@ -1054,10 +1059,10 @@ static bool exportFaceGroupToShape(shape_t *shape, real_t e1x = v2x - v1x; real_t e1y = v2y - v1y; real_t e1z = v2z - v1z; - float cx = std::fabs(e0y * e1z - e0z * e1y); - float cy = std::fabs(e0z * e1x - e0x * e1z); - float cz = std::fabs(e0x * e1y - e0y * e1x); - const float epsilon = 0.0001f; + real_t cx = std::fabs(e0y * e1z - e0z * e1y); + real_t cy = std::fabs(e0z * e1x - e0x * e1z); + real_t cz = std::fabs(e0x * e1y - e0y * e1x); + const real_t epsilon = std::numeric_limits::epsilon(); if (cx > epsilon || cy > epsilon || cz > epsilon) { // found a corner if (cx > cy && cx > cz) { @@ -1079,7 +1084,7 @@ static bool exportFaceGroupToShape(shape_t *shape, real_t v0y = v[vi0 * 3 + axes[1]]; real_t v1x = v[vi1 * 3 + axes[0]]; real_t v1y = v[vi1 * 3 + axes[1]]; - area += (v0x * v1y - v0y * v1x) * 0.5f; + area += (v0x * v1y - v0y * v1x) * static_cast(0.5); } int maxRounds = @@ -1108,7 +1113,7 @@ static bool exportFaceGroupToShape(shape_t *shape, real_t e1y = vy[2] - vy[1]; real_t cross = e0x * e1y - e0y * e1x; // if an internal angle - if (cross * area < 0.0f) { + if (cross * area < static_cast(0.0)) { guess_vert += 1; continue; } @@ -1396,7 +1401,7 @@ void LoadMtl(std::map *material_map, // We invert value of Tr(assume Tr is in range [0, 1]) // NOTE: Interpretation of Tr is application(exporter) dependent. For // some application(e.g. 3ds max obj exporter), Tr = d(Issue 43) - material.dissolve = 1.0f - parseReal(&token); + material.dissolve = static_cast(1.0) - parseReal(&token); } has_tr = true; continue;