Bug Fixing for the Rendering System

This commit is contained in:
Guido Ranzuglia 2016-06-29 14:19:20 +02:00
parent 9194ade7e5
commit 8374dd97e5
3 changed files with 54 additions and 43 deletions

View File

@ -2,7 +2,7 @@
* VCGLib o o * * VCGLib o o *
* Visual and Computer Graphics Library o o * * Visual and Computer Graphics Library o o *
* _ O _ * * _ O _ *
* Copyright(C) 2004-2016 \/)\/ * * Copyright(C) 2004 \/)\/ *
* Visual Computing Lab /\/| * * Visual Computing Lab /\/| *
* ISTI - Italian National Research Council | * * ISTI - Italian National Research Council | *
* \ * * \ *
@ -65,7 +65,7 @@ namespace vcg
ATT_NAMES(unsigned int att) ATT_NAMES(unsigned int att)
{ {
if (att >= ATT_NAMES::enumArity()) if ((att < ATT_VERTPOSITION) || (att >= ATT_NAMES::enumArity()))
throw Exception("Out of range value\n"); throw Exception("Out of range value\n");
else else
_val = att; _val = att;
@ -119,9 +119,9 @@ namespace vcg
class RenderingAtts class RenderingAtts
{ {
public: public:
RenderingAtts() RenderingAtts(bool defaultvalue = false)
{ {
reset(); reset(defaultvalue);
} }
RenderingAtts(const RenderingAtts<ATT_NAMES_DERIVED_CLASS>& att) RenderingAtts(const RenderingAtts<ATT_NAMES_DERIVED_CLASS>& att)
@ -174,12 +174,12 @@ namespace vcg
return _atts[ind]; return _atts[ind];
} }
void reset() void reset(bool defaultvalue = false)
{ {
//delete[] _atts; //delete[] _atts;
//_atts = new bool[ATT_NAMES_DERIVED_CLASS::enumArity()]; //_atts = new bool[ATT_NAMES_DERIVED_CLASS::enumArity()];
for(unsigned int ii = 0;ii < ATT_NAMES_DERIVED_CLASS::enumArity();++ii) for(unsigned int ii = 0;ii < ATT_NAMES_DERIVED_CLASS::enumArity();++ii)
_atts[ii] = false; _atts[ii] = defaultvalue;
} }
static RenderingAtts<ATT_NAMES_DERIVED_CLASS> unionSet(const RenderingAtts<ATT_NAMES_DERIVED_CLASS>& a,const RenderingAtts<ATT_NAMES_DERIVED_CLASS>& b) static RenderingAtts<ATT_NAMES_DERIVED_CLASS> unionSet(const RenderingAtts<ATT_NAMES_DERIVED_CLASS>& a,const RenderingAtts<ATT_NAMES_DERIVED_CLASS>& b)
@ -309,7 +309,7 @@ namespace vcg
INT_ATT_NAMES(unsigned int att) INT_ATT_NAMES(unsigned int att)
:ATT_NAMES() :ATT_NAMES()
{ {
if (att >= INT_ATT_NAMES::enumArity()) if ((att < INT_ATT_NAMES::ATT_VERTPOSITION) || (att >= INT_ATT_NAMES::enumArity()))
throw Exception("Out of range value\n"); throw Exception("Out of range value\n");
else else
_val = att; _val = att;
@ -429,4 +429,4 @@ namespace vcg
}; };
} }
#endif #endif

View File

