Commit 90de19aa authored by Martin Schultz's avatar Martin Schultz

added halfedge vbo to DrawMesh for rendering halfedges with offset

parent 498b200a
......@@ -57,6 +57,7 @@ DrawMeshBase::DrawMeshBase() :
numTris_(0), numVerts_(0),
meshComp_(0),
lineIBO_(0),
heVBO_(0),
indexType_(0),
pickVertexIBO_(0) {
......@@ -70,6 +71,7 @@ DrawMeshBase::~DrawMeshBase() {
if (vbo_) glDeleteBuffersARB(1, &vbo_);
if (ibo_) glDeleteBuffersARB(1, &ibo_);
if (lineIBO_) glDeleteBuffersARB(1, &lineIBO_);
if (heVBO_) glDeleteBuffersARB(1, &heVBO_);
delete vertexDecl_;
delete vertexDeclEdgeCol_;
......@@ -106,6 +108,18 @@ void DrawMeshBase::bindLineIbo() {
ACG::GLState::bindBufferARB(GL_ELEMENT_ARRAY_BUFFER, lineIBO_);
}
void DrawMeshBase::bindHEVbo() {
glGetIntegerv(GL_ARRAY_BUFFER_BINDING,&prevVBO_);
if (!heVBO_)
glGenBuffersARB(1, &heVBO_);
ACG::GLState::bindBufferARB(GL_ARRAY_BUFFER_ARB, heVBO_);
}
void DrawMeshBase::unbindHEVbo() {
ACG::GLState::bindBufferARB(GL_ARRAY_BUFFER_ARB, prevVBO_);
}
void DrawMeshBase::bindPickVertexIbo() {
if (!pickVertexIBO_)
glGenBuffersARB(1, &pickVertexIBO_);
......@@ -131,6 +145,13 @@ void DrawMeshBase::fillLineBuffer(size_t n_edges, void *data) {
data, GL_STATIC_DRAW_ARB);
}
void DrawMeshBase::fillHEVBO(size_t numberOfElements_, size_t sizeOfElements_, void* data_)
{
bindHEVbo();
glBufferData(GL_ARRAY_BUFFER,numberOfElements_ * sizeOfElements_, data_, GL_STATIC_DRAW);
unbindHEVbo();
}
void DrawMeshBase::fillVertexBuffer() {
if (!vertices_.empty())
glBufferDataARB(GL_ARRAY_BUFFER_ARB, numVerts_ * vertexDecl_->getVertexStride(), &vertices_[0], GL_STATIC_DRAW_ARB);
......
......@@ -97,10 +97,13 @@ class ACGDLLEXPORT DrawMeshBase {
void bindVbo();
void bindIbo();
void bindLineIbo();
void bindHEVbo();
void unbindHEVbo();
void bindPickVertexIbo();
void createIndexBuffer();
void fillLineBuffer(size_t n_edges, void *data);
void fillHEVBO(size_t numberOfElements_, size_t sizeOfElements_, void* data_);
void fillVertexBuffer();
void fillInvVertexMap(size_t n_vertices, void *data);
......@@ -132,6 +135,10 @@ class ACGDLLEXPORT DrawMeshBase {
/// index buffer used in Wireframe / Hiddenline mode
GLuint lineIBO_;
/// vbo for halfedge rendering, as they are offset
GLuint heVBO_;
//previously bound buffer
GLint prevVBO_;
/// support for 2 and 4 byte unsigned integers
GLenum indexType_;
......@@ -212,6 +219,11 @@ public:
*/
GLuint getIBO();
/**
* @brief getHEVBO get VBO which stores Halfedges with offset
* @return GLuint the VBO
*/
GLuint getHEVBO(){return heVBO_;}
/** \brief get vertex declaration of the current vbo layout
*/
......
......@@ -1835,10 +1835,19 @@ void DrawMeshT<Mesh>::updatePerHalfedgeBuffers()
perHalfedgeColorBuf_[ idx ] = color;
perHalfedgeColorBuf_[ idx + 1 ] = color;
}
idx += 2;
}
if(perHalfedgeVertexBuf_.size() > 0)
{
//create buffers if necessary and bind them
bindHEVbo();
//fill buffer with data
fillHEVBO(perHalfedgeVertexBuf_.size(), sizeof(perHalfedgeVertexBuf_[0]), perHalfedgeVertexBuf_.data());
// rebind the previous buffers
unbindHEVbo();
}
updatePerHalfedgeBuffers_ = 0;
updateEdgeHalfedgeVertexDeclarations();
......
......@@ -107,7 +107,7 @@ public:
protected:
//index buffer objects ,previously direct ram access was used in compat
//now use ibos on both compat and core profile.
//now use ibos / vbos on both compat and core profile.
GLuint heVBO_, eIBO_, fIBO_, vIBO_, pIBO_;
void updateIBOData(GLuint& bufferName_, size_t numberOfElements_, size_t sizeOfElements_, void* data_);
......
Markdown is supported
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