53 #ifndef ACG_DRAW_MESH_HH 54 #define ACG_DRAW_MESH_HH 61 #include <OpenMesh/Core/Utils/Property.hh> 62 #include <OpenMesh/Core/Utils/color_cast.hh> 64 #include <ACG/GL/globjects.hh> 65 #include <ACG/GL/GLState.hh> 66 #include <ACG/GL/IRenderer.hh> 67 #include <ACG/GL/MeshCompiler.hh> 68 #include <ACG/ShaderUtils/GLSLShader.hh> 70 #include <ACG/Config/ACGDefines.hh> 96 void bindPickVertexIbo();
98 void createIndexBuffer();
99 void fillLineBuffer(
size_t n_edges,
void *data);
100 void fillHEVBO(
size_t numberOfElements_,
size_t sizeOfElements_,
void* data_);
101 void fillVertexBuffer();
102 void fillInvVertexMap(
size_t n_vertices,
void *data);
105 size_t getNumTris()
const {
return numTris_; }
106 size_t getNumVerts()
const {
return numVerts_; }
111 unsigned int getNumSubsets()
const {
return meshComp_->
getNumSubsets();}
127 size_t numTris_, numVerts_;
172 template <
class Mesh>
180 unsigned long startIndex;
181 unsigned long numTris;
184 enum REBUILD_TYPE {REBUILD_NONE = 0, REBUILD_FULL = 1, REBUILD_GEOMETRY = 2, REBUILD_TOPOLOGY = 4, REBUILD_TEXTURES = 8};
192 void disableColors() {colorMode_ = 0;}
193 void usePerVertexColors() {colorMode_ = 1;}
194 void usePerFaceColors() {colorMode_ = 2;}
196 void setFlatShading() {flatMode_ = 1;}
197 void setSmoothShading() {flatMode_ = 0;}
199 void usePerVertexTexcoords() {textureMode_ = 0;}
200 void usePerHalfedgeTexcoords() {textureMode_ = 1;}
201 void usePerVertexNormals() {halfedgeNormalMode_ = 0;}
202 void usePerHalfedgeNormals() {halfedgeNormalMode_ = 1;}
230 unsigned int mapVertexToVBOIndex(
unsigned int _v);
239 void unbindBuffers();
246 void draw(std::map< int, GLuint>* _textureMap,
bool _nonindexed =
false);
256 void addTriRenderObjects(
IRenderer* _renderer,
const RenderObject* _baseObj, std::map< int, GLuint>* _textureMap,
bool _nonindexed =
false);
280 unsigned int getMemoryUsage(
bool _printReport =
false);
306 unsigned int getNumTextures();
316 void setTextureIndexPropertyName( std::string _indexPropertyName );
332 void setPerFaceTextureCoordinatePropertyName( std::string _perFaceTextureCoordinatePropertyName );
340 int perFaceTextureCoordinateAvailable();
349 int perFaceTextureIndexAvailable();
354 PROPERTY_SOURCE_VERTEX = 0,
355 PROPERTY_SOURCE_HALFEDGE,
356 PROPERTY_SOURCE_FACE,
364 void addVertexElement(
const std::string& _propertyName, PropertySource _source = PROPERTY_SOURCE_VERTEX );
376 bool scanVertexShaderForInput(
const std::string& _vertexShaderFile );
394 void readVertex(
size_t _vertex,
396 const typename Mesh::HalfedgeHandle& _hh,
397 const typename Mesh::FaceHandle& _fh);
409 unsigned int getFaceColor(
const typename Mesh::FaceHandle& _fh);
414 void updateGPUBuffers();
429 void createVertexDeclaration();
441 void updatePickingVertices(
ACG::GLState& _state , uint _offset = 0);
452 if ( !pickVertColBuf_.empty() )
453 return &(pickVertColBuf_)[0];
455 std::cerr <<
"Illegal request to pickVertexColorBuffer when buffer is empty!" << std::endl;
469 if ( !pickVertBuf_.empty() )
470 return &(pickVertBuf_)[0];
472 std::cerr <<
"Illegal request to pickVertexBuffer when buffer is empty!" << std::endl;
483 void drawPickingVertices_opt(
const GLMatrixf& _mvp,
size_t _pickOffset);
489 bool supportsPickingVertices_opt();
499 if ( pickVertexMapTBO_.is_valid() )
500 return &pickVertexMapTBO_;
502 std::cerr <<
"Illegal request to pickVertexMap_opt when buffer is empty!" << std::endl;
526 int pickVertexMethod_;
539 void updatePickingEdges(
ACG::GLState& _state , uint _offset = 0 );
550 if ( !pickEdgeBuf_.empty() )
551 return &(pickEdgeBuf_)[0];
553 std::cerr <<
"Illegal request to pickEdgeColorBuffer when buffer is empty!" << std::endl;
564 void drawPickingEdges_opt(
const GLMatrixf& _mvp,
size_t _pickOffset);
570 bool supportsPickingEdges_opt();
580 std::vector< ACG::Vec4uc > pickEdgeBuf_;
603 if ( !pickFaceColBuf_.empty() )
604 return &(pickFaceColBuf_)[0];
606 std::cerr <<
"Illegal request to pickFaceColorBuffer when buffer is empty!" << std::endl;
620 if ( !pickFaceVertexBuf_.empty() )
621 return &(pickFaceVertexBuf_)[0];
623 std::cerr <<
"Illegal request to pickFaceVertexBuffer when buffer is empty!" << std::endl;
633 void drawPickingFaces_opt(
const GLMatrixf& _mvp,
size_t _pickOffset);
639 bool supportsPickingFaces_opt();
649 if ( pickFaceTriToFaceMapTBO_.is_valid() )
650 return &pickFaceTriToFaceMapTBO_;
652 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_;
688 if ( !pickAnyFaceColBuf_.empty() )
689 return &(pickAnyFaceColBuf_)[0];
691 std::cerr <<
"Illegal request to pickAnyFaceColorBuffer when buffer is empty!" << std::endl;
705 if ( !pickAnyEdgeColBuf_.empty() )
706 return &(pickAnyEdgeColBuf_)[0];
708 std::cerr <<
"Illegal request to pickAnyEdgeColorBuffer when buffer is empty!" << std::endl;
722 if ( !pickAnyVertexColBuf_.empty() )
723 return &(pickAnyVertexColBuf_)[0];
725 std::cerr <<
"Illegal request to pickAnyVertexColorBuffer when buffer is empty!" << std::endl;
735 void drawPickingAny_opt(
const GLMatrixf& _mvp,
size_t _pickOffset);
740 bool supportsPickingAny_opt();
750 std::vector< ACG::Vec4uc > pickAnyFaceColBuf_;
751 std::vector< ACG::Vec4uc > pickAnyEdgeColBuf_;
752 std::vector< ACG::Vec4uc > pickAnyVertexColBuf_;
769 unsigned int countTris(
unsigned int* _pOutMaxPolyVerts = 0,
unsigned int* _pOutNumIndices = 0);
778 int getTextureIDofTri(
unsigned int _tri);
785 int getTextureIDofFace(
unsigned int _face);
795 const void* getMeshPropertyType(
OpenMesh::BaseProperty* _prop, GLuint* _outType,
unsigned int* _outSize)
const;
816 void dumpObj(
const char* _filename)
const;
875 PropertySource source_;
930 void writeVertexElement(
void* _dstBuf,
size_t _vertex,
size_t _stride,
size_t _elementOffset,
size_t _elementSize,
const void* _elementData);
932 void writePosition(
size_t _vertex,
const ACG::Vec3d& _p);
934 void writeNormal(
size_t _vertex,
const ACG::Vec3d& _n);
936 void writeTexcoord(
size_t _vertex,
const ACG::Vec2f& _uv);
938 void writeColor(
size_t _vertex,
unsigned int _color);
950 void readVertexFromVBO(
unsigned int _vertex,
void* _dst);
964 void invalidateFullVBO();
971 void updateFullVBO();
977 GeometryBuffer vboFull_;
1000 void updatePerEdgeBuffers();
1025 template<
typename Mesh::Normal (DrawMeshT::*NormalLookup)(
typename Mesh::FaceHandle)>
1026 void updatePerHalfedgeBuffers();
1043 void updateEdgeHalfedgeVertexDeclarations();
1060 int updatePerEdgeBuffers_;
1061 std::vector<ACG::Vec3f> perEdgeVertexBuf_;
1062 std::vector<ACG::Vec4f> perEdgeColorBuf_;
1064 int updatePerHalfedgeBuffers_;
1065 std::vector<ACG::Vec3f> perHalfedgeVertexBuf_;
1066 std::vector<ACG::Vec4f> perHalfedgeColorBuf_;
1075 template<
typename Mesh::Normal (DrawMeshT::*NormalLookup)(
typename Mesh::FaceHandle)>
1076 typename Mesh::Point halfedge_point(
const typename Mesh::HalfedgeHandle _heh);
1079 typename Mesh::Normal cachedNormalLookup(
typename Mesh::FaceHandle fh) {
1080 return mesh_.normal(fh);
1084 typename Mesh::Normal computedTriMeshNormal(
typename Mesh::FaceHandle fh) {
1085 typename Mesh::FVIter fv_iter = mesh_.fv_begin(fh);
1086 const typename Mesh::Point p1 = mesh_.point(*fv_iter);
1087 const typename Mesh::Point p2 = mesh_.point(*(++fv_iter));
1088 const typename Mesh::Point p3 = mesh_.point(*(++fv_iter));
1089 return ( p1 + p2 + p3 ) / 3.0;
1093 typename Mesh::Normal computedNormal(
typename Mesh::FaceHandle fh) {
1094 unsigned int count = 0;
1096 for (
typename Mesh::FVIter fv_it = mesh_.fv_begin(fh), fv_end = mesh_.fv_end(fh); fv_it != fv_end; ++fv_it) {
1097 normal += mesh_.point(*fv_it);
1104 typename Mesh::HalfedgeHandle mapToHalfedgeHandle(
size_t _vertexId);
1112 #if defined(INCLUDE_TEMPLATES) && !defined(ACG_DRAW_MESH_TCC) 1113 #define ACG_DRAW_MESH_TEMPLATES 1114 #include "DrawMeshT_impl.hh" 1117 #endif // ACG_DRAW_MESH_HH defined
Namespace providing different geometric functions concerning angles.
ACG::Vec4uc * pickFaceColorBuffer()
get a pointer to the per face picking color buffer
Class to define the vertex input layout.
unsigned int * indices_
final index buffer used for rendering
std::string textureIndexPropertyName_
Property for the per face texture index.
Kernel::Point Point
Coordinate type.
int textureMode_
per vertex / halfedge texture mode toggle: 0: per vertex, 1: per halfedge
int curVBOColorMode_
Color Mode of vbo.
const VertexDeclaration * getHalfedgeVertexDeclaration() const
getter for vertex declarations
void updateFull()
request a full rebuild of the mesh
std::vector< char > vertices_
ACG::Vec4uc * pickEdgeColorBuffer()
get a pointer to the per edge picking color buffer
GLuint heVBO_
vbo for halfedge rendering, as they are offset
void invalidatePerHalfedgeBuffers()
Update of the buffers.
GLSL::Program * pickFaceShader_
optimized face picking shader
GLuint pickVertexIBO_
map from openmesh vertex to vbo vertex id
std::string perFaceTextureCoordinatePropertyName_
Property for the per face texture coordinates.
const VertexDeclaration * getEdgeColoredVertexDeclaration() const
getter for vertex declarations
GLuint lineIBO_
index buffer used in Wireframe / Hiddenline mode
Interface class between scenegraph and renderer.
Kernel::VertexHandle VertexHandle
Handle for referencing the corresponding item.
int declElementID_
element id in vertex declaration
int colorMode_
Color Mode: 0: none, 1: per vertex, else: per face.
VertexDeclaration * vertexDeclEdgeCol_
vertex buffer layout declaration with per edge colors
void updateGeometry()
request an update for the mesh vertices
std::string name_
property name in openmesh
std::vector< ACG::Vec3f > pickVertBuf_
The vertex buffer used for vertex picking.
int halfedgeNormalMode_
per vertex / halfedge normals mode toggle: 0: per vertex, 1: per halfedge
unsigned int * invVertexMap_
unsigned int rebuild_
hint on what to rebuild
VertexElement destType_
property type as stored in vbo
VertexElement sourceType_
property type as stored in openmesh
void updateTextures()
request an update for the textures
int bVBOinFlatMode_
normals in VBO currently in flat / smooth mode
const VertexDeclaration * getHalfedgeColoredVertexDeclaration() const
getter for vertex declarations
Kernel::Normal Normal
Normal type.
GLuint getHEVBO()
getHEVBO get VBO which stores Halfedges with offset
ACG::Vec4uc * pickVertexColorBuffer()
get a pointer to the per vertex picking color buffer
std::vector< ACG::Vec4uc > pickVertColBuf_
The color buffer used for vertex picking.
Description of one vertex element.
int bVBOinHalfedgeTexMode_
texcoords in VBO currently in per vertex / halfedge mode toggle
int flatMode_
flat / smooth shade mode toggle
int bVBOinHalfedgeNormalMode_
normals in VBO currently in per vertex / halfedge mode toggle
const std::string & getTextureIndexPropertyName() const
get the name of the texture index property
Mesh & mesh_
OpenMesh object to be rendered.
VertexDeclaration * vertexDecl_
vertex buffer layout declaration with per vertex colors
MeshCompiler * getMeshCompiler()
get mesh compiler used to create the draw mesh
GLenum indexType_
support for 2 and 4 byte unsigned integers
ACG::Vec3f * pickFaceVertexBuffer()
get a pointer to the per vertex picking color buffer
const void * propDataPtr_
memory address of property data
ACG::Vec3f * pickVertexBuffer()
get a pointer to the per vertex picking vertex buffer
std::vector< VertexProperty > additionalElements_
additional optional elements
ACG::Vec4uc * pickAnyEdgeColorBuffer()
get a pointer to the any picking color buffer
ACG::Vec4uc * pickAnyFaceColorBuffer()
get a pointer to the any picking color buffer
int getNumSubsets() const
Get the number of subsets.
const size_t offsetPos_
fixed vertex elements:
ACG::Vec4uc * pickAnyVertexColorBuffer()
get a pointer to the any picking color buffer
VertexDeclaration * vertexDeclHalfedgeCol_
vertex buffer layout declaration with per halfedge colors
VertexDeclaration * vertexDeclHalfedgePos_
vertex buffer layout declaration with halfedge positions only
GLuint pickVertexIBO_opt()
get an index buffer mapping from openmesh vertices to drawmesh vbo vertices
void invalidatePerEdgeBuffers()
Update of the buffers.
std::string vertexShaderInputName_
input name id in vertex shader
void updateTopology()
request an update for the mesh topology
GLenum getIndexType() const
get index type of index buffer