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 : OpenGl_Window (theDisplay, theCWindow, theGContext),
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),
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)
95 theDisplay->InitAttributes();
97 // General initialization of the context
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);
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);
110 EnablePolygonOffset();
113 // =======================================================================
114 // function : ~OpenGl_Workspace
116 // =======================================================================
117 OpenGl_Workspace::~OpenGl_Workspace()
121 // =======================================================================
122 // function : Activate
124 // =======================================================================
125 Standard_Boolean OpenGl_Workspace::Activate()
127 if (!OpenGl_Window::Activate())
128 return Standard_False;
130 NamedStatus = IsTextureEnabled() ? OPENGL_NS_TEXTURE : 0;
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;
150 // =======================================================================
151 // function : UseTransparency
152 // purpose : call_togl_transparency
153 // =======================================================================
154 void OpenGl_Workspace::UseTransparency (const Standard_Boolean theFlag)
156 if ((myUseTransparency ? 1 : 0) != (theFlag ? 1 : 0))
158 myUseTransparency = theFlag;