本文整理汇总了C++中GLContext::fLinkProgram方法的典型用法代码示例。如果您正苦于以下问题:C++ GLContext::fLinkProgram方法的具体用法?C++ GLContext::fLinkProgram怎么用?C++ GLContext::fLinkProgram使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GLContext
的用法示例。
在下文中一共展示了GLContext::fLinkProgram方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
void
GLBlitTextureImageHelper::UseBlitProgram()
{
GLContext *gl = mCompositor->gl();
if (mBlitProgram) {
gl->fUseProgram(mBlitProgram);
return;
}
mBlitProgram = gl->fCreateProgram();
GLuint shaders[2];
shaders[0] = gl->fCreateShader(LOCAL_GL_VERTEX_SHADER);
shaders[1] = gl->fCreateShader(LOCAL_GL_FRAGMENT_SHADER);
const char *blitVSSrc =
"attribute vec2 aVertex;"
"attribute vec2 aTexCoord;"
"varying vec2 vTexCoord;"
"void main() {"
" vTexCoord = aTexCoord;"
" gl_Position = vec4(aVertex, 0.0, 1.0);"
"}";
const char *blitFSSrc = "#ifdef GL_ES\nprecision mediump float;\n#endif\n"
"uniform sampler2D uSrcTexture;"
"varying vec2 vTexCoord;"
"void main() {"
" gl_FragColor = texture2D(uSrcTexture, vTexCoord);"
"}";
gl->fShaderSource(shaders[0], 1, (const GLchar**) &blitVSSrc, nullptr);
gl->fShaderSource(shaders[1], 1, (const GLchar**) &blitFSSrc, nullptr);
for (int i = 0; i < 2; ++i) {
GLint success, len = 0;
gl->fCompileShader(shaders[i]);
gl->fGetShaderiv(shaders[i], LOCAL_GL_COMPILE_STATUS, &success);
NS_ASSERTION(success, "Shader compilation failed!");
if (!success) {
nsAutoCString log;
gl->fGetShaderiv(shaders[i], LOCAL_GL_INFO_LOG_LENGTH, (GLint*) &len);
log.SetCapacity(len);
gl->fGetShaderInfoLog(shaders[i], len, (GLint*) &len, (char*) log.BeginWriting());
log.SetLength(len);
printf_stderr("Shader %d compilation failed:\n%s\n", i, log.get());
return;
}
gl->fAttachShader(mBlitProgram, shaders[i]);
gl->fDeleteShader(shaders[i]);
}
gl->fBindAttribLocation(mBlitProgram, 0, "aVertex");
gl->fBindAttribLocation(mBlitProgram, 1, "aTexCoord");
gl->fLinkProgram(mBlitProgram);
GLint success, len = 0;
gl->fGetProgramiv(mBlitProgram, LOCAL_GL_LINK_STATUS, &success);
NS_ASSERTION(success, "Shader linking failed!");
if (!success) {
nsAutoCString log;
gl->fGetProgramiv(mBlitProgram, LOCAL_GL_INFO_LOG_LENGTH, (GLint*) &len);
log.SetCapacity(len);
gl->fGetProgramInfoLog(mBlitProgram, len, (GLint*) &len, (char*) log.BeginWriting());
log.SetLength(len);
printf_stderr("Program linking failed:\n%s\n", log.get());
return;
}
gl->fUseProgram(mBlitProgram);
gl->fUniform1i(gl->fGetUniformLocation(mBlitProgram, "uSrcTexture"), 0);
}