0024394: Visualization - implement more general way for rendering of immediate objects
[occt.git] / src / OpenGl / OpenGl_GraphicDriver_4.cxx
1 // Created on: 2011-10-20
2 // Created by: Sergey ZERCHANINOV
3 // Copyright (c) 2011-2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License 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.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 #include <OpenGl_GraphicDriver.hxx>
17
18 #include <NCollection_DataMap.hxx>
19 #include <OpenGl_Structure.hxx>
20 #include <OpenGl_CView.hxx>
21
22 void OpenGl_GraphicDriver::DisplayStructure (const Graphic3d_CView&             theCView,
23                                              const Handle(Graphic3d_Structure)& theStructure,
24                                              const Standard_Integer             thePriority)
25 {
26   const OpenGl_CView* aCView = (const OpenGl_CView* )theCView.ptrView;
27   if (aCView == NULL)
28     return;
29
30   aCView->View->DisplayStructure (theStructure, thePriority);
31 }
32
33 void OpenGl_GraphicDriver::EraseStructure (const Graphic3d_CView&             theCView,
34                                            const Handle(Graphic3d_Structure)& theStructure)
35 {
36   const OpenGl_CView* aCView = (const OpenGl_CView* )theCView.ptrView;
37   if (aCView == NULL)
38     return;
39
40   aCView->View->EraseStructure (theStructure);
41 }
42
43 void OpenGl_GraphicDriver::RemoveStructure (Handle(Graphic3d_CStructure)& theCStructure)
44 {
45   OpenGl_Structure* aStructure = NULL;
46   if (!myMapOfStructure.Find (theCStructure->Id, aStructure))
47   {
48     return;
49   }
50
51   myMapOfStructure.UnBind (theCStructure->Id);
52   aStructure->Release (GetSharedContext());
53   theCStructure.Nullify();
54 }
55
56 Handle(Graphic3d_CStructure) OpenGl_GraphicDriver::Structure (const Handle(Graphic3d_StructureManager)& theManager)
57 {
58   Handle(OpenGl_Structure) aStructure = new OpenGl_Structure (theManager);
59   myMapOfStructure.Bind (aStructure->Id, aStructure.operator->());
60   return aStructure;
61 }
62
63 //=======================================================================
64 //function : ChangeZLayer
65 //purpose  :
66 //=======================================================================
67
68 void OpenGl_GraphicDriver::ChangeZLayer (const Graphic3d_CStructure& theCStructure,
69                                          const Graphic3d_CView&      theCView,
70                                          const Graphic3d_ZLayerId    theNewLayerId)
71 {
72   const OpenGl_CView *aCView = (const OpenGl_CView *)theCView.ptrView;
73
74   if (!myMapOfStructure.IsBound (theCStructure.Id) || !aCView)
75     return;
76
77   OpenGl_Structure* aStructure = myMapOfStructure.Find (theCStructure.Id);
78
79   aCView->View->ChangeZLayer (aStructure, theNewLayerId);
80 }
81
82 //=======================================================================
83 //function : UnsetZLayer
84 //purpose  :
85 //=======================================================================
86
87 void OpenGl_GraphicDriver::UnsetZLayer (const Graphic3d_ZLayerId theLayerId)
88 {
89   NCollection_DataMap<Standard_Integer, OpenGl_Structure*>::Iterator aStructIt (myMapOfStructure);
90   for( ; aStructIt.More (); aStructIt.Next ())
91   {
92     OpenGl_Structure* aStruct = aStructIt.ChangeValue ();
93     if (aStruct->ZLayer() == theLayerId)
94       aStruct->SetZLayer (Graphic3d_ZLayerId_Default);
95   }
96 }
97
98 //=======================================================================
99 //function : ChangePriority
100 //purpose  :
101 //=======================================================================
102 void OpenGl_GraphicDriver::ChangePriority (const Graphic3d_CStructure& theCStructure,
103                                            const Graphic3d_CView&      theCView,
104                                            const Standard_Integer      theNewPriority)
105 {
106   const OpenGl_CView *aCView = (const OpenGl_CView *)theCView.ptrView;
107
108   if (!myMapOfStructure.IsBound (theCStructure.Id) || !aCView)
109     return;
110
111   OpenGl_Structure* aStructure = myMapOfStructure.Find (theCStructure.Id);
112
113   aCView->View->ChangePriority (aStructure, theNewPriority);
114 }