updated the rendering example using the new rendering system

This commit is contained in:
granzuglia 2016-05-06 02:23:45 +00:00
parent 673be536c4
commit e671856039
11 changed files with 297 additions and 722 deletions

View File

@ -37,20 +37,18 @@ Initial release.
#include <QWheelEvent> #include <QWheelEvent>
#include <wrap/qt/trackball.h> #include <wrap/qt/trackball.h>
#include <cassert> #include <cassert>
#include <wrap/gl/trimesh.h>
#include "mainwindow.h"
#ifdef Q_OS_MAC GLArea::GLArea (SharedDataOpenGLContext* sharedcontext,MainWindow* parent)
#define glGenVertexArrays glGenVertexArraysAPPLE :QGLWidget(NULL,sharedcontext),parwin(parent)
#define glBindVertexArray glBindVertexArrayAPPLE
#define glDeleteVertexArrays glDeleteVertexArraysAPPLE
#endif
GLArea::GLArea (CMeshO& m, MLThreadSafeGLMeshAttributesFeeder& feed,QWidget* parent,QGLWidget* sharedcont)
:QGLWidget (parent,sharedcont),mesh(m),feeder(feed),rq(),drawmode(MDM_SMOOTH)
{ {
} }
GLArea::~GLArea() GLArea::~GLArea()
{ {
} }
void GLArea::initializeGL() void GLArea::initializeGL()
@ -65,21 +63,31 @@ void GLArea::initializeGL()
glEnable(GL_COLOR_MATERIAL); glEnable(GL_COLOR_MATERIAL);
glEnable(GL_CULL_FACE); glEnable(GL_CULL_FACE);
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
GLenum err = glGetError();
assert(err == GL_NO_ERROR);
doneCurrent();
} }
void GLArea::resizeGL (int w, int h) void GLArea::resizeGL (int w, int h)
{ {
makeCurrent(); makeCurrent();
glViewport (0, 0, (GLsizei) w, (GLsizei) h); glViewport (0, 0, (GLsizei) w, (GLsizei) h);
doneCurrent();
//initializeGL(); //initializeGL();
} }
void GLArea::paintGL () void GLArea::paintGL ()
{ {
if (parwin == NULL)
return;
SharedDataOpenGLContext::MultiViewManager* man = parwin->getMultiviewerManager();
if (man == NULL)
return;
CMeshO& mesh = parwin->currentMesh();
//glt.m = &mesh;
makeCurrent(); makeCurrent();
glPushAttrib(GL_ALL_ATTRIB_BITS); glPushAttrib(GL_ALL_ATTRIB_BITS);
//GLenum err = glGetError();
//assert(err == GL_NO_ERROR);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_PROJECTION); glMatrixMode(GL_PROJECTION);
glPushMatrix(); glPushMatrix();
@ -91,33 +99,16 @@ void GLArea::paintGL ()
gluLookAt(0,0,5, 0,0,0, 0,1,0); gluLookAt(0,0,5, 0,0,0, 0,1,0);
track.center=vcg::Point3f(0, 0, 0); track.center=vcg::Point3f(0, 0, 0);
track.radius= 1; track.radius= 1;
track.GetView(); track.GetView();
track.Apply(); track.Apply();
glPushMatrix(); glPushMatrix();
float d=2.0f/mesh.bbox.Diag(); if (mesh.VN() > 0)
vcg::glScale(d); {
glTranslate(-mesh.bbox.Center()); float d=2.0f/mesh.bbox.Diag();
vcg::glScale(d);
if (mesh.VN() > 0) glTranslate(-mesh.bbox.Center());
{ man->draw(context());
switch(drawmode) }
{
case MDM_SMOOTH:
case MDM_FLAT:
feeder.drawTriangles(rq);
case MDM_WIRE:
feeder.drawWire(rq);
break;
case MDM_POINTS:
feeder.drawPoints(rq);
break;
case MDM_FLATWIRE:
feeder.drawFlatWire(rq);
break;
default:
break;
}
}
glPopMatrix(); glPopMatrix();
track.DrawPostApply(); track.DrawPostApply();
@ -125,7 +116,7 @@ void GLArea::paintGL ()
glMatrixMode(GL_PROJECTION); glMatrixMode(GL_PROJECTION);
glPopMatrix(); glPopMatrix();
glPopAttrib(); glPopAttrib();
//doneCurrent();
GLenum err = glGetError(); GLenum err = glGetError();
assert(err == GL_NO_ERROR); assert(err == GL_NO_ERROR);
} }
@ -139,7 +130,9 @@ void GLArea::keyReleaseEvent (QKeyEvent * e)
track.ButtonUp (QT2VCG (Qt::NoButton, Qt::ShiftModifier)); track.ButtonUp (QT2VCG (Qt::NoButton, Qt::ShiftModifier));
if (e->key () == Qt::Key_Alt) if (e->key () == Qt::Key_Alt)
track.ButtonUp (QT2VCG (Qt::NoButton, Qt::AltModifier)); track.ButtonUp (QT2VCG (Qt::NoButton, Qt::AltModifier));
makeCurrent();
updateGL (); updateGL ();
doneCurrent();
} }
void GLArea::keyPressEvent (QKeyEvent * e) void GLArea::keyPressEvent (QKeyEvent * e)
@ -151,7 +144,9 @@ void GLArea::keyPressEvent (QKeyEvent * e)
track.ButtonDown (QT2VCG (Qt::NoButton, Qt::ShiftModifier)); track.ButtonDown (QT2VCG (Qt::NoButton, Qt::ShiftModifier));
if (e->key () == Qt::Key_Alt) if (e->key () == Qt::Key_Alt)
track.ButtonDown (QT2VCG (Qt::NoButton, Qt::AltModifier)); track.ButtonDown (QT2VCG (Qt::NoButton, Qt::AltModifier));
makeCurrent();
updateGL (); updateGL ();
doneCurrent();
} }
void GLArea::mousePressEvent (QMouseEvent * e) void GLArea::mousePressEvent (QMouseEvent * e)
@ -159,103 +154,79 @@ void GLArea::mousePressEvent (QMouseEvent * e)
e->accept (); e->accept ();
setFocus (); setFocus ();
track.MouseDown (QT2VCG_X(this,e), QT2VCG_Y(this,e), QT2VCG (e->button (), e->modifiers ())); track.MouseDown (QT2VCG_X(this,e), QT2VCG_Y(this,e), QT2VCG (e->button (), e->modifiers ()));
makeCurrent();
updateGL (); updateGL ();
doneCurrent();
} }
void GLArea::mouseMoveEvent (QMouseEvent * e) void GLArea::mouseMoveEvent (QMouseEvent * e)
{ {
if (e->buttons ()) { if (e->buttons ()) {
track.MouseMove (QT2VCG_X(this,e), QT2VCG_Y(this,e)); track.MouseMove (QT2VCG_X(this,e), QT2VCG_Y(this,e));
makeCurrent();
updateGL (); updateGL ();
doneCurrent();
} }
} }
void GLArea::mouseReleaseEvent (QMouseEvent * e) void GLArea::mouseReleaseEvent (QMouseEvent * e)
{ {
track.MouseUp (QT2VCG_X(this,e), QT2VCG_Y(this,e), QT2VCG (e->button (), e->modifiers ())); track.MouseUp (QT2VCG_X(this,e), QT2VCG_Y(this,e), QT2VCG (e->button (), e->modifiers ()));
makeCurrent();
updateGL (); updateGL ();
doneCurrent();
} }
void GLArea::wheelEvent (QWheelEvent * e) void GLArea::wheelEvent (QWheelEvent * e)
{ {
const int WHEEL_STEP = 120; const int WHEEL_STEP = 120;
track.MouseWheel (e->delta () / float (WHEEL_STEP), QTWheel2VCG (e->modifiers ())); track.MouseWheel (e->delta () / float (WHEEL_STEP), QTWheel2VCG (e->modifiers ()));
makeCurrent();
updateGL (); updateGL ();
} doneCurrent();
void GLArea::updateRequested(MyDrawMode md,vcg::GLFeederInfo::ReqAtts& reqatts)
{
drawmode = md;
rq = reqatts;
updateGL();
} }
void GLArea::resetTrackBall() void GLArea::resetTrackBall()
{ {
makeCurrent();
track.Reset(); track.Reset();
updateGL(); makeCurrent();
updateGL();
doneCurrent(); doneCurrent();
} }
SharedDataOpenGLContext::SharedDataOpenGLContext( CMeshO& mesh,MLThreadSafeMemoryInfo& mi,QWidget* parent /*= 0*/ ) SharedDataOpenGLContext::SharedDataOpenGLContext(CMeshO& mesh,vcg::QtThreadSafeMemoryInfo& mi,QWidget* parent)
:QGLWidget(parent),feeder(mesh,mi,100000) :QGLWidget(parent),manager(mesh,mi,100000)
{ {
} }
SharedDataOpenGLContext::~SharedDataOpenGLContext() SharedDataOpenGLContext::~SharedDataOpenGLContext()
{ {
deAllocateBO();
} }
void SharedDataOpenGLContext::myInitGL() void SharedDataOpenGLContext::myInitGL()
{ {
makeCurrent(); makeCurrent();
glewInit(); glewInit();
doneCurrent(); doneCurrent();
}
void SharedDataOpenGLContext::passInfoToOpenGL(int mode)
{
makeCurrent();
MyDrawMode drawmode = static_cast<MyDrawMode>(mode);
//_tsbm.setUpBuffers();
vcg::GLFeederInfo::ReqAtts req;
bool allocated = false;
switch(drawmode)
{
case MDM_SMOOTH:
case MDM_WIRE:
req[vcg::GLFeederInfo::ATT_VERTPOSITION] = true;
req[vcg::GLFeederInfo::ATT_VERTNORMAL] = true;
req[vcg::GLFeederInfo::ATT_VERTINDEX] = true;
req.primitiveModality() = vcg::GLFeederInfo::PR_TRIANGLES;
break;
case MDM_POINTS:
req[vcg::GLFeederInfo::ATT_VERTPOSITION] = true;
req[vcg::GLFeederInfo::ATT_VERTNORMAL] = true;
req.primitiveModality() = vcg::GLFeederInfo::PR_POINTS;
break;
case MDM_FLAT:
case MDM_FLATWIRE:
req[vcg::GLFeederInfo::ATT_VERTPOSITION] = true;
req[vcg::GLFeederInfo::ATT_FACENORMAL] = true;
req.primitiveModality() = vcg::GLFeederInfo::PR_TRIANGLES;
break;
default:
break;
}
vcg::GLFeederInfo::ReqAtts rq = feeder.setupRequestedAttributes(req,allocated);
doneCurrent();
emit dataReadyToBeRead(drawmode,rq);
} }
void SharedDataOpenGLContext::deAllocateBO() void SharedDataOpenGLContext::deAllocateBO()
{ {
makeCurrent(); makeCurrent();
feeder.deAllocateBO(); manager.removeAllViewsAndDeallocateBO();
doneCurrent(); doneCurrent();
} }
void SharedDataOpenGLContext::setPerViewRendAtts( QGLContext* viewid,vcg::GLMeshAttributesInfo::PRIMITIVE_MODALITY_MASK mm,vcg::GLMeshAttributesInfo::RendAtts& atts )
{
manager.setPerViewInfo(viewid,mm,atts);
}
void SharedDataOpenGLContext::manageBuffers()
{
makeCurrent();
manager.manageBuffers();
doneCurrent();
}

