00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00027 #ifndef SHPROGRAMNODE_HPP
00028 #define SHPROGRAMNODE_HPP
00029
00030 #include <list>
00031 #include <map>
00032 #include <utility>
00033 #include <string>
00034 #include "ShDllExport.hpp"
00035 #include "ShRefCount.hpp"
00036 #include "ShTokenizer.hpp"
00037 #include "ShVariableNode.hpp"
00038 #include "ShCtrlGraph.hpp"
00039 #include "ShTextureNode.hpp"
00040 #include "ShChannelNode.hpp"
00041 #include "ShPaletteNode.hpp"
00042 #include "ShMeta.hpp"
00043
00044 namespace SH {
00045
00046 class ShBackendCode;
00047 class ShBackend;
00048
00051 class
00052 SH_DLLEXPORT ShProgramNode : public virtual ShRefCountable, public virtual ShMeta {
00053 public:
00054 ShProgramNode(const std::string& target);
00055
00056 ~ShProgramNode();
00057
00063 void compile(const ShPointer<ShBackend>& backend);
00064
00067 void compile(const std::string& target, const ShPointer<ShBackend>& backend);
00068
00070 std::string describe_interface() const;
00071
00075 ShPointer<ShBackendCode> code();
00076
00080 ShPointer<ShBackendCode> code(const ShPointer<ShBackend>& backend);
00081
00083 ShPointer<ShBackendCode> code(const std::string& target, const ShPointer<ShBackend>& backend);
00084
00086 void updateUniform(const ShVariableNodePtr& uniform);
00087
00090 ShTokenizer tokenizer;
00091
00095 ShPointer<ShCtrlGraph> ctrlGraph;
00096
00099 void collectVariables();
00100
00101 typedef std::list<ShVariableNodePtr> VarList;
00102 typedef std::list<ShTextureNodePtr> TexList;
00103 typedef std::list<ShChannelNodePtr> ChannelList;
00104 typedef std::list<ShPaletteNodePtr> PaletteList;
00105
00106 VarList::const_iterator inputs_begin() const;
00107 VarList::const_iterator inputs_end() const;
00108 VarList::const_iterator outputs_begin() const;
00109 VarList::const_iterator outputs_end() const;
00110 VarList::const_iterator temps_begin() const;
00111 VarList::const_iterator temps_end() const;
00112 VarList::const_iterator constants_begin() const;
00113 VarList::const_iterator constants_end() const;
00114 VarList::const_iterator uniforms_begin() const;
00115 VarList::const_iterator uniforms_end() const;
00116
00117 TexList::const_iterator textures_begin() const;
00118 TexList::const_iterator textures_end() const;
00119
00120 ChannelList::const_iterator channels_begin() const;
00121 ChannelList::const_iterator channels_end() const;
00122
00123 PaletteList::const_iterator palettes_begin() const;
00124 PaletteList::const_iterator palettes_end() const;
00125
00126
00127 VarList inputs;
00128 VarList outputs;
00129 VarList temps;
00130 VarList constants;
00131 VarList uniforms;
00132 TexList textures;
00133 ChannelList channels;
00134 PaletteList palettes;
00135
00137 std::string target() const { return m_target; }
00138
00140 std::string& target() { return m_target; }
00141
00143 ShPointer<ShProgramNode> clone() const;
00144
00146 static std::ostream& print(std::ostream& out, const VarList& list);
00147
00149 bool finished() const;
00150
00152 void finish();
00153
00157 void assign(const ShVariableNodePtr& var) const;
00158
00159 private:
00160
00161 std::string m_target;
00162
00163 void collectNodeVars(const ShPointer<ShCtrlGraphNode>& node);
00164 void collectVar(const ShVariableNodePtr& node);
00165
00166 typedef std::map< std::pair< std::string, ShPointer<ShBackend> >,
00167 ShPointer<ShBackendCode> > CodeMap;
00168 CodeMap m_code;
00169
00170 bool m_finished;
00171
00172
00173 mutable ShVariableNodePtr m_assigned_var;
00174 };
00175
00176 typedef ShPointer<ShProgramNode> ShProgramNodePtr;
00177 typedef ShPointer<const ShProgramNode> ShProgramNodeCPtr;
00178
00179 }
00180
00181 #endif
00182