CDrawContext.h
Go to the documentation of this file.
1 
2 #pragma once
3 
4 #include <ionCore.h>
5 #include <ionMath.h>
6 #include <ionGraphics.h>
7 
8 #include "CShaderProgram.h"
9 #include "CVertexBuffer.h"
10 #include "CIndexBuffer.h"
11 
12 
13 namespace ion
14 {
15  namespace Graphics
16  {
17  namespace GL
18  {
19 
20  class CDrawContext;
21 
22  class CDrawConfig : public IDrawConfig
23  {
24 
25  friend class CDrawContext;
26 
27  public:
28 
29  virtual void SetVertexBuffer(uint const Index, SharedPointer<IVertexBuffer> VertexBuffer);
31  virtual void SetUniform(string const & Name, SharedPointer<IUniform> Uniform);
32  virtual void SetTexture(string const & Name, SharedPointer<ITexture> Texture);
33  virtual void SetInstanceCount(uint const Count);
34 
35  protected:
36 
37  vector<SharedPointer<CVertexBuffer>> VertexBuffers;
40 
42  {
43  string Name;
44  int Handle = -1;
46  };
47 
49  {
50  string Name;
51  int Handle = -1;
53  };
54 
55  map<string, SUniformBinding *> ProvidedUniforms;
56  map<string, STextureBinding *> ProvidedTextures;
57 
58  vector<SUniformBinding *> UniformBindings;
59  vector<STextureBinding *> TextureBindings;
60 
61  set<string> RequiredUniforms;
62  set<string> UnboundAttributes;
63 
65 
66  bool NeedsToBeLoaded = true;
67  bool LoadedSuccessfully = false;
68 
70 
71  CDrawContext * Container = nullptr;
72 
73  };
74 
75  class CDrawContext : public IDrawContext
76  {
77 
78  public:
79 
80  CDrawContext();
81 
82  virtual void SetShader(SharedPointer<IShader> Shader);
83  virtual void SetVertexBuffer(uint const Index, SharedPointer<IVertexBuffer> VertexBuffer);
85  virtual void SetUniform(string const & Name, SharedPointer<IUniform> Uniform);
86  virtual void SetTexture(string const & Name, SharedPointer<ITexture> Texture);
87 
88  virtual void SetPrimitiveType(EPrimitiveType const PrimitiveType);
89  virtual void SetFeatureEnabled(EDrawFeature const Feature, bool const Enabled);
90  virtual void SetBlendMode(EBlendMode const BlendMode);
91  virtual void SetInstancingEnabled(bool const Enabled);
92 
93  virtual set<string> GetUnboundUniforms() const;
94 
95  virtual void Draw(IDrawConfig * DrawConfig);
96  virtual IDrawConfig * CreateDrawConfig();
97 
98  static void Invalidate();
99 
100  protected:
101 
103 
104  vector<SharedPointer<CVertexBuffer>> VertexBuffers;
106 
107  map<string, SharedPointer<IUniform const>> Uniforms;
108  map<string, SharedPointer<ITexture const>> Textures;
109 
110  map<uint, SharedPointer<IUniform const>> BoundUniforms;
111  map<uint, SharedPointer<ITexture const>> BoundTextures;
112 
113  set<string> RequiredUniforms;
114  set<string> UnboundAttributes;
115 
116  bool DrawWireframe = false;
117  bool CullFront = false;
118  bool CullBack = false;
119  bool DisableDepthTest = false;
120  bool DisableDepthWrite = false;
123  bool UseInstancing = false;
124 
125  vector<CDrawConfig *> Configs;
126 
127  int StartTextures = 0;
128 
129  void LoadConfig(CDrawConfig * DrawConfig);
130  void LoadVertexBuffer(CDrawConfig * DrawConfig, SharedPointer<CVertexBuffer> VertexBuffer);
131 
132  void InternalBindUniform(uint const Handle, SharedPointer<IUniform const> const Uniform);
133 
134  bool InternalDrawSetup();
135  void InternalDrawTeardown();
136 
138 
139  };
140  }
141  }
142 }
vector< CDrawConfig * > Configs
Definition: CDrawContext.h:125
virtual void SetInstanceCount(uint const Count)
Definition: CDrawContext.cpp:74
set< string > RequiredUniforms
Definition: CDrawContext.h:113
friend class CDrawContext
Definition: CDrawContext.h:25
Definition: CDrawContext.h:75
vector< SharedPointer< CVertexBuffer > > VertexBuffers
Definition: CDrawContext.h:104
EBlendMode
Definition: IPipelineState.h:30
uint InstanceCount
Definition: CDrawContext.h:69
set< string > UnboundAttributes
Definition: CDrawContext.h:114
SharedPointer< ITexture const > Texture
Definition: CDrawContext.h:52
uint VertexArrayHandle
Definition: CDrawContext.h:64
virtual void SetUniform(string const &Name, SharedPointer< IUniform > Uniform)
Definition: CDrawContext.cpp:36
map< string, STextureBinding * > ProvidedTextures
Definition: CDrawContext.h:56
map< string, SharedPointer< ITexture const > > Textures
Definition: CDrawContext.h:108
bool NeedsToBeLoaded
Definition: CDrawContext.h:66
virtual void SetTexture(string const &Name, SharedPointer< ITexture > Texture)
Definition: CDrawContext.cpp:55
SharedPointer< CIndexBuffer > IndexBuffer
Definition: CDrawContext.h:105
Definition: CDrawContext.h:22
Alternative to Pipeline State rendering. Represents the context for one or many draw calls...
Definition: IDrawContext.h:34
map< string, SUniformBinding * > ProvidedUniforms
Definition: CDrawContext.h:55
vector< SharedPointer< CVertexBuffer > > VertexBuffers
Definition: CDrawContext.h:37
static CDrawContext * CurrentContext
Definition: CDrawContext.h:137
Definition: CCatmullRomAdvancedSplineInterpolator.h:7
SharedPointer< CIndexBuffer > IndexBuffer
Definition: CDrawContext.h:38
SharedPointer< IUniform const > Uniform
Definition: CDrawContext.h:45
unsigned int uint
Definition: ionTypes.h:42
string Name
Definition: CDrawContext.h:43
virtual void SetVertexBuffer(uint const Index, SharedPointer< IVertexBuffer > VertexBuffer)
Definition: CDrawContext.cpp:16
int Handle
Definition: CDrawContext.h:44
EDrawFeature
Definition: IPipelineState.h:19
map< uint, SharedPointer< ITexture const > > BoundTextures
Definition: CDrawContext.h:111
map< uint, SharedPointer< IUniform const > > BoundUniforms
Definition: CDrawContext.h:110
uint PrimitiveType
Definition: CDrawContext.h:121
Alternative to Pipeline State rendering. Represents a single draw call.
Definition: IDrawContext.h:16
EPrimitiveType
Definition: IPipelineState.h:40
set< string > UnboundAttributes
Definition: CDrawContext.h:62
SharedPointer< CIndexBuffer > UsedIndexBuffer
Definition: CDrawContext.h:39
set< string > RequiredUniforms
Definition: CDrawContext.h:61
CDrawContext * Container
Definition: CDrawContext.h:71
string Name
Definition: CDrawContext.h:50
std::shared_ptr< T > SharedPointer
Definition: ionSmartPointer.h:25
SharedPointer< CShader > Shader
Definition: CDrawContext.h:102
vector< STextureBinding * > TextureBindings
Definition: CDrawContext.h:59
map< string, SharedPointer< IUniform const > > Uniforms
Definition: CDrawContext.h:107
bool LoadedSuccessfully
Definition: CDrawContext.h:67
vector< SUniformBinding * > UniformBindings
Definition: CDrawContext.h:58
virtual void SetIndexBuffer(SharedPointer< IIndexBuffer > IndexBuffer)
Definition: CDrawContext.cpp:29