0024947: Redesign OCCT legacy type system -- automatic
[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_Window.hxx>
25 #include <Handle_OpenGl_GraphicDriver.hxx>
26
27 #include <MMgt_TShared.hxx>
28
29 #if defined(__APPLE__)
30   #import <TargetConditionals.h>
31 #endif
32
33 #if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
34   #ifdef __OBJC__
35     @class UIView;
36   #else
37     struct UIView;
38   #endif
39 #endif
40
41 //! This class represents low-level wrapper over window with GL context.
42 //! The window itself should be provided to constructor.
43 class OpenGl_Window : public MMgt_TShared
44 {
45 public:
46
47   //! Main constructor - prepare GL context for specified window.
48   OpenGl_Window (const Handle(OpenGl_GraphicDriver)& theDriver,
49                  const CALL_DEF_WINDOW&        theCWindow,
50                  Aspect_RenderingContext       theGContext,
51                  const Handle(OpenGl_Caps)&    theCaps,
52                  const Handle(OpenGl_Context)& theShareCtx);
53
54   //! Destructor
55   virtual ~OpenGl_Window();
56
57   //! Resizes the window.
58   void Resize (const CALL_DEF_WINDOW& theCWindow);
59
60   //! Reads depth component for current scene into specified buffer.
61   void ReadDepths (const Standard_Integer theX,     const Standard_Integer theY,
62                    const Standard_Integer theWidth, const Standard_Integer theHeight,
63                    float* theDepths);
64
65   void SetBackgroundColor (const Standard_ShortReal theR,
66                            const Standard_ShortReal theG,
67                            const Standard_ShortReal theB);
68
69   Standard_Integer Width()  const { return myWidth; }
70   Standard_Integer Height() const { return myHeight; }
71   const TEL_COLOUR& BackgroundColor() const { return myBgColor; }
72
73   const Handle(OpenGl_Context)& GetGlContext() const { return myGlContext; }
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 protected:
87
88   Handle(OpenGl_Context) myGlContext;
89   Standard_Boolean       myOwnGContext; //!< set to TRUE if GL context was not created by this class
90 #if defined(__APPLE__)
91 #if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
92   UIView*                myUIView;
93 #endif
94   Standard_Integer       myWidthPt;     //!< window width  in logical units
95   Standard_Integer       myHeightPt;    //!< window height in logical units
96 #endif
97   Standard_Integer       myWidth;       //!< window width  in pixels
98   Standard_Integer       myHeight;      //!< window height in pixels
99   TEL_COLOUR             myBgColor;     //!< background color
100
101   Standard_Integer       mySwapInterval;//!< last assigned swap interval (VSync) for this window
102
103 public:
104
105   DEFINE_STANDARD_RTTI(OpenGl_Window, MMgt_TShared) // Type definition
106   DEFINE_STANDARD_ALLOC
107
108 };
109
110 #endif //_OpenGl_Window_Header