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 "ShMeta.hpp"
00042
00043
namespace SH {
00044
00045
class ShBackendCode;
00046
class ShBackend;
00047
00050 class
00051
SH_DLLEXPORT ShProgramNode :
public virtual ShRefCountable,
public virtual ShMeta {
00052
public:
00053 ShProgramNode(
const std::string& target);
00054
00055 ~ShProgramNode();
00056
00062
void compile(
const ShPointer<ShBackend>& backend);
00063
00066
void compile(
const std::string& target,
const ShPointer<ShBackend>& backend);
00067
00069 std::string describe_interface()
const;
00070
00074
ShPointer<ShBackendCode> code();
00075
00079
ShPointer<ShBackendCode> code(
const ShPointer<ShBackend>& backend);
00080
00082
ShPointer<ShBackendCode> code(
const std::string& target,
const ShPointer<ShBackend>& backend);
00083
00085
void updateUniform(
const ShVariableNodePtr& uniform);
00086
00089 ShTokenizer tokenizer;
00090
00094 ShPointer<ShCtrlGraph> ctrlGraph;
00095
00098
void collectVariables();
00099
00100
typedef std::list<ShVariableNodePtr> VarList;
00101
typedef std::list<ShTextureNodePtr> TexList;
00102
typedef std::list<ShChannelNodePtr> ChannelList;
00103
00104 VarList::const_iterator inputs_begin() const;
00105 VarList::const_iterator inputs_end() const;
00106 VarList::const_iterator outputs_begin() const;
00107 VarList::const_iterator outputs_end() const;
00108 VarList::const_iterator temps_begin() const;
00109 VarList::const_iterator temps_end() const;
00110 VarList::const_iterator constants_begin() const;
00111 VarList::const_iterator constants_end() const;
00112 VarList::const_iterator uniforms_begin() const;
00113 VarList::const_iterator uniforms_end() const;
00114
00115 TexList::const_iterator textures_begin() const;
00116 TexList::const_iterator textures_end() const;
00117
00118 ChannelList::const_iterator channels_begin() const;
00119 ChannelList::const_iterator channels_end() const;
00120
00121
00122 VarList inputs;
00123 VarList outputs;
00124 VarList temps;
00125 VarList constants;
00126 VarList uniforms;
00127 TexList textures;
00128 ChannelList channels;
00129
00131 std::string target()
const {
return m_target; }
00132
00134 std::string& target() {
return m_target; }
00135
00137
ShPointer<ShProgramNode> clone() const;
00138
00140 static std::ostream& print(std::ostream& out, const VarList& list);
00141
00143
bool finished() const;
00144
00146
void finish();
00147
00151
void assign(const
ShVariableNodePtr& var) const;
00152
00153 private:
00154
00155 std::string m_target;
00156
00157
void collectNodeVars(const
ShPointer<
ShCtrlGraphNode>& node);
00158
void collectVar(const
ShVariableNodePtr& node);
00159
00160 typedef std::map< std::pair< std::string,
ShPointer<ShBackend> >,
00161
ShPointer<ShBackendCode> > CodeMap;
00162 CodeMap m_code;
00163
00164
bool m_finished;
00165
00166
00167 mutable
ShVariableNodePtr m_assigned_var;
00168 };
00169
00170 typedef
ShPointer<ShProgramNode>
ShProgramNodePtr;
00171 typedef
ShPointer<const ShProgramNode>
ShProgramNodeCPtr;
00172
00173 }
00174
00175 #endif
00176