1 // Created on: 1997-01-28
3 // Copyright (c) 1997-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #ifndef _Graphic3d_GraphicDriver_HeaderFile
18 #define _Graphic3d_GraphicDriver_HeaderFile
20 #include <Aspect_GenId.hxx>
21 #include <Graphic3d_CStructure.hxx>
22 #include <Graphic3d_ZLayerId.hxx>
23 #include <Graphic3d_ZLayerSettings.hxx>
24 #include <Graphic3d_TypeOfLimit.hxx>
25 #include <TColStd_SequenceOfInteger.hxx>
27 class Aspect_DisplayConnection;
29 class Graphic3d_CView;
30 class Graphic3d_Layer;
31 class Graphic3d_StructureManager;
32 class TCollection_AsciiString;
34 DEFINE_STANDARD_HANDLE(Graphic3d_GraphicDriver, Standard_Transient)
36 //! This class allows the definition of a graphic driver
37 //! for 3d interface (currently only OpenGl driver is used).
38 class Graphic3d_GraphicDriver : public Standard_Transient
40 DEFINE_STANDARD_RTTIEXT(Graphic3d_GraphicDriver, Standard_Transient)
43 //! Request limit of graphic resource of specific type.
44 virtual Standard_Integer InquireLimit (const Graphic3d_TypeOfLimit theType) const = 0;
46 //! Request maximum number of active light sources supported by driver and hardware.
47 Standard_Integer InquireLightLimit() const { return InquireLimit (Graphic3d_TypeOfLimit_MaxNbLights); }
49 //! Request maximum number of active clipping planes supported by driver and hardware.
50 Standard_Integer InquirePlaneLimit() const { return InquireLimit (Graphic3d_TypeOfLimit_MaxNbClipPlanes); }
52 //! Request maximum number of views supported by driver.
53 Standard_Integer InquireViewLimit() const { return InquireLimit (Graphic3d_TypeOfLimit_MaxNbViews); }
57 //! Creates new empty graphic structure
58 virtual Handle(Graphic3d_CStructure) CreateStructure (const Handle(Graphic3d_StructureManager)& theManager) = 0;
60 //! Removes structure from graphic driver and releases its resources.
61 virtual void RemoveStructure (Handle(Graphic3d_CStructure)& theCStructure) = 0;
63 //! Creates new view for this graphic driver.
64 virtual Handle(Graphic3d_CView) CreateView (const Handle(Graphic3d_StructureManager)& theMgr) = 0;
66 //! Removes view from graphic driver and releases its resources.
67 virtual void RemoveView (const Handle(Graphic3d_CView)& theView) = 0;
69 //! enables/disables usage of OpenGL vertex buffer arrays while drawing primitive arrays
70 virtual void EnableVBO (const Standard_Boolean status) = 0;
72 //! Returns TRUE if vertical synchronization with display refresh rate (VSync) should be used; TRUE by default.
73 virtual bool IsVerticalSync() const = 0;
75 //! Set if vertical synchronization with display refresh rate (VSync) should be used.
76 virtual void SetVerticalSync (bool theToEnable) = 0;
78 //! Returns information about GPU memory usage.
79 virtual Standard_Boolean MemoryInfo (Standard_Size& theFreeBytes, TCollection_AsciiString& theInfo) const = 0;
81 virtual Standard_ShortReal DefaultTextHeight() const = 0;
83 //! Computes text width.
84 virtual void TextSize (const Handle(Graphic3d_CView)& theView,
85 const Standard_CString theText,
86 const Standard_ShortReal theHeight,
87 Standard_ShortReal& theWidth,
88 Standard_ShortReal& theAscent,
89 Standard_ShortReal& theDescent) const = 0;
91 //! Adds a layer to all views.
92 //! To add a structure to desired layer on display it is necessary to set the layer ID for the structure.
93 //! @param theNewLayerId [in] id of new layer, should be > 0 (negative values are reserved for default layers).
94 //! @param theSettings [in] new layer settings
95 //! @param theLayerAfter [in] id of layer to append new layer before
96 Standard_EXPORT virtual void InsertLayerBefore (const Graphic3d_ZLayerId theNewLayerId,
97 const Graphic3d_ZLayerSettings& theSettings,
98 const Graphic3d_ZLayerId theLayerAfter) = 0;
100 //! Adds a layer to all views.
101 //! @param theNewLayerId [in] id of new layer, should be > 0 (negative values are reserved for default layers).
102 //! @param theSettings [in] new layer settings
103 //! @param theLayerBefore [in] id of layer to append new layer after
104 Standard_EXPORT virtual void InsertLayerAfter (const Graphic3d_ZLayerId theNewLayerId,
105 const Graphic3d_ZLayerSettings& theSettings,
106 const Graphic3d_ZLayerId theLayerBefore) = 0;
108 //! Removes Z layer. All structures displayed at the moment in layer will be displayed in
109 //! default layer (the bottom-level z layer). By default, there are always default
110 //! bottom-level layer that can't be removed. The passed theLayerId should be not less than 0
111 //! (reserved for default layers that can not be removed).
112 Standard_EXPORT virtual void RemoveZLayer (const Graphic3d_ZLayerId theLayerId) = 0;
114 //! Returns list of Z layers defined for the graphical driver.
115 Standard_EXPORT virtual void ZLayers (TColStd_SequenceOfInteger& theLayerSeq) const;
117 //! Sets the settings for a single Z layer.
118 Standard_EXPORT virtual void SetZLayerSettings (const Graphic3d_ZLayerId theLayerId, const Graphic3d_ZLayerSettings& theSettings) = 0;
120 //! Returns the settings of a single Z layer.
121 Standard_EXPORT virtual const Graphic3d_ZLayerSettings& ZLayerSettings (const Graphic3d_ZLayerId theLayerId) const;
123 //! Returns view associated with the window if it is exists and is activated.
124 //! Returns Standard_True if the view associated to the window exists.
125 virtual Standard_Boolean ViewExists (const Handle(Aspect_Window)& theWindow, Handle(Graphic3d_CView)& theView) = 0;
127 //! returns Handle to display connection
128 Standard_EXPORT const Handle(Aspect_DisplayConnection)& GetDisplayConnection() const;
130 //! Returns a new identification number for a new structure.
131 Standard_EXPORT Standard_Integer NewIdentification();
133 //! Frees the identifier of a structure.
134 Standard_EXPORT void RemoveIdentification(const Standard_Integer theId);
136 //! Dumps the content of me into the stream
137 Standard_EXPORT void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const;
141 //! Initializes the Driver
142 Standard_EXPORT Graphic3d_GraphicDriver(const Handle(Aspect_DisplayConnection)& theDisp);
146 Handle(Aspect_DisplayConnection) myDisplayConnection;
147 Aspect_GenId myStructGenId;
148 NCollection_List<Handle(Graphic3d_Layer)> myLayers;
149 NCollection_DataMap<Graphic3d_ZLayerId, Handle(Graphic3d_Layer)> myLayerIds;
153 #endif // _Graphic3d_GraphicDriver_HeaderFile