00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef RU_PixelFunction_h
00024 #define RU_PixelFunction_h
00025
00026 #include "RU_API.h"
00027 #include <UT/UT_PtrArray.h>
00028 #include <UT/UT_Lock.h>
00029 #include <UT/UT_String.h>
00030 #include <UT/UT_StringArray.h>
00031 #include <RE/RE_Types.h>
00032
00033 class RU_PixelFunction;
00034 class RE_OGLComputeGPU;
00035
00036 typedef float (*RUPixelFunc)(RU_PixelFunction *, float, int);
00037 typedef void (*RUVectorFunc)(RU_PixelFunction *, float **, const bool *);
00038
00039 class RU_API RU_PixelFunction
00040 {
00041 public:
00042 RU_PixelFunction() : myNextFunc(0), myBuildLock(0L)
00043 { myScope[0] = myScope[1] = myScope[2] = myScope[3] = true; }
00044 virtual ~RU_PixelFunction();
00045
00046 void setScope(bool *scope);
00047 bool isScoped(int i) const { return myScope[i]; }
00048 const bool *getScope() const { return myScope; }
00049 bool isPartialScope() const;
00050
00051
00052 bool isComponentDependent() const;
00053
00054
00055 bool areAllComponentsNeeded() const;
00056
00057 void buildPixelEngine();
00058 void buildVectorEngine();
00059 void buildShaderEngine(RE_OGLComputeGPU *gpgpu);
00060
00061
00062
00063 inline float processValue(float val, int comp) const
00064 {
00065 for(int i= 0; i<myFunctions.entries(); i++)
00066 if(myParms(i)->isScoped(comp))
00067 val = myFunctions(i)( myParms(i), val, comp );
00068 return val;
00069 }
00070
00071 inline void processValues(float **vals) const
00072 {
00073 for(int i= 0; i<myVectorFunctions.entries(); i++)
00074 {
00075 myVectorFunctions(i)( myParms(i), vals,myParms(i)->getScope());
00076 }
00077 }
00078
00079 const char *getShaderCode() const { return myShaderCode; }
00080 const char *getFunctionCode() const { return myFunctionCode; }
00081 const char *getLocals() const { return myLocalVars; }
00082 bool usesNumCompsGlobal() const { return myUseNumComps;}
00083
00084 void setNext(RU_PixelFunction *next) { myNextFunc = next; }
00085 RU_PixelFunction *next() const { return myNextFunc; }
00086
00087 void setNumComps(int comps) { myNumComps = comps; }
00088
00089 protected:
00090 static float defaultPixelFunction(RU_PixelFunction *func,
00091 float val, int comp);
00092 static void defaultVectorFunction(RU_PixelFunction *func,
00093 float **vals,const bool *scope);
00094
00095
00096
00097 virtual bool needAllComponents() const { return false; }
00098
00099
00100 virtual bool eachComponentDifferent() const { return false; }
00101
00102
00103 virtual RUPixelFunc getPixelFunction() const;
00104
00105
00106
00107 virtual RUVectorFunc getVectorFunction() const;
00108
00109 virtual void getPixelShader(UT_String &frag_shader);
00110
00111 void addConstant(const char *name,
00112 RE_GPUType type, int vectorsize,
00113 const void *data,
00114 int array_size = 1);
00115 void addLocal(const char *name,
00116 RE_GPUType type,
00117 int vectorsize);
00118 void addArray(const char *name,
00119 RE_GPUType type,
00120 int vectorsize,
00121 int width,
00122 int height,
00123 const void *data);
00124 void addArray(const char *name,
00125 RE_GPUType type,
00126 int vectorsize,
00127 int width,
00128 int height,
00129 const void *data1,
00130 const void *data2,
00131 const void *data3,
00132 const void *data4);
00133
00134
00135
00136
00137 void addFunction(const char *function_name,
00138 const char *code);
00139
00140
00141
00142 void usesGlobal(const char *name);
00143
00144 int getFunctionIndex() const
00145 { return myHead->myFunctionIndex; }
00146 int getNumComps() const
00147 { return myHead->myNumComps; }
00148
00149 private:
00150 RU_PixelFunction *myNextFunc;
00151
00152 UT_Lock myBuildLock;
00153 UT_PtrArray<RUPixelFunc> myFunctions;
00154 UT_PtrArray<RUVectorFunc> myVectorFunctions;
00155 UT_PtrArray<RU_PixelFunction *> myParms;
00156
00157 mutable RUPixelFunc myVectorizedFunction;
00158 bool myScope[4];
00159
00160
00161 RU_PixelFunction *myHead;
00162 UT_String myShaderCode, myFunctionCode;
00163 UT_String myLocalVars;
00164 UT_String myParmCall;
00165 UT_String myParmDecl;
00166 UT_String myLocals;
00167 UT_StringArray myUserFunctions;
00168 UT_String myUserFunctionCode;
00169 RE_OGLComputeGPU *myGPU;
00170 int myFunctionIndex;
00171 int myNumComps;
00172 bool myUseNumComps;
00173
00174 friend class RU_ColorCurve;
00175 };
00176
00177 #endif