0033661: Data Exchange, Step Import - Tessellated GDTs are not imported
[occt.git] / src / OpenGl / OpenGl_VertexBuffer.hxx
CommitLineData
5e27df78 1// Created by: Kirill GAVRILOV
d5f74e42 2// Copyright (c) 2013-2014 OPEN CASCADE SAS
5e27df78 3//
973c2be1 4// This file is part of Open CASCADE Technology software library.
5e27df78 5//
d5f74e42 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
973c2be1 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.
5e27df78 11//
973c2be1 12// Alternatively, this file may be used under the terms of Open CASCADE
13// commercial license or contractual agreement.
5e27df78 14
5bd54bef 15#ifndef OpenGl_VertexBuffer_HeaderFile
16#define OpenGl_VertexBuffer_HeaderFile
5e27df78 17
1220d98e 18#include <OpenGl_Buffer.hxx>
19#include <Graphic3d_Buffer.hxx>
5e27df78 20
21//! Vertex Buffer Object - is a general storage object for vertex attributes (position, normal, color).
22//! Notice that you should use OpenGl_IndexBuffer specialization for array of indices.
1220d98e 23class OpenGl_VertexBuffer : public OpenGl_Buffer
5e27df78 24{
5e27df78 25public:
26
27 //! Create uninitialized VBO.
28 Standard_EXPORT OpenGl_VertexBuffer();
29
30 //! Destroy object.
31 Standard_EXPORT virtual ~OpenGl_VertexBuffer();
32
1220d98e 33 //! Return buffer target GL_ARRAY_BUFFER.
34 Standard_EXPORT virtual unsigned int GetTarget() const Standard_OVERRIDE;
d4cefcc0 35
5e27df78 36 //! Bind this VBO to active GLSL program.
37 Standard_EXPORT void BindVertexAttrib (const Handle(OpenGl_Context)& theGlCtx,
1220d98e 38 const unsigned int theAttribLoc) const;
5e27df78 39
40 //! Unbind any VBO from active GLSL program.
41 Standard_EXPORT void UnbindVertexAttrib (const Handle(OpenGl_Context)& theGlCtx,
1220d98e 42 const unsigned int theAttribLoc) const;
5e27df78 43
7d3e64ef 44 //! Bind this VBO and enable specified attribute in OpenGl_Context::ActiveProgram() or FFP.
5e27df78 45 //! @param theGlCtx - handle to bound GL context;
46 //! @param theMode - array mode (GL_VERTEX_ARRAY, GL_NORMAL_ARRAY, GL_COLOR_ARRAY, GL_INDEX_ARRAY, GL_TEXTURE_COORD_ARRAY).
7d3e64ef 47 void BindAttribute (const Handle(OpenGl_Context)& theCtx,
48 const Graphic3d_TypeOfAttribute theMode) const
49 {
50 if (IsValid())
51 {
52 Bind (theCtx);
1220d98e 53 bindAttribute (theCtx, theMode, static_cast<int> (myComponentsNb), myDataType, 0, myOffset);
7d3e64ef 54 }
55 }
5e27df78 56
7d3e64ef 57 //! Unbind this VBO and disable specified attribute in OpenGl_Context::ActiveProgram() or FFP.
58 //! @param theCtx handle to bound GL context
59 //! @param theMode array mode
60 void UnbindAttribute (const Handle(OpenGl_Context)& theCtx,
61 const Graphic3d_TypeOfAttribute theMode) const
62 {
63 if (IsValid())
64 {
65 Unbind (theCtx);
66 unbindAttribute (theCtx, theMode);
67 }
68 }
5e27df78 69
871fa103 70public: //! @name advanced methods
71
7d3e64ef 72 //! Setup array pointer - either for active GLSL program OpenGl_Context::ActiveProgram()
73 //! or for FFP using bindFixed() when no program bound.
1220d98e 74 Standard_EXPORT static void bindAttribute (const Handle(OpenGl_Context)& theGlCtx,
75 const Graphic3d_TypeOfAttribute theMode,
76 const Standard_Integer theNbComp,
77 const unsigned int theDataType,
78 const Standard_Integer theStride,
79 const void* theOffset);
7d3e64ef 80
81 //! Disable GLSL array pointer - either for active GLSL program OpenGl_Context::ActiveProgram()
82 //! or for FFP using unbindFixed() when no program bound.
1220d98e 83 Standard_EXPORT static void unbindAttribute (const Handle(OpenGl_Context)& theGlCtx,
84 const Graphic3d_TypeOfAttribute theMode);
7d3e64ef 85
86private:
8f7159cb 87
871fa103 88 //! Setup FFP array pointer.
1220d98e 89 Standard_EXPORT static void bindFixed (const Handle(OpenGl_Context)& theGlCtx,
90 const Graphic3d_TypeOfAttribute theMode,
91 const Standard_Integer theNbComp,
92 const unsigned int theDataType,
93 const Standard_Integer theStride,
94 const void* theOffset);
871fa103 95
96 //! Disable FFP array pointer.
1220d98e 97 Standard_EXPORT static void unbindFixed (const Handle(OpenGl_Context)& theGlCtx,
98 const Graphic3d_TypeOfAttribute theMode);
8613985b 99
100 //! Disable FFP color array pointer.
f114566d 101 Standard_EXPORT static void unbindFixedColor (const Handle(OpenGl_Context)& theCtx);
8613985b 102
871fa103 103public: //! @name methods for interleaved attributes array
104
7d3e64ef 105 //! @return true if buffer contains per-vertex color attribute
106 Standard_EXPORT virtual bool HasColorAttribute() const;
107
108 //! @return true if buffer contains per-vertex normal attribute
109 Standard_EXPORT virtual bool HasNormalAttribute() const;
871fa103 110
7d3e64ef 111 //! Bind all vertex attributes to active program OpenGl_Context::ActiveProgram() or for FFP.
112 //! Default implementation does nothing.
113 Standard_EXPORT virtual void BindAllAttributes (const Handle(OpenGl_Context)& theGlCtx) const;
871fa103 114
7d3e64ef 115 //! Bind vertex position attribute only. Default implementation does nothing.
116 Standard_EXPORT virtual void BindPositionAttribute (const Handle(OpenGl_Context)& theGlCtx) const;
871fa103 117
7d3e64ef 118 //! Unbind all vertex attributes. Default implementation does nothing.
119 Standard_EXPORT virtual void UnbindAllAttributes (const Handle(OpenGl_Context)& theGlCtx) const;
871fa103 120
5e27df78 121public:
122
1220d98e 123 DEFINE_STANDARD_RTTIEXT(OpenGl_VertexBuffer, OpenGl_Buffer)
5e27df78 124
125};
126
1220d98e 127DEFINE_STANDARD_HANDLE(OpenGl_VertexBuffer, OpenGl_Buffer)
7d3e64ef 128
5e27df78 129#endif // _OpenGl_VertexBuffer_H__