| 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 | |
| 20 | #ifndef OpenGl_Element_Header |
| 21 | #define OpenGl_Element_Header |
| 22 | |
| 23 | #include <Handle_OpenGl_Context.hxx> |
| 24 | #include <Handle_OpenGl_Workspace.hxx> |
| 25 | #include <OpenGl_RenderFilter.hxx> |
| 26 | |
| 27 | //! Base interface for drawable elements. |
| 28 | class OpenGl_Element |
| 29 | { |
| 30 | public: |
| 31 | |
| 32 | Standard_EXPORT OpenGl_Element(); |
| 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 | |
| 54 | public: |
| 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 | |
| 78 | protected: |
| 79 | |
| 80 | Standard_EXPORT virtual ~OpenGl_Element(); |
| 81 | |
| 82 | public: |
| 83 | |
| 84 | DEFINE_STANDARD_ALLOC |
| 85 | |
| 86 | }; |
| 87 | |
| 88 | #endif // OpenGl_Element_Header |