0023006: Improvement to debug memory leaks and insufficient memory growths.
[occt.git] / src / OpenGl / OpenGl_Workspace.cxx
CommitLineData
2166f0fa
SK
1// File: OpenGl_Workspace.cxx
2// Created: 20 September 2011
3// Author: Sergey ZERCHANINOV
4// Copyright: OPEN CASCADE 2011
5
6#include <InterfaceGraphic.hxx>
7
8#include <OpenGl_Workspace.hxx>
9
10#include <OpenGl_AspectLine.hxx>
11#include <OpenGl_AspectFace.hxx>
12#include <OpenGl_AspectMarker.hxx>
13#include <OpenGl_AspectText.hxx>
14
15#include <OpenGl_tgl_all.hxx>
16#include <OpenGl_TextureBox.hxx>
17
18IMPLEMENT_STANDARD_HANDLE(OpenGl_Workspace,OpenGl_Window)
19IMPLEMENT_STANDARD_RTTIEXT(OpenGl_Workspace,OpenGl_Window)
20
21namespace
22{
23 static const TEL_COLOUR myDefaultHighlightColor = { { 1.F, 1.F, 1.F, 1.F } };
24
25 static const OpenGl_AspectLine myDefaultAspectLine;
26 static const OpenGl_AspectFace myDefaultAspectFace;
27 static const OpenGl_AspectMarker myDefaultAspectMarker;
28 static const OpenGl_AspectText myDefaultAspectText;
29
30 static const OpenGl_TextParam myDefaultTextParam =
31 {
32 16, Graphic3d_HTA_LEFT, Graphic3d_VTA_BOTTOM
33 };
34
35 static const OpenGl_Matrix myDefaultMatrix =
36 {
37 {{ 1.0F, 0.0F, 0.0F, 0.0F },
38 { 0.0F, 1.0F, 0.0F, 0.0F },
39 { 0.0F, 0.0F, 1.0F, 0.0F },
40 { 0.0F, 0.0F, 0.0F, 1.0F }}
41 };
42};
43
44// =======================================================================
45// function : OpenGl_Workspace
46// purpose :
47// =======================================================================
48OpenGl_Workspace::OpenGl_Workspace (const Handle(OpenGl_Display)& theDisplay,
49 const CALL_DEF_WINDOW& theCWindow,
50 Aspect_RenderingContext theGContext)
51: OpenGl_Window (theDisplay, theCWindow, theGContext),
52 myIsUpdated (Standard_False),
53 myTransientList (0),
54 myIsTransientOpen (Standard_False),
55 myRetainMode (Standard_False),
56 myUseTransparency (Standard_False),
57 myUseZBuffer (Standard_False),
58 myUseDepthTest (Standard_True),
59 myUseGLLight (Standard_True),
60 myBackBufferRestored (Standard_False),
61 //
62 NamedStatus (0),
63 DegenerateModel (0),
64 SkipRatio (0.F),
65 HighlightColor (&myDefaultHighlightColor),
66 AspectLine_set (&myDefaultAspectLine),
67 AspectLine_applied (NULL),
68 AspectFace_set (&myDefaultAspectFace),
69 AspectFace_applied (NULL),
70 AspectMarker_set (&myDefaultAspectMarker),
71 AspectMarker_applied (NULL),
72 AspectText_set (&myDefaultAspectText),
73 AspectText_applied (NULL),
74 TextParam_set (&myDefaultTextParam),
75 TextParam_applied (NULL),
76 ViewMatrix_applied (&myDefaultMatrix),
77 StructureMatrix_applied (&myDefaultMatrix),
78 PolygonOffset_applied (NULL)
79{
80 theDisplay->InitAttributes();
81
82 // General initialization of the context
83
84 // Eviter d'avoir les faces mal orientees en noir.
85 // Pourrait etre utiliser pour detecter les problemes d'orientation
86 glLightModeli ((GLenum )GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
87
88 // Optimisation pour le Fog et l'antialiasing
89 glHint (GL_FOG_HINT, GL_FASTEST);
90 glHint (GL_POINT_SMOOTH_HINT, GL_FASTEST);
91 glHint (GL_LINE_SMOOTH_HINT, GL_FASTEST);
92 glHint (GL_POLYGON_SMOOTH_HINT, GL_FASTEST);
93
94 // Polygon Offset
95 EnablePolygonOffset();
96}
97
98// =======================================================================
99// function : ~OpenGl_Workspace
100// purpose :
101// =======================================================================
102OpenGl_Workspace::~OpenGl_Workspace()
103{
104}
105
106// =======================================================================
107// function : Activate
108// purpose :
109// =======================================================================
110Standard_Boolean OpenGl_Workspace::Activate()
111{
112 if (!OpenGl_Window::Activate())
113 return Standard_False;
114
115 NamedStatus = IsTextureEnabled() ? OPENGL_NS_TEXTURE : 0;
116 DegenerateModel = 0;
117 SkipRatio = 0.0f;
118 HighlightColor = &myDefaultHighlightColor;
119 AspectLine_set = &myDefaultAspectLine;
120 AspectLine_applied = NULL;
121 AspectFace_set = &myDefaultAspectFace;
122 AspectFace_applied = NULL;
123 AspectMarker_set = &myDefaultAspectMarker;
124 AspectMarker_applied = NULL;
125 AspectText_set = &myDefaultAspectText;
126 AspectText_applied = NULL;
127 TextParam_set = &myDefaultTextParam;
128 TextParam_applied = NULL;
129 ViewMatrix_applied = &myDefaultMatrix;
130 StructureMatrix_applied = &myDefaultMatrix;
131 PolygonOffset_applied = NULL;
132 return Standard_True;
133}
134
135// =======================================================================
136// function : UseTransparency
137// purpose : call_togl_transparency
138// =======================================================================
139void OpenGl_Workspace::UseTransparency (const Standard_Boolean theFlag)
140{
141 if ((myUseTransparency ? 1 : 0) != (theFlag ? 1 : 0))
142 {
143 myUseTransparency = theFlag;
144 EraseAnimation();
145 myIsUpdated = Standard_False;
146 }
147}