ShBaseTexture.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 SHBASETEXTURE_HPP
00021 #define SHBASETEXTURE_HPP
00022 
00023 #include <string>
00024 #include "ShDllExport.hpp"
00025 #include "ShTextureNode.hpp"
00026 #include "ShMemory.hpp"
00027 #include "ShVariable.hpp"
00028 #include "ShAttrib.hpp"
00029 #include "ShMetaForwarder.hpp"
00030 #include "ShTexData.hpp"
00031 
00032 namespace SH {
00033 
00034 class
00035 SH_DLLEXPORT ShBaseTexture : public ShMetaForwarder {
00036 public:
00037   ShBaseTexture(const ShTextureNodePtr& node);
00038 
00039   void build_mipmaps() { m_node->build_mipmaps(); }
00040 
00042   const ShTextureNodePtr & node() const { return m_node; }
00043 
00044 protected:
00045   ShTextureNodePtr m_node;
00046 };
00047 
00050 template<typename T>
00051 class ShBaseTexture1D : public ShBaseTexture {
00052 public:
00053   ShBaseTexture1D(const ShTextureTraits& traits);
00054   ShBaseTexture1D(int width, const ShTextureTraits& traits);
00055 
00056   template<typename T2>
00057   ShTexData<T, 1, T2> operator()(const ShGeneric<1, T2>& coords) const;
00058 
00059   template<typename T2>
00060   ShTexData<T, 1, T2> operator[](const ShGeneric<1, T2>& coords) const;
00061 
00062   ShMemoryPtr memory(int mipmap_level=0);
00063   void memory(ShMemoryPtr memory, int mipmap_level=0);
00064   void size(int width);
00065 
00066   ShAttrib1f size() const;
00067   int width() const { return m_node->width(); }
00068 
00069   typedef T return_type;
00070 };
00071 
00074 template<typename T>
00075 class ShBaseTexture2D : public ShBaseTexture  {
00076 public:
00077   ShBaseTexture2D(const ShTextureTraits& traits);
00078   ShBaseTexture2D(int width, int height, const ShTextureTraits& traits);
00079 
00080   template<typename T2>
00081   ShTexData<T, 2, T2> operator()(const ShGeneric<2, T2>& coords) const;
00082 
00084   template<typename T2>
00085   ShTexData<T, 2, T2> operator()(const ShGeneric<2, T2>& coords,
00086                                  const ShGeneric<2, T2>& dx,
00087                                  const ShGeneric<2, T2>& dy) const;
00088   
00089   template<typename T2>
00090   ShTexData<T, 2, T2> operator[](const ShGeneric<2, T2>& coords) const;
00091 
00092   ShMemoryPtr memory(int mipmap_level=0);
00093   void memory(ShMemoryPtr memory, int mipmap_level=0);
00094   void size(int width, int height);
00095 
00096   ShAttrib2f size() const;
00097 
00098   int width() const { return m_node->width(); }
00099   int height() const { return m_node->height(); }
00100 
00101   typedef T return_type;
00102 };
00103 
00106 template<typename T>
00107 class ShBaseTextureRect : public ShBaseTexture  {
00108 public:
00109   ShBaseTextureRect(const ShTextureTraits& traits);
00110   ShBaseTextureRect(int width, int height, const ShTextureTraits& traits);
00111 
00112   template<typename T2>
00113   ShTexData<T, 2, T2> operator()(const ShGeneric<2, T2>& coords) const;
00114 
00115   template<typename T2>
00116   ShTexData<T, 2, T2> operator[](const ShGeneric<2, T2>& coords) const;
00117 
00118   ShMemoryPtr memory(int mipmap_level=0);
00119   void memory(ShMemoryPtr memory, int mipmap_level=0);
00120   void size(int width, int height);
00121 
00122   ShAttrib2f size() const;
00123 
00124   int width() const { return m_node->width(); }
00125   int height() const { return m_node->height(); }
00126 
00127   typedef T return_type;
00128 };
00129 
00132 template<typename T>
00133 class ShBaseTexture3D : public ShBaseTexture  {
00134 public:
00135   ShBaseTexture3D(const ShTextureTraits& traits);
00136   ShBaseTexture3D(int width, int height, int depth, const ShTextureTraits& traits);
00137 
00138   template<typename T2>
00139   ShTexData<T, 3, T2> operator()(const ShGeneric<3, T2>& coords) const;
00140 
00141   template<typename T2>
00142   ShTexData<T, 3, T2> operator[](const ShGeneric<3, T2>& coords) const;
00143 
00144   ShMemoryPtr memory(int mipmap_level=0);
00145   void memory(ShMemoryPtr memory, int mipmap_level=0);
00146   void size(int width, int height, int depth);
00147 
00148   ShAttrib3f size() const;
00149   int width() const { return m_node->width(); }
00150   int height() const { return m_node->height(); }
00151   int depth() const { return m_node->depth(); }
00152 
00153   typedef T return_type;
00154 };
00155 
00158 template<typename T>
00159 class ShBaseTextureCube : public ShBaseTexture {
00160 public:
00161   ShBaseTextureCube(const ShTextureTraits& traits);
00162   ShBaseTextureCube(int width, int height, const ShTextureTraits& traits);
00163 
00164   template<typename T2>
00165   ShTexData<T, 3, T2> operator()(const ShGeneric<3, T2>& coords) const;
00166 
00167   ShMemoryPtr memory(ShCubeDirection face, int mipmap_level=0);
00168   void memory(ShMemoryPtr memory, ShCubeDirection face, int mipmap_level=0);
00169   void size(int width, int height);
00170 
00171   ShAttrib2f size() const;
00172 
00173   int width() const { return m_node->width(); }
00174   int height() const { return m_node->height(); }
00175 
00176   typedef T return_type;
00177 };
00178 
00179 }
00180 
00181 #include "ShBaseTextureImpl.hpp"
00182 
00183 #endif

Generated on Wed Nov 9 15:29:29 2005 for Sh by  doxygen 1.4.5