| 1 | // Created on: 2011-07-13 |
| 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_PrimitiveArray_Header |
| 17 | #define OpenGl_PrimitiveArray_Header |
| 18 | |
| 19 | #include <OpenGl_IndexBuffer.hxx> |
| 20 | |
| 21 | #include <InterfaceGraphic_Graphic3d.hxx> |
| 22 | #include <Aspect_InteriorStyle.hxx> |
| 23 | #include <Aspect_TypeOfMarker.hxx> |
| 24 | #include <Graphic3d_TypeOfPrimitiveArray.hxx> |
| 25 | #include <Graphic3d_IndexBuffer.hxx> |
| 26 | #include <Graphic3d_BoundBuffer.hxx> |
| 27 | |
| 28 | #include <OpenGl_Element.hxx> |
| 29 | |
| 30 | class OpenGl_GraphicDriver; |
| 31 | class Handle(OpenGl_ShaderProgram); |
| 32 | |
| 33 | //! Class for rendering of arbitrary primitive array. |
| 34 | class OpenGl_PrimitiveArray : public OpenGl_Element |
| 35 | { |
| 36 | public: |
| 37 | // OpenGL does not provide a constant for "none" draw mode. |
| 38 | // So we define our own one that does not conflict with GL constants |
| 39 | // and utilizes common GL invalid value |
| 40 | enum |
| 41 | { |
| 42 | DRAW_MODE_NONE = -1 |
| 43 | }; |
| 44 | |
| 45 | //! Default constructor |
| 46 | OpenGl_PrimitiveArray (const OpenGl_GraphicDriver* theDriver, |
| 47 | const Graphic3d_TypeOfPrimitiveArray theType, |
| 48 | const Handle(Graphic3d_IndexBuffer)& theIndices, |
| 49 | const Handle(Graphic3d_Buffer)& theAttribs, |
| 50 | const Handle(Graphic3d_BoundBuffer)& theBounds); |
| 51 | |
| 52 | //! Render primitives to the window |
| 53 | virtual void Render (const Handle(OpenGl_Workspace)& theWorkspace) const; |
| 54 | |
| 55 | virtual void Release (OpenGl_Context* theContext); |
| 56 | |
| 57 | //! @return primitive type (GL_LINES, GL_TRIANGLES and others) |
| 58 | GLint DrawMode() const { return myDrawMode; } |
| 59 | |
| 60 | //! @return indices array |
| 61 | const Handle(Graphic3d_IndexBuffer)& Indices() const { return myIndices; } |
| 62 | |
| 63 | //! @return attributes array |
| 64 | const Handle(Graphic3d_Buffer)& Attributes() const { return myAttribs; } |
| 65 | |
| 66 | //! @return bounds array |
| 67 | const Handle(Graphic3d_BoundBuffer)& Bounds() const { return myBounds; } |
| 68 | |
| 69 | //! Returns unique ID of primitive array. |
| 70 | const Standard_Size GetUID() const { return myUID; } |
| 71 | |
| 72 | private: |
| 73 | |
| 74 | //! Initialize normal (OpenGL-provided) VBO |
| 75 | Standard_Boolean initNormalVbo (const Handle(OpenGl_Context)& theCtx) const; |
| 76 | |
| 77 | //! VBO initialization procedures |
| 78 | //! @param theCtx bound GL context |
| 79 | //! @param theToKeepData when true, myAttribs will not be nullified after VBO creation |
| 80 | Standard_Boolean buildVBO (const Handle(OpenGl_Context)& theCtx, |
| 81 | const Standard_Boolean theToKeepData) const; |
| 82 | void clearMemoryGL (const Handle(OpenGl_Context)& theGlCtx) const; |
| 83 | |
| 84 | //! Main procedure to draw array |
| 85 | void drawArray (const Handle(OpenGl_Workspace)& theWorkspace, |
| 86 | const Graphic3d_Vec4* theFaceColors, |
| 87 | const Standard_Boolean theHasVertColor) const; |
| 88 | |
| 89 | //! Auxiliary procedures |
| 90 | void drawEdges (const TEL_COLOUR* theEdgeColour, |
| 91 | const Handle(OpenGl_Workspace)& theWorkspace) const; |
| 92 | |
| 93 | void drawMarkers (const Handle(OpenGl_Workspace)& theWorkspace) const; |
| 94 | |
| 95 | protected: |
| 96 | |
| 97 | //! Destructor |
| 98 | virtual ~OpenGl_PrimitiveArray(); |
| 99 | |
| 100 | protected: |
| 101 | |
| 102 | mutable Handle(OpenGl_VertexBuffer) myVboIndices; |
| 103 | mutable Handle(OpenGl_VertexBuffer) myVboAttribs; |
| 104 | |
| 105 | mutable Handle(Graphic3d_IndexBuffer) myIndices; |
| 106 | mutable Handle(Graphic3d_Buffer) myAttribs; |
| 107 | mutable Handle(Graphic3d_BoundBuffer) myBounds; |
| 108 | GLint myDrawMode; |
| 109 | mutable Standard_Boolean myIsVboInit; |
| 110 | |
| 111 | Standard_Size myUID; //!< Unique ID of primitive array. |
| 112 | |
| 113 | public: |
| 114 | |
| 115 | DEFINE_STANDARD_ALLOC |
| 116 | |
| 117 | }; |
| 118 | |
| 119 | #endif //OpenGl_PrimitiveArray_Header |