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

ShTextureNode.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 SHTEXTURENODE_HPP
00028 #define SHTEXTURENODE_HPP
00029 
00030 #include "ShDllExport.hpp"
00031 #include "ShVariableNode.hpp"
00032 #include "ShMemory.hpp"
00033 #include "ShRefCount.hpp"
00034 #include "ShVariable.hpp"
00035 
00036 namespace SH {
00037 
00041 enum ShTextureDims {
00042   SH_TEXTURE_1D,   // Power of two
00043   SH_TEXTURE_2D,   // Power of two
00044   SH_TEXTURE_RECT, // Non power of two
00045   SH_TEXTURE_3D,   // Power of two, but depth may not be
00046   SH_TEXTURE_CUBE, // 6 "2D" memory objects, power of two
00047 };
00048 
00052 enum ShCubeDirection {
00053   SH_CUBE_POS_X = 0,
00054   SH_CUBE_NEG_X = 1,
00055   SH_CUBE_POS_Y = 2,
00056   SH_CUBE_NEG_Y = 3,
00057   SH_CUBE_POS_Z = 4,
00058   SH_CUBE_NEG_Z = 5,
00059 };
00060 
00065 class 
00066 SH_DLLEXPORT ShTextureTraits {
00067 public:
00068   enum Filtering {
00069     SH_FILTER_NONE,
00070     SH_FILTER_MIPMAP
00071   };
00072   
00073   enum Wrapping {
00074     SH_WRAP_CLAMP,
00075     SH_WRAP_CLAMP_TO_EDGE,
00076     SH_WRAP_REPEAT
00077   };
00078   enum Clamping {
00079     SH_CLAMPED,
00080     SH_UNCLAMPED
00081   };
00082 
00083   ShTextureTraits(unsigned int interpolation,
00084                   Filtering filtering,
00085                   Wrapping wrapping,
00086                   Clamping clamping)
00087     : m_interpolation(interpolation),
00088       m_filtering(filtering),
00089       m_wrapping(wrapping),
00090       m_clamping(clamping)
00091   {
00092   }
00093 
00094   bool operator==(const ShTextureTraits& other) const
00095   {
00096     return m_interpolation == other.m_interpolation
00097       && m_filtering == other.m_filtering
00098       && m_wrapping == other.m_wrapping
00099       && m_clamping == other.m_clamping;
00100   }
00101 
00102   bool operator!=(const ShTextureTraits& other) const { return !(*this == other); }
00103   
00104   unsigned int interpolation() const { return m_interpolation; }
00105   ShTextureTraits& interpolation(unsigned int interp) { m_interpolation = interp; return *this; }
00106   
00107   Filtering filtering() const { return m_filtering; }
00108   ShTextureTraits& filtering(Filtering filtering) { m_filtering = filtering; return *this; }
00109   
00110   Wrapping wrapping() const { return m_wrapping; }
00111   ShTextureTraits& wrapping(Wrapping wrapping) { m_wrapping = wrapping; return *this; }
00112   
00113   Clamping clamping() const { return m_clamping; }
00114   ShTextureTraits& clamping(Clamping clamping) { m_clamping = clamping; return *this; }
00115 
00116 private:
00117   unsigned int m_interpolation;
00118   Filtering m_filtering;
00119   Wrapping m_wrapping;
00120   Clamping m_clamping;
00121 };
00122 
00123 class 
00124 SH_DLLEXPORT ShTextureNode : public ShVariableNode {
00125 public:
00126   ShTextureNode(ShTextureDims dims,
00127                 int size, // scalars per tuple 
00128                 ShValueType valueType, // type index 
00129                 const ShTextureTraits&,
00130                 int width, int height = 1, int depth = 1, int max_nb_elements = -1);
00131   virtual ~ShTextureNode();
00132 
00133   ShTextureDims dims() const;
00134 
00135   // Memory
00136   ShPointer<const ShMemory> memory(int n = 0) const;
00137   ShPointer<const ShMemory> memory(ShCubeDirection dir) const;
00138   ShMemoryPtr memory(int n = 0);
00139   ShMemoryPtr memory(ShCubeDirection dir);
00140   void memory(ShMemoryPtr memory, int n = 0);
00141   void memory(ShMemoryPtr memory, ShCubeDirection dir);
00142 
00143   // Basic properties - not all may be valid for all types
00144   const ShTextureTraits& traits() const; // valid for all texture nodes
00145   ShTextureTraits& traits(); // valid for all texture nodes
00146   int width() const; // valid for all texture nodes
00147   int height() const; // 1 for SH_TEXTURE_1D
00148   int depth() const; // 1 unless SH_TEXTURE_3D
00149   int count() const; // number of elements  
00150 
00151   void setTexSize(int w);
00152   void setTexSize(int w, int h);
00153   void setTexSize(int w, int h, int d);
00154   const ShVariable& texSizeVar() const;
00155   
00156 private:
00157   int m_count; // max nb of elements sent to the GPU or -1 if unknown (used by the stream backend)
00158 
00159   ShTextureDims m_dims;
00160   
00161   ShMemoryPtr* m_memory; // array of either 1 or 6 (for cubemaps)
00162   
00163   ShTextureTraits m_traits;
00164   int m_width, m_height, m_depth;
00165 
00166   ShVariable m_texSizeVar;
00167   
00168   // NOT IMPLEMENTED
00169   ShTextureNode(const ShTextureNode& other);
00170   ShTextureNode& operator=(const ShTextureNode& other);
00171 };
00172 
00173 typedef ShPointer<ShTextureNode> ShTextureNodePtr;
00174 typedef ShPointer<const ShTextureNode> ShTextureNodeCPtr;
00175 
00176 }
00177 #endif

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