Commit 82899572 authored by Philip Trettner's avatar Philip Trettner

setUniform with initializer_list, small fixes

parent 42e0e9af
......@@ -57,7 +57,7 @@ struct array_view
{
}
constexpr array_view(std::initializer_list<T> l) : _data(l.begin()), _size(l.size())
constexpr array_view(std::initializer_list<std::remove_const_t<T>> l) : _data(l.begin()), _size(l.size())
{
static_assert(std::is_const_v<T>, "the initializer_list ctor only works for const types");
}
......
......@@ -10,10 +10,6 @@ namespace glow
namespace util
{
/// Returns true iff str endswith suffix
inline bool endswith(const std::string& str, const std::string& suffix)
{
return str.size() >= suffix.size() && str.compare(str.size() - suffix.size(), suffix.size(), suffix) == 0;
}
inline bool endswith(std::string_view str, std::string_view suffix)
{
return str.size() >= suffix.size() && str.compare(str.size() - suffix.size(), suffix.size(), suffix) == 0;
......
......@@ -56,10 +56,10 @@ public: // static construction
static SharedElementArrayBuffer create(int indexCount, const uint16_t* data);
static SharedElementArrayBuffer create(int indexCount, const int32_t* data);
static SharedElementArrayBuffer create(int indexCount, const uint32_t* data);
[[deprecated("slower on modern hardware")]] static SharedElementArrayBuffer create(std::vector<int8_t> const& indices);
[[deprecated("slower on modern hardware")]] static SharedElementArrayBuffer create(std::vector<uint8_t> const& indices);
[[deprecated("slower on modern hardware")]] static SharedElementArrayBuffer create(int indexCount, const int8_t* data);
[[deprecated("slower on modern hardware")]] static SharedElementArrayBuffer create(int indexCount, const uint8_t* data);
[[deprecated("8bit indices are slow on modern hardware")]] static SharedElementArrayBuffer create(std::vector<int8_t> const& indices);
[[deprecated("8bit indices are slow on modern hardware")]] static SharedElementArrayBuffer create(std::vector<uint8_t> const& indices);
[[deprecated("8bit indices are slow on modern hardware")]] static SharedElementArrayBuffer create(int indexCount, const int8_t* data);
[[deprecated("8bit indices are slow on modern hardware")]] static SharedElementArrayBuffer create(int indexCount, const uint8_t* data);
template <typename T, std::size_t N>
static SharedElementArrayBuffer create(const T (&data)[N])
{
......
......@@ -82,6 +82,11 @@ public: // gl functions with use
else
static_assert(tg::always_false<T>, "don't know how to convert type to uniform (or uniform array)");
}
template <class T>
void setUniform(std::string_view name, std::initializer_list<T> value)
{
uniform<T[]>(name) = value;
}
// returns an untyped object that can be used to assign textures and uniforms
// Example:
......@@ -143,6 +148,11 @@ void uniform_proxy::operator=(T const& v) &&
{
prog.setUniform(name, v);
}
template <class T>
void uniform_proxy::operator=(std::initializer_list<T> v) &&
{
prog.setUniform(name, v);
}
template <class TextureT>
void uniform_proxy::operator=(std::shared_ptr<TextureT> const& tex) &&
{
......
#pragma once
#include <initializer_list>
#include <string_view>
#include <glow/common/array_view.hh>
......@@ -49,6 +50,8 @@ struct uniform_proxy
template <class T>
void operator=(T const& v) &&;
template <class T>
void operator=(std::initializer_list<T> v) &&;
template <class TextureT>
void operator=(std::shared_ptr<TextureT> const& tex) &&;
template <class T>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment