diff --git a/CMakeLists.txt b/CMakeLists.txt index a1ee659f..1a1d4dc5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -689,6 +689,25 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") PROPERTIES COMPILE_FLAGS ${TUSDZ_COMPILE_FLAGS}) endif() +# Increase warning level for gcc. +elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU") + + set(TUSDZ_COMPILE_FLAGS + "-Wall " + ) + + option(TINYUSDZ_NO_WERROR "Don't set -Werror when building the tinyusdz library" ${TINYUSDZ_DEFAULT_NO_WERROR}) + if (NOT TINYUSDZ_NO_WERROR) + set(TUSDZ_COMPILE_FLAGS "${TUSDZ_COMPILE_FLAGS} -Werror") + endif() + + set_source_files_properties(${TINYUSDZ_SOURCES} + PROPERTIES COMPILE_FLAGS ${TUSDZ_COMPILE_FLAGS}) + + if (TINYUSDZ_WITH_C_API) + set_source_files_properties(${TINYUSDZ_C_API_SOURCES} + PROPERTIES COMPILE_FLAGS ${TUSDZ_COMPILE_FLAGS}) + endif() endif() if(TINYUSDZ_CUSTOM_COMPILE_FLAGS) diff --git a/README.md b/README.md index 8006dfd1..cc05e5a8 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,7 @@ * [examples/openglviewer](examples/openglviewer) OpenGL viewer * [examples/sdlviewer](examples/sdlviewer) Software raytracing viewer * For Vulkan and Android Vulkan example, please refer https://github.com/syoyo/Vulkan-glTF-USDZ-PBR for a while + * For OpenGL + MaterialX example, please refer ASF MaterialXViewer fork to load USD model through TinyUSDZ https://github.com/lighttransport/materialx ## Mid-term todo @@ -154,13 +155,6 @@ USD itself is a generic container of 3D scene data. Tydra is an interface to Renderers/Viewers and other DCCs. Tydra may be something like Tiny version of pxrUSD Hydra, but its API is completely different. See [src/tydra/README.md](src/tydra/README.md) for the background. -* Image color space - * sRGB - * Linear - * Rec.709 - * [ ] Partial support of OCIO(OpenColor IO) through TinyColorIO https://github.com/syoyo/tinycolorio . Currently SPI3DLut only. -* More details are T.B.W. - ## Notice TinyUSDZ does not support Reality Composer file format(`.reality`) since it uses proprietary file format and we cannot understand it(so no conversion support from/to Reality also). diff --git a/src/crate-reader.cc b/src/crate-reader.cc index 6ab41a70..f6b26808 100644 --- a/src/crate-reader.cc +++ b/src/crate-reader.cc @@ -2795,7 +2795,7 @@ bool CrateReader::UnpackValueRep(const crate::ValueRep &rep, CHECK_MEMORY_USAGE(sizeof(double)); - double v; + double v{0.0}; if (!_sr->read_double(&v)) { PUSH_ERROR("Failed to read Double value."); return false; diff --git a/src/external/tiny_dng_loader.h b/src/external/tiny_dng_loader.h index 777d0353..2e652f27 100644 --- a/src/external/tiny_dng_loader.h +++ b/src/external/tiny_dng_loader.h @@ -34,6 +34,7 @@ THE SOFTWARE. #include #include +#include namespace tinydng { @@ -251,6 +252,9 @@ struct DNGImage { std::vector data; // Decoded pixel data(len = spp * width * height * bps / 8) + std::array shutter_speed{0,0}; // numerator, denominator + std::array aperture_value{0,0}; // numerator, denominator + // Custom fields std::vector custom_fields; }; @@ -346,7 +350,7 @@ bool IsDNGFromMemory(const char* mem, unsigned int size, std::string* msg); #pragma clang diagnostic ignored "-Weverything" #endif -#define TINY_DNG_LOADER_DEBUG +//#define TINY_DNG_LOADER_DEBUG #ifdef TINY_DNG_LOADER_DEBUG #define TINY_DNG_DPRINTF(...) printf(__VA_ARGS__) #else @@ -1928,6 +1932,8 @@ int lj92_encode(uint16_t* image, int width, int height, int bitdepth, #endif #endif +// NOTE: - https://exiftool.org/TagNames/EXIF.html +// - https://helpx.adobe.com/photoshop/kb/dng-specification-tags.html typedef enum { TAG_NEW_SUBFILE_TYPE = 254, TAG_SUBFILE_TYPE = 255, @@ -1941,6 +1947,11 @@ typedef enum { TAG_ROWS_PER_STRIP = 278, TAG_STRIP_BYTE_COUNTS = 279, TAG_PLANAR_CONFIGURATION = 284, + TAG_TRANSFER_FUNCTION = 301, // int16u[768] + TAG_SOFTWARE = 305, // string + TAG_MODIFY_DATA = 306, // string + TAG_ARTIST = 315, // string + //TAG_HOST_COMPUTER = 316, TAG_PREDICTOR = 317, TAG_SUB_IFDS = 330, TAG_TILE_WIDTH = 322, @@ -1979,6 +1990,28 @@ typedef enum { TAG_CR2_SLICES = 50752, TAG_CR2_META2 = 50885, + TAG_EXPOSURE_TIME = 0x829a, // rational64u + TAG_F_NUMBER = 0x829d, // rational64u + TAG_EXPOSURE_PROGRAM = 0x8822, // int16u + TAG_GPS_INFO = 0x8825, + TAG_ISO = 0x8827, // int16u[n] + + TAG_SHUTTER_SPEED_VALUE = 0x9201, // rational64s + TAG_APERTURE_VALUE = 0x9202, // rational64u + TAG_BRIGHTNESS_VALUE = 0x9203, // rational64s + TAG_EXPOSURE_COMPENSATION = 0x9204, // rational64s + TAG_MAX_APERTURE_VALUE = 0x9205, // rational64u + TAG_SUBJECT_DISTANCE = 0x9206, // rational64u + TAG_METERING_MODE = 0x9207, // int16u + TAG_LIGHT_SOURCE = 0x9208, // int16u + TAG_FLASH = 0x9209, // int16u + TAG_FOCAL_LENGTH = 0x920a, // rational64u + + TAG_LENS_INFO = 0xa432, // rational64u[4] + TAG_LENS_MAKE = 0xa433, // string + TAG_LENS_MODEL = 0xa434, // string + TAG_LENS_SERIAL_NUMBER = 0xa435, // string + // // OpCodeList // @@ -1986,10 +2019,11 @@ typedef enum { TAG_OPCODE_LIST2 = 0xc741, TAG_OPCODE_LIST3 = 0xc742, - TAG_NOISE_PROFILE = 51041, + + TAG_NOISE_PROFILE = 0xc761, // DNG 1.6(Apple ProRAW) - // ahttps://helpx.adobe.com/photoshop/kb/dng-specification-tags.html + // https://helpx.adobe.com/photoshop/kb/dng-specification-tags.html TAG_SEMANTIC_NAME = 52526, // Type: ASCII, Count: String length including // null, Value: null-terminated string @@ -2447,6 +2481,56 @@ class StreamReader { // never come here. } + bool read_rational(int type, uint32_t* ret0, uint32_t *ret1) const { + // @todo { Support more types. } + + if (!ret0 || !ret1) { + return false; + } + + if (type == TYPE_RATIONAL) { + unsigned int num; + if (!read4(&num)) { + return false; + } + unsigned int denom; + if (!read4(&denom)) { + return false; + } + + (*ret0) = num; + (*ret1) = denom; + return true; + } + + return false; + } + + bool read_srational(int type, int32_t* ret0, int32_t *ret1) const { + // @todo { Support more types. } + + if (!ret0 || !ret1) { + return false; + } + + if (type == TYPE_SRATIONAL) { + int num; + if (!read4(&num)) { + return false; + } + int denom; + if (!read4(&denom)) { + return false; + } + + (*ret0) = num; + (*ret1) = denom; + return true; + } + + return false; + } + // // Returns a memory address. The begining of address is computed in // relative(based on current seek pos). This function is useful when you just @@ -4039,7 +4123,7 @@ static bool ParseTIFFIFD(const StreamReader& sr, return false; } - size_t readLen = len * sizeof(float); + //size_t readLen = len * sizeof(float); const size_t kMaxSamples = 1024 * 1024; @@ -4112,7 +4196,7 @@ static bool ParseTIFFIFD(const StreamReader& sr, } } - if (len != (image.samples_per_pixel * 2)) { + if (size_t(len) != (size_t(image.samples_per_pixel) * 2)) { if (err) { (*err) += "Counts in NoisProfile must be 2 * SamplesPerPixel.\n"; } @@ -4501,7 +4585,7 @@ static bool ParseTIFFIFD(const StreamReader& sr, unsigned int strip_offset; if (!sr.read4(&strip_offset)) { if (err) { - (*err) += "Failed to read StripOffset value."; + (*err) += "Failed to read StripOffset value.\n"; } return false; } @@ -5847,7 +5931,7 @@ bool LoadDNGFromMemory(const char* mem, unsigned int size, } return false; } - TINY_DNG_DPRINTF("image.data.size = %lld\n", len); + TINY_DNG_DPRINTF("image.data.size = %u\n", uint32_t(len)); image->data.resize(len); TINY_DNG_DPRINTF("image.data.size = %d\n", int(len)); diff --git a/src/image-loader.cc b/src/image-loader.cc index 81b1e62b..dc298094 100644 --- a/src/image-loader.cc +++ b/src/image-loader.cc @@ -47,6 +47,13 @@ #pragma clang diagnostic ignored "-Weverything" #endif +#if defined(__GNUC__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wunused-variable" +#pragma GCC diagnostic ignored "-Wunused-function" +#endif + + #if defined(TINYUSDZ_USE_WUFFS_IMAGE_LOADER) #include "external/wuffs-unsupported-snapshot.c" @@ -92,6 +99,10 @@ #pragma clang diagnostic pop #endif +#if defined(__GNUC__) +#pragma GCC diagnostic pop +#endif + #include "image-loader.hh" #include "io-util.hh" diff --git a/src/image-util.cc b/src/image-util.cc index 3fd336cb..72912155 100644 --- a/src/image-util.cc +++ b/src/image-util.cc @@ -12,6 +12,13 @@ #pragma clang diagnostic ignored "-Weverything" #endif +#if defined(__GNUC__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wunused-variable" +#pragma GCC diagnostic ignored "-Wunused-function" +#pragma GCC diagnostic ignored "-Warray-bounds" +#endif + #if !defined(TINYUSDZ_NO_STB_IMAGE_RESIZE_IMPLEMENTATION) #define STB_IMAGE_RESIZE_IMPLEMENTATION #endif @@ -23,6 +30,10 @@ #pragma clang diagnostic pop #endif +#ifdef __GNUC__ +#pragma GCC diagnostic pop +#endif + #include "image-util.hh" #include "value-types.hh" #include "common-macros.inc" diff --git a/src/linear-algebra.cc b/src/linear-algebra.cc index 67f661e7..e361d89b 100644 --- a/src/linear-algebra.cc +++ b/src/linear-algebra.cc @@ -46,13 +46,14 @@ value::quatf slerp(const value::quatf &a, const value::quatf &b, const float t) linalg::vec qb; linalg::vec qret; - memcpy(&qa, &a, sizeof(float) * 4); - memcpy(&qb, &b, sizeof(float) * 4); + memcpy(reinterpret_cast(&qa), &a, sizeof(float) * 4); + memcpy(reinterpret_cast(&qb), &b, sizeof(float) * 4); qret = linalg::slerp(qa, qb, t); - - return *(reinterpret_cast(&qret)); + value::quatf ret; + memcpy(&ret, reinterpret_cast(&qret), sizeof(float) * 4); + return ret; } value::quatd slerp(const value::quatd &a, const value::quatd &b, const double t) { @@ -61,13 +62,15 @@ value::quatd slerp(const value::quatd &a, const value::quatd &b, const double t) linalg::vec qb; linalg::vec qret; - memcpy(&qa, &a, sizeof(double) * 4); - memcpy(&qb, &b, sizeof(double) * 4); + memcpy(reinterpret_cast(&qa), &a, sizeof(double) * 4); + memcpy(reinterpret_cast(&qb), &b, sizeof(double) * 4); qret = linalg::slerp(qa, qb, t); - - return *(reinterpret_cast(&qret)); + value::quatd ret; + memcpy(&ret, reinterpret_cast(&qret), sizeof(double) * 4); + return ret; + } float vlength(const value::float3 &a) { diff --git a/src/stream-reader.hh b/src/stream-reader.hh index 578366f8..3a5ce470 100644 --- a/src/stream-reader.hh +++ b/src/stream-reader.hh @@ -293,7 +293,7 @@ class StreamReader { return false; } - float value; + float value{}; if (!read4(reinterpret_cast(&value))) { return false; } @@ -308,7 +308,7 @@ class StreamReader { return false; } - double value; + double value{}; if (!read8(reinterpret_cast(&value))) { return false; } diff --git a/src/tydra/render-data.hh b/src/tydra/render-data.hh index f1fddd02..7f582134 100644 --- a/src/tydra/render-data.hh +++ b/src/tydra/render-data.hh @@ -1060,10 +1060,18 @@ struct UDIMTexture { std::unordered_map imageTileIds; }; +// workaround for GCC +#if defined(__GNUC__) && !defined(__clang__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wmaybe-uninitialized" +#endif + // T or TextureId template -struct ShaderParam { - ShaderParam(const T &t) { value = t; } +class ShaderParam { + public: + ShaderParam() = default; + ShaderParam(const T &t) : value(t) { } bool is_texture() const { return texture_id >= 0; } @@ -1078,12 +1086,14 @@ struct ShaderParam { memcpy(&value, &val, sizeof(T)); } - T value; + //private: + T value{}; int32_t texture_id{-1}; // negative = invalid }; // UsdPreviewSurface -struct PreviewSurfaceShader { +class PreviewSurfaceShader { + public: bool useSpecularWorkflow{false}; ShaderParam diffuseColor{{0.18f, 0.18f, 0.18f}}; @@ -1103,6 +1113,10 @@ struct PreviewSurfaceShader { uint64_t handle{0}; // Handle ID for Graphics API. 0 = invalid }; +#if defined(__GNUC__) && !defined(__clang__) +#pragma GCC diagnostic pop +#endif + // Material + Shader struct RenderMaterial { std::string name; // elementName in USD (e.g. "pbrMat") diff --git a/src/usdMtlx.cc b/src/usdMtlx.cc index c2b45c30..4a2ae451 100644 --- a/src/usdMtlx.cc +++ b/src/usdMtlx.cc @@ -377,7 +377,7 @@ bool ParseMaterialXValue(const std::string &str, T *value, std::string *err) { str.size(), /* swap endian */ false); tinyusdz::ascii::AsciiParser parser(&sr); - T val; + T val{}; if (!ParseValue(parser, val, err)) { return false; @@ -522,14 +522,14 @@ static bool ConvertPlace2d(const pugi::xml_node &node, PrimSpec &ps, } if (pugi::xml_attribute pivot_attr = node.attribute("pivot")) { - value::float2 value; + value::float2 value{}; if (!ParseMaterialXValue(pivot_attr.as_string(), &value, err)) { ps.props()["inputs:pivot"] = Property(Attribute::Uniform(value)); } } if (pugi::xml_attribute scale_attr = node.attribute("scale")) { - value::float2 value; + value::float2 value{}; if (!ParseMaterialXValue(scale_attr.as_string(), &value, err)) { PUSH_ERROR_AND_RETURN( "Failed to parse `rotate` attribute of `place2d`.\n"); @@ -538,7 +538,7 @@ static bool ConvertPlace2d(const pugi::xml_node &node, PrimSpec &ps, } if (pugi::xml_attribute rotate_attr = node.attribute("rotate")) { - float value; + float value{}; if (!ParseMaterialXValue(rotate_attr.as_string(), &value, err)) { PUSH_ERROR_AND_RETURN( "Failed to parse `rotate` attribute of `place2d`.\n"); @@ -548,7 +548,7 @@ static bool ConvertPlace2d(const pugi::xml_node &node, PrimSpec &ps, pugi::xml_attribute offset_attr = node.attribute("offset"); if (offset_attr) { - value::float2 value; + value::float2 value{}; if (!ParseMaterialXValue(offset_attr.as_string(), &value, err)) { PUSH_ERROR_AND_RETURN( "Failed to parse `offset` attribute of `place2d`.\n"); @@ -923,6 +923,7 @@ bool WriteMaterialXToString(const MtlxModel &mtlx, std::string &xml_str, if (auto usdps = mtlx.shader.as()) { return detail::WriteMaterialXToString(*usdps, xml_str, warn, err); } else if (auto adskss = mtlx.shader.as()) { + (void)adskss; // TODO PUSH_ERROR_AND_RETURN("TODO: AutodeskStandardSurface"); } else { diff --git a/src/usdc-reader.cc b/src/usdc-reader.cc index edd9ad84..6ca5a416 100644 --- a/src/usdc-reader.cc +++ b/src/usdc-reader.cc @@ -751,7 +751,7 @@ USDCReader::Impl::DecodeListOp(const ListOp &arg) { } } - return std::move(dst); + return dst; } bool USDCReader::Impl::BuildPropertyMap(const std::vector &pathIndices, @@ -2039,6 +2039,7 @@ bool USDCReader::Impl::ParsePrimSpec(const crate::FieldValuePairVector &fvs, } } else if (fv.first == "inherits") { // `inherits` composition if (auto pvb = fv.second.as()) { + (void)pvb; // make empty array primMeta.inherits = std::make_pair(ListEditQual::ResetToExplicit, std::vector()); @@ -2067,6 +2068,7 @@ bool USDCReader::Impl::ParsePrimSpec(const crate::FieldValuePairVector &fvs, } else if (fv.first == "references") { // `references` composition if (auto pvb = fv.second.as()) { + (void)pvb; // make empty array primMeta.references = std::make_pair(ListEditQual::ResetToExplicit, std::vector()); @@ -2096,6 +2098,7 @@ bool USDCReader::Impl::ParsePrimSpec(const crate::FieldValuePairVector &fvs, } } else if (fv.first == "payload") { // `payload` composition if (auto pvb = fv.second.as()) { + (void)pvb; // make empty array primMeta.payload = std::make_pair(ListEditQual::ResetToExplicit, std::vector()); diff --git a/src/usdc-writer.cc b/src/usdc-writer.cc index 69ba5126..d9bc89aa 100644 --- a/src/usdc-writer.cc +++ b/src/usdc-writer.cc @@ -208,6 +208,7 @@ class Packer { // by Index()(= ~0) }; +#if 0 // not used atm. crate::TokenIndex Packer::AddToken(const Token &token) { if (token_to_index_map.count(token)) { return token_to_index_map[token]; @@ -271,6 +272,7 @@ crate::FieldSetIndex Packer::AddFieldSet( return fieldset_to_index_map[fieldset]; } +#endif class Writer { public: diff --git a/src/value-types.cc b/src/value-types.cc index 1febf030..df6a37cb 100644 --- a/src/value-types.cc +++ b/src/value-types.cc @@ -896,7 +896,7 @@ bool RoleTypeCast(const uint32_t roleTyId, value::Value &inout) { if (auto pv = inout.get_value<__srcBaseTy>()) { \ __srcBaseTy val = pv.value(); \ __roleTy newval; \ - memcpy(&newval, &val, sizeof(__srcBaseTy)); \ + memcpy(reinterpret_cast<__srcBaseTy *>(&newval), &val, sizeof(__srcBaseTy)); \ inout = newval; \ return true; \ } \ @@ -909,7 +909,7 @@ bool RoleTypeCast(const uint32_t roleTyId, value::Value &inout) { std::vector<__srcBaseTy> val = pv.value(); \ std::vector<__roleTy> newval; \ newval.resize(val.size()); \ - memcpy(newval.data(), val.data(), sizeof(__srcBaseTy) * val.size()); \ + memcpy(reinterpret_cast<__srcBaseTy *>(newval.data()), val.data(), sizeof(__srcBaseTy) * val.size()); \ inout = newval; \ return true; \ } \