changed: gcc8 base update
[opensg.git] / Source / System / NodeCores / Drawables / Geometry / Base / OSGGeoSplitVertexArrayPumpGroup.cpp
blob75dfd9a6fc3b7e5fbb9ce77606d2d13a7c4722b6
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 "OSGGeoSplitVertexArrayPumpGroup.h"
63 #include "OSGGLFuncProtos.h"
65 OSG_BEGIN_NAMESPACE
67 #define OSG_COMPILE_SPLIT_PUMP 1
69 // Intentionally INSIDE the namespace
70 #include "OSGGeoPumpCommon.inl"
72 //#define DEBUG_WHICH_PUMP 1
74 /***************************************************************************\
75 * Description *
76 \***************************************************************************/
78 /***************************************************************************\
79 * Class variables *
80 \***************************************************************************/
82 /*! An InitFuncWrapper to initialize the GeoVertexArrayPumpGroup.
85 InitFuncWrapper GeoSplitVertexArrayPumpGroup::_glextInitFuncWrapper(
86 GeoSplitVertexArrayPumpGroup::glextInitFunction);
88 /*! OpenGL extension indices.
91 UInt32 GeoSplitVertexArrayPumpGroup::_arbVertexProgram;
92 #if !defined(OSG_OGL_COREONLY) || defined(OSG_CHECK_COREONLY)
93 UInt32 GeoSplitVertexArrayPumpGroup::_extSecondaryColor;
94 UInt32 GeoSplitVertexArrayPumpGroup::_extMultitexture;
95 #endif
97 /***************************************************************************\
98 * Instance methods *
99 \***************************************************************************/
101 /*------------- constructors & destructors --------------------------------*/
103 GeoSplitVertexArrayPumpGroup::GeoSplitVertexArrayPumpGroup(void)
107 GeoSplitVertexArrayPumpGroup::~GeoSplitVertexArrayPumpGroup(void)
111 /*-------------------------------------------------------------------------*\
112 - private -
113 \*-------------------------------------------------------------------------*/
115 #if !defined(OSG_DO_DOC) || defined(OSG_DOC_DEV)
117 namespace
119 // collect info for property in 'slot'
120 bool pumpGLSetup(PumpData &info, UInt16 slot)
122 bool retVal = false;
124 if(slot < info.prop->size())
125 info.attribPtr[slot] = (*info.prop)[slot];
127 if(slot < info.propIdx->size())
128 info.attribIndex[slot] = (*info.propIdx)[slot];
130 if(info.attribPtr[slot] != NULL &&
131 info.attribPtr[slot]->getIgnore() == false )
133 info.attribData [slot] = info.attribPtr[slot]->getData();
134 info.attribStride[slot] = info.attribPtr[slot]->getStride();
136 if(info.attribStride[slot] == 0)
138 info.attribStride[slot] =
139 info.attribPtr[slot]->getFormatSize() *
140 info.attribPtr[slot]->getDimension();
143 retVal = true;
146 return retVal;
149 #if !defined(OSG_OGL_COREONLY) || defined(OSG_CHECK_COREONLY)
150 // handle vertex attrib with global value
151 void globalAttrib(PumpData &info, UInt16 slot, UInt16 pumpSlot)
153 if(info.attribData[slot] != NULL &&
154 info.attribPtr [slot]->size() == 1 )
156 UInt16 formatIdx = info.attribPtr[slot]->getFormat() - formatBase;
157 UInt32 dimIdx = info.attribPtr[slot]->getDimension() - 1;
159 pumpFunc pump = pumpFuncs[pumpSlot][formatIdx][dimIdx];
161 if(pump == NULL)
163 SWARNING << "GeoVertexArrayPumpGroup - globalExtAttrib: "
164 << "Invalid pump function for property " << slot
165 << " type " << info.attribPtr[slot]->getDimension()
166 << "D " << formatNames[formatIdx]
167 << endLog;
168 return;
171 pump(info.attribData[slot]);
172 info.attribData[slot] = NULL;
173 info.attribPtr [slot] = NULL;
176 #endif
178 #if !defined(OSG_OGL_COREONLY) || defined(OSG_CHECK_COREONLY)
179 // handle vertex attrib with global value - using GL extension
180 void globalExtAttrib(PumpData &info, UInt16 slot,
181 UInt16 pumpSlot, Window *win)
183 if(info.attribData[slot] != NULL &&
184 info.attribPtr [slot]->size() == 1 )
186 UInt16 formatIdx = info.attribPtr[slot]->getFormat() - formatBase;
187 UInt32 dimIdx = info.attribPtr[slot]->getDimension() - 1;
188 UInt32 funcId = pumpFuncIDs[pumpSlot][formatIdx][dimIdx];
190 if(funcId == Window::invalidFunctionID)
192 SWARNING << "GeoVertexArrayPumpGroup - globalExtAttrib: "
193 << "Invalid extension function for property " << slot
194 << " type " << info.attribPtr[slot]->getDimension()
195 << "D " << formatNames[formatIdx]
196 << endLog;
197 return;
200 pumpFunc pump =
201 reinterpret_cast<pumpFunc>(win->getFunction(funcId));
203 if(pump == NULL)
205 SWARNING << "GeoVertexArrayPumpGroup - globalExtAttrib: "
206 << "Extension function for property " << slot
207 << " type " << info.attribPtr[slot]->getDimension()
208 << "D " << formatNames[formatIdx]
209 << " not supported by Window " << win
210 << endLog;
211 return;
214 pump(info.attribData[slot]);
215 info.attribData[slot] = NULL;
216 info.attribPtr [slot] = NULL;
219 #endif
221 #if !defined(OSG_OGL_COREONLY) || defined(OSG_CHECK_COREONLY)
222 // handle vertex attrib with global value - using GL extension, multi
223 void globalExtMultiAttrib(PumpData &info, UInt16 slot,
224 UInt16 pumpSlot, GLenum attrib,
225 Window *win )
227 if(info.attribData[slot] != NULL &&
228 info.attribPtr [slot]->size() == 1 )
230 UInt16 formatIdx = info.attribPtr[slot]->getFormat() - formatBase;
231 UInt32 dimIdx = info.attribPtr[slot]->getDimension() - 1;
232 UInt32 funcId = pumpFuncIDs[pumpSlot][formatIdx][dimIdx];
234 if(funcId == Window::invalidFunctionID)
236 SWARNING << "GeoVertexArrayPumpGroup - globalExtMultiAttrib: "
237 << "Invalid extension function for property " << slot
238 << " type " << info.attribPtr[slot]->getDimension()
239 << "D " << formatNames[formatIdx]
240 << endLog;
241 return;
244 multiPumpFunc pump =
245 reinterpret_cast<multiPumpFunc>(win->getFunction(funcId));
247 if(pump == NULL)
249 SWARNING << "GeoVertexArrayPumpGroup - globalExtMutliAttrib: "
250 << "Extension function for property " << slot
251 << " type " << info.attribPtr[slot]->getDimension()
252 << "D " << formatNames[formatIdx]
253 << " not supported by Window " << win
254 << endLog;
255 return;
258 pump(attrib, info.attribData[slot]);
259 info.attribData[slot] = NULL;
260 info.attribPtr [slot] = NULL;
263 #endif
265 } // namespace
267 #endif // remove from all but dev docs
271 GeoPumpGroup::SplitGeoPump GeoSplitVertexArrayPumpGroup::getSplitGeoPump(
272 DrawEnv *pEnv,
273 PropertyCharacteristics acset)
275 SplitGeoPump pump = { NULL, NULL, NULL };
277 // Remove the stuff we can handle
278 PropertyCharacteristics prop;
279 prop = acset & GeoPumpGroup::IndexMask;
281 if(prop == SingleIndexed || prop == NonIndexed)
283 Window *win = pEnv->getWindow();
285 if(win->hasExtOrVersion(_arbVertexProgram,
286 0x0200,
287 0x0200 ) && (acset & UsesShader))
289 pump.setupPump = masterAttribGeoSetupPumpFull;
290 pump.drawPump = masterAttribGeoJustDrawPump;
291 pump.shutdownPump = masterAttribGeoShutdownPump;
293 #if !defined(OSG_OGL_COREONLY) || defined(OSG_CHECK_COREONLY)
294 else
296 pump.setupPump = masterClassicGeoSetupPumpFull;
297 pump.drawPump = masterClassicGeoJustDrawPump;
298 pump.shutdownPump = masterClassicGeoShutdownPump;
300 #endif
303 return pump;
306 GeoPumpGroup::GeoPump GeoSplitVertexArrayPumpGroup::getGeoPump(
307 DrawEnv *pEnv,
308 PropertyCharacteristics acset)
310 return NULL;
313 bool GeoSplitVertexArrayPumpGroup::glextInitFunction(void)
315 #if !defined(OSG_OGL_COREONLY) || defined(OSG_CHECK_COREONLY)
316 _extSecondaryColor =
317 Window::registerExtension("GL_EXT_secondary_color");
318 _extMultitexture =
319 Window::registerExtension("GL_ARB_multitexture");
320 #endif
322 #if !defined(OSG_OGL_COREONLY) || defined(OSG_CHECK_COREONLY)
323 for(UInt16 i = 0; i < numFormats; ++i)
325 for(UInt16 j = 0; j < 4; ++j)
327 pumpFuncIDs[0][i][j] = Window::invalidFunctionID;
328 pumpFuncIDs[1][i][j] = Window::invalidFunctionID;
332 for(UInt16 i = 0; i < uiNumSecColFunc; ++i)
333 secondaryColorInitFuncs[i].init(pumpFuncIDs[SecColorsPumpSlot],
334 _extSecondaryColor );
336 for(UInt16 i = 0; i < uiNumMTexFuncs; ++i)
337 multiTexCoordsInitFuncs[i].init(pumpFuncIDs[TexCoords1PumpSlot],
338 _extMultitexture );
339 #endif
341 _arbVertexProgram =
342 Window::registerExtension("GL_ARB_vertex_program");
344 for(UInt16 i = 0; i < uiNumAttribFuncs; ++i)
345 attribInitFuncs[i].init(attribPumpFuncIDs, _arbVertexProgram);
347 for(UInt16 i = 0; i < uiNumNormAttribFuncs; ++i)
348 normAttribInitFuncs[i].init(normAttribPumpFuncIDs, _arbVertexProgram);
350 return true;
355 #if !defined(OSG_OGL_COREONLY) || defined(OSG_CHECK_COREONLY)
356 bool GeoSplitVertexArrayPumpGroup::masterClassicGeoSetupPump(
357 DrawEnv *pEnv,
358 const GeoIntegralProperty *lengths,
359 const GeoIntegralProperty *types,
360 const Geometry::MFPropertiesType *prop,
361 const Geometry::MFPropIndicesType *propIdx,
362 bool withFallback)
364 #ifdef DEBUG_WHICH_PUMP
365 static bool bPrinted = false;
367 if(bPrinted == false)
369 fprintf(stderr,
370 "GeoSplitVertexArrayPumpGroup::masterClassicGeoSetupPump\n");
371 bPrinted = true;
373 #endif
375 // Setup: get all the data
376 PumpData pumpData;
378 pumpData.lengths = lengths;
379 pumpData.types = types;
380 pumpData.prop = prop;
381 pumpData.propIdx = propIdx;
383 UInt16 nattrib = prop->size32();
385 for(UInt16 i = 0; i < nattrib; ++i)
387 if(pumpGLSetup(pumpData, i) == false)
388 continue;
391 // we need positions
392 if(pumpData.attribPtr[0] == NULL ||
393 pumpData.attribPtr[0]->getUseVBO() == false)
395 #ifdef DEBUG_WHICH_PUMP
396 static bool bPrinted1 = false;
398 if(bPrinted1 == false)
400 #endif
401 if(withFallback == false)
403 SWARNING << "GeoSplitVertexArrayPumpGroup::masterAttribGeoPump: "
404 << "No positions, or positions not in vbo." << endLog;
406 #ifdef DEBUG_WHICH_PUMP
407 bPrinted1 = true;
409 #endif
411 return false;
414 for(Int16 i = nattrib - 1; i >= 0; --i)
416 if(pumpData.attribPtr[i] != NULL &&
417 pumpData.attribPtr[i]->size() != 1 )
419 pumpData.attribPtr[i]->activate(pEnv, i);
423 return true;
427 void GeoSplitVertexArrayPumpGroup::masterClassicGeoDrawPump(
428 DrawEnv *pEnv,
429 const GeoIntegralProperty *lengths,
430 const GeoIntegralProperty *types,
431 const Geometry::MFPropertiesType *prop,
432 const Geometry::MFPropIndicesType *propIdx)
434 #ifdef DEBUG_WHICH_PUMP
435 static bool bPrinted = false;
437 if(bPrinted == false)
439 fprintf(stderr,
440 "GeoSplitVertexArrayPumpGroup::masterClassicGeoDrawPump\n");
441 bPrinted = true;
443 #endif
445 Window *win = pEnv->getWindow();
447 // check for empty geometry
448 if(types == NULL || types->size() == 0)
449 return;
451 if(!pumpInternalSetup(types, true))
452 return;
453 if(!pumpInternalSetup(lengths, false))
454 return;
456 PumpData pumpData;
458 pumpData.lengths = lengths;
459 pumpData.types = types;
460 pumpData.prop = prop;
461 pumpData.propIdx = propIdx;
463 UInt16 nattrib = prop->size32();
465 for(UInt16 i = 0; i < nattrib; ++i)
467 if(pumpGLSetup(pumpData, i) == false)
468 continue;
471 // Length handling. Special case: no length given
473 UInt32 curlen;
474 UInt32 nprims;
476 // no lengths? use all available data for the first type
477 if(lengths == NULL)
479 if(types->size() != 1)
481 SWARNING << "GeoVertexArrayPumpGroup::masterAttribGeoPump: "
482 << "No lengths, but more than one type?!"
483 << endLog;
484 return;
487 nprims = 1;
489 if(propIdx->size() != 0 && (*propIdx)[0] != NULL)
491 curlen = (*propIdx)[0]->size32();
493 else
495 curlen = (*prop)[0]->size32();
498 else
500 nprims = types->size32();
501 lengths->getValue(curlen, 0);
504 // global attribs?
505 globalAttrib(pumpData, Geometry::NormalsIndex, NormalsPumpSlot);
506 globalAttrib(pumpData, Geometry::ColorsIndex, ColorsPumpSlot);
507 globalAttrib(pumpData, Geometry::TexCoordsIndex, TexCoordsPumpSlot);
509 if(win->hasExtOrVersion(_extSecondaryColor, 0x0104) == true)
511 globalExtAttrib(pumpData, Geometry::SecondaryColorsIndex,
512 SecColorsPumpSlot, win );
515 if(win->hasExtOrVersion(_extMultitexture, 0x0103, 0x0200) == true)
517 globalExtMultiAttrib(pumpData, Geometry::TexCoords1Index,
518 TexCoords1PumpSlot, GL_TEXTURE1_ARB, win);
519 globalExtMultiAttrib(pumpData, Geometry::TexCoords1Index,
520 TexCoords2PumpSlot, GL_TEXTURE2_ARB, win);
521 globalExtMultiAttrib(pumpData, Geometry::TexCoords1Index,
522 TexCoords3PumpSlot, GL_TEXTURE3_ARB, win);
523 globalExtMultiAttrib(pumpData, Geometry::TexCoords1Index,
524 TexCoords4PumpSlot, GL_TEXTURE4_ARB, win);
525 globalExtMultiAttrib(pumpData, Geometry::TexCoords1Index,
526 TexCoords5PumpSlot, GL_TEXTURE5_ARB, win);
527 globalExtMultiAttrib(pumpData, Geometry::TexCoords1Index,
528 TexCoords6PumpSlot, GL_TEXTURE6_ARB, win);
529 globalExtMultiAttrib(pumpData, Geometry::TexCoords1Index,
530 TexCoords7PumpSlot, GL_TEXTURE7_ARB, win);
533 UInt32 vertindex = 0;
535 if(propIdx->size() != 0 && (*propIdx)[0] != NULL)
537 // Single Indexed
539 GeoIntegralProperty *index = (*propIdx)[0];
540 const UInt8 *indexData = index->getData();
541 GLenum indexFormat = index->getFormat();
542 UInt32 indexStride =
543 index->getStride() ? index->getStride() : index->getFormatSize() *
544 index->getDimension();
546 index->activate(pEnv, 0);
548 if(index->isInVBO(pEnv))
550 indexData = NULL;
553 for(UInt32 primindex = 0; primindex < nprims; ++primindex)
555 if(primindex < lengths->size())
556 curlen = lengths->getValue<UInt32>(primindex);
558 if(curlen > 0)
560 glDrawElements(types->getValue<UInt16>(primindex),
561 curlen,
562 indexFormat,
563 indexData + vertindex * indexStride);
565 vertindex += curlen;
569 index->deactivate(pEnv, 0);
571 else
573 // Non-indexed
574 for(UInt32 primindex = 0; primindex < nprims; ++primindex)
576 if(primindex < lengths->size())
577 curlen = lengths->getValue<UInt32>(primindex);
579 if(curlen > 0)
581 glDrawArrays(types->getValue<UInt16>(primindex), vertindex,
582 curlen);
583 vertindex += curlen;
590 bool GeoSplitVertexArrayPumpGroup::masterClassicGeoSetupPumpFull(
591 DrawEnv *pEnv,
592 const GeoIntegralProperty *lengths,
593 const GeoIntegralProperty *types,
594 const Geometry::MFPropertiesType *prop,
595 const Geometry::MFPropIndicesType *propIdx,
596 bool withFallback)
598 #ifdef DEBUG_WHICH_PUMP
599 static bool bPrinted = false;
601 if(bPrinted == false)
603 fprintf(stderr,
604 "GeoSplitVertexArrayPumpGroup::masterClassicGeoSetupPumpFull\n");
605 bPrinted = true;
607 #endif
609 // Setup: get all the data
610 PumpData pumpData;
612 pumpData.lengths = lengths;
613 pumpData.types = types;
614 pumpData.prop = prop;
615 pumpData.propIdx = propIdx;
617 UInt16 nattrib = prop->size32();
619 for(UInt16 i = 0; i < nattrib; ++i)
621 if(pumpGLSetup(pumpData, i) == false)
622 continue;
625 // we need positions
626 if(pumpData.attribPtr[0] == NULL ||
627 pumpData.attribPtr[0]->getUseVBO() == false)
629 #ifdef DEBUG_WHICH_PUMP
630 static bool bPrinted1 = false;
632 if(bPrinted1 == false)
634 #endif
635 if(withFallback == false)
637 SWARNING << "GeoSplitVertexArrayPumpGroup::masterAttribGeoPump: "
638 << "No positions." << endLog;
640 #ifdef DEBUG_WHICH_PUMP
641 bPrinted1 = true;
643 #endif
644 return false;
647 for(Int16 i = nattrib - 1; i >= 0; --i)
649 if(pumpData.attribPtr[i] != NULL &&
650 pumpData.attribPtr[i]->size() != 1 )
652 pumpData.attribPtr[i]->activate(pEnv, i);
656 if(propIdx->size() != 0 && (*propIdx)[0] != NULL)
658 (*propIdx)[0]->activate(pEnv, 0);
661 return true;
664 void GeoSplitVertexArrayPumpGroup::masterClassicGeoJustDrawPump(
665 DrawEnv *pEnv,
666 const GeoIntegralProperty *lengths,
667 const GeoIntegralProperty *types,
668 const Geometry::MFPropertiesType *prop,
669 const Geometry::MFPropIndicesType *propIdx,
670 UInt32 uiNumInstances)
672 #ifdef DEBUG_WHICH_PUMP
673 static bool bPrinted = false;
675 if(bPrinted == false)
677 fprintf(stderr,
678 "GeoSplitVertexArrayPumpGroup::masterClassicGeoJustDrawPump\n");
679 bPrinted = true;
681 #endif
683 Window *win = pEnv->getWindow();
685 // check for empty geometry
686 if(types == NULL || types->size() == 0)
687 return;
689 if(!pumpInternalSetup(types, true))
690 return;
691 if(!pumpInternalSetup(lengths, false))
692 return;
694 PumpData pumpData;
696 pumpData.lengths = lengths;
697 pumpData.types = types;
698 pumpData.prop = prop;
699 pumpData.propIdx = propIdx;
701 UInt16 nattrib = prop->size32();
703 for(UInt16 i = 0; i < nattrib; ++i)
705 if(pumpGLSetup(pumpData, i) == false)
706 continue;
709 // Length handling. Special case: no length given
711 UInt32 curlen;
712 UInt32 nprims;
714 // no lengths? use all available data for the first type
715 if(lengths == NULL)
717 if(types->size() != 1)
719 SWARNING << "GeoVertexArrayPumpGroup::masterAttribGeoPump: "
720 << "No lengths, but more than one type?!"
721 << endLog;
722 return;
725 nprims = 1;
727 if(propIdx->size() != 0 && (*propIdx)[0] != NULL)
729 curlen = (*propIdx)[0]->size32();
731 else
733 curlen = (*prop)[0]->size32();
736 else
738 nprims = types->size32();
739 lengths->getValue(curlen, 0);
742 // global attribs?
743 globalAttrib(pumpData, Geometry::NormalsIndex, NormalsPumpSlot);
744 globalAttrib(pumpData, Geometry::ColorsIndex, ColorsPumpSlot);
745 globalAttrib(pumpData, Geometry::TexCoordsIndex, TexCoordsPumpSlot);
747 if(win->hasExtOrVersion(_extSecondaryColor, 0x0104) == true)
749 globalExtAttrib(pumpData, Geometry::SecondaryColorsIndex,
750 SecColorsPumpSlot, win );
753 if(win->hasExtOrVersion(_extMultitexture, 0x0103, 0x0200) == true)
755 globalExtMultiAttrib(pumpData, Geometry::TexCoords1Index,
756 TexCoords1PumpSlot, GL_TEXTURE1_ARB, win);
757 globalExtMultiAttrib(pumpData, Geometry::TexCoords1Index,
758 TexCoords2PumpSlot, GL_TEXTURE2_ARB, win);
759 globalExtMultiAttrib(pumpData, Geometry::TexCoords1Index,
760 TexCoords3PumpSlot, GL_TEXTURE3_ARB, win);
761 globalExtMultiAttrib(pumpData, Geometry::TexCoords1Index,
762 TexCoords4PumpSlot, GL_TEXTURE4_ARB, win);
763 globalExtMultiAttrib(pumpData, Geometry::TexCoords1Index,
764 TexCoords5PumpSlot, GL_TEXTURE5_ARB, win);
765 globalExtMultiAttrib(pumpData, Geometry::TexCoords1Index,
766 TexCoords6PumpSlot, GL_TEXTURE6_ARB, win);
767 globalExtMultiAttrib(pumpData, Geometry::TexCoords1Index,
768 TexCoords7PumpSlot, GL_TEXTURE7_ARB, win);
771 UInt32 vertindex = 0;
773 if(propIdx->size() != 0 && (*propIdx)[0] != NULL)
775 // Single Indexed
777 GeoIntegralProperty *index = (*propIdx)[0];
778 const UInt8 *indexData = index->getData();
779 GLenum indexFormat = index->getFormat();
780 UInt32 indexStride =
781 index->getStride() ? index->getStride() : index->getFormatSize() *
782 index->getDimension();
784 #if 0
785 index->activate(pEnv, 0);
787 if(index->isInVBO(pEnv))
789 #endif
790 indexData = NULL;
791 #if 0
793 #endif
795 if(uiNumInstances > 1)
797 OSGGETGLFUNCBYID_GL3_ES(glDrawElementsInstanced,
798 osgGlDrawElementsInstanced,
799 Geometry::getFuncIdDrawElementsInstanced(),
800 win);
802 for(UInt32 primindex = 0; primindex < nprims; ++primindex)
804 if(primindex < lengths->size())
805 curlen = lengths->getValue<UInt32>(primindex);
807 if(curlen > 0)
809 osgGlDrawElementsInstanced(
810 types->getValue<UInt16>(primindex),
811 curlen,
812 indexFormat,
813 indexData + vertindex * indexStride,
814 uiNumInstances );
816 vertindex += curlen;
820 else
822 for(UInt32 primindex = 0; primindex < nprims; ++primindex)
824 if(primindex < lengths->size())
825 curlen = lengths->getValue<UInt32>(primindex);
827 if(curlen > 0)
829 glDrawElements(types->getValue<UInt16>(primindex),
830 curlen,
831 indexFormat,
832 indexData + vertindex * indexStride);
834 vertindex += curlen;
839 #if 0
840 index->deactivate(pEnv, 0);
841 #endif
843 else
845 if(uiNumInstances > 1)
847 OSGGETGLFUNCBYID_GL3_ES(glDrawArraysInstanced,
848 osgGlDrawArraysInstanced,
849 Geometry::getFuncIdDrawArraysInstanced(),
850 win);
851 // Non-indexed
852 for(UInt32 primindex = 0; primindex < nprims; ++primindex)
854 if(primindex < lengths->size())
855 curlen = lengths->getValue<UInt32>(primindex);
857 if(curlen > 0)
859 osgGlDrawArraysInstanced(
860 types->getValue<UInt16>(primindex),
861 vertindex,
862 curlen,
863 uiNumInstances);
865 vertindex += curlen;
869 else
871 // Non-indexed
872 for(UInt32 primindex = 0; primindex < nprims; ++primindex)
874 if(primindex < lengths->size())
875 curlen = lengths->getValue<UInt32>(primindex);
877 if(curlen > 0)
879 glDrawArrays(types->getValue<UInt16>(primindex), vertindex,
880 curlen);
881 vertindex += curlen;
888 bool GeoSplitVertexArrayPumpGroup::masterClassicGeoShutdownPump(
889 DrawEnv *pEnv,
890 const GeoIntegralProperty *lengths,
891 const GeoIntegralProperty *types,
892 const Geometry::MFPropertiesType *prop,
893 const Geometry::MFPropIndicesType *propIdx)
895 #ifdef DEBUG_WHICH_PUMP
896 static bool bPrinted = false;
898 if(bPrinted == false)
900 fprintf(stderr,
901 "GeoSplitVertexArrayPumpGroup::masterClassicGeoShutdownPump\n");
902 bPrinted = true;
904 #endif
906 // Setup: get all the data
907 PumpData pumpData;
909 pumpData.lengths = lengths;
910 pumpData.types = types;
911 pumpData.prop = prop;
912 pumpData.propIdx = propIdx;
914 UInt16 nattrib = prop->size32();
916 for(UInt16 i = 0; i < nattrib; ++i)
918 if(pumpGLSetup(pumpData, i) == false)
919 continue;
922 // we need positions
923 if(pumpData.attribPtr[0] == NULL ||
924 pumpData.attribPtr[0]->getUseVBO() == false)
926 #ifdef DEBUG_WHICH_PUMP
927 static bool bPrinted1 = false;
929 if(bPrinted1 == false)
931 #endif
932 SWARNING << "GeoSplitVertexArrayPumpGroup::masterAttribGeoPump: "
933 << "No positions." << endLog;
935 return false;
936 #ifdef DEBUG_WHICH_PUMP
937 bPrinted1 = true;
939 #endif
942 for(Int16 i = nattrib - 1; i >= 0; --i)
944 if(pumpData.attribPtr[i] != NULL &&
945 pumpData.attribPtr[i]->size() != 1 )
947 pumpData.attribPtr[i]->deactivate(pEnv, i);
951 if(propIdx->size() != 0 && (*propIdx)[0] != NULL)
953 (*propIdx)[0]->deactivate(pEnv, 0);
956 return true;
959 #endif
962 bool GeoSplitVertexArrayPumpGroup::masterAttribGeoSetupPump(
963 DrawEnv *pEnv,
964 const GeoIntegralProperty *lengths,
965 const GeoIntegralProperty *types,
966 const Geometry::MFPropertiesType *prop,
967 const Geometry::MFPropIndicesType *propIdx,
968 bool withFallback)
970 #ifdef DEBUG_WHICH_PUMP
971 static bool bPrinted = false;
973 if(bPrinted == false)
975 fprintf(stderr,
976 "GeoSplitVertexArrayPumpGroup::masterAttribGeoSetupPump\n");
977 bPrinted = true;
979 #endif
981 // Setup: get all the data
982 PumpData pumpData;
984 pumpData.lengths = lengths;
985 pumpData.types = types;
986 pumpData.prop = prop;
987 pumpData.propIdx = propIdx;
989 UInt16 nattrib = prop->size32();
991 for(UInt16 i = 0; i < nattrib; ++i)
993 if(pumpGLSetup(pumpData, i) == false)
994 continue;
997 // we need positions
998 if(pumpData.attribPtr[0] == NULL ||
999 pumpData.attribPtr[0]->getUseVBO() == false)
1001 #ifdef DEBUG_WHICH_PUMP
1002 static bool bPrinted1 = false;
1004 if(bPrinted1 == false)
1006 #endif
1007 if(withFallback == false)
1009 SWARNING << "GeoSplitVertexArrayPumpGroup::masterAttribGeoPump: "
1010 << "No positions." << endLog;
1012 #ifdef DEBUG_WHICH_PUMP
1013 bPrinted1 = true;
1015 #endif
1016 return false;
1019 for(Int16 i = nattrib - 1; i >= 0; --i)
1021 if(pumpData.attribPtr[i] != NULL &&
1022 pumpData.attribPtr[i]->size() != 1 )
1024 pumpData.attribPtr[i]->activate(pEnv, i + 16); // XXX HACK
1028 return true;
1032 void GeoSplitVertexArrayPumpGroup::masterAttribGeoDrawPump(
1033 DrawEnv *pEnv,
1034 const GeoIntegralProperty *lengths,
1035 const GeoIntegralProperty *types,
1036 const Geometry::MFPropertiesType *prop,
1037 const Geometry::MFPropIndicesType *propIdx)
1039 #ifdef DEBUG_WHICH_PUMP
1040 static bool bPrinted = false;
1042 if(bPrinted == false)
1044 fprintf(stderr,
1045 "GeoSplitVertexArrayPumpGroup::masterAttribGeoDrawPump\n");
1046 bPrinted = true;
1048 #endif
1050 Window *win = pEnv->getWindow();
1052 // check for empty geometry
1053 if(types == NULL || types->size() == 0)
1054 return;
1056 if(!pumpInternalSetup(types, true))
1057 return;
1058 if(!pumpInternalSetup(lengths, false))
1059 return;
1061 attribPumpFunc attribFunc[Geometry::MaxAttribs];
1062 PumpData pumpData;
1064 pumpData.lengths = lengths;
1065 pumpData.types = types;
1066 pumpData.prop = prop;
1067 pumpData.propIdx = propIdx;
1069 UInt16 nattrib = prop->size32();
1071 for(UInt16 i = 0; i < nattrib; ++i)
1073 if(pumpGLSetup(pumpData, i) == false)
1074 continue;
1076 UInt16 formatIdx = pumpData.attribPtr[i]->getFormat () - formatBase;
1077 UInt16 dimIdx = pumpData.attribPtr[i]->getDimension() - 1;
1079 #if !defined(OSG_USE_OGLES_PROTOS) && !defined(OSG_USE_OGL3_PROTOS) && \
1080 !defined(OSG_USE_OGL4_PROTOS)
1081 UInt32 funcId = Window::invalidFunctionID;
1083 if(pumpData.attribPtr[i]->getNormalize() == true)
1085 funcId = normAttribPumpFuncIDs[formatIdx][dimIdx];
1087 if(funcId == Window::invalidFunctionID)
1089 SWARNING << "GeoVertexArrayPumpGroup::masterAttribGeoPump: "
1090 << "Invalid pump function for property " << i
1091 << " type " << pumpData.attribPtr[i]->getDimension()
1092 << "D " << formatNames[formatIdx] << " (normalizing)."
1093 << endLog;
1095 pumpData.attribData[i] = NULL;
1096 pumpData.attribPtr [i] = NULL;
1097 continue;
1100 else
1102 funcId = attribPumpFuncIDs[formatIdx][dimIdx];
1104 if(funcId == Window::invalidFunctionID)
1106 SWARNING << "GeoVertexArrayPumpGroup::masterAttribGeoPump: "
1107 << "Invalid pump function for property " << i
1108 << " type " << pumpData.attribPtr[i]->getDimension()
1109 << "D " << formatNames[formatIdx]
1110 << endLog;
1112 pumpData.attribData[i] = NULL;
1113 pumpData.attribPtr [i] = NULL;
1114 continue;
1118 attribFunc[i] = reinterpret_cast<attribPumpFunc>(
1119 win->getFunction(funcId));
1121 #else
1122 if(pumpData.attribPtr[i]->getNormalize() == true)
1124 attribFunc[i] = attribNormPumpFuncs[formatIdx][dimIdx];
1126 else
1128 attribFunc[i] = attribPumpFuncs[formatIdx][dimIdx];
1130 #endif
1132 if(attribFunc[i] == NULL)
1134 SWARNING << "GeoVertexArrayPumpGroup::masterAttribGeoPump: "
1135 << "Extension function for property " << i
1136 << " type " << pumpData.attribPtr[i]->getDimension()
1137 << "D " << formatNames[formatIdx]
1138 << " not supported by Window " << win
1139 << endLog;
1141 pumpData.attribData[i] = NULL;
1142 pumpData.attribPtr [i] = NULL;
1143 continue;
1147 // Length handling. Special case: no length given
1149 UInt32 curlen;
1150 UInt32 nprims;
1152 // no lengths? use all available data for the first type
1153 if(lengths == NULL)
1155 if(types->size() != 1)
1157 SWARNING << "GeoVertexArrayPumpGroup::masterAttribGeoPump: "
1158 << "No lengths, but more than one type?!"
1159 << endLog;
1160 return;
1163 nprims = 1;
1165 if(propIdx->size() != 0 && (*propIdx)[0] != NULL)
1167 curlen = (*propIdx)[0]->size32();
1169 else
1171 curlen = (*prop)[0]->size32();
1174 else
1176 nprims = types->size32();
1177 lengths->getValue(curlen, 0);
1180 // global attribs?
1181 for(Int16 i = 0; i < nattrib; ++i)
1183 if(pumpData.attribData[i] != NULL &&
1184 pumpData.attribPtr [i]->size() == 1 )
1186 attribFunc[i](i, pumpData.attribData[i]);
1187 pumpData.attribData[i] = NULL;
1191 UInt32 vertindex = 0;
1193 if(propIdx->size() != 0 && (*propIdx)[0] != NULL)
1195 // Single Indexed
1197 GeoIntegralProperty *index = (*propIdx)[0];
1198 const UInt8 *indexData = index->getData();
1199 GLenum indexFormat = index->getFormat();
1200 UInt32 indexStride =
1201 index->getStride() ? index->getStride() : index->getFormatSize() *
1202 index->getDimension();
1204 index->activate(pEnv, 0);
1206 if(index->isInVBO(pEnv))
1208 indexData = NULL;
1211 for(UInt32 primindex = 0; primindex < nprims; ++primindex)
1213 if(primindex < lengths->size())
1214 curlen = lengths->getValue<UInt32>(primindex);
1216 if(curlen > 0)
1218 glDrawElements(types->getValue<UInt16>(primindex),
1219 curlen,
1220 indexFormat,
1221 indexData + vertindex * indexStride);
1223 vertindex += curlen;
1227 index->deactivate(pEnv, 0);
1229 else
1231 // Non-indexed
1232 for(UInt32 primindex = 0; primindex < nprims; ++primindex)
1234 if(primindex < lengths->size())
1235 curlen = lengths->getValue<UInt32>(primindex);
1237 if(curlen > 0)
1239 glDrawArrays(types->getValue<UInt16>(primindex), vertindex,
1240 curlen);
1241 vertindex += curlen;
1247 bool GeoSplitVertexArrayPumpGroup::masterAttribGeoSetupPumpFull(
1248 DrawEnv *pEnv,
1249 const GeoIntegralProperty *lengths,
1250 const GeoIntegralProperty *types,
1251 const Geometry::MFPropertiesType *prop,
1252 const Geometry::MFPropIndicesType *propIdx,
1253 bool withFallback)
1255 #ifdef DEBUG_WHICH_PUMP
1256 static bool bPrinted = false;
1258 if(bPrinted == false)
1260 fprintf(stderr,
1261 "GeoSplitVertexArrayPumpGroup::masterAttribGeoSetupPumpFull\n");
1262 bPrinted = true;
1264 #endif
1266 // Setup: get all the data
1267 PumpData pumpData;
1269 pumpData.lengths = lengths;
1270 pumpData.types = types;
1271 pumpData.prop = prop;
1272 pumpData.propIdx = propIdx;
1274 UInt16 nattrib = prop->size32();
1276 for(UInt16 i = 0; i < nattrib; ++i)
1278 if(pumpGLSetup(pumpData, i) == false)
1279 continue;
1282 // we need positions
1283 if(pumpData.attribPtr[0] == NULL ||
1284 pumpData.attribPtr[0]->getUseVBO() == false)
1286 #ifdef DEBUG_WHICH_PUMP
1287 static bool bPrinted1 = false;
1289 if(bPrinted1 == false)
1291 #endif
1292 if(withFallback == false)
1294 SWARNING << "GeoSplitVertexArrayPumpGroup::masterAttribGeoPump: "
1295 << "No positions, or positions not in vbo." << endLog;
1297 #ifdef DEBUG_WHICH_PUMP
1298 bPrinted1 = true;
1300 #endif
1301 return false;
1304 for(Int16 i = nattrib - 1; i >= 0; --i)
1306 if(pumpData.attribPtr[i] != NULL &&
1307 pumpData.attribPtr[i]->size() != 1 )
1309 pumpData.attribPtr[i]->activate(pEnv, i + 16); // XXX HACK
1313 if(propIdx->size() != 0 && (*propIdx)[0] != NULL)
1315 (*propIdx)[0]->activate(pEnv, 0);
1318 return true;
1321 void GeoSplitVertexArrayPumpGroup::masterAttribGeoJustDrawPump(
1322 DrawEnv *pEnv,
1323 const GeoIntegralProperty *lengths,
1324 const GeoIntegralProperty *types,
1325 const Geometry::MFPropertiesType *prop,
1326 const Geometry::MFPropIndicesType *propIdx,
1327 UInt32 uiNumInstances)
1329 #ifdef DEBUG_WHICH_PUMP
1330 static bool bPrinted = false;
1332 if(bPrinted == false)
1334 fprintf(stderr,
1335 "GeoSplitVertexArrayPumpGroup::masterAttribGeoJustDrawPump\n");
1336 bPrinted = true;
1338 #endif
1340 Window *win = pEnv->getWindow();
1342 // check for empty geometry
1343 if(types == NULL || types->size() == 0)
1344 return;
1346 if(!pumpInternalSetup(types, true))
1347 return;
1348 if(!pumpInternalSetup(lengths, false))
1349 return;
1351 attribPumpFunc attribFunc[Geometry::MaxAttribs];
1352 PumpData pumpData;
1354 pumpData.lengths = lengths;
1355 pumpData.types = types;
1356 pumpData.prop = prop;
1357 pumpData.propIdx = propIdx;
1359 UInt16 nattrib = prop->size32();
1361 for(UInt16 i = 0; i < nattrib; ++i)
1363 if(pumpGLSetup(pumpData, i) == false)
1364 continue;
1366 UInt16 formatIdx = pumpData.attribPtr[i]->getFormat () - formatBase;
1367 UInt16 dimIdx = pumpData.attribPtr[i]->getDimension() - 1;
1369 #if !defined(OSG_USE_OGLES_PROTOS) && !defined(OSG_USE_OGL3_PROTOS) && \
1370 !defined(OSG_USE_OGL4_PROTOS)
1371 UInt32 funcId = Window::invalidFunctionID;
1373 if(pumpData.attribPtr[i]->getNormalize() == true)
1375 funcId = normAttribPumpFuncIDs[formatIdx][dimIdx];
1377 if(funcId == Window::invalidFunctionID)
1379 SWARNING << "GeoVertexArrayPumpGroup::masterAttribGeoPump: "
1380 << "Invalid pump function for property " << i
1381 << " type " << pumpData.attribPtr[i]->getDimension()
1382 << "D " << formatNames[formatIdx] << " (normalizing)."
1383 << endLog;
1385 pumpData.attribData[i] = NULL;
1386 pumpData.attribPtr [i] = NULL;
1387 continue;
1390 else
1392 funcId = attribPumpFuncIDs[formatIdx][dimIdx];
1394 if(funcId == Window::invalidFunctionID)
1396 SWARNING << "GeoVertexArrayPumpGroup::masterAttribGeoPump: "
1397 << "Invalid pump function for property " << i
1398 << " type " << pumpData.attribPtr[i]->getDimension()
1399 << "D " << formatNames[formatIdx]
1400 << endLog;
1402 pumpData.attribData[i] = NULL;
1403 pumpData.attribPtr [i] = NULL;
1404 continue;
1408 attribFunc[i] = reinterpret_cast<attribPumpFunc>(
1409 win->getFunction(funcId));
1411 #else
1412 if(pumpData.attribPtr[i]->getNormalize() == true)
1414 attribFunc[i] = attribNormPumpFuncs[formatIdx][dimIdx];
1416 else
1418 attribFunc[i] = attribPumpFuncs[formatIdx][dimIdx];
1420 #endif
1422 if(attribFunc[i] == NULL)
1424 SWARNING << "GeoVertexArrayPumpGroup::masterAttribGeoPump: "
1425 << "Extension function for property " << i
1426 << " type " << pumpData.attribPtr[i]->getDimension()
1427 << "D " << formatNames[formatIdx]
1428 << " not supported by Window " << win
1429 << endLog;
1431 pumpData.attribData[i] = NULL;
1432 pumpData.attribPtr [i] = NULL;
1433 continue;
1437 // Length handling. Special case: no length given
1439 UInt32 curlen;
1440 UInt32 nprims;
1442 // no lengths? use all available data for the first type
1443 if(lengths == NULL)
1445 if(types->size() != 1)
1447 SWARNING << "GeoVertexArrayPumpGroup::masterAttribGeoPump: "
1448 << "No lengths, but more than one type?!"
1449 << endLog;
1450 return;
1453 nprims = 1;
1455 if(propIdx->size() != 0 && (*propIdx)[0] != NULL)
1457 curlen = (*propIdx)[0]->size32();
1459 else
1461 curlen = (*prop)[0]->size32();
1464 else
1466 nprims = types->size32();
1467 lengths->getValue(curlen, 0);
1470 // global attribs?
1471 for(Int16 i = 0; i < nattrib; ++i)
1473 if(pumpData.attribData[i] != NULL &&
1474 pumpData.attribPtr [i]->size() == 1 )
1476 attribFunc[i](i, pumpData.attribData[i]);
1477 pumpData.attribData[i] = NULL;
1481 UInt32 vertindex = 0;
1483 if(propIdx->size() != 0 && (*propIdx)[0] != NULL)
1485 // Single Indexed
1487 GeoIntegralProperty *index = (*propIdx)[0];
1488 const UInt8 *indexData = index->getData();
1489 GLenum indexFormat = index->getFormat();
1490 UInt32 indexStride =
1491 index->getStride() ? index->getStride() : index->getFormatSize() *
1492 index->getDimension();
1494 #if 0
1495 index->activate(pEnv, 0);
1497 if(index->isInVBO(pEnv))
1499 #endif
1500 indexData = NULL;
1501 #if 0
1503 #endif
1505 if(uiNumInstances > 1)
1507 OSGGETGLFUNCBYID_GL3_ES(glDrawElementsInstanced,
1508 osgGlDrawElementsInstanced,
1509 Geometry::getFuncIdDrawElementsInstanced(),
1510 win);
1512 for(UInt32 primindex = 0; primindex < nprims; ++primindex)
1514 if(primindex < lengths->size())
1515 curlen = lengths->getValue<UInt32>(primindex);
1517 if(curlen > 0)
1519 osgGlDrawElementsInstanced(
1520 types->getValue<UInt16>(primindex),
1521 curlen,
1522 indexFormat,
1523 indexData + vertindex * indexStride,
1524 uiNumInstances );
1526 vertindex += curlen;
1530 else
1532 for(UInt32 primindex = 0; primindex < nprims; ++primindex)
1534 if(primindex < lengths->size())
1535 curlen = lengths->getValue<UInt32>(primindex);
1537 if(curlen > 0)
1539 glDrawElements(types->getValue<UInt16>(primindex),
1540 curlen,
1541 indexFormat,
1542 indexData + vertindex * indexStride);
1544 vertindex += curlen;
1549 #if 0
1550 index->deactivate(pEnv, 0);
1551 #endif
1553 else
1555 if(uiNumInstances > 1)
1557 OSGGETGLFUNCBYID_GL3_ES(glDrawArraysInstanced,
1558 osgGlDrawArraysInstanced,
1559 Geometry::getFuncIdDrawArraysInstanced(),
1560 win);
1562 // Non-indexed
1563 for(UInt32 primindex = 0; primindex < nprims; ++primindex)
1565 if(primindex < lengths->size())
1566 curlen = lengths->getValue<UInt32>(primindex);
1568 if(curlen > 0)
1570 osgGlDrawArraysInstanced(
1571 types->getValue<UInt16>(primindex),
1572 vertindex,
1573 curlen,
1574 uiNumInstances );
1576 vertindex += curlen;
1580 else
1582 // Non-indexed
1583 for(UInt32 primindex = 0; primindex < nprims; ++primindex)
1585 if(primindex < lengths->size())
1586 curlen = lengths->getValue<UInt32>(primindex);
1588 if(curlen > 0)
1590 glDrawArrays(types->getValue<UInt16>(primindex), vertindex,
1591 curlen);
1592 vertindex += curlen;
1599 bool GeoSplitVertexArrayPumpGroup::masterAttribGeoShutdownPump(
1600 DrawEnv *pEnv,
1601 const GeoIntegralProperty *lengths,
1602 const GeoIntegralProperty *types,
1603 const Geometry::MFPropertiesType *prop,
1604 const Geometry::MFPropIndicesType *propIdx)
1606 #ifdef DEBUG_WHICH_PUMP
1607 static bool bPrinted = false;
1609 if(bPrinted == false)
1611 fprintf(stderr,
1612 "GeoSplitVertexArrayPumpGroup::masterAttribGeoShutdownPump\n");
1613 bPrinted = true;
1615 #endif
1617 // Setup: get all the data
1618 PumpData pumpData;
1620 pumpData.lengths = lengths;
1621 pumpData.types = types;
1622 pumpData.prop = prop;
1623 pumpData.propIdx = propIdx;
1625 UInt16 nattrib = prop->size32();
1627 for(UInt16 i = 0; i < nattrib; ++i)
1629 if(pumpGLSetup(pumpData, i) == false)
1630 continue;
1633 // we need positions
1634 if(pumpData.attribPtr[0] == NULL ||
1635 pumpData.attribPtr[0]->getUseVBO() == false)
1637 #ifdef DEBUG_WHICH_PUMP
1638 static bool bPrinted1 = false;
1640 if(bPrinted1 == false)
1642 #endif
1643 SWARNING << "GeoSplitVertexArrayPumpGroup::masterAttribGeoPump: "
1644 << "No positions." << endLog;
1646 #ifdef DEBUG_WHICH_PUMP
1647 bPrinted1 = true;
1649 #endif
1650 return false;
1653 for(Int16 i = nattrib - 1; i >= 0; --i)
1655 if(pumpData.attribPtr[i] != NULL &&
1656 pumpData.attribPtr[i]->size() != 1 )
1658 pumpData.attribPtr[i]->deactivate(pEnv, i + 16); // XXX HACK
1662 if(propIdx->size() != 0 && (*propIdx)[0] != NULL)
1664 (*propIdx)[0]->deactivate(pEnv, 0);
1667 return true;
1670 OSG_END_NAMESPACE