0024437: Visualization - silhouette edges based on OpenGL
[occt.git] / src / OpenGl / OpenGl_VertexBufferCompat.hxx
1 // Created by: Kirill GAVRILOV
2 // Copyright (c) 2014 OPEN CASCADE SAS
3 //
4 // This file is part of Open CASCADE Technology software library.
5 //
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License version 2.1 as published
8 // by the Free Software Foundation, with special exception defined in the file
9 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10 // distribution for complete text of the license and disclaimer of any warranty.
11 //
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
14
15 #ifndef _OpenGl_VertexBufferCompat_HeaderFile
16 #define _OpenGl_VertexBufferCompat_HeaderFile
17
18 #include <OpenGl_VertexBuffer.hxx>
19
20 //! Compatibility layer for old OpenGL without VBO.
21 //! Make sure to pass pointer from GetDataOffset() instead of NULL.
22 //! Method GetDataOffset() returns pointer to real data in this class
23 //! (while base class OpenGl_VertexBuffer always return NULL).
24 //!
25 //! Methods Bind()/Unbind() do nothing (do not affect OpenGL state)
26 //! and ::GetTarget() is never used.
27 //! For this reason there is no analog for OpenGl_IndexBuffer.
28 //! Just pass GetDataOffset() to glDrawElements() directly as last argument.
29 //!
30 //! Class overrides methods init() and subData() to copy data into own memory buffer.
31 //! Extra method initLink() might be used to pass existing buffer through handle without copying the data.
32 //!
33 //! Method Create() creates dummy identifier for this object which should NOT be passed to OpenGL functions.
34 class OpenGl_VertexBufferCompat : public OpenGl_VertexBuffer
35 {
36
37 public:
38
39   //! Create uninitialized VBO.
40   Standard_EXPORT OpenGl_VertexBufferCompat();
41
42   //! Destroy object.
43   Standard_EXPORT virtual ~OpenGl_VertexBufferCompat();
44
45   //! Return TRUE.
46   virtual bool IsVirtual() const Standard_OVERRIDE { return true; }
47
48   //! Creates VBO name (id) if not yet generated.
49   //! Data should be initialized by another method.
50   Standard_EXPORT bool Create (const Handle(OpenGl_Context)& theGlCtx) Standard_OVERRIDE;
51
52   //! Destroy object - will release memory if any.
53   Standard_EXPORT virtual void Release (OpenGl_Context* theGlCtx) Standard_OVERRIDE;
54
55   //! Bind this VBO.
56   Standard_EXPORT virtual void Bind (const Handle(OpenGl_Context)& theGlCtx) const Standard_OVERRIDE;
57
58   //! Unbind this VBO.
59   Standard_EXPORT virtual void Unbind (const Handle(OpenGl_Context)& theGlCtx) const Standard_OVERRIDE;
60
61 public: //! @name advanced methods
62
63   //! Initialize buffer with existing data.
64   //! Data will NOT be copied by this method!
65   Standard_EXPORT bool initLink (const Handle(NCollection_Buffer)& theData,
66                                  const GLuint   theComponentsNb,
67                                  const GLsizei  theElemsNb,
68                                  const GLenum   theDataType);
69
70   //! Initialize buffer with new data (data will be copied).
71   Standard_EXPORT virtual bool init (const Handle(OpenGl_Context)& theGlCtx,
72                                      const GLuint   theComponentsNb,
73                                      const GLsizei  theElemsNb,
74                                      const void*    theData,
75                                      const GLenum   theDataType,
76                                      const GLsizei  theStride) Standard_OVERRIDE;
77
78   //! Update part of the buffer with new data.
79   Standard_EXPORT virtual bool subData (const Handle(OpenGl_Context)& theGlCtx,
80                                         const GLsizei  theElemFrom,
81                                         const GLsizei  theElemsNb,
82                                         const void*    theData,
83                                         const GLenum   theDataType) Standard_OVERRIDE;
84
85 protected:
86
87   Handle(NCollection_Buffer) myData; //!< buffer data
88
89 public:
90
91   DEFINE_STANDARD_RTTIEXT(OpenGl_VertexBufferCompat,OpenGl_VertexBuffer) // Type definition
92
93 };
94
95 DEFINE_STANDARD_HANDLE(OpenGl_VertexBufferCompat, OpenGl_VertexBuffer)
96
97 #endif // _OpenGl_VertexBufferCompat_HeaderFile