Beispiel #1
0
TEST_F(TransformFeedbackTest, test)
{
    std::ifstream       vsFile("data/transform_feedback.vert");
    std::ifstream       gsFile("data/transform_feedback.geom");
    Shader              vertex(GL_VERTEX_SHADER);
    Shader              geometry(GL_GEOMETRY_SHADER);
    ShaderProgram       shader;
    Query               query(GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN);
    VAO                 vao;
    VBO                 vbo;
    TFBO                tfbo;
    const GLchar*       feedbackVaryings[] = { "outValue" };
    GLfloat             data[] = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f };
    GLfloat             feedback[15];
    GLuint              primitives;

    ASSERT_TRUE(vertex.compile(vsFile));
    ASSERT_TRUE(geometry.compile(gsFile));
    shader.attach(vertex);
    shader.attach(geometry);

    shader.setTransformFeedbackVaryings(1, feedbackVaryings, GL_INTERLEAVED_ATTRIBS);
    ASSERT_TRUE(shader.link());
    shader.use();
    shader.printDebug();

    vao.bind();

    vbo.bind();
    vbo.setData(sizeof(data), data, GL_STATIC_DRAW);

    GLint inputAttrib = shader.getAttribLocation("inValue");

    vao.enableAttrib(inputAttrib);
    glVertexAttribPointer(inputAttrib, 1, GL_FLOAT, GL_FALSE, 0, 0);

    tfbo.setData(sizeof(data) * 3, nullptr, GL_STATIC_READ);
    tfbo.bindBufferBase(0);

    mogl::enable(GL_RASTERIZER_DISCARD);
    query.begin();
    TransformFeedback::begin(GL_TRIANGLES);
    glDrawArrays(GL_POINTS, 0, 5);
    TransformFeedback::end();
    query.end();
    mogl::disable(GL_RASTERIZER_DISCARD);
    mogl::Sync::flush();

    primitives = query.get<GLuint>(GL_QUERY_RESULT);
    tfbo.getSubData(0, sizeof(feedback), feedback);
    std::cout << primitives << " primitives written" << std::endl;
    for (unsigned int i = 0; i < 15; ++i)
        std::cout << feedback[i] << std::endl;
}
    void canLinkProgramWhenShadersCompiled()
    {
        ShaderProgram shaderProgram;

        Shader fragmentShader(Shader::FRAGMENT_SHADER);
        shaderProgram.attach(fragmentShader);
        fragmentShader.compile(VALID_FRAGMENT_SHADER_SOURCE);

        QVERIFY(shaderProgram.link());

        Shader vertexShader(Shader::VERTEX_SHADER);
        vertexShader.compile(VALID_VERTEX_SHADER_SOURCE);
        shaderProgram.attach(vertexShader);

        QVERIFY(shaderProgram.link());
    }
    void cannotLinkProgramWhenShaderNotCompiled()
    {
        ShaderProgram shaderProgram;
        Shader shader(Shader::FRAGMENT_SHADER);

        shaderProgram.attach(shader);

        QVERIFY(!shaderProgram.link());
        QVERIFY(!shaderProgram.getLastLinkLog().empty());
    }
    void canCopyProgram()
    {
        ShaderProgram shaderProgram;

        Shader fragmentShader(Shader::FRAGMENT_SHADER);
        fragmentShader.compile(VALID_FRAGMENT_SHADER_SOURCE);
        shaderProgram.attach(fragmentShader);

        Shader vertexShader(Shader::VERTEX_SHADER);
        vertexShader.compile(VALID_VERTEX_SHADER_SOURCE);
        shaderProgram.attach(vertexShader);

        ShaderProgram copy = shaderProgram;

        QVERIFY(copy.exists());
        QVERIFY(copy.getId() != 0);
        QVERIFY(glIsProgram(copy.getId()));
        QVERIFY(copy.has(fragmentShader));
        QVERIFY(copy.has(vertexShader));
        QVERIFY(copy.link());
    }
    void canAttachDetachShader()
    {
        ShaderProgram shaderProgram;
        Shader shader(Shader::FRAGMENT_SHADER);

        QVERIFY(shaderProgram.attach(shader));

        QVERIFY(shaderProgram.has(shader));

        QVERIFY(shaderProgram.detach(shader));
        QVERIFY(!shaderProgram.has(shader));
    }
    void canAssignProgram()
    {
        ShaderProgram shaderProgram;

        Shader fragmentShader(Shader::FRAGMENT_SHADER);
        fragmentShader.compile(VALID_FRAGMENT_SHADER_SOURCE);
        shaderProgram.attach(fragmentShader);

        Shader vertexShader(Shader::VERTEX_SHADER);
        vertexShader.compile(VALID_VERTEX_SHADER_SOURCE);
        shaderProgram.attach(vertexShader);

        ShaderProgram copy;
        Shader anotherShader(Shader::VERTEX_SHADER);
        copy.attach(anotherShader);
        QVERIFY(copy.has(anotherShader));

        copy = shaderProgram;

        QVERIFY(copy.has(fragmentShader));
        QVERIFY(copy.has(vertexShader));
        QVERIFY(!copy.has(anotherShader));
        QVERIFY(copy.link());
    }
