20 #ifndef ANTKEEPER_RENDER_MATERIAL_PROPERTY_HPP
21 #define ANTKEEPER_RENDER_MATERIAL_PROPERTY_HPP
69 virtual bool upload(
double a)
const = 0;
94 return (
input !=
nullptr);
182 std::size_t element_count;
186 template <
typename T>
195 return math::lerp<float, float>(x, y,
static_cast<float>(
a));
201 return math::lerp<float2, float>(x, y,
static_cast<float>(
a));
207 return math::lerp<float3, float>(x, y,
static_cast<float>(
a));
213 return math::lerp<float4, float>(x, y,
static_cast<float>(
a));
218 element_count(element_count),
221 values =
new tween<T>[element_count];
234 for (std::size_t i = 0; i < element_count; ++i)
248 if (element_count > 1)
250 for (std::size_t i = 0; i < element_count; ++i)
252 if (!
input->upload(i, values[i].interpolate(
static_cast<float>(a))))
260 return input->upload(values[0].interpolate(
static_cast<float>(a)));
267 values[0][1] = value;
273 values[
index][1] = value;
279 for (std::size_t i = 0; i <
count; ++i)
281 this->values[
index + i][1] = values[i];
288 for (std::size_t i = 0; i < element_count; ++i)
290 this->values[i].set_interpolator(interpolator);
303 return values[
index][1];
448 for (std::size_t i = 0; i < element_count; ++i)
450 property->values[i][0] = values[i][0];
451 property->values[i][1] = values[i][1];
453 property->input =
input;
Abstract base class for material properties.
bool connect(const gl::shader_input *input)
Connects the material property to a shader input.
const gl::shader_input * input
void disconnect()
Disconnects the material property from its shader input.
bool is_connected() const
Returns true if the material property is connected to a shader input, false otherwise.
virtual material_property_base * clone() const =0
Creates a copy of this material property.
virtual void update_tweens()=0
Sets state 0 = state 1.
virtual gl::shader_variable_type get_data_type() const =0
Returns the type of data which the property contains.
virtual bool upload(double a) const =0
Uploads the material property to its shader program.
A property of a material which can be uploaded to a shader program via a shader input.
material_property(std::size_t element_count)
Creates a material property.
virtual gl::shader_variable_type get_data_type() const
Returns the type of data which the property contains.
material_property< T > & operator=(const material_property< T > &)=delete
void set_tween_interpolator(interpolator_type interpolator)
Sets the tween interpolator function.
const T & get_value(std::size_t index) const
Returns the value of the first element in this property.
void set_values(std::size_t index, const T *values, std::size_t count)
Sets the values of a range of elements in this array property.
static T default_interpolator(const T &x, const T &y, double a)
Default tween interpolator function for this material property type.
void set_value(const T &value)
Sets the value of this property.
void set_value(std::size_t index, const T &value)
Sets the value of a single element in this array property.
tween< T >::interpolator_type interpolator_type
virtual material_property_base * clone() const
Creates a copy of this material property.
virtual bool upload(double a) const
const T & get_value() const
Returns the value of the first element in this property.
virtual void update_tweens()
Sets state 0 = state 1.
material_property(const material_property< T > &)=delete
virtual ~material_property()
Destroys a material property.
Container which stores two states along with an interpolator, for quick and easy tween<T,...
std::decay< std::function< value_type(const value_type &, const value_type &, scalar_type)> >::type interpolator_type
constexpr int count(T x) noexcept
Returns the number of set bits in a value, known as a population count or Hamming weight.
constexpr math::vector2< T > a
void clone(entity::registry ®istry, entity::id source, entity::id destination)
Clones all the components of an entity.
@ index
General purpose index (uint)