Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:04:34

0001 // Created on: 2011-10-20
0002 // Created by: Sergey ZERCHANINOV
0003 // Copyright (c) 2011-2014 OPEN CASCADE SAS
0004 //
0005 // This file is part of Open CASCADE Technology software library.
0006 //
0007 // This library is free software; you can redistribute it and/or modify it under
0008 // the terms of the GNU Lesser General Public License version 2.1 as published
0009 // by the Free Software Foundation, with special exception defined in the file
0010 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0011 // distribution for complete text of the license and disclaimer of any warranty.
0012 //
0013 // Alternatively, this file may be used under the terms of Open CASCADE
0014 // commercial license or contractual agreement.
0015 
0016 #ifndef _OpenGl_GraphicDriver_HeaderFile
0017 #define _OpenGl_GraphicDriver_HeaderFile
0018 
0019 #include <Graphic3d_GraphicDriver.hxx>
0020 
0021 #include <Aspect_DisplayConnection.hxx>
0022 #include <Graphic3d_CView.hxx>
0023 #include <Graphic3d_CStructure.hxx>
0024 #include <NCollection_DataMap.hxx>
0025 #include <OpenGl_Context.hxx>
0026 
0027 class Aspect_Window;
0028 class OpenGl_Structure;
0029 class OpenGl_View;
0030 class OpenGl_Window;
0031 
0032 //! Tool class to implement consistent state counter
0033 //! for objects inside the same driver instance.
0034 class OpenGl_StateCounter
0035 {
0036 public:
0037 
0038   OpenGl_StateCounter() : myCounter (0) { }
0039 
0040   Standard_Size Increment() { return ++myCounter; }
0041 
0042 private:
0043 
0044   Standard_Size myCounter;
0045 };
0046 
0047 //! This class defines an OpenGl graphic driver
0048 class OpenGl_GraphicDriver : public Graphic3d_GraphicDriver
0049 {
0050   DEFINE_STANDARD_RTTIEXT(OpenGl_GraphicDriver, Graphic3d_GraphicDriver)
0051 public:
0052 
0053   //! Constructor.
0054   //! @param theDisp connection to display, required on Linux but optional on other systems
0055   //! @param theToInitialize perform initialization of default OpenGL context on construction
0056   Standard_EXPORT OpenGl_GraphicDriver (const Handle(Aspect_DisplayConnection)& theDisp,
0057                                         const Standard_Boolean                  theToInitialize = Standard_True);
0058 
0059   //! Destructor.
0060   Standard_EXPORT virtual ~OpenGl_GraphicDriver();
0061 
0062   //! Release default context.
0063   Standard_EXPORT void ReleaseContext();
0064 
0065   //! Perform initialization of default OpenGL context.
0066   Standard_EXPORT Standard_Boolean InitContext();
0067 
0068   //! Initialize default OpenGL context using existing one.
0069   //! @param theEglDisplay EGL connection to the Display
0070   //! @param theEglContext EGL rendering context
0071   //! @param theEglConfig  EGL configuration
0072   Standard_EXPORT Standard_Boolean InitEglContext (Aspect_Display          theEglDisplay,
0073                                                    Aspect_RenderingContext theEglContext,
0074                                                    void*                   theEglConfig);
0075 
0076   //! Request limit of graphic resource of specific type.
0077   Standard_EXPORT virtual Standard_Integer InquireLimit (const Graphic3d_TypeOfLimit theType) const Standard_OVERRIDE;
0078 
0079 public:
0080 
0081   Standard_EXPORT virtual Handle(Graphic3d_CStructure) CreateStructure (const Handle(Graphic3d_StructureManager)& theManager) Standard_OVERRIDE;
0082 
0083   Standard_EXPORT virtual void RemoveStructure (Handle(Graphic3d_CStructure)& theCStructure) Standard_OVERRIDE;
0084 
0085   Standard_EXPORT virtual Handle(Graphic3d_CView) CreateView (const Handle(Graphic3d_StructureManager)& theMgr) Standard_OVERRIDE;
0086 
0087   Standard_EXPORT virtual void RemoveView (const Handle(Graphic3d_CView)& theView) Standard_OVERRIDE;
0088 
0089   //! Create OpenGL window from native window.
0090   //! @param[in] theNativeWindow native window holder
0091   //! @param[in] theSizeWindow object defining window dimensions
0092   //! @param[in] theContext existing native rendering context
0093   Standard_EXPORT virtual Handle(OpenGl_Window) CreateRenderWindow (const Handle(Aspect_Window)& theNativeWindow,
0094                                                                     const Handle(Aspect_Window)& theSizeWindow,
0095                                                                     const Aspect_RenderingContext theContext);
0096 
0097 public:
0098 
0099   Standard_EXPORT void TextSize (const Handle(Graphic3d_CView)& theView,
0100                                  const Standard_CString         theText,
0101                                  const Standard_ShortReal       theHeight,
0102                                  Standard_ShortReal&            theWidth,
0103                                  Standard_ShortReal&            theAscent,
0104                                  Standard_ShortReal&            theDescent) const Standard_OVERRIDE;
0105 
0106   Standard_EXPORT Standard_ShortReal DefaultTextHeight() const Standard_OVERRIDE;
0107 
0108   Standard_EXPORT Standard_Boolean ViewExists (const Handle(Aspect_Window)& theWindow, Handle(Graphic3d_CView)& theView) Standard_OVERRIDE;
0109 
0110 public:
0111 
0112   //! Adds a layer to all views.
0113   //! @param[in] theNewLayerId id of new layer, should be > 0 (negative values are reserved for default layers).
0114   //! @param[in] theSettings   new layer settings
0115   //! @param[in] theLayerAfter id of layer to append new layer before
0116   Standard_EXPORT virtual void InsertLayerBefore (const Graphic3d_ZLayerId theNewLayerId,
0117                                                   const Graphic3d_ZLayerSettings& theSettings,
0118                                                   const Graphic3d_ZLayerId theLayerAfter) Standard_OVERRIDE;
0119 
0120   //! Adds a layer to all views.
0121   //! @param[in] theNewLayerId  id of created layer
0122   //! @param[in] theSettings    new layer settings
0123   //! @param[in] theLayerBefore id of layer to append new layer after
0124   Standard_EXPORT virtual void InsertLayerAfter (const Graphic3d_ZLayerId theNewLayerId,
0125                                                  const Graphic3d_ZLayerSettings& theSettings,
0126                                                  const Graphic3d_ZLayerId theLayerBefore) Standard_OVERRIDE;
0127 
0128   //! Removes Z layer. All structures displayed at the moment in layer will be displayed in
0129   //! default layer (the bottom-level z layer). By default, there are always default
0130   //! bottom-level layer that can't be removed.  The passed theLayerId should be not less than 0
0131   //! (reserved for default layers that can not be removed).
0132   Standard_EXPORT void RemoveZLayer (const Graphic3d_ZLayerId theLayerId) Standard_OVERRIDE;
0133 
0134   //! Sets the settings for a single Z layer.
0135   Standard_EXPORT void SetZLayerSettings (const Graphic3d_ZLayerId theLayerId, const Graphic3d_ZLayerSettings& theSettings) Standard_OVERRIDE;
0136 
0137 public:
0138 
0139   //! @return the visualization options
0140   inline const OpenGl_Caps& Options() const
0141   {
0142     return *myCaps.operator->();
0143   }
0144 
0145   //! @return the visualization options
0146   inline OpenGl_Caps& ChangeOptions()
0147   {
0148     return *myCaps.operator->();
0149   }
0150 
0151   //! Specify swap buffer behavior.
0152   Standard_EXPORT void SetBuffersNoSwap (const Standard_Boolean theIsNoSwap);
0153 
0154   //! VBO usage can be forbidden by this method even if it is supported by GL driver.
0155   //! Notice that disabling of VBO will cause rendering performance degradation.
0156   //! Warning! This method should be called only before any primitives are displayed in GL scene!
0157   Standard_EXPORT virtual void EnableVBO (const Standard_Boolean theToTurnOn) Standard_OVERRIDE;
0158 
0159 
0160   //! Returns TRUE if vertical synchronization with display refresh rate (VSync) should be used; TRUE by default.
0161   Standard_EXPORT virtual bool IsVerticalSync() const Standard_OVERRIDE;
0162 
0163   //! Set if vertical synchronization with display refresh rate (VSync) should be used.
0164   Standard_EXPORT virtual void SetVerticalSync (bool theToEnable) Standard_OVERRIDE;
0165 
0166   //! Returns information about GPU memory usage.
0167   //! Please read OpenGl_Context::MemoryInfo() for more description.
0168   Standard_EXPORT Standard_Boolean MemoryInfo (Standard_Size&           theFreeBytes,
0169                                                TCollection_AsciiString& theInfo) const Standard_OVERRIDE;
0170 
0171 public:
0172 
0173   //! Method to retrieve valid GL context.
0174   //! Could return NULL-handle if no window created by this driver.
0175   //! @param theBound if TRUE then currently bound context will be returned,
0176   //!                 any context will be returned otherwise
0177   Standard_EXPORT const Handle(OpenGl_Context)& GetSharedContext (bool theBound = false) const;
0178 
0179   Aspect_Display          getRawGlDisplay() const { return myEglDisplay; }
0180   Aspect_RenderingContext getRawGlContext() const { return myEglContext;  }
0181   void*                   getRawGlConfig()  const { return myEglConfig; }
0182 
0183   //! Set device lost flag for redrawn views.
0184   Standard_EXPORT void setDeviceLost();
0185 
0186 public:
0187 
0188   //! State counter for OpenGl structures.
0189   OpenGl_StateCounter* GetStateCounter() const { return &myStateCounter; }
0190 
0191   //! Returns unique ID for primitive arrays.
0192   Standard_Size GetNextPrimitiveArrayUID() const { return myUIDGenerator.Increment(); }
0193 
0194 protected:
0195 
0196   //! Choose default visual for new windows created by Aspect_DisplayConnection.
0197   Standard_EXPORT void chooseVisualInfo();
0198 
0199 protected:
0200 
0201   Standard_Boolean        myIsOwnContext; //!< indicates that shared context has been created within OpenGl_GraphicDriver
0202 
0203   Aspect_Display          myEglDisplay;   //!< EGL connection to the Display : EGLDisplay
0204   Aspect_RenderingContext myEglContext;   //!< EGL rendering context         : EGLContext
0205   void*                   myEglConfig;    //!< EGL configuration             : EGLConfig
0206 
0207   Handle(OpenGl_Caps)                                      myCaps;
0208   NCollection_Map<Handle(OpenGl_View)>                     myMapOfView;
0209   NCollection_DataMap<Standard_Integer, OpenGl_Structure*> myMapOfStructure;
0210 
0211   mutable OpenGl_StateCounter myStateCounter; //!< State counter for OpenGl structures.
0212   mutable OpenGl_StateCounter myUIDGenerator; //!< Unique ID counter for primitive arrays.
0213 
0214 };
0215 
0216 DEFINE_STANDARD_HANDLE(OpenGl_GraphicDriver, Graphic3d_GraphicDriver)
0217 
0218 #endif //_OpenGl_GraphicDriver_HeaderFile