1 /*---------------------------------------------------------------------------*\
5 * Copyright (C) 2000-2002 by the OpenSG Forum *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
11 \*---------------------------------------------------------------------------*/
12 /*---------------------------------------------------------------------------*\
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. *
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. *
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. *
28 \*---------------------------------------------------------------------------*/
29 /*---------------------------------------------------------------------------*\
37 \*---------------------------------------------------------------------------*/
39 //---------------------------------------------------------------------------
41 //---------------------------------------------------------------------------
46 #include "OSGConfig.h"
49 #include "OSGWindow.h"
50 #include "OSGGeoVectorProperty.h"
51 #include "OSGDrawEnv.h"
53 #include "OSGGLFuncProtos.h"
55 #include "OSGConceptPropertyChecks.h"
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 /***************************************************************************\
108 \***************************************************************************/
110 /***************************************************************************\
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 /***************************************************************************\
133 \***************************************************************************/
135 /*-------------------------------------------------------------------------*\
137 \*-------------------------------------------------------------------------*/
139 /*----------------------- constructors & destructors ----------------------*/
141 GeoVectorProperty::GeoVectorProperty(void) :
146 GeoVectorProperty::GeoVectorProperty(const GeoVectorProperty
&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
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
,
180 if(getGLId() != 0 && getUseVBO()) // Do we have a VBO?
182 pWin
->validateGLObject(getGLId(), pEnv
);
184 OSGGETGLFUNCBYID_GL3_ES( glBindBuffer
,
189 osgGlBindBuffer(GL_ARRAY_BUFFER_ARB
,
190 pWin
->getGLObjectId(getGLId()));
192 osgGlVertexAttribPointer(slot
,
199 osgGlBindBuffer(GL_ARRAY_BUFFER_ARB
, 0);
203 osgGlVertexAttribPointer(slot
,
211 OSGGETGLFUNCBYID_GL3_ES( glEnableVertexAttribArray
,
212 osgGlEnableVertexAttribArray
,
213 _funcEnableVertexAttribArrayARB
,
216 osgGlEnableVertexAttribArray(slot
);
218 OSGGETGLFUNCBYID_GL3_ES( glVertexAttribDivisor
,
219 osgGlVertexAttribDivisor
,
220 _funcVertexAttribDivisorARB
,
223 osgGlVertexAttribDivisor(slot
, _sfDivisor
.getValue());
227 #if !defined(OSG_OGL_COREONLY) || defined(OSG_CHECK_COREONLY)
228 const void *pData
= NULL
;
230 OSGGETGLFUNCBYID_GL3_ES( glBindBuffer
,
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()));
252 glVertexPointer(getDimension(),
257 glEnableClientState(GL_VERTEX_ARRAY
);
261 glNormalPointer(getFormat(),
265 glEnableClientState(GL_NORMAL_ARRAY
);
269 glColorPointer(getDimension(),
274 glEnableClientState(GL_COLOR_ARRAY
);
278 if(pWin
->hasExtOrVersion(_extSecondaryColor
, 0x0104))
280 OSGGETGLFUNCBYID_GL3( glSecondaryColorPointer
,
281 osgGlSecondaryColorPointer
,
282 _funcSecondaryColorPointer
,
285 osgGlSecondaryColorPointer(getDimension(),
290 glEnableClientState(GL_SECONDARY_COLOR_ARRAY_EXT
);
294 FWARNING(("GeoVectorProperty::activate: Window "
295 "has no Secondary Color extension\n"));
308 if(pWin
->hasExtOrVersion(_extMultitexture
, 0x0103, 0x0200))
310 OSGGETGLFUNCBYID_GL3_ES( glClientActiveTexture
,
311 osgGlClientActiveTexture
,
312 _funcClientActiveTextureARB
,
315 osgGlClientActiveTexture(GL_TEXTURE0_ARB
+ slot
- 8);
317 glTexCoordPointer(getDimension(),
322 glEnableClientState(GL_TEXTURE_COORD_ARRAY
);
326 glTexCoordPointer(getDimension(),
331 glEnableClientState(GL_TEXTURE_COORD_ARRAY
);
335 SWARNING
<< "GeoVectorProperty::activate: Window "
336 << "has no Multi Texture extension" << std::endl
;
341 default: FWARNING(("GeoVectorProperty::activate: Non-Generic"
342 " attribute nr. %d unknown!\n", slot
));
346 if(hasVBO
== true) // Do we have a VBO?
348 osgGlBindBuffer(GL_ARRAY_BUFFER_ARB
, 0);
354 void GeoVectorProperty::changeFrom(DrawEnv
*pEnv
,
358 // change from me to me?
359 // this assumes I haven't changed in the meantime.
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
377 osgSinkUnusedWarning(pWin
);
379 if(pWin
->hasExtOrVersion(_extVertexBufferObject
,
381 0x0200 ) && isGeneric
)
383 OSGGETGLFUNCBYID_GL3_ES( glDisableVertexAttribArray
,
384 osgGlDisableVertexAttribArray
,
385 _funcDisableVertexAttribArrayARB
,
388 osgGlDisableVertexAttribArray(slot
);
392 #if !defined(OSG_OGL_COREONLY) || defined(OSG_CHECK_COREONLY)
396 glDisableClientState(GL_VERTEX_ARRAY
);
400 glDisableClientState(GL_NORMAL_ARRAY
);
404 glDisableClientState(GL_COLOR_ARRAY
);
408 glDisableClientState(GL_SECONDARY_COLOR_ARRAY_EXT
);
420 if(pWin
->hasExtOrVersion(_extMultitexture
, 0x0103, 0x0200))
422 OSGGETGLFUNCBYID_GL3_ES( glClientActiveTexture
,
423 osgGlClientActiveTexture
,
424 _funcClientActiveTextureARB
,
427 osgGlClientActiveTexture(GL_TEXTURE0_ARB
+ slot
- 8);
429 glDisableClientState(GL_TEXTURE_COORD_ARRAY
);
433 glDisableClientState(GL_TEXTURE_COORD_ARRAY
);
437 SWARNING
<< "GeoVectorProperty::deactivate: Window "
438 << "has no Multi Texture extension" << std::endl
;
444 FWARNING(("GeoVectorProperty::deactivate: Non-Generic"
445 " attribute nr. %d unknown!\n", slot
));
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
,
468 OSGGETGLFUNCBYID_GL3 ( glMapBuffer
,
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);
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
,
501 OSGGETGLFUNCBYID_GL3 ( glUnmapBuffer
,
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);
518 /*----------------------------- class specific ----------------------------*/
520 void GeoVectorProperty::changed(ConstFieldMaskArg whichField
,
524 Inherited::changed(whichField
, origin
, details
);
527 void GeoVectorProperty::dump( UInt32
,
528 const BitVector
) const
530 SLOG
<< "Dump GeoVectorProperty NI" << std::endl
;