Oxygine  1
2g game engine
UberShaderProgram.h
1 #pragma once
2 #include <vector>
3 #include "Restorable.h"
4 #include "Object.h"
5 
6 namespace oxygine
7 {
9  {
10  public:
11  struct shader
12  {
13  shader(): program(0), flags(0) {}
14  ShaderProgram* program;
15  int flags;
16  };
17 
20 
21  void init(const std::vector<unsigned char>& baseShader, const char* prepend = "", const char* append = "");
22 
23  void release();
24 
25  typedef Closure<void (IVideoDriver*, ShaderProgram*)> ShaderUniformsCallback;
26 
27  ShaderUniformsCallback getShaderUniformsCallback() const { return _cb; }
28  void setShaderUniformsCallback(ShaderUniformsCallback cb) {_cb = cb;}
29 
30 
31  virtual ShaderProgram* getShaderProgram(int flags) = 0;
32 
33 
34  protected:
35  void* _getRestorableObject() {return this;}
36  void _restore(Restorable*, void*);
37 
38  std::vector<unsigned char> _data;
39  ShaderUniformsCallback _cb;
40 
41  virtual void releaseShaders() {}
42  };
43 
45  {
46  public:
49 
50  enum
51  {
52  ALPHA_PREMULTIPLY = 1,
53  SEPARATE_ALPHA = 1 << 1,
54  MASK_R_CHANNEL = 1 << 2,
55  MASK = 1 << 3,
56  SDF = 1 << 4,
57  ADD_COLOR = 1 << 5,
58  SDF_OUTLINE = 1 << 1,//same as SEPARATE_ALPHA
59  _SIZE = 1 << 6
60  };
61 
62  enum
63  {
64  SAMPLER_BASE,
65  SAMPLER_ALPHA,
66  SAMPLER_MASK,
67  SAMPLER_NUM,
68  };
69 
70  ShaderProgram* getShaderProgram(int flags) override;
71 
72  void apply(IVideoDriver* driver, spNativeTexture base, spNativeTexture alpha);
73 
74  protected:
75  void releaseShaders() override;
76  shader _shaders[_SIZE];
77  };
78 }
Definition: ShaderProgram.h:7
Definition: UberShaderProgram.h:8
Definition: UberShaderProgram.h:44
–oxgl-end–!
Definition: Actor.h:14
Definition: UberShaderProgram.h:11
Definition: Restorable.h:8
Definition: VideoDriver.h:12