1 // Created by: Kirill GAVRILOV
2 // Copyright (c) 2014 OPEN CASCADE SAS
4 // This file is part of Open CASCADE Technology software library.
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.
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
15 #ifndef _OpenGl_VertexBufferCompat_HeaderFile
16 #define _OpenGl_VertexBufferCompat_HeaderFile
18 #include <OpenGl_VertexBuffer.hxx>
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).
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.
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.
33 //! Method Create() creates dummy identifier for this object which should NOT be passed to OpenGL functions.
34 class OpenGl_VertexBufferCompat : public OpenGl_VertexBuffer
39 //! Create uninitialized VBO.
40 Standard_EXPORT OpenGl_VertexBufferCompat();
43 Standard_EXPORT virtual ~OpenGl_VertexBufferCompat();
45 //! Creates VBO name (id) if not yet generated.
46 //! Data should be initialized by another method.
47 Standard_EXPORT bool Create (const Handle(OpenGl_Context)& theGlCtx) Standard_OVERRIDE;
49 //! Destroy object - will release memory if any.
50 Standard_EXPORT virtual void Release (OpenGl_Context* theGlCtx) Standard_OVERRIDE;
53 Standard_EXPORT virtual void Bind (const Handle(OpenGl_Context)& theGlCtx) const Standard_OVERRIDE;
56 Standard_EXPORT virtual void Unbind (const Handle(OpenGl_Context)& theGlCtx) const Standard_OVERRIDE;
58 public: //! @name advanced methods
60 //! Initialize buffer with existing data.
61 //! Data will NOT be copied by this method!
62 Standard_EXPORT bool initLink (const Handle(NCollection_Buffer)& theData,
63 const GLuint theComponentsNb,
64 const GLsizei theElemsNb,
65 const GLenum theDataType);
67 //! Initialize buffer with new data (data will be copied).
68 Standard_EXPORT virtual bool init (const Handle(OpenGl_Context)& theGlCtx,
69 const GLuint theComponentsNb,
70 const GLsizei theElemsNb,
72 const GLenum theDataType,
73 const GLsizei theStride) Standard_OVERRIDE;
75 //! Update part of the buffer with new data.
76 Standard_EXPORT virtual bool subData (const Handle(OpenGl_Context)& theGlCtx,
77 const GLsizei theElemFrom,
78 const GLsizei theElemsNb,
80 const GLenum theDataType) Standard_OVERRIDE;
84 Handle(NCollection_Buffer) myData; //!< buffer data
88 DEFINE_STANDARD_RTTI(OpenGl_VertexBufferCompat, OpenGl_VertexBuffer) // Type definition
92 DEFINE_STANDARD_HANDLE(OpenGl_VertexBufferCompat, OpenGl_VertexBuffer)
94 #endif // _OpenGl_VertexBufferCompat_HeaderFile