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 @@ ...@@ -34,9 +34,9 @@
/*===========================================================================*\ /*===========================================================================*\
* * * *
* $Revision$ * * *
* $Author$ * * *
* $Date$ * * *
* * * *
\*===========================================================================*/ \*===========================================================================*/
...@@ -125,6 +125,7 @@ DrawMeshT<Mesh>::DrawMeshT(Mesh& _mesh) ...@@ -125,6 +125,7 @@ DrawMeshT<Mesh>::DrawMeshT(Mesh& _mesh)
indexType_(0), indexType_(0),
colorMode_(1), colorMode_(1),
flatMode_(0), bVBOinFlatMode_(0), flatMode_(0), bVBOinFlatMode_(0),
textureMode_(1), bVBOinHalfedgeTexMode_(1),
triToFaceMap_(0), triToFaceMap_(0),
vertexMap_(0), vertexMap_(0),
invVertexMap_(0), invVertexMap_(0),
...@@ -404,11 +405,10 @@ DrawMeshT<Mesh>::readVertex(Vertex* _pV, ...@@ -404,11 +405,10 @@ DrawMeshT<Mesh>::readVertex(Vertex* _pV,
if (m < 2) if (m < 2)
{ {
if (mesh_.has_vertex_texcoords2D()) if (mesh_.has_halfedge_texcoords2D())
{ {
if (_hh != (typename Mesh::HalfedgeHandle)(-1)) if (_hh != (typename Mesh::HalfedgeHandle)(-1))
_pV->tex[m] = mesh_.texcoord2D(_hh)[m]; _pV->tex[m] = mesh_.texcoord2D(_hh)[m];
else _pV->tex[m] = mesh_.texcoord2D(_vh)[m];
} }
else _pV->tex[m] = 0.0f; else _pV->tex[m] = 0.0f;
} }
...@@ -743,7 +743,7 @@ DrawMeshT<Mesh>::createVBO() ...@@ -743,7 +743,7 @@ DrawMeshT<Mesh>::createVBO()
glBindBufferARB(GL_ARRAY_BUFFER_ARB, vbo_); glBindBufferARB(GL_ARRAY_BUFFER_ARB, vbo_);
if (!flatMode_) if (!flatMode_ && textureMode_)
{ {
glBufferDataARB(GL_ARRAY_BUFFER_ARB, numVerts_ * sizeof(Vertex), vertices_, GL_STATIC_DRAW_ARB); glBufferDataARB(GL_ARRAY_BUFFER_ARB, numVerts_ * sizeof(Vertex), vertices_, GL_STATIC_DRAW_ARB);
bVBOinFlatMode_ = 0; bVBOinFlatMode_ = 0;
...@@ -753,31 +753,46 @@ DrawMeshT<Mesh>::createVBO() ...@@ -753,31 +753,46 @@ DrawMeshT<Mesh>::createVBO()
// use per face normals // use per face normals
memcpy(verticesTmp_, vertices_, sizeof(Vertex) * numVerts_); memcpy(verticesTmp_, vertices_, sizeof(Vertex) * numVerts_);
for (unsigned int i = 0; i < numTris_; ++i) if (flatMode_)
{ {
// calculate face normal for (unsigned int i = 0; i < numTris_; ++i)
ACG::Vec3f V[3];
for (unsigned int k = 0; k < 3; ++k)
{ {
Vertex* p = verticesTmp_ + indices_[i * 3 + k]; // calculate face normal
V[k] = ACG::Vec3f(p->pos[0], p->pos[1], p->pos[2]); ACG::Vec3f V[3];
}
for (unsigned int k = 0; k < 3; ++k)
{
Vertex* p = verticesTmp_ + indices_[i * 3 + k];
V[k] = ACG::Vec3f(p->pos[0], p->pos[1], p->pos[2]);
}
ACG::Vec3f u = V[1] - V[0]; ACG::Vec3f u = V[1] - V[0];
ACG::Vec3f v = V[2] - V[0]; ACG::Vec3f v = V[2] - V[0];
ACG::Vec3f n = OpenMesh::cross(u, v).normalize_cond(); 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) 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)
{ {
verticesTmp_[indices_[i*3+2]].n[k] = n[k]; 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); glBufferDataARB(GL_ARRAY_BUFFER_ARB, numVerts_ * sizeof(Vertex), verticesTmp_, GL_STATIC_DRAW_ARB);
bVBOinFlatMode_ = 1;
} }
glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0); glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
...@@ -886,7 +901,7 @@ void DrawMeshT<Mesh>::bindBuffers() ...@@ -886,7 +901,7 @@ void DrawMeshT<Mesh>::bindBuffers()
// to update normals // to update normals
if (rebuild_ == REBUILD_NONE) if (rebuild_ == REBUILD_NONE)
{ {
if (bVBOinFlatMode_ != flatMode_) if (bVBOinFlatMode_ != flatMode_ || bVBOinHalfedgeTexMode_ != textureMode_)
createVBO(); createVBO();
} }
else else
......
...@@ -34,9 +34,9 @@ ...@@ -34,9 +34,9 @@
/*===========================================================================*\ /*===========================================================================*\
* * * *
* $Revision$ * * *
* $Author$ * * *
* $Date$ * * *
* * * *
\*===========================================================================*/ \*===========================================================================*/
...@@ -109,7 +109,7 @@ private: ...@@ -109,7 +109,7 @@ private:
Vertex(); Vertex();
float pos[3]; /*!< Position */ float pos[3]; /*!< Position */
float tex[2]; /*!< texture coordinates */ float tex[2]; /*!< per halfedge texture coordinates */
float n[3]; /*!< normal vector */ float n[3]; /*!< normal vector */
// float tan[4]; /*!< tangent vector + parity */ // float tan[4]; /*!< tangent vector + parity */
...@@ -154,6 +154,9 @@ public: ...@@ -154,6 +154,9 @@ public:
void setFlatShading() {flatMode_ = 1;} void setFlatShading() {flatMode_ = 1;}
void setSmoothShading() {flatMode_ = 0;} 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 /** \brief eventually rebuilds buffers used for rendering and binds index and vertex buffer
*/ */
void bindBuffers(); void bindBuffers();
...@@ -580,10 +583,16 @@ private: ...@@ -580,10 +583,16 @@ private:
int colorMode_; int colorMode_;
/// flat / smooth shade mode toggle /// flat / smooth shade mode toggle
int flatMode_; int flatMode_;
/// normals in VBO currently in flat / smooth mode /// normals in VBO currently in flat / smooth mode
int bVBOinFlatMode_; 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 /** remapping for faster mesh change updates
* maps from triangle index to Mesh::FaceHandle::idx * maps from triangle index to Mesh::FaceHandle::idx
...@@ -714,4 +723,4 @@ private: ...@@ -714,4 +723,4 @@ private:
#endif #endif
//============================================================================= //=============================================================================
#endif // ACG_DRAW_MESH_HH defined #endif // ACG_DRAW_MESH_HH defined
//============================================================================= //=============================================================================
\ No newline at end of file
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