0024023: Revamp the OCCT Handle -- automatic
[occt.git] / src / OpenGl / OpenGl_Window.hxx
CommitLineData
b311480e 1// Created on: 2011-09-20
2// Created by: Sergey ZERCHANINOV
973c2be1 3// Copyright (c) 2011-2014 OPEN CASCADE SAS
b311480e 4//
973c2be1 5// This file is part of Open CASCADE Technology software library.
b311480e 6//
d5f74e42 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
973c2be1 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.
b311480e 12//
973c2be1 13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
b311480e 15
2166f0fa
SK
16#ifndef _OpenGl_Window_Header
17#define _OpenGl_Window_Header
18
3695b8c2 19#include <OpenGl_GlCore11.hxx>
2166f0fa 20#include <InterfaceGraphic_Aspect.hxx>
58655684 21#include <OpenGl_Caps.hxx>
2166f0fa 22
3695b8c2 23
24#include <MMgt_TShared.hxx>
2166f0fa 25
a2e4f780 26#if defined(__APPLE__)
27 #import <TargetConditionals.h>
28#endif
29
30#if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
31 #ifdef __OBJC__
32 @class UIView;
33 #else
34 struct UIView;
35 #endif
36#endif
37
2166f0fa
SK
38//! This class represents low-level wrapper over window with GL context.
39//! The window itself should be provided to constructor.
40class OpenGl_Window : public MMgt_TShared
41{
42public:
43
44 //! Main constructor - prepare GL context for specified window.
25b97fac 45 OpenGl_Window (const Handle(OpenGl_GraphicDriver)& theDriver,
2166f0fa 46 const CALL_DEF_WINDOW& theCWindow,
5e27df78 47 Aspect_RenderingContext theGContext,
58655684 48 const Handle(OpenGl_Caps)& theCaps,
5e27df78 49 const Handle(OpenGl_Context)& theShareCtx);
2166f0fa
SK
50
51 //! Destructor
52 virtual ~OpenGl_Window();
53
54 //! Resizes the window.
55 void Resize (const CALL_DEF_WINDOW& theCWindow);
56
57 //! Reads depth component for current scene into specified buffer.
58 void ReadDepths (const Standard_Integer theX, const Standard_Integer theY,
59 const Standard_Integer theWidth, const Standard_Integer theHeight,
60 float* theDepths);
61
62 void SetBackgroundColor (const Standard_ShortReal theR,
63 const Standard_ShortReal theG,
64 const Standard_ShortReal theB);
65
2166f0fa
SK
66 Standard_Integer Width() const { return myWidth; }
67 Standard_Integer Height() const { return myHeight; }
68 const TEL_COLOUR& BackgroundColor() const { return myBgColor; }
2166f0fa
SK
69
70 const Handle(OpenGl_Context)& GetGlContext() const { return myGlContext; }
71
2166f0fa
SK
72protected:
73
74 //! Activates GL context and setup viewport.
75 void Init();
76
77 //! Makes GL context for this window active in current thread
78 virtual Standard_Boolean Activate();
79
80 void EnableFeatures() const;
81 void DisableFeatures() const;
82
2166f0fa
SK
83protected:
84
2166f0fa 85 Handle(OpenGl_Context) myGlContext;
2166f0fa 86 Standard_Boolean myOwnGContext; //!< set to TRUE if GL context was not created by this class
a2e4f780 87#if defined(__APPLE__)
88#if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
89 UIView* myUIView;
90#endif
91 Standard_Integer myWidthPt; //!< window width in logical units
92 Standard_Integer myHeightPt; //!< window height in logical units
93#endif
94 Standard_Integer myWidth; //!< window width in pixels
95 Standard_Integer myHeight; //!< window height in pixels
73192b37 96 TEL_COLOUR myBgColor; //!< background color
2166f0fa 97
f978241f 98 Standard_Integer mySwapInterval;//!< last assigned swap interval (VSync) for this window
99
2166f0fa
SK
100public:
101
ec357c5c 102 DEFINE_STANDARD_RTTI(OpenGl_Window, MMgt_TShared) // Type definition
1c35b92f 103 DEFINE_STANDARD_ALLOC
2166f0fa
SK
104
105};
106
107#endif //_OpenGl_Window_Header