我正在使用OpenGL为Windows平台编写After Effects插件。初始化并编译我的着色器程序后,我打电话给
glGetProgramiv(inData.mProgramObjSu, GL_ATTACHED_SHADERS, &size);
我得到了值3(这是正确的,因为我附上了几何着色器)。
我还使用各种属性名称调用glGetAttribLocation
并获取有效值。当稍后调用我的渲染函数时,着色器程序完全没用,每次调用glGetattribLocation
都返回-1,前面使用的属性字符串相同,glGetProgramiv(inData.mProgramObjSu, GL_ATTACHED_SHADERS, &size);
返回的大小为2.我有在OpenGL编程方面有一点经验,但我之前从未遇到过这样的问题。
这是着色器初始化代码:
GLint vertCompiledB = 0;
GLint geoCompiledB = 0;
GLint fragCompiledB = 0;
GLint linkedB = 0;
// Create vertex shader
inData.mVertexShaderSu = glCreateShader( GL_VERTEX_SHADER );
glShaderSource( inData.mVertexShaderSu, 1, &inVertexShader, nullptr );
glCompileShader( inData.mVertexShaderSu);
glGetShaderiv( inData.mVertexShaderSu, GL_COMPILE_STATUS, &vertCompiledB );
char str[4096];
if(!vertCompiledB)
{
glGetShaderInfoLog(inData.mVertexShaderSu, sizeof(str), NULL, str);
GL_CHECK(AESDK_OpenGL_ShaderInit_Err);
}
// Create geometry shader
inData.mGeometryShaderSu = glCreateShader( GL_GEOMETRY_SHADER );
glShaderSource( inData.mGeometryShaderSu, 1, &inGeometryShader, nullptr );
glCompileShader( inData.mGeometryShaderSu);
glGetShaderiv( inData.mGeometryShaderSu, GL_COMPILE_STATUS, &geoCompiledB );
if(!geoCompiledB)
{
glGetShaderInfoLog(inData.mGeometryShaderSu, sizeof(str), NULL, str);
GL_CHECK(AESDK_OpenGL_ShaderInit_Err);
}
// Create fragment shader
inData.mFragmentShaderSu = glCreateShader( GL_FRAGMENT_SHADER );
glShaderSource( inData.mFragmentShaderSu, 1, &inFragmentShader, nullptr );
glCompileShader( inData.mFragmentShaderSu );
glGetShaderiv( inData.mFragmentShaderSu, GL_COMPILE_STATUS,&fragCompiledB );
if(!fragCompiledB)
{
glGetShaderInfoLog( inData.mFragmentShaderSu, sizeof(str), NULL, str );
GL_CHECK(AESDK_OpenGL_ShaderInit_Err);
}
// Create a program object and attach the two compiled shaders...
inData.mProgramObjSu = glCreateProgram();
glAttachShader( inData.mProgramObjSu, inData.mVertexShaderSu );
glAttachShader( inData.mProgramObjSu, inData.mGeometryShaderSu );
glAttachShader( inData.mProgramObjSu, inData.mFragmentShaderSu );
// Link the program object
glLinkProgram( inData.mProgramObjSu );
glGetProgramiv( inData.mProgramObjSu, GL_LINK_STATUS, &linkedB );
inData.mPosAttribLoc = glGetAttribLocation(inData.mProgramObjSu, "pos");
inData.mNormAttribLoc = glGetAttribLocation(inData.mProgramObjSu, "norm");
inData.mMVPUnifLoc = glGetUniformLocation(inData.mProgramObjSu, "mvp");
inData.mNormMatUnifLoc = glGetUniformLocation(inData.mProgramObjSu, "normMat");
inData.mLineWidthUnifLoc = glGetUniformLocation(inData.mProgramObjSu, "width");
inData.mEdgeWidthRatioUnifLoc = glGetUniformLocation(inData.mProgramObjSu, "edgeWidthRatio");
inData.mStrokeOverflowUnifLoc = glGetUniformLocation(inData.mProgramObjSu, "strokeOverflow");
int length;
int size;
GLenum type;
GLchar name[40];
glGetActiveUniform(inData.mProgramObjSu, 1, 40, &length, &size, &type, name);
glGetProgramiv(inData.mProgramObjSu, GL_ATTACHED_SHADERS, &size);
if( !linkedB )
{
int length;
glGetShaderInfoLog( inData.mProgramObjSu, 1000, &length, str );
GL_CHECK(AESDK_OpenGL_ShaderInit_Err);
}