Ion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
shaderprogram.h
Go to the documentation of this file.
1 
18 #ifndef ION_GFX_SHADERPROGRAM_H_
19 #define ION_GFX_SHADERPROGRAM_H_
20 
21 #include "ion/base/referent.h"
22 #include "ion/gfx/resourceholder.h"
23 #include "ion/gfx/shader.h"
24 
25 namespace ion {
26 namespace gfx {
27 
28 class ShaderInputRegistry;
30 
32 class ShaderProgram;
35 
38 class ION_API ShaderProgram : public ShaderBase {
39  public:
41  enum Changes {
42  kVertexShaderChanged = kNumBaseChanges,
44  kNumChanges
45  };
46 
48  explicit ShaderProgram(const ShaderInputRegistryPtr& registry);
49 
51  const ShaderInputRegistryPtr& GetRegistry() const { return registry_; }
52 
54  void SetVertexShader(const ShaderPtr& shader) {
55  if (Shader* old_shader = vertex_shader_.Get().Get())
56  old_shader->RemoveReceiver(this);
57  vertex_shader_.Set(shader);
58  if (shader.Get())
59  shader->AddReceiver(this);
60  }
61  const ShaderPtr& GetVertexShader() const {
62  return vertex_shader_.Get();
63  }
64 
66  void SetFragmentShader(const ShaderPtr& shader) {
67  if (Shader* old_shader = fragment_shader_.Get().Get())
68  old_shader->RemoveReceiver(this);
69  fragment_shader_.Set(shader);
70  if (shader.Get())
71  shader->AddReceiver(this);
72  }
73  const ShaderPtr& GetFragmentShader() const {
74  return fragment_shader_.Get();
75  }
76 
88  void SetConcurrent(bool value);
89  bool IsConcurrent() const { return concurrent_; }
90 
98  static const ShaderProgramPtr BuildFromStrings(
99  const std::string& id_string,
100  const ShaderInputRegistryPtr& registry_ptr,
101  const std::string& vertex_shader_string,
102  const std::string& fragment_shader_string,
103  const base::AllocatorPtr& allocator);
104 
105  protected:
108  ~ShaderProgram() override;
109 
110  private:
112  void OnNotify(const base::Notifier* notifier) override;
113 
114  Field<ShaderPtr> vertex_shader_;
115  Field<ShaderPtr> fragment_shader_;
116  ShaderInputRegistryPtr registry_;
118  bool concurrent_;
120  bool concurrent_set_;
121 };
122 
123 } // namespace gfx
124 } // namespace ion
125 
126 #endif // ION_GFX_SHADERPROGRAM_H_
void SetVertexShader(const ShaderPtr &shader)
Sets/returns the vertex shader stage.
Definition: shaderprogram.h:54
Changes
Changes that affect the resource.
Definition: shaderprogram.h:41
A ShaderProgram represents an OpenGL shader program that can be applied to shapes.
Definition: shaderprogram.h:38
double value
A Notifier both sends notifications to and receives notifications from other Notifiers.
Definition: notifier.h:35
const ShaderPtr & GetVertexShader() const
Definition: shaderprogram.h:61
base::WeakReferentPtr< ShaderProgram > ShaderProgramWeakPtr
Definition: shaderprogram.h:34
const ShaderPtr & GetFragmentShader() const
Definition: shaderprogram.h:73
T * Get() const
Returns a raw pointer to the instance, which may be NULL.
Definition: sharedptr.h:89
base::ReferentPtr< ShaderProgram >::Type ShaderProgramPtr
SharedPtr< ShaderInputRegistry > Type
Definition: referent.h:60
const ShaderInputRegistryPtr & GetRegistry() const
Returns the ShaderInputRegistry used for the instance.
Definition: shaderprogram.h:51
A Shader represents an OpenGL shader stage.
Definition: shader.h:59
void SetFragmentShader(const ShaderPtr &shader)
Sets/returns the fragment shader stage.
Definition: shaderprogram.h:66
base::ReferentPtr< ShaderInputRegistry >::Type ShaderInputRegistryPtr
Convenience typedef for shared pointer to a ShaderInputRegistry.
Base class for Shader and ShaderProgram objects.
Definition: shader.h:30
bool IsConcurrent() const
Definition: shaderprogram.h:89
A SharedPtr is a smart shared pointer to an instance of some class that implements reference counting...
Definition: sharedptr.h:60
A WeakReferentPtr is a weak reference to an instance of some class derived from Referent.
Definition: weakreferent.h:182