PDA

View Full Version : QGLShaderProgram works on Debug mode, fails on running in Release.



escobar
21st September 2013, 18:03
I'm loosing my mind trying to imagine what the hell I'm missing.

This is my first time with OpenGL with Qt and I wanna use custom shaders, all seems to work properly on Debug mode but in Release


bool __thiscall QGLShaderPrivate::create(void): Could not create shader of type 1.
Vertex Shader Error ""
bool __thiscall QGLShaderPrivate::create(void): Could not create shader of type 2.
Fragment Shader Error ""
Shader Program Linker Error ""

PS. I forget to say that this errors are shown in the console but the app doesn't crash, it just doesn't work properly.


Thanks in advance for any help!

ChrisW67
22nd September 2013, 01:21
How about sharing some information about what your code is doing to trigger this warning from the Qt internals.
Or whether the fault occurs inside an IDE or in a standalone deployed environment

saman_artorious
22nd September 2013, 06:11
Your shader program has not been linked yet. That's why you receive the warning in the console.

escobar
22nd September 2013, 19:05
Thank you both!

About the test both were made using the IDE but in deployment Debug runs fine and Release seems to have the same problems (but obviously I don't get that console messages).

Here is my loading routine (pretty basic):



void MyGLWidget::loadShader(QString vshader, QString fshader)
{
if(ShaderProgram)
{
ShaderProgram->release();
ShaderProgram->removeAllShaders();
}
else ShaderProgram = new QGLShaderProgram;

if(VertexShader)
{
delete VertexShader;
VertexShader = NULL;
}

if(FragmentShader)
{
delete FragmentShader;
FragmentShader = NULL;
}

std::cout << "loadShader "<<vshader.toStdString()<<" "<<fshader.toStdString()<<std::endl;
// load and compile vertex shader
QFileInfo vsh(vshader);
if(vsh.exists())
{
VertexShader = new QGLShader(QGLShader::Vertex);
if(VertexShader->compileSourceFile(vshader))
ShaderProgram->addShader(VertexShader);
else qWarning() << "Vertex Shader Error" << VertexShader->log();
}
else qWarning() << "Vertex Shader source file " << vshader << " not found.";

// load and compile fragment shader
QFileInfo fsh(fshader);
if(fsh.exists())
{
FragmentShader = new QGLShader(QGLShader::Fragment);
if(FragmentShader->compileSourceFile(fshader))
ShaderProgram->addShader(FragmentShader);
else qWarning() << "Fragment Shader Error" << FragmentShader->log();
}
else qWarning() << "Fragment Shader source file " << fshader << " not found.";

if(!ShaderProgram->link())
{
qWarning() << "Shader Program Linker Error" << ShaderProgram->log();
}
else
ShaderProgram->bind();
}

And the problem is shown in the IDE for Release mode:


bool __thiscall QGLShaderPrivate::create(void): Could not create shader of type 1.
Vertex Shader Error ""
bool __thiscall QGLShaderPrivate::create(void): Could not create shader of type 2.
Fragment Shader Error ""
Shader Program Linker Error ""
GPU: "GeForce GTX 560/PCIe/SSE2"
OpenGL: "2.1.2"
GLSL: "1.20 NVIDIA via Cg compiler"


Thanks in advance.

saman_artorious
23rd September 2013, 11:24
Would you click Projects and see whether "Shadow Build" is ticked. If it is, remove it. Now build again and run in release mode.

escobar
23rd September 2013, 13:08
That's even more strange... if I disable Shadow Build it doesn't run:

The program has unexpectedly finished. ...Test3.exe exited with code -1073741515

Edit: I found that this means that is missing some libs, it happens since disabling shadow build it is placed in another directory, after putting that dlls there I have the same "bool __thiscall QGLShaderPrivate::create(void): Could not create shader of type" error.

So that didn't solve nothing but thank you for your time anyway.

saman_artorious
23rd September 2013, 13:24
Would you upload your shader programs in a different way. Add vertext.sh and fragment.sh to your src. Then try linking them this way as below:



//#version 130

precision mediump float;

uniform mat4 mvpMatrix;

attribute vec4 vertex;
attribute float color;

varying float varyingColor;

void main(void)
{
varyingColor = color;
gl_Position = mvpMatrix * vertex;
}

fragment shader has the same format, you know it. Then do this in the code:



initCommon();

shaderProgram.addShaderFromSourceFile(QGLShader::V ertex, ":/vertexShader.vsh");

shaderProgram.addShaderFromSourceFile(QGLShader::F ragment, ":/fragmentShader.fsh");

if(!shaderProgram.link())
{
exit(1);
}



initCommon() is:


void GlWidget::initCommon()
{
//qglClearColor(QColor(Qt::black));
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);

glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}



check this method and let us know about the result.

PS: don't forget to upload your shaders to your resources.

escobar
23rd September 2013, 13:51
No luck, also I tried to load from "./a.vert" "./a.frag" it founds the files but they aren't created properly.

:confused:

It looks that the problem is during the compilation not on loading.

compileSourceCode(code) doesn't work neither on Release but works on Debug.

escobar
26th September 2013, 19:35
I fixed it... just by updating to Qt 5.1.1 :confused: