0025442: Visualization, TKOpenGl - prevent inclusion of system header glxext.h
[occt.git] / src / OpenGl / OpenGl_Layer.cxx
1 // Created on: 2014-03-31
2 // Created by: Danila ULYANOV
3 // Copyright (c) 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_Layer.hxx>
17 #include <OpenGl_Workspace.hxx>
18 #include <OpenGl_GlCore11.hxx>
19
20 //=======================================================================
21 //function : OpenGl_Layer
22 //purpose  : 
23 //=======================================================================
24 OpenGl_Layer::OpenGl_Layer (const Standard_Integer theNbPriorities)
25   : myPriorityList (theNbPriorities)
26 {
27   //
28 }
29
30 //=======================================================================
31 //function : Render
32 //purpose  : 
33 //=======================================================================
34 void OpenGl_Layer::Render (const Handle(OpenGl_Workspace) &theWorkspace, const OpenGl_GlobalLayerSettings& theDefaultSettings) const
35 {
36   TEL_POFFSET_PARAM anAppliedOffsetParams = theWorkspace->AppliedPolygonOffset();
37
38   // separate depth buffers
39   if (IsSettingEnabled (Graphic3d_ZLayerDepthClear))
40   {
41     glClear (GL_DEPTH_BUFFER_BIT);
42   }
43  
44   // handle depth test
45   if (IsSettingEnabled (Graphic3d_ZLayerDepthTest))
46   {
47     // assuming depth test is enabled by default
48     glDepthFunc (theDefaultSettings.DepthFunc);
49   }
50   else
51   {
52     glDepthFunc (GL_ALWAYS);
53   }
54   
55   // handle depth offset
56   if (IsSettingEnabled (Graphic3d_ZLayerDepthOffset))
57   {
58     theWorkspace->SetPolygonOffset (Aspect_POM_Fill,
59                                     myLayerSettings.DepthOffsetFactor,
60                                     myLayerSettings.DepthOffsetUnits);
61   }
62   else
63   {
64     theWorkspace->SetPolygonOffset (anAppliedOffsetParams.mode,
65                                     anAppliedOffsetParams.factor,
66                                     anAppliedOffsetParams.units);
67   }
68
69   // handle depth write
70   if (IsSettingEnabled (Graphic3d_ZLayerDepthWrite))
71   {
72     glDepthMask (GL_TRUE);
73   }
74   else
75   {
76     glDepthMask (GL_FALSE);
77   }
78
79   // render priority list
80   myPriorityList.Render (theWorkspace);
81
82   // always restore polygon offset between layers rendering
83   theWorkspace->SetPolygonOffset (anAppliedOffsetParams.mode,
84                                   anAppliedOffsetParams.factor,
85                                   anAppliedOffsetParams.units);
86 }