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_;
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};
244 void draw(std::map< int, GLuint>* _textureMap,
bool _nonindexed =
false);
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 );
453 std::cerr <<
"Illegal request to pickVertexColorBuffer when buffer is empty!" << std::endl;
470 std::cerr <<
"Illegal request to pickVertexBuffer when buffer is empty!" << std::endl;
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_;
548 if ( !pickEdgeBuf_.empty() )
549 return &(pickEdgeBuf_)[0];
551 std::cerr <<
"Illegal request to pickEdgeColorBuffer when buffer is empty!" << std::endl;
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;
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_;
662 TextureBuffer pickFaceTriToFaceMapTBO_;
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;
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);
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);
975 GeometryBuffer vboFull_;
981 GeometryBuffer vboEdges_;
1028 template<
typename Mesh::Normal (DrawMeshT::*NormalLookup)(
typename Mesh::FaceHandle)>
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)>
1085 return mesh_.normal(fh);
1090 typename Mesh::FVIter fv_iter =
mesh_.fv_begin(fh);
1094 return ( p1 + p2 + p3 ) / 3.0;
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);
1115extern template class DrawMeshT<::OpenMesh::TriMesh>;
1116extern template class DrawMeshT<::OpenMesh::PolyMesh>;
GLenum getIndexType() const
get index type of index buffer
GLuint pickVertexIBO_opt()
get an index buffer mapping from openmesh vertices to drawmesh vbo vertices
GLuint pickVertexIBO_
map from openmesh vertex to vbo vertex id
VertexDeclaration * vertexDeclHalfedgePos_
vertex buffer layout declaration with halfedge positions only
GLenum indexType_
support for 2 and 4 byte unsigned integers
VertexDeclaration vertexDeclEdgeNew_
vertex buffer layout declaration with per edge colors
VertexDeclaration * vertexDeclEdgeCol_
vertex buffer layout declaration with per edge colors, legacy path
VertexDeclaration * vertexDecl_
vertex buffer layout declaration with per vertex colors
VertexDeclaration * vertexDeclHalfedgeCol_
vertex buffer layout declaration with per halfedge colors
GLuint heVBO_
vbo for halfedge rendering, as they are offset
MeshCompiler * getMeshCompiler()
get mesh compiler used to create the draw mesh
std::vector< char > vertices_
GLuint lineIBO_
index buffer used in Wireframe / Hiddenline mode
void updatePickingAny_opt(ACG::GLState &_state)
Update color picking array for the shader implementation.
ACG::Vec4f * perHalfedgeColorBuffer()
get a pointer to the per edge color buffer
void updatePickingAny(ACG::GLState &_state)
Call this function to update the color picking array.
unsigned int countTris(unsigned int *_pOutMaxPolyVerts=0, unsigned int *_pOutNumIndices=0)
Number of triangles after triangulation of the mesh.
VertexDeclaration * getVertexDeclaration()
get vertex declaration of the current vbo layout
int perFaceTextureCoordinateAvailable()
Check if per Face Texture coordinates are available.
ACG::Vec3f * perHalfedgeVertexBuffer()
get a pointer to the per edge vertex buffer
void addLineRenderObjects(IRenderer *_renderer, const RenderObject *_baseObj)
render the mesh in wireframe mode, deferred draw call
const void * testMeshPropertyTypeT(const OpenMesh::BaseProperty *_prop, unsigned int *_outSize) const
test mesh property for type T
void createVertexDeclaration()
creates all vertex declarations needed for deferred draw call renderer
void drawLines()
render the mesh in wireframe mode
ACG::Vec4uc * pickAnyFaceColorBuffer()
get a pointer to the any picking color buffer
ACG::Vec3f * perEdgeVertexBuffer()
get a pointer to the per edge vertex buffer
void updatePickingFaces_opt(ACG::GLState &_state)
Update color picking array for the shader implementation.
int halfedgeNormalMode_
per vertex / halfedge normals mode toggle: 0: per vertex, 1: per halfedge
void drawPickingFaces_opt(const GLMatrixf &_mvp, size_t _pickOffset)
Optimized rendering of face picking ids with a shader.
void drawPickingEdges_opt(const GLMatrixf &_mvp, size_t _pickOffset)
Optimized rendering of edge picking ids with a shader.
ACG::Vec4uc * pickAnyVertexColorBuffer()
get a pointer to the any picking color buffer
void bindBuffers()
eventually rebuilds buffers used for rendering and binds index and vertex buffer
void updateTopology()
request an update for the mesh topology
void drawPickingAny_opt(const GLMatrixf &_mvp, size_t _pickOffset)
Optimized rendering of any picking ids with a shader.
int colorMode_
Color Mode: 0: none, 1: per vertex, else: per face.
void addVertexElement(const std::string &_propertyName, PropertySource _source=PROPERTY_SOURCE_VERTEX)
Add custom elements to the vertex layout.
void updatePickingEdges(ACG::GLState &_state, uint _offset=0)
Update color picking array for edges.
unsigned int getFaceColor(const typename Mesh::FaceHandle &_fh)
return a face color from mesh
unsigned int mapVertexToVBOIndex(unsigned int _v)
map from vertex index of the original mesh point buffer to the corresponding vertex index inside the ...
void updateGPUBuffers()
eventually update vertex and index buffers
const void * getMeshPropertyType(OpenMesh::BaseProperty *_prop, GLuint *_outType, unsigned int *_outSize) const
get the data type of a mesh property
ACG::Vec3f * pickFaceVertexBuffer()
get a pointer to the per vertex picking color buffer
void updateFull()
request a full rebuild of the mesh
void updatePickingEdges_opt(ACG::GLState &_state)
Update color picking array for the shader implementation.
void updatePerHalfedgeBuffers()
Update all per edge drawing buffer n The updated buffers are: per edge vertex buffer ( 2 vertices per...
int getTextureIDofFace(unsigned int _face)
get the texture index of a face
void rebuild()
draw_mesh updater
void updateTextures()
request an update for the textures
void invalidatePerEdgeBuffers()
Update of the buffers.
unsigned int * invVertexMap_
void drawVertices()
render vertices only
int bVBOinHalfedgeTexMode_
texcoords in VBO currently in per vertex / halfedge mode toggle
unsigned int getMemoryUsage(bool _printReport=false)
measures the size in bytes of allocated memory. eventually prints a report to std::cout
const VertexDeclaration * getHalfedgeColoredVertexDeclaration() const
getter for vertex declarations
void invalidateFullVBO()
the mesh has been changed
bool supportsPickingAny_opt()
Check if optimized any picking is supported.
bool supportsPickingVertices_opt()
Check if optimized vertex picking is supported.
void readVertexFromVBO(unsigned int _vertex, void *_dst)
Read one vertex from the rendering vbo.
void setPerFaceTextureCoordinatePropertyName(std::string _perFaceTextureCoordinatePropertyName)
set the name of the property used for texture coordinate
std::vector< ACG::Vec4uc > pickVertColBuf_
The color buffer used for vertex picking.
void setTextureIndexPropertyName(std::string _indexPropertyName)
set the name of the property used for texture index specification
unsigned int rebuild_
hint on what to rebuild
int flatMode_
flat / smooth shade mode toggle
ACG::Vec4uc * pickEdgeColorBuffer()
get a pointer to the per edge picking color buffer
bool supportsPickingEdges_opt()
Check if optimized face picking is supported.
ACG::Vec4f * perEdgeColorBuffer()
get a pointer to the per edge color buffer
unsigned int getVertexColor(const typename Mesh::VertexHandle &_vh)
return a vertex color from mesh
int bVBOinFlatMode_
normals in VBO currently in flat / smooth mode
bool supportsPickingFaces_opt()
Check if optimized face picking is supported.
std::vector< VertexProperty > additionalElements_
additional optional elements
void addTriRenderObjects(IRenderer *_renderer, const RenderObject *_baseObj, std::map< int, GLuint > *_textureMap, bool _nonindexed=false)
adds RenderObjects to a deferred draw call renderer
Mesh::Point halfedge_point(const typename Mesh::HalfedgeHandle _heh)
compute halfedge point compute visualization point for halfedge (shifted to interior of face)
void createVBO()
stores the vertex buffer on the gpu
void readVertex(size_t _vertex, const typename Mesh::VertexHandle &_vh, const typename Mesh::HalfedgeHandle &_hh, const typename Mesh::FaceHandle &_fh)
reads a vertex from mesh_ and write it to vertex buffer
void updateFullVBO()
update the full mesh vbo
unsigned int * indices_
final index buffer used for rendering
GLSL::Program * pickFaceShader_
optimized face picking shader
const VertexDeclaration * getEdgeColoredVertexDeclaration() const
getter for vertex declarations
void drawPickingVertices_opt(const GLMatrixf &_mvp, size_t _pickOffset)
Optimized rendering of vertex picking ids with a shader.
std::vector< ACG::Vec3f > pickVertBuf_
The vertex buffer used for vertex picking.
ACG::Vec4uc * pickAnyEdgeColorBuffer()
get a pointer to the any picking color buffer
void updatePickingVertices(ACG::GLState &_state, uint _offset=0)
GLuint getHEVBO()
getHEVBO get VBO which stores Halfedges with offset
int getTextureIDofTri(unsigned int _tri)
get the texture index of a triangle
const VertexDeclaration * getHalfedgeVertexDeclaration() const
getter for vertex declarations
void invalidatePerHalfedgeBuffers()
Update of the buffers.
void updatePerEdgeBuffersNew()
Update the combined position + color buffer for edge rendering.
const std::string & getTextureIndexPropertyName() const
get the name of the texture index property
void updatePickingVertices_opt(ACG::GLState &_state)
Update color picking array for the shader implementation.
void draw(std::map< int, GLuint > *_textureMap, bool _nonindexed=false)
binds index and vertex buffer and executes draw calls
GLuint getVBO()
get opengl vertex buffer id
ACG::Vec3f * pickVertexBuffer()
get a pointer to the per vertex picking vertex buffer
Mesh & mesh_
OpenMesh object to be rendered.
int perFaceTextureIndexAvailable()
Check if texture indices are available.
void updateGeometry()
request an update for the mesh vertices
bool scanVertexShaderForInput(const std::string &_vertexShaderFile)
Scan vertex layout from vertex shader.
GLuint getIBO()
get opengl index buffer id
ACG::Vec4uc * pickVertexColorBuffer()
get a pointer to the per vertex picking color buffer
void createIBO()
stores the index buffer on the gpu
void updatePickingFaces(ACG::GLState &_state)
Update color picking array for faces.
void addPointRenderObjects(IRenderer *_renderer, const RenderObject *_baseObj)
render vertices only, deferred draw call
void unbindBuffers()
disables vertex, normal, texcoord and color pointers in OpenGL
unsigned int getNumTextures()
returns the number of used textured of this mesh
void bindBuffersToRenderObject(RenderObject *_obj)
eventually rebuilds buffers used for rendering and binds index and vertex buffer
std::string textureIndexPropertyName_
Property for the per face texture index.
int textureMode_
per vertex / halfedge texture mode toggle: 0: per vertex, 1: per halfedge
void updatePerEdgeBuffers()
Update all per edge drawing buffers.
void dumpObj(const char *_filename) const
dump current vertex/index buffer to wavefront obj
int curVBOColorMode_
Color Mode of vbo.
std::string perFaceTextureCoordinatePropertyName_
Property for the per face texture coordinates.
int bVBOinHalfedgeNormalMode_
normals in VBO currently in per vertex / halfedge mode toggle
ACG::Vec4uc * pickFaceColorBuffer()
get a pointer to the per face picking color buffer
const size_t offsetPos_
fixed vertex elements:
void updateEdgeHalfedgeVertexDeclarations()
updates per edge and halfedge vertex declarations
int getNumSubsets() const
Get the number of subsets.
Class to define the vertex input layout.
Kernel::VertexHandle VertexHandle
Handle for referencing the corresponding item.
Kernel::Normal Normal
Normal type.
Kernel::FaceHandle FaceHandle
Scalar type.
Kernel::HalfedgeHandle HalfedgeHandle
Scalar type.
Kernel::Point Point
Coordinate type.
Namespace providing different geometric functions concerning angles.
const void * propDataPtr_
memory address of property data
VertexElement sourceType_
property type as stored in openmesh
std::string vertexShaderInputName_
input name id in vertex shader
VertexElement destType_
property type as stored in vbo
std::string name_
property name in openmesh
int declElementID_
element id in vertex declaration
Interface class between scenegraph and renderer.
Description of one vertex element.