From 6bb2ed6382e82013677f653d4a810afd8367bac0 Mon Sep 17 00:00:00 2001 From: granzuglia Date: Thu, 30 Jul 2015 11:13:19 +0000 Subject: [PATCH] - recommitted last working version of the trimesh_QT_shared project contained in the git repository --- apps/sample/trimesh_QT_shared/glarea.cpp | 515 +++++++++--------- apps/sample/trimesh_QT_shared/glarea.h | 234 ++++---- apps/sample/trimesh_QT_shared/main.cpp | 96 ++-- apps/sample/trimesh_QT_shared/mainwindow.cpp | 224 ++++---- apps/sample/trimesh_QT_shared/mainwindow.h | 122 ++--- apps/sample/trimesh_QT_shared/mainwindow.ui | 402 +++++++------- apps/sample/trimesh_QT_shared/mesh.h | 50 +- .../trimesh_QT_shared/ml_scene_renderer.cpp | 219 +++++--- .../trimesh_QT_shared/ml_scene_renderer.h | 68 ++- .../ml_thread_safe_memory_info.cpp | 12 +- .../ml_thread_safe_memory_info.h | 17 +- apps/sample/trimesh_QT_shared/trimesh_qt.pro | 112 ++-- 12 files changed, 1078 insertions(+), 993 deletions(-) diff --git a/apps/sample/trimesh_QT_shared/glarea.cpp b/apps/sample/trimesh_QT_shared/glarea.cpp index 77c4eb6a..381f4bb2 100644 --- a/apps/sample/trimesh_QT_shared/glarea.cpp +++ b/apps/sample/trimesh_QT_shared/glarea.cpp @@ -1,254 +1,261 @@ -/**************************************************************************** -* VCGLib o o * -* Visual and Computer Graphics Library o o * -* _ O _ * -* Copyright(C) 2007 \/)\/ * -* 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. * -* * -****************************************************************************/ -/**************************************************************************** -History - -$Log: not supported by cvs2svn $ -Revision 1.1 2007/10/18 08:52:06 benedetti -Initial release. - - -****************************************************************************/ - - -#include "glarea.h" -#include -#include -#include -#include -#include - -#ifdef Q_OS_MAC -#define glGenVertexArrays glGenVertexArraysAPPLE -#define glBindVertexArray glBindVertexArrayAPPLE -#define glDeleteVertexArrays glDeleteVertexArraysAPPLE -#endif - -GLArea::GLArea (CMesh& m, MLThreadSafeGLMeshAttributesFeeder& feed,QWidget* parent,QGLWidget* sharedcont) - :QGLWidget (parent,sharedcont),vaohandlespecificicforglcontext(0),mesh(m),feeder(feed),sem(0) -{ - drawmode= MDM_SMOOTH; -} - -GLArea::~GLArea() -{ - glDeleteVertexArrays(1,&vaohandlespecificicforglcontext); -} - -void GLArea::initializeGL() -{ - makeCurrent(); - glewExperimental=GL_TRUE; - glewInit(); - glClearColor(0, 0, 0, 0); - glEnable(GL_LIGHTING); - glEnable(GL_LIGHT0); - glEnable(GL_NORMALIZE); - glEnable(GL_COLOR_MATERIAL); - glEnable(GL_CULL_FACE); - glEnable(GL_DEPTH_TEST); - glGenVertexArrays(1,&vaohandlespecificicforglcontext); -} - -void GLArea::resizeGL (int w, int h) -{ - makeCurrent(); - glViewport (0, 0, (GLsizei) w, (GLsizei) h); - //initializeGL(); -} - -void GLArea::paintGL () -{ - makeCurrent(); - //GLenum err = glGetError(); - //assert(err == GL_NO_ERROR); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - gluPerspective(25, GLArea::width()/(float)GLArea::height(), 0.1, 100); - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - gluLookAt(0,0,5, 0,0,0, 0,1,0); - track.center=vcg::Point3f(0, 0, 0); - track.radius= 1; - track.GetView(); - track.Apply(); - glPushMatrix(); - float d=2.0f/mesh.bbox.Diag(); - vcg::glScale(d); - glTranslate(-mesh.bbox.Center()); - - if (sem == true) - { - glBindVertexArray(vaohandlespecificicforglcontext); - switch(drawmode) - { - case MDM_SMOOTH: - feeder.drawTriangles(vaohandlespecificicforglcontext,vcg::GLFeedEnum::NR_PERVERT,vcg::GLFeedEnum::CL_NONE,vcg::GLFeedEnum::TX_NONE); - break; - case MDM_POINTS: - feeder.drawPoints(vaohandlespecificicforglcontext,vcg::GLFeedEnum::NR_PERVERT,vcg::GLFeedEnum::CL_NONE); - break; - case MDM_WIRE: - feeder.drawWire(vaohandlespecificicforglcontext,vcg::GLFeedEnum::NR_PERVERT,vcg::GLFeedEnum::CL_NONE); - break; - case MDM_FLATWIRE: - feeder.drawFlatWire(vaohandlespecificicforglcontext,vcg::GLFeedEnum::CL_NONE,vcg::GLFeedEnum::TX_NONE); - break; - case MDM_FLAT: - feeder.drawTriangles(vaohandlespecificicforglcontext,vcg::GLFeedEnum::NR_PERFACE,vcg::GLFeedEnum::CL_NONE,vcg::GLFeedEnum::TX_NONE); - break; - default: - break; - } - glBindVertexArray(0); - } - - glPopMatrix(); - track.DrawPostApply(); - GLenum err = glGetError(); - assert(err == GL_NO_ERROR); -} - -void GLArea::keyReleaseEvent (QKeyEvent * e) -{ - e->ignore (); - if (e->key () == Qt::Key_Control) - track.ButtonUp (QT2VCG (Qt::NoButton, Qt::ControlModifier)); - if (e->key () == Qt::Key_Shift) - track.ButtonUp (QT2VCG (Qt::NoButton, Qt::ShiftModifier)); - if (e->key () == Qt::Key_Alt) - track.ButtonUp (QT2VCG (Qt::NoButton, Qt::AltModifier)); - updateGL (); -} - -void GLArea::keyPressEvent (QKeyEvent * e) -{ - e->ignore (); - if (e->key () == Qt::Key_Control) - track.ButtonDown (QT2VCG (Qt::NoButton, Qt::ControlModifier)); - if (e->key () == Qt::Key_Shift) - track.ButtonDown (QT2VCG (Qt::NoButton, Qt::ShiftModifier)); - if (e->key () == Qt::Key_Alt) - track.ButtonDown (QT2VCG (Qt::NoButton, Qt::AltModifier)); - updateGL (); -} - -void GLArea::mousePressEvent (QMouseEvent * e) -{ - e->accept (); - setFocus (); - track.MouseDown (QT2VCG_X(this,e), QT2VCG_Y(this,e), QT2VCG (e->button (), e->modifiers ())); - updateGL (); -} - -void GLArea::mouseMoveEvent (QMouseEvent * e) -{ - if (e->buttons ()) { - track.MouseMove (QT2VCG_X(this,e), QT2VCG_Y(this,e)); - updateGL (); - } -} - -void GLArea::mouseReleaseEvent (QMouseEvent * e) -{ - track.MouseUp (QT2VCG_X(this,e), QT2VCG_Y(this,e), QT2VCG (e->button (), e->modifiers ())); - updateGL (); -} - -void GLArea::wheelEvent (QWheelEvent * e) -{ - const int WHEEL_STEP = 120; - track.MouseWheel (e->delta () / float (WHEEL_STEP), QTWheel2VCG (e->modifiers ())); - updateGL (); -} - -void GLArea::setupEnvironment(MyDrawMode mode) -{ - sem = false; - drawmode=mode; - makeCurrent(); - std::vector 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(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); -} +/**************************************************************************** +* VCGLib o o * +* Visual and Computer Graphics Library o o * +* _ O _ * +* Copyright(C) 2007 \/)\/ * +* 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. * +* * +****************************************************************************/ +/**************************************************************************** +History + +$Log: not supported by cvs2svn $ +Revision 1.1 2007/10/18 08:52:06 benedetti +Initial release. + + +****************************************************************************/ + + +#include "glarea.h" +#include +#include +#include +#include +#include + +#ifdef Q_OS_MAC +#define glGenVertexArrays glGenVertexArraysAPPLE +#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() +{ +} + +void GLArea::initializeGL() +{ + makeCurrent(); + glewExperimental=GL_TRUE; + glewInit(); + glClearColor(0, 0, 0, 0); + glEnable(GL_LIGHTING); + glEnable(GL_LIGHT0); + glEnable(GL_NORMALIZE); + glEnable(GL_COLOR_MATERIAL); + glEnable(GL_CULL_FACE); + glEnable(GL_DEPTH_TEST); +} + +void GLArea::resizeGL (int w, int h) +{ + makeCurrent(); + glViewport (0, 0, (GLsizei) w, (GLsizei) h); + //initializeGL(); +} + +void GLArea::paintGL () +{ + makeCurrent(); + glPushAttrib(GL_ALL_ATTRIB_BITS); + //GLenum err = glGetError(); + //assert(err == GL_NO_ERROR); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glMatrixMode(GL_PROJECTION); + glPushMatrix(); + glLoadIdentity(); + gluPerspective(25, GLArea::width()/(float)GLArea::height(), 0.1, 100); + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); + glLoadIdentity(); + gluLookAt(0,0,5, 0,0,0, 0,1,0); + track.center=vcg::Point3f(0, 0, 0); + track.radius= 1; + track.GetView(); + track.Apply(); + glPushMatrix(); + float d=2.0f/mesh.bbox.Diag(); + vcg::glScale(d); + glTranslate(-mesh.bbox.Center()); + + if (mesh.VN() > 0) + { + 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(); + + track.DrawPostApply(); + glPopMatrix(); + glMatrixMode(GL_PROJECTION); + glPopMatrix(); + glPopAttrib(); + //doneCurrent(); + GLenum err = glGetError(); + assert(err == GL_NO_ERROR); +} + +void GLArea::keyReleaseEvent (QKeyEvent * e) +{ + e->ignore (); + if (e->key () == Qt::Key_Control) + track.ButtonUp (QT2VCG (Qt::NoButton, Qt::ControlModifier)); + if (e->key () == Qt::Key_Shift) + track.ButtonUp (QT2VCG (Qt::NoButton, Qt::ShiftModifier)); + if (e->key () == Qt::Key_Alt) + track.ButtonUp (QT2VCG (Qt::NoButton, Qt::AltModifier)); + updateGL (); +} + +void GLArea::keyPressEvent (QKeyEvent * e) +{ + e->ignore (); + if (e->key () == Qt::Key_Control) + track.ButtonDown (QT2VCG (Qt::NoButton, Qt::ControlModifier)); + if (e->key () == Qt::Key_Shift) + track.ButtonDown (QT2VCG (Qt::NoButton, Qt::ShiftModifier)); + if (e->key () == Qt::Key_Alt) + track.ButtonDown (QT2VCG (Qt::NoButton, Qt::AltModifier)); + updateGL (); +} + +void GLArea::mousePressEvent (QMouseEvent * e) +{ + e->accept (); + setFocus (); + track.MouseDown (QT2VCG_X(this,e), QT2VCG_Y(this,e), QT2VCG (e->button (), e->modifiers ())); + updateGL (); +} + +void GLArea::mouseMoveEvent (QMouseEvent * e) +{ + if (e->buttons ()) { + track.MouseMove (QT2VCG_X(this,e), QT2VCG_Y(this,e)); + updateGL (); + } +} + +void GLArea::mouseReleaseEvent (QMouseEvent * e) +{ + track.MouseUp (QT2VCG_X(this,e), QT2VCG_Y(this,e), QT2VCG (e->button (), e->modifiers ())); + updateGL (); +} + +void GLArea::wheelEvent (QWheelEvent * e) +{ + const int WHEEL_STEP = 120; + track.MouseWheel (e->delta () / float (WHEEL_STEP), QTWheel2VCG (e->modifiers ())); + updateGL (); +} + +void GLArea::updateRequested(MyDrawMode md,vcg::GLFeederInfo::ReqAtts& reqatts) +{ + drawmode = md; + rq = reqatts; + updateGL(); +} + +void GLArea::resetTrackBall() +{ + makeCurrent(); + track.Reset(); + updateGL(); + doneCurrent(); +} + + + +SharedDataOpenGLContext::SharedDataOpenGLContext( CMeshO& mesh,MLThreadSafeMemoryInfo& mi,QWidget* parent /*= 0*/ ) + :QGLWidget(parent),feeder(mesh,mi,100000) +{ +} + +SharedDataOpenGLContext::~SharedDataOpenGLContext() +{ + deAllocateBO(); +} + +void SharedDataOpenGLContext::myInitGL() +{ + makeCurrent(); + glewInit(); + doneCurrent(); +} + +void SharedDataOpenGLContext::passInfoToOpenGL(int mode) +{ + makeCurrent(); + MyDrawMode drawmode = static_cast(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() +{ + makeCurrent(); + feeder.deAllocateBO(); + doneCurrent(); +} diff --git a/apps/sample/trimesh_QT_shared/glarea.h b/apps/sample/trimesh_QT_shared/glarea.h index 7c0cb13d..47ed9f0a 100644 --- a/apps/sample/trimesh_QT_shared/glarea.h +++ b/apps/sample/trimesh_QT_shared/glarea.h @@ -1,125 +1,109 @@ -/**************************************************************************** -* VCGLib o o * -* Visual and Computer Graphics Library o o * -* _ O _ * -* Copyright(C) 2007 \/)\/ * -* 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. * -* * -****************************************************************************/ -/**************************************************************************** -History - -$Log: not supported by cvs2svn $ -Revision 1.1 2007/10/18 08:52:06 benedetti -Initial release. - - -****************************************************************************/ - -#ifndef GLAREA_H_ -#define GLAREA_H_ - -/// Opengl related imports -#include -#include - -/// wrapper imports -#include - - -#include "mesh.h" -#include "ml_scene_renderer.h" -#include "ml_atomic_guard.h" -/// 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 -{ - Q_OBJECT -public: - GLArea (CMesh& m,MLThreadSafeGLMeshAttributesFeeder& feed,QWidget* parent = NULL,QGLWidget* sharedcont = NULL); - ~GLArea(); - /// we choosed a subset of the avaible drawing modes -public slots: - void setupEnvironment(MyDrawMode mode); - -signals: - /// signal for setting the statusbar message - void setStatusBar(QString message); -protected: - /// opengl initialization and drawing calls - void initializeGL (); - void resizeGL (int w, int h); - void paintGL (); - /// keyboard and mouse event callbacks - void keyReleaseEvent(QKeyEvent * e); - void keyPressEvent(QKeyEvent * e); - void mousePressEvent(QMouseEvent*e); - void mouseMoveEvent(QMouseEvent*e); - void mouseReleaseEvent(QMouseEvent*e); - void wheelEvent(QWheelEvent*e); -private: - MLAtomicGuard sem; - - GLuint vaohandlespecificicforglcontext; - /// the active mesh instance - CMesh& mesh; - /// the active manipulator - vcg::Trackball track; - /// mesh data structure initializer - void initMesh(QString message); - //MLThreadSafeMemoryInfo& mi; - 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_ */ +/**************************************************************************** +* VCGLib o o * +* Visual and Computer Graphics Library o o * +* _ O _ * +* Copyright(C) 2007 \/)\/ * +* 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. * +* * +****************************************************************************/ +/**************************************************************************** +History + +$Log: not supported by cvs2svn $ +Revision 1.1 2007/10/18 08:52:06 benedetti +Initial release. + + +****************************************************************************/ + +#ifndef GLAREA_H_ +#define GLAREA_H_ + +/// Opengl related imports +#include +#include + +/// wrapper imports +#include + + +#include "mesh.h" +#include "ml_scene_renderer.h" +/// 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(CMeshO& mesh,MLThreadSafeMemoryInfo& mi,QWidget* parent = 0); + ~SharedDataOpenGLContext(); + + void myInitGL(); + void deAllocateBO(); + + MLThreadSafeGLMeshAttributesFeeder feeder; + +public slots: + /// widget-based user interaction slots + void passInfoToOpenGL(int mode); + +signals: + void dataReadyToBeRead(MyDrawMode,vcg::GLFeederInfo::ReqAtts&); +}; + +class GLArea:public QGLWidget +{ + Q_OBJECT +public: + GLArea (CMeshO& m,MLThreadSafeGLMeshAttributesFeeder& feed,QWidget* parent = NULL,QGLWidget* sharedcont = NULL); + ~GLArea(); + void resetTrackBall(); + /// we choosed a subset of the avaible drawing modes + +signals: + /// signal for setting the statusbar message + void setStatusBar(QString message); +protected: + /// opengl initialization and drawing calls + void initializeGL (); + void resizeGL (int w, int h); + void paintGL (); + /// keyboard and mouse event callbacks + void keyReleaseEvent(QKeyEvent * e); + void keyPressEvent(QKeyEvent * e); + void mousePressEvent(QMouseEvent*e); + void mouseMoveEvent(QMouseEvent*e); + void mouseReleaseEvent(QMouseEvent*e); + void wheelEvent(QWheelEvent*e); +public slots: + void updateRequested(MyDrawMode,vcg::GLFeederInfo::ReqAtts&); +private: + /// the active mesh instance + CMeshO& mesh; + /// the active manipulator + vcg::Trackball track; + /// mesh data structure initializer + void initMesh(QString message); + MyDrawMode drawmode; + MLThreadSafeGLMeshAttributesFeeder& feeder; + vcg::GLFeederInfo::ReqAtts rq; +}; + +#endif /*GLAREA_H_ */ diff --git a/apps/sample/trimesh_QT_shared/main.cpp b/apps/sample/trimesh_QT_shared/main.cpp index 23b9d0eb..b8e441ba 100644 --- a/apps/sample/trimesh_QT_shared/main.cpp +++ b/apps/sample/trimesh_QT_shared/main.cpp @@ -1,48 +1,48 @@ -/**************************************************************************** - * VCGLib o o * - * Visual and Computer Graphics Library o o * - * _ O _ * - * Copyright(C) 2007 \/)\/ * - * 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. * - * * - ****************************************************************************/ -/**************************************************************************** - History - -$Log: not supported by cvs2svn $ - -****************************************************************************/ - -/** - * Minimal QT trimesh viewer - * - * This sample shows how to use togheter: - * - the Opengl module in QT using the designer - * - the trimesh loading and initialization - * - basic usage of the default manipulators (the "Trackball") - */ - -#include -#include "mainwindow.h" - -int main(int argc, char *argv[]) -{ - QApplication app(argc, argv); - MainWindow mw; - mw.show(); - return app.exec(); -} +/**************************************************************************** + * VCGLib o o * + * Visual and Computer Graphics Library o o * + * _ O _ * + * Copyright(C) 2007 \/)\/ * + * 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. * + * * + ****************************************************************************/ +/**************************************************************************** + History + +$Log: not supported by cvs2svn $ + +****************************************************************************/ + +/** + * Minimal QT trimesh viewer + * + * This sample shows how to use togheter: + * - the Opengl module in QT using the designer + * - the trimesh loading and initialization + * - basic usage of the default manipulators (the "Trackball") + */ + +#include +#include "mainwindow.h" + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + MainWindow mw; + mw.show(); + return app.exec(); +} diff --git a/apps/sample/trimesh_QT_shared/mainwindow.cpp b/apps/sample/trimesh_QT_shared/mainwindow.cpp index 1e4a98ea..4f019d59 100644 --- a/apps/sample/trimesh_QT_shared/mainwindow.cpp +++ b/apps/sample/trimesh_QT_shared/mainwindow.cpp @@ -1,111 +1,113 @@ -/**************************************************************************** -* VCGLib o o * -* Visual and Computer Graphics Library o o * -* _ O _ * -* Copyright(C) 2007 \/)\/ * -* 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. * -* * -****************************************************************************/ -/**************************************************************************** -History - -$Log: not supported by cvs2svn $ - -****************************************************************************/ - - -#include "mainwindow.h" -#include -#include -#include - -MainWindow::MainWindow (QWidget * parent) - :QMainWindow (parent),mi(1000000000),mesh() -{ - ui.setupUi (this); - 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) - { - glar[ii] = new GLArea(mesh,shared->feeder,NULL,shared); - connect (shared,SIGNAL(dataReadyToBeRead(MyDrawMode)),glar[ii], SLOT (setupEnvironment(MyDrawMode))); - tmp->addWidget(glar[ii]); - } - - - - connect (ui.loadMeshPushButton, SIGNAL (clicked()),this, SLOT (chooseMesh())); - connect (ui.loadTetrahedronPushButton, SIGNAL (clicked()),this, SLOT (loadTetrahedron())); - connect (ui.loadDodecahedronPushButton, SIGNAL (clicked()),this, SLOT (loadDodecahedron())); - //from toolFrame to glArea through mainwindow - -} - -// mesh chooser file dialog -void MainWindow::chooseMesh() -{ - mesh.Clear(); - QString fileName = QFileDialog::getOpenFileName(this, - tr("Open Mesh"), QDir::currentPath(), - tr("Poly Model (*.ply)")); - int err=vcg::tri::io::ImporterPLY::Open(mesh,(fileName.toStdString()).c_str()); - if(err!=0) - { - const char* errmsg=vcg::tri::io::ImporterPLY::ErrorMsg(err); - QMessageBox::warning(this,tr("Error Loading Mesh"),QString(errmsg)); - } - initMesh(fileName); -} - -void MainWindow::loadTetrahedron() -{ - mesh.Clear(); - vcg::tri::Tetrahedron(mesh); - initMesh(tr("Tethraedron [builtin]")); -} - -void MainWindow::loadDodecahedron() -{ - mesh.Clear(); - vcg::tri::Dodecahedron(mesh); - initMesh(tr("Dodecahedron [builtin]")); -} - -void MainWindow::initMesh(QString message) -{ - ui.statusbar->showMessage(message); - // update bounding box - vcg::tri::UpdateBounding::Box(mesh); - // update Normals - vcg::tri::UpdateNormal::PerVertexNormalizedPerFaceNormalized(mesh); - shared->feeder.update(vcg::GLMeshAttributesFeeder::ATT_ALL); - shared->passInfoToOpenGL(ui.drawModeComboBox->currentIndex()); -} - -MainWindow::~MainWindow() -{ - for(int ii = 0;ii < 2;++ii) - delete glar[ii]; - delete shared; -} +/**************************************************************************** +* VCGLib o o * +* Visual and Computer Graphics Library o o * +* _ O _ * +* Copyright(C) 2007 \/)\/ * +* 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. * +* * +****************************************************************************/ +/**************************************************************************** +History + +$Log: not supported by cvs2svn $ + +****************************************************************************/ + + +#include "mainwindow.h" +#include +#include +#include + +MainWindow::MainWindow (QWidget * parent) + :QMainWindow (parent),mi(1000000000),mesh() +{ + ui.setupUi (this); + 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) + { + glar[ii] = new GLArea(mesh,shared->feeder,NULL,shared); + connect (shared,SIGNAL(dataReadyToBeRead(MyDrawMode,vcg::GLFeederInfo::ReqAtts&)),glar[ii], SLOT (updateRequested(MyDrawMode,vcg::GLFeederInfo::ReqAtts&))); + tmp->addWidget(glar[ii]); + } + + connect (ui.loadMeshPushButton, SIGNAL (clicked()),this, SLOT (chooseMesh())); + connect (ui.loadTetrahedronPushButton, SIGNAL (clicked()),this, SLOT (loadTetrahedron())); + connect (ui.loadDodecahedronPushButton, SIGNAL (clicked()),this, SLOT (loadDodecahedron())); + //from toolFrame to glArea through mainwindow + +} + +// mesh chooser file dialog +void MainWindow::chooseMesh() +{ + mesh.Clear(); + QString fileName = QFileDialog::getOpenFileName(this, + tr("Open Mesh"), QDir::currentPath(), + tr("Poly Model (*.ply)")); + int err=vcg::tri::io::ImporterPLY::Open(mesh,(fileName.toStdString()).c_str()); + if(err!=0) + { + const char* errmsg=vcg::tri::io::ImporterPLY::ErrorMsg(err); + QMessageBox::warning(this,tr("Error Loading Mesh"),QString(errmsg)); + } + initMesh(fileName); +} + +void MainWindow::loadTetrahedron() +{ + mesh.Clear(); + vcg::tri::Tetrahedron(mesh); + initMesh(tr("Tethraedron [builtin]")); +} + +void MainWindow::loadDodecahedron() +{ + mesh.Clear(); + vcg::tri::Dodecahedron(mesh); + initMesh(tr("Dodecahedron [builtin]")); +} + +void MainWindow::initMesh(QString message) +{ + if (shared != NULL) + shared->deAllocateBO(); + // update bounding box + vcg::tri::UpdateBounding::Box(mesh); + // update Normals + vcg::tri::UpdateNormal::PerVertexNormalizedPerFaceNormalized(mesh); + shared->passInfoToOpenGL(ui.drawModeComboBox->currentIndex()); + for(size_t ii = 0;ii < 2;++ii) + if (glar[ii] != NULL) + glar[ii]->resetTrackBall(); + ui.statusbar->showMessage(message); +} + +MainWindow::~MainWindow() +{ + for(int ii = 0;ii < 2;++ii) + delete glar[ii]; + delete shared; +} diff --git a/apps/sample/trimesh_QT_shared/mainwindow.h b/apps/sample/trimesh_QT_shared/mainwindow.h index 6b237230..34358177 100644 --- a/apps/sample/trimesh_QT_shared/mainwindow.h +++ b/apps/sample/trimesh_QT_shared/mainwindow.h @@ -1,61 +1,61 @@ -/**************************************************************************** - * VCGLib o o * - * Visual and Computer Graphics Library o o * - * _ O _ * - * Copyright(C) 2007 \/)\/ * - * 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. * - * * - ****************************************************************************/ -/**************************************************************************** - History - -$Log: not supported by cvs2svn $ - -****************************************************************************/ -#ifndef MAINWINDOW_H_ -#define MAINWINDOW_H_ - -#include "ui_mainwindow.h" -#include "glarea.h" -#include "ml_thread_safe_memory_info.h" - - -class MainWindow:public QMainWindow -{ -Q_OBJECT -public: - MainWindow(QWidget * parent = 0); - ~MainWindow(); -public slots: - void chooseMesh(); - void loadTetrahedron(); - void loadDodecahedron(); - void initMesh(QString message); - -signals: - void loadMesh(QString newMesh); -private: - Ui::mainWindow ui; - GLArea* glar[2]; - - SharedDataOpenGLContext* shared; - MLThreadSafeMemoryInfo mi; - /// the active mesh instance - CMesh mesh; -}; - -#endif /*MAINWINDOW_H_ */ +/**************************************************************************** + * VCGLib o o * + * Visual and Computer Graphics Library o o * + * _ O _ * + * Copyright(C) 2007 \/)\/ * + * 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. * + * * + ****************************************************************************/ +/**************************************************************************** + History + +$Log: not supported by cvs2svn $ + +****************************************************************************/ +#ifndef MAINWINDOW_H_ +#define MAINWINDOW_H_ + +#include "ui_mainwindow.h" +#include "glarea.h" +#include "ml_thread_safe_memory_info.h" + + +class MainWindow:public QMainWindow +{ +Q_OBJECT +public: + MainWindow(QWidget * parent = 0); + ~MainWindow(); +public slots: + void chooseMesh(); + void loadTetrahedron(); + void loadDodecahedron(); + void initMesh(QString message); + +signals: + void loadMesh(QString newMesh); +private: + Ui::mainWindow ui; + GLArea* glar[2]; + + SharedDataOpenGLContext* shared; + MLThreadSafeMemoryInfo mi; + /// the active mesh instance + CMeshO mesh; +}; + +#endif /*MAINWINDOW_H_ */ diff --git a/apps/sample/trimesh_QT_shared/mainwindow.ui b/apps/sample/trimesh_QT_shared/mainwindow.ui index eb5e949d..75e8e073 100644 --- a/apps/sample/trimesh_QT_shared/mainwindow.ui +++ b/apps/sample/trimesh_QT_shared/mainwindow.ui @@ -1,201 +1,201 @@ - - - mainWindow - - - - 0 - 0 - 715 - 579 - - - - Trimesh QT - - - - - 6 - - - 9 - - - 9 - - - 9 - - - 9 - - - - - - 0 - 0 - - - - QFrame::StyledPanel - - - QFrame::Raised - - - - 6 - - - 9 - - - 9 - - - 9 - - - 9 - - - - - Draw &Mode : - - - drawModeComboBox - - - - - - - - Smooth - - - - - Points - - - - - Wire - - - - - Flat Wire - - - - - Flat - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - Load &Mesh - - - - - - - Load &Tetrahedron - - - - - - - Load &Dodecahedron - - - - - - - Qt::Horizontal - - - - 20 - 40 - - - - - - - - - - - QFrame::StyledPanel - - - QFrame::Raised - - - - 6 - - - 9 - - - 9 - - - 9 - - - 9 - - - - - - - - - - 0 - 0 - 715 - 21 - - - - - - - drawModeComboBox - loadMeshPushButton - loadTetrahedronPushButton - loadDodecahedronPushButton - - - - + + + mainWindow + + + + 0 + 0 + 715 + 579 + + + + Trimesh QT + + + + + 6 + + + 9 + + + 9 + + + 9 + + + 9 + + + + + + 0 + 0 + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + 6 + + + 9 + + + 9 + + + 9 + + + 9 + + + + + Draw &Mode : + + + drawModeComboBox + + + + + + + + Smooth + + + + + Points + + + + + Wire + + + + + Flat Wire + + + + + Flat + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Load &Mesh + + + + + + + Load &Tetrahedron + + + + + + + Load &Dodecahedron + + + + + + + Qt::Horizontal + + + + 20 + 40 + + + + + + + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + 6 + + + 9 + + + 9 + + + 9 + + + 9 + + + + + + + + + + 0 + 0 + 715 + 21 + + + + + + + drawModeComboBox + loadMeshPushButton + loadTetrahedronPushButton + loadDodecahedronPushButton + + + + diff --git a/apps/sample/trimesh_QT_shared/mesh.h b/apps/sample/trimesh_QT_shared/mesh.h index 5726365b..d6e56d8f 100644 --- a/apps/sample/trimesh_QT_shared/mesh.h +++ b/apps/sample/trimesh_QT_shared/mesh.h @@ -1,24 +1,28 @@ -#ifndef MESH_H -#define MESH_H - -/// vcg imports -#include -#include -#include -#include - -#include - -using namespace vcg; -class CFace; -class CVertex; - -struct MyUsedTypes : public UsedTypes< Use ::AsVertexType, - Use ::AsFaceType>{}; - -/// compositing wanted proprieties -class CVertex : public vcg::Vertex< MyUsedTypes, vcg::vertex::Coord3f, vcg::vertex::Normal3f, vcg::vertex::BitFlags>{}; -class CFace : public vcg::Face< MyUsedTypes, vcg::face::VertexRef, vcg::face::Normal3f, vcg::face::BitFlags > {}; -class CMesh : public vcg::tri::TriMesh< std::vector, std::vector > {}; - +#ifndef MESH_H +#define MESH_H + +/// vcg imports +#include +#include +#include +#include + +#include + +using namespace vcg; +class CFaceO; +class CVertexO; + +struct MyUsedTypes : public UsedTypes< Use ::AsVertexType, + Use ::AsFaceType>{}; + +/// compositing wanted proprieties +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 CMeshO : public vcg::tri::TriMesh< std::vector, std::vector > +{ +public: + vcg::Box3f bbox; +}; + #endif \ No newline at end of file diff --git a/apps/sample/trimesh_QT_shared/ml_scene_renderer.cpp b/apps/sample/trimesh_QT_shared/ml_scene_renderer.cpp index 9df18465..7fab80a1 100644 --- a/apps/sample/trimesh_QT_shared/ml_scene_renderer.cpp +++ b/apps/sample/trimesh_QT_shared/ml_scene_renderer.cpp @@ -1,126 +1,201 @@ #include "ml_scene_renderer.h" #include "ml_thread_safe_memory_info.h" +#include "glarea.h" -MLThreadSafeGLMeshAttributesFeeder::MLThreadSafeGLMeshAttributesFeeder(CMesh& mesh,MLThreadSafeMemoryInfo& gpumeminfo,size_t perbatchtriangles) - :GLMeshAttributesFeeder(mesh,gpumeminfo,perbatchtriangles),_lock(QReadWriteLock::Recursive) +#include + +MLThreadSafeGLMeshAttributesFeeder::MLThreadSafeGLMeshAttributesFeeder(CMeshO& mesh,MLThreadSafeMemoryInfo& gpumeminfo,size_t perbatchtriangles) + :GLMeshAttributesFeeder(mesh,gpumeminfo,perbatchtriangles),_lock(QReadWriteLock::Recursive) { } void MLThreadSafeGLMeshAttributesFeeder::setPerBatchTriangles( size_t perbatchtriangles ) { QWriteLocker locker(&_lock); - GLMeshAttributesFeeder::setPerBatchTriangles(perbatchtriangles); + GLMeshAttributesFeeder::setPerBatchPrimitives(perbatchtriangles); } size_t MLThreadSafeGLMeshAttributesFeeder::perBatchTriangles() const { QReadLocker locker(&_lock); - return GLMeshAttributesFeeder::perBatchTriangles(); - + return GLMeshAttributesFeeder::perBatchPrimitives(); + } bool MLThreadSafeGLMeshAttributesFeeder::renderedWithBO() const { QReadLocker locker(&_lock); - return GLMeshAttributesFeeder::renderedWithBO(); + return GLMeshAttributesFeeder::isPossibleToUseBORendering(); } -void MLThreadSafeGLMeshAttributesFeeder::update( int mask ) +void MLThreadSafeGLMeshAttributesFeeder::meshAttributesUpdated( int mask ) { QWriteLocker locker(&_lock); - GLMeshAttributesFeeder::update(mask); + GLMeshAttributesFeeder::meshAttributesUpdated(mask); } -void MLThreadSafeGLMeshAttributesFeeder::drawWire(GLuint& vaohandlespecificperopenglcontext,vcg::GLFeedEnum::NORMAL_MODALITY nm,vcg::GLFeedEnum::COLOR_MODALITY cm ) +vcg::GLFeederInfo::ReqAtts MLThreadSafeGLMeshAttributesFeeder::setupRequestedAttributes(const vcg::GLFeederInfo::ReqAtts& rq,bool& allocated ) { - glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); - drawTriangles(vaohandlespecificperopenglcontext,nm,cm,vcg::GLFeedEnum::TX_NONE); - glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); + QWriteLocker locker(&_lock); + return GLMeshAttributesFeeder::setupRequestedAttributes(rq,allocated); } -void MLThreadSafeGLMeshAttributesFeeder::drawFlatWire(GLuint& vaohandlespecificperopenglcontext,vcg::GLFeedEnum::COLOR_MODALITY cm,vcg::GLFeedEnum::TEXTURE_MODALITY tm,const std::vector& textureindex ) + +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(vaohandlespecificperopenglcontext,vcg::GLFeedEnum::NR_PERFACE,cm,tm,textureindex); - + drawTriangles(rq); glDisable(GL_POLYGON_OFFSET_FILL); + glEnable(GL_COLOR_MATERIAL); glColorMaterial(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE); - glColor3f(.3f,.3f,.3f); - drawWire(vaohandlespecificperopenglcontext,vcg::GLFeedEnum::NR_PERFACE,vcg::GLFeedEnum::CL_NONE); + 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::drawTriangles(tmp,_textids.textId()); + glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); + glPopAttrib(); } -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); - GLMeshAttributesFeeder::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,const std::vector& textureindex ) +void MLThreadSafeGLMeshAttributesFeeder::drawPoints(vcg::GLFeederInfo::ReqAtts& rq) { QReadLocker locker(&_lock); - GLMeshAttributesFeeder::drawTriangles(vaohandlespecificperopenglcontext,nm,cm,tm,textureindex); + GLMeshAttributesFeeder::drawPoints(rq); } -void MLThreadSafeGLMeshAttributesFeeder::passTrianglesToOpenGL(GLuint& vaohandlespecificperopenglcontext,vcg::GLFeedEnum::NORMAL_MODALITY nm,vcg::GLFeedEnum::COLOR_MODALITY cm,vcg::GLFeedEnum::TEXTURE_MODALITY tm ) -{ - QWriteLocker locker(&_lock); - GLMeshAttributesFeeder::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::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::tryToAllocatePerPointAttributesInBO(vaohandlespecificperopenglcontext,nm,cm); -} - -bool MLThreadSafeGLMeshAttributesFeeder::updateClientSideEnvironmentVAO( GLuint& vaohandle,const std::vector& importattribute) const +void MLThreadSafeGLMeshAttributesFeeder::drawTriangles(vcg::GLFeederInfo::ReqAtts& rq) { QReadLocker locker(&_lock); - - glBindVertexArray(vaohandle); - int ii = 0; - for(std::vector::const_iterator it = _bo.begin();it != _bo.end();++it) - { - BO_NAMES boname = static_cast(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; + GLMeshAttributesFeeder::drawTriangles(rq,_textids.textId()); } -void MLThreadSafeGLMeshAttributesFeeder::attributesToBeImportedInPointBasedPipeline( std::vector &importattribute, NORMAL_MODALITY nm, COLOR_MODALITY cm ) const +void MLThreadSafeGLMeshAttributesFeeder::drawBBox(vcg::GLFeederInfo::ReqAtts& rq) { QReadLocker locker(&_lock); - GLMeshAttributesFeeder::attributesToBeImportedInPointBasedPipeline(importattribute,nm,cm); + + vcg::Box3f& b = _mesh.bbox; + glPushAttrib(GL_ALL_ATTRIB_BITS); + glDisable(GL_LIGHTING); + GLuint bbhandle; + glGenBuffers(1,&bbhandle); + std::vector 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::attributesToBeImportedInTriangleBasedPipeline( std::vector &importattribute, NORMAL_MODALITY nm, COLOR_MODALITY cm, TEXTURE_MODALITY tm ) const + +void MLThreadSafeGLMeshAttributesFeeder::deAllocateBO() +{ + QWriteLocker locker(&_lock); + GLMeshAttributesFeeder::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); - GLMeshAttributesFeeder::attributesToBeImportedInTriangleBasedPipeline(importattribute,nm,cm,tm); + return _tmid.size(); } + +bool MLThreadSafeGLMeshAttributesFeeder::MLThreadSafeTextureNamesContainer::empty() const +{ + QReadLocker locker(&_lock); + return _tmid.empty(); +} + +void MLThreadSafeGLMeshAttributesFeeder::MLThreadSafeTextureNamesContainer::clear() +{ + QWriteLocker locker(&_lock); + _tmid.clear(); +} \ No newline at end of file diff --git a/apps/sample/trimesh_QT_shared/ml_scene_renderer.h b/apps/sample/trimesh_QT_shared/ml_scene_renderer.h index 03a35d94..293d6205 100644 --- a/apps/sample/trimesh_QT_shared/ml_scene_renderer.h +++ b/apps/sample/trimesh_QT_shared/ml_scene_renderer.h @@ -24,58 +24,74 @@ #ifndef __ML_SCENE_RENDERER_H #define __ML_SCENE_RENDERER_H +#include +#include "mesh.h" +#include + #include #include #include -#include "mesh.h" - -#include -#include - class MLThreadSafeMemoryInfo; -class MLThreadSafeGLMeshAttributesFeeder : public vcg::GLMeshAttributesFeeder +class MLThreadSafeGLMeshAttributesFeeder : public vcg::GLMeshAttributesFeeder { public: - MLThreadSafeGLMeshAttributesFeeder(CMesh& mesh,MLThreadSafeMemoryInfo& gpumeminfo,size_t perbatchtriangles); + 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& textId() {return _tmid;}; + private: + std::vector _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; - 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 meshAttributesUpdated(int mask); - void drawFlatWire(GLuint& vaohandlespecificperopenglcontext,vcg::GLFeedEnum::COLOR_MODALITY cm,vcg::GLFeedEnum::TEXTURE_MODALITY tm,const std::vector& textureindex = std::vector()); + vcg::GLFeederInfo::ReqAtts setupRequestedAttributes(const vcg::GLFeederInfo::ReqAtts& rq,bool& allocated); - 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& textureindex = std::vector() ); + void deAllocateBO(); - bool enableClientSideEnvironmentVAO(GLuint& vaohandle) const; + void drawWire(vcg::GLFeederInfo::ReqAtts& rq); - bool updateClientSideEnvironmentVAO(GLuint& vaohandle,const std::vector& importattribute) const; + void drawFlatWire(vcg::GLFeederInfo::ReqAtts& rq); - void attributesToBeImportedInPointBasedPipeline( std::vector &importattribute, NORMAL_MODALITY nm, COLOR_MODALITY cm) const; + void drawPoints(vcg::GLFeederInfo::ReqAtts& rq); - void attributesToBeImportedInTriangleBasedPipeline( std::vector &importattribute, NORMAL_MODALITY nm, COLOR_MODALITY cm, TEXTURE_MODALITY tm ) const; + 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 diff --git a/apps/sample/trimesh_QT_shared/ml_thread_safe_memory_info.cpp b/apps/sample/trimesh_QT_shared/ml_thread_safe_memory_info.cpp index 2ba64b8e..9838f86f 100644 --- a/apps/sample/trimesh_QT_shared/ml_thread_safe_memory_info.cpp +++ b/apps/sample/trimesh_QT_shared/ml_thread_safe_memory_info.cpp @@ -23,7 +23,7 @@ #include "ml_thread_safe_memory_info.h" -MLThreadSafeMemoryInfo::MLThreadSafeMemoryInfo( long long unsigned int originalmem ) +MLThreadSafeMemoryInfo::MLThreadSafeMemoryInfo( std::ptrdiff_t originalmem ) :vcg::NotThreadSafeMemoryInfo(originalmem),lock(QReadWriteLock::Recursive) { @@ -33,32 +33,32 @@ MLThreadSafeMemoryInfo::~MLThreadSafeMemoryInfo() { } -void MLThreadSafeMemoryInfo::acquiredMemory(long long unsigned int mem) +void MLThreadSafeMemoryInfo::acquiredMemory(std::ptrdiff_t mem) { QWriteLocker locker(&lock); vcg::NotThreadSafeMemoryInfo::acquiredMemory(mem); } -long long unsigned int MLThreadSafeMemoryInfo::usedMemory() const +std::ptrdiff_t MLThreadSafeMemoryInfo::usedMemory() const { QReadLocker locker(&lock); return vcg::NotThreadSafeMemoryInfo::usedMemory(); } -long long unsigned int MLThreadSafeMemoryInfo::currentFreeMemory() const +std::ptrdiff_t MLThreadSafeMemoryInfo::currentFreeMemory() const { QReadLocker locker(&lock); return vcg::NotThreadSafeMemoryInfo::currentFreeMemory(); } -void MLThreadSafeMemoryInfo::releasedMemory(long long unsigned int mem) +void MLThreadSafeMemoryInfo::releasedMemory(std::ptrdiff_t mem) { QWriteLocker locker(&lock); vcg::NotThreadSafeMemoryInfo::releasedMemory(mem); } -bool MLThreadSafeMemoryInfo::isAdditionalMemoryAvailable( long long unsigned int mem ) +bool MLThreadSafeMemoryInfo::isAdditionalMemoryAvailable( std::ptrdiff_t mem ) { QReadLocker locker(&lock); return vcg::NotThreadSafeMemoryInfo::isAdditionalMemoryAvailable(mem); diff --git a/apps/sample/trimesh_QT_shared/ml_thread_safe_memory_info.h b/apps/sample/trimesh_QT_shared/ml_thread_safe_memory_info.h index 148b5abc..a4d65030 100644 --- a/apps/sample/trimesh_QT_shared/ml_thread_safe_memory_info.h +++ b/apps/sample/trimesh_QT_shared/ml_thread_safe_memory_info.h @@ -26,28 +26,25 @@ #include -#include "mesh.h" - -#include -#include +#include class MLThreadSafeMemoryInfo : public vcg::NotThreadSafeMemoryInfo { public: - MLThreadSafeMemoryInfo(long long unsigned int originalmem); + MLThreadSafeMemoryInfo(std::ptrdiff_t originalmem); ~MLThreadSafeMemoryInfo(); - void acquiredMemory(long long unsigned int mem); + void acquiredMemory(std::ptrdiff_t mem); - long long unsigned int usedMemory() const; + std::ptrdiff_t usedMemory() const; - long long unsigned int currentFreeMemory() const; + std::ptrdiff_t currentFreeMemory() const; - void releasedMemory(long long unsigned int mem = 0); + void releasedMemory(std::ptrdiff_t mem = 0); - bool isAdditionalMemoryAvailable(long long unsigned int mem); + 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 diff --git a/apps/sample/trimesh_QT_shared/trimesh_qt.pro b/apps/sample/trimesh_QT_shared/trimesh_qt.pro index 66e3ca9b..1f7eebd0 100644 --- a/apps/sample/trimesh_QT_shared/trimesh_qt.pro +++ b/apps/sample/trimesh_QT_shared/trimesh_qt.pro @@ -1,56 +1,56 @@ -# Base options -TEMPLATE = app -LANGUAGE = C++ - -# QT modules -QT += opengl - -# Executable name -TARGET = trimesh_qt - -# Directories -DESTDIR = . -UI_DIR = build/ui -MOC_DIR = build/moc -OBJECTS_DIR = build/obj - -# Lib headers -INCLUDEPATH += . -INCLUDEPATH += ../../.. - -# Lib sources -SOURCES += ../../../wrap/ply/plylib.cpp -SOURCES += ../../../wrap/gui/trackball.cpp -SOURCES += ../../../wrap/gui/trackmode.cpp - - -# Compile glew -DEFINES += GLEW_STATIC -INCLUDEPATH += ../../../../lib/glew/include -SOURCES += ../../../../lib/glew/src/glew.c - -# Awful problem with windows.. -win32{ - DEFINES += NOMINMAX -} - -# Input -HEADERS += mainwindow.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 += mainwindow.cpp -SOURCES += glarea.cpp -SOURCES += ml_thread_safe_memory_info.cpp -SOURCES += ml_scene_renderer.cpp - -FORMS += mainwindow.ui - -linux-g++:LIBS += -lGLU -linux-g++-32:LIBS += -lGLU -linux-g++-64:LIBS += -lGLU +# Base options +TEMPLATE = app +LANGUAGE = C++ + +# QT modules +QT += opengl + +# Executable name +TARGET = trimesh_qt + +# Directories +DESTDIR = . +UI_DIR = build/ui +MOC_DIR = build/moc +OBJECTS_DIR = build/obj + +# Lib headers +INCLUDEPATH += . +INCLUDEPATH += ../../.. + +# Lib sources +SOURCES += ../../../wrap/ply/plylib.cpp +SOURCES += ../../../wrap/gui/trackball.cpp +SOURCES += ../../../wrap/gui/trackmode.cpp + + +# Compile glew +DEFINES += GLEW_STATIC +INCLUDEPATH += ../../../../lib/glew/include +SOURCES += ../../../../lib/glew/src/glew.c + +# Awful problem with windows.. +win32{ + DEFINES += NOMINMAX +} + +# Input +HEADERS += mainwindow.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 += mainwindow.cpp +SOURCES += glarea.cpp +SOURCES += ml_thread_safe_memory_info.cpp +SOURCES += ml_scene_renderer.cpp + +FORMS += mainwindow.ui + +linux-g++:LIBS += -lGLU +linux-g++-32:LIBS += -lGLU +linux-g++-64:LIBS += -lGLU