Merge pull request #386 from geometrian/master

Fix Clang Compile Warnings/Errors (and Typos)
This commit is contained in:
Syoyo Fujita 2022-10-08 19:08:22 +09:00 committed by GitHub
commit 091a1fcc1a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -32,7 +32,7 @@
// - v2.6.0 Support serializing sparse accessor(Thanks to @fynv). // - v2.6.0 Support serializing sparse accessor(Thanks to @fynv).
// Disable expanding file path for security(no use of awkward `wordexp` anymore). // Disable expanding file path for security(no use of awkward `wordexp` anymore).
// - v2.5.0 Add SetPreserveImageChannels() option to load image data as is. // - v2.5.0 Add SetPreserveImageChannels() option to load image data as is.
// - v2.4.3 Fix null object output when when material has all default // - v2.4.3 Fix null object output when material has all default
// parameters. // parameters.
// - v2.4.2 Decode percent-encoded URI. // - v2.4.2 Decode percent-encoded URI.
// - v2.4.1 Fix some glTF object class does not have `extensions` and/or // - v2.4.1 Fix some glTF object class does not have `extensions` and/or
@ -46,7 +46,7 @@
// - v2.2.0 Add loading 16bit PNG support. Add Sparse accessor support(Thanks // - v2.2.0 Add loading 16bit PNG support. Add Sparse accessor support(Thanks
// to @Ybalrid) // to @Ybalrid)
// - v2.1.0 Add draco compression. // - v2.1.0 Add draco compression.
// - v2.0.1 Add comparsion feature(Thanks to @Selmar). // - v2.0.1 Add comparison feature(Thanks to @Selmar).
// - v2.0.0 glTF 2.0!. // - v2.0.0 glTF 2.0!.
// //
// Tiny glTF loader is using following third party libraries: // Tiny glTF loader is using following third party libraries:
@ -233,7 +233,7 @@ static inline int32_t GetComponentSizeInBytes(uint32_t componentType) {
} else if (componentType == TINYGLTF_COMPONENT_TYPE_DOUBLE) { } else if (componentType == TINYGLTF_COMPONENT_TYPE_DOUBLE) {
return 8; return 8;
} else { } else {
// Unknown componenty type // Unknown component type
return -1; return -1;
} }
} }
@ -254,7 +254,7 @@ static inline int32_t GetNumComponentsInType(uint32_t ty) {
} else if (ty == TINYGLTF_TYPE_MAT4) { } else if (ty == TINYGLTF_TYPE_MAT4) {
return 16; return 16;
} else { } else {
// Unknown componenty type // Unknown component type
return -1; return -1;
} }
} }
@ -441,7 +441,7 @@ TINYGLTF_VALUE_GET(Value::Object, object_value_)
#pragma clang diagnostic ignored "-Wpadded" #pragma clang diagnostic ignored "-Wpadded"
#endif #endif
/// Agregate object for representing a color /// Aggregate object for representing a color
using ColorValue = std::array<double, 4>; using ColorValue = std::array<double, 4>;
// === legacy interface ==== // === legacy interface ====
@ -478,7 +478,7 @@ struct Parameter {
if (it != std::end(json_double_value)) { if (it != std::end(json_double_value)) {
return int(it->second); return int(it->second);
} }
// As per the spec, if texCoord is ommited, this parameter is 0 // As per the spec, if texCoord is omitted, this parameter is 0
return 0; return 0;
} }
@ -490,7 +490,7 @@ struct Parameter {
if (it != std::end(json_double_value)) { if (it != std::end(json_double_value)) {
return it->second; return it->second;
} }
// As per the spec, if scale is ommited, this paramter is 1 // As per the spec, if scale is omitted, this parameter is 1
return 1; return 1;
} }
@ -502,7 +502,7 @@ struct Parameter {
if (it != std::end(json_double_value)) { if (it != std::end(json_double_value)) {
return it->second; return it->second;
} }
// As per the spec, if strenghth is ommited, this parameter is 1 // As per the spec, if strength is omitted, this parameter is 1
return 1; return 1;
} }
@ -516,7 +516,7 @@ struct Parameter {
/// material /// material
ColorValue ColorFactor() const { ColorValue ColorFactor() const {
return { return {
{// this agregate intialize the std::array object, and uses C++11 RVO. {// this aggregate initialize the std::array object, and uses C++11 RVO.
number_array[0], number_array[1], number_array[2], number_array[0], number_array[1], number_array[2],
(number_array.size() > 3 ? number_array[3] : 1.0)}}; (number_array.size() > 3 ? number_array[3] : 1.0)}};
} }
@ -827,7 +827,7 @@ struct BufferView {
size_t byteStride{0}; // minimum 4, maximum 252 (multiple of 4), default 0 = size_t byteStride{0}; // minimum 4, maximum 252 (multiple of 4), default 0 =
// understood to be tightly packed // understood to be tightly packed
int target{0}; // ["ARRAY_BUFFER", "ELEMENT_ARRAY_BUFFER"] for vertex indices int target{0}; // ["ARRAY_BUFFER", "ELEMENT_ARRAY_BUFFER"] for vertex indices
// or atttribs. Could be 0 for other data // or attribs. Could be 0 for other data
Value extras; Value extras;
ExtensionMap extensions; ExtensionMap extensions;
@ -903,7 +903,7 @@ struct Accessor {
return componentSizeInBytes * numComponents; return componentSizeInBytes * numComponents;
} else { } else {
// Check if byteStride is a mulple of the size of the accessor's component // Check if byteStride is a multiple of the size of the accessor's component
// type. // type.
int componentSizeInBytes = int componentSizeInBytes =
GetComponentSizeInBytes(static_cast<uint32_t>(componentType)); GetComponentSizeInBytes(static_cast<uint32_t>(componentType));
@ -942,7 +942,7 @@ struct PerspectiveCamera {
PerspectiveCamera() PerspectiveCamera()
: aspectRatio(0.0), : aspectRatio(0.0),
yfov(0.0), yfov(0.0),
zfar(0.0) // 0 = use infinite projecton matrix zfar(0.0) // 0 = use infinite projection matrix
, ,
znear(0.0) {} znear(0.0) {}
DEFAULT_METHODS(PerspectiveCamera) DEFAULT_METHODS(PerspectiveCamera)
@ -1003,7 +1003,7 @@ struct Primitive {
int indices; // The index of the accessor that contains the indices. int indices; // The index of the accessor that contains the indices.
int mode; // one of TINYGLTF_MODE_*** int mode; // one of TINYGLTF_MODE_***
std::vector<std::map<std::string, int> > targets; // array of morph targets, std::vector<std::map<std::string, int> > targets; // array of morph targets,
// where each target is a dict with attribues in ["POSITION, "NORMAL", // where each target is a dict with attributes in ["POSITION, "NORMAL",
// "TANGENT"] pointing // "TANGENT"] pointing
// to their corresponding accessors // to their corresponding accessors
ExtensionMap extensions; ExtensionMap extensions;
@ -1138,7 +1138,7 @@ struct Light {
std::vector<double> color; std::vector<double> color;
double intensity{1.0}; double intensity{1.0};
std::string type; std::string type;
double range{0.0}; // 0.0 = inifinite double range{0.0}; // 0.0 = infinite
SpotLight spot; SpotLight spot;
Light() : intensity(1.0), range(0.0) {} Light() : intensity(1.0), range(0.0) {}
@ -1288,7 +1288,7 @@ bool WriteWholeFile(std::string *err, const std::string &filepath,
#endif #endif
/// ///
/// glTF Parser/Serialier context. /// glTF Parser/Serializer context.
/// ///
class TinyGLTF { class TinyGLTF {
public: public:
@ -1351,7 +1351,7 @@ class TinyGLTF {
unsigned int check_sections = REQUIRE_VERSION); unsigned int check_sections = REQUIRE_VERSION);
/// ///
/// Write glTF to stream, buffers and images will be embeded /// Write glTF to stream, buffers and images will be embedded
/// ///
bool WriteGltfSceneToStream(Model *model, std::ostream &stream, bool WriteGltfSceneToStream(Model *model, std::ostream &stream,
bool prettyPrint, bool writeBinary); bool prettyPrint, bool writeBinary);
@ -1386,7 +1386,7 @@ class TinyGLTF {
/// ///
/// Set serializing default values(default = false). /// Set serializing default values(default = false).
/// When true, default values are force serialized to .glTF. /// When true, default values are force serialized to .glTF.
/// This may be helpfull if you want to serialize a full description of glTF /// This may be helpful if you want to serialize a full description of glTF
/// data. /// data.
/// ///
/// TODO(LTE): Supply parsing option as function arguments to /// TODO(LTE): Supply parsing option as function arguments to
@ -1412,8 +1412,8 @@ class TinyGLTF {
} }
/// ///
/// Specify whether preserve image channales when loading images or not. /// Specify whether preserve image channels when loading images or not.
/// (Not effective when the user suppy their own LoadImageData callbacks) /// (Not effective when the user supplies their own LoadImageData callbacks)
/// ///
void SetPreserveImageChannels(bool onoff) { void SetPreserveImageChannels(bool onoff) {
preserve_image_channels_ = onoff; preserve_image_channels_ = onoff;
@ -1550,7 +1550,7 @@ class TinyGLTF {
#endif #endif
#endif #endif
// Disable GCC warnigs // Disable GCC warnings
#ifdef __GNUC__ #ifdef __GNUC__
#pragma GCC diagnostic push #pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wtype-limits" #pragma GCC diagnostic ignored "-Wtype-limits"
@ -1599,7 +1599,7 @@ class TinyGLTF {
// issue 143. // issue 143.
// Define NOMINMAX to avoid min/max defines, // Define NOMINMAX to avoid min/max defines,
// but undef it after included windows.h // but undef it after included Windows.h
#ifndef NOMINMAX #ifndef NOMINMAX
#define TINYGLTF_INTERNAL_NOMINMAX #define TINYGLTF_INTERNAL_NOMINMAX
#define NOMINMAX #define NOMINMAX
@ -1609,7 +1609,11 @@ class TinyGLTF {
#define WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN
#define TINYGLTF_INTERNAL_WIN32_LEAN_AND_MEAN #define TINYGLTF_INTERNAL_WIN32_LEAN_AND_MEAN
#endif #endif
#include <windows.h> // include API for expanding a file path #ifndef __MINGW32__
#include <Windows.h> // include API for expanding a file path
#else
#include <windows.h>
#endif
#ifdef TINYGLTF_INTERNAL_WIN32_LEAN_AND_MEAN #ifdef TINYGLTF_INTERNAL_WIN32_LEAN_AND_MEAN
#undef WIN32_LEAN_AND_MEAN #undef WIN32_LEAN_AND_MEAN
@ -1740,7 +1744,7 @@ namespace tinygltf {
struct LoadImageDataOption { struct LoadImageDataOption {
// true: preserve image channels(e.g. load as RGB image if the image has RGB // true: preserve image channels(e.g. load as RGB image if the image has RGB
// channels) default `false`(channels are expanded to RGBA for backward // channels) default `false`(channels are expanded to RGBA for backward
// compatiblity). // compatibility).
bool preserve_channels{false}; bool preserve_channels{false};
}; };
@ -2387,7 +2391,7 @@ bool LoadImageData(Image *image, const int image_idx, std::string *err,
// It is possible that the image we want to load is a 16bit per channel image // It is possible that the image we want to load is a 16bit per channel image
// We are going to attempt to load it as 16bit per channel, and if it worked, // We are going to attempt to load it as 16bit per channel, and if it worked,
// set the image data accodingly. We are casting the returned pointer into // set the image data accordingly. We are casting the returned pointer into
// unsigned char, because we are representing "bytes". But we are updating // unsigned char, because we are representing "bytes". But we are updating
// the Image metadata to signal that this image uses 2 bytes (16bits) per // the Image metadata to signal that this image uses 2 bytes (16bits) per
// channel: // channel:
@ -2402,7 +2406,7 @@ bool LoadImageData(Image *image, const int image_idx, std::string *err,
// at this point, if data is still NULL, it means that the image wasn't // at this point, if data is still NULL, it means that the image wasn't
// 16bit per channel, we are going to load it as a normal 8bit per channel // 16bit per channel, we are going to load it as a normal 8bit per channel
// mage as we used to do: // image as we used to do:
// if image cannot be decoded, ignore parsing and keep it by its path // if image cannot be decoded, ignore parsing and keep it by its path
// don't break in this case // don't break in this case
// FIXME we should only enter this function if the image is embedded. If // FIXME we should only enter this function if the image is embedded. If
@ -2562,7 +2566,7 @@ void TinyGLTF::SetFsCallbacks(FsCallbacks callbacks) { fs = callbacks; }
static inline std::wstring UTF8ToWchar(const std::string &str) { static inline std::wstring UTF8ToWchar(const std::string &str) {
int wstr_size = int wstr_size =
MultiByteToWideChar(CP_UTF8, 0, str.data(), (int)str.size(), nullptr, 0); MultiByteToWideChar(CP_UTF8, 0, str.data(), (int)str.size(), nullptr, 0);
std::wstring wstr(wstr_size, 0); std::wstring wstr((size_t)wstr_size, 0);
MultiByteToWideChar(CP_UTF8, 0, str.data(), (int)str.size(), &wstr[0], MultiByteToWideChar(CP_UTF8, 0, str.data(), (int)str.size(), &wstr[0],
(int)wstr.size()); (int)wstr.size());
return wstr; return wstr;
@ -2570,10 +2574,10 @@ static inline std::wstring UTF8ToWchar(const std::string &str) {
static inline std::string WcharToUTF8(const std::wstring &wstr) { static inline std::string WcharToUTF8(const std::wstring &wstr) {
int str_size = WideCharToMultiByte(CP_UTF8, 0, wstr.data(), (int)wstr.size(), int str_size = WideCharToMultiByte(CP_UTF8, 0, wstr.data(), (int)wstr.size(),
nullptr, 0, NULL, NULL); nullptr, 0, nullptr, nullptr);
std::string str(str_size, 0); std::string str((size_t)str_size, 0);
WideCharToMultiByte(CP_UTF8, 0, wstr.data(), (int)wstr.size(), &str[0], WideCharToMultiByte(CP_UTF8, 0, wstr.data(), (int)wstr.size(), &str[0],
(int)str.size(), NULL, NULL); (int)str.size(), nullptr, nullptr);
return str; return str;
} }
#endif #endif
@ -2826,7 +2830,7 @@ static void UpdateImageObject(Image &image, std::string &baseDir, int index,
void *user_data = nullptr) { void *user_data = nullptr) {
std::string filename; std::string filename;
std::string ext; std::string ext;
// If image has uri, use it it as a filename // If image has uri, use it as a filename
if (image.uri.size()) { if (image.uri.size()) {
filename = GetBaseFilename(image.uri); filename = GetBaseFilename(image.uri);
ext = GetFilePathExtension(filename); ext = GetFilePathExtension(filename);
@ -4272,7 +4276,7 @@ static bool ParseSparseAccessor(Accessor *accessor, std::string *err,
} }
if (!FindMember(o, "values", values_iterator)) { if (!FindMember(o, "values", values_iterator)) {
(*err) = "the sparse object ob ths accessor doesn't have values"; (*err) = "the sparse object of this accessor doesn't have values";
return false; return false;
} }
@ -4618,7 +4622,7 @@ static bool ParsePrimitive(Primitive *primitive, Model *model, std::string *err,
int mode = TINYGLTF_MODE_TRIANGLES; int mode = TINYGLTF_MODE_TRIANGLES;
ParseIntegerProperty(&mode, err, o, "mode", false); ParseIntegerProperty(&mode, err, o, "mode", false);
primitive->mode = mode; // Why only triangled were supported ? primitive->mode = mode; // Why only triangles were supported ?
int indices = -1; int indices = -1;
ParseIntegerProperty(&indices, err, o, "indices", false); ParseIntegerProperty(&indices, err, o, "indices", false);
@ -4901,7 +4905,7 @@ static bool ParseMaterial(Material *material, std::string *err, const json &o,
// Old code path. For backward compatibility, we still store material values // Old code path. For backward compatibility, we still store material values
// as Parameter. This will create duplicated information for // as Parameter. This will create duplicated information for
// example(pbrMetallicRoughness), but should be neglible in terms of memory // example(pbrMetallicRoughness), but should be negligible in terms of memory
// consumption. // consumption.
// TODO(syoyo): Remove in the next major release. // TODO(syoyo): Remove in the next major release.
material->values.clear(); material->values.clear();
@ -4934,7 +4938,7 @@ static bool ParseMaterial(Material *material, std::string *err, const json &o,
Parameter param; Parameter param;
if (ParseParameterProperty(&param, err, o, key, false)) { if (ParseParameterProperty(&param, err, o, key, false)) {
// names of materials have already been parsed. Putting it in this map // names of materials have already been parsed. Putting it in this map
// doesn't correctly reflext the glTF specification // doesn't correctly reflect the glTF specification
if (key != "name") if (key != "name")
material->additionalValues.emplace(std::move(key), std::move(param)); material->additionalValues.emplace(std::move(key), std::move(param));
} }
@ -5140,7 +5144,7 @@ static bool ParseSampler(Sampler *sampler, std::string *err, const json &o,
// ParseIntegerProperty(&wrapR, err, o, "wrapR", false); // tinygltf // ParseIntegerProperty(&wrapR, err, o, "wrapR", false); // tinygltf
// extension // extension
// TODO(syoyo): Check the value is alloed one. // TODO(syoyo): Check the value is allowed one.
// (e.g. we allow 9728(NEAREST), but don't allow 9727) // (e.g. we allow 9728(NEAREST), but don't allow 9727)
sampler->minFilter = minFilter; sampler->minFilter = minFilter;
@ -5349,7 +5353,7 @@ static bool ParseCamera(Camera *camera, std::string *err, const json &o,
if (!FindMember(o, "orthographic", orthoIt)) { if (!FindMember(o, "orthographic", orthoIt)) {
if (err) { if (err) {
std::stringstream ss; std::stringstream ss;
ss << "Orhographic camera description not found." << std::endl; ss << "Orthographic camera description not found." << std::endl;
(*err) += ss.str(); (*err) += ss.str();
} }
return false; return false;
@ -5801,7 +5805,7 @@ bool TinyGLTF::LoadFromString(Model *model, std::string *err, std::string *warn,
model->bufferViews[size_t(bufferView)].target = model->bufferViews[size_t(bufferView)].target =
TINYGLTF_TARGET_ELEMENT_ARRAY_BUFFER; TINYGLTF_TARGET_ELEMENT_ARRAY_BUFFER;
// we could optionally check if acessors' bufferView type is Scalar, as // we could optionally check if accessors' bufferView type is Scalar, as
// it should be // it should be
} }
@ -5810,7 +5814,7 @@ bool TinyGLTF::LoadFromString(Model *model, std::string *err, std::string *warn,
if (accessorsIndex < model->accessors.size()) { if (accessorsIndex < model->accessors.size()) {
const auto bufferView = model->accessors[accessorsIndex].bufferView; const auto bufferView = model->accessors[accessorsIndex].bufferView;
// bufferView could be null(-1) for sparse morph target // bufferView could be null(-1) for sparse morph target
if (bufferView >= 0 && bufferView < model->bufferViews.size()) { if (bufferView >= 0 && bufferView < (int)model->bufferViews.size()) {
model->bufferViews[size_t(bufferView)].target = model->bufferViews[size_t(bufferView)].target =
TINYGLTF_TARGET_ARRAY_BUFFER; TINYGLTF_TARGET_ARRAY_BUFFER;
} }
@ -5823,7 +5827,7 @@ bool TinyGLTF::LoadFromString(Model *model, std::string *err, std::string *warn,
if (accessorsIndex < model->accessors.size()) { if (accessorsIndex < model->accessors.size()) {
const auto bufferView = model->accessors[accessorsIndex].bufferView; const auto bufferView = model->accessors[accessorsIndex].bufferView;
// bufferView could be null(-1) for sparse morph target // bufferView could be null(-1) for sparse morph target
if (bufferView >= 0 && bufferView < model->bufferViews.size()) { if (bufferView >= 0 && bufferView < (int)model->bufferViews.size()) {
model->bufferViews[size_t(bufferView)].target = model->bufferViews[size_t(bufferView)].target =
TINYGLTF_TARGET_ARRAY_BUFFER; TINYGLTF_TARGET_ARRAY_BUFFER;
} }
@ -6324,7 +6328,7 @@ bool TinyGLTF::LoadBinaryFromMemory(Model *model, std::string *err,
bin_size_ = 0; bin_size_ = 0;
} else { } else {
// Read Chunk1 info(BIN data) // Read Chunk1 info(BIN data)
// At least Chunk1 should have 12 bytes(8 bytes(header) + 4 bytes(bin payload could be 1~3 bytes, but need to be aliged to 4 bytes) // At least Chunk1 should have 12 bytes(8 bytes(header) + 4 bytes(bin payload could be 1~3 bytes, but need to be aligned to 4 bytes)
if ((header_and_json_size + 12ull) > uint64_t(length)) { if ((header_and_json_size + 12ull) > uint64_t(length)) {
if (err) { if (err) {
(*err) = "Insufficient storage space for Chunk1(BIN data). At least Chunk1 Must have 4 bytes or more bytes, but got " + std::to_string((header_and_json_size + 12ull) - uint64_t(length)) + ".\n"; (*err) = "Insufficient storage space for Chunk1(BIN data). At least Chunk1 Must have 4 bytes or more bytes, but got " + std::to_string((header_and_json_size + 12ull) - uint64_t(length)) + ".\n";
@ -6364,7 +6368,7 @@ bool TinyGLTF::LoadBinaryFromMemory(Model *model, std::string *err,
if (chunk1_format != 0x004e4942) { if (chunk1_format != 0x004e4942) {
if (err) { if (err) {
(*err) = "Invlid type for chunk1 data."; (*err) = "Invalid type for chunk1 data.";
} }
return false; return false;
} }
@ -6653,7 +6657,7 @@ static void SerializeGltfBufferData(const std::vector<unsigned char> &data,
SerializeStringProperty("uri", header + encodedData, o); SerializeStringProperty("uri", header + encodedData, o);
} else { } else {
// Issue #229 // Issue #229
// size 0 is allowd. Just emit mime header. // size 0 is allowed. Just emit mime header.
SerializeStringProperty("uri", header, o); SerializeStringProperty("uri", header, o);
} }
} }
@ -7151,7 +7155,7 @@ static void SerializeGltfMaterial(Material &material, json &o) {
// Do not serialize `pbrMetallicRoughness` if pbrMetallicRoughness has all // Do not serialize `pbrMetallicRoughness` if pbrMetallicRoughness has all
// default values(json is null). Otherwise it will serialize to // default values(json is null). Otherwise it will serialize to
// `pbrMetallicRoughness : null`, which cannot be read by other glTF // `pbrMetallicRoughness : null`, which cannot be read by other glTF
// importers(and validators). // importers (and validators).
// //
if (!JsonIsNull(pbrMetallicRoughness)) { if (!JsonIsNull(pbrMetallicRoughness)) {
JsonAddMember(o, "pbrMetallicRoughness", std::move(pbrMetallicRoughness)); JsonAddMember(o, "pbrMetallicRoughness", std::move(pbrMetallicRoughness));
@ -7193,7 +7197,7 @@ static void SerializeGltfMesh(Mesh &mesh, json &o) {
JsonAddMember(primitive, "attributes", std::move(attributes)); JsonAddMember(primitive, "attributes", std::move(attributes));
} }
// Indicies is optional // Indices is optional
if (gltfPrimitive.indices > -1) { if (gltfPrimitive.indices > -1) {
SerializeNumberProperty<int>("indices", gltfPrimitive.indices, primitive); SerializeNumberProperty<int>("indices", gltfPrimitive.indices, primitive);
} }