0027860: Visualization - clean up Transformation Persistence API
[occt.git] / src / OpenGl / OpenGl_Element.hxx
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_Header
17 #define OpenGl_Element_Header
18
19 #include <OpenGl_RenderFilter.hxx>
20
21 class OpenGl_Workspace;
22 class OpenGl_Context;
23
24 //! Base interface for drawable elements.
25 class OpenGl_Element
26 {
27 public:
28
29   Standard_EXPORT OpenGl_Element();
30
31   virtual void Render (const Handle(OpenGl_Workspace)& theWorkspace) const = 0;
32
33   //! Release GPU resources.
34   //! Pointer to the context is used because this method might be called
35   //! when the context is already being destroyed and usage of a handle
36   //! would be unsafe
37   virtual void Release (OpenGl_Context* theContext) = 0;
38
39   //! Pointer to the context is used because this method might be called
40   //! when the context is already being destroyed and usage of a handle
41   //! would be unsafe
42   template <typename theResource_t>
43   static void Destroy (OpenGl_Context* theContext,
44                        theResource_t*& theElement)
45   {
46     if (theElement == NULL)
47     {
48       return;
49     }
50
51     theElement->Release (theContext);
52     OpenGl_Element* anElement = theElement;
53     delete anElement;
54     theElement = NULL;
55   }
56
57 public:
58
59   //! Render element if it passes the filtering procedure. This method should
60   //! be used for elements which can be used in scope of rendering algorithms.
61   //! E.g. elements of groups during recursive rendering.
62   //! If render filter is null, pure rendering is performed.
63   //! @param theWorkspace [in] the rendering workspace.
64   //! @param theFilter [in] the rendering filter to check whether the element
65   //! should be rendered or not.
66   //! @return True if element passes the filering check and is rendered.
67   inline Standard_Boolean
68     RenderFiltered (const Handle(OpenGl_Workspace)& theWorkspace,
69                     const Handle(OpenGl_RenderFilter)& theFilter) const
70   {
71     if (!theFilter.IsNull() && !theFilter->CanRender (this))
72     {
73       return Standard_False;
74     }
75
76     Render (theWorkspace);
77
78     return Standard_True;
79   }
80
81 protected:
82
83   Standard_EXPORT virtual ~OpenGl_Element();
84
85 public:
86
87   DEFINE_STANDARD_ALLOC
88
89 };
90
91 #endif // OpenGl_Element_Header