]> git.tdb.fi Git - libs/gl.git/blob - demos/forestpond/source/water.h
88bf93590da6579189075553be1ff41bd384c6cb
[libs/gl.git] / demos / forestpond / source / water.h
1 #ifndef WATER_H_
2 #define WATER_H_
3
4 #include <random>
5 #include <msp/gl/objectinstance.h>
6 #include <msp/gl/texture2d.h>
7
8 class Water: public Msp::GL::ObjectInstance
9 {
10 public:
11         struct Region
12         {
13                 const Msp::GL::Mesh &terrain;
14                 float left;
15                 float bottom;
16                 float right;
17                 float top;
18         };
19
20 private:
21         struct State
22         {
23                 Msp::GL::Texture2D surface;
24                 Msp::GL::Texture2D velocity;
25                 Msp::GL::Texture2D clamping;
26         };
27
28         unsigned width;
29         unsigned height;
30         State state[2];
31         State *current;
32         State *next;
33         float time = 0.0f;
34         float stepsize = 0.001f;
35         std::minstd_rand rng;
36         Msp::GL::Texture2D bottom;
37         Msp::GL::Texture2D normals;
38         Msp::GL::Texture2D variance_x;
39         Msp::GL::Texture2D variance_y;
40         const Msp::GL::Sampler &sampler;
41         const Msp::GL::Program &sim_integrate;
42         const Msp::GL::Program &sim_velocity;
43         const Msp::GL::Program &sim_clamp;
44         const Msp::GL::Program &normals_shader;
45         const Msp::GL::Program &variance_x_shader;
46         const Msp::GL::Program &variance_y_shader;
47         Msp::GL::ProgramData sim_shdata;
48         Msp::GL::ProgramData shdata;
49         bool simulated = false;
50
51 public:
52         Water(const Msp::GL::Object &, Msp::DataFile::Collection &, const Region &);
53
54 public:
55         void setup_frame(Msp::GL::Renderer &) override;
56         void finish_frame() override;
57
58         void setup_render(Msp::GL::Renderer &, Msp::GL::Tag) const override;
59 };
60
61 #endif