Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

ShProgram.hpp

00001 // Sh: A GPU metaprogramming language.
00002 //
00003 // Copyright 2003-2005 Serious Hack Inc.
00004 // 
00005 // This library is free software; you can redistribute it and/or
00006 // modify it under the terms of the GNU Lesser General Public
00007 // License as published by the Free Software Foundation; either
00008 // version 2.1 of the License, or (at your option) any later version.
00009 //
00010 // This library is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 // Lesser General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU Lesser General Public
00016 // License along with this library; if not, write to the Free Software
00017 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
00018 // MA  02110-1301, USA
00020 #ifndef SHPROGRAM_HPP
00021 #define SHPROGRAM_HPP
00022 
00023 #include "ShDllExport.hpp"
00024 #include "ShProgramNode.hpp"
00025 #include "ShBackend.hpp"
00026 
00027 namespace SH {
00028 
00029 class ShStream;
00030 template<typename T> class ShChannel;
00031 class ShRecord;
00032 
00035 class
00036 SH_DLLEXPORT ShProgram : public ShMetaForwarder {
00037 public:
00038   ShProgram();
00039   ShProgram(const ShProgram& other);
00040   ShProgram(const std::string& target);
00041   ShProgram(const ShProgramNodePtr& node);
00042 
00043   ShProgram& operator=(const ShProgram& other);
00044   
00046   ShProgramNodeCPtr node() const { return m_node; }
00047 
00049   ShProgramNodePtr node() { return m_node; }
00050   
00055   void compile(const ShPointer<ShBackend>& backend) { m_node->compile(backend); }
00056 
00060   void compile(const std::string& target, const ShPointer<ShBackend>& backend)
00061   {
00062     m_node->compile(target, backend);
00063   }
00064 
00068   bool is_compiled() const { return m_node->is_compiled(); }
00069 
00072   bool is_compiled(const std::string& target) const
00073   { 
00074     return m_node->is_compiled(target);
00075   }
00076 
00079   std::string describe_interface() const
00080   {
00081     return m_node->describe_interface();
00082   }
00083   
00087   ShPointer<ShBackendCode> code() { return m_node->code(); }
00088   
00092   ShPointer<ShBackendCode> code(const ShPointer<ShBackend>& backend) {
00093     return m_node->code(backend);
00094   }
00095 
00097   ShPointer<ShBackendCode> code(const std::string& target, const ShPointer<ShBackend>& backend)
00098   {
00099     return m_node->code(target, backend);
00100   }
00101 
00103   void updateUniform(const ShVariableNodePtr& uniform)
00104   {
00105     m_node->updateUniform(uniform);
00106   }
00107 
00108   std::string target() const { return m_node->target(); }
00109 
00111   std::string& target() { return m_node->target(); }
00112 
00113   ShProgramNode::VarList::const_iterator inputs_begin() const { return m_node->inputs_begin(); }
00114   ShProgramNode::VarList::const_iterator inputs_end() const { return m_node->inputs_end(); }
00115   ShProgramNode::VarList::const_iterator outputs_begin() const { return m_node->outputs_begin(); }
00116   ShProgramNode::VarList::const_iterator outputs_end() const { return m_node->outputs_end(); }
00117   ShProgramNode::VarList::const_iterator temps_begin() const { return m_node->temps_begin(); }
00118   ShProgramNode::VarList::const_iterator temps_end() const { return m_node->temps_end(); }
00119   ShProgramNode::VarList::const_iterator constants_begin() const { return m_node->constants_begin(); }
00120   ShProgramNode::VarList::const_iterator constants_end() const { return m_node->constants_end(); }
00121   ShProgramNode::VarList::const_iterator uniforms_begin() const { return m_node->uniforms_begin(); }
00122   ShProgramNode::VarList::const_iterator uniforms_end() const { return m_node->uniforms_end(); }
00123   ShProgramNode::TexList::const_iterator textures_begin() const { return m_node->textures_begin(); }
00124   ShProgramNode::TexList::const_iterator textures_end() const { return m_node->textures_end(); }
00125   ShProgramNode::ChannelList::const_iterator channels_begin() const { return m_node->channels_begin(); }
00126   ShProgramNode::ChannelList::const_iterator channels_end() const { return m_node->channels_end(); }
00127   ShProgramNode::PaletteList::const_iterator palettes_begin() const { return m_node->palettes_begin(); }
00128   ShProgramNode::PaletteList::const_iterator palettes_end() const { return m_node->palettes_end(); }
00129 
00130   // Call operators for channels and streams.
00131   // Equivalent to operator<< invocations.
00132   // Note that the template functions are implemented in
00133   // ShChannelImpl.hpp
00134   template<typename T0>
00135   ShProgram operator()(const ShChannel<T0>& t0) const;
00136   ShProgram operator()(const ShStream& s0) const;
00137   template<typename T0, typename T1>
00138   ShProgram operator()(const ShChannel<T0>& t0,
00139                         const ShChannel<T1>& t1) const;
00140   ShProgram operator()(const ShStream& s0,
00141                         const ShStream& s1) const;
00142   template<typename T0, typename T1, typename T2>
00143   ShProgram operator()(const ShChannel<T0>& t0,
00144                         const ShChannel<T1>& t1,
00145                         const ShChannel<T2>& t2) const;
00146   ShProgram operator()(const ShStream& s0,
00147                         const ShStream& s1,
00148                         const ShStream& s2) const;
00149   template<typename T0, typename T1, typename T2, typename T3>
00150   ShProgram operator()(const ShChannel<T0>& t0,
00151                         const ShChannel<T1>& t1,
00152                         const ShChannel<T2>& t2,
00153                         const ShChannel<T3>& t3) const;
00154   ShProgram operator()(const ShStream& s0,
00155                         const ShStream& s1,
00156                         const ShStream& s2,
00157                         const ShStream& s3) const;
00158   template<typename T0, typename T1, typename T2, typename T3,
00159            typename T4>
00160   ShProgram operator()(const ShChannel<T0>& t0,
00161                         const ShChannel<T1>& t1,
00162                         const ShChannel<T2>& t2,
00163                         const ShChannel<T3>& t3,
00164                         const ShChannel<T4>& t4) const;
00165   ShProgram operator()(const ShStream& s0,
00166                         const ShStream& s1,
00167                         const ShStream& s2,
00168                         const ShStream& s3,
00169                         const ShStream& s4) const;
00170   
00171   // Call operators for records
00172   // May want to merge these with above in the long term. 
00173   ShProgram operator()(const ShRecord &rec) const;
00174   ShProgram operator()(const ShVariable &v0) const;
00175   ShProgram operator()(const ShVariable &v0, 
00176                        const ShVariable &v1) const;
00177   ShProgram operator()(const ShVariable &v0, 
00178                        const ShVariable &v1, 
00179                        const ShVariable &v2) const;
00180   ShProgram operator()(const ShVariable &v0, 
00181                        const ShVariable &v1, 
00182                        const ShVariable &v2, 
00183                        const ShVariable &v3) const;
00184   
00185 private:
00186 
00187   ShProgramNodePtr m_node;
00188 };
00189 
00190 }
00191 
00192 #endif
00193 

Generated on Thu Jul 28 17:33:05 2005 for Sh by  doxygen 1.4.3-20050530