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 
41  map<string, SharedPointer<IUniform const>> Uniforms;
42  map<string, SharedPointer<ITexture const>> Textures;
43 
44  map<uint, SharedPointer<IUniform const>> BoundUniforms;
45  map<u32, SharedPointer<ITexture const>> BoundTextures;
46 
47  set<string> RequiredUniforms;
48  set<string> UnboundAttributes;
49 
51 
52  bool NeedsToBeLoaded = true;
53  bool LoadedSuccessfully = false;
54 
56 
57  CDrawContext * Container = nullptr;
58 
59  };
60 
61  class CDrawContext : public IDrawContext
62  {
63 
64  public:
65 
66  CDrawContext();
67 
68  virtual void SetProgram(SharedPointer<IShaderProgram> ShaderProgram);
69  virtual void SetVertexBuffer(uint const Index, SharedPointer<IVertexBuffer> VertexBuffer);
71  virtual void SetUniform(string const & Name, SharedPointer<IUniform> Uniform);
72  virtual void SetTexture(string const & Name, SharedPointer<ITexture> Texture);
73 
74  virtual void SetPrimitiveType(EPrimitiveType const PrimitiveType);
75  virtual void SetFeatureEnabled(EDrawFeature const Feature, bool const Enabled);
76  virtual void SetBlendMode(EBlendMode const BlendMode);
77  virtual void SetInstancingEnabled(bool const Enabled);
78 
79  virtual set<string> GetUnboundUniforms() const;
80 
81  virtual void Draw(IDrawConfig * DrawConfig);
82  virtual IDrawConfig * CreateDrawConfig();
83 
84  static void Invalidate();
85 
86  protected:
87 
89 
90  vector<SharedPointer<CVertexBuffer>> VertexBuffers;
92 
93  map<string, SharedPointer<IUniform const>> Uniforms;
94  map<string, SharedPointer<ITexture const>> Textures;
95 
96  map<uint, SharedPointer<IUniform const>> BoundUniforms;
97  map<u32, SharedPointer<ITexture const>> BoundTextures;
98 
99  set<string> RequiredUniforms;
100  set<string> UnboundAttributes;
101 
102  bool DrawWireframe = false;
103  bool CullFront = false;
104  bool CullBack = false;
105  bool DisableDepthTest = false;
106  bool DisableDepthWrite = false;
109  bool UseInstancing = false;
110 
111  vector<CDrawConfig *> Configs;
112 
113  void LoadConfig(CDrawConfig * DrawConfig);
114  void LoadVertexBuffer(CDrawConfig * DrawConfig, SharedPointer<CVertexBuffer> VertexBuffer);
115 
116  void InternalBindUniform(uint const Handle, SharedPointer<IUniform const> const Uniform);
117 
118  bool InternalDrawSetup();
119  void InternalDrawTeardown();
120 
122 
123  };
124  }
125  }
126 }
vector< CDrawConfig * > Configs
Definition: CDrawContext.h:111
virtual void SetInstanceCount(uint const Count)
Definition: CDrawContext.cpp:50
set< string > RequiredUniforms
Definition: CDrawContext.h:99
friend class CDrawContext
Definition: CDrawContext.h:25
Definition: CDrawContext.h:61
map< uint, SharedPointer< IUniform const > > BoundUniforms
Definition: CDrawContext.h:44
vector< SharedPointer< CVertexBuffer > > VertexBuffers
Definition: CDrawContext.h:90
EBlendMode
Definition: IPipelineState.h:30
uint InstanceCount
Definition: CDrawContext.h:55
set< string > UnboundAttributes
Definition: CDrawContext.h:100
uint VertexArrayHandle
Definition: CDrawContext.h:50
virtual void SetUniform(string const &Name, SharedPointer< IUniform > Uniform)
Definition: CDrawContext.cpp:36
std::shared_ptr< T > SharedPointer
Definition: ionSmartPointer.h:22
map< string, SharedPointer< ITexture const > > Textures
Definition: CDrawContext.h:94
bool NeedsToBeLoaded
Definition: CDrawContext.h:52
map< u32, SharedPointer< ITexture const > > BoundTextures
Definition: CDrawContext.h:97
virtual void SetTexture(string const &Name, SharedPointer< ITexture > Texture)
Definition: CDrawContext.cpp:43
map< string, SharedPointer< IUniform const > > Uniforms
Definition: CDrawContext.h:41
SharedPointer< CIndexBuffer > IndexBuffer
Definition: CDrawContext.h:91
unsigned int uint
Definition: ionTypes.h:99
Definition: CDrawContext.h:22
Alternative to Pipeline State rendering. Represents the context for one or many draw calls...
Definition: IDrawContext.h:34
vector< SharedPointer< CVertexBuffer > > VertexBuffers
Definition: CDrawContext.h:37
map< u32, SharedPointer< ITexture const > > BoundTextures
Definition: CDrawContext.h:45
static CDrawContext * CurrentContext
Definition: CDrawContext.h:121
Definition: CCatmullRomAdvancedSplineInterpolator.h:7
SharedPointer< CIndexBuffer > IndexBuffer
Definition: CDrawContext.h:38
virtual void SetVertexBuffer(uint const Index, SharedPointer< IVertexBuffer > VertexBuffer)
Definition: CDrawContext.cpp:16
EDrawFeature
Definition: IPipelineState.h:19
map< uint, SharedPointer< IUniform const > > BoundUniforms
Definition: CDrawContext.h:96
uint PrimitiveType
Definition: CDrawContext.h:107
SharedPointer< CShaderProgram > ShaderProgram
Definition: CDrawContext.h:88
Alternative to Pipeline State rendering. Represents a single draw call.
Definition: IDrawContext.h:16
EPrimitiveType
Definition: IPipelineState.h:38
set< string > UnboundAttributes
Definition: CDrawContext.h:48
SharedPointer< CIndexBuffer > UsedIndexBuffer
Definition: CDrawContext.h:39
set< string > RequiredUniforms
Definition: CDrawContext.h:47
CDrawContext * Container
Definition: CDrawContext.h:57
map< string, SharedPointer< IUniform const > > Uniforms
Definition: CDrawContext.h:93
bool LoadedSuccessfully
Definition: CDrawContext.h:53
virtual void SetIndexBuffer(SharedPointer< IIndexBuffer > IndexBuffer)
Definition: CDrawContext.cpp:29
map< string, SharedPointer< ITexture const > > Textures
Definition: CDrawContext.h:42