1 // Created by: Kirill GAVRILOV
2 // Copyright (c) 2013-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_VertexBuffer_H__
16 #define _OpenGl_VertexBuffer_H__
18 #include <OpenGl_Buffer.hxx>
19 #include <Graphic3d_Buffer.hxx>
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.
23 class OpenGl_VertexBuffer : public OpenGl_Buffer
27 //! Create uninitialized VBO.
28 Standard_EXPORT OpenGl_VertexBuffer();
31 Standard_EXPORT virtual ~OpenGl_VertexBuffer();
33 //! Return buffer target GL_ARRAY_BUFFER.
34 Standard_EXPORT virtual unsigned int GetTarget() const Standard_OVERRIDE;
36 //! Bind this VBO to active GLSL program.
37 Standard_EXPORT void BindVertexAttrib (const Handle(OpenGl_Context)& theGlCtx,
38 const unsigned int theAttribLoc) const;
40 //! Unbind any VBO from active GLSL program.
41 Standard_EXPORT void UnbindVertexAttrib (const Handle(OpenGl_Context)& theGlCtx,
42 const unsigned int theAttribLoc) const;
44 //! Bind this VBO and enable specified attribute in OpenGl_Context::ActiveProgram() or FFP.
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).
47 void BindAttribute (const Handle(OpenGl_Context)& theCtx,
48 const Graphic3d_TypeOfAttribute theMode) const
53 bindAttribute (theCtx, theMode, static_cast<int> (myComponentsNb), myDataType, 0, myOffset);
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
66 unbindAttribute (theCtx, theMode);
70 public: //! @name advanced methods
72 //! Setup array pointer - either for active GLSL program OpenGl_Context::ActiveProgram()
73 //! or for FFP using bindFixed() when no program bound.
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);
81 //! Disable GLSL array pointer - either for active GLSL program OpenGl_Context::ActiveProgram()
82 //! or for FFP using unbindFixed() when no program bound.
83 Standard_EXPORT static void unbindAttribute (const Handle(OpenGl_Context)& theGlCtx,
84 const Graphic3d_TypeOfAttribute theMode);
87 #if !defined(GL_ES_VERSION_2_0)
88 //! Setup FFP array pointer.
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);
96 //! Disable FFP array pointer.
97 Standard_EXPORT static void unbindFixed (const Handle(OpenGl_Context)& theGlCtx,
98 const Graphic3d_TypeOfAttribute theMode);
100 //! Disable FFP color array pointer.
101 Standard_EXPORT static void unbindFixedColor (const Handle(OpenGl_Context)& theCtx);
104 public: //! @name methods for interleaved attributes array
106 //! @return true if buffer contains per-vertex color attribute
107 Standard_EXPORT virtual bool HasColorAttribute() const;
109 //! @return true if buffer contains per-vertex normal attribute
110 Standard_EXPORT virtual bool HasNormalAttribute() const;
112 //! Bind all vertex attributes to active program OpenGl_Context::ActiveProgram() or for FFP.
113 //! Default implementation does nothing.
114 Standard_EXPORT virtual void BindAllAttributes (const Handle(OpenGl_Context)& theGlCtx) const;
116 //! Bind vertex position attribute only. Default implementation does nothing.
117 Standard_EXPORT virtual void BindPositionAttribute (const Handle(OpenGl_Context)& theGlCtx) const;
119 //! Unbind all vertex attributes. Default implementation does nothing.
120 Standard_EXPORT virtual void UnbindAllAttributes (const Handle(OpenGl_Context)& theGlCtx) const;
124 DEFINE_STANDARD_RTTIEXT(OpenGl_VertexBuffer, OpenGl_Buffer)
128 DEFINE_STANDARD_HANDLE(OpenGl_VertexBuffer, OpenGl_Buffer)
130 #endif // _OpenGl_VertexBuffer_H__