00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef __RE_Uniform__
00020 #define __RE_Uniform__
00021
00022 #include "RE_API.h"
00023
00024 #include <UT/UT_HashTable.h>
00025 #include <UT/UT_String.h>
00026
00027 class RE_Render;
00028
00029 enum RE_UniformLanguage
00030 {
00031 RE_UNIFORM_CG = 1,
00032 RE_UNIFORM_GLSL = 1 << 1,
00033 RE_UNIFORM_ALL_LANGUAGES = ~0
00034 };
00035
00036
00037
00038
00039 enum RE_UniformBuiltIn
00040 {
00041 RE_UNIFORM_EMISSION = 0,
00042 RE_UNIFORM_SPECULAR,
00043 RE_UNIFORM_DIFFUSE,
00044 RE_UNIFORM_AMBIENT,
00045 RE_UNIFORM_MATERIAL_PASS,
00046 RE_UNIFORM_MAT_GHOST,
00047 RE_UNIFORM_LIGHT_ENABLED,
00048 RE_UNIFORM_LIGHT_MASK,
00049 RE_UNIFORM_INV_VIEW_MATRIX,
00050 RE_UNIFORM_VIEW_MATRIX,
00051 RE_UNIFORM_OBJECT_MATRIX,
00052 RE_UNIFORM_SCREEN_SIZE,
00053 RE_UNIFORM_DEPTH_PEEL_ENABLE,
00054 RE_UNIFORM_DEPTH_PEEL_MAP,
00055 RE_UNIFORM_ALPHA_PASS,
00056 RE_UNIFORM_BUILT_IN__count
00057 };
00058
00059
00060 enum RE_UniformBinding
00061 {
00062 RE_UNIFORM_BIND_ALL,
00063 RE_UNIFORM_BIND_DISPLAY_LIST_INDEPENDENT,
00064 RE_UNIFORM_BIND_DISPLAY_LIST_DEPENDENT
00065 };
00066
00067
00068
00069 enum RE_UniformType
00070 {
00071 RE_UNIFORM_FLOAT,
00072 RE_UNIFORM_FLOAT_VEC2,
00073 RE_UNIFORM_FLOAT_VEC3,
00074 RE_UNIFORM_FLOAT_VEC4,
00075 RE_UNIFORM_DOUBLE,
00076 RE_UNIFORM_DOUBLE_VEC2,
00077 RE_UNIFORM_DOUBLE_VEC3,
00078 RE_UNIFORM_DOUBLE_VEC4,
00079 RE_UNIFORM_INT,
00080 RE_UNIFORM_INT_VEC2,
00081 RE_UNIFORM_INT_VEC3,
00082 RE_UNIFORM_INT_VEC4,
00083 RE_UNIFORM_FLOAT_MAT2,
00084 RE_UNIFORM_FLOAT_MAT3,
00085 RE_UNIFORM_FLOAT_MAT4,
00086 RE_UNIFORM_DOUBLE_MAT2,
00087 RE_UNIFORM_DOUBLE_MAT3,
00088 RE_UNIFORM_DOUBLE_MAT4,
00089 RE_UNIFORM_SAMPLER_1D,
00090 RE_UNIFORM_SAMPLER_2D,
00091 RE_UNIFORM_SAMPLER_3D,
00092 RE_UNIFORM_SAMPLER_CUBE,
00093 RE_UNIFORM_SAMPLER_RECTANGLE,
00094 RE_UNIFORM_SAMPLER_1D_ARRAY,
00095 RE_UNIFORM_SAMPLER_2D_ARRAY,
00096 RE_UNIFORM_SAMPLER_2D_MULTISAMPLE,
00097 RE_UNIFORM_SAMPLER_2D_SHADOW,
00098 RE_UNIFORM_TYPE__count
00099 };
00100
00101 class RE_API RE_Uniform
00102 {
00103 public:
00104
00105 RE_Uniform(const UT_String &name, RE_UniformType type, int size);
00106 RE_Uniform(RE_UniformBuiltIn built_in, int size);
00107 virtual ~RE_Uniform();
00108
00109
00110
00111 static void getArrayNameAndIndex(const char *str,
00112 UT_String &name_out,
00113 int *index_out);
00114
00115
00116
00117 virtual void getIndexedName(int index, UT_String &out)const;
00118
00119 virtual const UT_String &getName() const { return myName; }
00120
00121
00122
00123
00124 virtual int getSize() const { return mySize; }
00125 virtual RE_UniformType getType() const { return myType; }
00126
00127
00128
00129
00130 virtual const void *getValue(int index=0) const;
00131 virtual void setValue(const void *value, int index=0);
00132
00133
00134
00135 virtual int getVersion() const { return myVersion; }
00136
00137
00138
00139
00140
00141 static int getBuiltIn(const RE_Uniform *uniform,
00142 int languages =
00143 RE_UNIFORM_ALL_LANGUAGES);
00144 static int getBuiltIn(const UT_String &name,
00145 RE_UniformType type,
00146 int languages =
00147 RE_UNIFORM_ALL_LANGUAGES);
00148
00149
00150
00151 static const char *getBuiltInName(RE_UniformBuiltIn built_in);
00152 static RE_UniformType getBuiltInType(RE_UniformBuiltIn built_in);
00153 static int isDisplayListDependent(RE_UniformBuiltIn built_in);
00154
00155
00156
00157
00158
00159
00160 static void registerBuiltIn(RE_Render *r,
00161 RE_UniformBuiltIn built_in,
00162 const RE_Uniform *uniform);
00163
00164
00165
00166 static void assignBuiltIn(RE_Render *r,
00167 RE_UniformBuiltIn built_in,
00168 const void *data);
00169
00170
00171
00172 static void unregisterBuiltIn(RE_Render *r,
00173 RE_UniformBuiltIn built_in,
00174 const RE_Uniform *uniform =
00175 NULL);
00176
00177 void print();
00178
00179 private:
00180 static const int theTypeSizes[RE_UNIFORM_TYPE__count];
00181 static UT_HashTable theBuiltIns;
00182 UT_String myName;
00183 RE_UniformType myType;
00184 int mySize;
00185 int myVersion;
00186 char *myValues;
00187 };
00188
00189 #endif
00190