fixed: auto_ptr -> unique_ptr
[opensg.git] / Source / System / NodeCores / Drawables / Geometry / Base / OSGGeoPumpGroup.cpp
blobd93c158a3ab432b36bb06b1ed542562c1614d698
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 * *
16 * *
17 * This library is free software; you can redistribute it and/or modify it *
18 * under the terms of the GNU Library General Public License as published *
19 * by the Free Software Foundation, version 2. *
20 * *
21 * This library is distributed in the hope that it will be useful, but *
22 * WITHOUT ANY WARRANTY; without even the implied warranty of *
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
24 * Library General Public License for more details. *
25 * *
26 * You should have received a copy of the GNU Library General Public *
27 * License along with this library; if not, write to the Free Software *
28 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
29 * *
30 * *
31 \*---------------------------------------------------------------------------*/
32 /*---------------------------------------------------------------------------*\
33 * Changes *
34 * *
35 * *
36 * *
37 * *
38 * *
39 * *
40 \*---------------------------------------------------------------------------*/
42 //---------------------------------------------------------------------------
43 // Includes
44 //---------------------------------------------------------------------------
46 #include <cstdlib>
47 #include <cstdio>
49 #include "OSGConfig.h"
51 #include "OSGGL.h"
52 #include "OSGGLEXT.h"
54 #include "OSGLog.h"
56 #include "OSGGeometry.h"
57 #include "OSGDrawEnv.h"
59 #include "OSGMaterial.h"
61 #include "OSGGeoPumpGroup.h"
62 #include "OSGGeoImmediatePumpGroup.h"
63 #include "OSGGeoVertexArrayPumpGroup.h"
64 #include "OSGGeoSplitVertexArrayPumpGroup.h"
66 OSG_USING_NAMESPACE
69 /***************************************************************************\
70 * Description *
71 \***************************************************************************/
73 /* \class OSG::GeoPumpGroup
74 \ingroup GrpSystemNodeCoresDrawablesGeometry
76 The PumpGroup is responsible for selecting the most appropriate pump
77 function to send the geometry's data to OpenGL in the most efficient manner.
79 The pump is selected inside the rendering function and should not be accessed
80 from the outside.
82 \dev The pump factory chooses the pump based on the used properties. For
83 non- and single-indexed geometry OpenGL VertexArrays are used, for
84 multi-indexed geometry an immediate mode pump has to be used. Specialized Pumps
85 for all combinations of properties are created to optimizie this case as much
86 as possible.
90 std::vector<GeoPumpGroup*> *GeoPumpGroup::_activeGroups;
92 /*! Initialize the _activeGroups at startup.
94 InitFuncWrapper GeoPumpGroup::actInit(GeoPumpGroup::initActiveGroups);
96 bool GeoPumpGroup::initActiveGroups(void)
98 _activeGroups = new std::vector<GeoPumpGroup*>;
100 _activeGroups->push_back(new GeoVertexArrayPumpGroup);
101 _activeGroups->push_back(new GeoSplitVertexArrayPumpGroup);
102 #if !defined(OSG_OGL_COREONLY) || defined(OSG_CHECK_COREONLY)
103 _activeGroups->push_back(new GeoImmediatePumpGroup);
104 #endif
106 addPostFactoryExitFunction(&GeoPumpGroup::terminateActiveGroups);
108 return true;
111 bool GeoPumpGroup::terminateActiveGroups(void)
113 for(UInt32 i = 0; i < _activeGroups->size(); ++i)
115 delete (*_activeGroups)[i];
118 delete _activeGroups;
120 return true;
123 /*! PropertyCharacteristics handling.
126 std::string GeoPumpGroup::describePropertyCharacteristics(
127 PropertyCharacteristics ac)
129 std::string result;
131 if(ac & GeoPumpGroup::NonIndexed) result += "NonIndexed,";
132 if(ac & GeoPumpGroup::SingleIndexed) result += "SingleIndexed,";
133 if(ac & GeoPumpGroup::MultiIndexed) result += "MultiIndexed,";
134 if(ac & GeoPumpGroup::NonTraditionalProperties)
135 result += "NonTraditionalProperties,";
137 if(result.empty() == true)
138 result += "unknown,";
140 result.resize(result.length()-1);
142 return result;
145 GeoPumpGroup::PropertyCharacteristics
146 GeoPumpGroup::characterizeGeometry(Geometry* geo)
148 return characterizeGeometry(geo->getMFProperties(),
149 geo->getMFPropIndices());
152 GeoPumpGroup::PropertyCharacteristics
153 GeoPumpGroup::characterizeGeometry(const Geometry::MFPropertiesType *prop,
154 const Geometry::MFPropIndicesType *propIdx)
156 PropertyCharacteristics retVal = 0;
158 Int16 natt = prop ->size32();
159 Int16 nind = propIdx->size32();
161 // Check for single- and multi-indexed
162 GeoIntegralProperty *ind = NULL;
164 bool single = true;
165 bool multi = true;
166 bool nonind = true;
167 bool allPropVAO = true;
168 bool allIdxVAO = true;
170 for(Int16 i = 0; i < natt; ++i)
172 // Only count actual attributes
173 if((*prop)[i] != NULL && (*prop)[i]->getDivisor() == 0)
175 if((*prop)[i]->getUseVBO() == false)
177 allPropVAO = false;
180 if(i < nind)
182 if((*propIdx)[i] == NULL)
184 if((*prop)[i]->size() != 1)
186 single = false;
187 multi = false;
190 else
192 if((*propIdx)[i]->getUseVBO() == false)
194 allIdxVAO = false;
197 nonind = false;
199 if(ind == NULL)
200 ind = (*propIdx)[i];
202 if((*propIdx)[i] != ind && (*prop)[i]->size() != 1)
203 single = false;
206 else
208 single = false;
209 multi = false;
214 if(nonind)
215 retVal |= GeoPumpGroup::NonIndexed;
216 else if(single)
217 retVal |= GeoPumpGroup::SingleIndexed;
218 else if(multi)
219 retVal |= GeoPumpGroup::MultiIndexed;
221 if(allPropVAO == true)
223 retVal |= AllPropsVAO;
226 if(allIdxVAO == true)
228 retVal |= AllPropIdxVAO;
231 #if 0
232 // check double single + multi char
233 fprintf(stderr,
234 "single %d | no %d | multi %d | prop vao %d | idx vao %d\n",
235 UInt32(single),
236 UInt32(nonind),
237 UInt32(multi),
238 UInt32(allPropVAO),
239 UInt32(allIdxVAO));
240 #endif
242 // Check for non-traditional properties.
243 // Right now just check existence of attribs 6&7
244 // To be complete this would also have to check
245 // type compatibility! *DR*
247 if(natt > 6 && (*prop)[6] != NULL)
248 retVal |= GeoPumpGroup::NonTraditionalProperties;
249 if(natt > 7 && (*prop)[7] != NULL)
250 retVal |= GeoPumpGroup::NonTraditionalProperties;
252 return retVal;
255 /*! Find the actual pumps for the given Window/Geometry.
258 GeoPumpGroup::GeoPump GeoPumpGroup::findGeoPump(DrawEnv *pEnv,
259 PropertyCharacteristics acset)
261 GeoPump pump = NULL;
262 Window *win = pEnv->getWindow();
264 for(std::vector<GeoPumpGroup*>::iterator it = _activeGroups->begin();
265 it != _activeGroups->end() && pump == NULL;
266 ++it)
268 pump = (*it)->getGeoPump(pEnv,acset);
271 if(pump == NULL)
273 FWARNING(("GeoPumpGroup::findGeoPump: Couldn't find pump for"
274 "Window %p and characteristics %s!\n",
275 static_cast<void *>(win),
276 describePropertyCharacteristics(acset).c_str() ));
279 return pump;
282 GeoPumpGroup::SplitGeoPump GeoPumpGroup::findSplitGeoPump(
283 DrawEnv *pEnv,
284 PropertyCharacteristics acset)
286 SplitGeoPump pump = { NULL, NULL, NULL };
287 Window *win = pEnv->getWindow();
289 std::vector<GeoPumpGroup*>::const_iterator pIt = _activeGroups->begin();
290 std::vector<GeoPumpGroup*>::const_iterator pEnd = _activeGroups->end ();
292 for(; pIt != pEnd && pump.setupPump == NULL; ++pIt)
294 pump = (*pIt)->getSplitGeoPump(pEnv, acset);
297 if(pump.setupPump == NULL)
299 FWARNING(("GeoPumpGroup::findSplitGeoPump: Couldn't find pump for"
300 "Window %p and characteristics %s!\n",
301 static_cast<void *>(win),
302 describePropertyCharacteristics(acset).c_str() ));
305 return pump;
308 GeoPumpGroup::SplitGeoPump GeoPumpGroup::getSplitGeoPump(
309 DrawEnv *,
310 PropertyCharacteristics )
312 SplitGeoPump pump = { NULL, NULL, NULL };
314 return pump;
317 GeoPumpGroup::~GeoPumpGroup()