0023022: This is desirable to access OpenGl extensions and core API (1.2+) in one...
[occt.git] / src / OpenGl / OpenGl_PriorityList.cxx
1 // File:      OpenGl_PriorityList.cxx
2 // Created:   2 November 2011
3 // Author:    Sergey ZERCHANINOV
4 // Copyright: OPEN CASCADE 2011
5
6 #include <OpenGl_PriorityList.hxx>
7
8 #include <OpenGl_Structure.hxx>
9
10 /*----------------------------------------------------------------------*/
11
12 void OpenGl_PriorityList::Add (const OpenGl_Structure *AStructure,const Standard_Integer APriority)
13 {
14   Standard_Integer anIndex = APriority;
15   if (anIndex < 0) anIndex = 0;
16   else if (anIndex >= myArray.Length()) anIndex = myArray.Length()-1;
17   myArray(anIndex).Append(AStructure);
18   myNbStructures++;
19 }
20
21 /*----------------------------------------------------------------------*/
22
23 Standard_Integer OpenGl_PriorityList::Remove (const OpenGl_Structure *AStructure)
24 {
25   const Standard_Integer aNbPr = myArray.Length();
26   Standard_Integer i = 0;
27   OpenGl_SequenceOfStructure::Iterator its;
28   for (; i < aNbPr; i++)
29   {
30     OpenGl_SequenceOfStructure &aSeq = myArray(i);
31     for (its.Init(aSeq); its.More(); its.Next())
32     {
33       if (its.Value() == AStructure)
34       {
35         aSeq.Remove(its);
36         myNbStructures--;
37         return i;
38       }
39     }
40   }
41
42   return -1;
43 }
44
45 /*----------------------------------------------------------------------*/
46
47 void OpenGl_PriorityList::Render (const Handle(OpenGl_Workspace) &AWorkspace) const
48 {
49   const Standard_Integer aNbPr = myArray.Length();
50   Standard_Integer i = 0;
51   OpenGl_SequenceOfStructure::Iterator its;
52   for (; i < aNbPr; i++)
53   {
54     for (its.Init(myArray(i)); its.More(); its.Next())
55       its.Value()->Render(AWorkspace);
56   }
57 }
58
59 //=======================================================================
60 //function : Append
61 //purpose  : 
62 //=======================================================================
63
64 Standard_Boolean OpenGl_PriorityList::Append (const OpenGl_PriorityList& theOther)
65 {
66   // the source priority list shouldn't have more priorities
67   const Standard_Integer aNbPriorities = theOther.NbPriorities ();
68   if (aNbPriorities > NbPriorities ())
69     return Standard_False;
70
71   // add all structures to destination priority list
72   Standard_Integer aIdx = 0;
73   OpenGl_SequenceOfStructure::Iterator anIts;
74   for (; aIdx < aNbPriorities; aIdx++)
75   {
76     const OpenGl_SequenceOfStructure& aSeq = theOther.myArray (aIdx);
77     for (anIts.Init (aSeq); anIts.More (); anIts.Next ())
78       Add (anIts.Value (), aIdx);
79   }
80
81   return Standard_True;
82 }
83
84 //=======================================================================
85 //function : NbPriorities
86 //purpose  : 
87 //=======================================================================
88
89 Standard_Integer OpenGl_PriorityList::NbPriorities() const
90 {
91   return myArray.Length();
92 }