]> git.tdb.fi Git - libs/demoscene.git/blob - source/filmgrain.h
Allow stages to define actions
[libs/demoscene.git] / source / filmgrain.h
1 #ifndef MSP_DEMOSCENE_FILMGRAIN_H_
2 #define MSP_DEMOSCENE_FILMGRAIN_H_
3
4 #include <msp/gl/mesh.h>
5 #include <msp/gl/postprocessor.h>
6 #include <msp/gl/program.h>
7 #include <msp/gl/programdata.h>
8 #include <msp/gl/texture2darray.h>
9 #include <msp/gl/texturing.h>
10
11 namespace Msp {
12 namespace DemoScene {
13
14 class FilmGrain: public GL::PostProcessor
15 {
16 public:
17         struct Template: public PostProcessor::Template
18         {
19                 class Loader: public DataFile::DerivedObjectLoader<Template, PostProcessor::Template::Loader>
20                 {
21                 public:
22                         Loader(Template &t);
23                 };
24
25                 unsigned size;
26                 unsigned layers;
27                 float coarseness;
28                 float strength;
29
30                 Template();
31
32                 virtual FilmGrain *create(unsigned, unsigned) const;
33         };
34
35 private:
36         const Msp::GL::Mesh &mesh;
37         const Msp::GL::Program &shprog;
38         Msp::GL::ProgramData shdata;
39         Msp::GL::Texturing texturing;
40         unsigned size;
41         unsigned layers;
42         Msp::GL::Texture2DArray grain;
43         unsigned current_layer;
44
45 public:
46         FilmGrain(unsigned = 256, unsigned = 16);
47
48 private:
49         void generate_grain();
50         void bicubic2x(const UInt8 *, UInt8 *, Int16 *);
51         static UInt8 clamp(int);
52
53 public:
54         void set_coarseness(float);
55         void set_strength(float);
56
57         virtual void render(GL::Renderer &, const GL::Texture2D &, const GL::Texture2D &);
58 };
59
60 } // namespace DemoScene
61 } // namespace Msp
62
63 #endif