1 // Created on: 2011-09-20
2 // Created by: Sergey ZERCHANINOV
3 // Copyright (c) 2011-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #ifndef OpenGl_Window_HeaderFile
17 #define OpenGl_Window_HeaderFile
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>
25 #if defined(__APPLE__)
26 #import <TargetConditionals.h>
29 #if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
38 class OpenGl_GraphicDriver;
40 DEFINE_STANDARD_HANDLE(OpenGl_Window,Standard_Transient)
42 //! This class represents low-level wrapper over window with GL context.
43 //! The window itself should be provided to constructor.
44 class OpenGl_Window : public Standard_Transient
46 DEFINE_STANDARD_RTTIEXT(OpenGl_Window, Standard_Transient)
49 //! Empty constructor.
50 Standard_EXPORT OpenGl_Window();
52 //! Initialize the new window - prepare GL context for specified window.
53 //! Throws exception in case of failure.
54 Standard_EXPORT void Init (const Handle(OpenGl_GraphicDriver)& theDriver,
55 const Handle(Aspect_Window)& thePlatformWindow,
56 const Handle(Aspect_Window)& theSizeWindow,
57 Aspect_RenderingContext theGContext,
58 const Handle(OpenGl_Caps)& theCaps,
59 const Handle(OpenGl_Context)& theShareCtx);
62 Standard_EXPORT virtual ~OpenGl_Window();
64 //! Resizes the window.
65 Standard_EXPORT virtual void Resize();
67 //! Return platform window.
68 const Handle(Aspect_Window)& PlatformWindow() { return myPlatformWindow; }
70 //! Return window object defining dimensions.
71 const Handle(Aspect_Window)& SizeWindow() { return mySizeWindow; }
73 Standard_Integer Width() const { return mySize.x(); }
74 Standard_Integer Height() const { return mySize.y(); }
76 //! Return OpenGL context.
77 const Handle(OpenGl_Context)& GetGlContext() const { return myGlContext; }
79 //! Makes GL context for this window active in current thread
80 Standard_EXPORT virtual Standard_Boolean Activate();
82 //! Sets swap interval for this window according to the context's settings.
83 Standard_EXPORT void SetSwapInterval (Standard_Boolean theToForceNoSync);
87 //! Activates GL context and setup viewport.
88 Standard_EXPORT void init();
92 Handle(OpenGl_Context) myGlContext;
93 Standard_Boolean myOwnGContext; //!< set to TRUE if GL context was not created by this class
94 Handle(Aspect_Window) myPlatformWindow; //!< software platform window wrapper
95 Handle(Aspect_Window) mySizeWindow; //!< window object defining dimensions
96 #if defined(__APPLE__)
97 #if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
100 Graphic3d_Vec2i mySizePt; //!< window width x height in logical units
102 Graphic3d_Vec2i mySize; //!< window width x height in pixels
104 Standard_Integer mySwapInterval;//!< last assigned swap interval (VSync) for this window
108 #endif //_OpenGl_Window_Header