struct Uniformtypename
{
std::string name;
E_uniformtype type;
};
Static Uniformtypename _datatypetoglsl[17] = {
{"Float", ut_float}, {"Vec2", ut_float_vec2}, {"Vec3", ut_float_vec3}, {"Vec4", UT_FLOAT_VEC4},
{"int", Ut_int}, {"Ivec2", ut_int_vec2}, {"Ivec3", ut_int_vec3}, {"Ivec4", UT_INT_VEC4},
{"bool", Ut_bool}, {"Bvec2", ut_bool_vec2}, {"Bvec3", ut_bool_vec3}, {"Bvec4", UT_BOOL_VEC4},
{"Mat2", Ut_float_mat2}, {"Mat3", Ut_float_mat3}, {"Mat4", UT_FLOAT_MAT4},
{"Sampler2d", ut_sampler_2d},{"Samplercube", Ut_sampler_cube}};
Class Automaticuniformbase:public Uniformbase
{
Public
Automaticuniformbase () {}
~automaticuniformbase () {}
std::string getdeclaration (const std::string& name)
{
std::string declaration = "Uniform" + getdatatypename (this->_datatype) + "" + Name;
Std::stringstream Sizestr;
sizestr<<_size;
if (_size = = 1) {
declaration + = ";";
} else {
declaration + = "[" + sizestr.str () + "];";
}
return declaration;
}
std::string getdatatypename (E_uniformtype typeenum)
{
std::string result ("");
for (int i = 0; i< sizeof (_DATATYPETOGLSL); i++)
{
if (Typeenum = = _datatypetoglsl[i].type)
{
result = _datatypetoglsl[i].name;
Break
}
}
return result;
}
};
Template<class t>
Class Automaticuniform:public Automaticuniformbase
{
Public
Automaticuniform ()
{
This->_uniformclasstype = Uct_auto;
}
typedef T (* getvaluefunc) (uniformstate*);
Automaticuniform (unsigned int size, e_uniformtype type, Getvaluefunc getValue)
{
this->_size = size;
This->_datatype = type;
This->_getvalue = GetValue;
This->_uniformclasstype = Uct_auto;
}
struct Option
{
unsigned int _size;
E_uniformtype _datatype;
Getvaluefunc _getvalue;
};
Automaticuniform (const option& Option)
{
This->_size = option._size;
This->_datatype = Option._datatype;
This->_getvalue = Option._getvalue;
This->_uniformclasstype = Uct_auto;
}
Public
Getvaluefunc _getvalue;
};
Encapsulating uniform variables of OpenGL Shader with template classes