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

ShBaseTextureImpl.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 SHBASETEXTUREIMPL_HPP
00028 #define SHBASETEXTUREIMPL_HPP
00029 
00030 #include "ShBaseTexture.hpp"
00031 #include "ShContext.hpp"
00032 #include "ShError.hpp"
00033 #include "ShLibMisc.hpp"
00034 
00035 namespace SH {
00036 
00037 template<typename T>
00038 ShBaseTexture1D<T>::ShBaseTexture1D(int width, const ShTextureTraits& traits)
00039   : ShBaseTexture(new ShTextureNode(SH_TEXTURE_1D, T::typesize, T::value_type, traits, width))
00040 {
00041 }
00042 
00043 template<typename T>
00044 ShBaseTexture2D<T>::ShBaseTexture2D(int width, int height, const ShTextureTraits& traits)
00045   : ShBaseTexture(new ShTextureNode(SH_TEXTURE_2D, T::typesize, T::value_type, traits, width, height))
00046 {
00047 }
00048 
00049 template<typename T>
00050 ShBaseTextureRect<T>::ShBaseTextureRect(int width, int height, const ShTextureTraits& traits)
00051   : ShBaseTexture(new ShTextureNode(SH_TEXTURE_RECT, T::typesize, T::value_type, traits, width, height))
00052 {
00053 }
00054 
00055 template<typename T>
00056 ShBaseTexture3D<T>::ShBaseTexture3D(int width, int height, int depth, const ShTextureTraits& traits)
00057   : ShBaseTexture(new ShTextureNode(SH_TEXTURE_3D, T::typesize, T::value_type, traits, width, height, depth))
00058 {
00059 }
00060 
00061 template<typename T>
00062 ShBaseTextureCube<T>::ShBaseTextureCube(int width, int height, const ShTextureTraits& traits)
00063   : ShBaseTexture(new ShTextureNode(SH_TEXTURE_CUBE, T::typesize, T::value_type, traits, width, height))
00064 {
00065 }
00066 
00067 template<typename T>
00068 ShBaseTexture1D<T>::ShBaseTexture1D(const ShTextureTraits& traits)
00069   : ShBaseTexture(new ShTextureNode(SH_TEXTURE_1D, T::typesize, T::value_type, traits, 0))
00070 {
00071 }
00072 
00073 template<typename T>
00074 ShBaseTexture2D<T>::ShBaseTexture2D(const ShTextureTraits& traits)
00075   : ShBaseTexture(new ShTextureNode(SH_TEXTURE_2D, T::typesize, T::value_type, traits, 0, 0))
00076 {
00077 }
00078 
00079 template<typename T>
00080 ShBaseTextureRect<T>::ShBaseTextureRect(const ShTextureTraits& traits)
00081   : ShBaseTexture(new ShTextureNode(SH_TEXTURE_RECT, T::typesize, T::value_type, traits, 0, 0))
00082 {
00083 }
00084 
00085 template<typename T>
00086 ShBaseTexture3D<T>::ShBaseTexture3D(const ShTextureTraits& traits)
00087   : ShBaseTexture(new ShTextureNode(SH_TEXTURE_3D, T::typesize, T::value_type, traits, 0, 0, 0))
00088 {
00089 }
00090 
00091 template<typename T>
00092 ShBaseTextureCube<T>::ShBaseTextureCube(const ShTextureTraits& traits)
00093   : ShBaseTexture(new ShTextureNode(SH_TEXTURE_CUBE, T::typesize, T::value_type, traits, 0, 0))
00094 {
00095 }
00096 
00097 template<typename T>
00098 template<typename T2>
00099 T ShBaseTexture1D<T>::operator()(const ShGeneric<1, T2>& coords) const
00100 {
00101   if (ShContext::current()->parsing()) {
00102     T t;
00103     ShVariable texVar(m_node);
00104     ShStatement stmt(t, texVar, SH_OP_TEX, coords);
00105     ShContext::current()->parsing()->tokenizer.blockList()->addStatement(stmt);
00106     return t;
00107   } else {
00108     // TODO!
00109     T t;
00110     return t;
00111   }
00112 }
00113 
00114 template<typename T>
00115 template<typename T2>
00116 T ShBaseTexture2D<T>::operator()(const ShGeneric<2, T2>& coords) const
00117 {
00118   if (ShContext::current()->parsing()) {
00119     T t;
00120     ShVariable texVar(m_node);
00121     ShStatement stmt(t, texVar, SH_OP_TEX, coords);
00122     ShContext::current()->parsing()->tokenizer.blockList()->addStatement(stmt);
00123     return t;
00124   } else {
00125     // TODO!
00126     T t;
00127     return t;
00128   }
00129 }
00130 
00131 template<typename T>
00132 template<typename T2, typename T3, typename T4>
00133 T ShBaseTexture2D<T>::operator()(const ShGeneric<2, T2>& coords,
00134                                  const ShGeneric<2, T3>& dx,
00135                                  const ShGeneric<2, T4>& dy) const
00136 {
00137   if (ShContext::current()->parsing()) {
00138     T t;
00139     ShVariable texVar(m_node);
00140     ShStatement stmt(t, SH_OP_TEXD, texVar, coords, join(dx, dy));
00141     ShContext::current()->parsing()->tokenizer.blockList()->addStatement(stmt);
00142     return t;
00143   } else {
00144     shError(ShScopeException("Cannot do derivative texture lookup in immediate mode"));
00145     T t; return t;
00146   }
00147 }
00148 
00149 template<typename T>
00150 template<typename T2>
00151 T ShBaseTextureRect<T>::operator()(const ShGeneric<2, T2>& coords) const
00152 {
00153   if (ShContext::current()->parsing()) {
00154     T t;
00155     ShVariable texVar(m_node);
00156     ShStatement stmt(t, texVar, SH_OP_TEX, coords);
00157     ShContext::current()->parsing()->tokenizer.blockList()->addStatement(stmt);
00158     return t;
00159   } else {
00160     // TODO!
00161     T t;
00162     return t;
00163   }
00164 }
00165 
00166 template<typename T>
00167 template<typename T2>
00168 T ShBaseTexture3D<T>::operator()(const ShGeneric<3, T2>& coords) const
00169 {
00170   if (ShContext::current()->parsing()) {
00171     T t;
00172     ShVariable texVar(m_node);
00173     ShStatement stmt(t, texVar, SH_OP_TEX, coords);
00174     ShContext::current()->parsing()->tokenizer.blockList()->addStatement(stmt);
00175     return t;
00176   } else {
00177     // TODO!
00178     T t;
00179     return t;
00180   }
00181 } 
00182 
00183 template<typename T>
00184 template<typename T2>
00185 T ShBaseTextureCube<T>::operator()(const ShGeneric<3, T2>& coords) const
00186 {
00187   if (ShContext::current()->parsing()) {
00188     T t;
00189     ShVariable texVar(m_node);
00190     ShStatement stmt(t, texVar, SH_OP_TEX, coords);
00191     ShContext::current()->parsing()->tokenizer.blockList()->addStatement(stmt);
00192     return t;
00193   } else {
00194     // TODO!
00195     T t;
00196     return t;
00197   }
00198 } 
00199 
00200 template<typename T>
00201 template<typename T2>
00202 T ShBaseTexture1D<T>::operator[](const ShGeneric<1, T2>& coords) const
00203 {
00204   if (ShContext::current()->parsing()) {
00205     T t;
00206     ShVariable texVar(m_node);
00207     ShStatement stmt(t, texVar, SH_OP_TEXI, coords);
00208     ShContext::current()->parsing()->tokenizer.blockList()->addStatement(stmt);
00209     return t;
00210   } else {
00211     // TODO!
00212     T t;
00213     return t;
00214   }
00215 }
00216 
00217 template<typename T>
00218 template<typename T2>
00219 T ShBaseTexture2D<T>::operator[](const ShGeneric<2, T2>& coords) const
00220 {
00221   if (ShContext::current()->parsing()) {
00222     T t;
00223     ShVariable texVar(m_node);
00224     ShStatement stmt(t, texVar, SH_OP_TEXI, coords);
00225     ShContext::current()->parsing()->tokenizer.blockList()->addStatement(stmt);
00226     return t;
00227   } else {
00228     // TODO!
00229     T t;
00230     return t;
00231   }
00232 }
00233 
00234 template<typename T>
00235 template<typename T2>
00236 T ShBaseTextureRect<T>::operator[](const ShGeneric<2, T2>& coords) const
00237 {
00238   if (ShContext::current()->parsing()) {
00239     T t;
00240     ShVariable texVar(m_node);
00241     ShStatement stmt(t, texVar, SH_OP_TEXI, coords);
00242     ShContext::current()->parsing()->tokenizer.blockList()->addStatement(stmt);
00243     return t;
00244   } else {
00245     // TODO!
00246     T t;
00247     return t;
00248   }
00249 }
00250 
00251 template<typename T>
00252 template<typename T2>
00253 T ShBaseTexture3D<T>::operator[](const ShGeneric<3, T2>& coords) const
00254 {
00255   if (ShContext::current()->parsing()) {
00256     T t;
00257     ShVariable texVar(m_node);
00258     ShStatement stmt(t, texVar, SH_OP_TEXI, coords);
00259     ShContext::current()->parsing()->tokenizer.blockList()->addStatement(stmt);
00260     return t;
00261   } else {
00262     // TODO!
00263     T t;
00264     return t;
00265   }
00266 }
00267 
00268 // setMemory
00269 
00270 template<typename T>
00271 void ShBaseTexture1D<T>::memory(ShMemoryPtr memory)
00272 {
00273   m_node->memory(memory);
00274 }
00275 
00276 template<typename T>
00277 void ShBaseTexture2D<T>::memory(ShMemoryPtr memory)
00278 {
00279   m_node->memory(memory);
00280 }
00281 
00282 template<typename T>
00283 void ShBaseTextureRect<T>::memory(ShMemoryPtr memory)
00284 {
00285   m_node->memory(memory);
00286 }
00287 
00288 template<typename T>
00289 void ShBaseTexture3D<T>::memory(ShMemoryPtr memory)
00290 {
00291   m_node->memory(memory);
00292 }
00293 
00294 template<typename T>
00295 void ShBaseTextureCube<T>::memory(ShMemoryPtr memory,
00296                                   ShCubeDirection face)
00297 {
00298   m_node->memory(memory, face);
00299 }
00300 
00301 // get memory
00302 
00303 template<typename T>
00304 ShMemoryPtr ShBaseTexture1D<T>::memory()
00305 {
00306   return m_node->memory();
00307 }
00308 
00309 template<typename T>
00310 ShMemoryPtr ShBaseTexture2D<T>::memory()
00311 {
00312   return m_node->memory();
00313 }
00314 
00315 template<typename T>
00316 ShMemoryPtr ShBaseTextureRect<T>::memory()
00317 {
00318   return m_node->memory();
00319 }
00320 
00321 template<typename T>
00322 ShMemoryPtr ShBaseTexture3D<T>::memory()
00323 {
00324   return m_node->memory();
00325 }
00326 
00327 template<typename T>
00328 ShMemoryPtr ShBaseTextureCube<T>::memory(ShCubeDirection face)
00329 {
00330   return m_node->memory(face);
00331 }
00332 
00333 // get size
00334 
00335 template<typename T>
00336 ShAttrib1f ShBaseTexture1D<T>::size() const
00337 {
00338   ShAttrib1f t(m_node->texSizeVar().node(), ShSwizzle(m_node->texSizeVar().size()), false);
00339   return t;
00340 }
00341 
00342 template<typename T>
00343 ShAttrib2f ShBaseTexture2D<T>::size() const
00344 {
00345   ShAttrib2f t(m_node->texSizeVar().node(), ShSwizzle(m_node->texSizeVar().size()), false);
00346   return t;
00347 }
00348 
00349 template<typename T>
00350 ShAttrib2f ShBaseTextureRect<T>::size() const
00351 {
00352   ShAttrib2f t(m_node->texSizeVar().node(), ShSwizzle(m_node->texSizeVar().size()), false);
00353   return t;
00354 }
00355 
00356 template<typename T>
00357 ShAttrib3f ShBaseTexture3D<T>::size() const
00358 {
00359   ShAttrib3f t(m_node->texSizeVar().node(), ShSwizzle(m_node->texSizeVar().size()), false);
00360   return t;
00361 }
00362 
00363 template<typename T>
00364 ShAttrib2f ShBaseTextureCube<T>::size() const
00365 {
00366   ShAttrib2f t(m_node->texSizeVar().node(), ShSwizzle(m_node->texSizeVar().size()), false);
00367   return t;
00368 }
00369 
00370 // set size
00371 
00372 template<typename T>
00373 void ShBaseTexture1D<T>::size(int width)
00374 {
00375   m_node->setTexSize(width);
00376 }
00377 
00378 template<typename T>
00379 void ShBaseTexture2D<T>::size(int width, int height)
00380 {
00381   m_node->setTexSize(width, height);
00382 }
00383 
00384 template<typename T>
00385 void ShBaseTextureRect<T>::size(int width, int height)
00386 {
00387   m_node->setTexSize(width, height);
00388 }
00389 
00390 template<typename T>
00391 void ShBaseTexture3D<T>::size(int width, int height, int depth)
00392 {
00393   m_node->setTexSize(width, height, depth);
00394 }
00395 
00396 template<typename T>
00397 void ShBaseTextureCube<T>::size(int width, int height)
00398 {
00399   m_node->setTexSize(width, height);
00400 }
00401 
00402 }
00403 
00404 #endif

Generated on Mon Jan 24 18:36:30 2005 for Sh by  doxygen 1.4.1