Developer Documentation
DrawMesh.cc
1 /*===========================================================================*\
2  * *
3  * OpenFlipper *
4  * Copyright (c) 2001-2015, RWTH-Aachen University *
5  * Department of Computer Graphics and Multimedia *
6  * All rights reserved. *
7  * www.openflipper.org *
8  * *
9  *---------------------------------------------------------------------------*
10  * This file is part of OpenFlipper. *
11  *---------------------------------------------------------------------------*
12  * *
13  * Redistribution and use in source and binary forms, with or without *
14  * modification, are permitted provided that the following conditions *
15  * are met: *
16  * *
17  * 1. Redistributions of source code must retain the above copyright notice, *
18  * this list of conditions and the following disclaimer. *
19  * *
20  * 2. Redistributions in binary form must reproduce the above copyright *
21  * notice, this list of conditions and the following disclaimer in the *
22  * documentation and/or other materials provided with the distribution. *
23  * *
24  * 3. Neither the name of the copyright holder nor the names of its *
25  * contributors may be used to endorse or promote products derived from *
26  * this software without specific prior written permission. *
27  * *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39  * *
40 \*===========================================================================*/
41 
42 /*===========================================================================*\
43 * *
44 * $Revision$ *
45 * $LastChangedBy$ *
46 * $Date$ *
47 * *
48 \*===========================================================================*/
49 
50 #include <ACG/GL/acg_glew.hh>
51 #include "DrawMesh.hh"
52 
53 namespace ACG {
54 
55 DrawMeshBase::DrawMeshBase() :
56  vbo_(0), ibo_(0),
57  numTris_(0), numVerts_(0),
58  meshComp_(0),
59  lineIBO_(0),
60  indexType_(0),
61  pickVertexIBO_(0) {
62 
63  vertexDecl_ = new VertexDeclaration;
64  vertexDeclEdgeCol_ = new VertexDeclaration;
65  vertexDeclHalfedgeCol_ = new VertexDeclaration;
66  vertexDeclHalfedgePos_ = new VertexDeclaration;
67 }
68 
69 DrawMeshBase::~DrawMeshBase() {
70  if (vbo_) glDeleteBuffersARB(1, &vbo_);
71  if (ibo_) glDeleteBuffersARB(1, &ibo_);
72  if (lineIBO_) glDeleteBuffersARB(1, &lineIBO_);
73 
74  delete vertexDecl_;
75  delete vertexDeclEdgeCol_;
76  delete vertexDeclHalfedgeCol_;
77  delete vertexDeclHalfedgePos_;
78 
79  if (pickVertexIBO_) glDeleteBuffersARB(1, &pickVertexIBO_);
80 }
81 
82 void DrawMeshBase::deleteIbo() {
83  if (ibo_)
84  glDeleteBuffers(1, &ibo_);
85  ibo_ = 0;
86 }
87 
88 void DrawMeshBase::bindVbo() {
89  if (!vbo_)
90  glGenBuffersARB(1, &vbo_);
91 
92  ACG::GLState::bindBufferARB(GL_ARRAY_BUFFER_ARB, vbo_);
93 }
94 
95 void DrawMeshBase::bindIbo() {
96  if (!ibo_)
97  glGenBuffersARB(1, &ibo_);
98 
99  ACG::GLState::bindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, ibo_);
100 }
101 
102 void DrawMeshBase::bindLineIbo() {
103  if (!lineIBO_)
104  glGenBuffersARB(1, &lineIBO_);
105 
106  ACG::GLState::bindBufferARB(GL_ELEMENT_ARRAY_BUFFER, lineIBO_);
107 }
108 
109 void DrawMeshBase::bindPickVertexIbo() {
110  if (!pickVertexIBO_)
111  glGenBuffersARB(1, &pickVertexIBO_);
112 
113  glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, pickVertexIBO_);
114 }
115 
116 void DrawMeshBase::createIndexBuffer() {
117  glBufferDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB,
118  numTris_ * 3 * sizeof(unsigned int),
119  meshComp_->getIndexBuffer(), GL_STATIC_DRAW_ARB);
120 }
121 
122 void DrawMeshBase::fillLineBuffer(size_t n_edges, void *data) {
123  // 2 or 4 byte indices:
124  if (indexType_ == GL_UNSIGNED_SHORT)
125  glBufferDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB,
126  n_edges * 2 * sizeof(unsigned short),
127  data, GL_STATIC_DRAW_ARB);
128  else
129  glBufferDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB,
130  n_edges * 2 * sizeof(unsigned int),
131  data, GL_STATIC_DRAW_ARB);
132 }
133 
134 void DrawMeshBase::fillVertexBuffer() {
135  if (!vertices_.empty())
136  glBufferDataARB(GL_ARRAY_BUFFER_ARB, numVerts_ * vertexDecl_->getVertexStride(), &vertices_[0], GL_STATIC_DRAW_ARB);
137 }
138 
139 void DrawMeshBase::fillInvVertexMap(size_t n_vertices, void *data) {
140  glBufferDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB, sizeof(int) * n_vertices, data, GL_STATIC_DRAW);
141 }
142 
143 } /* namespace ACG */
Namespace providing different geometric functions concerning angles.
Definition: DBSCANT.cc:51
static void bindBufferARB(GLenum _target, GLuint _buffer)
same function as bindBuffer
Definition: GLState.hh:576