{
引用Shader中的属性(自己在Shader中写的一些需要传值的类型) glGetU/A...
设置Shader数据(Shader什么类型就用什么类型设置内容) glU/V...
附加
}
{引用Shader中的属性(自己在Shader中写的一些需要传值的类型) glGetU/A...
typedef int attribute;
typedef int uniform;
attribute _position;
uniform _MVP;
const char* vs = {
...
"uniform mat4 _MVP;"
"attribute vec2 _position;"
...
};
_MVP = glGetUniformLocation(shaderValue.pID,"_MVP");
_position = glGetAttribLocation(shaderValue.pID, "_position");
... 类似的API
//获取Shader程序中的属性(attribute)
glGetAttribLocation (GLuint program, const GLchar* name);
//获取Shader程序全局(uniform)变量对象
glGetUniformLocation (GLuint program, const GLchar* name);
}
{设置Shader数据(Shader什么类型就用什么类型设置内容) glU/V...
CELL::float2 pos[]={//逆时针给坐标点,顺时针会出问题
CELL::float2(x,y),
CELL::float2(x,y+h),
CELL::float2(x+w,y),
CELL::float2(x+w,y+h)
};
...
glUniformMatrix4fv(shader._MVP,1,false,project.data());
glVertexAttribPointer(shader._position,2,GL_FLOAT,false,sizeof(CELL::float2),pos);
...
... 类似的API
//设置Shader内Uniform变量的值
glUniformMatrix2fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat* value);
glUniformMatrix3fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat* value);
glUniformMatrix4fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat* value);
//设置Shader内Uniform变量的值(值float)
glUniform1f (GLint location, GLfloat x);
glUniform1fv (GLint location, GLsizei count, const GLfloat* v);
//设置Shader内Uniform变量的值(值int)
glUniform1i (GLint location, GLint x);
glUniform1iv (GLint location, GLsizei count, const GLint* v);
glUniform2f (GLint location, GLfloat x, GLfloat y);
glUniform2fv (GLint location, GLsizei count, const GLfloat* v);
glUniform2i (GLint location, GLint x, GLint y);
glUniform2iv (GLint location, GLsizei count, const GLint* v);
glUniform3f (GLint location, GLfloat x, GLfloat y, GLfloat z);
glUniform3fv (GLint location, GLsizei count, const GLfloat* v);
glUniform3i (GLint location, GLint x, GLint y, GLint z);
glUniform3iv (GLint location, GLsizei count, const GLint* v);
glUniform4f (GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
glUniform4fv (GLint location, GLsizei count, const GLfloat* v);
glUniform4i (GLint location, GLint x, GLint y, GLint z, GLint w);
glUniform4iv (GLint location, GLsizei count, const GLint* v);
glVertexAttrib1f (GLuint indx, GLfloat x);
glVertexAttrib1fv (GLuint indx, const GLfloat* values);
glVertexAttrib2f (GLuint indx, GLfloat x, GLfloat y);
glVertexAttrib2fv (GLuint indx, const GLfloat* values);
glVertexAttrib3f (GLuint indx, GLfloat x, GLfloat y, GLfloat z);
glVertexAttrib3fv (GLuint indx, const GLfloat* values);
glVertexAttrib4f (GLuint indx, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
glVertexAttrib4fv (GLuint indx, const GLfloat* values);
glVertexAttribPointer (GLuint indx, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid* ptr);
}
{附加
uniform 设置这个属性不限于顶点Shader(vs)或片段Shader(fs)
glUniformMatrix4fv 设置MVP ...
glUniform4f 设置颜色值 ...
attribute 设置这个属性只限于顶点Shander(vs),假如片段Shader(fs)用的话,只能用varying 传值
glVertexAttribPointer 设置图片位置 ...
}
/** 获取Shader程序中的 attribute/Uniform 类型
* @param program 程序ID
* @param name 属性名字
* @return
*/
GL_APICALL int GL_APIENTRY glGetAttribLocation (GLuint program, const GLchar* name);
GL_APICALL int GL_APIENTRY glGetUniformLocation (GLuint program, const GLchar* name);
/** 设置Shader数据 顶点数据源
* 指定顶点数据源(位置,法线,uv坐标,副法线,切线...需要绘制的顶点数据都叫属性)
* @param indx Shader中的属性
* @param size 数量(位置(x,y,z)数量3,颜色(r,g,b,a)数量4)
* @param type 数据类型(GL_FLOAT,GL_BYTE, GL_UNSIGNED_BYTE ...)
* @param normalized 是否规格化 指定当被访问时,固定点数据值是否应该被归一化(GL_TRUE)或者直接转换为固定点值(GL_FALSE)
* @param stride 偏移量,初始值为0。
* @param ptr 要传入的数据。初始值为0;
* @return
*/
GL_APICALL void GL_APIENTRY glVertexAttribPointer (GLuint indx, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid* ptr);