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