0024070: OpenGL capped object-level clipping planes
[occt.git] / src / OpenGl / OpenGl_Element.hxx
CommitLineData
b311480e 1// Created on: 2011-08-05
2// Created by: Sergey ZERCHANINOV
3// Copyright (c) 2011-2012 OPEN CASCADE SAS
4//
5// The content of this file is subject to the Open CASCADE Technology Public
6// License Version 6.5 (the "License"). You may not use the content of this file
7// except in compliance with the License. Please obtain a copy of the License
8// at http://www.opencascade.org and read it completely before using this file.
9//
10// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
12//
13// The Original Code and all software distributed under the License is
14// distributed on an "AS IS" basis, without warranty of any kind, and the
15// Initial Developer hereby disclaims all such warranties, including without
16// limitation, any warranties of merchantability, fitness for a particular
17// purpose or non-infringement. Please see the License for the specific terms
18// and conditions governing the rights and limitations under the License.
19
2166f0fa
SK
20#ifndef OpenGl_Element_Header
21#define OpenGl_Element_Header
22
bf75be98 23#include <Handle_OpenGl_Context.hxx>
24#include <Handle_OpenGl_Workspace.hxx>
4269bd1b 25#include <OpenGl_RenderFilter.hxx>
2166f0fa 26
a174a3c5 27//! Base interface for drawable elements.
2166f0fa
SK
28class OpenGl_Element
29{
5e27df78 30public:
2166f0fa 31
a174a3c5 32 Standard_EXPORT OpenGl_Element();
5e27df78 33
34 virtual void Render (const Handle(OpenGl_Workspace)& theWorkspace) const = 0;
35
36 //! Release GPU resources.
37 virtual void Release (const Handle(OpenGl_Context)& theContext) = 0;
38
39 template <typename theResource_t>
40 static void Destroy (const Handle(OpenGl_Context)& theContext,
41 theResource_t*& theElement)
42 {
43 if (theElement == NULL)
44 {
45 return;
46 }
47
48 theElement->Release (theContext);
49 OpenGl_Element* anElement = theElement;
50 delete anElement;
51 theElement = NULL;
52 }
53
4269bd1b 54public:
55
56 //! Render element if it passes the filtering procedure. This method should
57 //! be used for elements which can be used in scope of rendering algorithms.
58 //! E.g. elements of groups during recursive rendering.
59 //! If render filter is null, pure rendering is performed.
60 //! @param theWorkspace [in] the rendering workspace.
61 //! @param theFilter [in] the rendering filter to check whether the element
62 //! should be rendered or not.
63 //! @return True if element passes the filering check and is rendered.
64 inline Standard_Boolean
65 RenderFiltered (const Handle(OpenGl_Workspace)& theWorkspace,
66 const Handle(OpenGl_RenderFilter)& theFilter) const
67 {
68 if (!theFilter.IsNull() && !theFilter->CanRender (this))
69 {
70 return Standard_False;
71 }
72
73 Render (theWorkspace);
74
75 return Standard_True;
76 }
77
5e27df78 78protected:
79
a174a3c5 80 Standard_EXPORT virtual ~OpenGl_Element();
5e27df78 81
82public:
2166f0fa 83
1c35b92f 84 DEFINE_STANDARD_ALLOC
5e27df78 85
2166f0fa
SK
86};
87
a174a3c5 88#endif // OpenGl_Element_Header