1 // Created on: 2011-08-05
2 // Created by: Sergey ZERCHANINOV
3 // Copyright (c) 2011-2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
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.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15 
16 #ifndef OpenGl_Element_HeaderFile
17 #define OpenGl_Element_HeaderFile
18 
19 #include <OpenGl_RenderFilter.hxx>
20 #include <Standard_Type.hxx>
21 
22 class Graphic3d_FrameStatsDataTmp;
23 class OpenGl_Workspace;
24 class OpenGl_Context;
25 
26 //! Base interface for drawable elements.
27 class OpenGl_Element
28 {
29 public:
30 
31   Standard_EXPORT OpenGl_Element();
32 
33   virtual void Render (const Handle(OpenGl_Workspace)& theWorkspace) const = 0;
34 
35   //! Release GPU resources.
36   //! Pointer to the context is used because this method might be called
37   //! when the context is already being destroyed and usage of a handle
38   //! would be unsafe
39   virtual void Release (OpenGl_Context* theContext) = 0;
40 
41   //! Pointer to the context is used because this method might be called
42   //! when the context is already being destroyed and usage of a handle
43   //! would be unsafe
44   template <typename theResource_t>
Destroy(OpenGl_Context * theContext,theResource_t * & theElement)45   static void Destroy (OpenGl_Context* theContext,
46                        theResource_t*& theElement)
47   {
48     if (theElement == NULL)
49     {
50       return;
51     }
52 
53     theElement->Release (theContext);
54     OpenGl_Element* anElement = theElement;
55     delete anElement;
56     theElement = NULL;
57   }
58 
59 public:
60 
61   //! Return TRUE if primitive type generates shaded triangulation (to be used in filters).
IsFillDrawMode() const62   virtual Standard_Boolean IsFillDrawMode() const { return false; }
63 
64   //! Returns estimated GPU memory usage for holding data without considering overheads and allocation alignment rules.
EstimatedDataSize() const65   virtual Standard_Size EstimatedDataSize() const { return 0; }
66 
67   //! Increment memory usage statistics.
68   //! Default implementation puts EstimatedDataSize() into Graphic3d_FrameStatsCounter_EstimatedBytesGeom.
69   Standard_EXPORT virtual void UpdateMemStats (Graphic3d_FrameStatsDataTmp& theStats) const;
70 
71   //! Increment draw calls statistics.
72   //! @param theStats [in] [out] frame counters to increment
73   //! @param theIsDetailed  [in] indicate detailed dump (more counters - number of triangles, points, etc.)
74   Standard_EXPORT virtual void UpdateDrawStats (Graphic3d_FrameStatsDataTmp& theStats,
75                                                  bool theIsDetailed) const;
76 
77   //! Update parameters of the drawable elements.
SynchronizeAspects()78   virtual void SynchronizeAspects() {}
79 
80   //! Dumps the content of me into the stream
81   Standard_EXPORT virtual void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const;
82 
83 protected:
84 
85   Standard_EXPORT virtual ~OpenGl_Element();
86 
87 public:
88 
89   DEFINE_STANDARD_ALLOC
90 
91 };
92 
93 #endif // OpenGl_Element_Header
94