View File

@ -39,47 +39,44 @@ Initial release.
/// wrapper imports /// wrapper imports
#include <wrap/gui/trackball.h> #include <wrap/gui/trackball.h>
#include <wrap/qt/qt_thread_safe_memory_info.h>
#include <wrap/qt/qt_thread_safe_mesh_attributes_multi_viewer_bo_manager.h>
#include <wrap/gl/trimesh.h>
#include "mesh.h" #include "mesh.h"
#include "ml_scene_renderer.h"
/// declaring edge and face type
class MainWindow;
enum MyDrawMode{MDM_SMOOTH=0,MDM_POINTS,MDM_WIRE,MDM_FLATWIRE,MDM_FLAT};
class SharedDataOpenGLContext : public QGLWidget class SharedDataOpenGLContext : public QGLWidget
{ {
Q_OBJECT Q_OBJECT
public: public:
SharedDataOpenGLContext(CMeshO& mesh,MLThreadSafeMemoryInfo& mi,QWidget* parent = 0); typedef vcg::QtThreadSafeGLMeshAttributesMultiViewerBOManager<CMeshO,QGLContext*> MultiViewManager;
SharedDataOpenGLContext(CMeshO& mesh,vcg::QtThreadSafeMemoryInfo& mi,QWidget* parent = 0);
~SharedDataOpenGLContext(); ~SharedDataOpenGLContext();
void myInitGL(); void myInitGL();
void deAllocateBO(); void deAllocateBO();
void setPerViewRendAtts(QGLContext* view,vcg::GLMeshAttributesInfo::PRIMITIVE_MODALITY_MASK mm,vcg::GLMeshAttributesInfo::RendAtts& atts);
MLThreadSafeGLMeshAttributesFeeder feeder; void manageBuffers();
MultiViewManager manager;
public slots:
/// widget-based user interaction slots
void passInfoToOpenGL(int mode);
signals:
void dataReadyToBeRead(MyDrawMode,vcg::GLFeederInfo::ReqAtts&);
}; };
class GLArea:public QGLWidget class GLArea:public QGLWidget
{ {
Q_OBJECT Q_OBJECT
public: public:
GLArea (CMeshO& m,MLThreadSafeGLMeshAttributesFeeder& feed,QWidget* parent = NULL,QGLWidget* sharedcont = NULL); GLArea (SharedDataOpenGLContext* sharedcontext,MainWindow* parent);
~GLArea(); ~GLArea();
void resetTrackBall(); void resetTrackBall();
//unsigned int getId() const {return areaid;}
/// we choosed a subset of the avaible drawing modes /// we choosed a subset of the avaible drawing modes
signals: signals:
/// signal for setting the statusbar message /// signal for setting the statusbar message
void setStatusBar(QString message); void setStatusBar(QString message);
void updateRenderModalityRequested(int);
protected: protected:
/// opengl initialization and drawing calls /// opengl initialization and drawing calls
void initializeGL (); void initializeGL ();
@ -92,18 +89,15 @@ protected:
void mouseMoveEvent(QMouseEvent*e); void mouseMoveEvent(QMouseEvent*e);
void mouseReleaseEvent(QMouseEvent*e); void mouseReleaseEvent(QMouseEvent*e);
void wheelEvent(QWheelEvent*e); void wheelEvent(QWheelEvent*e);
public slots:
void updateRequested(MyDrawMode,vcg::GLFeederInfo::ReqAtts&);
private: private:
/// the active mesh instance MainWindow* parwin;
CMeshO& mesh;
/// the active manipulator /// the active manipulator
vcg::Trackball track; vcg::Trackball track;
/// mesh data structure initializer /// mesh data structure initializer
void initMesh(QString message); void initMesh(QString message);
MyDrawMode drawmode; //unsigned int areaid;
MLThreadSafeGLMeshAttributesFeeder& feeder; //vcg::GlTrimesh<CMeshO> glt;
vcg::GLFeederInfo::ReqAtts rq;
}; };
#endif /*GLAREA_H_ */ #endif /*GLAREA_H_ */

View File

@ -29,51 +29,86 @@ $Log: not supported by cvs2svn $
#include "mainwindow.h" #include "mainwindow.h"
#include "glarea.h"
#include <QGridLayout>
#include <QFileDialog> #include <QFileDialog>
#include <QMessageBox> #include <QMessageBox>
#include <QDebug> #include <QDebug>
#include <QTime>
QProgressBar *MainWindow::qb;
QStatusBar* MainWindow::sb;
MainWindow::MainWindow (QWidget * parent) MainWindow::MainWindow (QWidget * parent)
:QMainWindow (parent),mi(1000000000),mesh() :QMainWindow (parent),mi(2000000000),mesh()
{ {
ui.setupUi (this); ui.setupUi (this);
QLayout* tmp = ui.glFrame->layout(); initTable();
QGridLayout* grid = new QGridLayout();
//parent is set to NULL in order to avoid QT bug on MAC (business as usual...). //parent is set to NULL in order to avoid QT bug on MAC (business as usual...).
//The QGLWidget are destroyed by hand in the MainWindow destructor... //The QGLWidget are destroyed by hand in the MainWindow destructor...
shared = new SharedDataOpenGLContext(mesh,mi,NULL); shared = new SharedDataOpenGLContext(mesh,mi,NULL);
shared->setHidden(true); shared->setHidden(true);
shared->myInitGL(); shared->myInitGL();
connect (ui.drawModeComboBox, SIGNAL (currentIndexChanged(int)),shared, SLOT (passInfoToOpenGL(int)));
for(int ii = 0;ii < 2;++ii) for(unsigned int ii = 0;ii < 2;++ii)
{ {
glar[ii] = new GLArea(mesh,shared->feeder,NULL,shared); rendbox[ii] = new QComboBox(this);
connect (shared,SIGNAL(dataReadyToBeRead(MyDrawMode,vcg::GLFeederInfo::ReqAtts&)),glar[ii], SLOT (updateRequested(MyDrawMode,vcg::GLFeederInfo::ReqAtts&))); for(QMap<MyDrawMode,QString>::iterator it = stringrendtable.begin();it != stringrendtable.end();++it)
tmp->addWidget(glar[ii]); rendbox[ii]->addItem(it.value());
} rendbox[ii]->setCurrentIndex((int) MDM_SMOOTH);
glar[ii] = new GLArea(shared,this);
connect(rendbox[ii],SIGNAL(activated(int)),glar[ii],SIGNAL(updateRenderModalityRequested(int)));
connect(glar[ii],SIGNAL(updateRenderModalityRequested(int)),this,SLOT(updateRenderModality(int)));
//connect(shared,SIGNAL(dataReadyToBeRead(MyDrawMode,vcg::GLFeederInfo::ReqAtts&)),glar[ii], SLOT(updateRequested(MyDrawMode,vcg::GLFeederInfo::ReqAtts&)));
grid->addWidget(rendbox[ii],0,ii,1,1,Qt::AlignRight);
grid->addWidget(glar[ii],1,ii,1,1);
}
ui.glbox->setLayout(grid);
connect (ui.loadMeshPushButton, SIGNAL (clicked()),this, SLOT (chooseMesh())); connect(ui.actionLoad_Mesh,SIGNAL(triggered()),this,SLOT(chooseMesh()));
connect (ui.loadTetrahedronPushButton, SIGNAL (clicked()),this, SLOT (loadTetrahedron())); connect (ui.actionLoad_Tetrahedron, SIGNAL (triggered()),this, SLOT (loadTetrahedron()));
connect (ui.loadDodecahedronPushButton, SIGNAL (clicked()),this, SLOT (loadDodecahedron())); connect (ui.actionLoad_Dodecahedron, SIGNAL (triggered()),this, SLOT (loadDodecahedron()));
//from toolFrame to glArea through mainwindow
sb = statusBar();
qb=new QProgressBar(this);
qb->setMaximum(100);
qb->setMinimum(0);
qb->reset();
statusBar()->addPermanentWidget(qb,0);
} }
// mesh chooser file dialog // mesh chooser file dialog
void MainWindow::chooseMesh() void MainWindow::chooseMesh()
{ {
mesh.Clear(); mesh.Clear();
QString plyext("ply");
QString objext("obj");
QString extoptions = QString("Poly Model (*.") + plyext + ");;OBJ Model (*." + objext + ")";
QString fileName = QFileDialog::getOpenFileName(this, QString fileName = QFileDialog::getOpenFileName(this,
tr("Open Mesh"), QDir::currentPath(), tr("Open Mesh"), QDir::currentPath(),
tr("Poly Model (*.ply)")); extoptions);
int err=vcg::tri::io::ImporterPLY<CMeshO>::Open(mesh,(fileName.toStdString()).c_str()); QFileInfo fi(fileName);
QTime loadingtime;
loadingtime.start();
int err=0;
if (fi.suffix() == plyext)
err=vcg::tri::io::ImporterPLY<CMeshO>::Open(mesh,(fileName.toStdString()).c_str(),qCallBack);
else
if (fi.suffix() == objext)
{
int loadmask;
err=vcg::tri::io::ImporterOBJ<CMeshO>::Open(mesh,(fileName.toStdString()).c_str(),loadmask,qCallBack);
}
int msec = loadingtime.elapsed();
if(err!=0) if(err!=0)
{ {
const char* errmsg=vcg::tri::io::ImporterPLY<CMeshO>::ErrorMsg(err); const char* errmsg=vcg::tri::io::ImporterPLY<CMeshO>::ErrorMsg(err);
QMessageBox::warning(this,tr("Error Loading Mesh"),QString(errmsg)); QMessageBox::warning(this,tr("Error Loading Mesh"),QString(errmsg));
} }
initMesh(fileName); QString msg = fileName + " vtx: " + QString::number(mesh.VN()) + " fcs: " + QString::number(mesh.FN()) + " loading time: " + QString::number(msec) + " msec";
initMesh(msg);
} }
void MainWindow::loadTetrahedron() void MainWindow::loadTetrahedron()
@ -90,7 +125,7 @@ void MainWindow::loadDodecahedron()
initMesh(tr("Dodecahedron [builtin]")); initMesh(tr("Dodecahedron [builtin]"));
} }
void MainWindow::initMesh(QString message) void MainWindow::initMesh(QString& message)
{ {
if (shared != NULL) if (shared != NULL)
shared->deAllocateBO(); shared->deAllocateBO();
@ -98,16 +133,111 @@ void MainWindow::initMesh(QString message)
vcg::tri::UpdateBounding<CMeshO>::Box(mesh); vcg::tri::UpdateBounding<CMeshO>::Box(mesh);
// update Normals // update Normals
vcg::tri::UpdateNormal<CMeshO>::PerVertexNormalizedPerFaceNormalized(mesh); vcg::tri::UpdateNormal<CMeshO>::PerVertexNormalizedPerFaceNormalized(mesh);
shared->passInfoToOpenGL(ui.drawModeComboBox->currentIndex()); QTime rdsetuptime;
for(size_t ii = 0;ii < 2;++ii) rdsetuptime.start();
if (glar[ii] != NULL) for(unsigned int ii = 0;ii < 2;++ii)
glar[ii]->resetTrackBall(); if ((glar[ii] != NULL) && (rendbox[ii] != NULL))
ui.statusbar->showMessage(message); {
glar[ii]->resetTrackBall();
MyDrawMode mdm = (MyDrawMode) rendbox[ii]->currentIndex();
QMap<MyDrawMode,QPair<vcg::GLMeshAttributesInfo::PRIMITIVE_MODALITY_MASK, vcg::GLMeshAttributesInfo::RendAtts> >::iterator it = rendtable.find(mdm);
if (it == rendtable.end())
return;
shared->setPerViewRendAtts(glar[ii]->context(),it.value().first,it.value().second);
}
shared->manageBuffers();
for(unsigned int ii = 0;ii < 2;++ii)
glar[ii]->updateGL();
qb->reset();
int msec = rdsetuptime.elapsed();
message += " bo creation: " + QString::number(msec) + " msec";
statusBar()->showMessage(message);
}
void MainWindow::updateRenderModality(int clickedindex)
{
GLArea* glasender = qobject_cast<GLArea*>(sender());
if (glasender == NULL)
return;
updateRenderModality(glasender,clickedindex);
}
void MainWindow::updateRenderModality( GLArea* area,int clickedindex )
{
if ((shared == NULL) || (area == NULL))
return;
MyDrawMode mdm = (MyDrawMode) clickedindex;
QMap<MyDrawMode,QPair<vcg::GLMeshAttributesInfo::PRIMITIVE_MODALITY_MASK, vcg::GLMeshAttributesInfo::RendAtts> >::iterator it = rendtable.find(mdm);
if (it == rendtable.end())
return;
shared->setPerViewRendAtts(area->context(),it.value().first,it.value().second);
shared->manageBuffers();
for(unsigned int ii = 0;ii < 2;++ii)
glar[ii]->updateGL();
} }
MainWindow::~MainWindow() MainWindow::~MainWindow()
{ {
for(int ii = 0;ii < 2;++ii) for(int ii = 0;ii < 2;++ii)
delete glar[ii]; delete glar[ii];
delete shared; delete shared;
} }
void MainWindow::initTable()
{
stringrendtable[MDM_SMOOTH] = QString("Solid Smooth");
stringrendtable[MDM_FLAT] = QString("Solid Flat");
stringrendtable[MDM_WIRE] = QString("Wire");
stringrendtable[MDM_POINTS] = QString("Points");
stringrendtable[MDM_QUAD_WIRE] = QString("Wire Quad");
stringrendtable[MDM_QUAD_SMOOTH_WIRE] = QString("Wire Solid Smooth Quad");
vcg::GLMeshAttributesInfo::PRIMITIVE_MODALITY_MASK mmask = vcg::GLMeshAttributesInfo::PR_SOLID;
vcg::GLMeshAttributesInfo::RendAtts ratts;
ratts[vcg::GLMeshAttributesInfo::ATT_NAMES::ATT_VERTPOSITION] = true;
ratts[vcg::GLMeshAttributesInfo::ATT_NAMES::ATT_VERTNORMAL] = true;
rendtable[MDM_SMOOTH] = qMakePair(mmask,ratts);
ratts.reset(true);
ratts[vcg::GLMeshAttributesInfo::ATT_NAMES::ATT_FACENORMAL] = true;
rendtable[MDM_FLAT] = qMakePair(mmask,ratts);
ratts.reset(true);
mmask = vcg::GLMeshAttributesInfo::PR_WIREFRAME_TRIANGLES;
rendtable[MDM_WIRE] = qMakePair(mmask,ratts);
ratts.reset(true);
mmask = vcg::GLMeshAttributesInfo::PR_POINTS;
ratts[vcg::GLMeshAttributesInfo::ATT_NAMES::ATT_VERTNORMAL] = true;
rendtable[MDM_POINTS] = qMakePair(mmask,ratts);
ratts.reset(true);
mmask = vcg::GLMeshAttributesInfo::PR_WIREFRAME_EDGES;
rendtable[MDM_QUAD_WIRE] = qMakePair(mmask,ratts);
ratts.reset(true);
mmask = vcg::GLMeshAttributesInfo::PR_WIREFRAME_EDGES | vcg::GLMeshAttributesInfo::PR_SOLID;
ratts[vcg::GLMeshAttributesInfo::ATT_NAMES::ATT_VERTNORMAL] = true;
rendtable[MDM_QUAD_SMOOTH_WIRE] = qMakePair(mmask,ratts);
}
bool MainWindow::qCallBack(const int pos, const char * str)
{
int static lastPos=-1;
if(pos==lastPos) return true;
lastPos=pos;
static QTime currTime = QTime::currentTime();
if(currTime.elapsed()< 100) return true;
currTime.start();
sb->showMessage(str,5000);
qb->show();
qb->setEnabled(true);
qb->setValue(pos);
sb->update();
qApp->processEvents();
return true;
}
SharedDataOpenGLContext::MultiViewManager* MainWindow::getMultiviewerManager()
{
if (shared == NULL)
return NULL;
return &(shared->manager);
}

View File

@ -29,33 +29,55 @@ $Log: not supported by cvs2svn $
#ifndef MAINWINDOW_H_ #ifndef MAINWINDOW_H_
#define MAINWINDOW_H_ #define MAINWINDOW_H_
#include <GL/glew.h>
#include <QGLContext>
#include "ui_mainwindow.h" #include "ui_mainwindow.h"
#include "mesh.h"
#include <wrap/gl/gl_mesh_attributes_info.h>
#include <wrap/qt/qt_thread_safe_mesh_attributes_multi_viewer_bo_manager.h>
#include <wrap/qt/qt_thread_safe_memory_info.h>
#include <QProgressBar>
#include <QStatusBar>
#include <QComboBox>
#include "glarea.h" #include "glarea.h"
#include "ml_thread_safe_memory_info.h" enum MyDrawMode{MDM_SMOOTH=0,MDM_POINTS,MDM_WIRE,MDM_FLAT,MDM_QUAD_WIRE,MDM_QUAD_SMOOTH_WIRE};
class MainWindow:public QMainWindow class MainWindow:public QMainWindow
{ {
Q_OBJECT Q_OBJECT
public: public:
MainWindow(QWidget * parent = 0); MainWindow(QWidget * parent = 0);
~MainWindow(); ~MainWindow();
CMeshO& currentMesh() {return mesh;}
SharedDataOpenGLContext::MultiViewManager* getMultiviewerManager();
void updateRenderModality(GLArea* area,int clickedindex);
static bool qCallBack(const int pos, const char * str);
public slots: public slots:
void chooseMesh(); void chooseMesh();
void loadTetrahedron(); void loadTetrahedron();
void loadDodecahedron(); void loadDodecahedron();
void initMesh(QString message); void initMesh(QString& message);
void updateRenderModality(int clickedindex);
signals: signals:
void loadMesh(QString newMesh); void loadMesh(QString newMesh);
void updateRenderModalityRequested(int);
private: private:
void initTable();
Ui::mainWindow ui; Ui::mainWindow ui;
GLArea* glar[2]; GLArea* glar[2];
SharedDataOpenGLContext* shared; SharedDataOpenGLContext* shared;
MLThreadSafeMemoryInfo mi; vcg::QtThreadSafeMemoryInfo mi;
QComboBox* rendbox[2];
/// the active mesh instance /// the active mesh instance
CMeshO mesh; CMeshO mesh;
QMap<MyDrawMode,QString> stringrendtable;
QMap<MyDrawMode,QPair<vcg::GLMeshAttributesInfo::PRIMITIVE_MODALITY_MASK,vcg::GLMeshAttributesInfo::RendAtts> > rendtable;
static QProgressBar* qb;
static QStatusBar* sb;
}; };
#endif /*MAINWINDOW_H_ */ #endif /*MAINWINDOW_H_ */

View File

@ -31,150 +31,7 @@
<number>9</number> <number>9</number>
</property> </property>
<item> <item>
<widget class="QFrame" name="toolsFrame"> <widget class="QWidget" name="glbox" native="true"/>
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QHBoxLayout">
<property name="spacing">
<number>6</number>
</property>
<property name="leftMargin">
<number>9</number>
</property>
<property name="topMargin">
<number>9</number>
</property>
<property name="rightMargin">
<number>9</number>
</property>
<property name="bottomMargin">
<number>9</number>
</property>
<item>
<widget class="QLabel" name="drawModeLabel">
<property name="text">
<string>Draw &amp;Mode :</string>
</property>
<property name="buddy">
<cstring>drawModeComboBox</cstring>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="drawModeComboBox">
<item>
<property name="text">
<string>Smooth</string>
</property>
</item>
<item>
<property name="text">
<string>Points</string>
</property>
</item>
<item>
<property name="text">
<string>Wire</string>
</property>
</item>
<item>
<property name="text">
<string>Flat Wire</string>
</property>
</item>
<item>
<property name="text">
<string>Flat</string>
</property>
</item>
</widget>
</item>
<item>
<spacer>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="loadMeshPushButton">
<property name="text">
<string>Load &amp;Mesh</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="loadTetrahedronPushButton">
<property name="text">
<string>Load &amp;Tetrahedron</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="loadDodecahedronPushButton">
<property name="text">
<string>Load &amp;Dodecahedron</string>
</property>
</widget>
</item>
<item>
<spacer>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QFrame" name="glFrame">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QVBoxLayout">
<property name="spacing">
<number>6</number>
</property>
<property name="leftMargin">
<number>9</number>
</property>
<property name="topMargin">
<number>9</number>
</property>
<property name="rightMargin">
<number>9</number>
</property>
<property name="bottomMargin">
<number>9</number>
</property>
</layout>
</widget>
</item> </item>
</layout> </layout>
</widget> </widget>
@ -187,15 +44,39 @@
<height>21</height> <height>21</height>
</rect> </rect>
</property> </property>
<widget class="QMenu" name="menuFile">
<property name="title">
<string>File</string>
</property>
<addaction name="actionLoad_Mesh"/>
<addaction name="actionLoad_Tetrahedron"/>
<addaction name="actionLoad_Dodecahedron"/>
<addaction name="separator"/>
<addaction name="actionClose"/>
</widget>
<addaction name="menuFile"/>
</widget> </widget>
<widget class="QStatusBar" name="statusbar"/> <action name="actionLoad_Mesh">
<property name="text">
<string>Load Mesh</string>
</property>
</action>
<action name="actionLoad_Tetrahedron">
<property name="text">
<string>Load Tetrahedron</string>
</property>
</action>
<action name="actionLoad_Dodecahedron">
<property name="text">
<string>Load Dodecahedron</string>
</property>
</action>
<action name="actionClose">
<property name="text">
<string>Close</string>
</property>
</action>
</widget> </widget>
<tabstops>
<tabstop>drawModeComboBox</tabstop>
<tabstop>loadMeshPushButton</tabstop>
<tabstop>loadTetrahedronPushButton</tabstop>
<tabstop>loadDodecahedronPushButton</tabstop>
</tabstops>
<resources/> <resources/>
<connections/> <connections/>
</ui> </ui>

View File

@ -12,17 +12,17 @@
using namespace vcg; using namespace vcg;
class CFaceO; class CFaceO;
class CVertexO; class CVertexO;
class CEdgeO;
struct MyUsedTypes : public UsedTypes< Use<CVertexO> ::AsVertexType, struct MyUsedTypes : public UsedTypes<Use<CVertexO> ::AsVertexType, vcg::Use<CEdgeO >::AsEdgeType,
Use<CFaceO> ::AsFaceType>{}; Use<CFaceO> ::AsFaceType>{};
/// compositing wanted proprieties /// compositing wanted proprieties
class CVertexO : public vcg::Vertex< MyUsedTypes, vcg::vertex::Coord3f, vcg::vertex::Normal3f, vcg::vertex::BitFlags>{}; class CVertexO : public vcg::Vertex< MyUsedTypes, vcg::vertex::Coord3f, vcg::vertex::Normal3f, vcg::vertex::BitFlags>{};
class CFaceO : public vcg::Face< MyUsedTypes, vcg::face::VertexRef, vcg::face::Normal3f, vcg::face::BitFlags > {}; class CFaceO : public vcg::Face< MyUsedTypes, vcg::face::VertexRef, vcg::face::Normal3f, vcg::face::BitFlags > {};
class CMeshO : public vcg::tri::TriMesh< std::vector<CVertexO>, std::vector<CFaceO> > class CEdgeO : public vcg::Edge<MyUsedTypes,vcg::edge::BitFlags,vcg::edge::EVAdj,vcg::edge::EEAdj>{};
class CMeshO : public vcg::tri::TriMesh< std::vector<CVertexO>, std::vector<CFaceO>,std::vector<CEdgeO> >
{ {
public:
vcg::Box3f bbox;
}; };
#endif #endif

View File

@ -1,201 +0,0 @@
#include "ml_scene_renderer.h"
#include "ml_thread_safe_memory_info.h"
#include "glarea.h"
#include <vector>
MLThreadSafeGLMeshAttributesFeeder::MLThreadSafeGLMeshAttributesFeeder(CMeshO& mesh,MLThreadSafeMemoryInfo& gpumeminfo,size_t perbatchtriangles)
:GLMeshAttributesFeeder<CMeshO>(mesh,gpumeminfo,perbatchtriangles),_lock(QReadWriteLock::Recursive)
{
}
void MLThreadSafeGLMeshAttributesFeeder::setPerBatchTriangles( size_t perbatchtriangles )
{
QWriteLocker locker(&_lock);
GLMeshAttributesFeeder<CMeshO>::setPerBatchPrimitives(perbatchtriangles);
}
size_t MLThreadSafeGLMeshAttributesFeeder::perBatchTriangles() const
{
QReadLocker locker(&_lock);
return GLMeshAttributesFeeder<CMeshO>::perBatchPrimitives();
}
bool MLThreadSafeGLMeshAttributesFeeder::renderedWithBO() const
{
QReadLocker locker(&_lock);
return GLMeshAttributesFeeder<CMeshO>::isPossibleToUseBORendering();
}
void MLThreadSafeGLMeshAttributesFeeder::meshAttributesUpdated( int mask )
{
QWriteLocker locker(&_lock);
GLMeshAttributesFeeder<CMeshO>::meshAttributesUpdated(mask);
}
vcg::GLFeederInfo::ReqAtts MLThreadSafeGLMeshAttributesFeeder::setupRequestedAttributes(const vcg::GLFeederInfo::ReqAtts& rq,bool& allocated )
{
QWriteLocker locker(&_lock);
return GLMeshAttributesFeeder<CMeshO>::setupRequestedAttributes(rq,allocated);
}
void MLThreadSafeGLMeshAttributesFeeder::drawWire(vcg::GLFeederInfo::ReqAtts& rq)
{
glPushAttrib(GL_ENABLE_BIT | GL_CURRENT_BIT | GL_LIGHTING_BIT );
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
drawTriangles(rq);
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glPopAttrib();
}
void MLThreadSafeGLMeshAttributesFeeder::drawFlatWire(vcg::GLFeederInfo::ReqAtts& rq)
{
glPushAttrib(GL_ENABLE_BIT | GL_CURRENT_BIT | GL_LIGHTING_BIT );
glEnable(GL_POLYGON_OFFSET_FILL);
glPolygonOffset(1.0, 1);
drawTriangles(rq);
glDisable(GL_POLYGON_OFFSET_FILL);
glEnable(GL_COLOR_MATERIAL);
glColorMaterial(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE);
ReqAtts tmp = rq;
tmp[ATT_VERTCOLOR] = false;
tmp[ATT_FACECOLOR] = false;
tmp[ATT_MESHCOLOR] = false;
glColor3f(.3f,.3f,.3f);
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
QReadLocker locker(&_lock);
GLMeshAttributesFeeder<CMeshO>::drawTriangles(tmp,_textids.textId());
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glPopAttrib();
}
void MLThreadSafeGLMeshAttributesFeeder::drawPoints(vcg::GLFeederInfo::ReqAtts& rq)
{
QReadLocker locker(&_lock);
GLMeshAttributesFeeder<CMeshO>::drawPoints(rq);
}
void MLThreadSafeGLMeshAttributesFeeder::drawTriangles(vcg::GLFeederInfo::ReqAtts& rq)
{
QReadLocker locker(&_lock);
GLMeshAttributesFeeder<CMeshO>::drawTriangles(rq,_textids.textId());
}
void MLThreadSafeGLMeshAttributesFeeder::drawBBox(vcg::GLFeederInfo::ReqAtts& rq)
{
QReadLocker locker(&_lock);
vcg::Box3f& b = _mesh.bbox;
glPushAttrib(GL_ALL_ATTRIB_BITS);
glDisable(GL_LIGHTING);
GLuint bbhandle;
glGenBuffers(1,&bbhandle);
std::vector<vcg::Point3f> bbox(12 * 2);
//0
bbox[0] = vcg::Point3f((float)b.min[0],(float)b.min[1],(float)b.min[2]);
bbox[1] = vcg::Point3f((float)b.max[0],(float)b.min[1],(float)b.min[2]);
//1
bbox[2] = vcg::Point3f((float)b.max[0],(float)b.min[1],(float)b.min[2]);
bbox[3] = vcg::Point3f((float)b.max[0],(float)b.max[1],(float)b.min[2]);
//2
bbox[4] = vcg::Point3f((float)b.max[0],(float)b.max[1],(float)b.min[2]);
bbox[5] = vcg::Point3f((float)b.min[0],(float)b.max[1],(float)b.min[2]);
//3
bbox[6] = vcg::Point3f((float)b.min[0],(float)b.max[1],(float)b.min[2]);
bbox[7] = vcg::Point3f((float)b.min[0],(float)b.min[1],(float)b.min[2]);
//4
bbox[8] = vcg::Point3f((float)b.min[0],(float)b.min[1],(float)b.min[2]);
bbox[9] = vcg::Point3f((float)b.min[0],(float)b.min[1],(float)b.max[2]);
//5
bbox[10] = vcg::Point3f((float)b.min[0],(float)b.min[1],(float)b.max[2]);
bbox[11] = vcg::Point3f((float)b.max[0],(float)b.min[1],(float)b.max[2]);
//6
bbox[12] = vcg::Point3f((float)b.max[0],(float)b.min[1],(float)b.max[2]);
bbox[13] = vcg::Point3f((float)b.max[0],(float)b.min[1],(float)b.min[2]);
//7
bbox[14] = vcg::Point3f((float)b.max[0],(float)b.min[1],(float)b.max[2]);
bbox[15] = vcg::Point3f((float)b.max[0],(float)b.max[1],(float)b.max[2]);
//8
bbox[16] = vcg::Point3f((float)b.max[0],(float)b.max[1],(float)b.max[2]);
bbox[17] = vcg::Point3f((float)b.max[0],(float)b.max[1],(float)b.min[2]);
//9
bbox[18] = vcg::Point3f((float)b.max[0],(float)b.max[1],(float)b.max[2]);
bbox[19] = vcg::Point3f((float)b.min[0],(float)b.max[1],(float)b.max[2]);
//10
bbox[20] = vcg::Point3f((float)b.min[0],(float)b.max[1],(float)b.max[2]);
bbox[21] = vcg::Point3f((float)b.min[0],(float)b.min[1],(float)b.max[2]);
//11
bbox[22] = vcg::Point3f((float)b.min[0],(float)b.max[1],(float)b.max[2]);
bbox[23] = vcg::Point3f((float)b.min[0],(float)b.max[1],(float)b.min[2]);
glColor3f(1.0f,1.0f,1.0f);
glBindBuffer(GL_ARRAY_BUFFER,bbhandle);
glBufferData(GL_ARRAY_BUFFER, 12 * 2 * sizeof(vcg::Point3f), &(bbox[0]), GL_STATIC_DRAW);
glVertexPointer(3,GL_FLOAT,0,0);
glBindBuffer(GL_ARRAY_BUFFER,0);
glEnableClientState(GL_VERTEX_ARRAY);
glDrawArrays(GL_LINES,0,24);
glDisableClientState(GL_VERTEX_ARRAY);
glDeleteBuffers(1,&bbhandle);
glPopAttrib();
}
void MLThreadSafeGLMeshAttributesFeeder::deAllocateBO()
{
QWriteLocker locker(&_lock);
GLMeshAttributesFeeder<CMeshO>::buffersDeAllocationRequested();
}
MLThreadSafeGLMeshAttributesFeeder::MLThreadSafeTextureNamesContainer::MLThreadSafeTextureNamesContainer()
:_tmid(),_lock(QReadWriteLock::Recursive)
{
}
MLThreadSafeGLMeshAttributesFeeder::MLThreadSafeTextureNamesContainer::~MLThreadSafeTextureNamesContainer()
{
clear();
}
void MLThreadSafeGLMeshAttributesFeeder::MLThreadSafeTextureNamesContainer::push_back( GLuint textid )
{
QWriteLocker locker(&_lock);
_tmid.push_back(textid);
}
size_t MLThreadSafeGLMeshAttributesFeeder::MLThreadSafeTextureNamesContainer::size() const
{
QReadLocker locker(&_lock);
return _tmid.size();
}
bool MLThreadSafeGLMeshAttributesFeeder::MLThreadSafeTextureNamesContainer::empty() const
{
QReadLocker locker(&_lock);
return _tmid.empty();
}
void MLThreadSafeGLMeshAttributesFeeder::MLThreadSafeTextureNamesContainer::clear()
{
QWriteLocker locker(&_lock);
_tmid.clear();
}

View File

