Commit 3a242bf9 authored by Jan Möbius's avatar Jan Möbius
Browse files

Added arrays for per edge colors and per edge rendering

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@8401 383ad7c9-94d9-4d36-a494-682f7c89f535
parent be4fb622
......@@ -369,10 +369,22 @@ template<class Mesh>
void
TriStripNodeT<Mesh>::
draw_lines() {
if ( !lineIndexBufferInitialized_ )
std::cerr << "Error! Uninitialized Line buffer in draw call! " << std::endl;
if ( enabled_arrays_ & LINE_INDEX_ARRAY )
// Check if array is set up correctly
if ( lineIndexBufferInitialized_ )
glDrawElements(GL_LINES, mesh_.n_edges() * 2, GL_UNSIGNED_INT, 0 );
else
std::cerr << "Error! Uninitialized Line buffer in draw call! " << std::endl;
// If we are rendering per edge per vertex attributes, we need to use a seperated vertex buffer!
else if ( enabled_arrays_ & PER_EDGE_VERTEX_ARRAY )
glDrawArrays(GL_LINES, 0, mesh_.n_edges() * 2);
glDrawElements(GL_LINES, mesh_.n_edges() * 2, GL_UNSIGNED_INT, 0 );
// Something went wrong here!
else
std::cerr << "Unable to Draw! array configuration is invalid!!" << std::endl;
}
template<class Mesh>
......@@ -444,7 +456,7 @@ enable_arrays(unsigned int _arrays) {
//===================================================================
// Check if we should enable the normal array
if (_arrays & NORMAL_VERTEX_ARRAY) {
if ( mesh_.has_vertex_normals() && ( _arrays & NORMAL_VERTEX_ARRAY ) ) {
if ( !normalVertexBufferInitialized_ )
std::cerr << "Error! Uninitialized normal buffer! " << std::endl;
......@@ -472,7 +484,7 @@ enable_arrays(unsigned int _arrays) {
/// \todo This is different to normal and vertex buffer since it uses openmesh colors directly! Check for different color representations in OpenMesh!
// Check if we should enable the color array
if (_arrays & COLOR_VERTEX_ARRAY) {
if ( mesh_.has_vertex_colors() && ( _arrays & COLOR_VERTEX_ARRAY )) {
// Check if its already enabled
if (!(enabled_arrays_ & COLOR_VERTEX_ARRAY)) {
......@@ -492,6 +504,54 @@ enable_arrays(unsigned int _arrays) {
glDisableClientState(GL_COLOR_ARRAY);
}
//===================================================================
// per Edge Vertex Array
//===================================================================
// Check if we should enable the per face vertex array
if (_arrays & PER_EDGE_VERTEX_ARRAY) {
// Check if its already enabled
if (!(enabled_arrays_ & PER_EDGE_VERTEX_ARRAY)) {
enabled_arrays_ |= PER_EDGE_VERTEX_ARRAY;
// For this version we load the colors directly not from vbo
glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
glVertexPointer( stripProcessor_.perEdgeVertexBuffer() );
glEnableClientState(GL_VERTEX_ARRAY);
}
} else if (enabled_arrays_ & PER_EDGE_VERTEX_ARRAY) {
// Disable Vertex array
enabled_arrays_ &= ~PER_EDGE_VERTEX_ARRAY;
glDisableClientState(GL_VERTEX_ARRAY);
}
//===================================================================
// per Edge Color Array
//===================================================================
// Check if we should enable the per face vertex array
if ( mesh_.has_edge_colors() && ( _arrays & PER_EDGE_COLOR_ARRAY) ) {
// Check if its already enabled
if (!(enabled_arrays_ & PER_EDGE_COLOR_ARRAY)) {
enabled_arrays_ |= PER_EDGE_COLOR_ARRAY;
// For this version we load the colors directly not from vbo
glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
glColorPointer( stripProcessor_.perEdgeColorBuffer() );
glEnableClientState(GL_COLOR_ARRAY);
}
} else if (enabled_arrays_ & PER_EDGE_COLOR_ARRAY) {
// Disable Vertex array
enabled_arrays_ &= ~PER_EDGE_COLOR_ARRAY;
glDisableClientState(GL_COLOR_ARRAY);
}
//===================================================================
// per Face Vertex Array
//===================================================================
......@@ -776,7 +836,7 @@ pick_edges(GLState& _state, bool _front)
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
glVertexPointer (stripProcessor_.pickEdgeVertexBuffer());
glVertexPointer (stripProcessor_.perEdgeVertexBuffer());
glColorPointer(stripProcessor_.pickEdgeColorBuffer());
glDrawArrays(GL_LINES, 0, mesh_.n_edges() * 2);
......@@ -920,7 +980,7 @@ pick_any(GLState& _state)
glDepthFunc(GL_LEQUAL);
glVertexPointer (stripProcessor_.pickEdgeVertexBuffer());
glVertexPointer (stripProcessor_.perEdgeVertexBuffer());
glColorPointer(stripProcessor_.pickEdgeColorBuffer());
glDrawArrays(GL_LINES, 0, mesh_.n_edges() * 2);
......@@ -1145,6 +1205,9 @@ update_topology() {
// Set per face arrays to invalid as they have to be regenerated
stripProcessor_.invalidatePerFaceBuffers();
// Set per edge arrays to invalid as they have to be regenerated
stripProcessor_.invalidatePerEdgeBuffers();
// std::cerr << "Created " << stripProcessor_.nStrips() << " strips\n" << std::endl;
// ==========================================================================
......
......@@ -349,9 +349,11 @@ private:
NORMAL_VERTEX_ARRAY = 2,
COLOR_VERTEX_ARRAY = 4,
LINE_INDEX_ARRAY = 8,
PER_FACE_VERTEX_ARRAY = 16,
PER_FACE_NORMAL_ARRAY = 32,
PER_FACE_COLOR_ARRAY = 64
PER_EDGE_VERTEX_ARRAY = 16,
PER_EDGE_COLOR_ARRAY = 32,
PER_FACE_VERTEX_ARRAY = 64,
PER_FACE_NORMAL_ARRAY = 128,
PER_FACE_COLOR_ARRAY = 256
};
/// which arrays are currently enabled?
......
......@@ -181,8 +181,7 @@ private:
// Property name of the per face texture coordinates
std::string default_halfedge_textcoord_property_;
// Property name of the per face texture index.
std::string indexPropertyName_;
// display Lists used for picking
GLuint faceList_;
......
......@@ -67,7 +67,9 @@ StripProcessorT<Mesh>::
StripProcessorT(Mesh& _mesh) :
mesh_(_mesh),
triangulated_(false),
updatePerFaceBuffers_(true)
updatePerEdgeBuffers_(true),
updatePerFaceBuffers_(true),
indexPropertyName_("f:textureindex")
{
}
......@@ -328,6 +330,19 @@ buildStripPolyMesh(typename Mesh::HalfedgeHandle _start_hh,
strip.push_back(mesh_.to_vertex_handle(_start_hh).idx());
// Don't update face map here! See below why
// Check if we have to take care of textures
// If this property is not available, we do not have texture info and will therefore
// skip texture handling in strip generation
bool textureHandling = false;
OpenMesh::FPropHandleT< int > texture_index_property;
if ( mesh_.get_property_handle(texture_index_property,indexPropertyName_) ) {
std::cerr << "Texture index property found!" << std::endl;
textureHandling = true;
} else {
std::cerr << "No textures" << std::endl;
}
// Walk along the strip: 1st direction
// We construct the strip by using alternating vertices
......@@ -588,8 +603,11 @@ template <class Mesh>
void
StripProcessorT<Mesh>::
updatePickingEdges(ACG::GLState& _state, uint _offset ) {
updatePerEdgeBuffers();
pickEdgeColorBuf_.resize(mesh_.n_edges() * 2);
pickEdgeVertexBuf_.resize(mesh_.n_edges() * 2);
int idx = 0;
......@@ -600,9 +618,7 @@ updatePickingEdges(ACG::GLState& _state, uint _offset ) {
pickEdgeColorBuf_[idx] = pickColor;
pickEdgeColorBuf_[idx+1] = pickColor;
pickEdgeVertexBuf_[idx] = mesh_.point(mesh_.to_vertex_handle(mesh_.halfedge_handle(e_it, 0)));
pickEdgeVertexBuf_[idx+1] = mesh_.point(mesh_.to_vertex_handle(mesh_.halfedge_handle(e_it, 1)));
idx += 2;
}
}
......@@ -695,6 +711,63 @@ updatePickingAny(ACG::GLState& _state ) {
updatePickingVertices(_state,mesh_.n_faces() + mesh_.n_edges());
}
template <class Mesh>
void
StripProcessorT<Mesh>::
updatePerEdgeBuffers() {
// Only update buffers if they are invalid
if (!updatePerEdgeBuffers_)
return;
perEdgeVertexBuffer_.resize(mesh_.n_edges() * 2);
if ( mesh_.has_edge_colors() ) {
perEdgeColorBuffer_.resize(mesh_.n_edges() * 2);
std::cerr << "Per Edge color buffer generated" << std::endl;
} else
perEdgeColorBuffer_.clear();
unsigned int idx = 0;
typename Mesh::ConstEdgeIter e_it(mesh_.edges_sbegin()), e_end(mesh_.edges_end());
for (; e_it!=e_end; ++e_it) {
perEdgeVertexBuffer_[idx] = mesh_.point(mesh_.to_vertex_handle(mesh_.halfedge_handle(e_it, 0)));
perEdgeVertexBuffer_[idx+1] = mesh_.point(mesh_.to_vertex_handle(mesh_.halfedge_handle(e_it, 1)));
if ( mesh_.has_edge_colors() ) {
const Vec4f color = OpenMesh::color_cast<Vec4f>( mesh_.color(e_it) ) ;
perEdgeColorBuffer_[ idx ] = color;
perEdgeColorBuffer_[ idx + 1 ] = color;
}
idx += 2;
}
updatePerEdgeBuffers_ = false;
}
template <class Mesh>
ACG::Vec3f *
StripProcessorT<Mesh>::
perEdgeVertexBuffer() {
// Force update of the buffers if required
if (updatePerEdgeBuffers_)
updatePerEdgeBuffers();
return &(perEdgeVertexBuffer_)[0];
}
template <class Mesh>
ACG::Vec4f *
StripProcessorT<Mesh>::
perEdgeColorBuffer() {
// Force update of the buffers if required
if (updatePerEdgeBuffers_)
updatePerEdgeBuffers();
return &(perEdgeColorBuffer_)[0];
}
template <class Mesh>
void
StripProcessorT<Mesh>::
......
......@@ -178,6 +178,47 @@ private:
bool triangulated_;
std::vector<FaceMap> faceMaps_;
//===========================================================================
/** @name Per edge drawing arrays handling
* @{ */
//===========================================================================
public:
/** \brief get a pointer to the per edge vertex buffer
*
* This function will return a pointer to the first element of the vertex buffer.
*/
ACG::Vec3f * perEdgeVertexBuffer();
/** \brief get a pointer to the per edge color buffer
*
* This function will return a pointer to the first element of the color buffer.
*/
ACG::Vec4f * perEdgeColorBuffer();
/** \brief Update of the buffers
*
* This function will set all per edge buffers to invalid and will force an update
* whe they are requested
*/
void invalidatePerEdgeBuffers(){ updatePerEdgeBuffers_ = true; };
private:
/** \brief Update all per edge drawing buffer
*n
* The updated buffers are: per edge vertex buffer ( 2 vertices per edge )
*/
void updatePerEdgeBuffers();
/// Per Edge vertex buffer (glLines)
std::vector< ACG::Vec3f > perEdgeVertexBuffer_;
/// Per Edge color buffer
std::vector< ACG::Vec4f > perEdgeColorBuffer_;
/// This flag controls if an update is really necessary
bool updatePerEdgeBuffers_;
/** @} */
//===========================================================================
/** @name Per face drawing arrays handling
* @{ */
......@@ -231,6 +272,7 @@ private:
std::vector< ACG::Vec4f > perFaceColorBuffer_;
std::vector< ACG::Vec3f > perFaceNormalBuffer_;
/// This flag controls if an update is really necessary
bool updatePerFaceBuffers_;
/** @} */
......@@ -285,18 +327,11 @@ private:
*/
ACG::Vec4uc * pickEdgeColorBuffer(){ return &(pickEdgeColorBuf_)[0]; };
/** \brief get a pointer to the per edge picking vertex buffer
*
* This function will return a pointer to the first element of the picking buffer.
* Use updatePickingEdges to update the buffer before you render it via
* glColorPointer.
*/
ACG::Vec3f * pickEdgeVertexBuffer(){ return &(pickEdgeVertexBuf_)[0]; };
private:
std::vector< ACG::Vec4uc > pickEdgeColorBuf_;
std::vector< ACG::Vec3f > pickEdgeVertexBuf_;
/** @} */
......@@ -359,7 +394,25 @@ private:
std::vector< ACG::Vec4uc > pickAnyColorBuf_;
/** @} */
/** @} */
//===========================================================================
/** @name Texture handling
* @{ */
//===========================================================================
private:
/** \brief Property name of the per face texture index.
*
* This name is used by the mesh for texture index specification.
* If this is empty, Then it is assumed that there is one or no active
* texture. This means that the generated strips will be independent of texture
* information.
*/
std::string indexPropertyName_;
/** @} */
};
......
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