GLIP-Lib
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
UniformsLoader.hpp
Go to the documentation of this file.
1 /* ************************************************************************************************************* */
2 /* */
3 /* GLIP-LIB */
4 /* OpenGL Image Processing LIBrary */
5 /* */
6 /* Author : R. Kerviche */
7 /* LICENSE : MIT License */
8 /* Website : glip-lib.net */
9 /* */
10 /* File : UniformsLoader.hpp */
11 /* Original Date : June 8th 2013 */
12 /* */
13 /* Description : Uniforms variables save/load. */
14 /* */
15 /* ************************************************************************************************************* */
16 
24 #ifndef __UNIFORMS_VARS_LOADER_INCLUDE__
25 #define __UNIFORMS_VARS_LOADER_INCLUDE__
26 
27  // Includes
28  #include <map>
29  #include "Core/LibTools.hpp"
30  #include "Core/HdlDynamicData.hpp"
31  #include "Core/HdlTexture.hpp"
32  #include "Core/HdlShader.hpp"
33  #include "Core/Pipeline.hpp"
34  #include "Modules/VanillaParser.hpp"
35 
36 namespace Glip
37 {
38  using namespace CoreGL;
39  using namespace CorePipeline;
40 
41  namespace Modules
42  {
44  enum UniformsLoaderKeyword
45  {
46  KW_UL_PIPELINE,
47  KW_UL_FILTER,
48  KW_UL_GL_FLOAT,
49  KW_UL_GL_FLOAT_VEC2,
50  KW_UL_GL_FLOAT_VEC3,
51  KW_UL_GL_FLOAT_VEC4,
52  KW_UL_GL_DOUBLE,
53  KW_UL_GL_DOUBLE_VEC2,
54  KW_UL_GL_DOUBLE_VEC3,
55  KW_UL_GL_DOUBLE_VEC4,
56  KW_UL_GL_INT,
57  KW_UL_GL_INT_VEC2,
58  KW_UL_GL_INT_VEC3,
59  KW_UL_GL_INT_VEC4,
60  KW_UL_GL_UNSIGNED_INT,
61  KW_UL_GL_UNSIGNED_INT_VEC2,
62  KW_UL_GL_UNSIGNED_INT_VEC3,
63  KW_UL_GL_UNSIGNED_INT_VEC4,
64  KW_UL_GL_BOOL,
65  KW_UL_GL_BOOL_VEC2,
66  KW_UL_GL_BOOL_VEC3,
67  KW_UL_GL_BOOL_VEC4,
68  KW_UL_GL_FLOAT_MAT2,
69  KW_UL_GL_FLOAT_MAT3,
70  KW_UL_GL_FLOAT_MAT4,
71  UL_NumKeywords,
72  UL_UnknownKeyword
73  };
74 
137  class GLIP_API UniformsLoader
138  {
139  private :
140  static const char* keywords[UL_NumKeywords];
141 
142  public :
143  // Prototypes :
144  class Node;
145  class Resource;
146 
148  typedef std::map<const std::string, Node>::const_iterator NodeConstIterator;
150  typedef std::map<const std::string, Node>::iterator NodeIterator;
152  typedef std::map<const std::string, Resource>::const_iterator ResourceConstIterator;
154  typedef std::map<const std::string, Resource>::iterator ResourceIterator;
155 
158  {
168  ReplaceOnlySilent
169  };
170 
175  class GLIP_API Resource
176  {
177  private :
178  std::string name;
179  HdlDynamicData* data;
180 
181  public :
183  bool modified;
184 
185  Resource(void);
186  Resource(const Resource& cpy);
187  Resource(const VanillaParserSpace::Element& e);
188  Resource(const std::string& _name, const HdlDynamicData& _data);
189 
190  ~Resource(void);
191 
192  Resource& operator=(const Resource& cpy);
193 
194  const std::string& getName(void) const;
195  const HdlDynamicData& object(void) const;
196  HdlDynamicData& object(void);
197  int applyTo(Filter& filter, bool forceWrite=true) const;
198  VanillaParserSpace::Element getCodeElement(void) const;
199  };
200 
205  class GLIP_API Node
206  {
207  private :
208  std::string name;
209  std::map<const std::string, Node> subNodes;
210  std::map<const std::string, Resource> resources;
211 
212  public :
213  Node(void);
214  Node(const VanillaParserSpace::Element& e);
215  Node(const std::string& _name, Pipeline& pipeline, const AbstractPipelineLayout& current);
216  Node(const std::string& _name, Pipeline& pipeline, const AbstractPipelineLayout& parent, const AbstractFilterLayout& current);
217  Node(const Node& cpy);
218  ~Node(void);
219 
220  Node& operator=(const Node& cpy);
221  void softCopy(const Node& cpy, bool appendNewNodes=true, bool appendNewResources=true, bool removeAbsentNodes=true, bool removeAbsentResources=true);
222  void softCopy(const Node& cpy, LoadingFilter loadingFilter);
223 
224  const std::string& getName(void) const;
225  bool isFilter(void) const;
226  bool isPipeline(void) const;
227  bool empty(void) const;
228  void clear(void);
229  bool hasModifications(void) const;
230  void clearModifiedFlags(bool value=false);
231 
232  int getNumSubNodes(void) const;
233  std::vector<std::string> getSubNodesNamesList(void) const;
234  bool subNodeExists(const std::string& nodeName) const;
235  const Node& subNode(const std::string& nodeName) const;
236  Node& subNode(const std::string& nodeName);
237  void eraseNode(const std::string& nodeName);
238  NodeConstIterator nodeBegin(void) const;
239  NodeConstIterator nodeEnd(void) const;
240  NodeConstIterator findNode(const std::string& nodeName) const;
241  NodeIterator nodeBegin(void);
242  NodeIterator nodeEnd(void);
243  NodeIterator findNode(const std::string& nodeName);
244 
245  int getNumResources(void) const;
246  std::vector<std::string> getResourcesNamesList(void) const;
247  bool resourceExists(const std::string& resourceName) const;
248  const Resource& resource(const std::string& resourceName) const;
249  Resource& resource(const std::string& resourceName);
250  void eraseResource(const std::string& resourceName);
251  ResourceConstIterator resourceBegin(void) const;
252  ResourceConstIterator resourceEnd(void) const;
253  ResourceConstIterator findResource(const std::string& resourceName) const;
254  ResourceIterator resourceBegin(void);
255  ResourceIterator resourceEnd(void);
256  ResourceIterator findResource(const std::string& resourceName);
257 
258  int applyTo(Pipeline& pipeline, const AbstractPipelineLayout& current, bool forceWrite=true, bool silent=false) const;
259  int applyTo(Pipeline& pipeline, Filter& filter, bool forceWrite=true, bool silent=false) const;
260  VanillaParserSpace::Element getCodeElement(void) const;
261  };
262 
263  private :
264  std::map<const std::string, Node> nodes;
265 
266  public :
267  UniformsLoader(void);
268  UniformsLoader(const UniformsLoader& cpy);
269  ~UniformsLoader(void);
270 
271  void load(std::string source, LoadingFilter loadingFilter=LoadAll, int lineOffset=1);
272  void load(Pipeline& pipeline, LoadingFilter loadingFilter=LoadAll);
273  void load(const UniformsLoader& subLoader, LoadingFilter loadingFilter=LoadAll);
274  bool empty(void) const;
275  void clear(void);
276  void clear(const std::string& name);
277  bool hasPipeline(const std::string& name) const;
278  std::vector<std::string> getPipelinesTypeNames(void) const;
279  const Node& getRootNode(const std::string& name) const;
280  Node& getRootNode(const std::string& name);
281  NodeConstIterator rootNodeBegin(void) const;
282  NodeConstIterator rootNodeEnd(void) const;
283  NodeIterator rootNodeBegin(void);
284  NodeIterator rootNodeEnd(void);
285  int applyTo(Pipeline& pipeline, bool forceWrite=true, bool silent=false) const;
286  std::string getCode(void) const;
287  std::string getCode(const std::string& name) const;
288  void writeToFile(const std::string& filename) const;
289 
290  static const char* getKeyword(UniformsLoaderKeyword k);
291  };
292  }
293 }
294 
295 #endif
296 
Specific defines for the API structure.
Pipeline object.
OpenGL Dynamic Memory Allocator.
Container structure (filter, pipeline).
Definition: UniformsLoader.hpp:205
Small file parser.
Filter layout (Read Only).
Definition: Filter.hpp:59
bool modified
This flag can be used to manually set the variable as modified or non-modified, in order to limit dri...
Definition: UniformsLoader.hpp:183
Load all the data, append new data, replace existing data.
Definition: UniformsLoader.hpp:160
Loads and writes a set of uniforms variables values from a file or a string.
Definition: UniformsLoader.hpp:137
OpenGL Texture Handle.
Pipeline layout (Read Only).
Definition: Pipeline.hpp:63
Definition: Component.hpp:32
std::map< const std::string, Node >::const_iterator NodeConstIterator
Const iterator over the nodes (refers to a std::pair, use second to access the const UniformsLoader::...
Definition: UniformsLoader.hpp:145
Replace existing data only, throw an Exception if there is some new data.
Definition: UniformsLoader.hpp:166
Load only new data, throw an Exception if some data already exists.
Definition: UniformsLoader.hpp:162
Dynamic allocator for GL types (run-time resolution of type).
Definition: HdlDynamicData.hpp:65
Load only new data, ignore data which already exists.
Definition: UniformsLoader.hpp:164
LoadingFilter
Flags used for loading data from pipelines, strings or files.
Definition: UniformsLoader.hpp:157
std::map< const std::string, Node >::iterator NodeIterator
Iterator over the nodes (refers to a std::pair, use second to access the UniformsLoader::Node& object...
Definition: UniformsLoader.hpp:150
OpenGL Pixel and Fragment Shader Handle.
Resource (variable) of a structure (filter, pipeline).
Definition: UniformsLoader.hpp:175
Pipeline object.
Definition: Pipeline.hpp:261
Filter object.
Definition: Filter.hpp:124
std::map< const std::string, Resource >::const_iterator ResourceConstIterator
Const iterator over the resources (refers to a std::pair, use second to access the const UniformsLoad...
Definition: UniformsLoader.hpp:152
std::map< const std::string, Resource >::iterator ResourceIterator
Iterator over the resources (refers to a std::pair, use second to access the UniformsLoader::Resource...
Definition: UniformsLoader.hpp:154