Developer Documentation

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
MeshNode2.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 * $Author$ *
46 * $Date$ *
47 * *
48 \*===========================================================================*/
49
50 #include <ACG/GL/acg_glew.hh>
51 #include "MeshNode2T.hh"
52
53 namespace ACG {
54 namespace SceneGraph {
55
56 MeshNodeBase::MeshNodeBase(BaseNode* _parent, std::string _name) :
57 BaseNode(_parent, _name),
58 drawMeshBase_(0),
59 polyEdgeBuf_(0),
60 polyEdgeBufSize_(0),
61 polyEdgeBufTex_(0) {
62 }
63
64 void MeshNodeBase::supplyDrawMesh(DrawMeshBase *drawMeshBase) {
65 /*
66 * We take the luxury of checking these conditions even in release
67 * mode as this method is rarely called.
68 */
69 if (drawMeshBase_)
70 throw std::runtime_error("MeshNodeBase::supplyDrawMesh called "
71 "more than once.");
72 if (!drawMeshBase)
73 throw std::runtime_error("MeshNodeBase::supplyDrawMesh called "
74 "with NULL parameter.");
75
76 drawMeshBase_ = drawMeshBase;
77 }
78
79 void MeshNodeBase::updatePolyEdgeBuf()
80 {
81
82 #ifdef GL_ARB_texture_buffer_object
83 // drawMeshBase_ must have been supplied.
84 assert(drawMeshBase_);
85
86 MeshCompiler * const mc = drawMeshBase_->getMeshCompiler();
87 if (mc && !mc->isTriangleMesh())
88 {
89 // create/update the poly-edge buffer
90 if (!polyEdgeBuf_)
91 glGenBuffers(1, &polyEdgeBuf_);
92
93 const int nTris = mc->getNumTriangles();
94
95 const int newBufSize = (nTris/2+1);
96
97 if (polyEdgeBufSize_ != newBufSize)
98 {
99 glBindBuffer(GL_TEXTURE_BUFFER, polyEdgeBuf_);
100
101 // The poly-edge buffer is a texture buffer that stores one byte for each triangle, which encodes triangle edge properties.
102 // An inner edge is an edge that was added during the triangulation of a n-poly,
103 // whereas outer edges are edges that already exist in the input mesh object.
104 // This information is used in the wireframe/hiddenline geometry shader to identify edges, which should not be rendered.
105 // Buffer storage:
106 // each triangle uses 3 bits to mark edges as visible or hidden
107 // outer edge -> bit = 1 (visible)
108 // inner edge -> bit = 0 (hidden)
109 // each byte can store edges for two triangles and the remaining 2 bits are left unused
110
111 polyEdgeBufSize_ = newBufSize;
112 unsigned char* polyEdgeBufData = new unsigned char[newBufSize];
113
114 // set zero
115 memset(polyEdgeBufData, 0, newBufSize);
116
117 // build buffer
118 for (int i = 0; i < nTris; ++i)
119 {
120 int byteidx = i>>1;
121 int bitidx = (i&1) * 3;
122
123 for (int k = 0; k < 3; ++k)
124 if (mc->isFaceEdge(i, k))
125 polyEdgeBufData[byteidx] += 1 << (k + bitidx);
126 }
127
128 glBufferData(GL_TEXTURE_BUFFER, polyEdgeBufSize_, polyEdgeBufData, GL_STATIC_DRAW);
129
130
131 delete [] polyEdgeBufData;
132 polyEdgeBufData = 0;
133
134 // create texture object for the texture buffer
135
136 if (!polyEdgeBufTex_)
137 {
138 glGenTextures(1, &polyEdgeBufTex_);
139
140 glActiveTexture(GL_TEXTURE0);
141 glBindTexture(GL_TEXTURE_BUFFER, polyEdgeBufTex_);
142 glTexBuffer(GL_TEXTURE_BUFFER, GL_R8UI, polyEdgeBuf_);
143
144 glBindTexture(GL_TEXTURE_2D, 0);
145 }
146
147 ACG::glCheckErrors();
148 }
149 }
150 #endif
151 }
152
153
154 } /* namespace SceneGraph */
155 } /* namespace ACG */
ACG
Namespace providing different geometric functions concerning angles.
Definition: DBSCANT.cc:51
ACG::SceneGraph::BaseNode
Definition: BaseNode.hh:135
ACG::DrawMeshBase::getMeshCompiler
MeshCompiler * getMeshCompiler()
get mesh compiler used to create the draw mesh
Definition: DrawMesh.hh:113
ACG::glCheckErrors
void glCheckErrors()
Definition: GLError.hh:105