Beispiel #7
0
void GLShaderDev::buildCurrentProject()
{
    ShaderProgram*  prog = new ShaderProgram;
    bool            success = true;
    int             i = 1;
    OutputParser    parser(_glInfo.getVendor());
    const ShaderProject::Stages&  stages = _projectManager.getCurrentProject()->getStages();

    _editor->saveAll();
    _output->getModel()->clear();
    _buildOutputDock->setVisible(true);

    for (ShaderProject::Stages::const_iterator it = stages.begin(); it != stages.end(); ++it)
    {
        QFile       file(it->second);
        QFileInfo       fileInfo(file);
        ShaderObject*   obj = new ShaderObject;
        QString     str = QString(tr("[%1/%2] Compiling %3...")).arg(i).arg(stages.size()).arg(fileInfo.fileName());

        _output->getModel()->addItem(OutputItem(str, OutputItem::InformationItem));
        if (!file.open(QIODevice::ReadOnly))
            throw (GlsdException(std::string("Could not open shader file") + it->second.toStdString())); // TODO proper exception handling
            if (!obj->compile(QString(file.readAll()).toStdString(), static_cast<ShaderObject::ShaderType>(it->first)))
            {
                _output->getModel()->addItems(parser.parse(obj->getErrorLog(), fileInfo.absoluteFilePath().toStdString()));
                success = false;
            }
            prog->attach(*obj);
        ++i;
    }

    _output->getModel()->addItem(OutputItem(tr("Linking shader..."), OutputItem::InformationItem));
    if (!prog->link())
    {
        _output->getModel()->addItem(OutputItem(prog->getLog().c_str(), OutputItem::ErrorItem));
        success = false;
    }

    if (!success)
    {
        _output->getModel()->addItem(OutputItem(tr("*** Compilation failed ***"), OutputItem::StandardItem));
        return;
    }
    _output->getModel()->addItem(OutputItem(tr("*** Compilation successful ***"), OutputItem::StandardItem));
    // FIXME Set shader properly, with attributes correctly bound
    _glwidget->setShader(prog);
    prog->printDebug();
}
inline bool OmniStereoGraphicsRenderer::onCreate() {
  mOmni.onCreate();

  Shader vert, frag;
  vert.source(OmniStereo::glsl() + vertexCode(), Shader::VERTEX).compile();
  vert.printLog();
  frag.source(fragmentCode(), Shader::FRAGMENT).compile();
  frag.printLog();
  mShader.attach(vert).attach(frag).link();
  mShader.printLog();
  mShader.begin();
  mShader.uniform("lighting", 0.0);
  mShader.uniform("texture", 0.0);
  mShader.end();

  return true;
}
    void canDetachAllShaders()
    {
        ShaderProgram shaderProgram;
        Shader shader1(Shader::VERTEX_SHADER);
        Shader shader2(Shader::FRAGMENT_SHADER);

        QVERIFY(shaderProgram.attach(shader1));
        QVERIFY(shaderProgram.attach(shader2));

        QVERIFY(shaderProgram.has(shader1));
        QVERIFY(shaderProgram.has(shader2));

        shaderProgram.detachAllShaders();

        QVERIFY(!shaderProgram.has(shader1));
        QVERIFY(!shaderProgram.has(shader2));
    }
	bool onCreate(){

		// initialize the shaders:
		frag.compile();
		vert.compile();
		shaderprogram.attach(vert);
		shaderprogram.attach(frag);
		shaderprogram.link();
		shaderprogram.listParams();
		printf("frag %s\n", frag.log());
		printf("vert %s\n", vert.log());


		// draw the models into a display list:
		scene_list.begin();
		Mesh mesh;
			for (unsigned i=0; i<ascene->meshes(); i++) {
				ascene->mesh(i, mesh);
				gl.draw(mesh);
			}
		scene_list.end();

		return true;
	}