0024732: OpenGl_Context - retrieve functions up to GL4.4
[occt.git] / src / OpenGl / OpenGl_Window.hxx
1 // Created on: 2011-09-20
2 // Created by: Sergey ZERCHANINOV
3 // Copyright (c) 2011-2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 #ifndef _OpenGl_Window_Header
17 #define _OpenGl_Window_Header
18
19 #include <OpenGl_GlCore11.hxx>
20 #include <InterfaceGraphic_Aspect.hxx>
21 #include <OpenGl_Caps.hxx>
22
23 #include <Handle_OpenGl_Context.hxx>
24 #include <Handle_OpenGl_Display.hxx>
25 #include <Handle_OpenGl_Window.hxx>
26
27 #include <MMgt_TShared.hxx>
28
29 //! This class represents low-level wrapper over window with GL context.
30 //! The window itself should be provided to constructor.
31 class OpenGl_Window : public MMgt_TShared
32 {
33 public:
34
35   //! Main constructor - prepare GL context for specified window.
36   OpenGl_Window (const Handle(OpenGl_Display)& theDisplay,
37                  const CALL_DEF_WINDOW&        theCWindow,
38                  Aspect_RenderingContext       theGContext,
39                  const Handle(OpenGl_Caps)&    theCaps,
40                  const Handle(OpenGl_Context)& theShareCtx);
41
42   //! Destructor
43   virtual ~OpenGl_Window();
44
45   //! Resizes the window.
46   void Resize (const CALL_DEF_WINDOW& theCWindow);
47
48   //! Reads depth component for current scene into specified buffer.
49   void ReadDepths (const Standard_Integer theX,     const Standard_Integer theY,
50                    const Standard_Integer theWidth, const Standard_Integer theHeight,
51                    float* theDepths);
52
53   void SetBackgroundColor (const Standard_ShortReal theR,
54                            const Standard_ShortReal theG,
55                            const Standard_ShortReal theB);
56
57   void EnablePolygonOffset() const;
58   void DisablePolygonOffset() const;
59
60   Standard_Integer Width()  const { return myWidth; }
61   Standard_Integer Height() const { return myHeight; }
62   const TEL_COLOUR& BackgroundColor() const { return myBgColor; }
63   Standard_Boolean Dither()     const { return myDither; }
64   Standard_Boolean BackDither() const { return myBackDither; }
65
66   const Handle(OpenGl_Display)& GetDisplay() const { return myDisplay; }
67
68   const Handle(OpenGl_Context)& GetGlContext() const { return myGlContext; }
69
70   //! This method will be removed in future version!
71   GLCONTEXT GetGContext() const;
72
73 protected:
74
75   //! Activates GL context and setup viewport.
76   void Init();
77
78   //! Makes GL context for this window active in current thread
79   virtual Standard_Boolean Activate();
80
81   void EnableFeatures() const;
82   void DisableFeatures() const;
83
84   //! Draw directly to the FRONT buffer. Can cause artifacts on the screen.
85   void MakeFrontBufCurrent() const;
86
87   //! Draw to BACK buffer. Normal and default state.
88   void MakeBackBufCurrent() const;
89
90   //! Draw simultaneously to BACK and FRONT buffers. Abnormal usage.
91   void MakeFrontAndBackBufCurrent() const;
92
93 protected:
94
95   Handle(OpenGl_Display) myDisplay;
96   Handle(OpenGl_Context) myGlContext;
97   Standard_Boolean       myOwnGContext; //!< set to TRUE if GL context was not created by this class
98 #if (defined(_WIN32) || defined(__WIN32__))
99   BOOL                   mySysPalInUse;
100 #endif
101
102   Standard_Integer       myWidth;       // WSWidth
103   Standard_Integer       myHeight;      // WSHeight
104   TEL_COLOUR             myBgColor;     // WSBackground
105   Standard_Boolean       myDither;
106   Standard_Boolean       myBackDither;
107
108 public:
109
110   DEFINE_STANDARD_RTTI(OpenGl_Window) // Type definition
111   DEFINE_STANDARD_ALLOC
112
113 };
114
115 #endif //_OpenGl_Window_Header