GLIP-Lib
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
LayoutLoader.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 : LayoutLoader.hpp */
11 /* Original Date : December 22th 2011 */
12 /* */
13 /* Description : Layout Loader from files or strings. */
14 /* */
15 /* ************************************************************************************************************* */
16 
24 #ifndef __LAYOUT_LOADER_INCLUDE__
25 #define __LAYOUT_LOADER_INCLUDE__
26 
27  #include <map>
28  #include "Core/LibTools.hpp"
29  #include "Core/HdlTexture.hpp"
30  #include "Core/Geometry.hpp"
31  #include "Core/ShaderSource.hpp"
32  #include "Core/Filter.hpp"
33  #include "Core/Pipeline.hpp"
34  #include "Modules/VanillaParser.hpp"
36 
37 namespace Glip
38 {
39  using namespace CoreGL;
40  using namespace CorePipeline;
41 
42  namespace Modules
43  {
48  enum LayoutLoaderKeyword
49  {
50  KW_LL_TRUE,
51  KW_LL_FALSE,
52  KW_LL_FORMAT,
53  KW_LL_SOURCE,
54  KW_LL_FILTER_LAYOUT,
55  KW_LL_PIPELINE_LAYOUT,
56  KW_LL_PIPELINE_MAIN,
57  KW_LL_INCLUDE,
58  KW_LL_FILTER_INSTANCE,
59  KW_LL_PIPELINE_INSTANCE,
60  KW_LL_CONNECTION,
61  KW_LL_INPUT_PORTS,
62  KW_LL_OUTPUT_PORTS,
63  KW_LL_THIS_PIPELINE,
64  KW_LL_REQUIRED_FORMAT,
65  KW_LL_REQUIRED_SOURCE,
66  KW_LL_REQUIRED_GEOMETRY,
67  KW_LL_REQUIRED_PIPELINE,
68  KW_LL_INSERT,
69  KW_LL_GEOMETRY,
70  KW_LL_GRID_2D,
71  KW_LL_GRID_3D,
72  KW_LL_CUSTOM_MODEL,
73  KW_LL_STANDARD_QUAD,
74  KW_LL_VERTEX,
75  KW_LL_ELEMENT,
76  KW_LL_ADD_PATH,
77  KW_LL_CALL,
78  KW_LL_SAFE_CALL,
79  KW_LL_UNIQUE,
80  LL_NumKeywords,
81  LL_UnknownKeyword
82  };
83 
706  class GLIP_API LayoutLoader
707  {
708  public :
715  struct GLIP_API PipelineScriptElements
716  {
718  std::string unique;
720  std::vector<std::string> addedPaths,
722  includedFiles,
724  requiredFormats,
726  requiredSources,
728  requiredGeometries,
730  requiredPipelines,
732  modulesCalls,
734  formats,
736  sources,
738  geometries,
740  filtersLayout,
742  pipelines;
744  std::vector< std::vector<std::string> > pipelineInputs;
746  std::vector< std::vector<std::string> > pipelineOutputs;
748  std::string mainPipeline;
750  std::vector<std::string> mainPipelineInputs,
753  };
754 
755  private :
756  static const char* keywords[LL_NumKeywords];
757 
758  bool isSubLoader;
759 
760  // Reading dynamic :
761  std::string currentPath;
762  std::vector<std::string> dynamicPaths;
763  std::vector<LayoutLoaderKeyword> associatedKeyword;
764  std::vector<std::string> uniqueList;
765  std::map<std::string, HdlTextureFormat> formatList;
766  std::map<std::string, ShaderSource> sourceList;
767  std::map<std::string, GeometryModel> geometryList;
768  std::map<std::string, FilterLayout> filterList;
769  std::map<std::string, PipelineLayout> pipelineList;
770 
771  // Static :
772  std::vector<std::string> staticPaths;
773  std::map<std::string, HdlTextureFormat> requiredFormatList;
774  std::map<std::string, ShaderSource> requiredSourceList;
775  std::map<std::string, GeometryModel> requiredGeometryList;
776  std::map<std::string, PipelineLayout> requiredPipelineList;
777  std::map<std::string, LayoutLoaderModule*> modules; // Using pointers to avoid conflict between polymorphism and object slicing.
778 
779  // Tools :
780  LayoutLoader(const LayoutLoader& master);
781 
782  LayoutLoaderKeyword getKeyword(const std::string& str);
783 
784  void clean(void);
785  void classify(const std::vector<VanillaParserSpace::Element>& elements, std::vector<LayoutLoaderKeyword>& associatedKeywords);
786  bool fileExists(const std::string& filename, std::string& source, const bool test=false);
787  void loadFile(const std::string& filename, std::string& content, std::string& usedPath);
788  void preliminaryTests(const VanillaParserSpace::Element& e, char nameProperty, int minArguments, int maxArguments, char bodyProperty, const std::string& objectName);
789  ShaderSource enhanceShaderSource(const std::string& str, const std::string& sourceName, int startLine=1);
790  void append(LayoutLoader& subLoader);
791  void appendPath(const VanillaParserSpace::Element& e);
792  void includeFile(const VanillaParserSpace::Element& e);
793  bool checkUnique(const VanillaParserSpace::Element& e);
794  void buildRequiredFormat(const VanillaParserSpace::Element& e);
795  void buildRequiredSource(const VanillaParserSpace::Element& e);
796  void buildRequiredGeometry(const VanillaParserSpace::Element& e);
797  void buildRequiredPipeline(const VanillaParserSpace::Element& e);
798  void moduleCall(const VanillaParserSpace::Element& e, std::string& mainPipelineName, const bool safe=false);
799  void buildFormat(const VanillaParserSpace::Element& e);
800  void buildSource(const VanillaParserSpace::Element& e);
801  void buildGeometry(const VanillaParserSpace::Element& e);
802  void buildFilter(const VanillaParserSpace::Element& e);
803  void buildPipeline(const VanillaParserSpace::Element& e);
804  void process(const std::string& code, std::string& mainPipelineName, const std::string& sourceName, int startLine=1);
805 
806  void listPipelinePorts(const VanillaParserSpace::Element& e, std::vector<std::string>& inputs, std::vector<std::string>& outputs);
807 
808  public :
809  LayoutLoader(void);
810  virtual ~LayoutLoader(void);
811 
812  const std::vector<std::string>& paths(void) const;
813  void clearPaths(void);
814  void addToPaths(std::string p);
815  void addToPaths(const std::vector<std::string>& paths);
816  bool removeFromPaths(const std::string& p);
817 
818  AbstractPipelineLayout getPipelineLayout(const std::string& source, std::string sourceName="", int startLine=1);
819  Pipeline* getPipeline(const std::string& source, std::string pipelineName="", std::string sourceName="", int startLine=1);
820 
821  void addRequiredElement(const std::string& name, const HdlAbstractTextureFormat& fmt, bool replace=true);
822  bool hasRequiredFormat(const std::string& name) const;
823  const HdlAbstractTextureFormat& getRequiredFormat(const std::string& name) const;
824  int clearRequiredFormat(const std::string& name="");
825  int clearRequiredFormat(bool (*filter)(const std::string&));
826  void addRequiredElement(const std::string& name, const ShaderSource& src, bool replace=true);
827  bool hasRequiredSource(const std::string& name) const;
828  const ShaderSource& getRequiredSource(const std::string& name) const;
829  int clearRequiredSource(const std::string& name="");
830  int clearRequiredSource(bool (*filter)(const std::string&));
831  void addRequiredElement(const std::string& name, const GeometryModel& mdl, bool replace=true);
832  bool hasRequiredGeometry(const std::string& name) const;
833  const GeometryModel& getRequiredGeometry(const std::string& name) const;
834  int clearRequiredGeometry(const std::string& name="");
835  int clearRequiredGeometry(bool (*filter)(const std::string&));
836  void addRequiredElement(const std::string& name, AbstractPipelineLayout& layout, bool replace=true);
837  bool hasRequiredPipeline(const std::string& name) const;
838  const AbstractPipelineLayout& getRequiredPipelineLayout(const std::string& name) const;
839  int clearRequiredPipelineLayout(const std::string& name="");
840  int clearRequiredPipelineLayout(bool (*filter)(const std::string&));
841  int clearRequiredElements(const std::string& name="");
842  int clearRequiredElements(bool (*filter)(const std::string&));
843 
844  PipelineScriptElements listElements(const std::string& source, std::string sourceName="", int startLine=1);
845 
846  void addModule(LayoutLoaderModule* module, bool replace=false);
847  bool hasModule(const LayoutLoaderModule* module) const;
848  bool hasModule(const std::string& name) const;
849  std::vector<const LayoutLoaderModule*> listModules(void) const;
850  std::vector<LayoutLoaderModule*> listModules(void);
851  std::vector<std::string> listModuleNames(void) const;
852  const LayoutLoaderModule& module(const std::string& name) const;
853  LayoutLoaderModule& module(const std::string& name);
854  const LayoutLoaderModule* removeModule(const LayoutLoaderModule* module);
855  LayoutLoaderModule* removeModule(const std::string& name);
856 
857  static const char* getKeyword(LayoutLoaderKeyword k);
858  };
859 
874  class GLIP_API LayoutWriter
875  {
876  public :
877  static VanillaParserSpace::Element write(const HdlAbstractTextureFormat& format, const std::string& name);
878  static VanillaParserSpace::Element write(const ShaderSource& source, const std::string& name);
879  static VanillaParserSpace::Element write(const GeometryModel& mdl, const std::string& name);
880 
881  private:
882  VanillaParserSpace::Element write(const AbstractFilterLayout& fLayout);
883  VanillaParserSpace::Element write(const AbstractPipelineLayout& pLayout, bool isMain=false);
884 
885  std::string code;
886 
887  public :
888  LayoutWriter(void);
889  virtual ~LayoutWriter(void);
890 
891  std::string getCode(const AbstractPipelineLayout& pipelineLayout);
892  void writeToFile(const AbstractPipelineLayout& pipelineLayout, const std::string& filename);
893  };
894  }
895 }
896 
897 #endif
898 
Specific defines for the API structure.
Contains data about a script, possibly made before the load operation.
Definition: LayoutLoader.hpp:715
Pipeline object.
std::string mainPipeline
Name of the main pipeline contained in the script.
Definition: LayoutLoader.hpp:748
Filter object.
Small file parser.
Module description for the LayoutLoader class.
Definition: LayoutLoaderModules.hpp:746
Filter layout (Read Only).
Definition: Filter.hpp:59
OpenGL Texture Handle.
Pipeline layout (Read Only).
Definition: Pipeline.hpp:63
std::vector< std::string > mainPipelineOutputs
List of the output ports for the main pipeline contained in the script.
Definition: LayoutLoader.hpp:750
Definition: Component.hpp:32
Shader source and tools.
std::string unique
Unique identifier.
Definition: LayoutLoader.hpp:718
std::vector< std::vector< std::string > > pipelineOutputs
List of the output ports for each pipeline contained in the script (same order as pipelines)...
Definition: LayoutLoader.hpp:746
std::vector< std::string > sources
Names of the shader source code contained in the script.
Definition: LayoutLoader.hpp:720
Geometry objects and memory management.
Shader source code and infos.
Definition: ShaderSource.hpp:55
Get equivalent pipeline code from a pipeline layout.
Definition: LayoutLoader.hpp:874
Geometry stored on the host.
Definition: Geometry.hpp:50
Pipeline object.
Definition: Pipeline.hpp:261
std::vector< std::vector< std::string > > pipelineInputs
List of the input ports for each pipeline contained in the script (same order as pipelines).
Definition: LayoutLoader.hpp:744
Load and save pipelines layouts to file.
Definition: LayoutLoader.hpp:706
Layout Loader Modules.
Object handle for OpenGL texture formats (Read Only).
Definition: HdlTexture.hpp:42