1 #include <osg/Config>
2 #ifndef OSG_USE_DEPRECATED_GEOMETRY_METHODS
3 #define OSG_USE_DEPRECATED_GEOMETRY_METHODS 1
4 #endif
5
6 #include <osg/Geometry>
7 #include <osg/Notify>
8 #include <osg/io_utils>
9
10 #include <osgDB/Registry>
11 #include <osgDB/Input>
12 #include <osgDB/ParameterOutput>
13
14 #include <string.h>
15
16 using namespace osg;
17 using namespace osgDB;
18
19 // forward declare functions to use later.
20 bool Geometry_readLocalData(Object& obj, Input& fr);
21 bool Geometry_writeLocalData(const Object& obj, Output& fw);
22
23 bool Geometry_matchBindingTypeStr(const char* str,deprecated_osg::Geometry::AttributeBinding& mode);
24 const char* Geometry_getBindingTypeStr(deprecated_osg::Geometry::AttributeBinding mode);
25
26 bool Geometry_matchPrimitiveModeStr(const char* str,GLenum& mode);
27 const char* Geometry_getPrimitiveModeStr(GLenum mode);
28
29 Array* Array_readLocalData(Input& fr);
30
31 bool Primitive_readLocalData(Input& fr,osg::Geometry& geom);
32
33 //register the read and write functions with the osgDB::Registry.
34 REGISTER_DOTOSGWRAPPER(Geometry)
35 (
36 new osg::Geometry,
37 "Geometry",
38 "Object Drawable Geometry",
39 &Geometry_readLocalData,
40 &Geometry_writeLocalData,
41 DotOsgWrapper::READ_AND_WRITE
42 );
43
Geometry_readLocalData(Object & obj,Input & fr)44 bool Geometry_readLocalData(Object& obj, Input& fr)
45 {
46 bool iteratorAdvanced = false;
47
48 deprecated_osg::Geometry& geom = static_cast<deprecated_osg::Geometry&>(obj);
49
50 if (fr.matchSequence("Primitives %i {") || fr.matchSequence("PrimitiveSets %i {") )
51 {
52 int entry = fr[1].getNoNestedBrackets();
53
54 int capacity;
55 fr[1].getInt(capacity);
56
57 Geometry::PrimitiveSetList& primitives = geom.getPrimitiveSetList();
58 if (capacity>0) primitives.reserve(capacity);
59
60
61 fr += 3;
62
63
64 while (!fr.eof() && fr[0].getNoNestedBrackets()>entry)
65 {
66 if (!Primitive_readLocalData(fr,geom)) fr.advanceOverCurrentFieldOrBlock();
67 }
68
69 ++fr;
70
71 iteratorAdvanced = true;
72
73 }
74
75 if (fr[0].matchWord("VertexArray"))
76 {
77 if (fr.matchSequence("VertexArray %i {"))
78 {
79
80 int entry = fr[0].getNoNestedBrackets();
81
82 int capacity;
83 fr[1].getInt(capacity);
84
85 Vec3Array* vertices = new Vec3Array;
86 vertices->reserve(capacity);
87
88 fr += 3;
89
90 while (!fr.eof() && fr[0].getNoNestedBrackets()>entry)
91 {
92 Vec3 v;
93 if (fr[0].getFloat(v.x()) && fr[1].getFloat(v.y()) && fr[2].getFloat(v.z()))
94 {
95 fr += 3;
96 vertices->push_back(v);
97 }
98 else
99 {
100 ++fr;
101 }
102 }
103
104 geom.setVertexArray(vertices);
105
106 iteratorAdvanced = true;
107 ++fr;
108
109 }
110 else
111 {
112 // post 0.9.3 releases.
113 ++fr;
114 Array* vertices = Array_readLocalData(fr);
115 if (vertices)
116 {
117 geom.setVertexArray(vertices);
118 }
119 iteratorAdvanced = true;
120 }
121 }
122
123 if (fr[0].matchWord("VertexIndices"))
124 {
125 ++fr;
126
127 IndexArray* indices = dynamic_cast<IndexArray*>(Array_readLocalData(fr));
128 if (indices)
129 {
130 geom.setVertexIndices(indices);
131 }
132
133 iteratorAdvanced = true;
134 }
135
136
137 deprecated_osg::Geometry::AttributeBinding normalBinding = deprecated_osg::Geometry::BIND_OFF;
138 if (fr[0].matchWord("NormalBinding") && Geometry_matchBindingTypeStr(fr[1].getStr(),normalBinding))
139 {
140 fr+=2;
141 iteratorAdvanced = true;
142 }
143
144 if (fr[0].matchWord("NormalArray"))
145 {
146 if (fr.matchSequence("NormalArray %i {"))
147 {
148 // pre 0.9.3 releases..
149 int entry = fr[0].getNoNestedBrackets();
150
151 int capacity;
152 fr[1].getInt(capacity);
153
154 Vec3Array* normals = new Vec3Array;
155 normals->reserve(capacity);
156
157 fr += 3;
158
159 while (!fr.eof() && fr[0].getNoNestedBrackets()>entry)
160 {
161 Vec3 v;
162 if (fr[0].getFloat(v.x()) && fr[1].getFloat(v.y()) && fr[2].getFloat(v.z()))
163 {
164 fr += 3;
165 normals->push_back(v);
166 }
167 else
168 {
169 ++fr;
170 }
171 }
172
173 geom.setNormalArray(normals);
174
175 iteratorAdvanced = true;
176 ++fr;
177 }
178 else
179 {
180 // post 0.9.3 releases.
181 ++fr;
182 Array* normals = Array_readLocalData(fr);
183 if (normals)
184 {
185 geom.setNormalArray(normals);
186 }
187 iteratorAdvanced = true;
188 }
189
190 geom.setNormalBinding(normalBinding);
191 }
192 if (fr[0].matchWord("NormalIndices"))
193 {
194 ++fr;
195 IndexArray* indices = dynamic_cast<IndexArray*>(Array_readLocalData(fr));
196 if (indices)
197 {
198 geom.setNormalIndices(indices);
199 }
200 iteratorAdvanced = true;
201 }
202
203 deprecated_osg::Geometry::AttributeBinding colorBinding = deprecated_osg::Geometry::BIND_OFF;
204 if (fr[0].matchWord("ColorBinding") && Geometry_matchBindingTypeStr(fr[1].getStr(),colorBinding))
205 {
206 fr+=2;
207 iteratorAdvanced = true;
208 }
209
210 if (fr[0].matchWord("ColorArray"))
211 {
212 ++fr;
213 Array* colors = Array_readLocalData(fr);
214 if (colors)
215 {
216 geom.setColorArray(colors);
217 geom.setColorBinding(colorBinding);
218 }
219 iteratorAdvanced = true;
220 }
221
222 if (fr[0].matchWord("ColorIndices"))
223 {
224 ++fr;
225 IndexArray* indices = dynamic_cast<IndexArray*>(Array_readLocalData(fr));
226 if (indices)
227 {
228 geom.setColorIndices(indices);
229 }
230 iteratorAdvanced = true;
231 }
232
233
234 deprecated_osg::Geometry::AttributeBinding secondaryColorBinding = deprecated_osg::Geometry::BIND_OFF;
235 if (fr[0].matchWord("SecondaryColorBinding") && Geometry_matchBindingTypeStr(fr[1].getStr(),secondaryColorBinding))
236 {
237 fr+=2;
238 iteratorAdvanced = true;
239 }
240
241 if (fr[0].matchWord("SecondaryColorArray"))
242 {
243 ++fr;
244 Array* colors = Array_readLocalData(fr);
245 if (colors)
246 {
247 geom.setSecondaryColorArray(colors);
248 geom.setSecondaryColorBinding(secondaryColorBinding);
249 }
250 iteratorAdvanced = true;
251 }
252
253 if (fr[0].matchWord("SecondaryColorIndices"))
254 {
255 ++fr;
256 IndexArray* indices = dynamic_cast<IndexArray*>(Array_readLocalData(fr));
257 if (indices)
258 {
259 geom.setSecondaryColorIndices(indices);
260 }
261 iteratorAdvanced = true;
262 }
263
264
265 deprecated_osg::Geometry::AttributeBinding fogCoordBinding = deprecated_osg::Geometry::BIND_OFF;
266 if (fr[0].matchWord("FogCoordBinding") && Geometry_matchBindingTypeStr(fr[1].getStr(),fogCoordBinding))
267 {
268 fr+=2;
269 iteratorAdvanced = true;
270 }
271
272 if (fr[0].matchWord("FogCoordArray"))
273 {
274 ++fr;
275 Array* fogcoords = Array_readLocalData(fr);
276 if (fogcoords)
277 {
278 geom.setFogCoordArray(fogcoords);
279 geom.setFogCoordBinding(fogCoordBinding);
280 }
281 iteratorAdvanced = true;
282 }
283
284 if (fr[0].matchWord("FogCoordIndices"))
285 {
286 ++fr;
287 IndexArray* indices = dynamic_cast<IndexArray*>(Array_readLocalData(fr));
288 if (indices)
289 {
290 geom.setFogCoordIndices(indices);
291 }
292 iteratorAdvanced = true;
293 }
294
295
296 if (fr.matchSequence("TexCoordArray %i"))
297 {
298 int unit=0;
299 fr[1].getInt(unit);
300
301 fr+=2;
302 Array* texcoords = Array_readLocalData(fr);
303 if (texcoords)
304 {
305 geom.setTexCoordArray(unit,texcoords);
306 }
307 iteratorAdvanced = true;
308
309 }
310
311 if (fr.matchSequence("TexCoordIndices %i"))
312 {
313 int unit=0;
314 fr[1].getInt(unit);
315
316 fr+=2;
317 IndexArray* indices = dynamic_cast<IndexArray*>(Array_readLocalData(fr));
318 if (indices)
319 {
320 geom.setTexCoordIndices(unit,indices);
321 }
322 iteratorAdvanced = true;
323 }
324
325 deprecated_osg::Geometry::AttributeBinding vertexAttribBinding = deprecated_osg::Geometry::BIND_OFF;
326 if (fr.matchSequence("VertexAttribBinding %i %w") && Geometry_matchBindingTypeStr(fr[2].getStr(),vertexAttribBinding))
327 {
328 int unit=0;
329 fr[1].getInt(unit);
330 fr+=3;
331 iteratorAdvanced = true;
332 }
333
334 bool vertexAttribNormalize = false;
335 if (fr.matchSequence("VertexAttribNormalize %i %w"))
336 {
337 int unit=0;
338 fr[1].getInt(unit);
339
340 vertexAttribNormalize = fr[2].matchString("TRUE");
341
342 fr+=3;
343 iteratorAdvanced = true;
344 }
345
346
347 if (fr.matchSequence("VertexAttribArray %i"))
348 {
349 int unit=0;
350 fr[1].getInt(unit);
351
352 fr+=2;
353 Array* vertexattrib = Array_readLocalData(fr);
354 if (vertexattrib)
355 {
356 geom.setVertexAttribArray(unit,vertexattrib);
357 geom.setVertexAttribBinding(unit,vertexAttribBinding);
358 geom.setVertexAttribNormalize(unit,vertexAttribNormalize);
359 }
360 iteratorAdvanced = true;
361
362 }
363
364 if (fr.matchSequence("VertexAttribIndices %i"))
365 {
366 int unit=0;
367 fr[1].getInt(unit);
368
369 fr+=2;
370 IndexArray* indices = dynamic_cast<IndexArray*>(Array_readLocalData(fr));
371 if (indices)
372 {
373 geom.setVertexAttribIndices(unit,indices);
374 }
375 iteratorAdvanced = true;
376 }
377
378 return iteratorAdvanced;
379 }
380
381
Array_readLocalData(Input & fr)382 Array* Array_readLocalData(Input& fr)
383 {
384 if (fr[0].matchWord("Use"))
385 {
386 if (fr[1].isString())
387 {
388 Object* obj = fr.getObjectForUniqueID(fr[1].getStr());
389 if (obj)
390 {
391 fr+=2;
392 return dynamic_cast<Array*>(obj);
393 }
394 }
395
396 osg::notify(osg::WARN)<<"Warning: invalid uniqueID found in file."<<std::endl;
397 return NULL;
398 }
399
400 std::string uniqueID;
401 if (fr[0].matchWord("UniqueID") && fr[1].isString())
402 {
403 uniqueID = fr[1].getStr();
404 fr += 2;
405 }
406
407
408 int entry = fr[0].getNoNestedBrackets();
409
410 const char* arrayName = fr[0].getStr();
411
412 unsigned int capacity = 0;
413 fr[1].getUInt(capacity);
414 ++fr;
415
416 fr += 2;
417
418
419 Array* return_array = 0;
420
421 if (strcmp(arrayName,"ByteArray")==0)
422 {
423 ByteArray* array = new ByteArray;
424 array->reserve(capacity);
425 while (!fr.eof() && fr[0].getNoNestedBrackets()>entry)
426 {
427 int int_value;
428 if (fr[0].getInt(int_value))
429 {
430 ++fr;
431 array->push_back(int_value);
432 }
433 else ++fr;
434 }
435 ++fr;
436
437 return_array = array;
438 }
439 else if (strcmp(arrayName,"ShortArray")==0)
440 {
441 ShortArray* array = new ShortArray;
442 array->reserve(capacity);
443 while (!fr.eof() && fr[0].getNoNestedBrackets()>entry)
444 {
445 int int_value;
446 if (fr[0].getInt(int_value))
447 {
448 ++fr;
449 array->push_back(int_value);
450 }
451 else ++fr;
452 }
453 ++fr;
454 return_array = array;
455 }
456 else if (strcmp(arrayName,"IntArray")==0)
457 {
458 IntArray* array = new IntArray;
459 array->reserve(capacity);
460 while (!fr.eof() && fr[0].getNoNestedBrackets()>entry)
461 {
462 int int_value;
463 if (fr[0].getInt(int_value))
464 {
465 ++fr;
466 array->push_back(int_value);
467 }
468 else ++fr;
469 }
470 ++fr;
471 return_array = array;
472 }
473 else if (strcmp(arrayName,"UByteArray")==0)
474 {
475 UByteArray* array = new UByteArray;
476 array->reserve(capacity);
477 while (!fr.eof() && fr[0].getNoNestedBrackets()>entry)
478 {
479 unsigned int uint_value;
480 if (fr[0].getUInt(uint_value))
481 {
482 ++fr;
483 array->push_back(uint_value);
484 }
485 else ++fr;
486 }
487 ++fr;
488 return_array = array;
489 }
490 else if (strcmp(arrayName,"UShortArray")==0)
491 {
492 UShortArray* array = new UShortArray;
493 array->reserve(capacity);
494 while (!fr.eof() && fr[0].getNoNestedBrackets()>entry)
495 {
496 unsigned int uint_value;
497 if (fr[0].getUInt(uint_value))
498 {
499 ++fr;
500 array->push_back(uint_value);
501 }
502 else ++fr;
503 }
504 ++fr;
505 return_array = array;
506 }
507 else if (strcmp(arrayName,"UIntArray")==0)
508 {
509 UIntArray* array = new UIntArray;
510 array->reserve(capacity);
511 while (!fr.eof() && fr[0].getNoNestedBrackets()>entry)
512 {
513 unsigned int uint_value;
514 if (fr[0].getUInt(uint_value))
515 {
516 ++fr;
517 array->push_back(uint_value);
518 }
519 else ++fr;
520 }
521 ++fr;
522 return_array = array;
523 }
524 else if (strcmp(arrayName,"UVec4bArray")==0 || strcmp(arrayName,"Vec4ubArray")==0)
525 {
526 Vec4ubArray* array = new Vec4ubArray;
527 array->reserve(capacity);
528 while (!fr.eof() && fr[0].getNoNestedBrackets()>entry)
529 {
530 unsigned int r,g,b,a;
531 if (fr[0].getUInt(r) &&
532 fr[1].getUInt(g) &&
533 fr[2].getUInt(b) &&
534 fr[3].getUInt(a))
535 {
536 fr+=4;
537 array->push_back(osg::Vec4ub(r,g,b,a));
538 }
539 else ++fr;
540 }
541 ++fr;
542 return_array = array;
543 }
544 else if (strcmp(arrayName,"FloatArray")==0)
545 {
546 FloatArray* array = new FloatArray;
547 array->reserve(capacity);
548 while (!fr.eof() && fr[0].getNoNestedBrackets()>entry)
549 {
550 float float_value;
551 if (fr[0].getFloat(float_value))
552 {
553 ++fr;
554 array->push_back(float_value);
555 }
556 else ++fr;
557 }
558 ++fr;
559 return_array = array;
560 }
561 else if (strcmp(arrayName,"DoubleArray")==0)
562 {
563 DoubleArray* array = new DoubleArray;
564 array->reserve(capacity);
565 while (!fr.eof() && fr[0].getNoNestedBrackets()>entry)
566 {
567 double double_value;
568 if (fr[0].getFloat(double_value))
569 {
570 ++fr;
571 array->push_back(double_value);
572 }
573 else ++fr;
574 }
575 ++fr;
576 return_array = array;
577 }
578 else if (strcmp(arrayName,"Vec2Array")==0)
579 {
580 Vec2Array* array = new Vec2Array;
581 array->reserve(capacity);
582 while (!fr.eof() && fr[0].getNoNestedBrackets()>entry)
583 {
584 Vec2 v;
585 if (fr[0].getFloat(v.x()) && fr[1].getFloat(v.y()))
586 {
587 fr += 2;
588 array->push_back(v);
589 }
590 else ++fr;
591 }
592 ++fr;
593 return_array = array;
594 }
595 else if (strcmp(arrayName,"Vec2dArray")==0)
596 {
597 Vec2dArray* array = new Vec2dArray;
598 array->reserve(capacity);
599 while (!fr.eof() && fr[0].getNoNestedBrackets()>entry)
600 {
601 Vec2d v;
602 if (fr[0].getFloat(v.x()) && fr[1].getFloat(v.y()))
603 {
604 fr += 2;
605 array->push_back(v);
606 }
607 else ++fr;
608 }
609 ++fr;
610 return_array = array;
611 }
612 else if (strcmp(arrayName,"Vec3Array")==0)
613 {
614 Vec3Array* array = new Vec3Array;
615 array->reserve(capacity);
616 while (!fr.eof() && fr[0].getNoNestedBrackets()>entry)
617 {
618 Vec3 v;
619 if (fr[0].getFloat(v.x()) && fr[1].getFloat(v.y()) && fr[2].getFloat(v.z()))
620 {
621 fr += 3;
622 array->push_back(v);
623 }
624 else ++fr;
625 }
626 ++fr;
627 return_array = array;
628 }
629 else if (strcmp(arrayName,"Vec3dArray")==0)
630 {
631 Vec3dArray* array = new Vec3dArray;
632 array->reserve(capacity);
633 while (!fr.eof() && fr[0].getNoNestedBrackets()>entry)
634 {
635 Vec3d v;
636 if (fr[0].getFloat(v.x()) && fr[1].getFloat(v.y()) && fr[2].getFloat(v.z()))
637 {
638 fr += 3;
639 array->push_back(v);
640 }
641 else ++fr;
642 }
643 ++fr;
644 return_array = array;
645 }
646 else if (strcmp(arrayName,"Vec4Array")==0)
647 {
648 Vec4Array* array = new Vec4Array;
649 array->reserve(capacity);
650 while (!fr.eof() && fr[0].getNoNestedBrackets()>entry)
651 {
652 Vec4 v;
653 if (fr[0].getFloat(v.x()) && fr[1].getFloat(v.y()) && fr[2].getFloat(v.z()) && fr[3].getFloat(v.w()))
654 {
655 fr += 4;
656 array->push_back(v);
657 }
658 else ++fr;
659 }
660 ++fr;
661 return_array = array;
662 }
663 else if (strcmp(arrayName,"Vec4dArray")==0)
664 {
665 Vec4dArray* array = new Vec4dArray;
666 array->reserve(capacity);
667 while (!fr.eof() && fr[0].getNoNestedBrackets()>entry)
668 {
669 Vec4d v;
670 if (fr[0].getFloat(v.x()) && fr[1].getFloat(v.y()) && fr[2].getFloat(v.z()) && fr[3].getFloat(v.w()))
671 {
672 fr += 4;
673 array->push_back(v);
674 }
675 else ++fr;
676 }
677 ++fr;
678 return_array = array;
679 }
680 else if (strcmp(arrayName,"Vec2bArray")==0)
681 {
682 Vec2bArray* array = new Vec2bArray;
683 array->reserve(capacity);
684 while (!fr.eof() && fr[0].getNoNestedBrackets()>entry)
685 {
686 unsigned int r,g;
687 if (fr[0].getUInt(r) &&
688 fr[1].getUInt(g))
689 {
690 fr+=2;
691 array->push_back(osg::Vec2b(r,g));
692 }
693 else ++fr;
694 }
695 ++fr;
696 return_array = array;
697 }
698 else if (strcmp(arrayName,"Vec3bArray")==0)
699 {
700 Vec3bArray* array = new Vec3bArray;
701 array->reserve(capacity);
702 while (!fr.eof() && fr[0].getNoNestedBrackets()>entry)
703 {
704 unsigned int r,g,b;
705 if (fr[0].getUInt(r) &&
706 fr[1].getUInt(g) &&
707 fr[2].getUInt(b))
708 {
709 fr+=3;
710 array->push_back(osg::Vec3b(r,g,b));
711 }
712 else ++fr;
713 }
714 ++fr;
715 return_array = array;
716 }
717 else if (strcmp(arrayName,"Vec4bArray")==0)
718 {
719 Vec4bArray* array = new Vec4bArray;
720 array->reserve(capacity);
721 while (!fr.eof() && fr[0].getNoNestedBrackets()>entry)
722 {
723 unsigned int r,g,b,a;
724 if (fr[0].getUInt(r) &&
725 fr[1].getUInt(g) &&
726 fr[2].getUInt(b) &&
727 fr[3].getUInt(a))
728 {
729 fr+=4;
730 array->push_back(osg::Vec4b(r,g,b,a));
731 }
732 else ++fr;
733 }
734 ++fr;
735 return_array = array;
736 }
737 else if (strcmp(arrayName,"Vec2sArray")==0)
738 {
739 Vec2sArray* array = new Vec2sArray;
740 array->reserve(capacity);
741 while (!fr.eof() && fr[0].getNoNestedBrackets()>entry)
742 {
743 unsigned int r,g;
744 if (fr[0].getUInt(r) &&
745 fr[1].getUInt(g))
746 {
747 fr+=2;
748 array->push_back(osg::Vec2s(r,g));
749 }
750 else ++fr;
751 }
752 ++fr;
753 return_array = array;
754 }
755 else if (strcmp(arrayName,"Vec3sArray")==0)
756 {
757 Vec3sArray* array = new Vec3sArray;
758 array->reserve(capacity);
759 while (!fr.eof() && fr[0].getNoNestedBrackets()>entry)
760 {
761 unsigned int r,g,b;
762 if (fr[0].getUInt(r) &&
763 fr[1].getUInt(g) &&
764 fr[2].getUInt(b))
765 {
766 fr+=3;
767 array->push_back(osg::Vec3s(r,g,b));
768 }
769 else ++fr;
770 }
771 ++fr;
772 return_array = array;
773 }
774 else if (strcmp(arrayName,"Vec4sArray")==0)
775 {
776 Vec4sArray* array = new Vec4sArray;
777 array->reserve(capacity);
778 while (!fr.eof() && fr[0].getNoNestedBrackets()>entry)
779 {
780 unsigned int r,g,b,a;
781 if (fr[0].getUInt(r) &&
782 fr[1].getUInt(g) &&
783 fr[2].getUInt(b) &&
784 fr[3].getUInt(a))
785 {
786 fr+=4;
787 array->push_back(osg::Vec4s(r,g,b,a));
788 }
789 else ++fr;
790 }
791 ++fr;
792 return_array = array;
793 }
794
795 if (return_array)
796 {
797 if (!uniqueID.empty()) fr.registerUniqueIDForObject(uniqueID.c_str(),return_array);
798 }
799
800 return return_array;
801 }
802
803
Array_writeLocalData(const Array & array,Output & fw)804 bool Array_writeLocalData(const Array& array,Output& fw)
805 {
806 if (array.referenceCount()>1)
807 {
808 std::string uniqueID;
809 if (fw.getUniqueIDForObject(&array,uniqueID))
810 {
811 fw << "Use " << uniqueID << std::endl;
812 return true;
813 }
814 else
815 {
816 std::string uniqueID;
817 fw.createUniqueIDForObject(&array,uniqueID);
818 fw.registerUniqueIDForObject(&array,uniqueID);
819 fw << "UniqueID " << uniqueID << " ";
820 }
821 }
822
823
824 switch(array.getType())
825 {
826 case(Array::ByteArrayType):
827 {
828 fw<<array.className()<<" "<<array.getNumElements()<<std::endl;
829 const ByteArray::ElementDataType* base = static_cast<const ByteArray::ElementDataType*>(array.getDataPointer());
830 writeArrayAsInts(fw,&base[0], &base[array.getNumElements()]);
831 return true;
832 }
833 break;
834 case(Array::ShortArrayType):
835 {
836 fw<<array.className()<<" "<<array.getNumElements()<<std::endl;
837 const ShortArray::ElementDataType* base = static_cast<const ShortArray::ElementDataType*>(array.getDataPointer());
838 writeArray(fw,&base[0], &base[array.getNumElements()]);
839 return true;
840 }
841 break;
842 case(Array::IntArrayType):
843 {
844 fw<<array.className()<<" "<<array.getNumElements()<<std::endl;
845 const IntArray::ElementDataType* base = static_cast<const IntArray::ElementDataType*>(array.getDataPointer());
846 writeArray(fw,&base[0], &base[array.getNumElements()]);
847 return true;
848 }
849 break;
850 case(Array::UByteArrayType):
851 {
852 fw<<array.className()<<" "<<array.getNumElements()<<std::endl;
853 const UByteArray::ElementDataType* base = static_cast<const UByteArray::ElementDataType*>(array.getDataPointer());
854 writeArrayAsInts(fw,&base[0], &base[array.getNumElements()]);
855 return true;
856 }
857 break;
858 case(Array::UShortArrayType):
859 {
860 fw<<array.className()<<" "<<array.getNumElements()<<std::endl;
861 const UShortArray::ElementDataType* base = static_cast<const UShortArray::ElementDataType*>(array.getDataPointer());
862 writeArray(fw,&base[0], &base[array.getNumElements()]);
863 return true;
864 }
865 break;
866 case(Array::UIntArrayType):
867 {
868 fw<<array.className()<<" "<<array.getNumElements()<<std::endl;
869 const UIntArray::ElementDataType* base = static_cast<const UIntArray::ElementDataType*>(array.getDataPointer());
870 writeArray(fw,&base[0], &base[array.getNumElements()]);
871 return true;
872 }
873 break;
874 case(Array::Vec4ubArrayType):
875 {
876 fw<<array.className()<<" "<<array.getNumElements()<<std::endl;
877 const Vec4ubArray::ElementDataType* base = static_cast<const Vec4ubArray::ElementDataType*>(array.getDataPointer());
878 writeArray(fw,&base[0], &base[array.getNumElements()],1);
879 return true;
880 }
881 break;
882 case(Array::FloatArrayType):
883 {
884 fw<<array.className()<<" "<<array.getNumElements()<<std::endl;
885 const FloatArray::ElementDataType* base = static_cast<const FloatArray::ElementDataType*>(array.getDataPointer());
886 writeArray(fw,&base[0], &base[array.getNumElements()]);
887 return true;
888 }
889 break;
890 case(Array::Vec2ArrayType):
891 {
892 fw<<array.className()<<" "<<array.getNumElements()<<std::endl;
893 const Vec2Array::ElementDataType* base = static_cast<const Vec2Array::ElementDataType*>(array.getDataPointer());
894 writeArray(fw,&base[0], &base[array.getNumElements()],1);
895 return true;
896 }
897 break;
898 case(Array::Vec3ArrayType):
899 {
900 fw<<array.className()<<" "<<array.getNumElements()<<std::endl;
901 const Vec3Array::ElementDataType* base = static_cast<const Vec3Array::ElementDataType*>(array.getDataPointer());
902 writeArray(fw,&base[0], &base[array.getNumElements()],1);
903 return true;
904 }
905 break;
906 case(Array::Vec4ArrayType):
907 {
908 fw<<array.className()<<" "<<array.getNumElements()<<std::endl;
909 const Vec4Array::ElementDataType* base = static_cast<const Vec4Array::ElementDataType*>(array.getDataPointer());
910 writeArray(fw,&base[0], &base[array.getNumElements()],1);
911 return true;
912 }
913 break;
914 case(Array::DoubleArrayType):
915 {
916 int prec = fw.precision(15);
917 fw<<array.className()<<" "<<array.getNumElements()<<std::endl;
918 const DoubleArray::ElementDataType* base = static_cast<const DoubleArray::ElementDataType*>(array.getDataPointer());
919 writeArray(fw,&base[0], &base[array.getNumElements()]);
920 fw.precision(prec);
921 return true;
922 }
923 break;
924 case(Array::Vec2dArrayType):
925 {
926 int prec = fw.precision(15);
927 fw<<array.className()<<" "<<array.getNumElements()<<std::endl;
928 const Vec2dArray::ElementDataType* base = static_cast<const Vec2dArray::ElementDataType*>(array.getDataPointer());
929 writeArray(fw,&base[0], &base[array.getNumElements()],1);
930 fw.precision(prec);
931 return true;
932 }
933 break;
934 case(Array::Vec3dArrayType):
935 {
936 int prec = fw.precision(15);
937 fw<<array.className()<<" "<<array.getNumElements()<<std::endl;
938 const Vec3dArray::ElementDataType* base = static_cast<const Vec3dArray::ElementDataType*>(array.getDataPointer());
939 writeArray(fw,&base[0], &base[array.getNumElements()],1);
940 fw.precision(prec);
941 return true;
942 }
943 break;
944 case(Array::Vec4dArrayType):
945 {
946 int prec = fw.precision(15);
947 fw<<array.className()<<" "<<array.getNumElements()<<std::endl;
948 const Vec4dArray::ElementDataType* base = static_cast<const Vec4dArray::ElementDataType*>(array.getDataPointer());
949 writeArray(fw,&base[0], &base[array.getNumElements()],1);
950 fw.precision(prec);
951 return true;
952 }
953 break;
954 case(Array::Vec2sArrayType):
955 {
956 fw<<array.className()<<" "<<array.getNumElements()<<std::endl;
957 const Vec2sArray::ElementDataType* base = static_cast<const Vec2sArray::ElementDataType*>(array.getDataPointer());
958 writeArray(fw,&base[0], &base[array.getNumElements()], 3);
959 return true;
960 }
961 break;
962 case(Array::Vec3sArrayType):
963 {
964 fw<<array.className()<<" "<<array.getNumElements()<<std::endl;
965 const Vec3sArray::ElementDataType* base = static_cast<const Vec3sArray::ElementDataType*>(array.getDataPointer());
966 writeArray(fw,&base[0], &base[array.getNumElements()], 2);
967 return true;
968 }
969 break;
970 case(Array::Vec4sArrayType):
971 {
972 fw<<array.className()<<" "<<array.getNumElements()<<std::endl;
973 const Vec4sArray::ElementDataType* base = static_cast<const Vec4sArray::ElementDataType*>(array.getDataPointer());
974 writeArray(fw,&base[0], &base[array.getNumElements()], 1);
975 return true;
976 }
977 break;
978 case(Array::Vec2bArrayType):
979 {
980 fw<<array.className()<<" "<<array.getNumElements()<<std::endl;
981 const Vec2bArray::ElementDataType* base = static_cast<const Vec2bArray::ElementDataType*>(array.getDataPointer());
982 writeArray(fw,&base[0], &base[array.getNumElements()],1);
983 return true;
984 }
985 break;
986 case(Array::Vec3bArrayType):
987 {
988 fw<<array.className()<<" "<<array.getNumElements()<<std::endl;
989 const Vec3bArray::ElementDataType* base = static_cast<const Vec3bArray::ElementDataType*>(array.getDataPointer());
990 writeArray(fw,&base[0], &base[array.getNumElements()],1);
991 return true;
992 }
993 break;
994 case(Array::Vec4bArrayType):
995 {
996 fw<<array.className()<<" "<<array.getNumElements()<<std::endl;
997 const Vec4bArray::ElementDataType* base = static_cast<const Vec4bArray::ElementDataType*>(array.getDataPointer());
998 writeArray(fw,&base[0], &base[array.getNumElements()],1);
999 return true;
1000 }
1001 break;
1002 case(Array::ArrayType):
1003 default:
1004 return false;
1005 }
1006 }
1007
1008
Primitive_readLocalData(Input & fr,osg::Geometry & geom)1009 bool Primitive_readLocalData(Input& fr,osg::Geometry& geom)
1010 {
1011 bool iteratorAdvanced = false;
1012 bool firstMatched = false;
1013 if ((firstMatched = fr.matchSequence("DrawArrays %w %i %i %i")) ||
1014 fr.matchSequence("DrawArrays %w %i %i") )
1015 {
1016
1017 GLenum mode;
1018 Geometry_matchPrimitiveModeStr(fr[1].getStr(),mode);
1019
1020 int first;
1021 fr[2].getInt(first);
1022
1023 int count;
1024 fr[3].getInt(count);
1025
1026 int numInstances = 0;
1027 if (firstMatched)
1028 {
1029 fr[4].getInt(numInstances);
1030 fr += 5;
1031 }
1032 else
1033 {
1034 fr += 4;
1035 }
1036
1037 geom.addPrimitiveSet(new DrawArrays(mode, first, count, numInstances));
1038
1039
1040 iteratorAdvanced = true;
1041
1042 }
1043 else if ((firstMatched = fr.matchSequence("DrawArrayLengths %w %i %i %i {")) ||
1044 fr.matchSequence("DrawArrayLengths %w %i %i {") )
1045 {
1046 int entry = fr[1].getNoNestedBrackets();
1047
1048 GLenum mode;
1049 Geometry_matchPrimitiveModeStr(fr[1].getStr(),mode);
1050
1051 int first;
1052 fr[2].getInt(first);
1053
1054 int capacity;
1055 fr[3].getInt(capacity);
1056
1057 int numInstances = 0;
1058 if (firstMatched)
1059 {
1060 fr[4].getInt(numInstances);
1061 fr += 6;
1062 }
1063 else
1064 {
1065 fr += 5;
1066 }
1067
1068 DrawArrayLengths* prim = new DrawArrayLengths;
1069 prim->setMode(mode);
1070 prim->setNumInstances(numInstances);
1071 prim->setFirst(first);
1072 prim->reserve(capacity);
1073
1074 while (!fr.eof() && fr[0].getNoNestedBrackets()>entry)
1075 {
1076 unsigned int i;
1077 if (fr[0].getUInt(i))
1078 {
1079 prim->push_back(i);
1080 ++fr;
1081 }
1082 }
1083 ++fr;
1084
1085 geom.addPrimitiveSet(prim);
1086
1087 iteratorAdvanced = true;
1088 }
1089 else if ((firstMatched = fr.matchSequence("DrawElementsUByte %w %i %i {")) ||
1090 fr.matchSequence("DrawElementsUByte %w %i {"))
1091 {
1092 int entry = fr[1].getNoNestedBrackets();
1093
1094 GLenum mode;
1095 Geometry_matchPrimitiveModeStr(fr[1].getStr(),mode);
1096
1097 int capacity;
1098 fr[2].getInt(capacity);
1099
1100 int numInstances = 0;
1101 if (firstMatched)
1102 {
1103 fr[3].getInt(numInstances);
1104 fr += 5;
1105 }
1106 else
1107 {
1108 fr += 4;
1109 }
1110
1111 DrawElementsUByte* prim = new DrawElementsUByte;
1112 prim->setMode(mode);
1113 prim->setNumInstances(numInstances);
1114 prim->reserve(capacity);
1115
1116 while (!fr.eof() && fr[0].getNoNestedBrackets()>entry)
1117 {
1118 unsigned int i;
1119 if (fr[0].getUInt(i))
1120 {
1121 prim->push_back(i);
1122 ++fr;
1123 }
1124 }
1125 ++fr;
1126
1127 geom.addPrimitiveSet(prim);
1128
1129 iteratorAdvanced = true;
1130 }
1131 else if ((firstMatched = fr.matchSequence("DrawElementsUShort %w %i %i {")) ||
1132 fr.matchSequence("DrawElementsUShort %w %i {"))
1133 {
1134 int entry = fr[1].getNoNestedBrackets();
1135
1136 GLenum mode;
1137 Geometry_matchPrimitiveModeStr(fr[1].getStr(),mode);
1138
1139 int capacity;
1140 fr[2].getInt(capacity);
1141
1142 int numInstances = 0;
1143 if (firstMatched)
1144 {
1145 fr[3].getInt(numInstances);
1146 fr += 5;
1147 }
1148 else
1149 {
1150 fr += 4;
1151 }
1152
1153 DrawElementsUShort* prim = new DrawElementsUShort;
1154 prim->setMode(mode);
1155 prim->setNumInstances(numInstances);
1156 prim->reserve(capacity);
1157
1158 while (!fr.eof() && fr[0].getNoNestedBrackets()>entry)
1159 {
1160 unsigned int i;
1161 if (fr[0].getUInt(i))
1162 {
1163 prim->push_back(i);
1164 ++fr;
1165 }
1166 }
1167 ++fr;
1168
1169 geom.addPrimitiveSet(prim);
1170
1171 iteratorAdvanced = true;
1172 }
1173 else if ((firstMatched = fr.matchSequence("DrawElementsUInt %w %i %i {")) ||
1174 fr.matchSequence("DrawElementsUInt %w %i {"))
1175 {
1176 int entry = fr[1].getNoNestedBrackets();
1177
1178 GLenum mode;
1179 Geometry_matchPrimitiveModeStr(fr[1].getStr(),mode);
1180
1181 int capacity;
1182 fr[2].getInt(capacity);
1183
1184 int numInstances = 0;
1185 if (firstMatched)
1186 {
1187 fr[3].getInt(numInstances);
1188 fr += 5;
1189 }
1190 else
1191 {
1192 fr += 4;
1193 }
1194
1195 DrawElementsUInt* prim = new DrawElementsUInt;
1196 prim->setMode(mode);
1197 prim->setNumInstances(numInstances);
1198 prim->reserve(capacity);
1199
1200 while (!fr.eof() && fr[0].getNoNestedBrackets()>entry)
1201 {
1202 unsigned int i;
1203 if (fr[0].getUInt(i))
1204 {
1205 prim->push_back(i);
1206 ++fr;
1207 }
1208 }
1209 ++fr;
1210
1211 geom.addPrimitiveSet(prim);
1212
1213 iteratorAdvanced = true;
1214 }
1215
1216 return iteratorAdvanced;
1217 }
1218
Primitive_writeLocalData(const PrimitiveSet & prim,Output & fw)1219 bool Primitive_writeLocalData(const PrimitiveSet& prim,Output& fw)
1220 {
1221
1222 switch(prim.getType())
1223 {
1224 case(PrimitiveSet::DrawArraysPrimitiveType):
1225 {
1226 const DrawArrays& cprim = static_cast<const DrawArrays&>(prim);
1227 fw<<cprim.className()<<" "<<Geometry_getPrimitiveModeStr(cprim.getMode())<<" "<<cprim.getFirst()<<" "<<cprim.getCount();
1228 if (prim.getNumInstances()>0) fw<<" "<<prim.getNumInstances();
1229 fw<<std::endl;
1230 return true;
1231 }
1232 break;
1233 case(PrimitiveSet::DrawArrayLengthsPrimitiveType):
1234 {
1235 const DrawArrayLengths& cprim = static_cast<const DrawArrayLengths&>(prim);
1236 fw<<cprim.className()<<" "<<Geometry_getPrimitiveModeStr(cprim.getMode())<<" "<<cprim.getFirst()<<" "<<cprim.size();
1237 if (prim.getNumInstances()>0) fw<<" "<<prim.getNumInstances();
1238 fw<<std::endl;
1239 writeArray(fw,cprim.begin(),cprim.end());
1240 return true;
1241 }
1242 break;
1243 case(PrimitiveSet::DrawElementsUBytePrimitiveType):
1244 {
1245 const DrawElementsUByte& cprim = static_cast<const DrawElementsUByte&>(prim);
1246 fw<<cprim.className()<<" "<<Geometry_getPrimitiveModeStr(cprim.getMode())<<" "<<cprim.size();
1247 if (prim.getNumInstances()>0) fw<<" "<<prim.getNumInstances();
1248 fw<<std::endl;
1249 writeArrayAsInts(fw,cprim.begin(),cprim.end());
1250 return true;
1251 }
1252 break;
1253 case(PrimitiveSet::DrawElementsUShortPrimitiveType):
1254 {
1255 const DrawElementsUShort& cprim = static_cast<const DrawElementsUShort&>(prim);
1256 fw<<cprim.className()<<" "<<Geometry_getPrimitiveModeStr(cprim.getMode())<<" "<<cprim.size();
1257 if (prim.getNumInstances()>0) fw<<" "<<prim.getNumInstances();
1258 fw<<std::endl;
1259 writeArray(fw,cprim.begin(),cprim.end());
1260 return true;
1261 }
1262 break;
1263 case(PrimitiveSet::DrawElementsUIntPrimitiveType):
1264 {
1265 const DrawElementsUInt& cprim = static_cast<const DrawElementsUInt&>(prim);
1266 fw<<cprim.className()<<" "<<Geometry_getPrimitiveModeStr(cprim.getMode())<<" "<<cprim.size();
1267 if (prim.getNumInstances()>0) fw<<" "<<prim.getNumInstances();
1268 fw<<std::endl;
1269 writeArray(fw,cprim.begin(),cprim.end());
1270 return true;
1271 }
1272 break;
1273 default:
1274 return false;
1275 }
1276 }
1277
Geometry_writeLocalData(const Object & obj,Output & fw)1278 bool Geometry_writeLocalData(const Object& obj, Output& fw)
1279 {
1280 const deprecated_osg::Geometry& geom = static_cast<const deprecated_osg::Geometry&>(obj);
1281
1282 const Geometry::PrimitiveSetList& primitives = geom.getPrimitiveSetList();
1283 if (!primitives.empty())
1284 {
1285 fw.indent() << "PrimitiveSets "<<primitives.size()<<std::endl;
1286 fw.indent() << "{"<<std::endl;
1287 fw.moveIn();
1288 for(Geometry::PrimitiveSetList::const_iterator itr=primitives.begin();
1289 itr!=primitives.end();
1290 ++itr)
1291 {
1292 fw.indent();
1293 Primitive_writeLocalData(**itr,fw);
1294 }
1295 fw.moveOut();
1296 fw.indent() << "}"<<std::endl;
1297 }
1298
1299 if (geom.getVertexArray())
1300 {
1301 // const Vec3Array& vertices = *geom.getVertexArray();
1302 // fw.indent()<<"VertexArray "<<vertices.size()<<std::endl;
1303 // Array_writeLocalData(fw,vertices.begin(),vertices.end(),1);
1304
1305 fw.indent()<<"VertexArray ";
1306 Array_writeLocalData(*geom.getVertexArray(),fw);
1307
1308 }
1309 if (geom.getVertexIndices())
1310 {
1311 fw.indent()<<"VertexIndices ";
1312 Array_writeLocalData(*geom.getVertexIndices(),fw);
1313 }
1314
1315 if (geom.getNormalArray())
1316 {
1317
1318 fw.indent()<<"NormalBinding "<<Geometry_getBindingTypeStr(geom.getNormalBinding())<<std::endl;
1319
1320 // const Vec3Array& normals = *geom.getNormalArray();
1321 // fw.indent()<<"NormalArray "<<normals.size()<<std::endl;
1322 // Array_writeLocalData(fw,normals.begin(),normals.end(),1);
1323
1324 fw.indent()<<"NormalArray ";
1325 Array_writeLocalData(*geom.getNormalArray(),fw);
1326
1327 }
1328 if (geom.getNormalIndices())
1329 {
1330 fw.indent()<<"NormalIndices ";
1331 Array_writeLocalData(*geom.getNormalIndices(),fw);
1332 }
1333
1334 if (geom.getColorArray())
1335 {
1336 fw.indent()<<"ColorBinding "<<Geometry_getBindingTypeStr(geom.getColorBinding())<<std::endl;
1337 fw.indent()<<"ColorArray ";
1338 Array_writeLocalData(*geom.getColorArray(),fw);
1339 }
1340 if (geom.getColorIndices())
1341 {
1342 fw.indent()<<"ColorIndices ";
1343 Array_writeLocalData(*geom.getColorIndices(),fw);
1344 }
1345
1346 if (geom.getSecondaryColorArray())
1347 {
1348 fw.indent()<<"SecondaryColorBinding "<<Geometry_getBindingTypeStr(geom.getSecondaryColorBinding())<<std::endl;
1349 fw.indent()<<"SecondaryColorArray ";
1350 Array_writeLocalData(*geom.getSecondaryColorArray(),fw);
1351 }
1352 if (geom.getSecondaryColorIndices())
1353 {
1354 fw.indent()<<"SecondayColorIndices ";
1355 Array_writeLocalData(*geom.getSecondaryColorIndices(),fw);
1356 }
1357
1358 if (geom.getFogCoordArray())
1359 {
1360 fw.indent()<<"FogCoordBinding "<<Geometry_getBindingTypeStr(geom.getFogCoordBinding())<<std::endl;
1361 fw.indent()<<"FogCoordArray ";
1362 Array_writeLocalData(*geom.getFogCoordArray(),fw);
1363 }
1364 if (geom.getFogCoordIndices())
1365 {
1366 fw.indent()<<"FogCoordIndices ";
1367 Array_writeLocalData(*geom.getFogCoordIndices(),fw);
1368 }
1369
1370 const Geometry::ArrayList& tcal=geom.getTexCoordArrayList();
1371 unsigned int i;
1372 for(i=0;i<tcal.size();++i)
1373 {
1374 const osg::Array* array = tcal[i].get();
1375 if (array)
1376 {
1377 fw.indent()<<"TexCoordArray "<<i<<" ";
1378 Array_writeLocalData(*array,fw);
1379 }
1380
1381 const osg::IndexArray* indices = (array!=0) ? dynamic_cast<const osg::IndexArray*>(array->getUserData()) : 0;
1382 if (indices)
1383 {
1384 fw.indent()<<"TexCoordIndices "<<i<<" ";
1385 Array_writeLocalData(*indices,fw);
1386 }
1387 }
1388
1389 const Geometry::ArrayList& vaal=geom.getVertexAttribArrayList();
1390 for(i=0;i<vaal.size();++i)
1391 {
1392 const osg::Array* array = vaal[i].get();
1393
1394 if (array)
1395 {
1396 fw.indent()<<"VertexAttribBinding "<<i<<" "<<Geometry_getBindingTypeStr(static_cast<deprecated_osg::Geometry::AttributeBinding>(array->getBinding()))<<std::endl;
1397
1398 if (array->getNormalize())
1399 fw.indent()<<"VertexAttribNormalize "<<i<<" TRUE"<<std::endl;
1400 else
1401 fw.indent()<<"VertexAttribNormalize "<<i<<" FALSE"<<std::endl;
1402
1403 fw.indent()<<"VertexAttribArray "<<i<<" ";
1404 Array_writeLocalData(*array,fw);
1405 }
1406
1407 const osg::IndexArray* indices = (array!=0) ? dynamic_cast<const osg::IndexArray*>(array->getUserData()) : 0;
1408 if (indices)
1409 {
1410 fw.indent()<<"VertexAttribIndices "<<i<<" ";
1411 Array_writeLocalData(*indices,fw);
1412 }
1413 }
1414
1415 return true;
1416 }
1417
Geometry_matchBindingTypeStr(const char * str,deprecated_osg::Geometry::AttributeBinding & mode)1418 bool Geometry_matchBindingTypeStr(const char* str,deprecated_osg::Geometry::AttributeBinding& mode)
1419 {
1420 if (strcmp(str,"OFF")==0) mode = deprecated_osg::Geometry::BIND_OFF;
1421 else if (strcmp(str,"OVERALL")==0) mode = deprecated_osg::Geometry::BIND_OVERALL;
1422 else if (strcmp(str,"PER_PRIMITIVE")==0) mode = deprecated_osg::Geometry::BIND_PER_PRIMITIVE;
1423 else if (strcmp(str,"PER_PRIMITIVE_SET")==0) mode = deprecated_osg::Geometry::BIND_PER_PRIMITIVE_SET;
1424 else if (strcmp(str,"PER_VERTEX")==0) mode = deprecated_osg::Geometry::BIND_PER_VERTEX;
1425 else return false;
1426 return true;
1427 }
1428
1429
Geometry_getBindingTypeStr(deprecated_osg::Geometry::AttributeBinding mode)1430 const char* Geometry_getBindingTypeStr(deprecated_osg::Geometry::AttributeBinding mode)
1431 {
1432 switch(mode)
1433 {
1434 case (deprecated_osg::Geometry::BIND_OVERALL) : return "OVERALL";
1435 case (deprecated_osg::Geometry::BIND_PER_PRIMITIVE) : return "PER_PRIMITIVE";
1436 case (deprecated_osg::Geometry::BIND_PER_PRIMITIVE_SET) : return "PER_PRIMITIVE_SET";
1437 case (deprecated_osg::Geometry::BIND_PER_VERTEX) : return "PER_VERTEX";
1438 case (deprecated_osg::Geometry::BIND_OFF) :
1439 default : return "OFF";
1440 }
1441 }
1442
Geometry_matchPrimitiveModeStr(const char * str,GLenum & mode)1443 bool Geometry_matchPrimitiveModeStr(const char* str,GLenum& mode)
1444 {
1445 if (strcmp(str,"POINTS")==0) mode = PrimitiveSet::POINTS;
1446 else if (strcmp(str,"LINES")==0) mode = PrimitiveSet::LINES;
1447 else if (strcmp(str,"LINE_STRIP")==0) mode = PrimitiveSet::LINE_STRIP;
1448 else if (strcmp(str,"LINE_LOOP")==0) mode = PrimitiveSet::LINE_LOOP;
1449 else if (strcmp(str,"TRIANGLES")==0) mode = PrimitiveSet::TRIANGLES;
1450 else if (strcmp(str,"TRIANGLE_STRIP")==0) mode = PrimitiveSet::TRIANGLE_STRIP;
1451 else if (strcmp(str,"TRIANGLE_FAN")==0) mode = PrimitiveSet::TRIANGLE_FAN;
1452 else if (strcmp(str,"QUADS")==0) mode = PrimitiveSet::QUADS;
1453 else if (strcmp(str,"QUAD_STRIP")==0) mode = PrimitiveSet::QUAD_STRIP;
1454 else if (strcmp(str,"POLYGON")==0) mode = PrimitiveSet::POLYGON;
1455 else if (strcmp(str,"LINES_ADJACENCY")==0) mode = PrimitiveSet::LINES_ADJACENCY;
1456 else if (strcmp(str,"LINE_STRIP_ADJACENCY")==0) mode = PrimitiveSet::LINE_STRIP_ADJACENCY;
1457 else if (strcmp(str,"TRIANGLES_ADJACENCY")==0) mode = PrimitiveSet::TRIANGLES_ADJACENCY;
1458 else if (strcmp(str,"TRIANGLE_STRIP_ADJECENCY")==0) mode = PrimitiveSet::TRIANGLE_STRIP_ADJACENCY;
1459 else if (strcmp(str,"TRIANGLE_STRIP_ADJACENCY")==0) mode = PrimitiveSet::TRIANGLE_STRIP_ADJACENCY;
1460 else if (strcmp(str,"PATCHES")==0) mode = PrimitiveSet::PATCHES;
1461 else return false;
1462 return true;
1463 }
1464
1465
Geometry_getPrimitiveModeStr(GLenum mode)1466 const char* Geometry_getPrimitiveModeStr(GLenum mode)
1467 {
1468 switch(mode)
1469 {
1470 case (PrimitiveSet::POINTS) : return "POINTS";
1471 case (PrimitiveSet::LINES) : return "LINES";
1472 case (PrimitiveSet::LINE_STRIP) : return "LINE_STRIP";
1473 case (PrimitiveSet::LINE_LOOP) : return "LINE_LOOP";
1474 case (PrimitiveSet::TRIANGLES) : return "TRIANGLES";
1475 case (PrimitiveSet::TRIANGLE_STRIP) : return "TRIANGLE_STRIP";
1476 case (PrimitiveSet::TRIANGLE_FAN) : return "TRIANGLE_FAN";
1477 case (PrimitiveSet::QUADS) : return "QUADS";
1478 case (PrimitiveSet::QUAD_STRIP) : return "QUAD_STRIP";
1479 case (PrimitiveSet::POLYGON) : return "POLYGON";
1480 case (PrimitiveSet::LINES_ADJACENCY) : return "LINES_ADJACENCY";
1481 case (PrimitiveSet::LINE_STRIP_ADJACENCY) : return "LINE_STRIP_ADJACENCY";
1482 case (PrimitiveSet::TRIANGLES_ADJACENCY) : return "TRIANGLES_ADJACENCY";
1483 case (PrimitiveSet::TRIANGLE_STRIP_ADJACENCY) : return "TRIANGLE_STRIP_ADJACENCY";
1484 case (PrimitiveSet::PATCHES) : return "PATCHES";
1485 default : return "UnknownPrimitveType";
1486 }
1487 }
1488