ShLibWorley.hpp

00001 // Sh: A GPU metaprogramming language.
00002 //
00003 // Copyright 2003-2005 Serious Hack Inc.
00004 // 
00005 // This library is free software; you can redistribute it and/or
00006 // modify it under the terms of the GNU Lesser General Public
00007 // License as published by the Free Software Foundation; either
00008 // version 2.1 of the License, or (at your option) any later version.
00009 //
00010 // This library is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 // Lesser General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU Lesser General Public
00016 // License along with this library; if not, write to the Free Software
00017 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
00018 // MA  02110-1301, USA
00020 #include "ShLib.hpp" // ShLibWorley needs to be included from within ShLib
00021 
00022 #ifndef SHLIBWORLEY_HPP 
00023 #define SHLIBWORLEY_HPP
00024 
00025 #include <vector>
00026 #include "ShAttrib.hpp"
00027 #include "ShColor.hpp"
00028 
00029 namespace SH {
00030 
00060 // A Generator point represents the position of a generator relative
00061 // to the cell origin of a lookup position. 
00062 //
00063 template<int D, typename T>
00064 struct Generator {
00065   Generator() {}
00066   ShAttrib<D, SH_TEMP, T> pos; // position 
00067   ShAttrib<D, SH_TEMP, T> offset; // offset of the cell relative to lookup point's cell
00068   ShAttrib<D, SH_TEMP, T> cell; // integer cell (this should actually be typed T = int, but not possible yet) 
00069 };
00070 
00071 // Generator Factory 
00072 // A Point Generator must implement a function that 
00073 // sets a Generator array with P candidate generator points. 
00074 template<int P, int D, typename T>
00075 struct GeneratorFactory {
00076   static const int NUM_POINTS = P;
00077   virtual ~GeneratorFactory() {}
00078   virtual void operator()(const ShGeneric<D, T> &p, Generator<D, T> result[]) const = 0;
00079 };
00080 
00081 // Property Factory
00082 // This takes a Generator and attaches N properties to it.
00083 // The first property in the result is used to sort the generator points 
00084 // (and so should probably be a distance metric).
00085 template<int N, int D, typename T>
00086 struct PropertyFactory {
00087   static const int NUM_PROPS = N;
00088   static const int DIM = D;
00089   typedef T PropType; 
00090   
00091   virtual ~PropertyFactory() {} 
00092   virtual ShGeneric<N, T> operator()(const ShGeneric<D, T> &p, const Generator<D, T> &g) const = 0; 
00093 };
00094 
00095 #ifndef WIN32
00096 
00102 template<int K, int D, typename T>
00103 ShGeneric<K, T> worley(const ShGeneric<D, T> &p, bool useTexture = true); 
00105 
00109 template<int K, int L, int P, int D, typename T>
00110 void worley(ShGeneric<K, T> result[], const ShGeneric<D, T> &p, 
00111             const GeneratorFactory<P, D, T> *genFactory,
00112             const PropertyFactory<L, D, T> *propFactory);
00113 
00121 template<int K, int D, typename T>
00122 ShProgram shWorley(bool useTexture);
00123 
00124 template<int K, int N, int P, int D, typename T>
00125 ShProgram shWorley(const GeneratorFactory<P, D, T> *genFactory,
00126                    const PropertyFactory<N, D, T> *propFactory);
00128 
00129 #endif // WIN32
00130 
00131 } // namespace SH
00132 
00133 #include "ShLibWorleyImpl.hpp"
00134 
00135 #endif // SHLIBWORLEY_HPP

Generated on Wed Nov 9 15:29:35 2005 for Sh by  doxygen 1.4.5