UGDK  0.5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
manager.h
Go to the documentation of this file.
1 #ifndef UGDK_GRAPHIC_MANAGER_H_
2 #define UGDK_GRAPHIC_MANAGER_H_
3 
4 #include <ugdk/structure/types.h>
5 #include <ugdk/math/vector2D.h>
6 
7 #include <ugdk/action.h>
8 #include <ugdk/graphic.h>
9 #include <ugdk/desktop.h>
10 #include <ugdk/util.h>
11 
13 
14 #include <string>
15 #include <bitset>
16 #include <functional>
17 #include <memory>
18 
19 struct SDL_Window;
20 typedef void* SDL_GLContext;
21 
22 #ifdef SWIG
23 // Nested class not supported
24 #pragma SWIG nowarn=325
25 #endif
26 
27 namespace ugdk {
28 namespace graphic {
29 
30 class RenderScreen;
31 action::Scene* CreateLightrenderingScene(std::function<void (Canvas&)> render_light_function);
32 
33 enum class VertexType {
35 };
36 
37 class Manager {
38  public:
39  Manager();
40  ~Manager();
41 
42  bool Initialize(const std::weak_ptr<desktop::Window>&, const math::Vector2D& canvas_size);
43  void Release();
44 
45  void AttachTo(const std::shared_ptr<desktop::Window>&);
46  void ResizeScreen(const math::Vector2D& canvas_size);
47 
48 #ifndef SWIG
49  TextureUnit ReserveTextureUnit(const graphic::GLTexture* texture = nullptr);
50 #endif
52  unsigned int LocationForVertexType(VertexType);
53 
54  class Shaders {
55  public:
56  enum Flag {
59 
60  NUM_FLAGS // Value generated by the compiler
61  };
62 
63  const ShaderProgram* current_shader() const;
64 
65  const ShaderProgram* GetSpecificShader(const std::bitset<NUM_FLAGS>& flags) const;
66 
67  bool IsFlagSet(Flag) const;
68  void ChangeFlag(Flag, bool);
69 
71 
74  void ReplaceShader(const std::bitset<NUM_FLAGS>& flags, ShaderProgram* program);
75 
76  void ReplaceShader(unsigned long flags, ShaderProgram* program) {
77  ReplaceShader(std::bitset<NUM_FLAGS>(flags), program);
78  }
79 
80  void ReplaceShader(const std::string& flags, ShaderProgram* program) {
81  ReplaceShader(std::bitset<NUM_FLAGS>(flags), program);
82  }
83 
84  private:
85  Shaders();
86  ~Shaders();
87 
88  ShaderProgram* shaders_[1 << NUM_FLAGS];
89  std::bitset<NUM_FLAGS> flags_;
90 
91  friend class Manager;
92  };
93 
94  RenderTarget* screen() const;
95  RenderTexture* light_buffer() const { return light_buffer_.get(); }
96 
97  graphic::GLTexture* white_texture() { return white_texture_; }
98  Shaders& shaders() { return shaders_; }
99  const Shaders& shaders() const { return shaders_; }
100  ShaderProgram* light_shader() { return light_shader_; }
101 
102  private:
103  void CreateLightBuffer(const math::Vector2D& size);
104  void ReleaseTextureUnitID(int id);
105 
106  SDL_GLContext context_;
107  std::unique_ptr<RenderScreen> screen_;
108  std::unique_ptr<RenderTexture> light_buffer_;
109  std::unique_ptr<util::IDGenerator> textureunit_ids_;
110  graphic::GLTexture* white_texture_;
111 
112  Shaders shaders_;
113  ShaderProgram* light_shader_;
114 
115  friend class ::ugdk::graphic::TextureUnit;
116 };
117 
118 } // namespace graphic
119 } // namespace ugdk
120 
121 #endif // UGDK_GRAPHIC_MANAGER_H_
VertexType
Definition: manager.h:33
const ShaderProgram * GetSpecificShader(const std::bitset< NUM_FLAGS > &flags) const
void AttachTo(const std::shared_ptr< desktop::Window > &)
Definition: vector2D.h:18
void ReplaceShader(const std::bitset< NUM_FLAGS > &flags, ShaderProgram *program)
Replace the ShaderProgram UGDK uses for the given combination of flags.
bool Initialize(const std::weak_ptr< desktop::Window > &, const math::Vector2D &canvas_size)
Definition: rendertexture.h:14
void ReplaceShader(const std::string &flags, ShaderProgram *program)
Definition: manager.h:80
const ShaderProgram * current_shader() const
unsigned int LocationForVertexType(VertexType)
ShaderProgram * light_shader()
Definition: manager.h:100
Definition: textureunit.h:10
Definition: animation.h:11
const Shaders & shaders() const
Definition: manager.h:99
Definition: manager.h:54
graphic::GLTexture * white_texture()
Definition: manager.h:97
RenderTarget * screen() const
Definition: manager.h:37
action::Scene * CreateLightrenderingScene(std::function< void(Canvas &)> render_light_function)
void ReplaceShader(unsigned long flags, ShaderProgram *program)
Definition: manager.h:76
void DisableVertexType(VertexType)
TextureUnit ReserveTextureUnit(const graphic::GLTexture *texture=nullptr)
void ResizeScreen(const math::Vector2D &canvas_size)
Definition: shaderprogram.h:11
void * SDL_GLContext
Definition: manager.h:19
Shaders & shaders()
Definition: manager.h:98
RenderTexture * light_buffer() const
Definition: manager.h:95
Flag
Definition: manager.h:56
Definition: rendertarget.h:12