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 <sstream>
00028 #include "ShKernelLib.hpp"
00029 #include "ShFunc.hpp"
00030
00031 namespace ShUtil {
00032
00033 std::string ShKernelLib::makeName(std::string prefix, int index) {
00034 std::ostringstream name;
00035 if( index == 0 ) return prefix;
00036 name << prefix << index;
00037 return name.str();
00038 }
00039
00040 ShProgram ShKernelLib::outputPass( const ShProgram &p ) {
00041 ShProgram passer = SH_BEGIN_PROGRAM() {
00042 for( ShProgramNode::VarList::const_iterator it = p.node()->outputs.begin();
00043 it != p.node()->outputs.end(); ++it ) {
00044 ShVariableNodePtr var = *it;
00045 ShVariable inout(new ShVariableNode(SH_INOUT, var->size(), var->valueType(), var->specialType()));
00046 inout.name( var->name() );
00047 }
00048 } SH_END;
00049 return passer;
00050 }
00051
00052 ShProgram ShKernelLib::inputPass( const ShProgram &p ) {
00053 ShProgram passer = SH_BEGIN_PROGRAM() {
00054 for( ShProgramNode::VarList::const_iterator it = p.node()->inputs.begin();
00055 it != p.node()->inputs.end(); ++it ) {
00056 ShVariableNodePtr var = *it;
00057 ShVariable inout(new ShVariableNode(SH_INOUT, var->size(), var->valueType(), var->specialType()));
00058 inout.name( var->name() );
00059 }
00060 } SH_END;
00061 return passer;
00062 }
00063
00064 ShProgram ShKernelLib::shChangeBasis(std::string name,
00065 std::string b0Name, std::string b1Name, std::string b2Name) {
00066 ShProgram kernel = SH_BEGIN_PROGRAM() {
00067 ShInputVector3f SH_NAMEDECL( b0, b0Name );
00068 ShInputVector3f SH_NAMEDECL( b1, b1Name );
00069 ShInputVector3f SH_NAMEDECL( b2, b2Name );
00070 ShInOutVector3f SH_NAMEDECL( vec, name ) = changeBasis(b0, b1, b2, vec);
00071 } SH_END;
00072 return kernel;
00073 }
00074
00075 };