0024001: Stereographic rendering support
[occt.git] / src / OpenGl / OpenGl_PriorityList.cxx
CommitLineData
b311480e 1// Created on: 2011-11-02
2// Created by: Sergey ZERCHANINOV
973c2be1 3// Copyright (c) 2011-2014 OPEN CASCADE SAS
b311480e 4//
973c2be1 5// This file is part of Open CASCADE Technology software library.
b311480e 6//
973c2be1 7// This library is free software; you can redistribute it and / or modify it
8// under the terms of the GNU Lesser General Public version 2.1 as published
9// by the Free Software Foundation, with special exception defined in the file
10// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11// distribution for complete text of the license and disclaimer of any warranty.
b311480e 12//
973c2be1 13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
2166f0fa
SK
15
16#include <OpenGl_PriorityList.hxx>
17
18#include <OpenGl_Structure.hxx>
19
20/*----------------------------------------------------------------------*/
21
22void OpenGl_PriorityList::Add (const OpenGl_Structure *AStructure,const Standard_Integer APriority)
23{
24 Standard_Integer anIndex = APriority;
25 if (anIndex < 0) anIndex = 0;
26 else if (anIndex >= myArray.Length()) anIndex = myArray.Length()-1;
27 myArray(anIndex).Append(AStructure);
28 myNbStructures++;
29}
30
31/*----------------------------------------------------------------------*/
32
59f45b7c 33Standard_Integer OpenGl_PriorityList::Remove (const OpenGl_Structure *AStructure)
2166f0fa
SK
34{
35 const Standard_Integer aNbPr = myArray.Length();
36 Standard_Integer i = 0;
37 OpenGl_SequenceOfStructure::Iterator its;
38 for (; i < aNbPr; i++)
39 {
40 OpenGl_SequenceOfStructure &aSeq = myArray(i);
41 for (its.Init(aSeq); its.More(); its.Next())
42 {
43 if (its.Value() == AStructure)
44 {
45 aSeq.Remove(its);
46 myNbStructures--;
59f45b7c 47 return i;
2166f0fa
SK
48 }
49 }
50 }
59f45b7c 51
52 return -1;
2166f0fa
SK
53}
54
55/*----------------------------------------------------------------------*/
56
57void OpenGl_PriorityList::Render (const Handle(OpenGl_Workspace) &AWorkspace) const
58{
59 const Standard_Integer aNbPr = myArray.Length();
60 Standard_Integer i = 0;
61 OpenGl_SequenceOfStructure::Iterator its;
62 for (; i < aNbPr; i++)
63 {
64 for (its.Init(myArray(i)); its.More(); its.Next())
65 its.Value()->Render(AWorkspace);
66 }
67}
68
59f45b7c 69//=======================================================================
70//function : Append
71//purpose :
72//=======================================================================
73
74Standard_Boolean OpenGl_PriorityList::Append (const OpenGl_PriorityList& theOther)
75{
76 // the source priority list shouldn't have more priorities
77 const Standard_Integer aNbPriorities = theOther.NbPriorities ();
78 if (aNbPriorities > NbPriorities ())
79 return Standard_False;
80
81 // add all structures to destination priority list
82 Standard_Integer aIdx = 0;
83 OpenGl_SequenceOfStructure::Iterator anIts;
84 for (; aIdx < aNbPriorities; aIdx++)
85 {
86 const OpenGl_SequenceOfStructure& aSeq = theOther.myArray (aIdx);
87 for (anIts.Init (aSeq); anIts.More (); anIts.Next ())
88 Add (anIts.Value (), aIdx);
89 }
90
91 return Standard_True;
92}
93
94//=======================================================================
95//function : NbPriorities
96//purpose :
97//=======================================================================
98
99Standard_Integer OpenGl_PriorityList::NbPriorities() const
100{
101 return myArray.Length();
102}