Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-31 08:30:59

0001 // Created by: Kirill GAVRILOV
0002 // Copyright (c) 2013-2014 OPEN CASCADE SAS
0003 //
0004 // This file is part of Open CASCADE Technology software library.
0005 //
0006 // This library is free software; you can redistribute it and/or modify it under
0007 // the terms of the GNU Lesser General Public License version 2.1 as published
0008 // by the Free Software Foundation, with special exception defined in the file
0009 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0010 // distribution for complete text of the license and disclaimer of any warranty.
0011 //
0012 // Alternatively, this file may be used under the terms of Open CASCADE
0013 // commercial license or contractual agreement.
0014 
0015 #ifndef OpenGl_VertexBuffer_HeaderFile
0016 #define OpenGl_VertexBuffer_HeaderFile
0017 
0018 #include <OpenGl_Buffer.hxx>
0019 #include <Graphic3d_Buffer.hxx>
0020 
0021 //! Vertex Buffer Object - is a general storage object for vertex attributes (position, normal,
0022 //! color). Notice that you should use OpenGl_IndexBuffer specialization for array of indices.
0023 class OpenGl_VertexBuffer : public OpenGl_Buffer
0024 {
0025 public:
0026   //! Create uninitialized VBO.
0027   Standard_EXPORT OpenGl_VertexBuffer();
0028 
0029   //! Destroy object.
0030   Standard_EXPORT virtual ~OpenGl_VertexBuffer();
0031 
0032   //! Return buffer target GL_ARRAY_BUFFER.
0033   Standard_EXPORT virtual unsigned int GetTarget() const Standard_OVERRIDE;
0034 
0035   //! Bind this VBO to active GLSL program.
0036   Standard_EXPORT void BindVertexAttrib(const Handle(OpenGl_Context)& theGlCtx,
0037                                         const unsigned int            theAttribLoc) const;
0038 
0039   //! Unbind any VBO from active GLSL program.
0040   Standard_EXPORT void UnbindVertexAttrib(const Handle(OpenGl_Context)& theGlCtx,
0041                                           const unsigned int            theAttribLoc) const;
0042 
0043   //! Bind this VBO and enable specified attribute in OpenGl_Context::ActiveProgram() or FFP.
0044   //! @param theGlCtx - handle to bound GL context;
0045   //! @param theMode  - array mode (GL_VERTEX_ARRAY, GL_NORMAL_ARRAY, GL_COLOR_ARRAY,
0046   //! GL_INDEX_ARRAY, GL_TEXTURE_COORD_ARRAY).
0047   void BindAttribute(const Handle(OpenGl_Context)&   theCtx,
0048                      const Graphic3d_TypeOfAttribute theMode) const
0049   {
0050     if (IsValid())
0051     {
0052       Bind(theCtx);
0053       bindAttribute(theCtx, theMode, static_cast<int>(myComponentsNb), myDataType, 0, myOffset);
0054     }
0055   }
0056 
0057   //! Unbind this VBO and disable specified attribute in OpenGl_Context::ActiveProgram() or FFP.
0058   //! @param theCtx handle to bound GL context
0059   //! @param theMode  array mode
0060   void UnbindAttribute(const Handle(OpenGl_Context)&   theCtx,
0061                        const Graphic3d_TypeOfAttribute theMode) const
0062   {
0063     if (IsValid())
0064     {
0065       Unbind(theCtx);
0066       unbindAttribute(theCtx, theMode);
0067     }
0068   }
0069 
0070 public: //! @name advanced methods
0071   //! Setup array pointer - either for active GLSL program OpenGl_Context::ActiveProgram()
0072   //! or for FFP using bindFixed() when no program bound.
0073   Standard_EXPORT static void bindAttribute(const Handle(OpenGl_Context)&   theGlCtx,
0074                                             const Graphic3d_TypeOfAttribute theMode,
0075                                             const Standard_Integer          theNbComp,
0076                                             const unsigned int              theDataType,
0077                                             const Standard_Integer          theStride,
0078                                             const void*                     theOffset);
0079 
0080   //! Disable GLSL array pointer - either for active GLSL program OpenGl_Context::ActiveProgram()
0081   //! or for FFP using unbindFixed() when no program bound.
0082   Standard_EXPORT static void unbindAttribute(const Handle(OpenGl_Context)&   theGlCtx,
0083                                               const Graphic3d_TypeOfAttribute theMode);
0084 
0085 private:
0086   //! Setup FFP array pointer.
0087   Standard_EXPORT static void bindFixed(const Handle(OpenGl_Context)&   theGlCtx,
0088                                         const Graphic3d_TypeOfAttribute theMode,
0089                                         const Standard_Integer          theNbComp,
0090                                         const unsigned int              theDataType,
0091                                         const Standard_Integer          theStride,
0092                                         const void*                     theOffset);
0093 
0094   //! Disable FFP array pointer.
0095   Standard_EXPORT static void unbindFixed(const Handle(OpenGl_Context)&   theGlCtx,
0096                                           const Graphic3d_TypeOfAttribute theMode);
0097 
0098   //! Disable FFP color array pointer.
0099   Standard_EXPORT static void unbindFixedColor(const Handle(OpenGl_Context)& theCtx);
0100 
0101 public: //! @name methods for interleaved attributes array
0102   //! @return true if buffer contains per-vertex color attribute
0103   Standard_EXPORT virtual bool HasColorAttribute() const;
0104 
0105   //! @return true if buffer contains per-vertex normal attribute
0106   Standard_EXPORT virtual bool HasNormalAttribute() const;
0107 
0108   //! Bind all vertex attributes to active program OpenGl_Context::ActiveProgram() or for FFP.
0109   //! Default implementation does nothing.
0110   Standard_EXPORT virtual void BindAllAttributes(const Handle(OpenGl_Context)& theGlCtx) const;
0111 
0112   //! Bind vertex position attribute only. Default implementation does nothing.
0113   Standard_EXPORT virtual void BindPositionAttribute(const Handle(OpenGl_Context)& theGlCtx) const;
0114 
0115   //! Unbind all vertex attributes. Default implementation does nothing.
0116   Standard_EXPORT virtual void UnbindAllAttributes(const Handle(OpenGl_Context)& theGlCtx) const;
0117 
0118 public:
0119   DEFINE_STANDARD_RTTIEXT(OpenGl_VertexBuffer, OpenGl_Buffer)
0120 };
0121 
0122 DEFINE_STANDARD_HANDLE(OpenGl_VertexBuffer, OpenGl_Buffer)
0123 
0124 #endif // _OpenGl_VertexBuffer_H__