我有一些OpenGL 2.x代码,我想运行这些着色器:
static const char* YUYV_VS = ""
"#version 150\n"
"uniform mat4 u_pm;"
"uniform mat4 u_mm;"
"in vec4 a_pos;"
"in vec2 a_tex;"
"out vec2 v_tex;"
"void main() {"
" gl_Position = u_pm * u_mm * a_pos; "
" v_tex = a_tex;"
"}"
"";
static const char* YUYV_FS = ""
"#version 150\n"
"uniform sampler2D u_tex;"
"out vec4 outcol;"
"in vec2 v_tex;"
"const vec3 R_cf = vec3(1.164383, 0.000000, 1.596027);"
"const vec3 G_cf = vec3(1.164383, -0.391762, -0.812968);"
"const vec3 B_cf = vec3(1.164383, 2.017232, 0.000000);"
"const vec3 offset = vec3(-0.0625, -0.5, -0.5);"
"void main() {"
" vec3 tc = texture( u_tex, v_tex ).rgb;"
" vec3 yuv = vec3(tc.g, tc.b, tc.r);"
" yuv += offset;"
" outcol.r = dot(yuv, R_cf);"
" outcol.g = dot(yuv, G_cf);"
" outcol.b = dot(yuv, B_cf);"
" outcol.a = 1.0;"
"}"
"";
麻烦的是,OpenGL 2.x不支持版本150的着色器。有没有人知道如何将着色器反向转换为2.x?
答案 0 :(得分:3)
使用this procedure,但从GLSL 1.50 spec开始,而不是从1.30开始。
答案 1 :(得分:1)
文件shader.vsh
uniform mat4 u_pm;
uniform mat4 u_mm;
attribute vec4 a_pos;
attribute vec2 v_tex;
varying vec2 fragmentTextureCoordinates;
void main() {
gl_Position = u_pm * u_mm * a_pos;
fragmentTextureCoordinates = v_tex;
}
文件shader.fsh
uniform sampler2D u_tex;
varying vec2 fragmentTextureCoordinates;
const vec3 R_cf = vec3(1.164383, 0.000000, 1.596027);
const vec3 G_cf = vec3(1.164383, -0.391762, -0.812968);
const vec3 B_cf = vec3(1.164383, 2.017232, 0.000000);
const vec3 offset = vec3(-0.0625, -0.5, -0.5);
void main() {
vec3 tc = texture2D(u_tex, fragmentTextureCoordinates).rgb;
vec3 yuv = vec3(tc.g, tc.b, tc.r);
yuv += offset;
gl_FragColor.r = dot(yuv, R_cf);
gl_FragColor.g = dot(yuv, G_cf);
gl_FragColor.b = dot(yuv, B_cf);
gl_FragColor.a = 1.0;
}
那会有用吗?您可能必须调整传递给程序/技术/着色器的变量。