Commit | Line | Data |
---|---|---|
b311480e | 1 | // Created on: 2011-08-05 |
2 | // Created by: Sergey ZERCHANINOV | |
973c2be1 | 3 | // Copyright (c) 2011-2014 OPEN CASCADE SAS |
b311480e | 4 | // |
973c2be1 | 5 | // This file is part of Open CASCADE Technology software library. |
b311480e | 6 | // |
d5f74e42 | 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 | |
973c2be1 | 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. | |
b311480e | 12 | // |
973c2be1 | 13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. | |
b311480e | 15 | |
2166f0fa SK |
16 | #ifndef OpenGl_Element_Header |
17 | #define OpenGl_Element_Header | |
18 | ||
bf75be98 | 19 | #include <Handle_OpenGl_Context.hxx> |
20 | #include <Handle_OpenGl_Workspace.hxx> | |
4269bd1b | 21 | #include <OpenGl_RenderFilter.hxx> |
2166f0fa | 22 | |
a174a3c5 | 23 | //! Base interface for drawable elements. |
2166f0fa SK |
24 | class OpenGl_Element |
25 | { | |
5e27df78 | 26 | public: |
2166f0fa | 27 | |
a174a3c5 | 28 | Standard_EXPORT OpenGl_Element(); |
5e27df78 | 29 | |
30 | virtual void Render (const Handle(OpenGl_Workspace)& theWorkspace) const = 0; | |
31 | ||
32 | //! Release GPU resources. | |
10b9c7df | 33 | //! Pointer to the context is used because this method might be called |
34 | //! when the context is already being destroyed and usage of a handle | |
35 | //! would be unsafe | |
36 | virtual void Release (OpenGl_Context* theContext) = 0; | |
37 | ||
38 | //! Pointer to the context is used because this method might be called | |
39 | //! when the context is already being destroyed and usage of a handle | |
40 | //! would be unsafe | |
5e27df78 | 41 | template <typename theResource_t> |
10b9c7df | 42 | static void Destroy (OpenGl_Context* theContext, |
43 | theResource_t*& theElement) | |
5e27df78 | 44 | { |
45 | if (theElement == NULL) | |
46 | { | |
47 | return; | |
48 | } | |
49 | ||
50 | theElement->Release (theContext); | |
51 | OpenGl_Element* anElement = theElement; | |
52 | delete anElement; | |
53 | theElement = NULL; | |
54 | } | |
55 | ||
4269bd1b | 56 | public: |
57 | ||
58 | //! Render element if it passes the filtering procedure. This method should | |
59 | //! be used for elements which can be used in scope of rendering algorithms. | |
60 | //! E.g. elements of groups during recursive rendering. | |
61 | //! If render filter is null, pure rendering is performed. | |
62 | //! @param theWorkspace [in] the rendering workspace. | |
63 | //! @param theFilter [in] the rendering filter to check whether the element | |
64 | //! should be rendered or not. | |
65 | //! @return True if element passes the filering check and is rendered. | |
66 | inline Standard_Boolean | |
67 | RenderFiltered (const Handle(OpenGl_Workspace)& theWorkspace, | |
68 | const Handle(OpenGl_RenderFilter)& theFilter) const | |
69 | { | |
70 | if (!theFilter.IsNull() && !theFilter->CanRender (this)) | |
71 | { | |
72 | return Standard_False; | |
73 | } | |
74 | ||
75 | Render (theWorkspace); | |
76 | ||
77 | return Standard_True; | |
78 | } | |
79 | ||
5e27df78 | 80 | protected: |
81 | ||
a174a3c5 | 82 | Standard_EXPORT virtual ~OpenGl_Element(); |
5e27df78 | 83 | |
84 | public: | |
2166f0fa | 85 | |
1c35b92f | 86 | DEFINE_STANDARD_ALLOC |
5e27df78 | 87 | |
2166f0fa SK |
88 | }; |
89 | ||
a174a3c5 | 90 | #endif // OpenGl_Element_Header |