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