00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00024 #ifndef SHBACKEND_HPP
00025 #define SHBACKEND_HPP
00026
00027 #include <vector>
00028 #include <iosfwd>
00029 #include <string>
00030 #include "ShDllExport.hpp"
00031 #include "ShRefCount.hpp"
00032 #include "ShProgram.hpp"
00033 #include "ShProgramSet.hpp"
00034 #include "ShVariableNode.hpp"
00035
00036 namespace SH {
00037
00038 class ShStream;
00039
00040 class
00041 SH_DLLEXPORT ShBackendCode : public ShRefCountable {
00042 public:
00043 virtual ~ShBackendCode();
00044
00047 virtual bool allocateRegister(const ShVariableNodePtr& var) = 0;
00048
00052 virtual void freeRegister(const ShVariableNodePtr& var) = 0;
00053
00055 virtual void upload() = 0;
00056
00058 virtual void bind() = 0;
00059
00061 virtual void unbind() = 0;
00062
00064 virtual void update() = 0;
00065
00067 virtual void updateUniform(const ShVariableNodePtr& uniform) = 0;
00068
00069 virtual std::ostream& print(std::ostream& out) = 0;
00070
00072
00073
00074 virtual std::ostream& describe_interface(std::ostream& out) = 0;
00075 };
00076
00077 typedef ShPointer<ShBackendCode> ShBackendCodePtr;
00078 typedef ShPointer<const ShBackendCode> ShBackendCodeCPtr;
00079
00080
00081 class
00082 SH_DLLEXPORT ShBackendSet : public ShRefCountable {
00083 public:
00084 virtual ~ShBackendSet();
00085
00086 virtual void link() = 0;
00087
00088 virtual void bind() = 0;
00089 virtual void unbind() = 0;
00090 };
00091
00092 typedef ShPointer<ShBackendSet> ShBackendSetPtr;
00093 typedef ShPointer<const ShBackendSet> ShBackendSetCPtr;
00094
00095 class ShTransformer;
00096 class
00097 SH_DLLEXPORT ShBackend : public ShRefCountable {
00098 public:
00099 virtual ~ShBackend();
00100 virtual std::string name() const = 0;
00101
00105 virtual ShBackendCodePtr generate_code(const std::string& target,
00106 const ShProgramNodeCPtr& shader) = 0;
00107
00108 virtual ShBackendSetPtr generate_set(const ShProgramSet& s);
00109
00110
00111 virtual void execute(const ShProgramNodeCPtr& program, ShStream& dest) = 0;
00112
00113
00114 virtual void unbind_all();
00115
00116 typedef std::vector< ShPointer<ShBackend> > ShBackendList;
00117
00118 static ShBackendList::iterator begin();
00119 static ShBackendList::iterator end();
00120
00121 static ShPointer<ShBackend> lookup(const std::string& name);
00122
00123 protected:
00124 ShBackend();
00125
00126 private:
00127 static void init();
00128
00129 static ShBackendList* m_backends;
00130 static bool m_doneInit;
00131 };
00132
00133 typedef ShPointer<ShBackend> ShBackendPtr;
00134 typedef ShPointer<const ShBackend> ShBackendCPtr;
00135
00136 }
00137
00138 #endif