00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00024 #ifndef SHPROGRAMNODE_HPP
00025 #define SHPROGRAMNODE_HPP
00026
00027 #include <list>
00028 #include <map>
00029 #include <utility>
00030 #include <string>
00031 #include "ShDllExport.hpp"
00032 #include "ShRefCount.hpp"
00033 #include "ShTokenizer.hpp"
00034 #include "ShVariableNode.hpp"
00035 #include "ShCtrlGraph.hpp"
00036 #include "ShTextureNode.hpp"
00037 #include "ShChannelNode.hpp"
00038 #include "ShPaletteNode.hpp"
00039 #include "ShMeta.hpp"
00040
00041 namespace SH {
00042
00043 class ShBackendCode;
00044 class ShBackend;
00045
00048 class
00049 SH_DLLEXPORT ShProgramNode : public virtual ShRefCountable, public virtual ShMeta, public virtual ShInfoHolder {
00050 public:
00051 ShProgramNode(const std::string& target);
00052
00053 ~ShProgramNode();
00054
00060 void compile(const ShPointer<ShBackend>& backend);
00061
00064 void compile(const std::string& target, const ShPointer<ShBackend>& backend);
00065
00067 std::string describe_interface() const;
00068
00070 std::string describe_vars() const;
00071
00073 std::string describe_decls() const;
00074
00077 void dump(std::string filename) const;
00078
00082 ShPointer<ShBackendCode> code();
00083
00087 ShPointer<ShBackendCode> code(const ShPointer<ShBackend>& backend);
00088
00090 ShPointer<ShBackendCode> code(const std::string& target, const ShPointer<ShBackend>& backend);
00091
00093 void updateUniform(const ShVariableNodePtr& uniform);
00094
00097 ShTokenizer tokenizer;
00098
00102 ShPointer<ShCtrlGraph> ctrlGraph;
00103
00105 void collectDecls();
00106
00108 void collectVariables();
00109
00111 bool hasDecl(ShVariableNodePtr node) const;
00112
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123 void addDecl(ShVariableNodePtr node, ShCtrlGraphNodePtr);
00124 void addDecl(ShVariableNodePtr node);
00126
00127 typedef std::set<ShVariableNodePtr> VarSet;
00128 typedef std::list<ShVariableNodePtr> VarList;
00129 typedef std::list<ShTextureNodePtr> TexList;
00130 typedef std::list<ShChannelNodePtr> ChannelList;
00131 typedef std::list<ShPaletteNodePtr> PaletteList;
00132
00133 VarList::const_iterator inputs_begin() const;
00134 VarList::const_iterator inputs_end() const;
00135 VarList::const_iterator outputs_begin() const;
00136 VarList::const_iterator outputs_end() const;
00137 VarList::const_iterator temps_begin() const;
00138 VarList::const_iterator temps_end() const;
00139 VarList::const_iterator constants_begin() const;
00140 VarList::const_iterator constants_end() const;
00141 VarList::const_iterator uniforms_begin() const;
00142 VarList::const_iterator uniforms_end() const;
00143
00144 TexList::const_iterator textures_begin() const;
00145 TexList::const_iterator textures_end() const;
00146
00147 ChannelList::const_iterator channels_begin() const;
00148 ChannelList::const_iterator channels_end() const;
00149
00150 PaletteList::const_iterator palettes_begin() const;
00151 PaletteList::const_iterator palettes_end() const;
00152
00153
00154 VarList inputs;
00155 VarList outputs;
00156 VarList temps;
00157 VarSet tempDecls;
00158 VarList constants;
00159 VarList uniforms;
00160 TexList textures;
00161 ChannelList channels;
00162 PaletteList palettes;
00163
00165 std::string target() const { return m_target; }
00166
00168 std::string& target() { return m_target; }
00169
00171 ShPointer<ShProgramNode> clone() const;
00172
00174 static std::ostream& print(std::ostream& out, const VarList& list);
00175
00177 bool finished() const;
00178
00180 void finish();
00181
00185 void assign(const ShVariableNodePtr& var) const;
00186
00187 private:
00188 static std::string describe(const VarList &varlist);
00189 static std::string describe(const ChannelList &chanlist);
00190
00191 std::string m_target;
00192
00193 void collectNodeDecls(const ShPointer<ShCtrlGraphNode>& node);
00194
00195 void collectNodeVars(const ShPointer<ShCtrlGraphNode>& node);
00196 void collectVar(const ShVariableNodePtr& node);
00197
00198 typedef std::map< std::pair< std::string, ShPointer<ShBackend> >,
00199 ShPointer<ShBackendCode> > CodeMap;
00200 CodeMap m_code;
00201
00202 bool m_finished;
00203
00204
00205 mutable ShVariableNodePtr m_assigned_var;
00206 };
00207
00208 typedef ShPointer<ShProgramNode> ShProgramNodePtr;
00209 typedef ShPointer<const ShProgramNode> ShProgramNodeCPtr;
00210
00211 }
00212
00213 #endif
00214