Example #1
0
void GL::bufferData(Enum target, Sizeiptr size, const void * data, Enum usage)
{
	g_OpenGLFunctions.glBufferData(target, size, data, usage);
	CHECK_GL_ERROR4(glBufferData, target, size, data, usage);
}
Example #2
0
void visual_unit_factory::generate_geometry_parallel( dataset_db &db, QGLFunctions qglf ){

    //
    helpers::debug_out( QString("creating geometry for dataset: [%1]...").arg( db.name()) );

    //  Create the buffers.
    //
    qglf.glGenBuffers(2,_active_visual_unit->_info._vbo_ids);

    //  How many threads will we use?
    //
    int ideal = QThread::idealThreadCount();

    //  Go through each point in the database.
    //
    std::vector<Vertex> _vertices;
    std::vector<GLshort> _indices;
    int num_points = db.num_points();
    if( num_points > 0 ){

        int points_per_thread = num_points / ideal;

        //  Create the workers.
        //
        std::vector<buffer_worker*> workers;
        std::vector<QThread*> threads;
        for( int ii=0; ii<ideal; ii++ )
            workers.push_back( new buffer_worker( points_per_thread, points_per_thread*ii, &db ) );

        //  Thread our workers.
        //
        for( int ii=0; ii<workers.size(); ii++ ){
            buffer_worker *worker = workers.at(ii);
            QThread* thread = new QThread;
            worker->moveToThread(thread);
            connect(worker, SIGNAL(error(QString)), this, SLOT(errorString(QString)));
            connect(thread, SIGNAL(started()), worker, SLOT(process()));
            connect(worker, SIGNAL(finished()), thread, SLOT(quit()));
            //connect(worker, SIGNAL(finished()), worker, SLOT(deleteLater()));
            connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
            thread->start();
            threads.push_back(thread);
        }

        //  Wait for all workers to finish.
        //  Break when all of our workers are marked finished.
        //
        unsigned int stamp = helpers::timestamp();
        bool done=false;
        while( !done ){
            done=true;
            for( int ii=0; ii<workers.size(); ii++ ){
                if( !workers.at(ii)->_finished )
                    done=false;
            }
        }
        float elapsed = helpers::milliseconds_to_seconds( helpers::time_elapsed(stamp) );
        helpers::debug_out(QString("threads finished: [seconds: %1]").arg(elapsed));

        //  Concat all of the fragments.
        //

        //  Find our amounts for reserving.
        //
        int fragments_verts_count = 0;
        int fragments_index_count = 0;
        for( int ii=0; ii<workers.size(); ii++ ){
            buffer_worker *worker = workers.at(ii);
            fragments_verts_count += worker->_fragment_vertices.size();
            fragments_index_count += worker->_fragment_indices.size();
        }
        _vertices.reserve( fragments_verts_count );
        _indices.reserve( fragments_index_count );

        //  Insert all fragments.
        //
        for( int ii=0; ii<workers.size(); ii++ ){
            buffer_worker *worker = workers.at(ii);
            _vertices.insert( _vertices.end(), worker->_fragment_vertices.begin(), worker->_fragment_vertices.end() );
            _indices.insert( _indices.end(), worker->_fragment_indices.begin(), worker->_fragment_indices.end() );
        }

    }

    //
    else
        push_fake_piechart();

    //
    helpers::debug_out( QString("Created glyphs [num: %1]").arg( num_points ) );

    //
    helpers::check_error_gl(20);

    //  Vertices.
    //
    qglf.glBindBuffer(GL_ARRAY_BUFFER, _active_visual_unit->_info._vbo_ids[VBO_ELEMENT_VERTEX]);
    qglf.glBufferData(GL_ARRAY_BUFFER, _vertices.size() * sizeof(Vertex), &_vertices[0], GL_STATIC_DRAW);

    //  Indices.
    //
    qglf.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _active_visual_unit->_info._vbo_ids[VBO_ELEMENT_INDICES]);
    qglf.glBufferData(GL_ELEMENT_ARRAY_BUFFER, _indices.size() * sizeof(GLushort), &_indices[0], GL_STATIC_DRAW);

    //
    helpers::check_error_gl(21);

    //  How many vertices.
    //
    helpers::debug_out( QString("...num vertices [val:%1]")
                        .arg(_vertices.size()) );
    _active_visual_unit->_info._draw_amount = _vertices.size();

    //  How many charts?
    //
    //_active_visual_unit->_info._num_charts = _vertices.count() / _active_visual_unit->_info._verts_in_single_chart;

    //  How many megabytes is our vbo.
    //
    int nBufferSize = 0;
    qglf.glGetBufferParameteriv(GL_ARRAY_BUFFER, GL_BUFFER_SIZE, &nBufferSize);
    int originalVertexArraySize = ( nBufferSize / sizeof(Vertex) );
    helpers::debug_out( QString("...vbo size [size:%1mb]")
                        .arg( (qreal)originalVertexArraySize / (qreal)1000000.0 ) );

    //
    _active_visual_unit->_info._ready_to_draw=true;
}
Example #3
0
//  Geometry.
//
//++++++++++++++++++++++
void visual_unit_factory::generate_geometry( dataset_db &db, QGLFunctions qglf ){

    //
    helpers::debug_out( QString("creating geometry for dataset: [%1]...").arg( db.name()) );

    //  Create the buffers.
    //
    qglf.glGenBuffers(2,_active_visual_unit->_info._vbo_ids);

    //  Get our list of colors.
    //
    std::vector<QVector3D> colors = db.descriptor()->list_color();
    QVector3D true_color;

    //  Go through each point in the database.
    //
    unsigned int stamp = helpers::timestamp();
    bool result=true;
    model_point point;
    int num_points = db.num_points();
    //int num_points = 10;
    for( int ii=0; ii<num_points; ii++ ){

        //  Get the next point.
        //
        result = db.get_point( ii, &point, true );

        //  End if we didn't get a point.
        //
        if( !result )
            break;

        //  Find the true color.
        //
        true_color = db.descriptor()->class_option_to_color( point._attribute_class );

        //  Create a piechart for the point.
        //
        push_piechart( point._position.x(), point._position.y(), point._probability_values, true_color, colors, 0.015 );
    }

    float elapsed = helpers::milliseconds_to_seconds( helpers::time_elapsed(stamp) );
    helpers::debug_out(QString("glyphs finished: [seconds: %1]").arg(elapsed));

    //  Empty dataset?
    //
    if( num_points == 0 )
        push_fake_piechart();

    //
    helpers::debug_out( QString("Created glyphs [num: %1]").arg( db.num_points() ) );

    //
    helpers::check_error_gl(20);

    //  Vertices.
    //
    qglf.glBindBuffer(GL_ARRAY_BUFFER, _active_visual_unit->_info._vbo_ids[VBO_ELEMENT_VERTEX]);
    qglf.glBufferData(GL_ARRAY_BUFFER, _active_visual_unit->_info._vertices.count() * sizeof(Vertex), &_active_visual_unit->_info._vertices[0], GL_STATIC_DRAW);

    //  Indices.
    //
    qglf.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _active_visual_unit->_info._vbo_ids[VBO_ELEMENT_INDICES]);
    qglf.glBufferData(GL_ELEMENT_ARRAY_BUFFER, _active_visual_unit->_info._indices.count() * sizeof(GLushort), &_active_visual_unit->_info._indices[0], GL_STATIC_DRAW);

    //
    helpers::check_error_gl(21);

    //  How many vertices.
    //
    helpers::debug_out( QString("...num vertices [val:%1]")
                        .arg(_active_visual_unit->_info._vertices.count()) );
    _active_visual_unit->_info._draw_amount = _active_visual_unit->_info._vertices.count();

    //  How many charts?
    //
    _active_visual_unit->_info._num_charts = _active_visual_unit->_info._vertices.count() / _active_visual_unit->_info._verts_in_single_chart;

    //  How many megabytes is our vbo.
    //
    int nBufferSize = 0;
    qglf.glGetBufferParameteriv(GL_ARRAY_BUFFER, GL_BUFFER_SIZE, &nBufferSize);
    int originalVertexArraySize = ( nBufferSize / sizeof(Vertex) );
    helpers::debug_out( QString("...vbo size [size:%1mb]")
                        .arg( (qreal)originalVertexArraySize / (qreal)1000000.0 ) );

    //
    _active_visual_unit->_info._ready_to_draw=true;
}
Example #4
0
void SW::GLViewer::init()
{

    setGL();
    initGLSL();

#if BUFFER_
    //glClearColor(0.0, 0.0, 0.0, 0.0);

    //glDisable(GL_DITHER);

    glShadeModel(GL_FLAT);

    //glEnable(GL_DEPTH_TEST);

    enum{Vertices, Color, Elements, NumVBOs};
    GLuint buffers[NumVBOs];

    // glew init is very important or errors occur
    glewInit();
    // generate vertex arrays, and each array is corresponding to a object to be render
    glGenVertexArrays(1, &arrayId);

#ifdef QT_BUFFER
    QGLFunctions qtgl;
    qtgl.initializeGLFunctions(0);
#endif

    // 3D world coordinate of points
#ifdef QT_BUFFER
    QVector<QVector3D> Verts;
    Verts.append(QVector3D(-1.0, -1.0, -1.0));
    Verts.append(QVector3D(-1.0, -1.0, 1.0));
    Verts.append(QVector3D(-1.0, 1.0, -1.0));
    Verts.append(QVector3D(-1.0, 1.0, 1.0));
    Verts.append(QVector3D(1.0, -1.0, -1.0));
    Verts.append(QVector3D(1.0, -1.0, 1.0));
    Verts.append(QVector3D(1.0, 1.0, -1.0));
    Verts.append(QVector3D(1.0, 1.0, 1.0));
#else


    GLfloat Verts[][3] = {
        {-1.0, -1.0, -1.0},
        {-1.0, -1.0, 1.0},
        {-1.0, 1.0, -1.0},
        {-1.0, 1.0, 1.0},
        {1.0,  -1.0, -1.0},
        {1.0, -1.0, 1.0},
        {1.0, 1.0, -1.0},
        {1.0, 1.0, 1.0},
    };
#endif

    // colors of points
#ifdef QT_BUFFER
    QVector<QVector3D> Colors;
    Colors.append(QVector3D(0, 0.0, 0.0));
    Colors.append(QVector3D(0, 0.0, 1.0));
    Colors.append(QVector3D(0, 1.0, 0.0));
    Colors.append(QVector3D(0, 1.0, 1.0));
    Colors.append(QVector3D(1.0, 0.0, 0.0));
    Colors.append(QVector3D(1.0, 0.0, 1.0));
    Colors.append(QVector3D(1.0, 1.0, 0.0));
    Colors.append(QVector3D(1.0, 1.0, 1.0));
#else
    GLfloat Colors[][3] = {
        {0.0, 0.0, 0.0},
        {0.0, 0.0, 1.0},
        {0.0, 1.0, 0.0},
        {0.0, 1.0, 1.0},
        {1.0, 0.0, 0.0},
        {1.0, 0.0, 1.0},
        {1.0, 1.0, 0.0},
        {1.0, 1.0, 1.0},
    };
#endif

    // indices of points
#ifdef QT_BUFFER
    QVector<uint> Indices;
    Indices.append(0);Indices.append(1);Indices.append(3);Indices.append(2);
    Indices.append(4);Indices.append(6);Indices.append(7);Indices.append(5);
    Indices.append(2);Indices.append(3);Indices.append(7);Indices.append(6);
    Indices.append(0);Indices.append(4);Indices.append(5);Indices.append(1);
    Indices.append(0);Indices.append(2);Indices.append(6);Indices.append(4);
    Indices.append(1);Indices.append(5);Indices.append(7);Indices.append(3);
#else
    GLubyte Indices[]={
        0, 1, 3, 2,
        4, 6, 7, 5,
        2, 3, 7, 6,
        0, 4, 5, 1,
        0, 2, 6, 4,
        1, 5, 7, 3,
    };
#endif

    // active a vertex array
    glBindVertexArray(arrayId);

    // generate buffer objects, and each attribute(vertices, color, and normal..) is corresponding to one buffer

#ifdef QT_BUFFER
    qtgl.glGenBuffers(NumVBOs, buffers);
#else
    glGenBuffers(NumVBOs, buffers);
#endif

    //---------------------------------------buffer for vertices----------------------------------//
    // active a buffer object
#ifdef QT_BUFFER
    qtgl.glBindBuffer(GL_ARRAY_BUFFER, buffers[Vertices]);
#else
    glBindBuffer(GL_ARRAY_BUFFER, buffers[Vertices]);
#endif
    // alloc a space for buffer
#ifdef QT_BUFFER
    qtgl.glBufferData(GL_ARRAY_BUFFER, Verts.size()*sizeof(GLfloat), Verts.data(), GL_STATIC_DRAW);
#else
    glBufferData(GL_ARRAY_BUFFER, sizeof(Verts), Verts, GL_STATIC_DRAW);
#endif
    // put the data into the corresponding buffer
    glVertexPointer(3, GL_FLOAT, 0,BUFFER_OFFSET(0));
    glEnableClientState(GL_VERTEX_ARRAY);



    //---------------------------------------buffer for colors----------------------------------//
    // buffer for colors
#ifdef QT_BUFFER
    qtgl.glBindBuffer(GL_ARRAY_BUFFER, buffers[Color]);
#else
    glBindBuffer(GL_ARRAY_BUFFER, buffers[Color]);
#endif
#ifdef QT_BUFFER
    qtgl.glBufferData(GL_ARRAY_BUFFER, Colors.size()*sizeof(GLfloat), Colors.data(), GL_STATIC_DRAW);
#else
    glBufferData(GL_ARRAY_BUFFER, sizeof(Colors), Colors, GL_STATIC_DRAW);
#endif
    glColorPointer(3, GL_FLOAT, 0, BUFFER_OFFSET(0));
    glEnableClientState(GL_COLOR_ARRAY);


    //---------------------------------------buffer for elements----------------------------------//
    // buffer for elements
#ifdef QT_BUFFER
    numElement = Indices.size();
#else
    numElement = sizeof(Indices)/sizeof(Indices[0]);
#endif
#ifdef QT_BUFFER
    qtgl.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffers[Elements]);
#else
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffers[Elements]);
#endif
#ifdef QT_BUFFER
    qtgl.glBufferData(GL_ELEMENT_ARRAY_BUFFER, Indices.size()*sizeof(uint), Indices.data(), GL_STATIC_DRAW);
#else
    glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(Indices), Indices, GL_STATIC_DRAW);
#endif

#endif
}