Commit cd999f07 authored by Christopher Tenter's avatar Christopher Tenter
Browse files

Added support for vertex / per halfedge texcoord toggle.

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@11727 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 4fcdeb7c
......@@ -34,9 +34,9 @@
/*===========================================================================*\
* *
* $Revision$ *
* $Author$ *
* $Date$ *
* *
* *
* *
* *
\*===========================================================================*/
......@@ -125,6 +125,7 @@ DrawMeshT<Mesh>::DrawMeshT(Mesh& _mesh)
indexType_(0),
colorMode_(1),
flatMode_(0), bVBOinFlatMode_(0),
textureMode_(1), bVBOinHalfedgeTexMode_(1),
triToFaceMap_(0),
vertexMap_(0),
invVertexMap_(0),
......@@ -404,11 +405,10 @@ DrawMeshT<Mesh>::readVertex(Vertex* _pV,
if (m < 2)
{
if (mesh_.has_vertex_texcoords2D())
if (mesh_.has_halfedge_texcoords2D())
{
if (_hh != (typename Mesh::HalfedgeHandle)(-1))
_pV->tex[m] = mesh_.texcoord2D(_hh)[m];
else _pV->tex[m] = mesh_.texcoord2D(_vh)[m];
}
else _pV->tex[m] = 0.0f;
}
......@@ -743,7 +743,7 @@ DrawMeshT<Mesh>::createVBO()
glBindBufferARB(GL_ARRAY_BUFFER_ARB, vbo_);
if (!flatMode_)
if (!flatMode_ && textureMode_)
{
glBufferDataARB(GL_ARRAY_BUFFER_ARB, numVerts_ * sizeof(Vertex), vertices_, GL_STATIC_DRAW_ARB);
bVBOinFlatMode_ = 0;
......@@ -753,6 +753,8 @@ DrawMeshT<Mesh>::createVBO()
// use per face normals
memcpy(verticesTmp_, vertices_, sizeof(Vertex) * numVerts_);
if (flatMode_)
{
for (unsigned int i = 0; i < numTris_; ++i)
{
// calculate face normal
......@@ -768,16 +770,29 @@ DrawMeshT<Mesh>::createVBO()
ACG::Vec3f v = V[2] - V[0];
ACG::Vec3f n = OpenMesh::cross(u, v).normalize_cond();
// store face normal in first vertex
// store face normal in last tri vertex
for (unsigned int k = 0; k < 3; ++k)
{
verticesTmp_[indices_[i*3+2]].n[k] = n[k];
}
}
bVBOinFlatMode_ = 1;
}
if (!textureMode_)
{
for (unsigned int i = 0; i < numVerts_; ++i)
{
for (int k = 0; k < 2; ++k)
{
verticesTmp_[i].tex[k] = mesh_.texcoord2D(
mesh_.to_vertex_handle(mesh_.halfedge_handle(vertexMap_[i])))[k];
}
}
bVBOinHalfedgeTexMode_ = 0;
}
glBufferDataARB(GL_ARRAY_BUFFER_ARB, numVerts_ * sizeof(Vertex), verticesTmp_, GL_STATIC_DRAW_ARB);
bVBOinFlatMode_ = 1;
}
glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
......@@ -886,7 +901,7 @@ void DrawMeshT<Mesh>::bindBuffers()
// to update normals
if (rebuild_ == REBUILD_NONE)
{
if (bVBOinFlatMode_ != flatMode_)
if (bVBOinFlatMode_ != flatMode_ || bVBOinHalfedgeTexMode_ != textureMode_)
createVBO();
}
else
......
......@@ -34,9 +34,9 @@
/*===========================================================================*\
* *
* $Revision$ *
* $Author$ *
* $Date$ *
* *
* *
* *
* *
\*===========================================================================*/
......@@ -109,7 +109,7 @@ private:
Vertex();
float pos[3]; /*!< Position */
float tex[2]; /*!< texture coordinates */
float tex[2]; /*!< per halfedge texture coordinates */
float n[3]; /*!< normal vector */
// float tan[4]; /*!< tangent vector + parity */
......@@ -154,6 +154,9 @@ public:
void setFlatShading() {flatMode_ = 1;}
void setSmoothShading() {flatMode_ = 0;}
void usePerVertexTexcoords() {textureMode_ = 0;}
void usePerHalfedgeTexcoords() {textureMode_ = 1;}
/** \brief eventually rebuilds buffers used for rendering and binds index and vertex buffer
*/
void bindBuffers();
......@@ -584,6 +587,12 @@ private:
/// normals in VBO currently in flat / smooth mode
int bVBOinFlatMode_;
/// per vertex / halfedge texture mode toggle: 0: per vertex, 1: per halfedge
int textureMode_;
/// texcoords in VBO currently in per vertex / halfedge mode toggle
int bVBOinHalfedgeTexMode_;
/** remapping for faster mesh change updates
* maps from triangle index to Mesh::FaceHandle::idx
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment