Back to home page

EIC code displayed by LXR

 
 

    


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

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 
0036   //! Helpful constants
0037   static const unsigned int NO_TEXTURE = 0;
0038 
0039 public:
0040 
0041   //! Create uninitialized TBO.
0042   Standard_EXPORT OpenGl_TextureBuffer();
0043 
0044   //! Destroy object, will throw exception if GPU memory not released with Release() before.
0045   Standard_EXPORT virtual ~OpenGl_TextureBuffer();
0046 
0047   //! Override VBO target
0048   Standard_EXPORT virtual unsigned int GetTarget() const Standard_OVERRIDE;
0049 
0050   //! Returns true if TBO is valid.
0051   //! Notice that no any real GL call is performed!
0052   bool IsValid() const
0053   {
0054     return OpenGl_Buffer::IsValid()
0055         && myTextureId != NO_TEXTURE;
0056   }
0057 
0058   //! Destroy object - will release GPU memory if any.
0059   Standard_EXPORT virtual void Release (OpenGl_Context* theGlCtx) Standard_OVERRIDE;
0060 
0061   //! Creates VBO and Texture names (ids) if not yet generated.
0062   //! Data should be initialized by another method.
0063   Standard_EXPORT bool Create (const Handle(OpenGl_Context)& theGlCtx) Standard_OVERRIDE;
0064 
0065   //! Perform TBO initialization with specified data.
0066   //! Existing data will be deleted.
0067   Standard_EXPORT bool Init (const Handle(OpenGl_Context)& theGlCtx,
0068                              const unsigned int     theComponentsNb,
0069                              const Standard_Integer theElemsNb,
0070                              const float* theData);
0071 
0072   //! Perform TBO initialization with specified data.
0073   //! Existing data will be deleted.
0074   Standard_EXPORT bool Init (const Handle(OpenGl_Context)& theGlCtx,
0075                              const unsigned int     theComponentsNb,
0076                              const Standard_Integer theElemsNb,
0077                              const unsigned int*    theData);
0078 
0079   //! Perform TBO initialization with specified data.
0080   //! Existing data will be deleted.
0081   Standard_EXPORT bool Init (const Handle(OpenGl_Context)& theGlCtx,
0082                              const unsigned int     theComponentsNb,
0083                              const Standard_Integer theElemsNb,
0084                              const unsigned short*  theData);
0085 
0086   //! Perform TBO initialization with specified data.
0087   //! Existing data will be deleted.
0088   Standard_EXPORT bool Init (const Handle(OpenGl_Context)& theGlCtx,
0089                              const unsigned int     theComponentsNb,
0090                              const Standard_Integer theElemsNb,
0091                              const Standard_Byte*   theData);
0092 
0093   //! Bind TBO to specified Texture Unit.
0094   Standard_EXPORT void BindTexture (const Handle(OpenGl_Context)& theGlCtx,
0095                                     const Graphic3d_TextureUnit   theTextureUnit) const;
0096 
0097   //! Unbind TBO.
0098   Standard_EXPORT void UnbindTexture (const Handle(OpenGl_Context)& theGlCtx,
0099                                       const Graphic3d_TextureUnit   theTextureUnit) const;
0100 
0101   //! Returns name of TBO.
0102   unsigned int TextureId() const { return myTextureId; }
0103 
0104   //! Returns internal texture format.
0105   unsigned int TextureFormat() const { return myTexFormat; }
0106 
0107 protected:
0108 
0109   unsigned int myTextureId; //!< texture id
0110   unsigned int myTexFormat; //!< internal texture format
0111 
0112 };
0113 
0114 DEFINE_STANDARD_HANDLE(OpenGl_TextureBuffer, OpenGl_Buffer)
0115 
0116 #endif // _OpenGl_TextureBuffer_H__