Exemplo n.º 1
0
void AssimpScene::draw(
    OpenGLFunctions & gl
,   QOpenGLShaderProgram & program
,   const GLenum mode)
{
    if (!m_valid)
        return;

    if (!program.isLinked())
        return;

    std::vector<AssimpMesh *>::const_iterator i = m_meshes.begin();
    const std::vector<AssimpMesh *>::const_iterator iEnd = m_meshes.end();

    program.bind();
    program.setUniformValue("model", m_transform * m_normalize);

    for (; i != iEnd; ++i)
    {
        AssimpMesh * mesh(*i);

        program.setUniformValue("diffuse", mesh->material.diffuse);
        program.setUniformValue("ambient", mesh->material.ambient);
        program.setUniformValue("specular", mesh->material.specular);
        program.setUniformValue("emissive", mesh->material.emissive);
        program.setUniformValue("shininess", mesh->material.shininess);
        program.setUniformValue("texCount", mesh->material.texCount);

        if (mesh->material.texCount > 0)
        {
            program.setUniformValue("difftex", 0);
            gl.glActiveTexture(GL_TEXTURE0);            
            gl.glBindTexture(GL_TEXTURE_2D, mesh->material.texture);
        }

        mesh->vao.bind();
        gl.glDrawElements(mode, mesh->faces * 3, GL_UNSIGNED_INT, nullptr);
        mesh->vao.release();

        if (mesh->material.texCount > 0)
            gl.glBindTexture(GL_TEXTURE_2D, 0);
    }
    program.release();
}