0023316: OpenGl package can not be compiled on RedHat40-64
[occt.git] / src / OpenGl / OpenGl_Window.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_Window_Header
21 #define _OpenGl_Window_Header
22
23 #include <OpenGl_GlCore11.hxx>
24 #include <InterfaceGraphic_Aspect.hxx>
25
26 #include <Handle_OpenGl_Context.hxx>
27 #include <Handle_OpenGl_Display.hxx>
28 #include <Handle_OpenGl_Window.hxx>
29
30 #include <MMgt_TShared.hxx>
31
32 //! This class represents low-level wrapper over window with GL context.
33 //! The window itself should be provided to constructor.
34 class OpenGl_Window : public MMgt_TShared
35 {
36 public:
37
38   //! Main constructor - prepare GL context for specified window.
39   OpenGl_Window (const Handle(OpenGl_Display)& theDisplay,
40                  const CALL_DEF_WINDOW&        theCWindow,
41                  Aspect_RenderingContext       theGContext,
42                  const Handle(OpenGl_Context)& theShareCtx);
43
44   //! Destructor
45   virtual ~OpenGl_Window();
46
47   //! Resizes the window.
48   void Resize (const CALL_DEF_WINDOW& theCWindow);
49
50   //! Reads depth component for current scene into specified buffer.
51   void ReadDepths (const Standard_Integer theX,     const Standard_Integer theY,
52                    const Standard_Integer theWidth, const Standard_Integer theHeight,
53                    float* theDepths);
54
55   void SetBackgroundColor (const Standard_ShortReal theR,
56                            const Standard_ShortReal theG,
57                            const Standard_ShortReal theB);
58
59   void EnablePolygonOffset() const;
60   void DisablePolygonOffset() const;
61
62   Standard_Integer Width()  const { return myWidth; }
63   Standard_Integer Height() const { return myHeight; }
64   const TEL_COLOUR& BackgroundColor() const { return myBgColor; }
65   Standard_Boolean Dither()     const { return myDither; }
66   Standard_Boolean BackDither() const { return myBackDither; }
67
68   const Handle(OpenGl_Display)& GetDisplay() const { return myDisplay; }
69
70   const Handle(OpenGl_Context)& GetGlContext() const { return myGlContext; }
71
72   //! This method will be removed in future version!
73   GLCONTEXT GetGContext() const;
74
75 protected:
76
77   //! Activates GL context and setup viewport.
78   void Init();
79
80   //! Makes GL context for this window active in current thread
81   virtual Standard_Boolean Activate();
82
83   void EnableFeatures() const;
84   void DisableFeatures() const;
85
86   //! Draw directly to the FRONT buffer. Can cause artifacts on the screen.
87   void MakeFrontBufCurrent() const;
88
89   //! Draw to BACK buffer. Normal and default state.
90   void MakeBackBufCurrent() const;
91
92   //! Draw simultaneously to BACK and FRONT buffers. Abnormal usage.
93   void MakeFrontAndBackBufCurrent() const;
94
95 protected:
96
97   Handle(OpenGl_Display) myDisplay;
98   Handle(OpenGl_Context) myGlContext;
99   Standard_Boolean       myOwnGContext; //!< set to TRUE if GL context was not created by this class
100 #if (defined(_WIN32) || defined(__WIN32__))
101   BOOL                   mySysPalInUse;
102 #endif
103
104   Standard_Integer       myWidth;       // WSWidth
105   Standard_Integer       myHeight;      // WSHeight
106   TEL_COLOUR             myBgColor;     // WSBackground
107   Standard_Boolean       myDither;
108   Standard_Boolean       myBackDither;
109
110 public:
111
112   DEFINE_STANDARD_RTTI(OpenGl_Window) // Type definition
113   DEFINE_STANDARD_ALLOC
114
115 };
116
117 #endif //_OpenGl_Window_Header