Vuo  2.0.0
VuoShaderFile.hh
Go to the documentation of this file.
1 
10 #pragma once
11 
12 #include <vector>
13 
14 #include "VuoFileUtilities.hh"
15 
16 typedef struct _VuoShader *VuoShader;
17 class VuoShaderIssues;
19 
30 {
31 public:
32 
36  enum Type
37  {
38  GLSLImageFilter,
39  GLSLImageGenerator,
40  GLSLImageTransition,
41  GLSLObjectRenderer,
42  GLSLObjectFilter,
43  };
44 
48  enum Stage
49  {
50  Vertex,
51  Geometry,
52  Fragment,
53 
54  Program,
55  };
56 
60  struct Port
61  {
62  string key;
63  string vuoTypeName;
64  json_object *vuoPortDetails;
65  };
66 
68  VuoShaderFile(VuoFileUtilities::File file, const string &overriddenFragmentSource="");
69 
71  static string stageName(Stage stage);
72  void dump();
73 
74  string name();
75 
76  Type type();
77  string typeName();
78  string typeNameISF();
79 
80 // bool typeAllowsVertexShader(); // All types allow a Vertex Shader.
83 
84  static set<string> supportedVuoTypes();
85 
88 
91 
92  vector<Port> inputPorts();
93  void setInputPorts(vector<Port> ports);
94  bool showsTime();
95 
96  Port outputPort();
97 
98  string &vertexSource();
99  void setVertexSource(const string &source);
100  string expandedVertexSource();
101 
102  string &geometrySource();
103  void setGeometrySource(const string &source);
104  string expandedGeometrySource();
105 
106  string &fragmentSource();
107  void setFragmentSource(const string &source);
108  string expandedFragmentSource();
109 
110  void save(string filePath);
111  string fragmentFileContents();
112 
113 private:
114  void init(VuoFileUtilities::File file, const string &overriddenFragmentSource="");
115  string readStage(VuoFileUtilities::File path);
116  void splitMetadataAndSource(string inputString, json_object **outputMetadata, string &outputSourceString);
117  void parseMetadata(json_object *metadata);
118  string vuoTypeForIsfType(string isfType);
119  string isfTypeForVuoType(string vuoType);
120  string glslDeclarationForPort(Port port);
121  void saveStage(string filePath, string &source, json_object *vuoModuleMetadata=NULL);
122  string stageFileContents(string &source, json_object *vuoModuleMetadata=NULL);
123  string spacesToTabs(string &str);
124  void insertPreamble(ostringstream &oss, bool isFragment);
125 
126  json_object *_vuoModuleMetadata;
127 
128  string basename;
129  string extension;
130 
131  Type _type;
132 
133  vector<Port> _inputPorts;
134  string outputKey;
135  string outputName;
136 
137  string _vertexSource;
138  string _geometrySource;
139  string _fragmentSource;
140 
141  string isfVersion;
142  string shaderVersion;
143  string _name;
144  string copyright;
145  string license;
146  string description;
147  string homepageLink;
148  string documentationLink;
149  vector<string> categories;
150  vector<string> keywords;
151  vector<string> examples;
152  bool _showsTime;
153 };