Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-07-15 08:26:00

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_TextureBuffer_H__
0016 #define _OpenGl_TextureBuffer_H__
0017 
0018 #include <Graphic3d_TextureUnit.hxx>
0019 #include <OpenGl_Buffer.hxx>
0020 
0021 //! Texture Buffer Object.
0022 //! This is a special 1D texture that VBO-style initialized.
0023 //! The main differences from general 1D texture:
0024 //!  - no interpolation between field;
0025 //!  - greater sizes;
0026 //!  - special sampler object in GLSL shader to access data by index.
0027 //!
0028 //! Notice that though TBO is inherited from VBO this is to unify design
0029 //! user shouldn't cast it to base class and all really useful methods
0030 //! are declared in this class.
0031 class OpenGl_TextureBuffer : public OpenGl_Buffer
0032 {
0033   DEFINE_STANDARD_RTTIEXT(OpenGl_TextureBuffer, OpenGl_Buffer)
0034 public:
0035   //! Helpful constants
0036   static const unsigned int NO_TEXTURE = 0;
0037 
0038 public:
0039   //! Create uninitialized TBO.
0040   Standard_EXPORT OpenGl_TextureBuffer();
0041 
0042   //! Destroy object, will throw exception if GPU memory not released with Release() before.
0043   Standard_EXPORT virtual ~OpenGl_TextureBuffer();
0044 
0045   //! Override VBO target
0046   Standard_EXPORT virtual unsigned int GetTarget() const Standard_OVERRIDE;
0047 
0048   //! Returns true if TBO is valid.
0049   //! Notice that no any real GL call is performed!
0050   bool IsValid() const { return OpenGl_Buffer::IsValid() && myTextureId != NO_TEXTURE; }
0051 
0052   //! Destroy object - will release GPU memory if any.
0053   Standard_EXPORT virtual void Release(OpenGl_Context* theGlCtx) Standard_OVERRIDE;
0054 
0055   //! Creates VBO and Texture names (ids) if not yet generated.
0056   //! Data should be initialized by another method.
0057   Standard_EXPORT bool Create(const Handle(OpenGl_Context)& theGlCtx) Standard_OVERRIDE;
0058 
0059   //! Perform TBO initialization with specified data.
0060   //! Existing data will be deleted.
0061   Standard_EXPORT bool Init(const Handle(OpenGl_Context)& theGlCtx,
0062                             const unsigned int            theComponentsNb,
0063                             const Standard_Integer        theElemsNb,
0064                             const float*                  theData);
0065 
0066   //! Perform TBO initialization with specified data.
0067   //! Existing data will be deleted.
0068   Standard_EXPORT bool Init(const Handle(OpenGl_Context)& theGlCtx,
0069                             const unsigned int            theComponentsNb,
0070                             const Standard_Integer        theElemsNb,
0071                             const unsigned int*           theData);
0072 
0073   //! Perform TBO initialization with specified data.
0074   //! Existing data will be deleted.
0075   Standard_EXPORT bool Init(const Handle(OpenGl_Context)& theGlCtx,
0076                             const unsigned int            theComponentsNb,
0077                             const Standard_Integer        theElemsNb,
0078                             const unsigned short*         theData);
0079 
0080   //! Perform TBO initialization with specified data.
0081   //! Existing data will be deleted.
0082   Standard_EXPORT bool Init(const Handle(OpenGl_Context)& theGlCtx,
0083                             const unsigned int            theComponentsNb,
0084                             const Standard_Integer        theElemsNb,
0085                             const Standard_Byte*          theData);
0086 
0087   //! Bind TBO to specified Texture Unit.
0088   Standard_EXPORT void BindTexture(const Handle(OpenGl_Context)& theGlCtx,
0089                                    const Graphic3d_TextureUnit   theTextureUnit) const;
0090 
0091   //! Unbind TBO.
0092   Standard_EXPORT void UnbindTexture(const Handle(OpenGl_Context)& theGlCtx,
0093                                      const Graphic3d_TextureUnit   theTextureUnit) const;
0094 
0095   //! Returns name of TBO.
0096   unsigned int TextureId() const { return myTextureId; }
0097 
0098   //! Returns internal texture format.
0099   unsigned int TextureFormat() const { return myTexFormat; }
0100 
0101 protected:
0102   unsigned int myTextureId; //!< texture id
0103   unsigned int myTexFormat; //!< internal texture format
0104 };
0105 
0106 DEFINE_STANDARD_HANDLE(OpenGl_TextureBuffer, OpenGl_Buffer)
0107 
0108 #endif // _OpenGl_TextureBuffer_H__