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

UberStorage.hpp

00001 // Sh: A GPU metaprogramming language. 00002 // 00003 // Copyright (c) 2003 University of Waterloo Computer Graphics Laboratory 00004 // Project administrator: Michael D. McCool 00005 // Authors: Zheng Qin, Stefanus Du Toit, Kevin Moule, Tiberiu S. Popa, 00006 // Michael D. McCool 00007 // 00008 // This software is provided 'as-is', without any express or implied 00009 // warranty. In no event will the authors be held liable for any damages 00010 // arising from the use of this software. 00011 // 00012 // Permission is granted to anyone to use this software for any purpose, 00013 // including commercial applications, and to alter it and redistribute it 00014 // freely, subject to the following restrictions: 00015 // 00016 // 1. The origin of this software must not be misrepresented; you must 00017 // not claim that you wrote the original software. If you use this 00018 // software in a product, an acknowledgment in the product documentation 00019 // would be appreciated but is not required. 00020 // 00021 // 2. Altered source versions must be plainly marked as such, and must 00022 // not be misrepresented as being the original software. 00023 // 00024 // 3. This notice may not be removed or altered from any source 00025 // distribution. 00027 #ifndef SHUBERSTORAGE_HPP 00028 #define SHUBERSTORAGE_HPP 00029 00030 #include "GlBackend.hpp" 00031 #include "ShRefCount.hpp" 00032 #include "ShMemory.hpp" 00033 #include "GlTextureName.hpp" 00034 00035 namespace shgl { 00036 00037 class HostUberTransfer; 00038 class UberStorage : public SH::ShStorage { 00039 public: 00040 UberStorage(int context, 00041 SH::ShMemory* memory, const GlTextureNamePtr& name, 00042 int width, int height, int pitch); 00043 ~UberStorage(); 00044 00045 void bindAsTexture(); 00046 void bindAsAux(unsigned int n); 00047 void unbind(); 00048 00049 enum Binding { 00050 SH_UBER_UNBOUND, 00051 SH_UBER_TEXTURE, 00052 SH_UBER_AUX 00053 }; 00054 00055 Binding binding() const; 00056 GlTextureNamePtr textureName() const; 00057 int auxTarget() const; // returns -1 if binding != aux 00058 00059 int width() const { return m_width; } 00060 int height() const { return m_height; } 00061 int pitch() const { return m_pitch; } 00062 int context() const { return m_context; } 00063 unsigned int mem() const { return m_mem; } 00064 00065 std::string id() const { return "uberbuffer"; } 00066 00067 // we need a dummy framebuffer object 00068 static int temp_fb[4]; 00069 static int allocfb(int, bool bForce = false); 00070 00071 void clearBuffer(float* col); 00072 00073 private: 00074 00075 static bool m_firstTime; 00076 00078 unsigned int alloc(int bForce=0); 00079 unsigned int remove(); 00080 00081 int m_context; 00082 00083 int m_width, m_height, m_pitch; 00084 00085 // the uber buffer 00086 unsigned int m_mem; 00087 00088 Binding m_binding; 00089 00090 GlTextureNamePtr m_textureName; 00091 int m_auxTarget; // m_binding == SH_UBER_AUX 00092 00093 friend class HostUberTransfer; 00094 friend class UberUberTransfer; 00095 }; 00096 00097 typedef SH::ShPointer<UberStorage> UberStoragePtr; 00098 00099 class UberUberTransfer : public SH::ShTransfer { 00100 public: 00101 bool transfer(const SH::ShStorage* from, SH::ShStorage* to); 00102 00103 int cost() 00104 { 00105 return 10; 00106 } 00107 00108 private: 00109 UberUberTransfer() 00110 : ShTransfer("uberbuffer", "uberbuffer") 00111 { 00112 } 00113 00114 static UberUberTransfer* instance; 00115 }; 00116 00117 00118 class UberHostTransfer : public SH::ShTransfer { 00119 public: 00120 bool transfer(const SH::ShStorage* from, SH::ShStorage* to); 00121 int cost() 00122 { 00123 return 100; 00124 } 00125 00126 private: 00127 UberHostTransfer() 00128 : ShTransfer("uberbuffer", "host") 00129 { 00130 } 00131 00132 static UberHostTransfer* instance; 00133 }; 00134 00135 00136 class HostUberTransfer : public SH::ShTransfer { 00137 public: 00138 bool transfer(const SH::ShStorage* from, SH::ShStorage* to); 00139 int cost() 00140 { 00141 return 100; 00142 } 00143 00144 private: 00145 HostUberTransfer() 00146 : ShTransfer("host", "uberbuffer") 00147 { 00148 } 00149 00150 static HostUberTransfer* instance; 00151 }; 00152 00153 } 00154 00155 #endif

Generated on Mon Oct 18 14:17:40 2004 for Sh by doxygen 1.3.7