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

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