Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/opencascade/OpenGl_GraphicDriver.hxx was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

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   OpenGl_StateCounter()
0038       : myCounter(0)
0039   {
0040   }
0041 
0042   size_t Increment() { return ++myCounter; }
0043 
0044 private:
0045   size_t myCounter;
0046 };
0047 
0048 //! This class defines an OpenGl graphic driver
0049 class OpenGl_GraphicDriver : public Graphic3d_GraphicDriver
0050 {
0051   DEFINE_STANDARD_RTTIEXT(OpenGl_GraphicDriver, Graphic3d_GraphicDriver)
0052 public:
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 occ::handle<Aspect_DisplayConnection>& theDisp,
0057                                        const bool theToInitialize = true);
0058 
0059   //! Destructor.
0060   Standard_EXPORT ~OpenGl_GraphicDriver() override;
0061 
0062   //! Release default context.
0063   Standard_EXPORT void ReleaseContext();
0064 
0065   //! Perform initialization of default OpenGL context.
0066   Standard_EXPORT bool 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 bool InitEglContext(Aspect_Display          theEglDisplay,
0073                                       Aspect_RenderingContext theEglContext,
0074                                       void*                   theEglConfig);
0075 
0076   //! Request limit of graphic resource of specific type.
0077   Standard_EXPORT int InquireLimit(const Graphic3d_TypeOfLimit theType) const override;
0078 
0079 public:
0080   Standard_EXPORT occ::handle<Graphic3d_CStructure> CreateStructure(
0081     const occ::handle<Graphic3d_StructureManager>& theManager) override;
0082 
0083   Standard_EXPORT void RemoveStructure(occ::handle<Graphic3d_CStructure>& theCStructure) override;
0084 
0085   Standard_EXPORT occ::handle<Graphic3d_CView> CreateView(
0086     const occ::handle<Graphic3d_StructureManager>& theMgr) override;
0087 
0088   Standard_EXPORT void RemoveView(const occ::handle<Graphic3d_CView>& theView) override;
0089 
0090   //! Create OpenGL window from native window.
0091   //! @param[in] theNativeWindow native window holder
0092   //! @param[in] theSizeWindow object defining window dimensions
0093   //! @param[in] theContext existing native rendering context
0094   Standard_EXPORT virtual occ::handle<OpenGl_Window> CreateRenderWindow(
0095     const occ::handle<Aspect_Window>& theNativeWindow,
0096     const occ::handle<Aspect_Window>& theSizeWindow,
0097     const Aspect_RenderingContext     theContext);
0098 
0099 public:
0100   Standard_EXPORT void TextSize(const occ::handle<Graphic3d_CView>& theView,
0101                                 const char* const                   theText,
0102                                 const float                         theHeight,
0103                                 float&                              theWidth,
0104                                 float&                              theAscent,
0105                                 float&                              theDescent) const override;
0106 
0107   Standard_EXPORT float DefaultTextHeight() const override;
0108 
0109   Standard_EXPORT bool ViewExists(const occ::handle<Aspect_Window>& theWindow,
0110                                   occ::handle<Graphic3d_CView>&     theView) override;
0111 
0112 public:
0113   //! Adds a layer to all views.
0114   //! @param[in] theNewLayerId id of new layer, should be > 0 (negative values are reserved for
0115   //! default layers).
0116   //! @param[in] theSettings   new layer settings
0117   //! @param[in] theLayerAfter id of layer to append new layer before
0118   Standard_EXPORT void InsertLayerBefore(const Graphic3d_ZLayerId        theNewLayerId,
0119                                          const Graphic3d_ZLayerSettings& theSettings,
0120                                          const Graphic3d_ZLayerId        theLayerAfter) override;
0121 
0122   //! Adds a layer to all views.
0123   //! @param[in] theNewLayerId  id of created layer
0124   //! @param[in] theSettings    new layer settings
0125   //! @param[in] theLayerBefore id of layer to append new layer after
0126   Standard_EXPORT void InsertLayerAfter(const Graphic3d_ZLayerId        theNewLayerId,
0127                                         const Graphic3d_ZLayerSettings& theSettings,
0128                                         const Graphic3d_ZLayerId        theLayerBefore) override;
0129 
0130   //! Removes Z layer. All structures displayed at the moment in layer will be displayed in
0131   //! default layer (the bottom-level z layer). By default, there are always default
0132   //! bottom-level layer that can't be removed. The passed theLayerId should be not less than 0
0133   //! (reserved for default layers that can not be removed).
0134   Standard_EXPORT void RemoveZLayer(const Graphic3d_ZLayerId theLayerId) override;
0135 
0136   //! Sets the settings for a single Z layer.
0137   Standard_EXPORT void SetZLayerSettings(const Graphic3d_ZLayerId        theLayerId,
0138                                          const Graphic3d_ZLayerSettings& theSettings) override;
0139 
0140 public:
0141   //! @return the visualization options
0142   inline const OpenGl_Caps& Options() const { return *myCaps.operator->(); }
0143 
0144   //! @return the visualization options
0145   inline OpenGl_Caps& ChangeOptions() { return *myCaps.operator->(); }
0146 
0147   //! Specify swap buffer behavior.
0148   Standard_EXPORT void SetBuffersNoSwap(const bool theIsNoSwap);
0149 
0150   //! VBO usage can be forbidden by this method even if it is supported by GL driver.
0151   //! Notice that disabling of VBO will cause rendering performance degradation.
0152   //! Warning! This method should be called only before any primitives are displayed in GL scene!
0153   Standard_EXPORT void EnableVBO(const bool theToTurnOn) override;
0154 
0155   //! Returns TRUE if vertical synchronization with display refresh rate (VSync) should be used;
0156   //! TRUE by default.
0157   Standard_EXPORT bool IsVerticalSync() const override;
0158 
0159   //! Set if vertical synchronization with display refresh rate (VSync) should be used.
0160   Standard_EXPORT void SetVerticalSync(bool theToEnable) override;
0161 
0162   //! Returns information about GPU memory usage.
0163   //! Please read OpenGl_Context::MemoryInfo() for more description.
0164   Standard_EXPORT bool MemoryInfo(size_t&                  theFreeBytes,
0165                                   TCollection_AsciiString& theInfo) const override;
0166 
0167 public:
0168   //! Method to retrieve valid GL context.
0169   //! Could return NULL-handle if no window created by this driver.
0170   //! @param theBound if TRUE then currently bound context will be returned,
0171   //!                 any context will be returned otherwise
0172   Standard_EXPORT const occ::handle<OpenGl_Context>& GetSharedContext(bool theBound = false) const;
0173 
0174   Aspect_Display getRawGlDisplay() const { return myEglDisplay; }
0175 
0176   Aspect_RenderingContext getRawGlContext() const { return myEglContext; }
0177 
0178   void* getRawGlConfig() const { return myEglConfig; }
0179 
0180   //! Set device lost flag for redrawn views.
0181   Standard_EXPORT void setDeviceLost();
0182 
0183 public:
0184   //! State counter for OpenGl structures.
0185   OpenGl_StateCounter* GetStateCounter() const { return &myStateCounter; }
0186 
0187   //! Returns unique ID for primitive arrays.
0188   size_t GetNextPrimitiveArrayUID() const { return myUIDGenerator.Increment(); }
0189 
0190 protected:
0191   //! Choose default visual for new windows created by Aspect_DisplayConnection.
0192   Standard_EXPORT void chooseVisualInfo();
0193 
0194 protected:
0195   // clang-format off
0196   bool        myIsOwnContext; //!< indicates that shared context has been created within OpenGl_GraphicDriver
0197   // clang-format on
0198 
0199   Aspect_Display          myEglDisplay; //!< EGL connection to the Display : EGLDisplay
0200   Aspect_RenderingContext myEglContext; //!< EGL rendering context         : EGLContext
0201   void*                   myEglConfig;  //!< EGL configuration             : EGLConfig
0202 
0203   occ::handle<OpenGl_Caps>                    myCaps;
0204   NCollection_Map<occ::handle<OpenGl_View>>   myMapOfView;
0205   NCollection_DataMap<int, OpenGl_Structure*> myMapOfStructure;
0206 
0207   mutable OpenGl_StateCounter myStateCounter; //!< State counter for OpenGl structures.
0208   mutable OpenGl_StateCounter myUIDGenerator; //!< Unique ID counter for primitive arrays.
0209 };
0210 
0211 #endif //_OpenGl_GraphicDriver_HeaderFile