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

Generated on Wed Jun 15 18:12:38 2005 for Sh by  doxygen 1.4.3-20050530