fmt.setVersion(2, 0);
fmt.
setProfile(QGLFormat::CompatibilityProfile);
if (ctx.create())
{
ctx.makeCurrent();
QGLFunctions fncs(&ctx);
QGLShaderProgram prg(&ctx);
bool needToLink = false;
QGLShader vs(QGLShader::Vertex, &ctx);
if (!vertex.isEmpty() && (needToLink |= vs.compileSourceCode(vertex)))
prg.addShader(&vs);
QGLShader fs(QGLShader::Fragment, &ctx);
if (!fragment.isEmpty() && (needToLink |= fs.compileSourceCode(fragment)))
prg.addShader(&fs);
if (!needToLink)
return;
Q_ASSERT(prg.link());
GLint total = -1;
fncs.glGetProgramiv( prg.programId(), GL_ACTIVE_UNIFORMS, &total );
for(GLint i = 0; i < total; ++i)
{
GLsizei nameLen = -1;
GLint num = -1;
GLenum type = GL_ZERO;
char name[100];
fncs.glGetActiveUniform( prg.programId(), i, sizeof(name)-1,
&nameLen, &num, &type, name );
name[nameLen] = 0;
uniforms << glsl_var_type(shaderParamType(type), name, num);
}
}
QGLFormat fmt = QGLFormat::defaultFormat();
fmt.setVersion(2, 0);
fmt.setProfile(QGLFormat::CompatibilityProfile);
QWidget temp;
QGLContext ctx(fmt, &temp);
if (ctx.create())
{
ctx.makeCurrent();
QGLFunctions fncs(&ctx);
QGLShaderProgram prg(&ctx);
bool needToLink = false;
QGLShader vs(QGLShader::Vertex, &ctx);
if (!vertex.isEmpty() && (needToLink |= vs.compileSourceCode(vertex)))
prg.addShader(&vs);
QGLShader fs(QGLShader::Fragment, &ctx);
if (!fragment.isEmpty() && (needToLink |= fs.compileSourceCode(fragment)))
prg.addShader(&fs);
if (!needToLink)
return;
Q_ASSERT(prg.link());
const QGLContext *context = QGLContext::currentContext();
GLint total = -1;
fncs.glGetProgramiv( prg.programId(), GL_ACTIVE_UNIFORMS, &total );
for(GLint i = 0; i < total; ++i)
{
GLsizei nameLen = -1;
GLint num = -1;
GLenum type = GL_ZERO;
char name[100];
fncs.glGetActiveUniform( prg.programId(), i, sizeof(name)-1,
&nameLen, &num, &type, name );
name[nameLen] = 0;
uniforms << glsl_var_type(shaderParamType(type), name, num);
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks