/usr/include/sofa/component/visualmodel/OglAttribute.inl is in libsofa1-dev 1.0~beta4-10ubuntu2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 | /******************************************************************************
* SOFA, Simulation Open-Framework Architecture, version 1.0 beta 4 *
* (c) 2006-2009 MGH, INRIA, USTL, UJF, CNRS *
* *
* This library is free software; you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as published by *
* the Free Software Foundation; either version 2.1 of the License, or (at *
* your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, but WITHOUT *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
* for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with this library; if not, write to the Free Software Foundation, *
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
*******************************************************************************
* SOFA :: Modules *
* *
* Authors: The SOFA Team and external contributors (see Authors.txt) *
* *
* Contact information: contact@sofa-framework.org *
******************************************************************************/
#ifndef _OGL_ATTRIBUTE_INL_
#define _OGL_ATTRIBUTE_INL_
#include <sofa/component/visualmodel/OglAttribute.h>
#include <sofa/component/topology/PointSetTopologyChange.h>
#include <sofa/component/topology/TriangleSetTopologyChange.h>
#include <sofa/component/topology/QuadSetTopologyChange.h>
#include <sofa/component/topology/TetrahedronSetTopologyChange.h>
#include <sofa/component/topology/HexahedronSetTopologyChange.h>
#include <sofa/core/ObjectFactory.h>
namespace sofa
{
namespace component
{
namespace visualmodel
{
using namespace sofa::core::componentmodel::topology;
using namespace sofa::component::topology;
template < int size, unsigned int type, class DataTypes>
OglAttribute< size, type, DataTypes>::OglAttribute() :
OglShaderElement()
, _abo ( -1 )
, usage( GL_STATIC_DRAW)
,value( initData(&value, "value", "internal Data"))
{
_topology = NULL;
}
template < int size, unsigned int type, class DataTypes>
OglAttribute< size, type, DataTypes>::~OglAttribute()
{
glDeleteBuffers(1, &_abo);
}
template < int size, unsigned int type, class DataTypes>
void OglAttribute< size, type, DataTypes>::init()
{
OglShaderElement::init();
getContext()->get( _topology);
if ( ( int ) _abo == -1 ) glGenBuffers ( 1, &_abo );
}
template < int size, unsigned int type, class DataTypes>
void OglAttribute< size, type, DataTypes>::initVisual ()
{
const ResizableExtVector<DataTypes>& data = value.getValue();
unsigned int totalSize = data.size() *sizeof ( data[0] );
glBindBuffer ( GL_ARRAY_BUFFER, _abo );
glBufferData ( GL_ARRAY_BUFFER,
totalSize,
NULL,
usage );
// Fill the buffer
glBufferSubData ( GL_ARRAY_BUFFER,
0,
totalSize,
data.getData() );
_index = shader->getAttribute ( 0, id.getValue().c_str() );
enable();
glBindBuffer(GL_ARRAY_BUFFER,0);
}
template < int size, unsigned int type, class DataTypes>
bool OglAttribute< size, type, DataTypes>::updateABO()
{
GLvoid* attrib_bo = NULL;
glBindBuffer(GL_ARRAY_BUFFER, _abo);
attrib_bo = (GLvoid*) glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY);
if(attrib_bo == NULL)
{
std::cerr << "OglAttribute : Unknown error when updating attribute indices buffer "<< std::endl;
return false;
}
const ResizableExtVector<DataTypes>& val = value.getValue();
memcpy(attrib_bo, &(val[0]), val.size()*sizeof(val[0]));
glUnmapBuffer(GL_ARRAY_BUFFER);
glBindBuffer(GL_ARRAY_BUFFER, 0);
return true;
}
template < int size, unsigned int type, class DataTypes>
ResizableExtVector<DataTypes>* OglAttribute< size, type, DataTypes>::beginEdit()
{
return value.beginEdit();
}
template < int size, unsigned int type, class DataTypes>
void OglAttribute< size, type, DataTypes>::endEdit()
{
value.endEdit();
}
template < int size, unsigned int type, class DataTypes>
const ResizableExtVector<DataTypes>& OglAttribute< size, type, DataTypes>::getValue() const
{
return value.getValue();
}
template < int size, unsigned int type, class DataTypes>
void OglAttribute< size, type, DataTypes>::setValue ( const ResizableExtVector<DataTypes>& value )
{
ResizableExtVector<DataTypes>& val = * ( this->value.beginEdit() );
val = value;
this->value.endEdit();
}
template < int size, unsigned int type, class DataTypes>
void OglAttribute< size, type, DataTypes>::enable()
{
glEnableVertexAttribArray ( _index );
glVertexAttribPointer ( _index, size, type, GL_FALSE, 0, ( char* ) NULL + 0 );
}
template < int size, unsigned int type, class DataTypes>
void OglAttribute< size, type, DataTypes>::disable()
{
glDisableVertexAttribArray ( _index );
}
template < int size, unsigned int type, class DataTypes>
void OglAttribute< size, type, DataTypes>::draw()
{
glEnableVertexAttribArray ( _index );
glVertexAttribPointer ( _index, size, type, GL_FALSE, 0, (void*)(&value.getValue()[0]));
}
template < int size, unsigned int type, class DataTypes>
void OglAttribute< size, type, DataTypes>::reinit()
{
init();
initVisual();
}
// Only resizing and renumbering is done. 'value' has to be set by external components.
template < int size, unsigned int type, class DataTypes>
void OglAttribute< size, type, DataTypes>::handleTopologyChange()
{
if( _topology)
{
std::list<const TopologyChange *>::const_iterator itBegin=_topology->firstChange();
std::list<const TopologyChange *>::const_iterator itEnd=_topology->lastChange();
while( itBegin != itEnd )
{
core::componentmodel::topology::TopologyChangeType changeType = (*itBegin)->getChangeType();
switch( changeType )
{
case core::componentmodel::topology::ENDING_EVENT:
{
//sout << "INFO_print : Vis - ENDING_EVENT" << sendl;
updateVisual();
break;
}
case core::componentmodel::topology::TRIANGLESADDED:
{
//sout << "INFO_print : Vis - TRIANGLESADDED" << sendl;
break;
}
case core::componentmodel::topology::QUADSADDED:
{
//sout << "INFO_print : Vis - QUADSADDED" << sendl;
break;
}
case core::componentmodel::topology::TRIANGLESREMOVED:
{
//sout << "INFO_print : Vis - TRIANGLESREMOVED" << sendl;
break;
}
case core::componentmodel::topology::QUADSREMOVED:
{
//sout << "INFO_print : Vis - QUADSREMOVED" << sendl;
break;
}
case core::componentmodel::topology::POINTSADDED:
{
//sout << "INFO_print : Vis - POINTSADDED" << sendl;
unsigned int nbPoints = ( static_cast< const PointsAdded * >( *itBegin ) )->getNbAddedVertices();
ResizableExtVector<DataTypes>& data = *value.beginEdit();
data.resize( data.size() + nbPoints);
value.endEdit();
break;
}
// Case "POINTSREMOVED" added to propagate the treatment to the Visual Model
case core::componentmodel::topology::POINTSREMOVED:
{
//sout << "INFO_print : Vis - POINTSREMOVED" << sendl;
const sofa::helper::vector<unsigned int> tab = ( static_cast< const sofa::component::topology::PointsRemoved * >( *itBegin ) )->getArray();
ResizableExtVector<DataTypes>& data = *value.beginEdit();
unsigned int last = data.size();
for ( unsigned int i = 0; i < tab.size(); ++i)
{
last--;
data[tab[i]] = data[last];
}
data.resize( last);
value.endEdit();
break;
}
// Case "POINTSRENUMBERING" added to propagate the treatment to the Visual Model
case core::componentmodel::topology::POINTSRENUMBERING:
{
//sout << "INFO_print : Vis - POINTSRENUMBERING" << sendl;
const sofa::helper::vector<unsigned int> tab = ( static_cast< const sofa::component::topology::PointsRenumbering * >( *itBegin ) )->getinv_IndexArray();
ResizableExtVector<DataTypes>& data = *value.beginEdit();
vector<DataTypes> tmp;
for ( unsigned int i = 0; i < tab.size(); ++i)
{
tmp.push_back( data[tab[i]]);
}
for ( unsigned int i = 0; i < tab.size(); ++i)
{
data[i] = tmp[i];
}
value.endEdit();
break;
}
default:
// Ignore events that are not Triangle related.
break;
}; // switch( changeType )
++itBegin;
} // while( changeIt != last; )
}
}
}
}
}
#endif
|