Exemplo n.º 1
0
void QGLRenderThread::LoadShader(QString vshader, QString fshader, QString gshader)
{
    if(ShaderProgram)
        {
        ShaderProgram->release();
        ShaderProgram->removeAllShaders();
        }
    else ShaderProgram = new QGLShaderProgram;

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

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

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


    // 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 gsh(gshader);
    if(gsh.exists())
        {
        GeometryShader = new QGLShader(QGLShader::Geometry);
        if(GeometryShader->compileSourceFile(gshader))
            ShaderProgram->addShader(GeometryShader);
        else qWarning() << "Geometry Shader Error" << GeometryShader->log();
        }
    else qWarning() << "Geometry Shader source file " << gshader << " 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();
}
void GLWidgetContext::loadShaders(QString vstring, QString fstring, QString tcstring, QString testring, QString gstring, QOpenGLShader *vshader, QOpenGLShader *fshader, QOpenGLShader *tcshader, QOpenGLShader *teshader, QOpenGLShader *gshader, QOpenGLShaderProgram *prog)
{
	QFileInfo vsh(vstring);
	if (vsh.exists()) {
		vshader = new QOpenGLShader(QOpenGLShader::Vertex);
		if (vshader->compileSourceFile(vstring)) {
			prog->addShader(vshader);
		} else {
			qWarning() << "Vertex shader error" << vshader->log();
		}
	} else {
		qWarning() << "Vertex shader source file " << vstring << " not found.";
	}

	QFileInfo fsh(fstring);
	if (fsh.exists()) {
		fshader = new QOpenGLShader(QOpenGLShader::Fragment);
		if (fshader->compileSourceFile(fstring)) {
			prog->addShader(fshader);
		} else {
			qWarning() << "Fragment shader error" << fshader->log();
		}
	} else {
		qWarning() << "Fragment shader source file " << fstring << " not found.";
	}

	QFileInfo tcsh(tcstring);
	if (tcsh.exists()) {
		tcshader = new QOpenGLShader(QOpenGLShader::TessellationControl);
		if (tcshader->compileSourceFile(tcstring)) {
			prog->addShader(tcshader);
		} else {
			qWarning() << "Tessellation control shader error" << tcshader->log();
		}
	} else {
		qWarning() << "Tesselation control source file " << tcstring << " not found.";
	}

	QFileInfo tesh(testring);
	if (tesh.exists()) {
		teshader = new QOpenGLShader(QOpenGLShader::TessellationEvaluation);
		if (teshader->compileSourceFile(testring)) {
			prog->addShader(teshader);
		} else {
			qWarning() << "Tessellation evaluation shader error" << teshader->log();
		}
	} else {
		qWarning() << "Tesselation evaluation source file " << testring << " not found.";
	}

	QFileInfo gsh(gstring);
	if (gsh.exists()) {
		gshader = new QOpenGLShader(QOpenGLShader::Geometry);
		if (gshader->compileSourceFile(gstring)) {
			prog->addShader(gshader);
		} else {
			qWarning() << "Geometry shader error" << gshader->log();
		}
	} else {
		qWarning() << "Geometry evaluation source file " << gstring << " not found.";
	}

	prog->link();
}