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   enum Clamping {
00076     SH_CLAMPED,
00077     SH_UNCLAMPED
00078   };
00079 
00080   ShTextureTraits(unsigned int interpolation,
00081                   Filtering filtering,
00082                   Wrapping wrapping,
00083                   Clamping clamping)
00084     : m_interpolation(interpolation),
00085       m_filtering(filtering),
00086       m_wrapping(wrapping),
00087       m_clamping(clamping)
00088   {
00089   }
00090 
00091   bool operator==(const ShTextureTraits& other) const
00092   {
00093     return m_interpolation == other.m_interpolation
00094       && m_filtering == other.m_filtering
00095       && m_wrapping == other.m_wrapping
00096       && m_clamping == other.m_clamping;
00097   }
00098 
00099   bool operator!=(const ShTextureTraits& other) const { return !(*this == other); }
00100   
00101   unsigned int interpolation() const { return m_interpolation; }
00102   ShTextureTraits& interpolation(unsigned int interp) { m_interpolation = interp; return *this; }
00103   
00104   Filtering filtering() const { return m_filtering; }
00105   ShTextureTraits& filtering(Filtering filtering) { m_filtering = filtering; return *this; }
00106   
00107   Wrapping wrapping() const { return m_wrapping; }
00108   ShTextureTraits& wrapping(Wrapping wrapping) { m_wrapping = wrapping; return *this; }
00109   
00110   Clamping clamping() const { return m_clamping; }
00111   ShTextureTraits& clamping(Clamping clamping) { m_clamping = clamping; return *this; }
00112 
00113 private:
00114   unsigned int m_interpolation;
00115   Filtering m_filtering;
00116   Wrapping m_wrapping;
00117   Clamping m_clamping;
00118 };
00119 
00120 class 
00121 SH_DLLEXPORT ShTextureNode : public ShVariableNode {
00122 public:
00123   ShTextureNode(ShTextureDims dims,
00124                 int size, // scalars per tuple 
00125                 ShValueType valueType, // type index 
00126                 const ShTextureTraits&,
00127                 int width, int height = 1, int depth = 1, int max_nb_elements = -1);
00128   virtual ~ShTextureNode();
00129 
00130   ShTextureDims dims() const;
00131 
00132   // Memory
00133   ShPointer<const ShMemory> memory(int n = 0) const;
00134   ShPointer<const ShMemory> memory(ShCubeDirection dir) const;
00135   ShMemoryPtr memory(int n = 0);
00136   ShMemoryPtr memory(ShCubeDirection dir);
00137   void memory(ShMemoryPtr memory, int n = 0);
00138   void memory(ShMemoryPtr memory, ShCubeDirection dir);
00139 
00140   // Basic properties - not all may be valid for all types
00141   const ShTextureTraits& traits() const; // valid for all texture nodes
00142   ShTextureTraits& traits(); // valid for all texture nodes
00143   int width() const; // valid for all texture nodes
00144   int height() const; // 1 for SH_TEXTURE_1D
00145   int depth() const; // 1 unless SH_TEXTURE_3D
00146   int count() const; // number of elements  
00147 
00148   void setTexSize(int w);
00149   void setTexSize(int w, int h);
00150   void setTexSize(int w, int h, int d);
00151   const ShVariable& texSizeVar() const;
00152 
00153   void count(int n);
00154   
00155 private:
00156   int m_count; // max nb of elements sent to the GPU or -1 if unknown (used by the stream backend)
00157 
00158   ShTextureDims m_dims;
00159   
00160   ShMemoryPtr* m_memory; // array of either 1 or 6 (for cubemaps)
00161   
00162   ShTextureTraits m_traits;
00163   int m_width, m_height, m_depth;
00164 
00165   ShVariable m_texSizeVar;
00166   
00167   // NOT IMPLEMENTED
00168   ShTextureNode(const ShTextureNode& other);
00169   ShTextureNode& operator=(const ShTextureNode& other);
00170 };
00171 
00172 typedef ShPointer<ShTextureNode> ShTextureNodePtr;
00173 typedef ShPointer<const ShTextureNode> ShTextureNodeCPtr;
00174 
00175 }
00176 #endif

Generated on Thu Apr 21 17:32:49 2005 for Sh by  doxygen 1.4.2