GlSystem.cpp
Go to the documentation of this file.
1 #include "GlSystem.hpp"
2 
4 
5 namespace iv
6 {
7 
8 GlSystem::GlSystem( SystemContainer * sc, RenderTarget * rt, bool gl_enabled ) :
9  System( sc ),
10  _render_target( rt ),
11  gl_listeners_iterating( false ),
12  gl_enabled( gl_enabled )
13 {
14 }
15 
17 {
18 }
19 
21 {
22  return this->_render_target;
23 }
24 
26 {
27  if( this->gl_enabled )
28  return;
29 
30  this->gl_enabled = true;
31 
32  this->gl_listeners_iterating = true;
33  for( auto listener : this->gl_listeners )
34  listener->GlEnable();
35  this->gl_listeners_iterating = false;
36 }
37 
39 {
40  if( !this->gl_enabled )
41  return;
42 
43  this->gl_listeners_iterating = true;
44  for( auto listener : this->gl_listeners )
45  listener->GlEnable();
46  this->gl_listeners_iterating = false;
47 
48  this->gl_enabled = false;
49 }
50 
52 {
53  if( !this->gl_enabled )
54  return;
55 
56  this->gl_enabled = false;
57 
58  this->gl_listeners_iterating = true;
59  for( auto listener : this->gl_listeners )
60  listener->GlDrop();
61  this->gl_listeners_iterating = false;
62 }
63 
65 {
66  return this->gl_enabled;
67 }
68 
70 {
71  if( this->gl_listeners_iterating )
72  this->warning( SRC_INFO, "Can not add gl listener when notifying gl listeners," );
73 
74  this->gl_listeners.insert( listener );
75 }
76 
78 {
79  if( this->gl_listeners_iterating )
80  this->warning( SRC_INFO, "Can not add gl listener when notifying gl listeners," );
81 
82  this->gl_listeners.erase( listener );
83 }
84 
86  inst( inst )
87 {
88 }
89 
91 {
92  return this->inst;
93 }
94 
95 bool GlInfo::GlIsEnabled() const
96 {
97  auto ds = this->instance()->getSystem< GlSystem >();
98  if( !ds )
99  return false;
100 
101  return ds->GlIsEnabled();
102 }
103 
105 {
106  auto ds = this->instance()->getSystem< GlSystem >();
107  if( !ds )
108  return nullptr;
109 
110  return ds->render_target();;
111 }
112 
114  GlInfo( inst )
115 {
116  auto ds = this->instance()->getSystem< GlSystem >();
117  if( !ds )
118  return;
119 
120  ds->AddGlListener( this );
121 }
122 
124 {
125  auto ds = this->instance()->getSystem< GlSystem >();
126  if( !ds )
127  return;
128 
129  ds->RemoveGlListener( this );
130 }
131 
132 }