// 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; }
void GL::getBufferParameteriv(Enum target, Enum pname, Int * params) { g_OpenGLFunctions.glGetBufferParameteriv(target, pname, params); CHECK_GL_ERROR3(glGetBufferParameteriv, target, pname, params); }
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; }