00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00020 #ifndef SHTEXTURENODE_HPP
00021 #define SHTEXTURENODE_HPP
00022
00023 #include "ShDllExport.hpp"
00024 #include "ShVariableNode.hpp"
00025 #include "ShMemory.hpp"
00026 #include "ShRefCount.hpp"
00027 #include "ShVariable.hpp"
00028
00029 namespace SH {
00030
00034 enum ShTextureDims {
00035 SH_TEXTURE_1D,
00036 SH_TEXTURE_2D,
00037 SH_TEXTURE_RECT,
00038 SH_TEXTURE_3D,
00039 SH_TEXTURE_CUBE
00040 };
00041
00045 enum ShCubeDirection {
00046 SH_CUBE_POS_X = 0,
00047 SH_CUBE_NEG_X = 1,
00048 SH_CUBE_POS_Y = 2,
00049 SH_CUBE_NEG_Y = 3,
00050 SH_CUBE_POS_Z = 4,
00051 SH_CUBE_NEG_Z = 5
00052 };
00053
00058 class
00059 SH_DLLEXPORT ShTextureTraits {
00060 public:
00061 enum Filtering {
00062 SH_FILTER_NONE,
00063 SH_FILTER_MIPMAP_NEAREST,
00064 SH_FILTER_MIPMAP_LINEAR
00065 };
00066
00067 enum Wrapping {
00068 SH_WRAP_CLAMP,
00069 SH_WRAP_CLAMP_TO_EDGE,
00070 SH_WRAP_REPEAT
00071 };
00072
00073 ShTextureTraits(unsigned int interpolation,
00074 Filtering filtering,
00075 Wrapping wrapping)
00076 : m_interpolation(interpolation),
00077 m_filtering(filtering),
00078 m_wrapping(wrapping)
00079 {
00080 }
00081
00082 bool operator==(const ShTextureTraits& other) const
00083 {
00084 return m_interpolation == other.m_interpolation
00085 && m_filtering == other.m_filtering
00086 && m_wrapping == other.m_wrapping;
00087 }
00088
00089 bool operator!=(const ShTextureTraits& other) const { return !(*this == other); }
00090
00091 unsigned int interpolation() const { return m_interpolation; }
00092 ShTextureTraits& interpolation(unsigned int interp) { m_interpolation = interp; return *this; }
00093
00094 Filtering filtering() const { return m_filtering; }
00095 ShTextureTraits& filtering(Filtering filtering) { m_filtering = filtering; return *this; }
00096
00097 Wrapping wrapping() const { return m_wrapping; }
00098 ShTextureTraits& wrapping(Wrapping wrapping) { m_wrapping = wrapping; return *this; }
00099
00100
00101 private:
00102 unsigned int m_interpolation;
00103 Filtering m_filtering;
00104 Wrapping m_wrapping;
00105 };
00106
00107 class
00108 SH_DLLEXPORT ShTextureNode : public ShVariableNode {
00109 public:
00110 ShTextureNode(ShTextureDims dims,
00111 int size,
00112 ShValueType valueType,
00113 const ShTextureTraits&,
00114 int width, int height = 1, int depth = 1, int max_nb_elements = -1);
00115 virtual ~ShTextureNode();
00116
00117 ShTextureDims dims() const;
00118
00119
00120 ShPointer<const ShMemory> memory(int n) const;
00121 ShPointer<const ShMemory> memory(ShCubeDirection dir, int n) const;
00122 ShMemoryPtr memory(int n);
00123 ShMemoryPtr memory(ShCubeDirection dir, int n);
00124 void memory(const ShMemoryPtr& memory, int n);
00125 void memory(const ShMemoryPtr& memory, ShCubeDirection dir, int n);
00126
00127
00128 const ShTextureTraits& traits() const;
00129 ShTextureTraits& traits();
00130 int width() const;
00131 int height() const;
00132 int depth() const;
00133 int count() const;
00134 int mipmap_levels();
00135
00136 void setTexSize(int w);
00137 void setTexSize(int w, int h);
00138 void setTexSize(int w, int h, int d);
00139 const ShVariable& texSizeVar() const;
00140
00141 void count(int n);
00142
00144 bool build_mipmaps(ShCubeDirection dir = SH_CUBE_POS_X);
00145
00146 private:
00147 int m_count;
00148
00149 ShTextureDims m_dims;
00150
00151 ShMemoryPtr* m_memory;
00152 int m_nb_memories;
00153 int m_mipmap_levels;
00154 int m_mipmap_generation_timestamp[6];
00155 ShMemory* m_mipmap_generation_basemem[6];
00156
00157 ShTextureTraits m_traits;
00158 int m_width, m_height, m_depth;
00159
00160 ShVariable m_texSizeVar;
00161 ShTextureTraits::Filtering m_old_filtering;
00162
00163 void initialize_memories(bool force_initialization);
00164 float interpolate1D(float* base_data, int scale, int x, int component);
00165 float interpolate2D(float* base_data, int scale, int x, int y, int component);
00166 float interpolate3D(float* base_data, int scale, int x, int y, int z, int component);
00167 ShMemoryPtr memory_error(int n) const;
00168
00169
00170 ShTextureNode(const ShTextureNode& other);
00171 ShTextureNode& operator=(const ShTextureNode& other);
00172 };
00173
00174 typedef ShPointer<ShTextureNode> ShTextureNodePtr;
00175 typedef ShPointer<const ShTextureNode> ShTextureNodeCPtr;
00176
00177 }
00178 #endif