not a good idea yet

This commit is contained in:
Hartmut Seichter 2023-07-01 15:21:44 +02:00
parent 1a5287bbc2
commit 296d3add7b
4 changed files with 59 additions and 22 deletions

View file

@ -27,11 +27,18 @@
namespace paradiso {
/**
* @brief position with integral type
*/
struct Point final {
using value_type = int32_t;
value_type x{0}, y{0};
};
/**
* @brief size with integral type
*/
struct Size final {
using value_type = uint32_t;
value_type width{0}, height{0};
@ -42,11 +49,20 @@ struct Size final {
return {.width = std::min(width, height),
.height = std::min(width, height)};
}
constexpr Size maximal_extent() const noexcept {
return {.width = std::max(width, height),
.height = std::max(width, height)};
}
};
struct Rectangle {
Point position;
Size size;
/**
* @brief position and size with integral type
*/
struct Rectangle final {
Point position{.x = 0, .y = 0};
Size size{};
constexpr bool contains(const Point& p) const noexcept {
return p.x >= position.x && p.x <= position.x + size.width &&

View file

@ -24,6 +24,8 @@
#define PARADISO_SHADER_HPP
#include <paradiso/globals.hpp>
#include <paradiso/matrix.hpp>
#include <paradiso/vector.hpp>
#include <memory>
#include <unordered_map>
@ -60,6 +62,9 @@ struct Shader final {
set_uniform_at_location(int location,
int32_t v) const; //!< sets a 32bit signed in a shader
const Shader&
set_uniform_at_location(int location,
const Vector2<float>& v) const; //!< sets a 2D float vector
/**
* @brief retrieves the position of a uniform
* @param name of the uniform
@ -77,7 +82,7 @@ struct Shader final {
}
/**
* sets data of the
* sets data of the uniform inside a shader program
*/
template <typename T>
const Shader& set_uniform(std::string const& name, T&& value) const {
@ -87,7 +92,7 @@ struct Shader final {
using uniform_t =
std::variant<bool, int, float,
double /*,vector2f,vector3f,vector4f,matrix4x4f*/>;
double ,Vector2<float>/*vector3f,vector4f,matrix4x4f*/>;
using uniform_entry_t = std::tuple<std::string, uniform_t, int>;
using uniform_cache_t = std::vector<uniform_entry_t>;

View file

@ -172,16 +172,19 @@ struct Shader::impl {
// glUniformMatrix4fv(location,1,GL_FALSE,m.ptr());
// }
// void bind(int location,const vector4f& v)
// {
// glUniform4fv(location,1,v.ptr());
// }
void bind(int location, const Vector2<float>& v) const {
glUniform2fv(location, 1, v.ptr());
}
void bind(int location, const float& v) const { glUniform1f(location, v); }
void bind(int location, const uint32_t& i) const { glUniform1ui(location, i); }
void bind(int location, const uint32_t& i) const {
glUniform1ui(location, i);
}
void bind(int location, const int32_t& i) const { glUniform1i(location, i); }
void bind(int location, const int32_t& i) const {
glUniform1i(location, i);
}
// void bind(int location,const texture& v)
// {
@ -211,11 +214,11 @@ const Shader& Shader::set_uniform_at_location(int location, int32_t v) const {
return *this;
}
// Shader &Shader::set_uniform_at_location(int location, vector4f const &v)
// {
// impl_->bind(location, v);
// return *this;
// }
const Shader &Shader::set_uniform_at_location(int location, Vector2<float> const &v) const
{
impl_->bind(location, v);
return *this;
}
// Shader &Shader::set_uniform_at_location(int location, matrix4x4f const &v)
// {