Oxygine  1
2g game engine
PostProcess.h
1 #pragma once
2 #include "oxygine-include.h"
3 #include "math/Rect.h"
4 #include "core/NativeTexture.h"
5 #include "core/Renderer.h"
6 #include "Material.h"
7 #include "Tween.h"
8 
9 namespace oxygine
10 {
12  {
13  public:
14  enum
15  {
16  flag_singleR2T = 1,
17  flag_fullscreen = 1 << 1,
18  flag_screen = 1 << 2,
19  };
20 
21  PostProcessOptions(int flags = 0) : _flags(flags), _downscale(1), _clearColor(0, 0, 0, 0) {}
22  PostProcessOptions& fullscreen(bool enable = true) { _flags = enable ? (_flags | flag_fullscreen) : (_flags & (~flag_fullscreen)); return *this; }
23  PostProcessOptions& singleRender(bool enable = true) { _flags = enable ? (_flags | flag_singleR2T) : (_flags & (~flag_singleR2T)); return *this; }
24  //loops -(2, 3, 4, ...), final size: 2^loops
25  PostProcessOptions& downscale(int loops = 2) { _downscale = loops; return *this; }
26  PostProcessOptions& clear(const Color& c) { _clearColor = c; return *this; }
27 
28  int _flags;
29  int _downscale;
30  Color _clearColor;
31  };
32 
33 
35  {
36  public:
37 
38  static ShaderProgram* shaderBlurV;
39  static ShaderProgram* shaderBlurH;
40  static ShaderProgram* shaderBlit;
41 
42  static void initShaders();
43  static void freeShaders();
44 
45  PostProcess(const PostProcessOptions& opt);
46  ~PostProcess();
47 
48  void free();
49 
50  void update(Actor* actor);
51  Rect getScreenRect(const Actor& actor) const;
52 
53  Point _extend;
54  spNativeTexture _rt;
55  TextureFormat _format;
56  Transform _transform;
57  Rect _screen;
58 
59  PostProcessOptions _options;
60  };
61 
62  class PPTask
63  {
64  public:
65  virtual ~PPTask() {}
66  virtual void addRefPP() = 0;
67  virtual void releaseRefPP() = 0;
68  virtual void renderPP() = 0;
69  };
70 
71  DECLARE_SMART(TweenPostProcess, spTweenPostProcess);
72 
73  class TweenPostProcess : public TweenObj, public Material, public PPTask
74  {
75  public:
78 
79  void renderPP() override;
80  void addRefPP() override;
81  void releaseRefPP() override;
82 
83  void init(Actor& actor) override;
84  void update(Actor& actor, float p, const UpdateState& us) override;
85  void done(Actor& actor) override;
86  protected:
87  virtual void _renderPP() {}
88 
89 
90  Actor* _actor;
91  PostProcess _pp;
92  float _progress;
93 
94  Material* _prevMaterial;
95  };
96 
97 
99  {
100  public:
102 
103  spNativeTexture get(spNativeTexture current, int w, int h, TextureFormat tf);
104  void update();
105  void reset();
106 
107  protected:
108  void print();
109  bool isGood(const spNativeTexture& t, int w, int h, TextureFormat tf) const;
110 
111  typedef std::vector<spNativeTexture> rts;
112  rts _rts;
113 
114  typedef std::vector<spNativeTexture> free;
115  free _free;
116  };
117 
118  void pass(spNativeTexture srcTexture, const Rect& srcRect, spNativeTexture destTexture, const Rect& destRect, const Color& color = Color::White);
119 
120  RenderTargetsManager& getRTManager();
121 
122  void updatePortProcessItems();
123  bool isRenderingPostProcessItems();
124  void addPostProcessItem(PPTask*);
125  void removePostProcessItem(PPTask*);
126  void clearPostProcessItems();
127 }
Definition: PostProcess.h:98
Definition: ShaderProgram.h:7
Definition: PostProcess.h:34
Definition: Material.h:6
Definition: Actor.h:42
Definition: PostProcess.h:73
Definition: UpdateState.h:6
Definition: PostProcess.h:62
–oxgl-end–!
Definition: Actor.h:14
Definition: Tween.h:252
Definition: PostProcess.h:11
Definition: Color.h:8