00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00027 #include <cassert>
00028 #include "ShTextureNode.hpp"
00029 #include "ShEnvironment.hpp"
00030 #include "ShDebug.hpp"
00031 #include "ShGeneric.hpp"
00032 #include "ShAttrib.hpp"
00033
00034 namespace SH {
00035
00036 ShTextureNode::ShTextureNode(ShTextureDims dims, int size,
00037 ShValueType valueType,
00038 const ShTextureTraits& traits,
00039 int width, int height, int depth, int max_nb_elements)
00040 : ShVariableNode(SH_TEXTURE, size, valueType), m_count(max_nb_elements),
00041 m_dims(dims),
00042 m_memory(new ShMemoryPtr[dims == SH_TEXTURE_CUBE ? 6 : 1]),
00043 m_traits(traits),
00044 m_width(width), m_height(height), m_depth(depth)
00045 {
00046 if (m_dims == SH_TEXTURE_1D) {
00047 ShAttrib1f v = ShAttrib1f(width);
00048 m_texSizeVar = ShVariable(v.node());
00049 } else if (m_dims == SH_TEXTURE_3D) {
00050 ShAttrib3f v = ShAttrib3f(width, height, depth);
00051 m_texSizeVar = ShVariable(v.node());
00052 } else {
00053 ShAttrib2f v = ShAttrib2f(width, height);
00054 m_texSizeVar = ShVariable(v.node());
00055 }
00056 }
00057
00058 ShTextureNode::~ShTextureNode()
00059 {
00060 delete [] m_memory;
00061 }
00062
00063 ShTextureDims ShTextureNode::dims() const
00064 {
00065 return m_dims;
00066 }
00067
00068 ShMemoryPtr ShTextureNode::memory(int n)
00069 {
00070 SH_DEBUG_ASSERT((n == 0)
00071 || (m_dims == SH_TEXTURE_CUBE && n >= 0 && n < 6));
00072 return m_memory[n];
00073 }
00074
00075 ShPointer<const ShMemory> ShTextureNode::memory(int n) const
00076 {
00077 SH_DEBUG_ASSERT((n == 0)
00078 || (m_dims == SH_TEXTURE_CUBE && n >= 0 && n < 6));
00079 return m_memory[n];
00080 }
00081
00082 void ShTextureNode::memory(ShMemoryPtr memory, int n)
00083 {
00084 SH_DEBUG_ASSERT((n == 0)
00085 || (m_dims == SH_TEXTURE_CUBE && n >= 0 && n < 6));
00086 m_memory[n] = memory;
00087 }
00088
00089 ShMemoryPtr ShTextureNode::memory(ShCubeDirection dir)
00090 {
00091 return memory(static_cast<int>(dir));
00092 }
00093
00094 ShPointer<const ShMemory> ShTextureNode::memory(ShCubeDirection dir) const
00095 {
00096 return memory(static_cast<int>(dir));
00097 }
00098
00099 void ShTextureNode::memory(ShMemoryPtr mem, ShCubeDirection dir)
00100 {
00101 memory(mem, static_cast<int>(dir));
00102 }
00103
00104 const ShTextureTraits& ShTextureNode::traits() const
00105 {
00106 return m_traits;
00107 }
00108
00109 ShTextureTraits& ShTextureNode::traits()
00110 {
00111 return m_traits;
00112 }
00113
00114 void ShTextureNode::setTexSize(int w)
00115 {
00116 m_width = w;
00117 ShAttrib1f s(m_texSizeVar.node(), ShSwizzle(m_texSizeVar().size()), false);
00118 s = static_cast<float>(w);
00119 }
00120
00121 void ShTextureNode::setTexSize(int w, int h)
00122 {
00123 m_width = w;
00124 m_height = h;
00125 ShAttrib2f s(m_texSizeVar.node(), ShSwizzle(m_texSizeVar().size()), false);
00126 s = ShAttrib2f(w, h);
00127 }
00128
00129 void ShTextureNode::setTexSize(int w, int h, int d)
00130 {
00131 m_width = w;
00132 m_height = h;
00133 m_depth = d;
00134 ShAttrib3f s(m_texSizeVar.node(), ShSwizzle(m_texSizeVar().size()), false);
00135 s = ShAttrib3f(w, h, d);
00136 }
00137
00138 int ShTextureNode::width() const
00139 {
00140 return m_width;
00141 }
00142
00143 int ShTextureNode::height() const
00144 {
00145 return m_height;
00146 }
00147
00148 int ShTextureNode::depth() const
00149 {
00150 return m_depth;
00151 }
00152
00153 int ShTextureNode::count() const
00154 {
00155 return (m_count != -1) ? m_count : m_width * m_height * m_depth;
00156 }
00157
00158 const ShVariable& ShTextureNode::texSizeVar() const
00159 {
00160 return m_texSizeVar;
00161 }
00162
00163 }
00164