Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:04:36

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, color).
0022 //! Notice that you should use OpenGl_IndexBuffer specialization for array of indices.
0023 class OpenGl_VertexBuffer : public OpenGl_Buffer
0024 {
0025 public:
0026 
0027   //! Create uninitialized VBO.
0028   Standard_EXPORT OpenGl_VertexBuffer();
0029 
0030   //! Destroy object.
0031   Standard_EXPORT virtual ~OpenGl_VertexBuffer();
0032 
0033   //! Return buffer target GL_ARRAY_BUFFER.
0034   Standard_EXPORT virtual unsigned int GetTarget() const Standard_OVERRIDE;
0035 
0036   //! Bind this VBO to active GLSL program.
0037   Standard_EXPORT void BindVertexAttrib (const Handle(OpenGl_Context)& theGlCtx,
0038                                          const unsigned int            theAttribLoc) const;
0039 
0040   //! Unbind any VBO from active GLSL program.
0041   Standard_EXPORT void UnbindVertexAttrib (const Handle(OpenGl_Context)& theGlCtx,
0042                                            const unsigned int            theAttribLoc) const;
0043 
0044   //! Bind this VBO and enable specified attribute in OpenGl_Context::ActiveProgram() or FFP.
0045   //! @param theGlCtx - handle to bound GL context;
0046   //! @param theMode  - array mode (GL_VERTEX_ARRAY, GL_NORMAL_ARRAY, GL_COLOR_ARRAY, 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 
0072   //! Setup array pointer - either for active GLSL program OpenGl_Context::ActiveProgram()
0073   //! or for FFP using bindFixed() when no program bound.
0074   Standard_EXPORT static void bindAttribute (const Handle(OpenGl_Context)&   theGlCtx,
0075                                              const Graphic3d_TypeOfAttribute theMode,
0076                                              const Standard_Integer          theNbComp,
0077                                              const unsigned int              theDataType,
0078                                              const Standard_Integer          theStride,
0079                                              const void*                     theOffset);
0080 
0081   //! Disable GLSL array pointer - either for active GLSL program OpenGl_Context::ActiveProgram()
0082   //! or for FFP using unbindFixed() when no program bound.
0083   Standard_EXPORT static void unbindAttribute (const Handle(OpenGl_Context)&   theGlCtx,
0084                                                const Graphic3d_TypeOfAttribute theMode);
0085 
0086 private:
0087 
0088   //! Setup FFP array pointer.
0089   Standard_EXPORT static void bindFixed (const Handle(OpenGl_Context)&   theGlCtx,
0090                                          const Graphic3d_TypeOfAttribute theMode,
0091                                          const Standard_Integer          theNbComp,
0092                                          const unsigned int              theDataType,
0093                                          const Standard_Integer          theStride,
0094                                          const void*                     theOffset);
0095 
0096   //! Disable FFP array pointer.
0097   Standard_EXPORT static void unbindFixed (const Handle(OpenGl_Context)&   theGlCtx,
0098                                            const Graphic3d_TypeOfAttribute theMode);
0099 
0100   //! Disable FFP color array pointer.
0101   Standard_EXPORT static void unbindFixedColor (const Handle(OpenGl_Context)& theCtx);
0102 
0103 public: //! @name methods for interleaved attributes array
0104 
0105   //! @return true if buffer contains per-vertex color attribute
0106   Standard_EXPORT virtual bool HasColorAttribute() const;
0107 
0108   //! @return true if buffer contains per-vertex normal attribute
0109   Standard_EXPORT virtual bool HasNormalAttribute() const;
0110 
0111   //! Bind all vertex attributes to active program OpenGl_Context::ActiveProgram() or for FFP.
0112   //! Default implementation does nothing.
0113   Standard_EXPORT virtual void BindAllAttributes (const Handle(OpenGl_Context)& theGlCtx) const;
0114 
0115   //! Bind vertex position attribute only. Default implementation does nothing.
0116   Standard_EXPORT virtual void BindPositionAttribute (const Handle(OpenGl_Context)& theGlCtx) const;
0117 
0118   //! Unbind all vertex attributes. Default implementation does nothing.
0119   Standard_EXPORT virtual void UnbindAllAttributes (const Handle(OpenGl_Context)& theGlCtx) const;
0120 
0121 public:
0122 
0123   DEFINE_STANDARD_RTTIEXT(OpenGl_VertexBuffer, OpenGl_Buffer)
0124 
0125 };
0126 
0127 DEFINE_STANDARD_HANDLE(OpenGl_VertexBuffer, OpenGl_Buffer)
0128 
0129 #endif // _OpenGl_VertexBuffer_H__