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

ShVariable.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 <iostream> 00028 00029 #include "ShVariable.hpp" 00030 #include "ShProgram.hpp" 00031 00032 namespace SH { 00033 00034 ShVariable::ShVariable() 00035 : ShMetaForwarder(0), 00036 m_node(0), m_swizzle(0), m_neg(false) 00037 { 00038 } 00039 00040 ShVariable::ShVariable(const ShVariableNodePtr& node) 00041 : ShMetaForwarder(node.object()), 00042 m_node(node), m_swizzle(node ? node->size() : 0), m_neg(false) 00043 { 00044 } 00045 00046 ShVariable::ShVariable(const ShVariableNodePtr& node, 00047 const ShSwizzle& swizzle, 00048 bool neg) 00049 : ShMetaForwarder(node.object()), 00050 m_node(node), m_swizzle(swizzle), m_neg(neg) 00051 { 00052 } 00053 00054 ShVariable& ShVariable::operator=(const ShProgram& prgc) 00055 { 00056 ShProgram prg(prgc); 00057 if (prg.node()->finished()) { 00058 m_node->attach(prg.node()); 00059 } else { 00060 prg.node()->assign(m_node); 00061 } 00062 return *this; 00063 } 00064 00065 bool ShVariable::null() const 00066 { 00067 return !m_node; 00068 } 00069 00070 bool ShVariable::uniform() const 00071 { 00072 return m_node->uniform(); 00073 } 00074 00075 bool ShVariable::hasValues() const 00076 { 00077 return m_node->hasValues(); 00078 } 00079 00080 int ShVariable::size() const 00081 { 00082 return m_swizzle.size(); 00083 } 00084 00085 void ShVariable::range(ShVariableNode::ValueType low, ShVariableNode::ValueType high) 00086 { 00087 m_node->range(low, high); 00088 } 00089 00090 ShVariableNode::ValueType ShVariable::lowBound() const 00091 { 00092 return m_node->lowBound(); 00093 } 00094 00095 ShVariableNode::ValueType ShVariable::highBound() const 00096 { 00097 return m_node->highBound(); 00098 } 00099 00100 const ShSwizzle& ShVariable::swizzle() const 00101 { 00102 return m_swizzle; 00103 } 00104 00105 const ShVariableNodePtr& ShVariable::node() const 00106 { 00107 return m_node; 00108 } 00109 00110 bool ShVariable::neg() const 00111 { 00112 return m_neg; 00113 } 00114 00115 bool& ShVariable::neg() 00116 { 00117 return m_neg; 00118 } 00119 00120 void ShVariable::getValues(ShVariableNode::ValueType dest[]) const 00121 { 00122 for (int i = 0; i < size(); i++) { 00123 dest[i] = m_node->getValue(m_swizzle[i]); 00124 if (m_neg) dest[i] = -dest[i]; 00125 } 00126 } 00127 00128 ShVariableNode::ValueType ShVariable::getValue(int i) const 00129 { 00130 ShVariableNode::ValueType value = m_node->getValue(m_swizzle[i]); 00131 if (m_neg) value = -value; 00132 return value; 00133 } 00134 00135 void ShVariable::setValues(ShVariableNode::ValueType values[]) 00136 { 00137 m_node->lock(); 00138 for (int i = 0; i < size(); i++) { 00139 m_node->setValue(m_swizzle[i], values[i]); 00140 } 00141 m_node->unlock(); 00142 m_neg = false; 00143 } 00144 00145 void ShVariable::setValue(int index, ShVariableNode::ValueType value) 00146 { 00147 m_node->setValue(m_swizzle[index], (m_neg ? -value : value)); 00148 } 00149 00150 ShVariable ShVariable::operator()() const 00151 { 00152 return ShVariable(m_node, m_swizzle, m_neg); 00153 } 00154 00155 ShVariable ShVariable::operator()(int i1) const 00156 { 00157 return ShVariable(m_node, m_swizzle * ShSwizzle(size(), i1), m_neg); 00158 } 00159 00160 ShVariable ShVariable::operator()(int i1, int i2) const 00161 { 00162 return ShVariable(m_node, m_swizzle * ShSwizzle(size(), i1, i2), m_neg); 00163 } 00164 00165 ShVariable ShVariable::operator()(int i1, int i2, int i3) const 00166 { 00167 return ShVariable(m_node, m_swizzle * ShSwizzle(size(), i1, i2, i3), m_neg); 00168 } 00169 00170 ShVariable ShVariable::operator()(int i1, int i2, int i3, int i4) const 00171 { 00172 return ShVariable(m_node, m_swizzle * ShSwizzle(size(), i1, i2, i3, i4), m_neg); 00173 } 00174 00175 ShVariable ShVariable::operator()(int n, int indices[]) const 00176 { 00177 return ShVariable(m_node, m_swizzle * ShSwizzle(size(), n, indices), m_neg); 00178 } 00179 00180 00181 std::ostream& operator<<(std::ostream& out, const ShVariable& v) 00182 { 00183 if (!v.m_node){ 00184 out << "[null]"; 00185 return out; 00186 } 00187 if (!v.hasValues()){ 00188 out << "[not uniform]"; 00189 return out; 00190 } 00191 00192 out << '['; 00193 00194 for (int k = 0; k < v.size(); k++) { 00195 if (k) out << ", "; 00196 out << v.getValue(k); 00197 } 00198 00199 out << ']'; 00200 return out; 00201 } 00202 00203 00204 ShVariable ShVariable::operator-() const 00205 { 00206 return ShVariable(m_node, m_swizzle, !m_neg); 00207 } 00208 00209 bool ShVariable::operator==(const ShVariable& other) const 00210 { 00211 return m_node == other.m_node && m_swizzle == other.m_swizzle && m_neg == other.m_neg; 00212 } 00213 00214 void ShVariable::clone(const ShVariable& other) 00215 { 00216 m_node = other.m_node; 00217 m_swizzle = other.m_swizzle; 00218 m_neg = other.m_neg; 00219 } 00220 00221 00222 }

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