fixed: auto_ptr -> unique_ptr
[opensg.git] / Source / System / NodeCores / Drawables / Geometry / PropertiesBase / OSGGeoVectorProperty.cpp
blob9ef12662e1aa13623726bc2a6e5fbdf58223b642
1 /*---------------------------------------------------------------------------*\
2 * OpenSG *
3 * *
4 * *
5 * Copyright (C) 2000-2002 by the OpenSG Forum *
6 * *
7 * www.opensg.org *
8 * *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
10 * *
11 \*---------------------------------------------------------------------------*/
12 /*---------------------------------------------------------------------------*\
13 * License *
14 * *
15 * This library is free software; you can redistribute it and/or modify it *
16 * under the terms of the GNU Library General Public License as published *
17 * by the Free Software Foundation, version 2. *
18 * *
19 * This library is distributed in the hope that it will be useful, but *
20 * WITHOUT ANY WARRANTY; without even the implied warranty of *
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
22 * Library General Public License for more details. *
23 * *
24 * You should have received a copy of the GNU Library General Public *
25 * License along with this library; if not, write to the Free Software *
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
27 * *
28 \*---------------------------------------------------------------------------*/
29 /*---------------------------------------------------------------------------*\
30 * Changes *
31 * *
32 * *
33 * *
34 * *
35 * *
36 * *
37 \*---------------------------------------------------------------------------*/
39 //---------------------------------------------------------------------------
40 // Includes
41 //---------------------------------------------------------------------------
43 #include <cstdlib>
44 #include <cstdio>
46 #include "OSGConfig.h"
48 #include "OSGGLEXT.h"
49 #include "OSGWindow.h"
50 #include "OSGGeoVectorProperty.h"
51 #include "OSGDrawEnv.h"
53 #include "OSGGLFuncProtos.h"
55 #include "OSGConceptPropertyChecks.h"
57 OSG_USING_NAMESPACE
59 // Documentation for this class is emited in the
60 // OSGGeoVectorPropertyBase.cpp file.
61 // To modify it, please change the .fcd file (OSGGeoVectorProperty.fcd) and
62 // regenerate the base file.
64 /*! \fn bool GeoVectorProperty::getNormalize(void)
65 Returns if this property stores normalized vector data.
68 /*! \fn void GeoVectorProperty::clear(void)
69 Removes all values from this property.
72 /*! \fn void GeoVectorProperty::resize(size_t newsize)
73 Changes the size of this property to \a newsize. If the new size is smaller
74 than the current size, excessive elements are deleted; if the new is greater
75 than the current size, new elements are default constructed.
77 \param[in] newsize New size for this property.
80 /*! \fn UInt32 GeoIntegralProperty::size(void) const
81 \copydoc OSG::GeoProperty::size
84 /*! \fn void GeoVectorProperty::getGenericValue(MaxTypeT &val, const UInt32 index)
85 Retrieves this properties value at index \a index in \a val through the
86 most generic type available (MaxTypeT).
87 The templated access functions will use this internally and then convert to
88 the user specified type, thus the concrete properties derived from this
89 need to override this method.
91 \param[out] val The value stored at index \a index.
92 \param[in] index The index of the value to retrieve.
95 /*! \fn void GeoVectorProperty::setGenericValue(const MaxTypeT &val, const UInt32 index)
96 Stores the value \a val in this property at index \a index using the most
97 generic type available (MaxTypeT).
98 The templated access functions will use this internally and then convert to
99 the user specified type, thus the concrete properties derived from this
100 need to override this method.
102 \param[in] val The value to store at index \a index.
103 \param[in] index The index of the value to set.
106 /***************************************************************************\
107 * Class variables *
108 \***************************************************************************/
110 /***************************************************************************\
111 * Class methods *
112 \***************************************************************************/
114 void GeoVectorProperty::initMethod(InitPhase ePhase)
116 Inherited::initMethod(ePhase);
118 if(ePhase == TypeObject::SystemPost)
123 /*------------------------- Chunk Class Access ---------------------------*/
125 const StateChunkClass *GeoVectorProperty::getClass(void) const
127 return GeoProperty::getClass();
131 /***************************************************************************\
132 * Instance methods *
133 \***************************************************************************/
135 /*-------------------------------------------------------------------------*\
136 - private -
137 \*-------------------------------------------------------------------------*/
139 /*----------------------- constructors & destructors ----------------------*/
141 GeoVectorProperty::GeoVectorProperty(void) :
142 Inherited()
146 GeoVectorProperty::GeoVectorProperty(const GeoVectorProperty &source) :
147 Inherited(source)
151 GeoVectorProperty::~GeoVectorProperty(void)
155 /*! State Chunk handling */
157 GLenum GeoVectorProperty::getBufferType(void)
159 return GL_ARRAY_BUFFER_ARB;
162 void GeoVectorProperty::activate(DrawEnv *pEnv, UInt32 slot)
164 Window *pWin = pEnv->getWindow();
166 bool isGeneric = (slot >= 16); // !!!HACK. needs to be replaced for 2.0
167 slot &= 15;
169 bool hasVBO = pWin->hasExtOrVersion(_extVertexBufferObject, 0x0105, 0x0200);
171 osgSinkUnusedWarning(pWin);
173 if(hasVBO && isGeneric == true)
175 OSGGETGLFUNCBYID_GL3_ES( glVertexAttribPointer,
176 osgGlVertexAttribPointer,
177 _funcVertexAttribPointerARB,
178 pWin);
180 if(getGLId() != 0 && getUseVBO()) // Do we have a VBO?
182 pWin->validateGLObject(getGLId(), pEnv);
184 OSGGETGLFUNCBYID_GL3_ES( glBindBuffer,
185 osgGlBindBuffer,
186 _funcBindBuffer,
187 pWin);
189 osgGlBindBuffer(GL_ARRAY_BUFFER_ARB,
190 pWin->getGLObjectId(getGLId()));
192 osgGlVertexAttribPointer(slot,
193 getDimension(),
194 getFormat (),
195 getNormalize(),
196 getStride (),
199 osgGlBindBuffer(GL_ARRAY_BUFFER_ARB, 0);
201 else
203 osgGlVertexAttribPointer(slot,
204 getDimension(),
205 getFormat (),
206 getNormalize(),
207 getStride (),
208 getData ());
211 OSGGETGLFUNCBYID_GL3_ES( glEnableVertexAttribArray,
212 osgGlEnableVertexAttribArray,
213 _funcEnableVertexAttribArrayARB,
214 pWin);
216 osgGlEnableVertexAttribArray(slot);
218 OSGGETGLFUNCBYID_GL3_ES( glVertexAttribDivisor,
219 osgGlVertexAttribDivisor,
220 _funcVertexAttribDivisorARB,
221 pWin);
223 osgGlVertexAttribDivisor(slot, _sfDivisor.getValue());
225 else
227 #if !defined(OSG_OGL_COREONLY) || defined(OSG_CHECK_COREONLY)
228 const void *pData = NULL;
230 OSGGETGLFUNCBYID_GL3_ES( glBindBuffer,
231 osgGlBindBuffer,
232 _funcBindBuffer,
233 pWin);
235 hasVBO &= getUseVBO() && (getGLId() != 0);
237 if(hasVBO == true) // Do we have a VBO?
239 pWin->validateGLObject(getGLId(), pEnv);
241 osgGlBindBuffer(GL_ARRAY_BUFFER_ARB,
242 pWin->getGLObjectId(getGLId()));
244 else
246 pData = getData();
249 switch(slot)
251 case 0:
252 glVertexPointer(getDimension(),
253 getFormat (),
254 getStride (),
255 pData );
257 glEnableClientState(GL_VERTEX_ARRAY);
258 break;
260 case 2:
261 glNormalPointer(getFormat(),
262 getStride(),
263 pData );
265 glEnableClientState(GL_NORMAL_ARRAY);
266 break;
268 case 3:
269 glColorPointer(getDimension(),
270 getFormat (),
271 getStride (),
272 pData );
274 glEnableClientState(GL_COLOR_ARRAY);
275 break;
277 case 4:
278 if(pWin->hasExtOrVersion(_extSecondaryColor, 0x0104))
280 OSGGETGLFUNCBYID_GL3( glSecondaryColorPointer,
281 osgGlSecondaryColorPointer,
282 _funcSecondaryColorPointer,
283 pWin);
285 osgGlSecondaryColorPointer(getDimension(),
286 getFormat (),
287 getStride (),
288 pData );
290 glEnableClientState(GL_SECONDARY_COLOR_ARRAY_EXT);
292 else
294 FWARNING(("GeoVectorProperty::activate: Window "
295 "has no Secondary Color extension\n"));
297 break;
299 case 8:
300 case 9:
301 case 10:
302 case 11:
303 case 12:
304 case 13:
305 case 14:
306 case 15:
308 if(pWin->hasExtOrVersion(_extMultitexture, 0x0103, 0x0200))
310 OSGGETGLFUNCBYID_GL3_ES( glClientActiveTexture,
311 osgGlClientActiveTexture,
312 _funcClientActiveTextureARB,
313 pWin);
315 osgGlClientActiveTexture(GL_TEXTURE0_ARB + slot - 8);
317 glTexCoordPointer(getDimension(),
318 getFormat (),
319 getStride (),
320 pData );
322 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
324 else if(slot == 8)
326 glTexCoordPointer(getDimension(),
327 getFormat (),
328 getStride (),
329 pData );
331 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
333 else
335 SWARNING << "GeoVectorProperty::activate: Window "
336 << "has no Multi Texture extension" << std::endl;
339 break;
341 default: FWARNING(("GeoVectorProperty::activate: Non-Generic"
342 " attribute nr. %d unknown!\n", slot));
343 break;
346 if(hasVBO == true) // Do we have a VBO?
348 osgGlBindBuffer(GL_ARRAY_BUFFER_ARB, 0);
350 #endif
354 void GeoVectorProperty::changeFrom(DrawEnv *pEnv,
355 StateChunk *old,
356 UInt32 slot)
358 // change from me to me?
359 // this assumes I haven't changed in the meantime.
360 if(old == this)
361 return;
363 // The activation will overwrite the previous activation fully,
364 // so no need to deactivate
366 activate(pEnv, slot);
369 void GeoVectorProperty::deactivate(DrawEnv *pEnv, UInt32 slot)
371 Window *pWin = pEnv->getWindow();
373 bool isGeneric = (slot >= 16); // !!!HACK. needs to be replaced for 2.0
375 slot &= 15;
377 osgSinkUnusedWarning(pWin);
379 if(pWin->hasExtOrVersion(_extVertexBufferObject,
380 0x0105,
381 0x0200 ) && isGeneric)
383 OSGGETGLFUNCBYID_GL3_ES( glDisableVertexAttribArray,
384 osgGlDisableVertexAttribArray,
385 _funcDisableVertexAttribArrayARB,
386 pWin);
388 osgGlDisableVertexAttribArray(slot);
390 else
392 #if !defined(OSG_OGL_COREONLY) || defined(OSG_CHECK_COREONLY)
393 switch(slot)
395 case 0:
396 glDisableClientState(GL_VERTEX_ARRAY);
397 break;
399 case 2:
400 glDisableClientState(GL_NORMAL_ARRAY);
401 break;
403 case 3:
404 glDisableClientState(GL_COLOR_ARRAY);
405 break;
407 case 4:
408 glDisableClientState(GL_SECONDARY_COLOR_ARRAY_EXT);
409 break;
411 case 8:
412 case 9:
413 case 10:
414 case 11:
415 case 12:
416 case 13:
417 case 14:
418 case 15:
420 if(pWin->hasExtOrVersion(_extMultitexture, 0x0103, 0x0200))
422 OSGGETGLFUNCBYID_GL3_ES( glClientActiveTexture,
423 osgGlClientActiveTexture,
424 _funcClientActiveTextureARB,
425 pWin);
427 osgGlClientActiveTexture(GL_TEXTURE0_ARB + slot - 8);
429 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
431 else if(slot == 8)
433 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
435 else
437 SWARNING << "GeoVectorProperty::deactivate: Window "
438 << "has no Multi Texture extension" << std::endl;
441 break;
443 default:
444 FWARNING(("GeoVectorProperty::deactivate: Non-Generic"
445 " attribute nr. %d unknown!\n", slot));
446 break;
448 #endif
453 void *GeoVectorProperty::mapBuffer(GLenum eAccess, DrawEnv *pEnv)
455 void *returnValue = NULL;
457 if((getUseVBO() == true) && (getGLId() != 0))
459 Window *pWin = pEnv->getWindow();
461 osgSinkUnusedWarning(pWin);
463 OSGGETGLFUNCBYID_GL3_ES( glBindBuffer,
464 osgGlBindBuffer,
465 _funcBindBuffer,
466 pWin);
468 OSGGETGLFUNCBYID_GL3 ( glMapBuffer,
469 osgGlMapBuffer,
470 _funcMapBuffer,
471 pWin);
473 pWin->validateGLObject(getGLId(), pEnv);
475 osgGlBindBuffer(GL_ARRAY_BUFFER_ARB,
476 pWin->getGLObjectId(getGLId()));
478 returnValue = osgGlMapBuffer(GL_ARRAY_BUFFER_ARB, eAccess);
480 osgGlBindBuffer(GL_ARRAY_BUFFER_ARB, 0);
483 return returnValue;
486 bool GeoVectorProperty::unmapBuffer(DrawEnv *pEnv)
488 bool returnValue = true;
490 if((getUseVBO() == true) && (getGLId() != 0))
492 Window *pWin = pEnv->getWindow();
494 osgSinkUnusedWarning(pWin);
496 OSGGETGLFUNCBYID_GL3_ES( glBindBuffer,
497 osgGlBindBuffer,
498 _funcBindBuffer,
499 pWin);
501 OSGGETGLFUNCBYID_GL3 ( glUnmapBuffer,
502 osgGlUnmapBuffer,
503 _funcUnmapBuffer,
504 pWin);
506 osgGlBindBuffer(GL_ARRAY_BUFFER_ARB,
507 pWin->getGLObjectId(getGLId()));
509 returnValue = (osgGlUnmapBuffer(GL_ARRAY_BUFFER_ARB) != 0);
511 osgGlBindBuffer(GL_ARRAY_BUFFER_ARB, 0);
514 return returnValue;
518 /*----------------------------- class specific ----------------------------*/
520 void GeoVectorProperty::changed(ConstFieldMaskArg whichField,
521 UInt32 origin,
522 BitVector details)
524 Inherited::changed(whichField, origin, details);
527 void GeoVectorProperty::dump( UInt32 ,
528 const BitVector ) const
530 SLOG << "Dump GeoVectorProperty NI" << std::endl;