0023087: Upgrade of the OCCT test system
[occt.git] / src / OpenGl / OpenGl_Workspace.cxx
CommitLineData
b311480e 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
2166f0fa 20
5f8b738e 21#include <OpenGl_GlCore11.hxx>
22
2166f0fa
SK
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
2166f0fa
SK
32#include <OpenGl_TextureBox.hxx>
33
34IMPLEMENT_STANDARD_HANDLE(OpenGl_Workspace,OpenGl_Window)
35IMPLEMENT_STANDARD_RTTIEXT(OpenGl_Workspace,OpenGl_Window)
36
37namespace
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// =======================================================================
64OpenGl_Workspace::OpenGl_Workspace (const Handle(OpenGl_Display)& theDisplay,
65 const CALL_DEF_WINDOW& theCWindow,
66 Aspect_RenderingContext theGContext)
67: OpenGl_Window (theDisplay, theCWindow, theGContext),
2166f0fa
SK
68 myTransientList (0),
69 myIsTransientOpen (Standard_False),
70 myRetainMode (Standard_False),
71 myUseTransparency (Standard_False),
72 myUseZBuffer (Standard_False),
73 myUseDepthTest (Standard_True),
74 myUseGLLight (Standard_True),
75 myBackBufferRestored (Standard_False),
76 //
77 NamedStatus (0),
78 DegenerateModel (0),
79 SkipRatio (0.F),
80 HighlightColor (&myDefaultHighlightColor),
81 AspectLine_set (&myDefaultAspectLine),
82 AspectLine_applied (NULL),
83 AspectFace_set (&myDefaultAspectFace),
84 AspectFace_applied (NULL),
85 AspectMarker_set (&myDefaultAspectMarker),
86 AspectMarker_applied (NULL),
87 AspectText_set (&myDefaultAspectText),
88 AspectText_applied (NULL),
89 TextParam_set (&myDefaultTextParam),
90 TextParam_applied (NULL),
91 ViewMatrix_applied (&myDefaultMatrix),
92 StructureMatrix_applied (&myDefaultMatrix),
93 PolygonOffset_applied (NULL)
94{
95 theDisplay->InitAttributes();
96
97 // General initialization of the context
98
99 // Eviter d'avoir les faces mal orientees en noir.
100 // Pourrait etre utiliser pour detecter les problemes d'orientation
101 glLightModeli ((GLenum )GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
102
103 // Optimisation pour le Fog et l'antialiasing
104 glHint (GL_FOG_HINT, GL_FASTEST);
105 glHint (GL_POINT_SMOOTH_HINT, GL_FASTEST);
106 glHint (GL_LINE_SMOOTH_HINT, GL_FASTEST);
107 glHint (GL_POLYGON_SMOOTH_HINT, GL_FASTEST);
108
109 // Polygon Offset
110 EnablePolygonOffset();
111}
112
113// =======================================================================
114// function : ~OpenGl_Workspace
115// purpose :
116// =======================================================================
117OpenGl_Workspace::~OpenGl_Workspace()
118{
119}
120
121// =======================================================================
122// function : Activate
123// purpose :
124// =======================================================================
125Standard_Boolean OpenGl_Workspace::Activate()
126{
127 if (!OpenGl_Window::Activate())
128 return Standard_False;
129
130 NamedStatus = IsTextureEnabled() ? OPENGL_NS_TEXTURE : 0;
131 DegenerateModel = 0;
132 SkipRatio = 0.0f;
133 HighlightColor = &myDefaultHighlightColor;
134 AspectLine_set = &myDefaultAspectLine;
135 AspectLine_applied = NULL;
136 AspectFace_set = &myDefaultAspectFace;
137 AspectFace_applied = NULL;
138 AspectMarker_set = &myDefaultAspectMarker;
139 AspectMarker_applied = NULL;
140 AspectText_set = &myDefaultAspectText;
141 AspectText_applied = NULL;
142 TextParam_set = &myDefaultTextParam;
143 TextParam_applied = NULL;
144 ViewMatrix_applied = &myDefaultMatrix;
145 StructureMatrix_applied = &myDefaultMatrix;
146 PolygonOffset_applied = NULL;
147 return Standard_True;
148}
149
150// =======================================================================
151// function : UseTransparency
152// purpose : call_togl_transparency
153// =======================================================================
154void OpenGl_Workspace::UseTransparency (const Standard_Boolean theFlag)
155{
156 if ((myUseTransparency ? 1 : 0) != (theFlag ? 1 : 0))
157 {
158 myUseTransparency = theFlag;
159 EraseAnimation();
2166f0fa
SK
160 }
161}