@ -2,7 +2,7 @@
* VCGLib o o * * VCGLib o o *
* Visual and Computer Graphics Library o o * * Visual and Computer Graphics Library o o *
* _ O _ * * _ O _ *
* Copyright(C) 2004-2016 \/)\/ * * Copyright(C) 2004 \/)\/ *
* Visual Computing Lab /\/| * * Visual Computing Lab /\/| *
* ISTI - Italian National Research Council | * * ISTI - Italian National Research Council | *
* \ * * \ *
@ -426,6 +426,8 @@ namespace vcg
glPopMatrix(); glPopMatrix();
glPopAttrib(); glPopAttrib();
glFlush();
glFinish();
} }
bool isBORenderingAvailable() const bool isBORenderingAvailable() const
@ -531,9 +533,9 @@ namespace vcg
case(INT_ATT_NAMES::ATT_WEDGETEXTURE): case(INT_ATT_NAMES::ATT_WEDGETEXTURE):
return vcg::tri::HasPerWedgeTexCoord(_mesh); return vcg::tri::HasPerWedgeTexCoord(_mesh);
case(INT_ATT_NAMES::ATT_VERTINDICES): case(INT_ATT_NAMES::ATT_VERTINDICES):
return true; return (_mesh.VN() != 0) && (_mesh.FN() != 0);
case(INT_ATT_NAMES::ATT_EDGEINDICES): case(INT_ATT_NAMES::ATT_EDGEINDICES):
return vcg::tri::HasPerVertexFlags(_mesh); return vcg::tri::HasPerVertexFlags(_mesh) || ((_mesh.VN() != 0) && (_mesh.FN() == 0) && (_mesh.EN() == 0));
default: default:
return false; return false;
} }
@ -557,7 +559,7 @@ namespace vcg
{ {
//If a primitive_modality is not rendered (== no att_VERTPOSITION) all the referred attributes by this view can be eventually deallocated IF they are not used //If a primitive_modality is not rendered (== no att_VERTPOSITION) all the referred attributes by this view can be eventually deallocated IF they are not used
//by some other rendered primitive //by some other rendered primitive
//the vertindices is, as usual a diffrent case //the vertindices is, as usual, a different case
if (it->second._intatts[size_t(pm)][INT_ATT_NAMES::ATT_VERTPOSITION]) if (it->second._intatts[size_t(pm)][INT_ATT_NAMES::ATT_VERTPOSITION])
meaningfulrequiredbyatleastoneview = InternalRendAtts::unionSet(meaningfulrequiredbyatleastoneview,it->second._intatts[size_t(pm)]); meaningfulrequiredbyatleastoneview = InternalRendAtts::unionSet(meaningfulrequiredbyatleastoneview,it->second._intatts[size_t(pm)]);
else else
@ -565,12 +567,16 @@ namespace vcg
} }
} }
bool thereisreplicatedview = InternalRendAtts::replicatedPipelineNeeded(meaningfulrequiredbyatleastoneview); bool thereisreplicatedview = InternalRendAtts::replicatedPipelineNeeded(meaningfulrequiredbyatleastoneview);
meaningfulrequiredbyatleastoneview[INT_ATT_NAMES::ATT_VERTINDICES] = !thereisreplicatedview; meaningfulrequiredbyatleastoneview[INT_ATT_NAMES::ATT_VERTINDICES] &= !thereisreplicatedview;
InternalRendAtts reallyuseless = InternalRendAtts::complementSet(probabilyuseless,meaningfulrequiredbyatleastoneview); InternalRendAtts reallyuseless = InternalRendAtts::complementSet(probabilyuseless,meaningfulrequiredbyatleastoneview);
bool switchreplicatedindexed = (!InternalRendAtts::replicatedPipelineNeeded(_currallocatedboatt) && thereisreplicatedview) || (InternalRendAtts::replicatedPipelineNeeded(_currallocatedboatt) && !thereisreplicatedview); bool switchreplicatedindexed = (!InternalRendAtts::replicatedPipelineNeeded(_currallocatedboatt) && thereisreplicatedview) || (InternalRendAtts::replicatedPipelineNeeded(_currallocatedboatt) && !thereisreplicatedview);
/*in some way the vertices number changed. If i use the indexed pipeline i have to deallocate/allocate/update the vertex indices*/
bool numvertchanged = boExpectedSize(INT_ATT_NAMES::ATT_VERTPOSITION,thereisreplicatedview) != _bo[INT_ATT_NAMES::ATT_VERTPOSITION]->_size;
bool vertindforcedupdate = numvertchanged && meaningfulrequiredbyatleastoneview[INT_ATT_NAMES::ATT_VERTINDICES];
InternalRendAtts probablytoallocate = InternalRendAtts::complementSet(meaningfulrequiredbyatleastoneview,_currallocatedboatt); InternalRendAtts probablytoallocate = InternalRendAtts::complementSet(meaningfulrequiredbyatleastoneview,_currallocatedboatt);
InternalRendAtts probablytodeallocate = InternalRendAtts::complementSet(_currallocatedboatt,meaningfulrequiredbyatleastoneview); InternalRendAtts probablytodeallocate = InternalRendAtts::complementSet(_currallocatedboatt,meaningfulrequiredbyatleastoneview);
for(unsigned int ii = 0;ii < INT_ATT_NAMES::enumArity();++ii) for(unsigned int ii = 0;ii < INT_ATT_NAMES::enumArity();++ii)
@ -588,8 +594,11 @@ namespace vcg
tobedeallocated[boname] = (notempty && !hasmeshattribute) || tobedeallocated[boname] = (notempty && !hasmeshattribute) ||
(notempty && probablytodeallocate[boname]) || (notempty && probablytodeallocate[boname]) ||
(notempty && reallyuseless[boname]) || (notempty && reallyuseless[boname]) ||
(notempty && (_bo[boname]->_size != sz) && meaningfulrequiredbyatleastoneview[boname]); (notempty && (_bo[boname]->_size != sz) && meaningfulrequiredbyatleastoneview[boname]) ||
tobeallocated[boname] = (hasmeshattribute && (sz > 0) && (sz != _bo[boname]->_size) && meaningfulrequiredbyatleastoneview[boname]) || (hasmeshattribute && (sz > 0) && probablytoallocate[boname]); (notempty && (boname == INT_ATT_NAMES::ATT_VERTINDICES) && (vertindforcedupdate));
tobeallocated[boname] = (hasmeshattribute && (sz > 0) && (sz != _bo[boname]->_size) && meaningfulrequiredbyatleastoneview[boname]) ||
(hasmeshattribute && (sz > 0) && probablytoallocate[boname]) ||
(hasmeshattribute && (boname == INT_ATT_NAMES::ATT_VERTINDICES) && (vertindforcedupdate));
tobeupdated[boname] = tobeallocated[boname] || (hasmeshattribute && (sz > 0) && !(isvalid) && meaningfulrequiredbyatleastoneview[boname]); tobeupdated[boname] = tobeallocated[boname] || (hasmeshattribute && (sz > 0) && !(isvalid) && meaningfulrequiredbyatleastoneview[boname]);
} }
else else
@ -1290,14 +1299,14 @@ namespace vcg
glPushAttrib(GL_ALL_ATTRIB_BITS); glPushAttrib(GL_ALL_ATTRIB_BITS);
bool isgloptsvalid = (glopts != NULL); bool isgloptsvalid = (glopts != NULL);
if ((!isgloptsvalid) || (req[INT_ATT_NAMES::ATT_VERTNORMAL]) || (req[INT_ATT_NAMES::ATT_FACENORMAL])) if (isgloptsvalid && glopts->_persolid_noshading)
{
glEnable(GL_LIGHTING);
}
else if (isgloptsvalid && glopts->_persolid_noshading)
glDisable(GL_LIGHTING); glDisable(GL_LIGHTING);
else
if ((!isgloptsvalid) || (req[INT_ATT_NAMES::ATT_VERTNORMAL]) || (req[INT_ATT_NAMES::ATT_FACENORMAL]))
{
glEnable(GL_LIGHTING);
}
glEnable(GL_COLOR_MATERIAL); glEnable(GL_COLOR_MATERIAL);
if ((isgloptsvalid) && (glopts->_persolid_fixed_color_enabled)) if ((isgloptsvalid) && (glopts->_persolid_fixed_color_enabled))
@ -1332,14 +1341,14 @@ namespace vcg
bool isgloptsvalid = (glopts != NULL); bool isgloptsvalid = (glopts != NULL);
if ((!isgloptsvalid) || (req[INT_ATT_NAMES::ATT_VERTNORMAL])) if (isgloptsvalid && glopts->_perwire_noshading)
{
glEnable(GL_LIGHTING);
}
else if (isgloptsvalid && glopts->_perwire_noshading)
glDisable(GL_LIGHTING); glDisable(GL_LIGHTING);
else
if ((!isgloptsvalid) || (req[INT_ATT_NAMES::ATT_VERTNORMAL]))
{
glEnable(GL_LIGHTING);
}
glEnable(GL_COLOR_MATERIAL); glEnable(GL_COLOR_MATERIAL);
if ((isgloptsvalid) && (glopts->_perwire_fixed_color_enabled)) if ((isgloptsvalid) && (glopts->_perwire_fixed_color_enabled))
glColor(glopts->_perwire_fixed_color); glColor(glopts->_perwire_fixed_color);
@ -1547,12 +1556,14 @@ namespace vcg
bool isgloptsvalid = (glopts != NULL); bool isgloptsvalid = (glopts != NULL);
if ((!isgloptsvalid) || req[INT_ATT_NAMES::ATT_VERTNORMAL])
{ if (isgloptsvalid && glopts->_perpoint_noshading)
glEnable(GL_LIGHTING);
}
else if (isgloptsvalid && glopts->_perpoint_noshading)
glDisable(GL_LIGHTING); glDisable(GL_LIGHTING);
else
if ((!isgloptsvalid) || req[INT_ATT_NAMES::ATT_VERTNORMAL])
{
glEnable(GL_LIGHTING);
}
glEnable(GL_COLOR_MATERIAL); glEnable(GL_COLOR_MATERIAL);
if ((isgloptsvalid) && ((glopts->_perpoint_fixed_color_enabled) || (glopts->_perpoint_mesh_color_enabled))) if ((isgloptsvalid) && ((glopts->_perpoint_fixed_color_enabled) || (glopts->_perpoint_mesh_color_enabled)))
@ -1651,13 +1662,13 @@ namespace vcg
glEnable(GL_COLOR_MATERIAL); glEnable(GL_COLOR_MATERIAL);
glColorMaterial(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE); glColorMaterial(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE);
if ((!isgloptsvalid) || req[INT_ATT_NAMES::ATT_VERTNORMAL]) if (isgloptsvalid && glopts->_perwire_noshading)
{
glEnable(GL_LIGHTING);
}
else if (isgloptsvalid && glopts->_perwire_noshading)
glDisable(GL_LIGHTING); glDisable(GL_LIGHTING);
else
if ((!isgloptsvalid) || (req[INT_ATT_NAMES::ATT_VERTNORMAL]))
{
glEnable(GL_LIGHTING);
}
bool colordefinedenabled = (isgloptsvalid) && ((glopts->_perwire_fixed_color_enabled) || (glopts->_perwire_mesh_color_enabled)); bool colordefinedenabled = (isgloptsvalid) && ((glopts->_perwire_fixed_color_enabled) || (glopts->_perwire_mesh_color_enabled));
@ -1910,7 +1921,7 @@ namespace vcg
void setBufferPointer( INT_ATT_NAMES boname) const void setBufferPointer( INT_ATT_NAMES boname) const
{ {
unsigned int ii = boname; unsigned int ii = boname;
if (ii >= INT_ATT_NAMES::enumArity()) if ((ii < INT_ATT_NAMES::ATT_VERTPOSITION) || (ii >= INT_ATT_NAMES::enumArity()))
return; return;
GLBufferObject* cbo = _bo[ii]; GLBufferObject* cbo = _bo[ii];
if (cbo == NULL) if (cbo == NULL)
@ -1948,7 +1959,7 @@ namespace vcg
void disableClientState( INT_ATT_NAMES boname,const RendAtts& req) const void disableClientState( INT_ATT_NAMES boname,const RendAtts& req) const
{ {
if (boname >= INT_ATT_NAMES::enumArity()) if ((boname < INT_ATT_NAMES::ATT_VERTPOSITION) || (boname >= INT_ATT_NAMES::enumArity()))
return; return;
switch(boname) switch(boname)

View File

@ -113,7 +113,7 @@ namespace vcg
vcg::NotThreadSafeGLMeshAttributesMultiViewerBOManager<MESH_TYPE,UNIQUE_VIEW_ID_TYPE,GL_OPTIONS_DERIVED_TYPE>::setDebugMode(activatedebugmodality); vcg::NotThreadSafeGLMeshAttributesMultiViewerBOManager<MESH_TYPE,UNIQUE_VIEW_ID_TYPE,GL_OPTIONS_DERIVED_TYPE>::setDebugMode(activatedebugmodality);
} }
void getLog(vcg::GLMeshAttributesInfo::DebugInfo& info) void getLog(DebugInfo& info)
{ {
QWriteLocker locker(&_lock); QWriteLocker locker(&_lock);
vcg::NotThreadSafeGLMeshAttributesMultiViewerBOManager<MESH_TYPE,UNIQUE_VIEW_ID_TYPE,GL_OPTIONS_DERIVED_TYPE>::getLog(info); vcg::NotThreadSafeGLMeshAttributesMultiViewerBOManager<MESH_TYPE,UNIQUE_VIEW_ID_TYPE,GL_OPTIONS_DERIVED_TYPE>::getLog(info);