0031082: Visualization - crash on display if there are no lights in the view
[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 <Aspect_RenderingContext.hxx>
20 #include <Aspect_Window.hxx>
21 #include <OpenGl_GlCore11.hxx>
22 #include <OpenGl_Caps.hxx>
23 #include <Standard_Transient.hxx>
24
25 #if defined(__APPLE__)
26   #import <TargetConditionals.h>
27 #endif
28
29 #if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
30   #ifdef __OBJC__
31     @class UIView;
32   #else
33     struct UIView;
34   #endif
35 #endif
36
37 class OpenGl_Context;
38 class OpenGl_GraphicDriver;
39
40 class OpenGl_Window;
41 DEFINE_STANDARD_HANDLE(OpenGl_Window,Standard_Transient)
42
43 //! This class represents low-level wrapper over window with GL context.
44 //! The window itself should be provided to constructor.
45 class OpenGl_Window : public Standard_Transient
46 {
47 public:
48
49   //! Main constructor - prepare GL context for specified window.
50   Standard_EXPORT OpenGl_Window (const Handle(OpenGl_GraphicDriver)& theDriver,
51                                  const Handle(Aspect_Window)&  thePlatformWindow,
52                                  Aspect_RenderingContext       theGContext,
53                                  const Handle(OpenGl_Caps)&    theCaps,
54                                  const Handle(OpenGl_Context)& theShareCtx);
55
56   //! Destructor
57   Standard_EXPORT virtual ~OpenGl_Window();
58
59   //! Resizes the window.
60   Standard_EXPORT virtual void Resize();
61
62   Handle(Aspect_Window) PlatformWindow() { return myPlatformWindow; }
63
64   Standard_Integer Width()  const { return myWidth; }
65   Standard_Integer Height() const { return myHeight; }
66
67   const Handle(OpenGl_Context)& GetGlContext() const { return myGlContext; }
68
69   //! Activates GL context and setup viewport.
70   Standard_EXPORT void Init();
71
72   //! Makes GL context for this window active in current thread
73   Standard_EXPORT virtual Standard_Boolean Activate();
74
75   //! Sets swap interval for this window according to the context's settings.
76   Standard_EXPORT void SetSwapInterval();
77
78 protected:
79
80   Handle(OpenGl_Context) myGlContext;
81   Standard_Boolean       myOwnGContext; //!< set to TRUE if GL context was not created by this class
82   Handle(Aspect_Window)  myPlatformWindow; //!< software platform window wrapper
83 #if defined(__APPLE__)
84 #if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
85   UIView*                myUIView;
86 #endif
87   Standard_Integer       myWidthPt;     //!< window width  in logical units
88   Standard_Integer       myHeightPt;    //!< window height in logical units
89 #endif
90   Standard_Integer       myWidth;       //!< window width  in pixels
91   Standard_Integer       myHeight;      //!< window height in pixels
92
93   Standard_Integer       mySwapInterval;//!< last assigned swap interval (VSync) for this window
94
95 public:
96
97   DEFINE_STANDARD_RTTIEXT(OpenGl_Window,Standard_Transient) // Type definition
98   DEFINE_STANDARD_ALLOC
99
100 };
101
102 #endif //_OpenGl_Window_Header