diff --git a/libs/yocto/yocto_bvh.cpp b/libs/yocto/yocto_bvh.cpp index c8fe3cefa..45ad4a763 100644 --- a/libs/yocto/yocto_bvh.cpp +++ b/libs/yocto/yocto_bvh.cpp @@ -8,6 +8,7 @@ #include "yocto_bvh.h" +#include #include #include #include diff --git a/libs/yocto/yocto_math.h b/libs/yocto/yocto_math.h index fdc43b34a..6f546f2a6 100644 --- a/libs/yocto/yocto_math.h +++ b/libs/yocto/yocto_math.h @@ -39,7 +39,6 @@ #include #include -#include #include #include @@ -654,21 +653,6 @@ inline void swap(vec4i& a, vec4i& b); } // namespace yocto -// ----------------------------------------------------------------------------- -// VECTOR HASHING -// ----------------------------------------------------------------------------- -namespace std { - -// Hash functor for vector for use with hash_map -template <> -struct hash; -template <> -struct hash; -template <> -struct hash; - -} // namespace std - // ----------------------------------------------------------------------------- // MATRICES // ----------------------------------------------------------------------------- @@ -1942,48 +1926,6 @@ inline void swap(vec4i& a, vec4i& b) { std::swap(a, b); } } // namespace yocto -// ----------------------------------------------------------------------------- -// IMPLEMENRTATION OF VECTOR HASHING -// ----------------------------------------------------------------------------- -namespace std { - -// Hash functor for vector for use with hash_map -template <> -struct hash { - size_t operator()(const yocto::vec2i& v) const { - static const auto hasher = std::hash(); - auto h = (size_t)0; - h ^= hasher(v.x) + 0x9e3779b9 + (h << 6) + (h >> 2); - h ^= hasher(v.y) + 0x9e3779b9 + (h << 6) + (h >> 2); - return h; - } -}; -template <> -struct hash { - size_t operator()(const yocto::vec3i& v) const { - static const auto hasher = std::hash(); - auto h = (size_t)0; - h ^= hasher(v.x) + 0x9e3779b9 + (h << 6) + (h >> 2); - h ^= hasher(v.y) + 0x9e3779b9 + (h << 6) + (h >> 2); - h ^= hasher(v.z) + 0x9e3779b9 + (h << 6) + (h >> 2); - return h; - } -}; -template <> -struct hash { - size_t operator()(const yocto::vec4i& v) const { - static const auto hasher = std::hash(); - auto h = (size_t)0; - h ^= hasher(v.x) + 0x9e3779b9 + (h << 6) + (h >> 2); - h ^= hasher(v.y) + 0x9e3779b9 + (h << 6) + (h >> 2); - h ^= hasher(v.z) + 0x9e3779b9 + (h << 6) + (h >> 2); - h ^= hasher(v.w) + 0x9e3779b9 + (h << 6) + (h >> 2); - return h; - } -}; - -} // namespace std - // ----------------------------------------------------------------------------- // MATRICES // ----------------------------------------------------------------------------- diff --git a/libs/yocto/yocto_mesh.cpp b/libs/yocto/yocto_mesh.cpp index 128ac2efe..59070856e 100644 --- a/libs/yocto/yocto_mesh.cpp +++ b/libs/yocto/yocto_mesh.cpp @@ -38,6 +38,25 @@ using namespace std::string_literals; } // namespace yocto +// ----------------------------------------------------------------------------- +// VECTOR HASHING +// ----------------------------------------------------------------------------- +namespace std { + +// Hash functor for vector for use with hash_map +template <> +struct hash { + size_t operator()(const yocto::vec2i& v) const { + static const auto hasher = std::hash(); + auto h = (size_t)0; + h ^= hasher(v.x) + 0x9e3779b9 + (h << 6) + (h >> 2); + h ^= hasher(v.y) + 0x9e3779b9 + (h << 6) + (h >> 2); + return h; + } +}; + +} // namespace std + // ----------------------------------------------------------------------------- // UTILITIES // ----------------------------------------------------------------------------- diff --git a/libs/yocto/yocto_modelio.h b/libs/yocto/yocto_modelio.h index a3463267b..31871b6f9 100644 --- a/libs/yocto/yocto_modelio.h +++ b/libs/yocto/yocto_modelio.h @@ -41,7 +41,6 @@ #include #include #include -#include #include #include "yocto_math.h" @@ -54,7 +53,6 @@ namespace yocto { // using directives using std::array; using std::string; -using std::unordered_map; using std::vector; } // namespace yocto @@ -223,9 +221,6 @@ struct obj_texture { bool clamp = false; // clamp to edge float scale = 1; // scale for bump/displacement - // Properties not explicitly handled. - unordered_map> props; - obj_texture() {} explicit obj_texture(const char* path) : path{path} {} explicit obj_texture(const string& path) : path{path} {} diff --git a/libs/yocto/yocto_shading.h b/libs/yocto/yocto_shading.h index 0d9382014..511e80e47 100644 --- a/libs/yocto/yocto_shading.h +++ b/libs/yocto/yocto_shading.h @@ -37,8 +37,8 @@ // ----------------------------------------------------------------------------- #include -#include #include +#include #include "yocto_math.h" #include "yocto_sampling.h" @@ -51,7 +51,7 @@ namespace yocto { // using directives using std::pair; using std::string; -using std::unordered_map; +using std::vector; } // namespace yocto @@ -855,7 +855,7 @@ inline float sample_phasefunction_pdf( // Conductor etas inline pair conductor_eta(const string& name) { - static const unordered_map> metal_ior_table = { + static const vector>> metal_ior_table = { {"a-C", {{2.9440999183f, 2.2271502925f, 1.9681668794f}, {0.8874329109f, 0.7993216383f, 0.8152862927f}}}, {"Ag", {{0.1552646489f, 0.1167232965f, 0.1383806959f}, @@ -937,7 +937,10 @@ inline pair conductor_eta(const string& name) { {"W", {{4.3707029924f, 3.3002972445f, 2.9982666528f}, {3.5006778591f, 2.6048652781f, 2.2731930614f}}}, }; - return metal_ior_table.at(name); + for (auto& [ename, etas] : metal_ior_table) { + if (ename == name) return etas; + } + return {zero3f, zero3f}; } } // namespace yocto diff --git a/libs/yocto/yocto_shape.h b/libs/yocto/yocto_shape.h index 72c46b0f3..ca237a053 100644 --- a/libs/yocto/yocto_shape.h +++ b/libs/yocto/yocto_shape.h @@ -130,6 +130,48 @@ vector align_vertices( } // namespace yocto +// ----------------------------------------------------------------------------- +// VECTOR HASHING +// ----------------------------------------------------------------------------- +namespace std { + +// Hash functor for vector for use with hash_map +template <> +struct hash { + size_t operator()(const yocto::vec2i& v) const { + static const auto hasher = std::hash(); + auto h = (size_t)0; + h ^= hasher(v.x) + 0x9e3779b9 + (h << 6) + (h >> 2); + h ^= hasher(v.y) + 0x9e3779b9 + (h << 6) + (h >> 2); + return h; + } +}; +template <> +struct hash { + size_t operator()(const yocto::vec3i& v) const { + static const auto hasher = std::hash(); + auto h = (size_t)0; + h ^= hasher(v.x) + 0x9e3779b9 + (h << 6) + (h >> 2); + h ^= hasher(v.y) + 0x9e3779b9 + (h << 6) + (h >> 2); + h ^= hasher(v.z) + 0x9e3779b9 + (h << 6) + (h >> 2); + return h; + } +}; +template <> +struct hash { + size_t operator()(const yocto::vec4i& v) const { + static const auto hasher = std::hash(); + auto h = (size_t)0; + h ^= hasher(v.x) + 0x9e3779b9 + (h << 6) + (h >> 2); + h ^= hasher(v.y) + 0x9e3779b9 + (h << 6) + (h >> 2); + h ^= hasher(v.z) + 0x9e3779b9 + (h << 6) + (h >> 2); + h ^= hasher(v.w) + 0x9e3779b9 + (h << 6) + (h >> 2); + return h; + } +}; + +} // namespace std + // ----------------------------------------------------------------------------- // EDGES AND ADJACENCIES // ----------------------------------------------------------------------------- diff --git a/libs/yocto_gui/yocto_draw.cpp b/libs/yocto_gui/yocto_draw.cpp index 86af2bd1f..6748a23e0 100644 --- a/libs/yocto_gui/yocto_draw.cpp +++ b/libs/yocto_gui/yocto_draw.cpp @@ -31,9 +31,6 @@ #include -#include -#include - #include "ext/glad/glad.h" #ifdef _WIN32 @@ -47,8 +44,6 @@ namespace yocto { // using directives -using std::unordered_map; -using std::unordered_set; using namespace std::string_literals; } // namespace yocto diff --git a/libs/yocto_gui/yocto_imgui.cpp b/libs/yocto_gui/yocto_imgui.cpp index c48d4b1b2..e03885f8d 100644 --- a/libs/yocto_gui/yocto_imgui.cpp +++ b/libs/yocto_gui/yocto_imgui.cpp @@ -38,7 +38,6 @@ #include #include #include -#include #include #include "ext/glad/glad.h" @@ -66,7 +65,6 @@ namespace yocto { // using directives using std::mutex; using std::unordered_map; -using std::unordered_set; using namespace std::string_literals; } // namespace yocto diff --git a/libs/yocto_gui/yocto_opengl.cpp b/libs/yocto_gui/yocto_opengl.cpp index c7e7e01f3..6796ad5fe 100644 --- a/libs/yocto_gui/yocto_opengl.cpp +++ b/libs/yocto_gui/yocto_opengl.cpp @@ -37,7 +37,6 @@ #include #include #include -#include #include #include @@ -54,12 +53,30 @@ namespace yocto { // using directives -using std::unordered_map; using std::unordered_set; using namespace std::string_literals; } // namespace yocto +// ----------------------------------------------------------------------------- +// VECTOR HASHING +// ----------------------------------------------------------------------------- +namespace std { + +// Hash functor for vector for use with hash_map +template <> +struct hash { + size_t operator()(const yocto::vec2i& v) const { + static const auto hasher = std::hash(); + auto h = (size_t)0; + h ^= hasher(v.x) + 0x9e3779b9 + (h << 6) + (h >> 2); + h ^= hasher(v.y) + 0x9e3779b9 + (h << 6) + (h >> 2); + return h; + } +}; + +} // namespace std + // ----------------------------------------------------------------------------- // LOW-LEVEL OPENGL HELPERS // ----------------------------------------------------------------------------- @@ -141,24 +158,10 @@ void set_ogl_point_size(int size) { glPointSize(size); } void set_texture(ogl_texture* texture, const vec2i& size, int nchannels, const byte* img, bool as_srgb, bool linear, bool mipmap) { - static auto sformat = unordered_map{ - {1, GL_SRGB}, - {2, GL_SRGB}, - {3, GL_SRGB}, - {4, GL_SRGB_ALPHA}, - }; - static auto iformat = unordered_map{ - {1, GL_RGB}, - {2, GL_RGB}, - {3, GL_RGB}, - {4, GL_RGBA}, - }; - static auto cformat = unordered_map{ - {1, GL_RED}, - {2, GL_RG}, - {3, GL_RGB}, - {4, GL_RGBA}, - }; + static auto sformat = vector{ + 0, GL_SRGB, GL_SRGB, GL_SRGB, GL_SRGB_ALPHA}; + static auto iformat = vector{0, GL_RGB, GL_RGB, GL_RGB, GL_RGBA}; + static auto cformat = vector{0, GL_RED, GL_RG, GL_RGB, GL_RGBA}; assert_ogl_error(); if (size == zero2i) { clear_texture(texture); @@ -195,24 +198,10 @@ void set_texture(ogl_texture* texture, const vec2i& size, int nchannels, void set_texture(ogl_texture* texture, const vec2i& size, int nchannels, const float* img, bool as_float, bool linear, bool mipmap) { - static auto fformat = unordered_map{ - {1, GL_RGB16F}, - {2, GL_RGB16F}, - {3, GL_RGB16F}, - {4, GL_RGBA32F}, - }; - static auto iformat = unordered_map{ - {1, GL_RGB}, - {2, GL_RGB}, - {3, GL_RGB}, - {4, GL_RGBA}, - }; - static auto cformat = unordered_map{ - {1, GL_RED}, - {2, GL_RG}, - {3, GL_RGB}, - {4, GL_RGBA}, - }; + static auto fformat = vector{ + 0, GL_RGB16F, GL_RGB16F, GL_RGB16F, GL_RGBA32F}; + static auto iformat = vector{0, GL_RGB, GL_RGB, GL_RGB, GL_RGBA}; + static auto cformat = vector{0, GL_RED, GL_RG, GL_RGB, GL_RGBA}; assert_ogl_error(); if (size == zero2i) { clear_texture(texture); @@ -298,24 +287,10 @@ void set_texture(ogl_texture* texture, const image& img, bool as_float, void set_cubemap(ogl_cubemap* cubemap, int size, int nchannels, const array& images, bool as_srgb, bool linear, bool mipmap) { - static auto sformat = unordered_map{ - {1, GL_SRGB}, - {2, GL_SRGB}, - {3, GL_SRGB}, - {4, GL_SRGB_ALPHA}, - }; - static auto iformat = unordered_map{ - {1, GL_RGB}, - {2, GL_RGB}, - {3, GL_RGB}, - {4, GL_RGBA}, - }; - static auto cformat = unordered_map{ - {1, GL_RED}, - {2, GL_RG}, - {3, GL_RGB}, - {4, GL_RGBA}, - }; + static auto sformat = vector{ + 0, GL_SRGB, GL_SRGB, GL_SRGB, GL_SRGB_ALPHA}; + static auto iformat = vector{0, GL_RGB, GL_RGB, GL_RGB, GL_RGBA}; + static auto cformat = vector{0, GL_RED, GL_RG, GL_RGB, GL_RGBA}; assert_ogl_error(); if (size == 0) { clear_cubemap(cubemap); @@ -369,24 +344,10 @@ void set_cubemap(ogl_cubemap* cubemap, int size, int nchannels, void set_cubemap(ogl_cubemap* cubemap, int size, int nchannels, const array& images, bool as_float, bool linear, bool mipmap) { - static auto fformat = unordered_map{ - {1, GL_RGB16F}, - {2, GL_RGB16F}, - {3, GL_RGB16F}, - {4, GL_RGBA32F}, - }; - static auto iformat = unordered_map{ - {1, GL_RGB}, - {2, GL_RGB}, - {3, GL_RGB}, - {4, GL_RGBA}, - }; - static auto cformat = unordered_map{ - {1, GL_RED}, - {2, GL_RG}, - {3, GL_RGB}, - {4, GL_RGBA}, - }; + static auto fformat = vector{ + 0, GL_RGB16F, GL_RGB16F, GL_RGB16F, GL_RGBA32F}; + static auto iformat = vector{0, GL_RGB, GL_RGB, GL_RGB, GL_RGBA}; + static auto cformat = vector{0, GL_RED, GL_RG, GL_RGB, GL_RGBA}; assert_ogl_error(); if (size == 0) { clear_cubemap(cubemap); @@ -1009,14 +970,20 @@ void set_attribute(ogl_program* program, int location, const vec4f& value) { // draw elements void draw_elements(ogl_elementbuffer* buffer) { - static auto elements = unordered_map{ - {ogl_element_type::points, GL_POINTS}, - {ogl_element_type::lines, GL_LINES}, - {ogl_element_type::triangles, GL_TRIANGLES}, - }; glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffer->buffer_id); - glDrawElements(elements.at(buffer->element), (GLsizei)buffer->size, - GL_UNSIGNED_INT, nullptr); + switch (buffer->element) { + case ogl_element_type::points: + glDrawElements( + GL_POINTS, (GLsizei)buffer->size, GL_UNSIGNED_INT, nullptr); + break; + case ogl_element_type::lines: + glDrawElements(GL_LINES, (GLsizei)buffer->size, GL_UNSIGNED_INT, nullptr); + break; + case ogl_element_type::triangles: + glDrawElements( + GL_TRIANGLES, (GLsizei)buffer->size, GL_UNSIGNED_INT, nullptr); + break; + } assert_ogl_error(); }