- added optional debugging info system

- removed bugs
This commit is contained in:
granzuglia 2016-05-11 12:00:59 +00:00
parent 751a4ae261
commit 6c7fb7b0ab
2 changed files with 150 additions and 81 deletions

View File

@ -24,6 +24,9 @@
#ifndef __VCG_GL_MESH_ATTRIBUTES_INFO #ifndef __VCG_GL_MESH_ATTRIBUTES_INFO
#define __VCG_GL_MESH_ATTRIBUTES_INFO #define __VCG_GL_MESH_ATTRIBUTES_INFO
#include <vector>
#include <string>
namespace vcg namespace vcg
{ {
struct GLMeshAttributesInfo struct GLMeshAttributesInfo
@ -232,42 +235,32 @@ namespace vcg
typedef RenderingAtts<ATT_NAMES> RendAtts; typedef RenderingAtts<ATT_NAMES> RendAtts;
//template<typename MESH_TYPE> struct DebugInfo
//static void computeRenderingAttributesCompatibleWithMesh( const MESH_TYPE& mesh,const PRIMITIVE_MODALITY_MASK& inputpm,const RendAtts& inputatts, {
// PRIMITIVE_MODALITY_MASK& outputpm,RendAtts& outputatts ) std::string _tobeallocated;
//{ std::string _tobedeallocated;
// outputpm = 0; std::string _tobeupdated;
// outputatts.reset();
// if (mesh.VN() == 0) std::string _currentlyallocated;
// return;
// outputatts[ATT_NAMES::ATT_VERTPOSITION] = inputatts[ATT_NAMES::ATT_VERTPOSITION]; std::vector<std::string> _perviewdata;
// bool validfaces = (mesh.FN() > 0); DebugInfo()
// if (!validfaces) :_tobeallocated(),_tobedeallocated(),_tobeupdated(),_currentlyallocated(),_perviewdata()
// { {
// outputpm = (unsigned int) PR_POINTS;
// return;
// }
// outputpm = inputpm; }
// if ((inputpm & vcg::GLMeshAttributesInfo::PR_WIREFRAME_EDGES) && (!vcg::tri::HasPerVertexFlags(mesh)))
// outputpm = outputpm & (!vcg::GLMeshAttributesInfo::PR_WIREFRAME_EDGES);
// outputatts[ATT_NAMES::ATT_VERTNORMAL] = inputatts[ATT_NAMES::ATT_VERTNORMAL] && vcg::tri::HasPerVertexNormal(mesh); void reset()
// outputatts[ATT_NAMES::ATT_FACENORMAL] = inputatts[ATT_NAMES::ATT_FACENORMAL] && vcg::tri::HasPerFaceNormal(mesh) && validfaces; {
// outputatts[ATT_NAMES::ATT_VERTCOLOR] = inputatts[ATT_NAMES::ATT_VERTCOLOR] && vcg::tri::HasPerVertexColor(mesh); _tobeallocated.clear();
// outputatts[ATT_NAMES::ATT_FACECOLOR] = inputatts[ATT_NAMES::ATT_FACECOLOR] && vcg::tri::HasPerFaceColor(mesh) && validfaces; _tobedeallocated.clear();
// outputatts[ATT_NAMES::ATT_MESHCOLOR] = inputatts[ATT_NAMES::ATT_MESHCOLOR]; _tobeupdated.clear();
_currentlyallocated.clear();
_perviewdata.clear();
}
};
// //horrible trick caused by MeshLab GUI. In MeshLab exists just a button turning on/off the texture visualization.
// //Unfortunately the RenderMode::textureMode member field is not just a boolean value but and enum one.
// //The enum-value depends from the enabled attributes of input mesh.
// bool wedgetexture = vcg::tri::HasPerWedgeTexCoord(mesh) && validfaces;
// outputatts[ATT_NAMES::ATT_VERTTEXTURE] = inputatts[ATT_NAMES::ATT_VERTTEXTURE] && (vcg::tri::HasPerVertexTexCoord(mesh) && (!wedgetexture));
// outputatts[ATT_NAMES::ATT_WEDGETEXTURE] = inputatts[ATT_NAMES::ATT_WEDGETEXTURE] && wedgetexture;
//}
protected: protected:
struct INT_ATT_NAMES : public ATT_NAMES struct INT_ATT_NAMES : public ATT_NAMES
{ {
@ -341,7 +334,10 @@ namespace vcg
:RenderingAtts<INT_ATT_NAMES>() :RenderingAtts<INT_ATT_NAMES>()
{ {
for(unsigned int ii = 0;ii < ATT_NAMES::enumArity();++ii) for(unsigned int ii = 0;ii < ATT_NAMES::enumArity();++ii)
(*this)[ii] = reqatt[ii]; {
bool somethingtorender = (pm != ((unsigned int) PR_NONE));
(*this)[ii] = reqatt[ii] && somethingtorender;
}
(*this)[INT_ATT_NAMES::ATT_VERTINDICES] = isVertexIndexingRequired(reqatt,pm); (*this)[INT_ATT_NAMES::ATT_VERTINDICES] = isVertexIndexingRequired(reqatt,pm);
(*this)[INT_ATT_NAMES::ATT_EDGEINDICES] = isEdgeIndexingRequired(pm); (*this)[INT_ATT_NAMES::ATT_EDGEINDICES] = isEdgeIndexingRequired(pm);
@ -386,6 +382,10 @@ namespace vcg
static bool isVertexIndexingRequired(const RendAtts& rqatt,PRIMITIVE_MODALITY_MASK pm) static bool isVertexIndexingRequired(const RendAtts& rqatt,PRIMITIVE_MODALITY_MASK pm)
{ {
bool required = false; bool required = false;
if (pm == ((unsigned int) PR_NONE))
return false;
if (pm & PR_POINTS) if (pm & PR_POINTS)
required = required || isVertexIndexingRequired(rqatt,PR_POINTS); required = required || isVertexIndexingRequired(rqatt,PR_POINTS);
@ -429,6 +429,33 @@ namespace vcg
return required; return required;
} }
static void suggestedMinimalAttributeSetForPrimitiveModalityMask(PRIMITIVE_MODALITY_MASK pm,RenderingAtts<INT_ATT_NAMES>& atts)
{
if ((pm == (unsigned int)(PR_NONE)) || (pm == (unsigned int)(PR_BBOX)))
{
atts.reset();
return;
}
if (pm & PR_POINTS)
{
atts[INT_ATT_NAMES::ATT_VERTPOSITION] = true;
}
if (pm & PR_WIREFRAME_EDGES)
{
atts[INT_ATT_NAMES::ATT_VERTPOSITION] = true;
atts[INT_ATT_NAMES::ATT_EDGEINDICES] = true;
}
if ((pm & PR_WIREFRAME_TRIANGLES) || (pm & PR_SOLID))
{
atts[INT_ATT_NAMES::ATT_VERTPOSITION] = true;
atts[INT_ATT_NAMES::ATT_VERTINDICES] = true;
}
}
}; };
}; };
} }

View File

@ -29,6 +29,8 @@
#include <algorithm> #include <algorithm>
#include <stdexcept> #include <stdexcept>
#include <climits> #include <climits>
#include <string>
#include <bitset>
#include <wrap/gl/space.h> #include <wrap/gl/space.h>
#include <wrap/gl/math.h> #include <wrap/gl/math.h>
@ -97,7 +99,7 @@ namespace vcg
/*************************************************************************************************************************************************************************/ /*************************************************************************************************************************************************************************/
NotThreadSafeGLMeshAttributesMultiViewerBOManager(/*const*/ MESH_TYPE& mesh,MemoryInfo& meminfo, size_t perbatchprimitives) NotThreadSafeGLMeshAttributesMultiViewerBOManager(/*const*/ MESH_TYPE& mesh,MemoryInfo& meminfo, size_t perbatchprimitives)
:_mesh(mesh),_gpumeminfo(meminfo),_bo(INT_ATT_NAMES::enumArity(),NULL),_currallocatedboatt(),_perbatchprim(perbatchprimitives),_chunkmap(),_borendering(false),_edge(),_meshverticeswhenedgeindiceswerecomputed(0),_meshtriangleswhenedgeindiceswerecomputed(0),_tr() :_mesh(mesh),_gpumeminfo(meminfo),_bo(INT_ATT_NAMES::enumArity(),NULL),_currallocatedboatt(),_perbatchprim(perbatchprimitives),_chunkmap(),_borendering(false),_edge(),_meshverticeswhenedgeindiceswerecomputed(0),_meshtriangleswhenedgeindiceswerecomputed(0),_tr(),_debugmode(false),_loginfo()
{ {
_tr.SetIdentity(); _tr.SetIdentity();
@ -156,7 +158,8 @@ namespace vcg
void setPerViewInfo(UNIQUE_VIEW_ID_TYPE viewid,PRIMITIVE_MODALITY_MASK pm,const RendAtts& reqatts) void setPerViewInfo(UNIQUE_VIEW_ID_TYPE viewid,PRIMITIVE_MODALITY_MASK pm,const RendAtts& reqatts)
{ {
InternalRendAtts intreqatts(reqatts,pm); InternalRendAtts intreqatts(reqatts,pm);
_perviewreqatts[viewid] = PerViewData(pm,intreqatts); InternalRendAtts::suggestedMinimalAttributeSetForPrimitiveModalityMask(pm,intreqatts);
_perviewreqatts[viewid] = PerViewData(pm,intreqatts);
} }
bool removeView(UNIQUE_VIEW_ID_TYPE viewid) bool removeView(UNIQUE_VIEW_ID_TYPE viewid)
@ -270,7 +273,8 @@ namespace vcg
bool arebuffersok = checkBuffersAllocationStatus(tobeallocated,tobedeallocated,tobeupdated); bool arebuffersok = checkBuffersAllocationStatus(tobeallocated,tobedeallocated,tobeupdated);
if (!arebuffersok) if (!arebuffersok)
correctlyallocated = manageAndFeedBuffersIfNeeded(tobeallocated,tobedeallocated,tobeupdated); correctlyallocated = manageAndFeedBuffersIfNeeded(tobeallocated,tobedeallocated,tobeupdated);
if (_debugmode)
debug(tobeallocated,tobedeallocated,tobeupdated);
return (arebuffersok || correctlyallocated); return (arebuffersok || correctlyallocated);
} }
@ -289,6 +293,26 @@ namespace vcg
_tr = tr; _tr = tr;
} }
void setDebugMode(bool isdebug)
{
_debugmode = isdebug;
}
void getLog(DebugInfo& info)
{
info.reset();
info._tobedeallocated = _loginfo._tobedeallocated;
info._tobeallocated = _loginfo._tobeallocated;
info._tobeupdated = _loginfo._tobeupdated;
info._currentlyallocated = _loginfo._currentlyallocated;
info._perviewdata.resize(_loginfo._perviewdata.size());
for(std::vector<std::string>::iterator it = _loginfo._perviewdata.begin();it != _loginfo._perviewdata.end();++it)
info._perviewdata.push_back(*it);
_loginfo.reset();
}
private: private:
bool hasMeshAttribute(INT_ATT_NAMES attname) const bool hasMeshAttribute(INT_ATT_NAMES attname) const
{ {
@ -362,38 +386,6 @@ namespace vcg
} }
somethingtodo = somethingtodo || tobeallocated[boname] || tobedeallocated[boname] || tobeupdated[boname]; somethingtodo = somethingtodo || tobeallocated[boname] || tobedeallocated[boname] || tobeupdated[boname];
} }
if (somethingtodo)
{
std::string stdeallocate("deallocated: ");
std::string stallocate("allocated: ");
std::string stupdated("updated: ");
std::string truestring("true");
std::string falsestring("false");
for(unsigned int ii = 0;ii < INT_ATT_NAMES::enumArity();++ii)
{
std::string deallocres(falsestring);
if (tobedeallocated[ii])
deallocres = truestring;
stdeallocate += deallocres + " ";
std::string allocres(falsestring);
if (tobeallocated[ii])
allocres = truestring;
stallocate += allocres + " ";
std::string upres(falsestring);
if (tobeupdated[ii])
upres = truestring;
stupdated += upres + " ";
}
std::cout << "-------------------------------\n";
std::cout << "[" << stdeallocate << "]\n";
std::cout << "[" << stallocate << "]\n";
std::cout << "[" << stupdated << "]\n";
std::cout << "-------------------------------\n";
}
return !(somethingtodo); return !(somethingtodo);
} }
@ -514,7 +506,7 @@ namespace vcg
{ {
//the arity of the attribute contained in the bo didn't change so i can use the old space without reallocating it //the arity of the attribute contained in the bo didn't change so i can use the old space without reallocating it
if (cbo != NULL) if (cbo != NULL)
cbo->_isvalid = tobeupdated[boname]; cbo->_isvalid = cbo->_isvalid || tobeupdated[boname];
} }
++it; ++it;
++ii; ++ii;
@ -523,19 +515,6 @@ namespace vcg
buffersDeAllocationRequested(_currallocatedboatt); buffersDeAllocationRequested(_currallocatedboatt);
_borendering = !failedallocation; _borendering = !failedallocation;
} }
std::string stallocated("allocated: ");
std::string truestring("true");
std::string falsestring("false");
for(unsigned int ii = 0;ii < INT_ATT_NAMES::enumArity();++ii)
{
std::string allocres(falsestring);
if (_currallocatedboatt[ii])
allocres = truestring;
stallocated += allocres + " ";
}
std::cout << "********************************\n";
std::cout << "[" << stallocated << "]\n";
std::cout << "********************************\n";
return _borendering; return _borendering;
} }
@ -1506,6 +1485,66 @@ namespace vcg
_chunkmap[texind].push_back(std::make_pair(std::distance(_mesh.face.begin(),infrange),std::distance(_mesh.face.begin(),_mesh.face.end() - 1))); _chunkmap[texind].push_back(std::make_pair(std::distance(_mesh.face.begin(),infrange),std::distance(_mesh.face.begin(),_mesh.face.end() - 1)));
} }
void debug(const InternalRendAtts& tobeallocated,const InternalRendAtts& tobedeallocated,const InternalRendAtts& tobeupdated)
{
_loginfo.reset();
_loginfo._tobedeallocated = std::string("to_be_deallocated: ");
_loginfo._tobeallocated = std::string("to_be_allocated: ");
_loginfo._tobeupdated = std::string("to_be_updated: ");
std::string truestring("true");
std::string falsestring("false");
for(unsigned int ii = 0;ii < INT_ATT_NAMES::enumArity();++ii)
{
std::string deallocres(falsestring);
if (tobedeallocated[ii])
deallocres = truestring;
_loginfo._tobedeallocated += deallocres + " ";
std::string allocres(falsestring);
if (tobeallocated[ii])
allocres = truestring;
_loginfo._tobeallocated += allocres + " ";
std::string upres(falsestring);
if (tobeupdated[ii])
upres = truestring;
_loginfo._tobeupdated += upres + " ";
}
_loginfo._tobedeallocated = std::string("[") + _loginfo._tobedeallocated + std::string("]");
_loginfo._tobeallocated = std::string("[") + _loginfo._tobeallocated + std::string("]");
_loginfo._tobeupdated = std::string("[") + _loginfo._tobeupdated + std::string("]");
int hh = 0;
for(ViewsMap::const_iterator it = _perviewreqatts.begin();it != _perviewreqatts.end();++it)
{
std::stringstream tmpstream;
std::bitset<5> tmpset(int(it->second._pmmask));
tmpstream << "view_" << hh << " PR_MASK " << tmpset.to_string() << " ";
for(unsigned int ii = 0;ii < INT_ATT_NAMES::enumArity();++ii)
{
std::string res = falsestring;
if (it->second._intatts[ii])
res = truestring;
tmpstream << "att[" << ii << "]=" << res << " ";
}
_loginfo._perviewdata.push_back(tmpstream.str());
}
std::stringstream tmpstream;
tmpstream << "currently_allocated: " ;
for(unsigned int ii = 0;ii < INT_ATT_NAMES::enumArity();++ii)
{
std::string res = falsestring;
if (_currallocatedboatt[ii])
res = truestring;
tmpstream << "att[" << ii << "]=" << res << " ";
}
_loginfo._currentlyallocated = tmpstream.str();
}
class EdgeVertInd class EdgeVertInd
{ {
public: public:
@ -1586,7 +1625,7 @@ namespace vcg
static void fillUniqueEdgeVector(MESH_TYPE &m, std::vector<EdgeVertInd> &edgeVec) static void fillUniqueEdgeVector(MESH_TYPE &m, std::vector<EdgeVertInd> &edgeVec)
{ {
fillEdgeVector(m,edgeVec,false); fillEdgeVector(m,edgeVec,false);
std::sort(edgeVec.begin(), edgeVec.end()); // Lo ordino per vertici std::sort(edgeVec.begin(), edgeVec.end());
typename std::vector<EdgeVertInd>::iterator newEnd = std::unique(edgeVec.begin(), edgeVec.end()); typename std::vector<EdgeVertInd>::iterator newEnd = std::unique(edgeVec.begin(), edgeVec.end());
@ -1687,6 +1726,9 @@ namespace vcg
//vcg::GLOptions _glopts; //vcg::GLOptions _glopts;
vcg::Matrix44<typename MESH_TYPE::ScalarType> _tr; vcg::Matrix44<typename MESH_TYPE::ScalarType> _tr;
bool _debugmode;
DebugInfo _loginfo;
}; };
} }