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

ShTextureNode.cpp

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

Generated on Mon Oct 18 14:17:40 2004 for Sh by doxygen 1.3.7