00001
00002
00003
00004
00005
00006 #ifndef RC_UNIFORM_H
00007 #define RC_UNIFORM_H
00008
00009 #define UNIFORM_DEFAULT_ENTRIES_SIZE 8
00010
00011
00012
00013
00014 #define UNIFORM_FLAG_CLASS_MASK 0xFF
00015
00016 #define UNIFORM_FLAG_SCALAR (1 << 0)
00017
00018 #define UNIFORM_FLAG_VECTOR2 (1 << 1)
00019 #define UNIFORM_FLAG_VECTOR3 (1 << 2)
00020 #define UNIFORM_FLAG_VECTOR4 (1 << 3)
00021
00022 #define UNIFORM_FLAG_MATRIX2 (1 << 4)
00023 #define UNIFORM_FLAG_MATRIX3 (1 << 5)
00024 #define UNIFORM_FLAG_MATRIX4 (1 << 6)
00025
00026 #define UNIFORM_FLAG_INT (1 << 16)
00027 #define UNIFORM_FLAG_FLOAT (1 << 17)
00028
00029 #define UNIFORM_FLAG_TEXTURE (1 << 18)
00030 #define UNIFORM_FLAG_CUBEMAP (1 << 19)
00031
00032
00033 #define UNIFORM_FLAG_VECTOR (UNIFORM_FLAG_VECTOR2 | UNIFORM_FLAG_VECTOR3 | UNIFORM_FLAG_VECTOR4)
00034 #define UNIFORM_FLAG_MATRIX (UNIFORM_FLAG_MATRIX2 | UNIFORM_FLAG_MATRIX3 | UNIFORM_FLAG_MATRIX4)
00035
00036 typedef struct {
00037
00038 char *name;
00039
00040 u32 flags;
00041 u32 n;
00042
00043 union {
00044 void *ptr;
00045 void *value;
00046 void *handle;
00047 };
00048
00049 } UniformEntry_t;
00050
00051
00052
00053 class Uniform {
00054
00055 public:
00056
00057 Uniform(
00058 u32 entries_size = UNIFORM_DEFAULT_ENTRIES_SIZE
00059 );
00060
00061 ~Uniform();
00062
00063
00064 public:
00065
00066 void setScalar(
00067 const char *name,
00068 f32 value,
00069 UniformType_t type
00070 );
00071
00072 void setScalar(
00073 const char *name,
00074 i32 value,
00075 UniformType_t type
00076 );
00077
00078 void setScalarArray(
00079 const char *name,
00080 void *list,
00081 u32 n_values,
00082 UniformType_t type
00083 );
00084
00085
00086 void setVector(
00087 const char *name,
00088 void *vecptr,
00089 u32 dimension,
00090 UniformType_t type
00091 );
00092
00093 void setVectorArray(
00094 const char *name,
00095 void *list,
00096 u32 n_values,
00097 u32 dimension,
00098 UniformType_t type
00099 );
00100
00101 void setMatrix(
00102 const char *name,
00103 void *matptr,
00104 u32 dimension
00105 );
00106
00107 void setMatrixArray(
00108 const char *name,
00109 void *list,
00110 u32 n_values,
00111 u32 dimension
00112 );
00113
00114
00115
00116
00117 void setTexture(
00118 const char *name,
00119 Texture *tex
00120 );
00121
00122 void setCubeMap(
00123 const char *name,
00124 CubeMap *cubemap
00125 );
00126
00127
00128 void remove(
00129 char *name
00130 );
00131
00132 UniformEntry_t *getEntries();
00133
00134 u32 getEntryCount() const;
00135
00136 void copyTo(
00137 Uniform *uniform
00138 );
00139
00140 void log();
00141
00142 protected:
00143
00144 void setTextureHandle(
00145 const char *name,
00146 void *tex
00147 );
00148
00149 void setCubeMapHandle(
00150 const char *name,
00151 void *cubemap
00152 );
00153
00154 private:
00155
00156 void removeAt(
00157 u32 i
00158 );
00159
00160 u32 mapTypeFlag(
00161 UniformType_t type
00162 );
00163
00164 UniformEntry_t *prepEntry(
00165 const char *name,
00166 u32 size,
00167 u32 flags,
00168 u32 n
00169 );
00170
00171 i32 findEntry(
00172 const char *name
00173 );
00174
00175
00176 private:
00177
00178 UniformEntry_t *entries;
00179 u32 n_entries;
00180 u32 max_entries;
00181
00182 };
00183
00184 #endif
00185
00186