0023024: Update headers of OCCT files
[occt.git] / src / OpenGl / OpenGl_Workspace.cxx
1 // Created on: 2011-09-20
2 // Created by: Sergey ZERCHANINOV
3 // Copyright (c) 2011-2012 OPEN CASCADE SAS
4 //
5 // The content of this file is subject to the Open CASCADE Technology Public
6 // License Version 6.5 (the "License"). You may not use the content of this file
7 // except in compliance with the License. Please obtain a copy of the License
8 // at http://www.opencascade.org and read it completely before using this file.
9 //
10 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
12 //
13 // The Original Code and all software distributed under the License is
14 // distributed on an "AS IS" basis, without warranty of any kind, and the
15 // Initial Developer hereby disclaims all such warranties, including without
16 // limitation, any warranties of merchantability, fitness for a particular
17 // purpose or non-infringement. Please see the License for the specific terms
18 // and conditions governing the rights and limitations under the License.
19
20
21 #include <OpenGl_GlCore11.hxx>
22
23 #include <InterfaceGraphic.hxx>
24
25 #include <OpenGl_Workspace.hxx>
26
27 #include <OpenGl_AspectLine.hxx>
28 #include <OpenGl_AspectFace.hxx>
29 #include <OpenGl_AspectMarker.hxx>
30 #include <OpenGl_AspectText.hxx>
31
32 #include <OpenGl_TextureBox.hxx>
33
34 IMPLEMENT_STANDARD_HANDLE(OpenGl_Workspace,OpenGl_Window)
35 IMPLEMENT_STANDARD_RTTIEXT(OpenGl_Workspace,OpenGl_Window)
36
37 namespace
38 {
39   static const TEL_COLOUR myDefaultHighlightColor = { { 1.F, 1.F, 1.F, 1.F } };
40
41   static const OpenGl_AspectLine myDefaultAspectLine;
42   static const OpenGl_AspectFace myDefaultAspectFace;
43   static const OpenGl_AspectMarker myDefaultAspectMarker;
44   static const OpenGl_AspectText myDefaultAspectText;
45
46   static const OpenGl_TextParam myDefaultTextParam =
47   {
48     16, Graphic3d_HTA_LEFT, Graphic3d_VTA_BOTTOM
49   };
50
51   static const OpenGl_Matrix myDefaultMatrix =
52   {
53     {{ 1.0F, 0.0F, 0.0F, 0.0F },
54      { 0.0F, 1.0F, 0.0F, 0.0F },
55      { 0.0F, 0.0F, 1.0F, 0.0F },
56      { 0.0F, 0.0F, 0.0F, 1.0F }}
57   };
58 };
59
60 // =======================================================================
61 // function : OpenGl_Workspace
62 // purpose  :
63 // =======================================================================
64 OpenGl_Workspace::OpenGl_Workspace (const Handle(OpenGl_Display)& theDisplay,
65                                     const CALL_DEF_WINDOW&        theCWindow,
66                                     Aspect_RenderingContext       theGContext)
67 : OpenGl_Window (theDisplay, theCWindow, theGContext),
68   myIsUpdated (Standard_False),
69   myTransientList (0),
70   myIsTransientOpen (Standard_False),
71   myRetainMode (Standard_False),
72   myUseTransparency (Standard_False),
73   myUseZBuffer (Standard_False),
74   myUseDepthTest (Standard_True),
75   myUseGLLight (Standard_True),
76   myBackBufferRestored (Standard_False),
77   //
78   NamedStatus (0),
79   DegenerateModel (0),
80   SkipRatio (0.F),
81   HighlightColor (&myDefaultHighlightColor),
82   AspectLine_set (&myDefaultAspectLine),
83   AspectLine_applied (NULL),
84   AspectFace_set (&myDefaultAspectFace),
85   AspectFace_applied (NULL),
86   AspectMarker_set (&myDefaultAspectMarker),
87   AspectMarker_applied (NULL),
88   AspectText_set (&myDefaultAspectText),
89   AspectText_applied (NULL),
90   TextParam_set (&myDefaultTextParam),
91   TextParam_applied (NULL),
92   ViewMatrix_applied (&myDefaultMatrix),
93   StructureMatrix_applied (&myDefaultMatrix),
94   PolygonOffset_applied (NULL)
95 {
96   theDisplay->InitAttributes();
97
98   // General initialization of the context
99
100   // Eviter d'avoir les faces mal orientees en noir.
101   // Pourrait etre utiliser pour detecter les problemes d'orientation
102   glLightModeli ((GLenum )GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE); 
103
104   // Optimisation pour le Fog et l'antialiasing
105   glHint (GL_FOG_HINT,            GL_FASTEST);
106   glHint (GL_POINT_SMOOTH_HINT,   GL_FASTEST);
107   glHint (GL_LINE_SMOOTH_HINT,    GL_FASTEST);
108   glHint (GL_POLYGON_SMOOTH_HINT, GL_FASTEST);
109
110   // Polygon Offset
111   EnablePolygonOffset();
112 }
113
114 // =======================================================================
115 // function : ~OpenGl_Workspace
116 // purpose  :
117 // =======================================================================
118 OpenGl_Workspace::~OpenGl_Workspace()
119 {
120 }
121
122 // =======================================================================
123 // function : Activate
124 // purpose  :
125 // =======================================================================
126 Standard_Boolean OpenGl_Workspace::Activate()
127 {
128   if (!OpenGl_Window::Activate())
129     return Standard_False;
130
131   NamedStatus             = IsTextureEnabled() ? OPENGL_NS_TEXTURE : 0;
132   DegenerateModel         = 0;
133   SkipRatio               = 0.0f;
134   HighlightColor          = &myDefaultHighlightColor;
135   AspectLine_set          = &myDefaultAspectLine;
136   AspectLine_applied      = NULL;
137   AspectFace_set          = &myDefaultAspectFace;
138   AspectFace_applied      = NULL;
139   AspectMarker_set        = &myDefaultAspectMarker;
140   AspectMarker_applied    = NULL;
141   AspectText_set          = &myDefaultAspectText;
142   AspectText_applied      = NULL;
143   TextParam_set           = &myDefaultTextParam;
144   TextParam_applied       = NULL;
145   ViewMatrix_applied      = &myDefaultMatrix;
146   StructureMatrix_applied = &myDefaultMatrix;
147   PolygonOffset_applied   = NULL;
148         return Standard_True;
149 }
150
151 // =======================================================================
152 // function : UseTransparency
153 // purpose  : call_togl_transparency
154 // =======================================================================
155 void OpenGl_Workspace::UseTransparency (const Standard_Boolean theFlag)
156 {
157   if ((myUseTransparency ? 1 : 0) != (theFlag ? 1 : 0))
158   {
159     myUseTransparency = theFlag;
160     EraseAnimation();
161     myIsUpdated = Standard_False;
162   }
163 }