用模板类封装OpenGL Shader 的Uniform变量
来源:互联网 发布:县级火车站 知乎 编辑:程序博客网 时间:2024/06/10 04:30
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;
};
- 用模板类封装OpenGL Shader 的Uniform变量
- 用模板类封装OpenGL Shader Uniform 变量2
- opengl shader 2 uniform变量
- opengl 教程(5) shader(2) uniform变量
- OpenGL ES Shader的三种变量类型uniform,attribute和varying
- openGL---shader的几个变量
- Shader的数据接口:属性和uniform变量
- 代码修改shader Properties uniform变量
- 【OpenGL ES】uniform变量缓冲区对象layout
- shader中uniform变量的if或for判断会降低帧率
- shader三种变量类型(uniform,attribute和varying)
- shader三种变量类型(uniform,attribute和varying)
- shader三种变量类型(uniform,attribute和varying)
- shader三种变量类型(uniform,attribute和varying)
- shader三种变量类型(uniform,attribute和varying)
- shader三种变量类型(uniform,attribute和varying)
- shader着色器变量——uniform、attribute和varying
- OpenGL ES2.0 的三种变量类型(uniform,attribute和varying)
- [译] HTML5 prefetch
- [转载] ubuntu 命令 dpkg -l
- [零基础学python]Hello,第一个网页分析
- [零基础学python]python开发框架
- 图标
- 用模板类封装OpenGL Shader 的Uniform变量
- 虚拟机上Linux读取播放USB摄像头视频卡住的问题
- callback机制
- [零基础学python]使用tornado表单和模板
- 在VS2012中编译WinXP兼容的程序
- [零基础学python]模板中的语法
- [零基础学python]用Python操作数据库(1)
- [零基础学python]用Python操作数据库(2)
- 透彻理解贝叶斯-从先验概率,后验概率起