92 lines
2.3 KiB
C++
92 lines
2.3 KiB
C++
#pragma once
|
|
|
|
#include <limits>
|
|
#include <utility>
|
|
|
|
#include "../shading/model_geometry.hpp"
|
|
#include "../shading/shader_stage.hpp"
|
|
#include "../shading/features/mesh_features.hpp"
|
|
#include "../shading/features/point_cloud_features.hpp"
|
|
#include "../shading/features/generic_features.hpp"
|
|
#include <algorithm>
|
|
|
|
// TODO move implementation to .ipp file
|
|
namespace zgl
|
|
{
|
|
|
|
template<typename T>
|
|
struct shader_features_set
|
|
{
|
|
T features, static_enable, dynamic_enable;
|
|
|
|
template<typename U>
|
|
[[nodiscard]] shader_features_set<U> cast() const noexcept
|
|
{
|
|
return {
|
|
.features = static_cast<U>(features),
|
|
.static_enable = static_cast<U>(static_enable),
|
|
.dynamic_enable = static_cast<U>(dynamic_enable)
|
|
};
|
|
}
|
|
|
|
// TODO this may not compile
|
|
[[nodiscard]] bool operator==(const shader_features_set& other) const noexcept = default;
|
|
};
|
|
|
|
|
|
struct shader_source_metadata
|
|
{
|
|
union combined_feature_set_type {
|
|
shader_features_set<shading::features::mesh::flags> mesh;
|
|
shader_features_set<shading::features::point_cloud::flags> point_cloud;
|
|
};
|
|
|
|
using generic_feature_set_type = shader_features_set<shading::features::generic::type>;
|
|
|
|
shading::model_geometry::types geometry;
|
|
combined_feature_set_type feature_set;
|
|
shading::stage::types stage;
|
|
|
|
[[nodiscard]] generic_feature_set_type generic_feature_set() const noexcept
|
|
{
|
|
switch (geometry)
|
|
{
|
|
case shading::model_geometry::types::mesh:
|
|
return feature_set.mesh.cast<shading::features::generic::type>();
|
|
case shading::model_geometry::types::point_cloud:
|
|
return feature_set.point_cloud.cast<shading::features::generic::type>();
|
|
default:
|
|
std::unreachable();
|
|
}
|
|
}
|
|
|
|
void from_generic_feature_set(const generic_feature_set_type& generic_feature_set) noexcept
|
|
{
|
|
switch (geometry)
|
|
{
|
|
case shading::model_geometry::types::mesh:
|
|
feature_set.mesh = generic_feature_set.cast<shading::features::mesh::flags>();
|
|
case shading::model_geometry::types::point_cloud:
|
|
feature_set.point_cloud = generic_feature_set.cast<shading::features::point_cloud::flags>();
|
|
}
|
|
std::unreachable();
|
|
}
|
|
|
|
bool operator==(const shader_source_metadata& other) const noexcept
|
|
{
|
|
if (this->stage != other.stage)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
if (this->geometry != other.geometry)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
return this->generic_feature_set() == other.generic_feature_set();
|
|
}
|
|
};
|
|
|
|
}
|