0023457: Slow text rendering
[occt.git] / src / OpenGl / OpenGl_Display.hxx
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
20 #ifndef _OpenGl_Display_Header
21 #define _OpenGl_Display_Header
22
23 #include <Handle_OpenGl_Display.hxx>
24 #include <MMgt_TShared.hxx>
25
26 #include <Standard_CString.hxx>
27 #include <TColStd_HArray1OfByte.hxx>
28 #include <NCollection_DataMap.hxx>
29
30 #include <Aspect_Display.hxx>
31 #include <Aspect_Drawable.hxx>
32 #include <Aspect_TypeOfLine.hxx>
33 #include <Aspect_TypeOfMarker.hxx>
34
35 #include <Font_FontAspect.hxx>
36
37 #include <InterfaceGraphic_telem.hxx>
38
39 #include <Handle_OpenGl_Window.hxx>
40
41 struct OpenGl_Facilities
42 {
43   int AntiAliasing;
44   int DepthCueing;
45   int DoubleBuffer;
46   int ZBuffer;
47   int MaxLights;
48   int MaxViews;
49 };
50
51 struct OPENGL_MARKER_DATA
52 {
53   unsigned int ListId;
54   unsigned int Width;
55   unsigned int Height;
56   unsigned char* Array;
57   DEFINE_STANDARD_ALLOC
58 };
59
60 typedef NCollection_DataMap<int,OPENGL_MARKER_DATA> OpenGl_MapOfUserMarker;
61
62 class OpenGl_AspectText;
63 struct OpenGl_TextParam;
64
65 class OpenGl_Display : public MMgt_TShared
66 {
67  public:
68   OpenGl_Display (const Standard_CString ADisplay);
69   OpenGl_Display (const Aspect_Display ADisplay);
70   virtual ~OpenGl_Display ();
71
72   Aspect_Display GetDisplay () const { return myDisplay; }
73
74   Handle(OpenGl_Window) GetWindow (const Aspect_Drawable AParent) const;
75   void SetWindow (const Aspect_Drawable AParent, const Handle(OpenGl_Window) &AWindow);
76
77   const OpenGl_Facilities & Facilities () const { return myFacilities; }
78
79   Standard_Boolean DBuffer () const { return myDBuffer; }
80   Standard_Boolean Dither () const { return myDither; }
81   Standard_Boolean BackDither () const { return myBackDither; }
82   Standard_Boolean Walkthrough () const { return myWalkthrough; }
83   Standard_Boolean SymPerspective() const { return mySymPerspective; }
84   Standard_Boolean PolygonOffset (Standard_ShortReal &AFactor, Standard_ShortReal &AUnits) const
85   {
86     AFactor = myOffsetFactor;
87     AUnits = myOffsetUnits;
88     return Standard_True;
89   }
90   Standard_Integer AntiAliasingMode () const { return myAntiAliasingMode; }
91
92   // System attributes
93
94   void InitAttributes ();
95
96   const char * GetStringForMarker (const Aspect_TypeOfMarker AType, const Tfloat AVal) const;
97
98   void SetBaseForMarker () const;
99
100   void SetTypeOfLine (const Aspect_TypeOfLine AType) const;
101
102   void SetTypeOfHatch (const int AType) const;
103
104   // User markers
105
106   void AddUserMarker (const Standard_Integer AIndex,
107                       const Standard_Integer AMarkWidth,
108                       const Standard_Integer AMarkHeight,
109                       const Handle(TColStd_HArray1OfByte)& ATexture);
110
111   void UpdateUserMarkers ();
112
113   Standard_Integer GetUserMarkerListIndex (const Standard_Integer AIndex) const;
114
115   friend class OpenGl_Window;
116
117   // Type definition
118   //
119   DEFINE_STANDARD_RTTI(OpenGl_Display)
120
121  protected:
122
123   void Init ();
124
125   void ExportText (const wchar_t *text, const int is2d, const float x, const float y, const float z, const OpenGl_AspectText *aspect, const OpenGl_TextParam *param, const short height);
126
127 #ifdef HAVE_GL2PS
128   static void getGL2PSFontName(const char *src_font, char *ps_font);
129 #endif
130
131   Aspect_Display   myDisplay;
132   OpenGl_Facilities myFacilities;
133
134   Standard_Boolean myDBuffer;
135   Standard_Boolean myDither;
136   Standard_Boolean myBackDither;
137   Standard_Boolean myWalkthrough;
138   Standard_Boolean mySymPerspective;
139   Standard_ShortReal myOffsetFactor;
140   Standard_ShortReal myOffsetUnits;
141   Standard_Integer myAntiAliasingMode;
142
143 #if (defined(_WIN32) || defined(__WIN32__))
144   NCollection_DataMap<Aspect_Drawable,  Handle(OpenGl_Window)> myMapOfWindows;
145 #else
146   NCollection_DataMap<Standard_Integer, Handle(OpenGl_Window)> myMapOfWindows;
147 #endif
148
149   unsigned int myLinestyleBase;
150   unsigned int myPatternBase;
151   unsigned int myMarkerBase;
152
153   OpenGl_MapOfUserMarker myMapOfUM;
154
155  public:
156   DEFINE_STANDARD_ALLOC
157 };
158
159 extern Handle(OpenGl_Display) openglDisplay;
160
161 #endif //OpenGl_Workspace_Header