59 #ifndef ACG_DRAW_MESH_HH 60 #define ACG_DRAW_MESH_HH 67 #include <OpenMesh/Core/Utils/Property.hh> 68 #include <OpenMesh/Core/IO/MeshIO.hh> 70 #include <ACG/GL/globjects.hh> 71 #include <ACG/GL/GLState.hh> 72 #include <ACG/GL/IRenderer.hh> 73 #include <ACG/GL/MeshCompiler.hh> 74 #include <ACG/ShaderUtils/GLSLShader.hh> 76 #include <ACG/Config/ACGDefines.hh> 100 void bindPickVertexIbo();
102 void createIndexBuffer();
103 void fillLineBuffer(
size_t n_edges,
void *data);
104 void fillVertexBuffer();
105 void fillInvVertexMap(
size_t n_vertices,
void *data);
108 unsigned int getNumTris()
const {
return numTris_; }
109 unsigned int getNumVerts()
const {
return numVerts_; }
114 unsigned int getNumSubsets()
const {
return meshComp_->
getNumSubsets();}
130 size_t numTris_, numVerts_;
171 template <
class Mesh>
179 unsigned long startIndex;
180 unsigned long numTris;
183 enum REBUILD_TYPE {REBUILD_NONE = 0, REBUILD_FULL = 1, REBUILD_GEOMETRY = 2, REBUILD_TOPOLOGY = 4, REBUILD_TEXTURES = 8};
191 void disableColors() {colorMode_ = 0;}
192 void usePerVertexColors() {colorMode_ = 1;}
193 void usePerFaceColors() {colorMode_ = 2;}
195 void setFlatShading() {flatMode_ = 1;}
196 void setSmoothShading() {flatMode_ = 0;}
198 void usePerVertexTexcoords() {textureMode_ = 0;}
199 void usePerHalfedgeTexcoords() {textureMode_ = 1;}
200 void usePerVertexNormals() {halfedgeNormalMode_ = 0;}
201 void usePerHalfedgeNormals() {halfedgeNormalMode_ = 1;}
224 unsigned int mapVertexToVBOIndex(
unsigned int _v);
233 void unbindBuffers();
240 void draw(std::map< int, GLuint>* _textureMap,
bool _nonindexed =
false);
250 void addTriRenderObjects(
IRenderer* _renderer,
const RenderObject* _baseObj, std::map< int, GLuint>* _textureMap,
bool _nonindexed =
false);
274 unsigned int getMemoryUsage(
bool _printReport =
false);
300 unsigned int getNumTextures();
310 void setTextureIndexPropertyName( std::string _indexPropertyName );
326 void setPerFaceTextureCoordinatePropertyName( std::string _perFaceTextureCoordinatePropertyName );
334 int perFaceTextureCoordinateAvailable();
343 int perFaceTextureIndexAvailable();
348 PROPERTY_SOURCE_VERTEX = 0,
349 PROPERTY_SOURCE_HALFEDGE,
350 PROPERTY_SOURCE_FACE,
358 void addVertexElement(
const std::string& _propertyName, PropertySource _source = PROPERTY_SOURCE_VERTEX );
370 bool scanVertexShaderForInput(
const std::string& _vertexShaderFile );
388 void readVertex(
unsigned int _vertex,
390 const typename Mesh::HalfedgeHandle _hh,
391 const typename Mesh::FaceHandle _fh);
403 unsigned int getFaceColor(
const typename Mesh::FaceHandle _fh);
408 void updateGPUBuffers();
423 void createVertexDeclaration();
435 void updatePickingVertices(
ACG::GLState& _state , uint _offset = 0);
446 if ( !pickVertColBuf_.empty() )
447 return &(pickVertColBuf_)[0];
449 std::cerr <<
"Illegal request to pickVertexColorBuffer when buffer is empty!" << std::endl;
463 if ( !pickVertBuf_.empty() )
464 return &(pickVertBuf_)[0];
466 std::cerr <<
"Illegal request to pickVertexBuffer when buffer is empty!" << std::endl;
477 void drawPickingVertices_opt(
const GLMatrixf& _mvp,
int _pickOffset);
483 bool supportsPickingVertices_opt();
491 #ifdef GL_ARB_texture_buffer_object 494 if ( pickVertexMapTBO_.is_valid() )
495 return &pickVertexMapTBO_;
497 std::cerr <<
"Illegal request to pickVertexMap_opt when buffer is empty!" << std::endl;
502 #endif // GL_ARB_texture_buffer_object 512 #ifdef GL_ARB_texture_buffer_object 515 #endif // GL_ARB_texture_buffer_object 524 int pickVertexMethod_;
537 void updatePickingEdges(
ACG::GLState& _state , uint _offset = 0 );
548 if ( !pickEdgeBuf_.empty() )
549 return &(pickEdgeBuf_)[0];
551 std::cerr <<
"Illegal request to pickEdgeColorBuffer when buffer is empty!" << std::endl;
562 void drawPickingEdges_opt(
const GLMatrixf& _mvp,
int _pickOffset);
568 bool supportsPickingEdges_opt();
578 std::vector< ACG::Vec4uc > pickEdgeBuf_;
601 if ( !pickFaceColBuf_.empty() )
602 return &(pickFaceColBuf_)[0];
604 std::cerr <<
"Illegal request to pickFaceColorBuffer when buffer is empty!" << std::endl;
618 if ( !pickFaceVertexBuf_.empty() )
619 return &(pickFaceVertexBuf_)[0];
621 std::cerr <<
"Illegal request to pickFaceVertexBuffer when buffer is empty!" << std::endl;
631 void drawPickingFaces_opt(
const GLMatrixf& _mvp,
int _pickOffset);
637 bool supportsPickingFaces_opt();
645 #ifdef GL_ARB_texture_buffer_object 648 if ( pickFaceTriToFaceMapTBO_.is_valid() )
649 return &pickFaceTriToFaceMapTBO_;
651 std::cerr <<
"Illegal request to pickFaceTriangleMap_opt when buffer is empty!" << std::endl;
660 std::vector< ACG::Vec3f > pickFaceVertexBuf_;
661 std::vector< ACG::Vec4uc > pickFaceColBuf_;
663 #ifdef GL_ARB_texture_buffer_object 666 #endif // GL_ARB_texture_buffer_object 690 if ( !pickAnyFaceColBuf_.empty() )
691 return &(pickAnyFaceColBuf_)[0];
693 std::cerr <<
"Illegal request to pickAnyFaceColorBuffer when buffer is empty!" << std::endl;
707 if ( !pickAnyEdgeColBuf_.empty() )
708 return &(pickAnyEdgeColBuf_)[0];
710 std::cerr <<
"Illegal request to pickAnyEdgeColorBuffer when buffer is empty!" << std::endl;
724 if ( !pickAnyVertexColBuf_.empty() )
725 return &(pickAnyVertexColBuf_)[0];
727 std::cerr <<
"Illegal request to pickAnyVertexColorBuffer when buffer is empty!" << std::endl;
737 void drawPickingAny_opt(
const GLMatrixf& _mvp,
int _pickOffset);
742 bool supportsPickingAny_opt();
752 std::vector< ACG::Vec4uc > pickAnyFaceColBuf_;
753 std::vector< ACG::Vec4uc > pickAnyEdgeColBuf_;
754 std::vector< ACG::Vec4uc > pickAnyVertexColBuf_;
771 unsigned int countTris(
unsigned int* _pOutMaxPolyVerts = 0,
unsigned int* _pOutNumIndices = 0);
780 int getTextureIDofTri(
unsigned int _tri);
787 int getTextureIDofFace(
unsigned int _face);
797 const void* getMeshPropertyType(
OpenMesh::BaseProperty* _prop, GLuint* _outType,
unsigned int* _outSize)
const;
818 void dumpObj(
const char* _filename)
const;
877 PropertySource source_;
932 void writeVertexElement(
void* _dstBuf,
unsigned int _vertex,
unsigned int _stride,
unsigned int _elementOffset,
unsigned int _elementSize,
const void* _elementData);
934 void writePosition(
unsigned int _vertex,
const ACG::Vec3d& _p);
936 void writeNormal(
unsigned int _vertex,
const ACG::Vec3d& _n);
938 void writeTexcoord(
unsigned int _vertex,
const ACG::Vec2f& _uv);
940 void writeColor(
unsigned int _vertex,
unsigned int _color);
952 void readVertexFromVBO(
unsigned int _vertex,
void* _dst);
966 void invalidateFullVBO();
973 void updateFullVBO();
979 GeometryBuffer vboFull_;
1002 void updatePerEdgeBuffers();
1027 template<
typename Mesh::Normal (DrawMeshT::*NormalLookup)(
typename Mesh::FaceHandle)>
1028 void updatePerHalfedgeBuffers();
1045 void updateEdgeHalfedgeVertexDeclarations();
1062 int updatePerEdgeBuffers_;
1063 std::vector<ACG::Vec3f> perEdgeVertexBuf_;
1064 std::vector<ACG::Vec4f> perEdgeColorBuf_;
1066 int updatePerHalfedgeBuffers_;
1067 std::vector<ACG::Vec3f> perHalfedgeVertexBuf_;
1068 std::vector<ACG::Vec4f> perHalfedgeColorBuf_;
1077 template<
typename Mesh::Normal (DrawMeshT::*NormalLookup)(
typename Mesh::FaceHandle)>
1078 typename Mesh::Point halfedge_point(
const typename Mesh::HalfedgeHandle _heh);
1081 typename Mesh::Normal cachedNormalLookup(
typename Mesh::FaceHandle fh) {
1082 return mesh_.normal(fh);
1086 typename Mesh::Normal computedTriMeshNormal(
typename Mesh::FaceHandle fh) {
1087 typename Mesh::FVIter fv_iter = mesh_.fv_begin(fh);
1088 const typename Mesh::Point p1 = mesh_.point(*fv_iter);
1089 const typename Mesh::Point p2 = mesh_.point(*(++fv_iter));
1090 const typename Mesh::Point p3 = mesh_.point(*(++fv_iter));
1091 return ( p1 + p2 + p3 ) / 3.0;
1095 typename Mesh::Normal computedNormal(
typename Mesh::FaceHandle fh) {
1096 unsigned int count = 0;
1098 for (
typename Mesh::FVIter fv_it = mesh_.fv_begin(fh), fv_end = mesh_.fv_end(fh); fv_it != fv_end; ++fv_it) {
1099 normal += mesh_.point(*fv_it);
1106 typename Mesh::HalfedgeHandle mapToHalfedgeHandle(
int _vertexId);
1114 #if defined(INCLUDE_TEMPLATES) && !defined(ACG_DRAW_MESH_TCC) 1115 #define ACG_DRAW_MESH_TEMPLATES 1116 #include "DrawMeshT.cc" 1119 #endif // ACG_DRAW_MESH_HH defined Mesh & mesh_
OpenMesh object to be rendered.
VertexElement destType_
property type as stored in vbo
std::string textureIndexPropertyName_
Property for the per face texture index.
ACG::Vec4uc * pickVertexColorBuffer()
get a pointer to the per vertex picking color buffer
std::vector< char > vertices_
int getNumSubsets() const
Get the number of subsets.
std::vector< ACG::Vec3f > pickVertBuf_
The vertex buffer used for vertex picking.
ACG::Vec4uc * pickAnyEdgeColorBuffer()
get a pointer to the any picking color buffer
int declElementID_
element id in vertex declaration
Description of one vertex element.
void invalidatePerHalfedgeBuffers()
Update of the buffers.
ACG::Vec4uc * pickAnyVertexColorBuffer()
get a pointer to the any picking color buffer
std::string name_
property name in openmesh
int colorMode_
Color Mode: 0: none, 1: per vertex, else: per face.
const VertexDeclaration * getHalfedgeColoredVertexDeclaration() const
getter for vertex declarations
Class to define the vertex input layout.
std::string vertexShaderInputName_
input name id in vertex shader
void updateGeometry()
request an update for the mesh vertices
GLuint lineIBO_
index buffer used in Wireframe / Hiddenline mode
VertexDeclaration * vertexDeclHalfedgePos_
vertex buffer layout declaration with halfedge positions only
GLSL::Program * pickFaceShader_
optimized face picking shader
void updateTextures()
request an update for the textures
void updateTopology()
request an update for the mesh topology
unsigned int rebuild_
hint on what to rebuild
ACG::Vec4uc * pickAnyFaceColorBuffer()
get a pointer to the any picking color buffer
VertexElement sourceType_
property type as stored in openmesh
std::string perFaceTextureCoordinatePropertyName_
Property for the per face texture coordinates.
Kernel::Normal Normal
Normal type.
std::vector< ACG::Vec4uc > pickVertColBuf_
The color buffer used for vertex picking.
const size_t offsetPos_
fixed vertex elements:
const VertexDeclaration * getEdgeColoredVertexDeclaration() const
getter for vertex declarations
const VertexDeclaration * getHalfedgeVertexDeclaration() const
getter for vertex declarations
void updateFull()
request a full rebuild of the mesh
ACG::Vec3f * pickVertexBuffer()
get a pointer to the per vertex picking vertex buffer
GLenum getIndexType() const
get index type of index buffer
unsigned int * indices_
final index buffer used for rendering
GLuint pickVertexIBO_opt()
get an index buffer mapping from openmesh vertices to drawmesh vbo vertices
int textureMode_
per vertex / halfedge texture mode toggle: 0: per vertex, 1: per halfedge
Kernel::VertexHandle VertexHandle
Handle for referencing the corresponding item.
MeshCompiler * getMeshCompiler()
get mesh compiler used to create the draw mesh
Namespace providing different geometric functions concerning angles.
int bVBOinFlatMode_
normals in VBO currently in flat / smooth mode
ACG::Vec3f * pickFaceVertexBuffer()
get a pointer to the per vertex picking color buffer
void invalidatePerEdgeBuffers()
Update of the buffers.
GLuint pickVertexIBO_
map from openmesh vertex to vbo vertex id
GLenum indexType_
support for 2 and 4 byte unsigned integers
int flatMode_
flat / smooth shade mode toggle
unsigned int * invVertexMap_
const std::string & getTextureIndexPropertyName() const
get the name of the texture index property
VertexDeclaration * vertexDecl_
vertex buffer layout declaration with per vertex colors
int bVBOinHalfedgeTexMode_
texcoords in VBO currently in per vertex / halfedge mode toggle
Kernel::Point Point
Coordinate type.
VertexDeclaration * vertexDeclHalfedgeCol_
vertex buffer layout declaration with per halfedge colors
VertexDeclaration * vertexDeclEdgeCol_
vertex buffer layout declaration with per edge colors
Interface class between scenegraph and renderer.
const void * propDataPtr_
memory address of property data
int halfedgeNormalMode_
per vertex / halfedge normals mode toggle: 0: per vertex, 1: per halfedge
int curVBOColorMode_
Color Mode of vbo.
std::vector< VertexProperty > additionalElements_
additional optional elements
ACG::Vec4uc * pickEdgeColorBuffer()
get a pointer to the per edge picking color buffer
ACG::Vec4uc * pickFaceColorBuffer()
get a pointer to the per face picking color buffer
int bVBOinHalfedgeNormalMode_
normals in VBO currently in per vertex / halfedge mode toggle