- Fixed DrawFill method, which required the hint 'HNUseVArray' enabled in order to render the mesh with VBO. This was also causing extra overhead in the Update method since HNUseVArray has to be enabled and therefore extra calculation were done to copy vertices in VArrays even if the user was using only VBOs.
This commit is contained in:
parent
416dedd484
commit
63ee2004b6
|
@ -24,6 +24,9 @@
|
||||||
History
|
History
|
||||||
|
|
||||||
$Log: not supported by cvs2svn $
|
$Log: not supported by cvs2svn $
|
||||||
|
Revision 1.25 2007/09/12 16:20:24 m_di_benedetto
|
||||||
|
*** empty log message ***
|
||||||
|
|
||||||
Revision 1.24 2007/09/12 14:48:50 m_di_benedetto
|
Revision 1.24 2007/09/12 14:48:50 m_di_benedetto
|
||||||
Corrected indexing for non textured faces.
|
Corrected indexing for non textured faces.
|
||||||
|
|
||||||
|
@ -120,9 +123,9 @@ class GLW
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
enum DrawMode {DMNone, DMBox, DMPoints, DMWire, DMHidden, DMFlat, DMSmooth, DMFlatWire, DMRadar, DMLast} ;
|
enum DrawMode {DMNone, DMBox, DMPoints, DMWire, DMHidden, DMFlat, DMSmooth, DMFlatWire, DMRadar, DMLast} ;
|
||||||
enum NormalMode{NMNone, NMPerVert, NMPerFace, NMPerWedge, NMLast};
|
enum NormalMode {NMNone, NMPerVert, NMPerFace, NMPerWedge, NMLast};
|
||||||
enum ColorMode {CMNone, CMPerMesh, CMPerFace, CMPerVert, CMLast};
|
enum ColorMode {CMNone, CMPerMesh, CMPerFace, CMPerVert, CMLast};
|
||||||
enum TextureMode {TMNone, TMPerVert, TMPerWedge, TMPerWedgeMulti};
|
enum TextureMode{TMNone, TMPerVert, TMPerWedge, TMPerWedgeMulti};
|
||||||
enum Hint {
|
enum Hint {
|
||||||
HNUseTriStrip = 0x0001, // ha bisogno che ci sia la fftopology gia calcolata!
|
HNUseTriStrip = 0x0001, // ha bisogno che ci sia la fftopology gia calcolata!
|
||||||
// HNUseEdgeStrip = 0x0002, //
|
// HNUseEdgeStrip = 0x0002, //
|
||||||
|
@ -145,7 +148,8 @@ public:
|
||||||
CHNormal = 0x02,
|
CHNormal = 0x02,
|
||||||
CHColor = 0x04,
|
CHColor = 0x04,
|
||||||
CHFace = 0x08,
|
CHFace = 0x08,
|
||||||
CHFaceNormal= 0x10,
|
CHFaceNormal = 0x10,
|
||||||
|
CHRender = 0x20,
|
||||||
CHAll = 0xff
|
CHAll = 0xff
|
||||||
};
|
};
|
||||||
enum HintParami {
|
enum HintParami {
|
||||||
|
@ -180,11 +184,25 @@ public:
|
||||||
|
|
||||||
template <class MESH_TYPE, bool partial = false , class FACE_POINTER_CONTAINER = std::vector<typename MESH_TYPE::FacePointer> >
|
template <class MESH_TYPE, bool partial = false , class FACE_POINTER_CONTAINER = std::vector<typename MESH_TYPE::FacePointer> >
|
||||||
class GlTrimesh : public GLW
|
class GlTrimesh : public GLW
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
typedef MESH_TYPE mesh_type;
|
||||||
|
FACE_POINTER_CONTAINER face_pointers;
|
||||||
|
|
||||||
|
|
||||||
|
std::vector<unsigned int> TMId;
|
||||||
|
unsigned int b[3];
|
||||||
|
|
||||||
|
int h; // the current hints
|
||||||
|
|
||||||
|
// The parameters of hints
|
||||||
|
int HNParami[8];
|
||||||
|
float HNParamf[8];
|
||||||
|
|
||||||
MESH_TYPE *m;
|
MESH_TYPE *m;
|
||||||
GlTrimesh(){
|
GlTrimesh()
|
||||||
|
{
|
||||||
m=0;
|
m=0;
|
||||||
dl=0xffffffff;
|
dl=0xffffffff;
|
||||||
h=HNUseLazyEdgeStrip;
|
h=HNUseLazyEdgeStrip;
|
||||||
|
@ -196,17 +214,16 @@ class GlTrimesh : public GLW
|
||||||
SetHintParamf(HNPZTwist,0.00005f);
|
SetHintParamf(HNPZTwist,0.00005f);
|
||||||
|
|
||||||
}
|
}
|
||||||
typedef MESH_TYPE mesh_type;
|
|
||||||
FACE_POINTER_CONTAINER face_pointers;
|
|
||||||
|
|
||||||
|
~GlTrimesh()
|
||||||
|
{
|
||||||
|
//Delete the VBOs
|
||||||
|
if(h&HNUseVBO)
|
||||||
|
{
|
||||||
|
glDeleteBuffersARB(2, b);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<unsigned int> TMId;
|
|
||||||
|
|
||||||
unsigned int b[3];
|
|
||||||
int h; // the current hints
|
|
||||||
// The parameters of hints
|
|
||||||
int HNParami[8];
|
|
||||||
float HNParamf[8];
|
|
||||||
void SetHintParami(const HintParami hip, const int value)
|
void SetHintParami(const HintParami hip, const int value)
|
||||||
{
|
{
|
||||||
HNParami[hip]=value;
|
HNParami[hip]=value;
|
||||||
|
@ -223,17 +240,14 @@ class GlTrimesh : public GLW
|
||||||
{
|
{
|
||||||
return HNParamf[hip];
|
return HNParamf[hip];
|
||||||
}
|
}
|
||||||
|
void SetHint(Hint hn)
|
||||||
void SetHint(Hint hn)
|
{
|
||||||
{
|
|
||||||
h |= hn;
|
h |= hn;
|
||||||
}
|
}
|
||||||
void ClearHint(Hint hn)
|
void ClearHint(Hint hn)
|
||||||
{
|
{
|
||||||
h&=(~hn);
|
h&=(~hn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
unsigned int dl;
|
unsigned int dl;
|
||||||
std::vector<unsigned int> indices;
|
std::vector<unsigned int> indices;
|
||||||
|
@ -245,8 +259,9 @@ void ClearHint(Hint hn)
|
||||||
void Update(/*Change c=CHAll*/)
|
void Update(/*Change c=CHAll*/)
|
||||||
{
|
{
|
||||||
if(m==0) return;
|
if(m==0) return;
|
||||||
if(h&HNUseVArray){
|
|
||||||
|
|
||||||
|
if(h&HNUseVArray || h&HNUseVBO)
|
||||||
|
{
|
||||||
typename MESH_TYPE::FaceIterator fi;
|
typename MESH_TYPE::FaceIterator fi;
|
||||||
indices.clear();
|
indices.clear();
|
||||||
for(fi = m->face.begin(); fi != m->face.end(); ++fi)
|
for(fi = m->face.begin(); fi != m->face.end(); ++fi)
|
||||||
|
@ -256,7 +271,8 @@ void Update(/*Change c=CHAll*/)
|
||||||
indices.push_back((unsigned int)((*fi).V(2) - &(*m->vert.begin())));
|
indices.push_back((unsigned int)((*fi).V(2) - &(*m->vert.begin())));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(h&HNUseVBO){
|
if(h&HNUseVBO)
|
||||||
|
{
|
||||||
if(!glIsBuffer(b[1]))
|
if(!glIsBuffer(b[1]))
|
||||||
glGenBuffers(2,(GLuint*)b);
|
glGenBuffers(2,(GLuint*)b);
|
||||||
glBindBuffer(GL_ARRAY_BUFFER,b[0]);
|
glBindBuffer(GL_ARRAY_BUFFER,b[0]);
|
||||||
|
@ -266,8 +282,8 @@ void Update(/*Change c=CHAll*/)
|
||||||
glBindBuffer(GL_ARRAY_BUFFER,b[1]);
|
glBindBuffer(GL_ARRAY_BUFFER,b[1]);
|
||||||
glBufferData(GL_ARRAY_BUFFER_ARB, m->vn * sizeof(typename MESH_TYPE::VertexType),
|
glBufferData(GL_ARRAY_BUFFER_ARB, m->vn * sizeof(typename MESH_TYPE::VertexType),
|
||||||
(char *)&(m->vert[0].N()), GL_STATIC_DRAW_ARB);
|
(char *)&(m->vert[0].N()), GL_STATIC_DRAW_ARB);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
glVertexPointer(3,GL_FLOAT,sizeof(typename MESH_TYPE::VertexType),0);
|
glVertexPointer(3,GL_FLOAT,sizeof(typename MESH_TYPE::VertexType),0);
|
||||||
glNormalPointer(GL_FLOAT,sizeof(typename MESH_TYPE::VertexType),0);
|
glNormalPointer(GL_FLOAT,sizeof(typename MESH_TYPE::VertexType),0);
|
||||||
}
|
}
|
||||||
|
@ -399,37 +415,56 @@ void DrawFill()
|
||||||
typename std::vector<typename MESH_TYPE::FaceType*>::iterator fip;
|
typename std::vector<typename MESH_TYPE::FaceType*>::iterator fip;
|
||||||
short curtexname=-1;
|
short curtexname=-1;
|
||||||
|
|
||||||
if(cm == CMPerMesh) glColor(m->C());
|
if(cm == CMPerMesh)
|
||||||
//
|
glColor(m->C());
|
||||||
|
|
||||||
if(tm == TMPerWedge || tm == TMPerWedgeMulti ) {
|
if(tm == TMPerWedge || tm == TMPerWedgeMulti )
|
||||||
glDisable(GL_TEXTURE_2D);
|
glDisable(GL_TEXTURE_2D);
|
||||||
|
|
||||||
|
if(h&HNUseVBO)
|
||||||
|
{
|
||||||
|
if( (cm==CMNone) || (cm==CMPerMesh) )
|
||||||
|
{
|
||||||
|
if (nm==NMPerVert)
|
||||||
|
glEnableClientState (GL_NORMAL_ARRAY);
|
||||||
|
glEnableClientState (GL_VERTEX_ARRAY);
|
||||||
|
|
||||||
|
if (nm==NMPerVert)
|
||||||
|
{
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER,b[1]);
|
||||||
|
glNormalPointer(GL_FLOAT,sizeof(typename MESH_TYPE::VertexType),0);
|
||||||
|
}
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER,b[0]);
|
||||||
|
glVertexPointer(3,GL_FLOAT,sizeof(typename MESH_TYPE::VertexType),0);
|
||||||
|
|
||||||
|
glDrawElements(GL_TRIANGLES ,m->fn*3,GL_UNSIGNED_INT, &(*indices.begin()) );
|
||||||
|
glDisableClientState (GL_VERTEX_ARRAY);
|
||||||
|
if (nm==NMPerVert)
|
||||||
|
glDisableClientState (GL_NORMAL_ARRAY);
|
||||||
|
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||||
|
|
||||||
|
return;
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(h&HNUseVArray)
|
if(h&HNUseVArray)
|
||||||
{
|
{
|
||||||
if( (nm==NMPerVert) && ((cm==CMNone) || (cm==CMPerMesh)))
|
if( (cm==CMNone) || (cm==CMPerMesh) )
|
||||||
{
|
{
|
||||||
|
if (nm==NMPerVert)
|
||||||
glEnableClientState (GL_NORMAL_ARRAY);
|
glEnableClientState (GL_NORMAL_ARRAY);
|
||||||
glEnableClientState (GL_VERTEX_ARRAY);
|
glEnableClientState (GL_VERTEX_ARRAY);
|
||||||
|
|
||||||
if(h&HNUseVBO){
|
if (nm==NMPerVert)
|
||||||
glBindBuffer(GL_ARRAY_BUFFER,b[1]);
|
|
||||||
glNormalPointer(GL_FLOAT,sizeof(typename MESH_TYPE::VertexType),0);
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER,b[0]);
|
|
||||||
glVertexPointer(3,GL_FLOAT,sizeof(typename MESH_TYPE::VertexType),0);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
glNormalPointer(GL_FLOAT,sizeof(typename MESH_TYPE::VertexType),&(m->vert.begin()->N()[0]));
|
glNormalPointer(GL_FLOAT,sizeof(typename MESH_TYPE::VertexType),&(m->vert.begin()->N()[0]));
|
||||||
glVertexPointer(3,GL_FLOAT,sizeof(typename MESH_TYPE::VertexType),&(m->vert.begin()->P()[0]));
|
glVertexPointer(3,GL_FLOAT,sizeof(typename MESH_TYPE::VertexType),&(m->vert.begin()->P()[0]));
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
glDrawElements(GL_TRIANGLES ,m->fn*3,GL_UNSIGNED_INT, &(*indices.begin()) );
|
glDrawElements(GL_TRIANGLES ,m->fn*3,GL_UNSIGNED_INT, &(*indices.begin()) );
|
||||||
glDisableClientState (GL_VERTEX_ARRAY);
|
glDisableClientState (GL_VERTEX_ARRAY);
|
||||||
glDisableClientState (GL_NORMAL_ARRAY );
|
if (nm==NMPerVert)
|
||||||
|
glDisableClientState (GL_NORMAL_ARRAY);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -471,15 +506,14 @@ void DrawFill()
|
||||||
// if(nm == NMPerFace) ++fip;
|
// if(nm == NMPerFace) ++fip;
|
||||||
// }
|
// }
|
||||||
//glEnd();
|
//glEnd();
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
||||||
if(partial)
|
if(partial)
|
||||||
fp = face_pointers.begin();
|
fp = face_pointers.begin();
|
||||||
else
|
else
|
||||||
fi = m->face.begin();
|
fi = m->face.begin();
|
||||||
|
|
||||||
if(tm==TMPerWedgeMulti)
|
if(tm==TMPerWedgeMulti)
|
||||||
{
|
{
|
||||||
curtexname=(*fi).WT(0).n();
|
curtexname=(*fi).WT(0).n();
|
||||||
|
@ -493,17 +527,21 @@ void DrawFill()
|
||||||
glDisable(GL_TEXTURE_2D);
|
glDisable(GL_TEXTURE_2D);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
glBegin(GL_TRIANGLES);
|
glBegin(GL_TRIANGLES);
|
||||||
|
|
||||||
while( (partial)?(fp!=face_pointers.end()):(fi!=m->face.end()))
|
while( (partial)?(fp!=face_pointers.end()):(fi!=m->face.end()))
|
||||||
{
|
{
|
||||||
typename MESH_TYPE::FaceType & f = (partial)?(*(*fp)): *fi;
|
typename MESH_TYPE::FaceType & f = (partial)?(*(*fp)): *fi;
|
||||||
|
|
||||||
if(!f.IsD()){
|
if(!f.IsD())
|
||||||
|
{
|
||||||
if(tm==TMPerWedgeMulti)
|
if(tm==TMPerWedgeMulti)
|
||||||
if(f.WT(0).n() != curtexname)
|
if(f.WT(0).n() != curtexname)
|
||||||
{
|
{
|
||||||
curtexname=(*fi).WT(0).n();
|
curtexname=(*fi).WT(0).n();
|
||||||
glEnd();
|
glEnd();
|
||||||
|
|
||||||
if (curtexname >= 0)
|
if (curtexname >= 0)
|
||||||
{
|
{
|
||||||
glEnable(GL_TEXTURE_2D);
|
glEnable(GL_TEXTURE_2D);
|
||||||
|
@ -513,35 +551,41 @@ void DrawFill()
|
||||||
{
|
{
|
||||||
glDisable(GL_TEXTURE_2D);
|
glDisable(GL_TEXTURE_2D);
|
||||||
}
|
}
|
||||||
|
|
||||||
glBegin(GL_TRIANGLES);
|
glBegin(GL_TRIANGLES);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(nm == NMPerFace) glNormal(f.cN());
|
if(nm == NMPerFace) glNormal(f.cN());
|
||||||
|
if(nm == NMPerVert) glNormal(f.V(0)->cN());
|
||||||
|
if(nm == NMPerWedge)glNormal(f.WN(0));
|
||||||
|
|
||||||
if(cm == CMPerFace) glColor(f.C());
|
if(cm == CMPerFace) glColor(f.C());
|
||||||
|
if(cm == CMPerVert) glColor(f.V(0)->C());
|
||||||
|
|
||||||
if(nm==NMPerVert) glNormal(f.V(0)->cN());
|
|
||||||
if(nm==NMPerWedge)glNormal(f.WN(0));
|
|
||||||
if(cm==CMPerVert) glColor(f.V(0)->C());
|
|
||||||
// if(tm==TMPerVert) glTexCoord(f.V(0)->T());
|
// if(tm==TMPerVert) glTexCoord(f.V(0)->T());
|
||||||
if( (tm==TMPerWedge)||(tm==TMPerWedgeMulti) ) glTexCoord(f.WT(0).t(0));
|
if( (tm==TMPerWedge)||(tm==TMPerWedgeMulti) )glTexCoord(f.WT(0).t(0));
|
||||||
glVertex(f.V(0)->P());
|
glVertex(f.V(0)->P());
|
||||||
|
|
||||||
if(nm==NMPerVert) glNormal(f.V(1)->cN());
|
if(nm == NMPerVert) glNormal(f.V(1)->cN());
|
||||||
if(nm==NMPerWedge)glNormal(f.WN(1));
|
if(nm == NMPerWedge)glNormal(f.WN(1));
|
||||||
if(cm == CMPerVert) glColor(f.V(1)->C());
|
if(cm == CMPerVert) glColor(f.V(1)->C());
|
||||||
// if(tm==TMPerVert) glTexCoord(f.V(1)->T());
|
// if(tm==TMPerVert) glTexCoord(f.V(1)->T());
|
||||||
if( (tm==TMPerWedge)|| (tm==TMPerWedgeMulti)) glTexCoord(f.WT(1).t(0));
|
if( (tm==TMPerWedge)|| (tm==TMPerWedgeMulti)) glTexCoord(f.WT(1).t(0));
|
||||||
glVertex(f.V(1)->P());
|
glVertex(f.V(1)->P());
|
||||||
|
|
||||||
if(nm==NMPerVert) glNormal(f.V(2)->cN());
|
if(nm == NMPerVert) glNormal(f.V(2)->cN());
|
||||||
if(nm==NMPerWedge)glNormal(f.WN(2));
|
if(nm == NMPerWedge)glNormal(f.WN(2));
|
||||||
if(cm == CMPerVert) glColor(f.V(2)->C());
|
if(cm == CMPerVert) glColor(f.V(2)->C());
|
||||||
// if(tm==TMPerVert) glTexCoord(f.V(2)->T());
|
// if(tm==TMPerVert) glTexCoord(f.V(2)->T());
|
||||||
if( (tm==TMPerWedge)|| (tm==TMPerWedgeMulti)) glTexCoord(f.WT(2).t(0));
|
if( (tm==TMPerWedge)|| (tm==TMPerWedgeMulti)) glTexCoord(f.WT(2).t(0));
|
||||||
glVertex(f.V(2)->P());
|
glVertex(f.V(2)->P());
|
||||||
}
|
}
|
||||||
if(partial) ++fp; else ++fi;
|
|
||||||
|
if(partial)
|
||||||
|
++fp;
|
||||||
|
else
|
||||||
|
++fi;
|
||||||
}
|
}
|
||||||
|
|
||||||
glEnd();
|
glEnd();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue