- 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:
Paolo Cignoni 2007-12-04 17:59:41 +00:00
parent 416dedd484
commit 63ee2004b6
1 changed files with 177 additions and 133 deletions

View File

@ -24,6 +24,9 @@
History
$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
Corrected indexing for non textured faces.
@ -146,6 +149,7 @@ public:
CHColor = 0x04,
CHFace = 0x08,
CHFaceNormal = 0x10,
CHRender = 0x20,
CHAll = 0xff
};
enum HintParami {
@ -183,8 +187,22 @@ class GlTrimesh : public GLW
{
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;
GlTrimesh(){
GlTrimesh()
{
m=0;
dl=0xffffffff;
h=HNUseLazyEdgeStrip;
@ -196,17 +214,16 @@ class GlTrimesh : public GLW
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)
{
HNParami[hip]=value;
@ -223,7 +240,6 @@ class GlTrimesh : public GLW
{
return HNParamf[hip];
}
void SetHint(Hint hn)
{
h |= hn;
@ -233,8 +249,6 @@ void ClearHint(Hint hn)
h&=(~hn);
}
unsigned int dl;
std::vector<unsigned int> indices;
@ -245,8 +259,9 @@ void ClearHint(Hint hn)
void Update(/*Change c=CHAll*/)
{
if(m==0) return;
if(h&HNUseVArray){
if(h&HNUseVArray || h&HNUseVBO)
{
typename MESH_TYPE::FaceIterator fi;
indices.clear();
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())));
}
if(h&HNUseVBO){
if(h&HNUseVBO)
{
if(!glIsBuffer(b[1]))
glGenBuffers(2,(GLuint*)b);
glBindBuffer(GL_ARRAY_BUFFER,b[0]);
@ -266,8 +282,8 @@ void Update(/*Change c=CHAll*/)
glBindBuffer(GL_ARRAY_BUFFER,b[1]);
glBufferData(GL_ARRAY_BUFFER_ARB, m->vn * sizeof(typename MESH_TYPE::VertexType),
(char *)&(m->vert[0].N()), GL_STATIC_DRAW_ARB);
}
glVertexPointer(3,GL_FLOAT,sizeof(typename MESH_TYPE::VertexType),0);
glNormalPointer(GL_FLOAT,sizeof(typename MESH_TYPE::VertexType),0);
}
@ -399,36 +415,55 @@ void DrawFill()
typename std::vector<typename MESH_TYPE::FaceType*>::iterator fip;
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);
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( (nm==NMPerVert) && ((cm==CMNone) || (cm==CMPerMesh)))
if( (cm==CMNone) || (cm==CMPerMesh) )
{
if (nm==NMPerVert)
glEnableClientState (GL_NORMAL_ARRAY);
glEnableClientState (GL_VERTEX_ARRAY);
if(h&HNUseVBO){
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
{
if (nm==NMPerVert)
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]));
}
glDrawElements(GL_TRIANGLES ,m->fn*3,GL_UNSIGNED_INT, &(*indices.begin()) );
glDisableClientState (GL_VERTEX_ARRAY);
if (nm==NMPerVert)
glDisableClientState (GL_NORMAL_ARRAY);
return;
@ -471,15 +506,14 @@ void DrawFill()
// if(nm == NMPerFace) ++fip;
// }
//glEnd();
}
else
{
if(partial)
fp = face_pointers.begin();
else
fi = m->face.begin();
if(tm==TMPerWedgeMulti)
{
curtexname=(*fi).WT(0).n();
@ -493,17 +527,21 @@ void DrawFill()
glDisable(GL_TEXTURE_2D);
}
}
glBegin(GL_TRIANGLES);
while( (partial)?(fp!=face_pointers.end()):(fi!=m->face.end()))
{
typename MESH_TYPE::FaceType & f = (partial)?(*(*fp)): *fi;
if(!f.IsD()){
if(!f.IsD())
{
if(tm==TMPerWedgeMulti)
if(f.WT(0).n() != curtexname)
{
curtexname=(*fi).WT(0).n();
glEnd();
if (curtexname >= 0)
{
glEnable(GL_TEXTURE_2D);
@ -513,14 +551,15 @@ void DrawFill()
{
glDisable(GL_TEXTURE_2D);
}
glBegin(GL_TRIANGLES);
}
if(nm == NMPerFace) glNormal(f.cN());
if(cm == CMPerFace) glColor(f.C());
if(nm == NMPerVert) glNormal(f.V(0)->cN());
if(nm == NMPerWedge)glNormal(f.WN(0));
if(cm == CMPerFace) glColor(f.C());
if(cm == CMPerVert) glColor(f.V(0)->C());
// if(tm==TMPerVert) glTexCoord(f.V(0)->T());
if( (tm==TMPerWedge)||(tm==TMPerWedgeMulti) )glTexCoord(f.WT(0).t(0));
@ -540,8 +579,13 @@ void DrawFill()
if( (tm==TMPerWedge)|| (tm==TMPerWedgeMulti)) glTexCoord(f.WT(2).t(0));
glVertex(f.V(2)->P());
}
if(partial) ++fp; else ++fi;
if(partial)
++fp;
else
++fi;
}
glEnd();
}