@ -1,97 +0,0 @@
/****************************************************************************
* MeshLab o o *
* A versatile mesh processing toolbox o o *
* _ O _ *
* Copyright(C) 2005 \/)\/ *
* Visual Computing Lab /\/| *
* ISTI - Italian National Research Council | *
* \ *
* All rights reserved. *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt) *
* for more details. *
* *
****************************************************************************/
#ifndef __ML_SCENE_RENDERER_H
#define __ML_SCENE_RENDERER_H
#include <GL/glew.h>
#include "mesh.h"
#include <wrap/gl/gl_mesh_attributes_feeder.h>
#include <QObject>
#include <QMap>
#include <QReadWriteLock>
class MLThreadSafeMemoryInfo;
class MLThreadSafeGLMeshAttributesFeeder : public vcg::GLMeshAttributesFeeder<CMeshO>
{
public:
struct MLThreadSafeTextureNamesContainer
{
MLThreadSafeTextureNamesContainer();
~MLThreadSafeTextureNamesContainer();
void push_back(GLuint textid);
size_t size() const;
bool empty() const;
void clear();
GLuint& operator[](size_t ii) {return _tmid[ii];};
inline std::vector<GLuint>& textId() {return _tmid;};
private:
std::vector<GLuint> _tmid;
mutable QReadWriteLock _lock;
};
MLThreadSafeGLMeshAttributesFeeder(CMeshO& mesh,MLThreadSafeMemoryInfo& gpumeminfo,size_t perbatchtriangles);
~MLThreadSafeGLMeshAttributesFeeder() {};
void setPerBatchTriangles(size_t perbatchtriangles);
size_t perBatchTriangles() const;
bool renderedWithBO() const;
GLuint bufferObjectHandle() const;
void meshAttributesUpdated(int mask);
vcg::GLFeederInfo::ReqAtts setupRequestedAttributes(const vcg::GLFeederInfo::ReqAtts& rq,bool& allocated);
void deAllocateBO();
void drawWire(vcg::GLFeederInfo::ReqAtts& rq);
void drawFlatWire(vcg::GLFeederInfo::ReqAtts& rq);
void drawPoints(vcg::GLFeederInfo::ReqAtts& rq);
void drawTriangles(vcg::GLFeederInfo::ReqAtts& rq);
void drawBBox(vcg::GLFeederInfo::ReqAtts& rq);
inline CMeshO& mesh() {return _mesh;}
inline MLThreadSafeTextureNamesContainer& textureIDContainer() {return _textids;}
void buffersDeAllocationRequested();
private:
mutable QReadWriteLock _lock;
MLThreadSafeTextureNamesContainer _textids;
};
#endif

View File

@ -1,65 +0,0 @@
/****************************************************************************
* MeshLab o o *
* A versatile mesh processing toolbox o o *
* _ O _ *
* Copyright(C) 2005 \/)\/ *
* Visual Computing Lab /\/| *
* ISTI - Italian National Research Council | *
* \ *
* All rights reserved. *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt) *
* for more details. *
* *
****************************************************************************/
#include "ml_thread_safe_memory_info.h"
MLThreadSafeMemoryInfo::MLThreadSafeMemoryInfo( std::ptrdiff_t originalmem )
:vcg::NotThreadSafeMemoryInfo(originalmem),lock(QReadWriteLock::Recursive)
{
}
MLThreadSafeMemoryInfo::~MLThreadSafeMemoryInfo()
{
}
void MLThreadSafeMemoryInfo::acquiredMemory(std::ptrdiff_t mem)
{
QWriteLocker locker(&lock);
vcg::NotThreadSafeMemoryInfo::acquiredMemory(mem);
}
std::ptrdiff_t MLThreadSafeMemoryInfo::usedMemory() const
{
QReadLocker locker(&lock);
return vcg::NotThreadSafeMemoryInfo::usedMemory();
}
std::ptrdiff_t MLThreadSafeMemoryInfo::currentFreeMemory() const
{
QReadLocker locker(&lock);
return vcg::NotThreadSafeMemoryInfo::currentFreeMemory();
}
void MLThreadSafeMemoryInfo::releasedMemory(std::ptrdiff_t mem)
{
QWriteLocker locker(&lock);
vcg::NotThreadSafeMemoryInfo::releasedMemory(mem);
}
bool MLThreadSafeMemoryInfo::isAdditionalMemoryAvailable( std::ptrdiff_t mem )
{
QReadLocker locker(&lock);
return vcg::NotThreadSafeMemoryInfo::isAdditionalMemoryAvailable(mem);
}

View File

@ -1,55 +0,0 @@
/****************************************************************************
* MeshLab o o *
* A versatile mesh processing toolbox o o *
* _ O _ *
* Copyright(C) 2005 \/)\/ *
* Visual Computing Lab /\/| *
* ISTI - Italian National Research Council | *
* \ *
* All rights reserved. *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt) *
* for more details. *
* *
****************************************************************************/
#ifndef __ML_THREAD_SAFE_MEMORY_INFO_H
#define __ML_THREAD_SAFE_MEMORY_INFO_H
#include <QReadWriteLock>
#include <wrap/system/memory_info.h>
class MLThreadSafeMemoryInfo : public vcg::NotThreadSafeMemoryInfo
{
public:
MLThreadSafeMemoryInfo(std::ptrdiff_t originalmem);
~MLThreadSafeMemoryInfo();
void acquiredMemory(std::ptrdiff_t mem);
std::ptrdiff_t usedMemory() const;
std::ptrdiff_t currentFreeMemory() const;
void releasedMemory(std::ptrdiff_t mem = 0);
bool isAdditionalMemoryAvailable(std::ptrdiff_t mem);
private:
//mutable objects can be modified from the declared const functions
//in this way we have not to modified the basic vcg::MemoryInfo interface for the logically const functions
//whose need to lock the mutex for a simple reading operation
mutable QReadWriteLock lock;
};
#endif

View File

@ -37,17 +37,12 @@ win32{
# Input # Input
HEADERS += mainwindow.h HEADERS += mainwindow.h
HEADERS += glarea.h HEADERS += glarea.h
HEADERS += ml_thread_safe_memory_info.h
HEADERS += ml_scene_renderer.h
HEADERS += ml_atomic_guard.h
SOURCES += main.cpp SOURCES += main.cpp
SOURCES += mainwindow.cpp SOURCES += mainwindow.cpp
SOURCES += glarea.cpp SOURCES += glarea.cpp
SOURCES += ml_thread_safe_memory_info.cpp
SOURCES += ml_scene_renderer.cpp
FORMS += mainwindow.ui FORMS += mainwindow.ui