fsmoke
9th July 2014, 09:09
I need to get uniform names from ogl shaders(for simple editor project). I did not want to parse shaders by hands, so I writed some tricky code :) In Qt4 this code works just fine, but in Qt5 appears crash at ctx.create(). This crash deep in Qt Gui library, somewhere in QWindow…
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);
}
}
What you think about it? May be it is bug in library. Or it’s my bug. Anyway, how can I get uniform names – may be exists more beautiful solutions for this task?
PS
I post this question on qt-project forum but still no replies... So I decide copy my question here
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);
}
}
What you think about it? May be it is bug in library. Or it’s my bug. Anyway, how can I get uniform names – may be exists more beautiful solutions for this task?
PS
I post this question on qt-project forum but still no replies... So I decide copy my question here