Skip to content

Commit 7fcfafb

Browse files
committed
Fix compilation for double precision mode(Fixes #167).
1 parent 2dca727 commit 7fcfafb

2 files changed

Lines changed: 53 additions & 38 deletions

File tree

experimental/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,21 @@
66

77
* C++-11 compiler
88

9+
## How to build
10+
11+
```
12+
$ premak5 gmake
13+
```
14+
915
## Compile options
1016

1117
* zstd compressed .obj support. `--with-zstd` premake option.
1218
* gzip compressed .obj support. `--with-zlib` premake option.
1319

20+
## Notes on AMD GPU + Linux
21+
22+
You may need to link with libdrm(`-ldrm`).
23+
1424
## Licenses
1525

1626
* lfpAlloc : MIT license.

tiny_obj_loader.h

Lines changed: 43 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ namespace tinyobj {
5757
#if __has_warning("-Wzero-as-null-pointer-constant")
5858
#pragma clang diagnostic ignored "-Wzero-as-null-pointer-constant"
5959
#endif
60+
61+
#pragma clang diagnostic ignored "-Wpadded"
62+
6063
#endif
6164

6265
// https://en.wikipedia.org/wiki/Wavefront_.obj_file says ...
@@ -369,6 +372,7 @@ void LoadMtl(std::map<std::string, int> *material_map,
369372
#include <cstdlib>
370373
#include <cstring>
371374
#include <utility>
375+
#include <limits>
372376

373377
#include <fstream>
374378
#include <sstream>
@@ -866,22 +870,22 @@ static bool ParseTextureNameAndOption(std::string *texname,
866870
} else {
867871
texopt->imfchan = 'm';
868872
}
869-
texopt->bump_multiplier = 1.0f;
873+
texopt->bump_multiplier = static_cast<real_t>(1.0);
870874
texopt->clamp = false;
871875
texopt->blendu = true;
872876
texopt->blendv = true;
873-
texopt->sharpness = 1.0f;
874-
texopt->brightness = 0.0f;
875-
texopt->contrast = 1.0f;
876-
texopt->origin_offset[0] = 0.0f;
877-
texopt->origin_offset[1] = 0.0f;
878-
texopt->origin_offset[2] = 0.0f;
879-
texopt->scale[0] = 1.0f;
880-
texopt->scale[1] = 1.0f;
881-
texopt->scale[2] = 1.0f;
882-
texopt->turbulence[0] = 0.0f;
883-
texopt->turbulence[1] = 0.0f;
884-
texopt->turbulence[2] = 0.0f;
877+
texopt->sharpness = static_cast<real_t>(1.0);
878+
texopt->brightness = static_cast<real_t>(0.0);
879+
texopt->contrast = static_cast<real_t>(1.0);
880+
texopt->origin_offset[0] = static_cast<real_t>(0.0);
881+
texopt->origin_offset[1] = static_cast<real_t>(0.0);
882+
texopt->origin_offset[2] = static_cast<real_t>(0.0);
883+
texopt->scale[0] = static_cast<real_t>(1.0);
884+
texopt->scale[1] = static_cast<real_t>(1.0);
885+
texopt->scale[2] = static_cast<real_t>(1.0);
886+
texopt->turbulence[0] = static_cast<real_t>(0.0);
887+
texopt->turbulence[1] = static_cast<real_t>(0.0);
888+
texopt->turbulence[2] = static_cast<real_t>(0.0);
885889
texopt->type = TEXTURE_TYPE_NONE;
886890

887891
const char *token = linebuf; // Assume line ends with NULL
@@ -967,24 +971,24 @@ static void InitMaterial(material_t *material) {
967971
material->reflection_texname = "";
968972
material->alpha_texname = "";
969973
for (int i = 0; i < 3; i++) {
970-
material->ambient[i] = 0.f;
971-
material->diffuse[i] = 0.f;
972-
material->specular[i] = 0.f;
973-
material->transmittance[i] = 0.f;
974-
material->emission[i] = 0.f;
974+
material->ambient[i] = static_cast<real_t>(0.0);
975+
material->diffuse[i] = static_cast<real_t>(0.0);
976+
material->specular[i] = static_cast<real_t>(0.0);
977+
material->transmittance[i] = static_cast<real_t>(0.0);
978+
material->emission[i] = static_cast<real_t>(0.0);
975979
}
976980
material->illum = 0;
977-
material->dissolve = 1.f;
978-
material->shininess = 1.f;
979-
material->ior = 1.f;
980-
981-
material->roughness = 0.f;
982-
material->metallic = 0.f;
983-
material->sheen = 0.f;
984-
material->clearcoat_thickness = 0.f;
985-
material->clearcoat_roughness = 0.f;
986-
material->anisotropy_rotation = 0.f;
987-
material->anisotropy = 0.f;
981+
material->dissolve = static_cast<real_t>(1.0);
982+
material->shininess = static_cast<real_t>(1.0);
983+
material->ior = static_cast<real_t>(1.0);
984+
985+
material->roughness = static_cast<real_t>(0.0);
986+
material->metallic = static_cast<real_t>(0.0);
987+
material->sheen = static_cast<real_t>(0.0);
988+
material->clearcoat_thickness = static_cast<real_t>(0.0);
989+
material->clearcoat_roughness = static_cast<real_t>(0.0);
990+
material->anisotropy_rotation = static_cast<real_t>(0.0);
991+
material->anisotropy = static_cast<real_t>(0.0);
988992
material->roughness_texname = "";
989993
material->metallic_texname = "";
990994
material->sheen_texname = "";
@@ -995,8 +999,9 @@ static void InitMaterial(material_t *material) {
995999
}
9961000

9971001
// code from https://wrf.ecse.rpi.edu//Research/Short_Notes/pnpoly.html
998-
static int pnpoly(int nvert, float *vertx, float *verty, float testx,
999-
float testy) {
1002+
template<typename T>
1003+
static int pnpoly(int nvert, T *vertx, T *verty, T testx,
1004+
T testy) {
10001005
int i, j, c = 0;
10011006
for (i = 0, j = nvert - 1; i < nvert; j = i++) {
10021007
if (((verty[i] > testy) != (verty[j] > testy)) &&
@@ -1054,10 +1059,10 @@ static bool exportFaceGroupToShape(shape_t *shape,
10541059
real_t e1x = v2x - v1x;
10551060
real_t e1y = v2y - v1y;
10561061
real_t e1z = v2z - v1z;
1057-
float cx = std::fabs(e0y * e1z - e0z * e1y);
1058-
float cy = std::fabs(e0z * e1x - e0x * e1z);
1059-
float cz = std::fabs(e0x * e1y - e0y * e1x);
1060-
const float epsilon = 0.0001f;
1062+
real_t cx = std::fabs(e0y * e1z - e0z * e1y);
1063+
real_t cy = std::fabs(e0z * e1x - e0x * e1z);
1064+
real_t cz = std::fabs(e0x * e1y - e0y * e1x);
1065+
const real_t epsilon = std::numeric_limits<real_t>::epsilon();
10611066
if (cx > epsilon || cy > epsilon || cz > epsilon) {
10621067
// found a corner
10631068
if (cx > cy && cx > cz) {
@@ -1079,7 +1084,7 @@ static bool exportFaceGroupToShape(shape_t *shape,
10791084
real_t v0y = v[vi0 * 3 + axes[1]];
10801085
real_t v1x = v[vi1 * 3 + axes[0]];
10811086
real_t v1y = v[vi1 * 3 + axes[1]];
1082-
area += (v0x * v1y - v0y * v1x) * 0.5f;
1087+
area += (v0x * v1y - v0y * v1x) * static_cast<real_t>(0.5);
10831088
}
10841089

10851090
int maxRounds =
@@ -1108,7 +1113,7 @@ static bool exportFaceGroupToShape(shape_t *shape,
11081113
real_t e1y = vy[2] - vy[1];
11091114
real_t cross = e0x * e1y - e0y * e1x;
11101115
// if an internal angle
1111-
if (cross * area < 0.0f) {
1116+
if (cross * area < static_cast<real_t>(0.0)) {
11121117
guess_vert += 1;
11131118
continue;
11141119
}
@@ -1396,7 +1401,7 @@ void LoadMtl(std::map<std::string, int> *material_map,
13961401
// We invert value of Tr(assume Tr is in range [0, 1])
13971402
// NOTE: Interpretation of Tr is application(exporter) dependent. For
13981403
// some application(e.g. 3ds max obj exporter), Tr = d(Issue 43)
1399-
material.dissolve = 1.0f - parseReal(&token);
1404+
material.dissolve = static_cast<real_t>(1.0) - parseReal(&token);
14001405
}
14011406
has_tr = true;
14021407
continue;

0 commit comments

Comments
 (0)