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 //---------------------------------------------------------------------------
45 #include <boost/bind.hpp>
47 #include "OSGConfig.h"
50 #include "OSGWindow.h"
52 #include "OSGGeoProperty.h"
53 #include "OSGDrawEnv.h"
55 #include "OSGGLFuncProtos.h"
57 #include "OSGConceptPropertyChecks.h"
61 // Documentation for this class is emited in the
62 // OSGGeoPropertyBase.cpp file.
63 // To modify it, please change the .fcd file (OSGGeoProperty.fcd) and
64 // regenerate the base file.
66 /*! \fn UInt32 GeoProperty::getFormat (void)
67 Returns the OpenGL type constant identifying the data type of the
71 /*! \fn UInt32 GeoProperty::getFormatSize(void)
72 Returns the size (as a multiple of <code>sizeof(char)</code>) of the data
73 type of the properties values.
76 /*! \fn UInt32 GeoProperty::getStride (void)
77 Returns the stride (the distance between successive values) of the
81 /*! \fn UInt32 GeoProperty::getDimension (void)
82 Returns the number of dimensions a single value of the property has.
85 /*! \fn UInt32 GeoProperty::size (void)
86 Returns the number of values the property holds.
88 \return Size of this property.
91 /*! \fn UInt8* GeoProperty::getData (void)
92 Returns a pointer to the values stored in this property. This mainly exists
93 to pass arrays to OpenGL.
96 /***************************************************************************\
98 \***************************************************************************/
100 StateChunkClass
GeoProperty::_class("GeoProperty", 16, 150);
102 UInt32
GeoProperty::_extVertexBufferObject
= Window::invalidExtensionID
;
103 UInt32
GeoProperty::_extMultitexture
= Window::invalidExtensionID
;
104 UInt32
GeoProperty::_arbVertexProgram
= Window::invalidExtensionID
;
105 UInt32
GeoProperty::_extSecondaryColor
= Window::invalidExtensionID
;
106 UInt32
GeoProperty::_arbInstancedArrays
= Window::invalidExtensionID
;
108 UInt32
GeoProperty::_funcBindBuffer
=
109 Window::invalidFunctionID
;
110 UInt32
GeoProperty::_funcMapBuffer
=
111 Window::invalidFunctionID
;
112 UInt32
GeoProperty::_funcUnmapBuffer
=
113 Window::invalidFunctionID
;
114 UInt32
GeoProperty::_funcBufferData
=
115 Window::invalidFunctionID
;
116 UInt32
GeoProperty::_funcBufferSubData
=
117 Window::invalidFunctionID
;
118 UInt32
GeoProperty::_funcGenBuffers
=
119 Window::invalidFunctionID
;
120 UInt32
GeoProperty::_funcDeleteBuffers
=
121 Window::invalidFunctionID
;
122 UInt32
GeoProperty::_funcVertexAttribPointerARB
=
123 Window::invalidFunctionID
;
124 UInt32
GeoProperty::_funcEnableVertexAttribArrayARB
=
125 Window::invalidFunctionID
;
126 UInt32
GeoProperty::_funcDisableVertexAttribArrayARB
=
127 Window::invalidFunctionID
;
129 UInt32
GeoProperty::_funcSecondaryColorPointer
=
130 Window::invalidFunctionID
;
131 UInt32
GeoProperty::_funcClientActiveTextureARB
=
132 Window::invalidFunctionID
;
133 UInt32
GeoProperty::_funcVertexAttribDivisorARB
=
134 Window::invalidFunctionID
;
136 /***************************************************************************\
138 \***************************************************************************/
140 void GeoProperty::initMethod(InitPhase ePhase
)
142 Inherited::initMethod(ePhase
);
144 if(ePhase
== TypeObject::SystemPost
)
146 _extVertexBufferObject
=
147 Window::registerExtension("GL_ARB_vertex_buffer_object");
149 _funcBindBuffer
= Window::registerFunction(
150 OSG_DLSYM_UNDERSCORE
"glBindBufferARB",
151 _extVertexBufferObject
);
153 _funcMapBuffer
= Window::registerFunction(
154 OSG_DLSYM_UNDERSCORE
"glMapBufferARB",
155 _extVertexBufferObject
);
157 _funcUnmapBuffer
= Window::registerFunction(
158 OSG_DLSYM_UNDERSCORE
"glUnmapBufferARB",
159 _extVertexBufferObject
);
161 _funcBufferData
= Window::registerFunction(
162 OSG_DLSYM_UNDERSCORE
"glBufferDataARB",
163 _extVertexBufferObject
);
165 _funcBufferSubData
= Window::registerFunction(
166 OSG_DLSYM_UNDERSCORE
"glBufferSubDataARB",
167 _extVertexBufferObject
);
169 _funcDeleteBuffers
= Window::registerFunction(
170 OSG_DLSYM_UNDERSCORE
"glDeleteBuffersARB",
171 _extVertexBufferObject
);
173 _funcGenBuffers
= Window::registerFunction(
174 OSG_DLSYM_UNDERSCORE
"glGenBuffersARB",
175 _extVertexBufferObject
);
178 Window::registerExtension("GL_ARB_vertex_program");
180 _funcVertexAttribPointerARB
= Window::registerFunction(
181 OSG_DLSYM_UNDERSCORE
"glVertexAttribPointerARB",
184 _funcEnableVertexAttribArrayARB
= Window::registerFunction(
185 OSG_DLSYM_UNDERSCORE
"glEnableVertexAttribArrayARB",
188 _funcDisableVertexAttribArrayARB
= Window::registerFunction(
189 OSG_DLSYM_UNDERSCORE
"glDisableVertexAttribArrayARB",
193 Window::registerExtension("GL_ARB_multitexture");
195 _funcClientActiveTextureARB
= Window::registerFunction(
196 OSG_DLSYM_UNDERSCORE
"glClientActiveTextureARB",
200 Window::registerExtension("GL_EXT_secondary_color");
202 _funcSecondaryColorPointer
= Window::registerFunction(
203 OSG_DLSYM_UNDERSCORE
"glSecondaryColorPointerEXT",
206 _arbInstancedArrays
=
207 Window::registerExtension("GL_ARB_instanced_arrays");
209 _funcVertexAttribDivisorARB
= Window::registerFunction(
210 OSG_DLSYM_UNDERSCORE
"glVertexAttribDivisorARB",
211 _arbInstancedArrays
);
216 /***************************************************************************\
218 \***************************************************************************/
220 /*-------------------------------------------------------------------------*\
222 \*-------------------------------------------------------------------------*/
224 /*----------------------- constructors & destructors ----------------------*/
226 GeoProperty::GeoProperty(void) :
231 GeoProperty::GeoProperty(const GeoProperty
&source
) :
236 GeoProperty::~GeoProperty(void)
241 /*------------------------- Chunk Class Access ---------------------------*/
243 const StateChunkClass
*GeoProperty::getClass(void) const
248 /*----------------------------- class specific ----------------------------*/
250 void GeoProperty::changed(ConstFieldMaskArg whichField
,
254 Inherited::changed(whichField
, origin
, details
);
256 if(0x0000 != (whichField
& ~UsageFieldMask
))
260 Window::refreshGLObject(getGLId());
265 void GeoProperty::dump( UInt32
,
266 const BitVector
) const
268 SLOG
<< "GeoProperty:"
269 << "Format: " << getFormat()
270 << " FormatSize: " << getFormatSize()
271 << " Stride: " << getStride()
272 << " Dim: " << getDimension()
273 << " Size: " << size() << std::endl
;
276 /*------------------------------ State ------------------------------------*/
279 /*! GL object handler
280 create the VBO and destroy it
283 UInt32
GeoProperty::handleGL(DrawEnv
*pEnv
,
285 Window::GLObjectStatusE mode
,
290 Window
*pWin
= pEnv
->getWindow();
292 osgSinkUnusedWarning(pWin
);
294 if(mode
== Window::initialize
|| mode
== Window::reinitialize
||
295 mode
== Window::needrefresh
)
297 if(mode
== Window::initialize
)
299 OSGGETGLFUNCBYID_GL3_ES( glGenBuffers
,
304 osgGlGenBuffers(1, &glid
);
306 pWin
->setGLObjectId(id
, glid
);
310 glid
= pWin
->getGLObjectId(id
);
313 OSGGETGLFUNCBYID_GL3_ES( glBindBuffer
,
318 OSGGETGLFUNCBYID_GL3_ES( glBufferData
,
323 OSGGETGLFUNCBYID_GL3_ES( glBufferSubData
,
328 osgGlBindBuffer(getBufferType(), glid
);
330 UInt32 uiBufferSize
= getFormatSize() * getDimension() * size32();
332 bool bSizeChanged
= (uiBufferSize
!= pWin
->getGLObjectInfo(id
));
335 if(mode
== Window::initialize
||
336 mode
== Window::reinitialize
||
337 bSizeChanged
== true )
339 osgGlBufferData(getBufferType(),
344 pWin
->setGLObjectInfo(id
, uiBufferSize
);
347 if(getData() != NULL
)
349 osgGlBufferSubData(getBufferType(),
355 osgGlBindBuffer(getBufferType(), 0);
359 SWARNING
<< "GeoProperty(" << this << "::handleGL: Illegal mode: "
360 << mode
<< " for id " << id
<< std::endl
;
366 void GeoProperty::handleDestroyGL(DrawEnv
*pEnv
,
368 Window::GLObjectStatusE mode
)
372 Window
*pWin
= pEnv
->getWindow();
374 osgSinkUnusedWarning(pWin
);
376 if(mode
== Window::destroy
)
378 OSGGETGLFUNCBYID_GL3_ES( glDeleteBuffers
,
383 glid
= pWin
->getGLObjectId(id
);
385 osgGlDeleteBuffers(1, &glid
);
387 pWin
->setGLObjectId(id
, 0);
389 else if(mode
== Window::finaldestroy
)
391 //SWARNING << "Last texture user destroyed" << std::endl;
395 SWARNING
<< "GeoProperty::handleDestroyGL: Illegal mode: "
396 << mode
<< " for id " << id
<< std::endl
;
400 /*-------------------------- Comparison -----------------------------------*/
402 bool GeoProperty::isTransparent(void) const
407 Real32
GeoProperty::switchCost(StateChunk
*)
412 bool GeoProperty::operator < (const StateChunk
&other
) const
414 return this < &other
;
417 bool GeoProperty::operator == (const StateChunk
&other
) const
419 GeoProperty
const *tother
= dynamic_cast<GeoProperty
const*>(&other
);
430 bool GeoProperty::operator != (const StateChunk
&other
) const
432 return ! (*this == other
);