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

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