Initial commit: Final state of the master project
This commit is contained in:
40
Research/scene/Material/BaseMaterial.h
Normal file
40
Research/scene/Material/BaseMaterial.h
Normal file
@@ -0,0 +1,40 @@
|
||||
#pragma once
|
||||
#include "../../inc/glm/common.hpp"
|
||||
#include <string>
|
||||
#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<BaseMaterial> {
|
||||
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<glm::u16vec3>()(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
|
||||
}
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user