GLIP-Lib
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
ShaderSource.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 : ShaderSource.hpp */
11 /* Original Date : August 15th 2011 */
12 /* */
13 /* Description : Shader source and tools */
14 /* */
15 /* ************************************************************************************************************* */
16 
24 #ifndef __GLIP_SHADERSOURCE__
25 #define __GLIP_SHADERSOURCE__
26 
27  // Includes
28  #include "Core/LibTools.hpp"
29  #include "Core/OglInclude.hpp"
30  #include "Core/Exception.hpp"
31  #include <string>
32  #include <vector>
33  #include <map>
34  #include <fstream>
35 
36  namespace Glip
37  {
38  namespace CoreGL
39  {
40  // Objects
55  class GLIP_API ShaderSource
56  {
57  public :
62  struct LineInfo
63  {
67  std::string sourceName;
68 
69  LineInfo(void);
70  LineInfo(const std::string& _sourceName, int _lineNumber);
71  };
72 
73  private :
74  // Data
75  std::string source,
76  sourceName;
77  std::vector<size_t> lineFirstChar,
78  lineLength;
79  std::vector<std::string> inSamplers2D;
80  std::vector<std::string> uniformVars;
81  std::vector<GLenum> uniformVarsType;
82  std::vector<std::string> outFragments;
83  bool compatibilityRequest;
84  int versionNumber,
85  startLine;
86 
87  // Tools :
88  void parseLines(void);
89  bool removeBlock(std::string& line, const std::string& bStart, const std::string& bEnd, bool nested);
90  void wordSplit(const std::string& line, std::vector<std::string>& split);
91  GLenum parseUniformTypeCode(const std::string& str, const std::string& cpl);
92  GLenum parseOutTypeCode(const std::string& str, const std::string& cpl);
93  void parseCode(void);
94 
95  public :
97  static std::string portNameForFragColor;
98 
100  std::map<int, LineInfo> linesInfo;
101 
102  ShaderSource(const std::string& src, const std::string& _sourceName="", int startLine=1, const std::map<int,LineInfo>& _linesInfo=std::map<int,LineInfo>());
103  ShaderSource(const ShaderSource& ss);
104  ~ShaderSource(void);
105 
106  ShaderSource& operator=(const ShaderSource& c);
107 
108  bool empty(void) const;
109  const std::string& getSource(void) const;
110  const std::string& getSourceName(void) const;
111  const char* getSourceCstr(void) const;
112  int getNumLines(void) const;
113  std::string getLine(int l, bool withNewLine=true) const;
114  LineInfo getLineInfo(int l) const;
115  Exception errorLog(const std::string& log) const;
116  bool requiresCompatibility(void) const;
117  int getVersion(void) const;
118 
119  const std::vector<std::string>& getInputVars(void) const;
120  const std::vector<std::string>& getOutputVars(void) const;
121  const std::vector<std::string>& getUniformVars(void) const;
122  const std::vector<GLenum>& getUniformTypes(void) const;
123  };
124  }
125  }
126 
127 #endif
Specific defines for the API structure.
Information about a specific line in ShaderSource.
Definition: ShaderSource.hpp:62
std::string sourceName
The name of the source (for example, the filename).
Definition: ShaderSource.hpp:67
static std::string portNameForFragColor
Name for the port mapping to gl_FragColor, if used.
Definition: ShaderSource.hpp:97
Definition: Component.hpp:32
std::map< int, LineInfo > linesInfo
Map containing information about specific lines of this source. The key represent the line number sta...
Definition: ShaderSource.hpp:100
Shader source code and infos.
Definition: ShaderSource.hpp:55
Exception class, derived from std::exception.
Definition: Exception.hpp:40
Exception class.
OpenGL includes and tools.
int lineNumber
The number of the line (including the offset).
Definition: ShaderSource.hpp:65