1 // Created on: 2011-09-20
2 // Created by: Sergey ZERCHANINOV
3 // Copyright (c) 2011-2012 OPEN CASCADE SAS
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.
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.
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.
21 #include <OpenGl_GlCore11.hxx>
23 #include <InterfaceGraphic.hxx>
25 #include <OpenGl_Workspace.hxx>
27 #include <OpenGl_AspectLine.hxx>
28 #include <OpenGl_AspectFace.hxx>
29 #include <OpenGl_AspectMarker.hxx>
30 #include <OpenGl_AspectText.hxx>
32 #include <OpenGl_TextureBox.hxx>
34 IMPLEMENT_STANDARD_HANDLE(OpenGl_Workspace,OpenGl_Window)
35 IMPLEMENT_STANDARD_RTTIEXT(OpenGl_Workspace,OpenGl_Window)
39 static const TEL_COLOUR myDefaultHighlightColor = { { 1.F, 1.F, 1.F, 1.F } };
41 static const OpenGl_AspectLine myDefaultAspectLine;
42 static const OpenGl_AspectFace myDefaultAspectFace;
43 static const OpenGl_AspectMarker myDefaultAspectMarker;
44 static const OpenGl_AspectText myDefaultAspectText;
46 static const OpenGl_TextParam myDefaultTextParam =
48 16, Graphic3d_HTA_LEFT, Graphic3d_VTA_BOTTOM
51 static const OpenGl_Matrix myDefaultMatrix =
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 }}
60 // =======================================================================
61 // function : OpenGl_Workspace
63 // =======================================================================
64 OpenGl_Workspace::OpenGl_Workspace (const Handle(OpenGl_Display)& theDisplay,
65 const CALL_DEF_WINDOW& theCWindow,
66 Aspect_RenderingContext theGContext,
67 const Handle(OpenGl_Context)& theShareCtx)
68 : OpenGl_Window (theDisplay, theCWindow, theGContext, theShareCtx),
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),
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)
96 theDisplay->InitAttributes();
98 // General initialization of the context
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);
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);
111 EnablePolygonOffset();
114 // =======================================================================
115 // function : ~OpenGl_Workspace
117 // =======================================================================
118 OpenGl_Workspace::~OpenGl_Workspace()
122 // =======================================================================
123 // function : Activate
125 // =======================================================================
126 Standard_Boolean OpenGl_Workspace::Activate()
128 if (!OpenGl_Window::Activate())
129 return Standard_False;
133 ViewMatrix_applied = &myDefaultMatrix;
134 StructureMatrix_applied = &myDefaultMatrix;
136 ResetAppliedAspect();
138 return Standard_True;
141 // =======================================================================
142 // function : UseTransparency
143 // purpose : call_togl_transparency
144 // =======================================================================
145 void OpenGl_Workspace::UseTransparency (const Standard_Boolean theFlag)
147 if ((myUseTransparency ? 1 : 0) != (theFlag ? 1 : 0))
149 myUseTransparency = theFlag;
154 //=======================================================================
155 //function : ResetAppliedAspect
156 //purpose : Sets default values of GL parameters in accordance with default aspects
157 //=======================================================================
158 void OpenGl_Workspace::ResetAppliedAspect()
160 NamedStatus = IsTextureEnabled() ? OPENGL_NS_TEXTURE : 0;
161 HighlightColor = &myDefaultHighlightColor;
162 AspectLine_set = &myDefaultAspectLine;
163 AspectLine_applied = NULL;
164 AspectFace_set = &myDefaultAspectFace;
165 AspectFace_applied = NULL;
166 AspectMarker_set = &myDefaultAspectMarker;
167 AspectMarker_applied = NULL;
168 AspectText_set = &myDefaultAspectText;
169 AspectText_applied = NULL;
170 TextParam_set = &myDefaultTextParam;
171 TextParam_applied = NULL;
172 PolygonOffset_applied = NULL;
174 AspectLine(Standard_True);
175 AspectFace(Standard_True);
176 AspectMarker(Standard_True);
177 AspectText(Standard_True);