53 #include <OpenMesh/Core/Utils/Property.hh> 54 #include <OpenMesh/Core/Utils/color_cast.hh> 56 #include <OpenMesh/Core/Mesh/DefaultTriMesh.hh> 57 #include <OpenMesh/Core/Mesh/DefaultPolyMesh.hh> 59 #include <ACG/GL/globjects.hh> 60 #include <ACG/GL/GLState.hh> 61 #include <ACG/GL/IRenderer.hh> 62 #include <ACG/GL/MeshCompiler.hh> 63 #include <ACG/ShaderUtils/GLSLShader.hh> 65 #include <ACG/Config/ACGDefines.hh> 91 void bindPickVertexIbo();
93 void createIndexBuffer();
94 void fillLineBuffer(
size_t n_edges,
void *data);
95 void fillHEVBO(
size_t numberOfElements_,
size_t sizeOfElements_,
void* data_);
96 void fillVertexBuffer();
97 void fillInvVertexMap(
size_t n_vertices,
void *data);
100 size_t getNumTris()
const {
return numTris_; }
101 size_t getNumVerts()
const {
return numVerts_; }
106 unsigned int getNumSubsets()
const {
return meshComp_->
getNumSubsets();}
122 size_t numTris_, numVerts_;
170 template <
class Mesh>
178 unsigned long startIndex;
179 unsigned long numTris;
182 enum REBUILD_TYPE {REBUILD_NONE = 0, REBUILD_FULL = 1, REBUILD_GEOMETRY = 2, REBUILD_TOPOLOGY = 4, REBUILD_TEXTURES = 8};
190 void disableColors() {colorMode_ = 0;}
191 void usePerVertexColors() {colorMode_ = 1;}
192 void usePerFaceColors() {colorMode_ = 2;}
194 void setFlatShading() {flatMode_ = 1;}
195 void setSmoothShading() {flatMode_ = 0;}
197 void usePerVertexTexcoords() {textureMode_ = 0;}
198 void usePerHalfedgeTexcoords() {textureMode_ = 1;}
199 void usePerVertexNormals() {halfedgeNormalMode_ = 0;}
200 void usePerHalfedgeNormals() {halfedgeNormalMode_ = 1;}
228 unsigned int mapVertexToVBOIndex(
unsigned int _v);
237 void unbindBuffers();
244 void draw(std::map< int, GLuint>* _textureMap,
bool _nonindexed =
false);
254 void addTriRenderObjects(
IRenderer* _renderer,
const RenderObject* _baseObj, std::map< int, GLuint>* _textureMap,
bool _nonindexed =
false);
278 unsigned int getMemoryUsage(
bool _printReport =
false);
304 unsigned int getNumTextures();
314 void setTextureIndexPropertyName( std::string _indexPropertyName );
330 void setPerFaceTextureCoordinatePropertyName( std::string _perFaceTextureCoordinatePropertyName );
338 int perFaceTextureCoordinateAvailable();
347 int perFaceTextureIndexAvailable();
352 PROPERTY_SOURCE_VERTEX = 0,
353 PROPERTY_SOURCE_HALFEDGE,
354 PROPERTY_SOURCE_FACE,
362 void addVertexElement(
const std::string& _propertyName, PropertySource _source = PROPERTY_SOURCE_VERTEX );
374 bool scanVertexShaderForInput(
const std::string& _vertexShaderFile );
392 void readVertex(
size_t _vertex,
394 const typename Mesh::HalfedgeHandle& _hh,
395 const typename Mesh::FaceHandle& _fh);
407 unsigned int getFaceColor(
const typename Mesh::FaceHandle& _fh);
412 void updateGPUBuffers();
427 void createVertexDeclaration();
439 void updatePickingVertices(
ACG::GLState& _state , uint _offset = 0);
450 if ( !pickVertColBuf_.empty() )
451 return &(pickVertColBuf_)[0];
453 std::cerr <<
"Illegal request to pickVertexColorBuffer when buffer is empty!" << std::endl;
467 if ( !pickVertBuf_.empty() )
468 return &(pickVertBuf_)[0];
470 std::cerr <<
"Illegal request to pickVertexBuffer when buffer is empty!" << std::endl;
481 void drawPickingVertices_opt(
const GLMatrixf& _mvp,
size_t _pickOffset);
487 bool supportsPickingVertices_opt();
497 if ( pickVertexMapTBO_.is_valid() )
498 return &pickVertexMapTBO_;
500 std::cerr <<
"Illegal request to pickVertexMap_opt when buffer is empty!" << std::endl;
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,
size_t _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,
size_t _pickOffset);
637 bool supportsPickingFaces_opt();
647 if ( pickFaceTriToFaceMapTBO_.is_valid() )
648 return &pickFaceTriToFaceMapTBO_;
650 std::cerr <<
"Illegal request to pickFaceTriangleMap_opt when buffer is empty!" << std::endl;
658 std::vector< ACG::Vec3f > pickFaceVertexBuf_;
659 std::vector< ACG::Vec4uc > pickFaceColBuf_;
686 if ( !pickAnyFaceColBuf_.empty() )
687 return &(pickAnyFaceColBuf_)[0];
689 std::cerr <<
"Illegal request to pickAnyFaceColorBuffer when buffer is empty!" << std::endl;
703 if ( !pickAnyEdgeColBuf_.empty() )
704 return &(pickAnyEdgeColBuf_)[0];
706 std::cerr <<
"Illegal request to pickAnyEdgeColorBuffer when buffer is empty!" << std::endl;
720 if ( !pickAnyVertexColBuf_.empty() )
721 return &(pickAnyVertexColBuf_)[0];
723 std::cerr <<
"Illegal request to pickAnyVertexColorBuffer when buffer is empty!" << std::endl;
733 void drawPickingAny_opt(
const GLMatrixf& _mvp,
size_t _pickOffset);
738 bool supportsPickingAny_opt();
748 std::vector< ACG::Vec4uc > pickAnyFaceColBuf_;
749 std::vector< ACG::Vec4uc > pickAnyEdgeColBuf_;
750 std::vector< ACG::Vec4uc > pickAnyVertexColBuf_;
767 unsigned int countTris(
unsigned int* _pOutMaxPolyVerts = 0,
unsigned int* _pOutNumIndices = 0);
776 int getTextureIDofTri(
unsigned int _tri);
783 int getTextureIDofFace(
unsigned int _face);
793 const void* getMeshPropertyType(
OpenMesh::BaseProperty* _prop, GLuint* _outType,
unsigned int* _outSize)
const;
814 void dumpObj(
const char* _filename)
const;
873 PropertySource source_;
928 void writeVertexElement(
void* _dstBuf,
size_t _vertex,
size_t _stride,
size_t _elementOffset,
size_t _elementSize,
const void* _elementData);
930 void writePosition(
size_t _vertex,
const ACG::Vec3d& _p);
932 void writeNormal(
size_t _vertex,
const ACG::Vec3d& _n);
934 void writeTexcoord(
size_t _vertex,
const ACG::Vec2f& _uv);
936 void writeColor(
size_t _vertex,
unsigned int _color);
948 void readVertexFromVBO(
unsigned int _vertex,
void* _dst);
962 void invalidateFullVBO();
969 void updateFullVBO();
975 GeometryBuffer vboFull_;
981 GeometryBuffer vboEdges_;
999 void updatePerEdgeBuffers();
1003 void updatePerEdgeBuffersNew();
1028 template<
typename Mesh::Normal (DrawMeshT::*NormalLookup)(
typename Mesh::FaceHandle)>
1029 void updatePerHalfedgeBuffers();
1046 void updateEdgeHalfedgeVertexDeclarations();
1063 int updatePerEdgeBuffers_;
1064 std::vector<ACG::Vec3f> perEdgeVertexBuf_;
1065 std::vector<ACG::Vec4f> perEdgeColorBuf_;
1067 std::vector<float> perEdgeBuf_;
1069 int updatePerHalfedgeBuffers_;
1070 std::vector<ACG::Vec3f> perHalfedgeVertexBuf_;
1071 std::vector<ACG::Vec4f> perHalfedgeColorBuf_;
1080 template<
typename Mesh::Normal (DrawMeshT::*NormalLookup)(
typename Mesh::FaceHandle)>
1081 typename Mesh::Point halfedge_point(
const typename Mesh::HalfedgeHandle _heh);
1084 typename Mesh::Normal cachedNormalLookup(
typename Mesh::FaceHandle fh) {
1085 return mesh_.normal(fh);
1089 typename Mesh::Normal computedTriMeshNormal(
typename Mesh::FaceHandle fh) {
1090 typename Mesh::FVIter fv_iter = mesh_.fv_begin(fh);
1091 const typename Mesh::Point p1 = mesh_.point(*fv_iter);
1092 const typename Mesh::Point p2 = mesh_.point(*(++fv_iter));
1093 const typename Mesh::Point p3 = mesh_.point(*(++fv_iter));
1094 return ( p1 + p2 + p3 ) / 3.0;
1098 typename Mesh::Normal computedNormal(
typename Mesh::FaceHandle fh) {
1099 unsigned int count = 0;
1101 for (
typename Mesh::FVIter fv_it = mesh_.fv_begin(fh), fv_end = mesh_.fv_end(fh); fv_it != fv_end; ++fv_it) {
1102 normal += mesh_.point(*fv_it);
1109 typename Mesh::HalfedgeHandle mapToHalfedgeHandle(
size_t _vertexId);
const VertexDeclaration * getHalfedgeColoredVertexDeclaration() const
getter for vertex declarations
GLuint pickVertexIBO_opt()
get an index buffer mapping from openmesh vertices to drawmesh vbo vertices
unsigned int * invVertexMap_
Kernel::Normal Normal
Normal type.
std::vector< ACG::Vec3f > pickVertBuf_
The vertex buffer used for vertex picking.
GLuint heVBO_
vbo for halfedge rendering, as they are offset
Namespace providing different geometric functions concerning angles.
void invalidatePerHalfedgeBuffers()
Update of the buffers.
ACG::Vec4uc * pickFaceColorBuffer()
get a pointer to the per face picking color buffer
VertexElement sourceType_
property type as stored in openmesh
VertexDeclaration * vertexDecl_
vertex buffer layout declaration with per vertex colors
Kernel::Point Point
Coordinate type.
VertexDeclaration * vertexDeclHalfedgeCol_
vertex buffer layout declaration with per halfedge colors
int colorMode_
Color Mode: 0: none, 1: per vertex, else: per face.
Class to define the vertex input layout.
std::string name_
property name in openmesh
GLuint getHEVBO()
getHEVBO get VBO which stores Halfedges with offset
VertexDeclaration * vertexDeclEdgeCol_
vertex buffer layout declaration with per edge colors, legacy path
int flatMode_
flat / smooth shade mode toggle
const std::string & getTextureIndexPropertyName() const
get the name of the texture index property
Mesh & mesh_
OpenMesh object to be rendered.
void updateTopology()
request an update for the mesh topology
int bVBOinFlatMode_
normals in VBO currently in flat / smooth mode
ACG::Vec4uc * pickAnyVertexColorBuffer()
get a pointer to the any picking color buffer
int curVBOColorMode_
Color Mode of vbo.
ACG::Vec3f * pickVertexBuffer()
get a pointer to the per vertex picking vertex buffer
int bVBOinHalfedgeTexMode_
texcoords in VBO currently in per vertex / halfedge mode toggle
const size_t offsetPos_
fixed vertex elements:
int halfedgeNormalMode_
per vertex / halfedge normals mode toggle: 0: per vertex, 1: per halfedge
MeshCompiler * getMeshCompiler()
get mesh compiler used to create the draw mesh
std::vector< VertexProperty > additionalElements_
additional optional elements
int declElementID_
element id in vertex declaration
std::vector< char > vertices_
ACG::Vec4uc * pickAnyFaceColorBuffer()
get a pointer to the any picking color buffer
void updateFull()
request a full rebuild of the mesh
std::string textureIndexPropertyName_
Property for the per face texture index.
VertexDeclaration vertexDeclEdgeNew_
vertex buffer layout declaration with per edge colors
Description of one vertex element.
VertexElement destType_
property type as stored in vbo
ACG::Vec3f * pickFaceVertexBuffer()
get a pointer to the per vertex picking color buffer
int textureMode_
per vertex / halfedge texture mode toggle: 0: per vertex, 1: per halfedge
GLenum getIndexType() const
get index type of index buffer
GLuint lineIBO_
index buffer used in Wireframe / Hiddenline mode
const void * propDataPtr_
memory address of property data
ACG::Vec4uc * pickAnyEdgeColorBuffer()
get a pointer to the any picking color buffer
std::vector< ACG::Vec4uc > pickVertColBuf_
The color buffer used for vertex picking.
unsigned int rebuild_
hint on what to rebuild
GLuint pickVertexIBO_
map from openmesh vertex to vbo vertex id
GLSL::Program * pickFaceShader_
optimized face picking shader
int getNumSubsets() const
Get the number of subsets.
std::string perFaceTextureCoordinatePropertyName_
Property for the per face texture coordinates.
const VertexDeclaration * getHalfedgeVertexDeclaration() const
getter for vertex declarations
ACG::Vec4uc * pickEdgeColorBuffer()
get a pointer to the per edge picking color buffer
const VertexDeclaration * getEdgeColoredVertexDeclaration() const
getter for vertex declarations
void updateTextures()
request an update for the textures
std::string vertexShaderInputName_
input name id in vertex shader
unsigned int * indices_
final index buffer used for rendering
Interface class between scenegraph and renderer.
int bVBOinHalfedgeNormalMode_
normals in VBO currently in per vertex / halfedge mode toggle
GLenum indexType_
support for 2 and 4 byte unsigned integers
void invalidatePerEdgeBuffers()
Update of the buffers.
Kernel::VertexHandle VertexHandle
Handle for referencing the corresponding item.
VertexDeclaration * vertexDeclHalfedgePos_
vertex buffer layout declaration with halfedge positions only
void updateGeometry()
request an update for the mesh vertices
ACG::Vec4uc * pickVertexColorBuffer()
get a pointer to the per vertex picking color buffer