#pragma once #include "../../inc/glm/common.hpp" #include #include "../../core/Hashers.h" class BaseMaterial { public: // Should return a 10-bit per channel precision vec3 virtual glm::u16vec3 GetProperties() const = 0; // Should update the materials in such a way that GetProperties should return the given properties virtual void SetProperties(glm::u16vec3 properties) = 0; virtual std::string GetTypeSuffix() const = 0; inline bool operator==(const BaseMaterial &other) const { auto otherV = other.GetProperties(); auto thisV = GetProperties(); return otherV == thisV; } }; namespace std { template<> struct hash { size_t operator()(BaseMaterial const &value) const { glm::u16vec3 properties = value.GetProperties(); // Since materials are only allowed to store 10 bits per channel, we should be able to hash them // perfectly in 32 bits. #ifdef ENVIRONMENT64 return std::hash()(properties); #else unsigned short mask = 0x3F; return (((size_t) (properties.x & mask)) << 20) | (((size_t) (properties.y & mask)) << 10) | (size_t) (properties.z & mask); #endif } }; }