在opengl shader的编写过程中,常用的两种方式是:
- 将shader 定义为字符串,然后使用glShaderSource加载
static const char *vs =
"attribute vec4 vertexIn;\n"
"attribute vec2 textureIn;\n"
"varying vec2 textureOut;\n"
"void main(void)\n"
"{\n"
"gl_Position = vertexIn;\n"
"textureOut = textureIn;\n"
"}\n";
static const char *fs =
"varying vec2 textureOut;\n"
"uniform sampler2D tex_y;\n"
"uniform sampler2D tex_u;\n"
"uniform sampler2D tex_v;\n"
"void main(void)\n"
"{\n"
"vec3 yuv;\n"
"vec3 rgb;\n"
"yuv.x = texture2D(tex_y, textureOut).r;\n"
"yuv.y = texture2D(tex_u, textureOut).r - 0.5;\n"
"yuv.z = texture2D(tex_v, textureOut).r - 0.5;\n"
"rgb = mat3(1, 1, 1, 0, -0.39465, 2.03211, 1.13983, -0.58060, 0) * yuv;\n"