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