Initial commit of ImageFilter shader presets

Clone source can choose a filter
This commit is contained in:
Bruno Herbelin
2022-05-01 22:24:59 +02:00
parent 77dc563219
commit 80469ead18
32 changed files with 1385 additions and 202 deletions

View File

@@ -2,9 +2,12 @@
#define IMAGEFILTER_H
#include <map>
#include <list>
#include <string>
#include <glm/glm.hpp>
#include <glib/gtimer.h>
#include "ImageShader.h"
class Surface;
class FrameBuffer;
@@ -13,36 +16,58 @@ class ImageFilteringShader;
class ImageFilter
{
std::string code_;
std::string name_;
// code resource file or GLSL (ShaderToy style)
std::pair< std::string, std::string > code_;
// list of parameters (uniforms names and values)
std::map< std::string, float > parameters_;
public:
ImageFilter();
ImageFilter(const std::string &name, const std::string &first_pass, const std::string &second_pass,
const std::map<std::string, float> &parameters);
ImageFilter(const ImageFilter &other);
ImageFilter& operator = (const ImageFilter& other);
bool operator !=(const ImageFilter& other) const;
ImageFilter& operator= (const ImageFilter& other);
bool operator!= (const ImageFilter& other) const;
// get the name of the filter
inline std::string name() const { return name_; }
// set the code of the filter
inline void setCode(const std::string &code) { code_ = code; }
inline void setCode(const std::pair< std::string, std::string > &code) { code_ = code; }
// get the code of the filter
inline std::string code() const { return code_; }
std::pair< std::string, std::string > code();
// global
// set the list of parameters of the filter
inline void setParameters(const std::map< std::string, float > &parameters) { parameters_ = parameters; }
// get the list of parameters of the filter
inline std::map< std::string, float > parameters() const { return parameters_; }
// set a value of a parameter
inline void setParameter(const std::string &p, float value) { parameters_[p] = value; }
// globals
static std::string getFilterCodeInputs();
static std::string getFilterCodeDefault();
static std::list< ImageFilter > presets;
};
class ImageFilteringShader;
class ImageFilterRenderer
{
Surface *surface_;
FrameBuffer *buffer_;
ImageFilteringShader *shader_;
ImageFilter filter_;
bool enabled_;
ImageFilter filter_;
std::pair< Surface *, Surface *> surfaces_;
std::pair< FrameBuffer *, FrameBuffer * > buffers_;
std::pair< ImageFilteringShader *, ImageFilteringShader *> shaders_;
public:
@@ -62,11 +87,11 @@ public:
// get the texture id of the rendered framebuffer
uint getOutputTexture() const;
// set the code of the filter
// set the filter
void setFilter(const ImageFilter &f, std::promise<std::string> *ret = nullptr);
// get the code of the filter
inline ImageFilter filter() const { return filter_; }
// get copy of the filter
ImageFilter filter() const;
};