文章目录
- 1 着色器对象
- 2 着色器二进制
- 3 程序对象
- 3.1 glCreateProgram创建程序对象
- 3.2 glDeleteProgram删除程序对象
- 3.3 glAttachShader将着色器对象依附到程序对象
- 3.4 glDetachShader 将着色器对象解除与程序对象的依附
- 3.5 glLinkProgram链接程序对象
- 3.6 glUseProgram
- 3.7 glGetProgramiv
- 3.8 glProgramParameteri设置程序对象参数
- 3.9 glIsProgram是否是程序对象
- 3.10 glCreateShaderProgramv
- 3.11 glGetProgramInterfaceiv
- 3.12 glGetProgramResourceiv
- 3.13 glGetProgramResourceIndex
- 3.14 glGetProgramResourceName
- 3.15 glGetProgramResourceLocation
- 3.16 glGetProgramResourceLocationIndex
- glGetProgramResourceLocationIndex
- 4 程序管道对象
- 5 程序二进制
- 6 Uniform变量
- 6.1 glGetUniformLocation 获取uniform变量位置
- 6.2 glGetUniformIndices 获取uniform变量索引
- 6.3 glGetActiveUniformName 获取uniform变量名
- 6.4 glGetActiveUniform 获取uniform变量信息
- 6.5 glGetActiveUniformsiv
- 6.6 glGetUniformBlockIndex
- 6.7 glGetActiveUniformBlockName
- 6.8 glGetActiveUniformBlockiv
- 6.9 glGetActiveAtomicCounterBufferiv
- 6.10 glUniform{1234}{ifd ui}
- 6.11 glUniform{1234}{ifd ui}v
- 6.12 glUniformMatrix{234}{fd}v 设置2x2,2x3,4x4矩阵
- 6.13 glUniformMatrix{2x3,3x2,2x4,4x2,3x4,4x3}{fd}v 设置2x3,3x2,2x4,4x2,3x4,4x3矩阵
- 6.14 glProgramUniform{1234}{ifd}
- 6.15 glProgramUniform{1234}{ifd}v
- 6.16 glProgramUniform{1234}ui
- 6.17 glProgramUniform{1234}uiv
- 6.18 glProgramUniformMatrix{234}{fd}v
- 6.19 glProgramUniformMatrix{2x3,3x2,2x4,4x2,3x4,4x3}{fd}v
- 6.20 glUniformBlockBinding
- 7 原子计数器缓冲器
- 8 着色器缓冲区变量和着色器存储块
- 9 统一变量子程序
- 10采样器
- 11 图像
- 12 着色器内存访问
- 13 着色器、程序和程序管道查询
1 着色器对象
示例程序
static const GLchar *vsource[] = {
"#version 450 core\n",
"layout (location = 0) in vec3 Position;\n",
"void main(){\n",
" gl_Position = vec4(Position, 1.0);\n",
"}\n"
};
GLuint vertex, fragment; //着色器
GLuint programID; //着色器程序ID
// 顶点着色器
vertex = glCreateShader(GL_VERTEX_SHADER)
// 加载着色器程序
glShaderSource(vertex, 1, &vertexShaderSource, nullptr);
// 编译着色器
glCompileShader(vertex);
// 着色器程序
programID = glCreateProgram();
// 绑定着色器程序
glAttachShader(programID, vertex);
glAttachShader(programID, fragment);
// 链接
glLinkProgram(programID);
// 删除着色器
glDeleteShader(vertex);
glDeleteShader(fragment);
1.1 glCreateShader 创建着色器对象
uint glCreateShader( enum type );
参数:
type着色器类型
Vertex shader 顶点着色器
Tessellation control shader
Tessellation evaluation shader
Geometry shader 集合着色器
Fragment shader 片段着色器
Compute shader
返回值:
着色器对象名.
功能:
创建着色器对象
1.2 glDeleteShader 删除着色器对象
void glDeleteShader( uint shader );
参数:
shader为着色器对象名
返回值:
无.
功能:
删除着色器对象
1.3 glShaderSource 加载着色器程序
void glShaderSource( uint shader, sizei count, const
char * const *string, const int *length );
参数:
shader为着色器对象名
count为数组string和数组length的元素个数.
string为着色器程序的二维指针, 一行代码对应一个指针.
length为着色器程序的每一行的字符数.
返回值:
无.
功能:
加载着色器程序到着色器对象
1.4 glCompileShader 编译着色器
void glCompileShader( uint shader );
参数:
shader为着色器对象名
返回值:
无.
功能:
加载着色器程序到着色器对象.
1.5 glReleaseShaderCompiler 释放着色器编译器
void glReleaseShaderCompiler( void );
1.6 glIsShader 是否是着色器对象
boolean glIsShader( uint shader );
1.7 glGetShaderiv 查询着色器对象状态
void GetShaderiv( uint shader, enum pname, int *params );
参数
shader为着色器对象名.
type着色器类型:
SHADER_TYPE 着色器类型
DELETE_STATUS 着色器对象删除状态
COMPILE_STATUS 着色器程序编译状态
INFO_LOG_LENGTH
SHADER_SOURCE_LENGTH 着色器程序长度
返回值:
无.
功能:
查询着色器对象信息/状态.
2 着色器二进制
glShaderBinary
3 程序对象
3.1 glCreateProgram创建程序对象
3.2 glDeleteProgram删除程序对象
3.3 glAttachShader将着色器对象依附到程序对象
3.4 glDetachShader 将着色器对象解除与程序对象的依附
3.5 glLinkProgram链接程序对象
3.6 glUseProgram
3.7 glGetProgramiv
3.8 glProgramParameteri设置程序对象参数
3.9 glIsProgram是否是程序对象
3.10 glCreateShaderProgramv
3.11 glGetProgramInterfaceiv
3.12 glGetProgramResourceiv
3.13 glGetProgramResourceIndex
3.14 glGetProgramResourceName
3.15 glGetProgramResourceLocation
3.16 glGetProgramResourceLocationIndex
int glGetProgramResourceLocation( uint program,
enum programInterface, const char *name );
glGetProgramResourceLocationIndex
int glGetProgramResourceLocationIndex( uint program,
enum programInterface, const char *name );
4 程序管道对象
5 程序二进制
6 Uniform变量
6.1 glGetUniformLocation 获取uniform变量位置
int glGetUniformLocation( uint program, const char *name );
参数:
program: 着色器程序对象.
name: 变量名
返回值:
功能:
获取程序对象program的 uniform变量name 的地址.
glGetUniformLocation( program, name );
等价于
glGetProgramResourceLocation(program, UNIFORM, name);
6.2 glGetUniformIndices 获取uniform变量索引
6.3 glGetActiveUniformName 获取uniform变量名
void GetActiveUniformName(
uint program,
uint uniformIndex,
sizei bufSize,
sizei *length,
char *uniformName);
参数:
返回值:
功能:
void glGetActiveUniformName(program, uniformIndex, bufSize, length,uniformName );
等价于
glGetProgramResourceName(program, UNIFORM, uniformIndex, bufSize, length, uniformName);
6.4 glGetActiveUniform 获取uniform变量信息
void glGetActiveUniform(
uint program,
uint index,
sizei bufSize,
sizei *length,
int *size,
enum *type,
char *name);
6.5 glGetActiveUniformsiv
6.6 glGetUniformBlockIndex
6.7 glGetActiveUniformBlockName
6.8 glGetActiveUniformBlockiv
6.9 glGetActiveAtomicCounterBufferiv
6.10 glUniform{1234}{ifd ui}
6.11 glUniform{1234}{ifd ui}v
6.12 glUniformMatrix{234}{fd}v 设置2x2,2x3,4x4矩阵
void UniformMatrix{234}{fd}v(
int location,
sizei count,
boolean transpose,
const float *value);
6.13 glUniformMatrix{2x3,3x2,2x4,4x2,3x4,4x3}{fd}v 设置2x3,3x2,2x4,4x2,3x4,4x3矩阵
void UniformMatrix{2x3,3x2,2x4,4x2,3x4,4x3}{fd}v(
int location,
sizei count,
boolean transpose,
constfloat *value );