- updated version of the shared context - multiple windows renderer
This commit is contained in:
parent
8842cea2b3
commit
1864d686c0
|
@ -30,6 +30,7 @@ Initial release.
|
||||||
|
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
#include "glarea.h"
|
#include "glarea.h"
|
||||||
#include <QKeyEvent>
|
#include <QKeyEvent>
|
||||||
#include <QKeyEvent>
|
#include <QKeyEvent>
|
||||||
|
@ -39,14 +40,14 @@ Initial release.
|
||||||
|
|
||||||
#ifdef Q_OS_MAC
|
#ifdef Q_OS_MAC
|
||||||
#define glGenVertexArrays glGenVertexArraysAPPLE
|
#define glGenVertexArrays glGenVertexArraysAPPLE
|
||||||
#define glBindVertexArrays glBindVertexArraysAPPLE
|
#define glBindVertexArray glBindVertexArrayAPPLE
|
||||||
#define glDeleteVertexArrays glDeleteVertexArraysAPPLE
|
#define glDeleteVertexArrays glDeleteVertexArraysAPPLE
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
GLArea::GLArea (CMesh& m,MLThreadSafeGLMeshAttributesFeeder& feed,QWidget * parent)
|
GLArea::GLArea (CMesh& m, MLThreadSafeGLMeshAttributesFeeder& feed,QWidget* parent,QGLWidget* sharedcont)
|
||||||
:QGLWidget (parent),vaohandlespecificicforglcontext(0),mesh(m),feeder(feed)
|
:QGLWidget (parent,sharedcont),vaohandlespecificicforglcontext(0),mesh(m),feeder(feed),sem(0)
|
||||||
{
|
{
|
||||||
drawmode= SMOOTH;
|
drawmode= MDM_SMOOTH;
|
||||||
}
|
}
|
||||||
|
|
||||||
GLArea::~GLArea()
|
GLArea::~GLArea()
|
||||||
|
@ -54,21 +55,11 @@ GLArea::~GLArea()
|
||||||
glDeleteVertexArrays(1,&vaohandlespecificicforglcontext);
|
glDeleteVertexArrays(1,&vaohandlespecificicforglcontext);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GLArea::initializeGL()
|
||||||
void GLArea::selectDrawMode(int mode)
|
|
||||||
{
|
|
||||||
feeder.update(vcg::GLMeshAttributesFeeder<CMesh>::ATT_ALL);
|
|
||||||
drawmode=DrawMode(mode);
|
|
||||||
updateGL();
|
|
||||||
}
|
|
||||||
|
|
||||||
void GLArea::initializeGL ()
|
|
||||||
{
|
{
|
||||||
makeCurrent();
|
makeCurrent();
|
||||||
glewExperimental=GL_TRUE;
|
glewExperimental=GL_TRUE;
|
||||||
glewInit();
|
glewInit();
|
||||||
if (vaohandlespecificicforglcontext == 0)
|
|
||||||
glGenVertexArrays(1,&vaohandlespecificicforglcontext);
|
|
||||||
glClearColor(0, 0, 0, 0);
|
glClearColor(0, 0, 0, 0);
|
||||||
glEnable(GL_LIGHTING);
|
glEnable(GL_LIGHTING);
|
||||||
glEnable(GL_LIGHT0);
|
glEnable(GL_LIGHT0);
|
||||||
|
@ -76,18 +67,21 @@ 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);
|
||||||
|
glGenVertexArrays(1,&vaohandlespecificicforglcontext);
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
||||||
initializeGL();
|
//initializeGL();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLArea::paintGL ()
|
void GLArea::paintGL ()
|
||||||
{
|
{
|
||||||
makeCurrent();
|
makeCurrent();
|
||||||
|
//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);
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
|
@ -102,34 +96,38 @@ void GLArea::paintGL ()
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
float d=2.0f/mesh.bbox.Diag();
|
float d=2.0f/mesh.bbox.Diag();
|
||||||
vcg::glScale(d);
|
vcg::glScale(d);
|
||||||
glTranslate(mesh.bbox.Center());
|
glTranslate(-mesh.bbox.Center());
|
||||||
// the trimesh drawing calls
|
|
||||||
|
|
||||||
switch(drawmode)
|
if (sem == true)
|
||||||
{
|
{
|
||||||
case SMOOTH:
|
glBindVertexArray(vaohandlespecificicforglcontext);
|
||||||
feeder.drawTriangles(vaohandlespecificicforglcontext,vcg::GLFeedEnum::NR_PERVERT,vcg::GLFeedEnum::CL_NONE,vcg::GLFeedEnum::TX_NONE);
|
switch(drawmode)
|
||||||
break;
|
{
|
||||||
case POINTS:
|
case MDM_SMOOTH:
|
||||||
feeder.drawPoints(vaohandlespecificicforglcontext,vcg::GLFeedEnum::CL_NONE);
|
feeder.drawTriangles(vaohandlespecificicforglcontext,vcg::GLFeedEnum::NR_PERVERT,vcg::GLFeedEnum::CL_NONE,vcg::GLFeedEnum::TX_NONE);
|
||||||
break;
|
break;
|
||||||
case WIRE:
|
case MDM_POINTS:
|
||||||
feeder.drawWire(vaohandlespecificicforglcontext,vcg::GLFeedEnum::NR_PERVERT,vcg::GLFeedEnum::CL_NONE);
|
feeder.drawPoints(vaohandlespecificicforglcontext,vcg::GLFeedEnum::NR_PERVERT,vcg::GLFeedEnum::CL_NONE);
|
||||||
break;
|
break;
|
||||||
case FLATWIRE:
|
case MDM_WIRE:
|
||||||
feeder.drawFlatWire(vaohandlespecificicforglcontext,vcg::GLFeedEnum::CL_NONE,vcg::GLFeedEnum::TX_NONE);
|
feeder.drawWire(vaohandlespecificicforglcontext,vcg::GLFeedEnum::NR_PERVERT,vcg::GLFeedEnum::CL_NONE);
|
||||||
break;
|
break;
|
||||||
case FLAT:
|
case MDM_FLATWIRE:
|
||||||
feeder.drawTriangles(vaohandlespecificicforglcontext,vcg::GLFeedEnum::NR_PERFACE,vcg::GLFeedEnum::CL_NONE,vcg::GLFeedEnum::TX_NONE);
|
feeder.drawFlatWire(vaohandlespecificicforglcontext,vcg::GLFeedEnum::CL_NONE,vcg::GLFeedEnum::TX_NONE);
|
||||||
break;
|
break;
|
||||||
default:
|
case MDM_FLAT:
|
||||||
break;
|
feeder.drawTriangles(vaohandlespecificicforglcontext,vcg::GLFeedEnum::NR_PERFACE,vcg::GLFeedEnum::CL_NONE,vcg::GLFeedEnum::TX_NONE);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
glBindVertexArray(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
track.DrawPostApply();
|
track.DrawPostApply();
|
||||||
GLenum err = glGetError();
|
GLenum err = glGetError();
|
||||||
assert(err == GL_NO_ERROR);
|
assert(err == GL_NO_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLArea::keyReleaseEvent (QKeyEvent * e)
|
void GLArea::keyReleaseEvent (QKeyEvent * e)
|
||||||
|
@ -184,3 +182,73 @@ void GLArea::wheelEvent (QWheelEvent * e)
|
||||||
track.MouseWheel (e->delta () / float (WHEEL_STEP), QTWheel2VCG (e->modifiers ()));
|
track.MouseWheel (e->delta () / float (WHEEL_STEP), QTWheel2VCG (e->modifiers ()));
|
||||||
updateGL ();
|
updateGL ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GLArea::setupEnvironment(MyDrawMode mode)
|
||||||
|
{
|
||||||
|
sem = false;
|
||||||
|
drawmode=mode;
|
||||||
|
makeCurrent();
|
||||||
|
std::vector<bool> import(8,false);
|
||||||
|
|
||||||
|
switch(drawmode)
|
||||||
|
{
|
||||||
|
case MDM_SMOOTH:
|
||||||
|
case MDM_WIRE:
|
||||||
|
feeder.attributesToBeImportedInTriangleBasedPipeline(import,vcg::GLFeedEnum::NR_PERVERT,vcg::GLFeedEnum::CL_NONE,vcg::GLFeedEnum::TX_NONE);
|
||||||
|
break;
|
||||||
|
case MDM_POINTS:
|
||||||
|
feeder.attributesToBeImportedInPointBasedPipeline(import,vcg::GLFeedEnum::NR_PERVERT,vcg::GLFeedEnum::CL_NONE);
|
||||||
|
break;
|
||||||
|
case MDM_FLAT:
|
||||||
|
case MDM_FLATWIRE:
|
||||||
|
feeder.attributesToBeImportedInTriangleBasedPipeline(import,vcg::GLFeedEnum::NR_PERFACE,vcg::GLFeedEnum::CL_NONE,vcg::GLFeedEnum::TX_NONE);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
feeder.updateClientSideEnvironmentVAO(vaohandlespecificicforglcontext,import);
|
||||||
|
sem = true;
|
||||||
|
updateGL();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
SharedDataOpenGLContext::SharedDataOpenGLContext( CMesh& mesh,MLThreadSafeMemoryInfo& mi,QWidget* parent /*= 0*/ )
|
||||||
|
:QGLWidget(parent),feeder(mesh,mi,100000),vaohandlespecificicforglcontext(0),drawmode(MDM_SMOOTH)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
SharedDataOpenGLContext::~SharedDataOpenGLContext()
|
||||||
|
{
|
||||||
|
makeCurrent();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SharedDataOpenGLContext::myInitGL()
|
||||||
|
{
|
||||||
|
makeCurrent();
|
||||||
|
glewInit();
|
||||||
|
glGenVertexArrays(1,&vaohandlespecificicforglcontext);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SharedDataOpenGLContext::passInfoToOpenGL(int mode)
|
||||||
|
{
|
||||||
|
makeCurrent();
|
||||||
|
drawmode = static_cast<MyDrawMode>(mode);
|
||||||
|
//_tsbm.setUpBuffers();
|
||||||
|
switch(drawmode)
|
||||||
|
{
|
||||||
|
case MDM_SMOOTH:
|
||||||
|
case MDM_WIRE:
|
||||||
|
feeder.tryToAllocatePerTriangleAttributesInBO(vaohandlespecificicforglcontext,vcg::GLFeedEnum::NR_PERVERT,vcg::GLFeedEnum::CL_NONE,vcg::GLFeedEnum::TX_NONE);
|
||||||
|
break;
|
||||||
|
case MDM_POINTS:
|
||||||
|
feeder.tryToAllocatePerPointAttributesInBO(vaohandlespecificicforglcontext,vcg::GLFeedEnum::NR_PERVERT,vcg::GLFeedEnum::CL_NONE);
|
||||||
|
break;
|
||||||
|
case MDM_FLAT:
|
||||||
|
case MDM_FLATWIRE:
|
||||||
|
feeder.tryToAllocatePerTriangleAttributesInBO(vaohandlespecificicforglcontext,vcg::GLFeedEnum::NR_PERFACE,vcg::GLFeedEnum::CL_NONE,vcg::GLFeedEnum::TX_NONE);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
emit dataReadyToBeRead(drawmode);
|
||||||
|
}
|
||||||
|
|
|
@ -37,26 +37,50 @@ Initial release.
|
||||||
#include <GL/glew.h>
|
#include <GL/glew.h>
|
||||||
#include <QGLWidget>
|
#include <QGLWidget>
|
||||||
|
|
||||||
|
|
||||||
/// wrapper imports
|
/// wrapper imports
|
||||||
#include <wrap/gui/trackball.h>
|
#include <wrap/gui/trackball.h>
|
||||||
|
|
||||||
|
|
||||||
#include "mesh.h"
|
#include "mesh.h"
|
||||||
#include "ml_scene_renderer.h"
|
#include "ml_scene_renderer.h"
|
||||||
|
#include "ml_atomic_guard.h"
|
||||||
/// declaring edge and face type
|
/// declaring edge and face type
|
||||||
|
|
||||||
|
|
||||||
|
enum MyDrawMode{MDM_SMOOTH=0,MDM_POINTS,MDM_WIRE,MDM_FLATWIRE,MDM_FLAT};
|
||||||
|
|
||||||
|
class SharedDataOpenGLContext : public QGLWidget
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
SharedDataOpenGLContext(CMesh& mesh,MLThreadSafeMemoryInfo& mi,QWidget* parent = 0);
|
||||||
|
~SharedDataOpenGLContext();
|
||||||
|
|
||||||
|
void myInitGL();
|
||||||
|
|
||||||
|
MLThreadSafeGLMeshAttributesFeeder feeder;
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
/// widget-based user interaction slots
|
||||||
|
void passInfoToOpenGL(int mode);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void dataReadyToBeRead(MyDrawMode mode);
|
||||||
|
private:
|
||||||
|
GLuint vaohandlespecificicforglcontext;
|
||||||
|
MyDrawMode drawmode;
|
||||||
|
};
|
||||||
|
|
||||||
class GLArea:public QGLWidget
|
class GLArea:public QGLWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
GLArea (CMesh& m,MLThreadSafeGLMeshAttributesFeeder& feed,QWidget * parent = 0);
|
GLArea (CMesh& m,MLThreadSafeGLMeshAttributesFeeder& feed,QWidget* parent = NULL,QGLWidget* sharedcont = NULL);
|
||||||
~GLArea();
|
~GLArea();
|
||||||
/// we choosed a subset of the avaible drawing modes
|
/// we choosed a subset of the avaible drawing modes
|
||||||
enum DrawMode{SMOOTH=0,POINTS,WIRE,FLATWIRE,FLAT};
|
public slots:
|
||||||
public slots:
|
void setupEnvironment(MyDrawMode mode);
|
||||||
/// widget-based user interaction slots
|
|
||||||
void selectDrawMode(int mode);
|
|
||||||
signals:
|
signals:
|
||||||
/// signal for setting the statusbar message
|
/// signal for setting the statusbar message
|
||||||
void setStatusBar(QString message);
|
void setStatusBar(QString message);
|
||||||
|
@ -73,17 +97,29 @@ protected:
|
||||||
void mouseReleaseEvent(QMouseEvent*e);
|
void mouseReleaseEvent(QMouseEvent*e);
|
||||||
void wheelEvent(QWheelEvent*e);
|
void wheelEvent(QWheelEvent*e);
|
||||||
private:
|
private:
|
||||||
|
MLAtomicGuard sem;
|
||||||
|
|
||||||
GLuint vaohandlespecificicforglcontext;
|
GLuint vaohandlespecificicforglcontext;
|
||||||
/// the active mesh instance
|
/// the active mesh instance
|
||||||
CMesh& mesh;
|
CMesh& mesh;
|
||||||
/// the active manipulator
|
/// the active manipulator
|
||||||
vcg::Trackball track;
|
vcg::Trackball track;
|
||||||
/// the current drawmode
|
|
||||||
DrawMode drawmode;
|
|
||||||
/// mesh data structure initializer
|
/// mesh data structure initializer
|
||||||
void initMesh(QString message);
|
void initMesh(QString message);
|
||||||
//MLThreadSafeMemoryInfo& mi;
|
//MLThreadSafeMemoryInfo& mi;
|
||||||
MLThreadSafeGLMeshAttributesFeeder& feeder;
|
MLThreadSafeGLMeshAttributesFeeder& feeder;
|
||||||
|
|
||||||
|
MyDrawMode drawmode;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//class GLAreaEXT:public GLArea
|
||||||
|
//{
|
||||||
|
// Q_OBJECT
|
||||||
|
//public:
|
||||||
|
// GLAreaEXT (CMesh& m,MLThreadSafeGLMeshAttributesFeeder& feed,QWidget * parent = NULL,QGLWidget* shared = NULL);
|
||||||
|
// ~GLAreaEXT();
|
||||||
|
//
|
||||||
|
// void paintGL ();
|
||||||
|
//};
|
||||||
|
|
||||||
#endif /*GLAREA_H_ */
|
#endif /*GLAREA_H_ */
|
||||||
|
|
|
@ -42,7 +42,7 @@ $Log: not supported by cvs2svn $
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
QApplication app(argc, argv);
|
QApplication app(argc, argv);
|
||||||
MainWindow *mw = new MainWindow;
|
MainWindow mw;
|
||||||
mw->show();
|
mw.show();
|
||||||
return app.exec();
|
return app.exec();
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,23 +31,30 @@ $Log: not supported by cvs2svn $
|
||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
MainWindow::MainWindow (QWidget * parent)
|
MainWindow::MainWindow (QWidget * parent)
|
||||||
:QMainWindow (parent),mi(1000000000),mesh(),feeder(mesh,mi,100000)
|
:QMainWindow (parent),mi(1000000000),mesh()
|
||||||
{
|
{
|
||||||
ui.setupUi (this);
|
ui.setupUi (this);
|
||||||
QLayout* tmp = ui.glFrame->layout();
|
QLayout* tmp = ui.glFrame->layout();
|
||||||
|
|
||||||
|
//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...
|
||||||
|
shared = new SharedDataOpenGLContext(mesh,mi,NULL);
|
||||||
|
shared->setHidden(true);
|
||||||
|
shared->myInitGL();
|
||||||
|
connect (ui.drawModeComboBox, SIGNAL (currentIndexChanged(int)),shared, SLOT (passInfoToOpenGL(int)));
|
||||||
|
|
||||||
for(int ii = 0;ii < 2;++ii)
|
for(int ii = 0;ii < 2;++ii)
|
||||||
{
|
{
|
||||||
glar[ii] = new GLArea(mesh,feeder,this);
|
glar[ii] = new GLArea(mesh,shared->feeder,NULL,shared);
|
||||||
|
connect (shared,SIGNAL(dataReadyToBeRead(MyDrawMode)),glar[ii], SLOT (setupEnvironment(MyDrawMode)));
|
||||||
connect (ui.drawModeComboBox, SIGNAL (currentIndexChanged(int)),
|
|
||||||
glar[ii], SLOT (selectDrawMode(int)));
|
|
||||||
|
|
||||||
tmp->addWidget(glar[ii]);
|
tmp->addWidget(glar[ii]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
connect (ui.loadMeshPushButton, SIGNAL (clicked()),this, SLOT (chooseMesh()));
|
connect (ui.loadMeshPushButton, SIGNAL (clicked()),this, SLOT (chooseMesh()));
|
||||||
connect (ui.loadTetrahedronPushButton, SIGNAL (clicked()),this, SLOT (loadTetrahedron()));
|
connect (ui.loadTetrahedronPushButton, SIGNAL (clicked()),this, SLOT (loadTetrahedron()));
|
||||||
connect (ui.loadDodecahedronPushButton, SIGNAL (clicked()),this, SLOT (loadDodecahedron()));
|
connect (ui.loadDodecahedronPushButton, SIGNAL (clicked()),this, SLOT (loadDodecahedron()));
|
||||||
|
@ -87,15 +94,18 @@ void MainWindow::loadDodecahedron()
|
||||||
|
|
||||||
void MainWindow::initMesh(QString message)
|
void MainWindow::initMesh(QString message)
|
||||||
{
|
{
|
||||||
//feeder.update(vcg::GLMeshAttributesFeeder<CMesh>::ATT_ALL);
|
ui.statusbar->showMessage(message);
|
||||||
// update bounding box
|
// update bounding box
|
||||||
vcg::tri::UpdateBounding<CMesh>::Box(mesh);
|
vcg::tri::UpdateBounding<CMesh>::Box(mesh);
|
||||||
// update Normals
|
// update Normals
|
||||||
vcg::tri::UpdateNormal<CMesh>::PerVertexNormalizedPerFaceNormalized(mesh);
|
vcg::tri::UpdateNormal<CMesh>::PerVertexNormalizedPerFaceNormalized(mesh);
|
||||||
|
shared->feeder.update(vcg::GLMeshAttributesFeeder<CMesh>::ATT_ALL);
|
||||||
|
shared->passInfoToOpenGL(ui.drawModeComboBox->currentIndex());
|
||||||
|
}
|
||||||
|
|
||||||
|
MainWindow::~MainWindow()
|
||||||
|
{
|
||||||
for(int ii = 0;ii < 2;++ii)
|
for(int ii = 0;ii < 2;++ii)
|
||||||
{
|
delete glar[ii];
|
||||||
feeder.update(vcg::GLMeshAttributesFeeder<CMesh>::ATT_ALL);
|
delete shared;
|
||||||
glar[ii]->updateGL();
|
}
|
||||||
}
|
|
||||||
ui.statusbar->showMessage(message);
|
|
||||||
}
|
|
||||||
|
|
|
@ -33,11 +33,13 @@ $Log: not supported by cvs2svn $
|
||||||
#include "glarea.h"
|
#include "glarea.h"
|
||||||
#include "ml_thread_safe_memory_info.h"
|
#include "ml_thread_safe_memory_info.h"
|
||||||
|
|
||||||
|
|
||||||
class MainWindow:public QMainWindow
|
class MainWindow:public QMainWindow
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
MainWindow(QWidget * parent = 0);
|
MainWindow(QWidget * parent = 0);
|
||||||
|
~MainWindow();
|
||||||
public slots:
|
public slots:
|
||||||
void chooseMesh();
|
void chooseMesh();
|
||||||
void loadTetrahedron();
|
void loadTetrahedron();
|
||||||
|
@ -50,11 +52,10 @@ private:
|
||||||
Ui::mainWindow ui;
|
Ui::mainWindow ui;
|
||||||
GLArea* glar[2];
|
GLArea* glar[2];
|
||||||
|
|
||||||
GLArea* shared;
|
SharedDataOpenGLContext* shared;
|
||||||
MLThreadSafeMemoryInfo mi;
|
MLThreadSafeMemoryInfo mi;
|
||||||
/// the active mesh instance
|
/// the active mesh instance
|
||||||
CMesh mesh;
|
CMesh mesh;
|
||||||
MLThreadSafeGLMeshAttributesFeeder feeder;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /*MAINWINDOW_H_ */
|
#endif /*MAINWINDOW_H_ */
|
||||||
|
|
|
@ -0,0 +1,36 @@
|
||||||
|
#ifndef __ML_ATOMIC_GUARD_H
|
||||||
|
#define __ML_ATOMIC_GUARD_H
|
||||||
|
|
||||||
|
class MLAtomicGuard
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
MLAtomicGuard(bool val)
|
||||||
|
:_lock(QReadWriteLock::Recursive),_guard(val) {}
|
||||||
|
|
||||||
|
~MLAtomicGuard() {}
|
||||||
|
|
||||||
|
MLAtomicGuard& operator=(bool v)
|
||||||
|
{
|
||||||
|
QWriteLocker locker(&_lock);
|
||||||
|
_guard = v;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator==(bool v) const
|
||||||
|
{
|
||||||
|
QReadLocker locker(&_lock);
|
||||||
|
return (_guard == v);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator!=(bool v) const
|
||||||
|
{
|
||||||
|
QReadLocker locker(&_lock);
|
||||||
|
return (_guard != v);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool _guard;
|
||||||
|
mutable QReadWriteLock _lock;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
|
@ -38,12 +38,12 @@ void MLThreadSafeGLMeshAttributesFeeder::drawWire(GLuint& vaohandlespecificperop
|
||||||
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MLThreadSafeGLMeshAttributesFeeder::drawFlatWire(GLuint& vaohandlespecificperopenglcontext,vcg::GLFeedEnum::COLOR_MODALITY cm,vcg::GLFeedEnum::TEXTURE_MODALITY tm )
|
void MLThreadSafeGLMeshAttributesFeeder::drawFlatWire(GLuint& vaohandlespecificperopenglcontext,vcg::GLFeedEnum::COLOR_MODALITY cm,vcg::GLFeedEnum::TEXTURE_MODALITY tm,const std::vector<GLuint>& textureindex )
|
||||||
{
|
{
|
||||||
glPushAttrib(GL_ENABLE_BIT | GL_CURRENT_BIT | GL_LIGHTING_BIT );
|
glPushAttrib(GL_ENABLE_BIT | GL_CURRENT_BIT | GL_LIGHTING_BIT );
|
||||||
glEnable(GL_POLYGON_OFFSET_FILL);
|
glEnable(GL_POLYGON_OFFSET_FILL);
|
||||||
glPolygonOffset(1.0, 1);
|
glPolygonOffset(1.0, 1);
|
||||||
drawTriangles(vaohandlespecificperopenglcontext,vcg::GLFeedEnum::NR_PERFACE,cm,tm);
|
drawTriangles(vaohandlespecificperopenglcontext,vcg::GLFeedEnum::NR_PERFACE,cm,tm,textureindex);
|
||||||
|
|
||||||
glDisable(GL_POLYGON_OFFSET_FILL);
|
glDisable(GL_POLYGON_OFFSET_FILL);
|
||||||
glEnable(GL_COLOR_MATERIAL);
|
glEnable(GL_COLOR_MATERIAL);
|
||||||
|
@ -54,16 +54,73 @@ void MLThreadSafeGLMeshAttributesFeeder::drawFlatWire(GLuint& vaohandlespecificp
|
||||||
glPopAttrib();
|
glPopAttrib();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MLThreadSafeGLMeshAttributesFeeder::drawPoints(GLuint& vaohandlespecificperopenglcontext,vcg::GLFeedEnum::COLOR_MODALITY cm )
|
void MLThreadSafeGLMeshAttributesFeeder::drawPoints(GLuint& vaohandlespecificperopenglcontext,vcg::GLFeedEnum::NORMAL_MODALITY nm,vcg::GLFeedEnum::COLOR_MODALITY cm )
|
||||||
|
{
|
||||||
|
passPointsToOpenGL(vaohandlespecificperopenglcontext,cm);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MLThreadSafeGLMeshAttributesFeeder::passPointsToOpenGL(GLuint& vaohandlespecificperopenglcontext,vcg::GLFeedEnum::COLOR_MODALITY cm )
|
||||||
{
|
{
|
||||||
QWriteLocker locker(&_lock);
|
QWriteLocker locker(&_lock);
|
||||||
GLMeshAttributesFeeder<CMesh>::passPointsToOpenGL(vaohandlespecificperopenglcontext,vcg::GLFeedEnum::NR_PERVERT,cm);
|
GLMeshAttributesFeeder<CMesh>::passPointsToOpenGL(vaohandlespecificperopenglcontext,vcg::GLFeedEnum::NR_PERVERT,cm);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MLThreadSafeGLMeshAttributesFeeder::drawTriangles(GLuint& vaohandlespecificperopenglcontext,vcg::GLFeedEnum::NORMAL_MODALITY nm,vcg::GLFeedEnum::COLOR_MODALITY cm,vcg::GLFeedEnum::TEXTURE_MODALITY tm )
|
void MLThreadSafeGLMeshAttributesFeeder::drawTriangles(GLuint& vaohandlespecificperopenglcontext,vcg::GLFeedEnum::NORMAL_MODALITY nm,vcg::GLFeedEnum::COLOR_MODALITY cm,vcg::GLFeedEnum::TEXTURE_MODALITY tm,const std::vector<GLuint>& textureindex )
|
||||||
|
{
|
||||||
|
QReadLocker locker(&_lock);
|
||||||
|
GLMeshAttributesFeeder<CMesh>::drawTriangles(vaohandlespecificperopenglcontext,nm,cm,tm,textureindex);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MLThreadSafeGLMeshAttributesFeeder::passTrianglesToOpenGL(GLuint& vaohandlespecificperopenglcontext,vcg::GLFeedEnum::NORMAL_MODALITY nm,vcg::GLFeedEnum::COLOR_MODALITY cm,vcg::GLFeedEnum::TEXTURE_MODALITY tm )
|
||||||
{
|
{
|
||||||
QWriteLocker locker(&_lock);
|
QWriteLocker locker(&_lock);
|
||||||
GLMeshAttributesFeeder<CMesh>::passTrianglesToOpenGL(vaohandlespecificperopenglcontext,nm,cm,tm);
|
GLMeshAttributesFeeder<CMesh>::passTrianglesToOpenGL(vaohandlespecificperopenglcontext,nm,cm,tm);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool MLThreadSafeGLMeshAttributesFeeder::tryToAllocatePerTriangleAttributesInBO( GLuint& vaohandlespecificperopenglcontext,vcg::GLFeedEnum::NORMAL_MODALITY nm,vcg::GLFeedEnum::COLOR_MODALITY cm,vcg::GLFeedEnum::TEXTURE_MODALITY tm )
|
||||||
|
{
|
||||||
|
QWriteLocker locker(&_lock);
|
||||||
|
return GLMeshAttributesFeeder<CMesh>::tryToAllocatePerTriangleAttributesInBO(vaohandlespecificperopenglcontext,nm,cm,tm);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MLThreadSafeGLMeshAttributesFeeder::tryToAllocatePerPointAttributesInBO( GLuint& vaohandlespecificperopenglcontext,vcg::GLFeedEnum::NORMAL_MODALITY nm,vcg::GLFeedEnum::COLOR_MODALITY cm )
|
||||||
|
{
|
||||||
|
QWriteLocker locker(&_lock);
|
||||||
|
return GLMeshAttributesFeeder<CMesh>::tryToAllocatePerPointAttributesInBO(vaohandlespecificperopenglcontext,nm,cm);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MLThreadSafeGLMeshAttributesFeeder::updateClientSideEnvironmentVAO( GLuint& vaohandle,const std::vector<bool>& importattribute) const
|
||||||
|
{
|
||||||
|
QReadLocker locker(&_lock);
|
||||||
|
|
||||||
|
glBindVertexArray(vaohandle);
|
||||||
|
int ii = 0;
|
||||||
|
for(std::vector<GLBufferObject*>::const_iterator it = _bo.begin();it != _bo.end();++it)
|
||||||
|
{
|
||||||
|
BO_NAMES boname = static_cast<BO_NAMES>(ii);
|
||||||
|
GLBufferObject* cbo = _bo.at(boname);
|
||||||
|
if (!cbo->_isvalid)
|
||||||
|
disableClientState(boname,importattribute);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
glBindBuffer(cbo->_target, cbo->_bohandle);
|
||||||
|
setBufferPointerEnableClientState(boname);
|
||||||
|
glBindBuffer(cbo->_target, 0);
|
||||||
|
}
|
||||||
|
++ii;
|
||||||
|
}
|
||||||
|
glBindVertexArray(0);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MLThreadSafeGLMeshAttributesFeeder::attributesToBeImportedInPointBasedPipeline( std::vector<bool> &importattribute, NORMAL_MODALITY nm, COLOR_MODALITY cm ) const
|
||||||
|
{
|
||||||
|
QReadLocker locker(&_lock);
|
||||||
|
GLMeshAttributesFeeder<CMesh>::attributesToBeImportedInPointBasedPipeline(importattribute,nm,cm);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MLThreadSafeGLMeshAttributesFeeder::attributesToBeImportedInTriangleBasedPipeline( std::vector<bool> &importattribute, NORMAL_MODALITY nm, COLOR_MODALITY cm, TEXTURE_MODALITY tm ) const
|
||||||
|
{
|
||||||
|
QReadLocker locker(&_lock);
|
||||||
|
GLMeshAttributesFeeder<CMesh>::attributesToBeImportedInTriangleBasedPipeline(importattribute,nm,cm,tm);
|
||||||
|
}
|
||||||
|
|
|
@ -47,13 +47,33 @@ public:
|
||||||
size_t perBatchTriangles() const;
|
size_t perBatchTriangles() const;
|
||||||
bool renderedWithBO() const;
|
bool renderedWithBO() const;
|
||||||
void update(int mask);
|
void update(int mask);
|
||||||
|
|
||||||
|
void passTrianglesToOpenGL(GLuint& vaohandlespecificperopenglcontext,vcg::GLFeedEnum::NORMAL_MODALITY nm,vcg::GLFeedEnum::COLOR_MODALITY cm,vcg::GLFeedEnum::TEXTURE_MODALITY tm );
|
||||||
|
|
||||||
|
void passPointsToOpenGL(GLuint& vaohandlespecificperopenglcontext,vcg::GLFeedEnum::COLOR_MODALITY cm );
|
||||||
|
|
||||||
|
bool tryToAllocatePerTriangleAttributesInBO( GLuint& vaohandlespecificperopenglcontext,vcg::GLFeedEnum::NORMAL_MODALITY nm,vcg::GLFeedEnum::COLOR_MODALITY cm,vcg::GLFeedEnum::TEXTURE_MODALITY tm );
|
||||||
|
|
||||||
|
bool tryToAllocatePerPointAttributesInBO( GLuint& vaohandlespecificperopenglcontext,vcg::GLFeedEnum::NORMAL_MODALITY nm,vcg::GLFeedEnum::COLOR_MODALITY cm );
|
||||||
|
|
||||||
|
GLuint bufferObjectHandle() const;
|
||||||
|
|
||||||
void drawWire(GLuint& vaohandlespecificperopenglcontext,vcg::GLFeedEnum::NORMAL_MODALITY nm,vcg::GLFeedEnum::COLOR_MODALITY cm);
|
void drawWire(GLuint& vaohandlespecificperopenglcontext,vcg::GLFeedEnum::NORMAL_MODALITY nm,vcg::GLFeedEnum::COLOR_MODALITY cm);
|
||||||
|
|
||||||
void drawFlatWire(GLuint& vaohandlespecificperopenglcontext,vcg::GLFeedEnum::COLOR_MODALITY cm,vcg::GLFeedEnum::TEXTURE_MODALITY tm);
|
void drawFlatWire(GLuint& vaohandlespecificperopenglcontext,vcg::GLFeedEnum::COLOR_MODALITY cm,vcg::GLFeedEnum::TEXTURE_MODALITY tm,const std::vector<GLuint>& textureindex = std::vector<GLuint>());
|
||||||
|
|
||||||
void drawPoints(GLuint& vaohandlespecificperopenglcontext,vcg::GLFeedEnum::COLOR_MODALITY cm);
|
void drawPoints(GLuint& vaohandlespecificperopenglcontext,vcg::GLFeedEnum::NORMAL_MODALITY nm,vcg::GLFeedEnum::COLOR_MODALITY cm);
|
||||||
|
|
||||||
|
void drawTriangles(GLuint& vaohandlespecificperopenglcontext,vcg::GLFeedEnum::NORMAL_MODALITY nm,vcg::GLFeedEnum::COLOR_MODALITY cm,vcg::GLFeedEnum::TEXTURE_MODALITY tm,const std::vector<GLuint>& textureindex = std::vector<GLuint>() );
|
||||||
|
|
||||||
|
bool enableClientSideEnvironmentVAO(GLuint& vaohandle) const;
|
||||||
|
|
||||||
|
bool updateClientSideEnvironmentVAO(GLuint& vaohandle,const std::vector<bool>& importattribute) const;
|
||||||
|
|
||||||
|
void attributesToBeImportedInPointBasedPipeline( std::vector<bool> &importattribute, NORMAL_MODALITY nm, COLOR_MODALITY cm) const;
|
||||||
|
|
||||||
|
void attributesToBeImportedInTriangleBasedPipeline( std::vector<bool> &importattribute, NORMAL_MODALITY nm, COLOR_MODALITY cm, TEXTURE_MODALITY tm ) const;
|
||||||
|
|
||||||
void drawTriangles(GLuint& vaohandlespecificperopenglcontext,vcg::GLFeedEnum::NORMAL_MODALITY nm,vcg::GLFeedEnum::COLOR_MODALITY cm,vcg::GLFeedEnum::TEXTURE_MODALITY tm);
|
|
||||||
private:
|
private:
|
||||||
mutable QReadWriteLock _lock;
|
mutable QReadWriteLock _lock;
|
||||||
};
|
};
|
||||||
|
|
|
@ -35,38 +35,31 @@ MLThreadSafeMemoryInfo::~MLThreadSafeMemoryInfo()
|
||||||
|
|
||||||
void MLThreadSafeMemoryInfo::acquiredMemory(long long unsigned int mem)
|
void MLThreadSafeMemoryInfo::acquiredMemory(long long unsigned int mem)
|
||||||
{
|
{
|
||||||
lock.lockForWrite();
|
QWriteLocker locker(&lock);
|
||||||
vcg::NotThreadSafeMemoryInfo::acquiredMemory(mem);
|
vcg::NotThreadSafeMemoryInfo::acquiredMemory(mem);
|
||||||
lock.unlock();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
long long unsigned int MLThreadSafeMemoryInfo::usedMemory() const
|
long long unsigned int MLThreadSafeMemoryInfo::usedMemory() const
|
||||||
{
|
{
|
||||||
lock.lockForRead();
|
QReadLocker locker(&lock);
|
||||||
long long unsigned int tmp = vcg::NotThreadSafeMemoryInfo::usedMemory();
|
return vcg::NotThreadSafeMemoryInfo::usedMemory();
|
||||||
lock.unlock();
|
|
||||||
return tmp;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
long long unsigned int MLThreadSafeMemoryInfo::currentFreeMemory() const
|
long long unsigned int MLThreadSafeMemoryInfo::currentFreeMemory() const
|
||||||
{
|
{
|
||||||
lock.lockForRead();
|
QReadLocker locker(&lock);
|
||||||
long long unsigned int tmp = vcg::NotThreadSafeMemoryInfo::currentFreeMemory();
|
return vcg::NotThreadSafeMemoryInfo::currentFreeMemory();
|
||||||
lock.unlock();
|
|
||||||
return tmp;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MLThreadSafeMemoryInfo::releasedMemory(long long unsigned int mem)
|
void MLThreadSafeMemoryInfo::releasedMemory(long long unsigned int mem)
|
||||||
{
|
{
|
||||||
lock.lockForWrite();
|
QWriteLocker locker(&lock);
|
||||||
vcg::NotThreadSafeMemoryInfo::releasedMemory(mem);
|
vcg::NotThreadSafeMemoryInfo::releasedMemory(mem);
|
||||||
lock.unlock();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MLThreadSafeMemoryInfo::isAdditionalMemoryAvailable( long long unsigned int mem )
|
bool MLThreadSafeMemoryInfo::isAdditionalMemoryAvailable( long long unsigned int mem )
|
||||||
{
|
{
|
||||||
lock.lockForRead();
|
QReadLocker locker(&lock);
|
||||||
bool tmp = vcg::NotThreadSafeMemoryInfo::isAdditionalMemoryAvailable(mem);
|
return vcg::NotThreadSafeMemoryInfo::isAdditionalMemoryAvailable(mem);
|
||||||
lock.unlock();
|
|
||||||
return tmp;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,6 +39,8 @@ HEADERS += mainwindow.h
|
||||||
HEADERS += glarea.h
|
HEADERS += glarea.h
|
||||||
HEADERS += ml_thread_safe_memory_info.h
|
HEADERS += ml_thread_safe_memory_info.h
|
||||||
HEADERS += ml_scene_renderer.h
|
HEADERS += ml_scene_renderer.h
|
||||||
|
HEADERS += ml_atomic_guard.h
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
SOURCES += main.cpp
|
SOURCES += main.cpp
|
||||||
|
|
Loading…
Reference in New Issue