Open CASCADE Technology  7.4.1.dev
Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes
OpenGl_Texture Class Reference

Texture resource. More...

#include <OpenGl_Texture.hxx>

Inheritance diagram for OpenGl_Texture:
Inheritance graph
[legend]

Public Member Functions

 OpenGl_Texture (const TCollection_AsciiString &theResourceId=TCollection_AsciiString(), const Handle< Graphic3d_TextureParams > &theParams=Handle< Graphic3d_TextureParams >())
 Create uninitialized texture. More...
 
virtual ~OpenGl_Texture ()
 Destroy object. More...
 
bool IsValid () const
 
GLenum GetTarget () const
 
GLsizei SizeX () const
 
GLsizei SizeY () const
 
GLuint TextureId () const
 
GLenum GetFormat () const
 
GLint SizedFormat () const
 
bool IsAlpha () const
 Return true for GL_RED and GL_ALPHA formats. More...
 
void SetAlpha (const bool theValue)
 Setup to interpret the format as Alpha by Shader Manager (should be GL_ALPHA within compatible context or GL_RED otherwise). More...
 
bool IsTopDown () const
 Return if 2D surface is defined top-down (TRUE) or bottom-up (FALSE). Normally set from Image_PixMap::IsTopDown() within texture initialization. More...
 
void SetTopDown (bool theIsTopDown)
 Set if 2D surface is defined top-down (TRUE) or bottom-up (FALSE). More...
 
bool Create (const Handle< OpenGl_Context > &theCtx)
 Creates Texture id if not yet generated. Data should be initialized by another method. More...
 
virtual void Release (OpenGl_Context *theCtx) override
 Destroy object - will release GPU memory if any. More...
 
const Handle< OpenGl_Sampler > & Sampler () const
 Return texture sampler. More...
 
void SetSampler (const Handle< OpenGl_Sampler > &theSampler)
 Set texture sampler. More...
 
bool InitSamplerObject (const Handle< OpenGl_Context > &theCtx)
 Initialize the Sampler Object (as OpenGL object). More...
 
void Bind (const Handle< OpenGl_Context > &theCtx) const
 Bind this Texture to the unit specified in sampler parameters. Also binds Sampler Object if it is allocated. More...
 
void Unbind (const Handle< OpenGl_Context > &theCtx) const
 Unbind texture from the unit specified in sampler parameters. Also unbinds Sampler Object if it is allocated. More...
 
void Bind (const Handle< OpenGl_Context > &theCtx, const Graphic3d_TextureUnit theTextureUnit) const
 Bind this Texture to specified unit. Also binds Sampler Object if it is allocated. More...
 
void Unbind (const Handle< OpenGl_Context > &theCtx, const Graphic3d_TextureUnit theTextureUnit) const
 Unbind texture from specified unit. Also unbinds Sampler Object if it is allocated. More...
 
Standard_Size Revision () const
 Revision of associated data source. More...
 
void SetRevision (const Standard_Size theRevision)
 Set revision of associated data source. More...
 
bool Init (const Handle< OpenGl_Context > &theCtx, const Image_PixMap &theImage, const Graphic3d_TypeOfTexture theType, const Standard_Boolean theIsColorMap)
 Notice that texture will be unbound after this call. More...
 
bool Init (const Handle< OpenGl_Context > &theCtx, const OpenGl_TextureFormat &theFormat, const Graphic3d_Vec2i &theSizeXY, const Graphic3d_TypeOfTexture theType, const Image_PixMap *theImage=NULL)
 Initialize the texture with specified format, size and texture type. If theImage is empty the texture data will contain trash. Notice that texture will be unbound after this call. More...
 
bool Init (const Handle< OpenGl_Context > &theCtx, const Handle< Graphic3d_TextureMap > &theTextureMap)
 Initialize the texture with Graphic3d_TextureMap. It is an universal way to initialize. Suitable initialization method will be chosen. More...
 
bool InitCompressed (const Handle< OpenGl_Context > &theCtx, const Image_CompressedPixMap &theImage, const Standard_Boolean theIsColorMap)
 Initialize the texture with Image_CompressedPixMap. More...
 
bool Init2DMultisample (const Handle< OpenGl_Context > &theCtx, const GLsizei theNbSamples, const GLint theTextFormat, const GLsizei theSizeX, const GLsizei theSizeY)
 Initialize the 2D multisampling texture using glTexImage2DMultisample(). More...
 
bool InitRectangle (const Handle< OpenGl_Context > &theCtx, const Standard_Integer theSizeX, const Standard_Integer theSizeY, const OpenGl_TextureFormat &theFormat)
 Allocates texture rectangle with specified format and size. More...
 
bool Init3D (const Handle< OpenGl_Context > &theCtx, const OpenGl_TextureFormat &theFormat, const Graphic3d_Vec3i &theSizeXYZ, const void *thePixels)
 Initializes 3D texture rectangle with specified format and size. More...
 
Standard_Boolean HasMipmaps () const
 
Standard_Integer MaxMipmapLevel () const
 Return upper mipmap level index (0 means no mipmaps). More...
 
virtual Standard_Size EstimatedDataSize () const override
 Returns estimated GPU memory usage for holding data without considering overheads and allocation alignment rules. More...
 
virtual bool IsPointSprite () const
 Returns TRUE for point sprite texture. More...
 
bool Init (const Handle< OpenGl_Context > &theCtx, const GLint theTextFormat, const GLenum thePixelFormat, const GLenum theDataType, const GLsizei theSizeX, const GLsizei theSizeY, const Graphic3d_TypeOfTexture theType, const Image_PixMap *theImage=NULL)
 
bool Init (const Handle< OpenGl_Context > &theCtx, const Image_PixMap &theImage, const Graphic3d_TypeOfTexture theType)
 
bool Init3D (const Handle< OpenGl_Context > &theCtx, const GLint theTextFormat, const GLenum thePixelFormat, const GLenum theDataType, const Standard_Integer theSizeX, const Standard_Integer theSizeY, const Standard_Integer theSizeZ, const void *thePixels)
 
bool InitCubeMap (const Handle< OpenGl_Context > &theCtx, const Handle< Graphic3d_CubeMap > &theCubeMap, Standard_Size theSize, Image_Format theFormat, Standard_Boolean theToGenMipmap, Standard_Boolean theIsColorMap)
 Initializes 6 sides of cubemap. If theCubeMap is not NULL then size and format will be taken from it and corresponding arguments will be ignored. Otherwise this parametres will be taken from arguments. More...
 
- Public Member Functions inherited from OpenGl_NamedResource
 OpenGl_NamedResource (const TCollection_AsciiString &theId)
 Empty constructor. More...
 
const TCollection_AsciiStringResourceId () const
 Return resource name. More...
 
- Public Member Functions inherited from OpenGl_Resource
 OpenGl_Resource ()
 Empty constructor. More...
 
virtual ~OpenGl_Resource ()
 Destructor. Inheritors should call Clean (NULL) within it. More...
 
virtual void DumpJson (Standard_OStream &theOStream, Standard_Integer theDepth=-1) const
 Dumps the content of me into the stream. More...
 
- Public Member Functions inherited from Standard_Transient
 Standard_Transient ()
 Empty constructor. More...
 
 Standard_Transient (const Standard_Transient &)
 Copy constructor – does nothing. More...
 
Standard_Transientoperator= (const Standard_Transient &)
 Assignment operator, needed to avoid copying reference counter. More...
 
virtual ~Standard_Transient ()
 Destructor must be virtual. More...
 
virtual void Delete () const
 Memory deallocator for transient classes. More...
 
virtual const opencascade::handle< Standard_Type > & DynamicType () const
 Returns a type descriptor about this object. More...
 
Standard_Boolean IsInstance (const opencascade::handle< Standard_Type > &theType) const
 Returns a true value if this is an instance of Type. More...
 
Standard_Boolean IsInstance (const Standard_CString theTypeName) const
 Returns a true value if this is an instance of TypeName. More...
 
Standard_Boolean IsKind (const opencascade::handle< Standard_Type > &theType) const
 Returns true if this is an instance of Type or an instance of any class that inherits from Type. Note that multiple inheritance is not supported by OCCT RTTI mechanism. More...
 
Standard_Boolean IsKind (const Standard_CString theTypeName) const
 Returns true if this is an instance of TypeName or an instance of any class that inherits from TypeName. Note that multiple inheritance is not supported by OCCT RTTI mechanism. More...
 
Standard_TransientThis () const
 Returns non-const pointer to this object (like const_cast). For protection against creating handle to objects allocated in stack or call from constructor, it will raise exception Standard_ProgramError if reference counter is zero. More...
 
Standard_Integer GetRefCount () const
 Get the reference counter of this object. More...
 
void IncrementRefCounter () const
 Increments the reference counter of this object. More...
 
Standard_Integer DecrementRefCounter () const
 Decrements the reference counter of this object; returns the decremented value. More...
 

Static Public Member Functions

static Standard_Size PixelSizeOfPixelFormat (Standard_Integer theInternalFormat)
 Return pixel size of pixel format in bytes. Note that this method considers that OpenGL natively supports this pixel format, which might be not the case - in the latter case, actual pixel size might differ! More...
 
static bool GetDataFormat (const Handle< OpenGl_Context > &theCtx, const Image_Format theFormat, GLint &theTextFormat, GLenum &thePixelFormat, GLenum &theDataType)
 
static bool GetDataFormat (const Handle< OpenGl_Context > &theCtx, const Image_PixMap &theData, GLint &theTextFormat, GLenum &thePixelFormat, GLenum &theDataType)
 
- Static Public Member Functions inherited from Standard_Transient
static const char * get_type_name ()
 Returns a type descriptor about this object. More...
 
static const opencascade::handle< Standard_Type > & get_type_descriptor ()
 Returns type descriptor of Standard_Transient class. More...
 

Static Public Attributes

static const GLuint NO_TEXTURE = 0
 Helpful constants. More...
 

Protected Member Functions

void applyDefaultSamplerParams (const Handle< OpenGl_Context > &theCtx)
 Apply default sampler parameters after texture creation. More...
 

Protected Attributes

Handle< OpenGl_SamplermySampler
 texture sampler More...
 
Standard_Size myRevision
 revision of associated data source More...
 
GLuint myTextureId
 GL resource ID. More...
 
GLenum myTarget
 GL_TEXTURE_1D/GL_TEXTURE_2D/GL_TEXTURE_3D. More...
 
GLsizei mySizeX
 texture width More...
 
GLsizei mySizeY
 texture height More...
 
GLsizei mySizeZ
 texture depth More...
 
GLenum myTextFormat
 texture format - GL_RGB, GL_RGBA,... More...
 
GLint mySizedFormat
 internal (sized) texture format More...
 
Standard_Integer myNbSamples
 number of MSAA samples More...
 
Standard_Integer myMaxMipLevel
 upper mipmap level index (0 means no mipmaps) More...
 
bool myIsAlpha
 indicates alpha format More...
 
bool myIsTopDown
 indicates if 2D surface is defined top-down (TRUE) or bottom-up (FALSE) More...
 
- Protected Attributes inherited from OpenGl_NamedResource
TCollection_AsciiString myResourceId
 resource name More...
 

Additional Inherited Members

- Public Types inherited from Standard_Transient
typedef void base_type
 Returns a type descriptor about this object. More...
 

Detailed Description

Texture resource.

Constructor & Destructor Documentation

◆ OpenGl_Texture()

OpenGl_Texture::OpenGl_Texture ( const TCollection_AsciiString theResourceId = TCollection_AsciiString(),
const Handle< Graphic3d_TextureParams > &  theParams = HandleGraphic3d_TextureParams >() 
)

Create uninitialized texture.

◆ ~OpenGl_Texture()

virtual OpenGl_Texture::~OpenGl_Texture ( )
virtual

Destroy object.

Member Function Documentation

◆ applyDefaultSamplerParams()

void OpenGl_Texture::applyDefaultSamplerParams ( const Handle< OpenGl_Context > &  theCtx)
protected

Apply default sampler parameters after texture creation.

◆ Bind() [1/2]

void OpenGl_Texture::Bind ( const Handle< OpenGl_Context > &  theCtx) const
inline

Bind this Texture to the unit specified in sampler parameters. Also binds Sampler Object if it is allocated.

◆ Bind() [2/2]

void OpenGl_Texture::Bind ( const Handle< OpenGl_Context > &  theCtx,
const Graphic3d_TextureUnit  theTextureUnit 
) const

Bind this Texture to specified unit. Also binds Sampler Object if it is allocated.

◆ Create()

bool OpenGl_Texture::Create ( const Handle< OpenGl_Context > &  theCtx)

Creates Texture id if not yet generated. Data should be initialized by another method.

◆ EstimatedDataSize()

virtual Standard_Size OpenGl_Texture::EstimatedDataSize ( ) const
overridevirtual

Returns estimated GPU memory usage for holding data without considering overheads and allocation alignment rules.

Implements OpenGl_Resource.

◆ GetDataFormat() [1/2]

static bool OpenGl_Texture::GetDataFormat ( const Handle< OpenGl_Context > &  theCtx,
const Image_Format  theFormat,
GLint &  theTextFormat,
GLenum &  thePixelFormat,
GLenum &  theDataType 
)
inlinestatic
Deprecated:
("Deprecated method, OpenGl_TextureFormat::FindFormat() should be used instead")

◆ GetDataFormat() [2/2]

static bool OpenGl_Texture::GetDataFormat ( const Handle< OpenGl_Context > &  theCtx,
const Image_PixMap theData,
GLint &  theTextFormat,
GLenum &  thePixelFormat,
GLenum &  theDataType 
)
inlinestatic
Deprecated:
("Deprecated method, OpenGl_TextureFormat::FindFormat() should be used instead")

◆ GetFormat()

GLenum OpenGl_Texture::GetFormat ( ) const
inline
Returns
texture format (not sized)

◆ GetTarget()

GLenum OpenGl_Texture::GetTarget ( ) const
inline
Returns
target to which the texture is bound (GL_TEXTURE_1D, GL_TEXTURE_2D)

◆ HasMipmaps()

Standard_Boolean OpenGl_Texture::HasMipmaps ( ) const
inline
Returns
true if texture was generated within mipmaps

◆ Init() [1/5]

bool OpenGl_Texture::Init ( const Handle< OpenGl_Context > &  theCtx,
const Image_PixMap theImage,
const Graphic3d_TypeOfTexture  theType,
const Standard_Boolean  theIsColorMap 
)

Notice that texture will be unbound after this call.

◆ Init() [2/5]

bool OpenGl_Texture::Init ( const Handle< OpenGl_Context > &  theCtx,
const OpenGl_TextureFormat theFormat,
const Graphic3d_Vec2i theSizeXY,
const Graphic3d_TypeOfTexture  theType,
const Image_PixMap theImage = NULL 
)

Initialize the texture with specified format, size and texture type. If theImage is empty the texture data will contain trash. Notice that texture will be unbound after this call.

◆ Init() [3/5]

bool OpenGl_Texture::Init ( const Handle< OpenGl_Context > &  theCtx,
const Handle< Graphic3d_TextureMap > &  theTextureMap 
)

Initialize the texture with Graphic3d_TextureMap. It is an universal way to initialize. Suitable initialization method will be chosen.

◆ Init() [4/5]

bool OpenGl_Texture::Init ( const Handle< OpenGl_Context > &  theCtx,
const GLint  theTextFormat,
const GLenum  thePixelFormat,
const GLenum  theDataType,
const GLsizei  theSizeX,
const GLsizei  theSizeY,
const Graphic3d_TypeOfTexture  theType,
const Image_PixMap theImage = NULL 
)
inline
Deprecated:
("Deprecated method, OpenGl_TextureFormat should be passed instead of separate parameters")

◆ Init() [5/5]

bool OpenGl_Texture::Init ( const Handle< OpenGl_Context > &  theCtx,
const Image_PixMap theImage,
const Graphic3d_TypeOfTexture  theType 
)
inline
Deprecated:
("Deprecated method, theIsColorMap parameter should be explicitly specified")

◆ Init2DMultisample()

bool OpenGl_Texture::Init2DMultisample ( const Handle< OpenGl_Context > &  theCtx,
const GLsizei  theNbSamples,
const GLint  theTextFormat,
const GLsizei  theSizeX,
const GLsizei  theSizeY 
)

Initialize the 2D multisampling texture using glTexImage2DMultisample().

◆ Init3D() [1/2]

bool OpenGl_Texture::Init3D ( const Handle< OpenGl_Context > &  theCtx,
const OpenGl_TextureFormat theFormat,
const Graphic3d_Vec3i theSizeXYZ,
const void *  thePixels 
)

Initializes 3D texture rectangle with specified format and size.

◆ Init3D() [2/2]

bool OpenGl_Texture::Init3D ( const Handle< OpenGl_Context > &  theCtx,
const GLint  theTextFormat,
const GLenum  thePixelFormat,
const GLenum  theDataType,
const Standard_Integer  theSizeX,
const Standard_Integer  theSizeY,
const Standard_Integer  theSizeZ,
const void *  thePixels 
)
inline
Deprecated:
("Deprecated method, OpenGl_TextureFormat should be passed instead of separate parameters")

◆ InitCompressed()

bool OpenGl_Texture::InitCompressed ( const Handle< OpenGl_Context > &  theCtx,
const Image_CompressedPixMap theImage,
const Standard_Boolean  theIsColorMap 
)

Initialize the texture with Image_CompressedPixMap.

◆ InitCubeMap()

bool OpenGl_Texture::InitCubeMap ( const Handle< OpenGl_Context > &  theCtx,
const Handle< Graphic3d_CubeMap > &  theCubeMap,
Standard_Size  theSize,
Image_Format  theFormat,
Standard_Boolean  theToGenMipmap,
Standard_Boolean  theIsColorMap 
)

Initializes 6 sides of cubemap. If theCubeMap is not NULL then size and format will be taken from it and corresponding arguments will be ignored. Otherwise this parametres will be taken from arguments.

Parameters
theCtx[in] active OpenGL context
theCubeMap[in] cubemap definition, can be NULL
theSize[in] cubemap dimensions
theFormat[in] image format
theToGenMipmap[in] flag to generate mipmaped cubemap
theIsColorMap[in] flag indicating cubemap storing color values

◆ InitRectangle()

bool OpenGl_Texture::InitRectangle ( const Handle< OpenGl_Context > &  theCtx,
const Standard_Integer  theSizeX,
const Standard_Integer  theSizeY,
const OpenGl_TextureFormat theFormat 
)

Allocates texture rectangle with specified format and size.

Note
Texture data is not initialized (will contain trash).

◆ InitSamplerObject()

bool OpenGl_Texture::InitSamplerObject ( const Handle< OpenGl_Context > &  theCtx)

Initialize the Sampler Object (as OpenGL object).

Parameters
theCtxcurrently bound OpenGL context

◆ IsAlpha()

bool OpenGl_Texture::IsAlpha ( ) const
inline

Return true for GL_RED and GL_ALPHA formats.

◆ IsPointSprite()

virtual bool OpenGl_Texture::IsPointSprite ( ) const
inlinevirtual

Returns TRUE for point sprite texture.

Reimplemented in OpenGl_PointSprite.

◆ IsTopDown()

bool OpenGl_Texture::IsTopDown ( ) const
inline

Return if 2D surface is defined top-down (TRUE) or bottom-up (FALSE). Normally set from Image_PixMap::IsTopDown() within texture initialization.

◆ IsValid()

bool OpenGl_Texture::IsValid ( ) const
inline
Returns
true if current object was initialized

◆ MaxMipmapLevel()

Standard_Integer OpenGl_Texture::MaxMipmapLevel ( ) const
inline

Return upper mipmap level index (0 means no mipmaps).

◆ PixelSizeOfPixelFormat()

static Standard_Size OpenGl_Texture::PixelSizeOfPixelFormat ( Standard_Integer  theInternalFormat)
static

Return pixel size of pixel format in bytes. Note that this method considers that OpenGL natively supports this pixel format, which might be not the case - in the latter case, actual pixel size might differ!

◆ Release()

virtual void OpenGl_Texture::Release ( OpenGl_Context theCtx)
overridevirtual

Destroy object - will release GPU memory if any.

Implements OpenGl_Resource.

Reimplemented in OpenGl_PointSprite.

◆ Revision()

Standard_Size OpenGl_Texture::Revision ( ) const
inline

Revision of associated data source.

◆ Sampler()

const Handle< OpenGl_Sampler >& OpenGl_Texture::Sampler ( ) const
inline

Return texture sampler.

◆ SetAlpha()

void OpenGl_Texture::SetAlpha ( const bool  theValue)
inline

Setup to interpret the format as Alpha by Shader Manager (should be GL_ALPHA within compatible context or GL_RED otherwise).

◆ SetRevision()

void OpenGl_Texture::SetRevision ( const Standard_Size  theRevision)
inline

Set revision of associated data source.

◆ SetSampler()

void OpenGl_Texture::SetSampler ( const Handle< OpenGl_Sampler > &  theSampler)
inline

Set texture sampler.

◆ SetTopDown()

void OpenGl_Texture::SetTopDown ( bool  theIsTopDown)
inline

Set if 2D surface is defined top-down (TRUE) or bottom-up (FALSE).

◆ SizedFormat()

GLint OpenGl_Texture::SizedFormat ( ) const
inline
Returns
texture format (sized)

◆ SizeX()

GLsizei OpenGl_Texture::SizeX ( ) const
inline
Returns
texture width (0 LOD)

◆ SizeY()

GLsizei OpenGl_Texture::SizeY ( ) const
inline
Returns
texture height (0 LOD)

◆ TextureId()

GLuint OpenGl_Texture::TextureId ( ) const
inline
Returns
texture ID

◆ Unbind() [1/2]

void OpenGl_Texture::Unbind ( const Handle< OpenGl_Context > &  theCtx) const
inline

Unbind texture from the unit specified in sampler parameters. Also unbinds Sampler Object if it is allocated.

◆ Unbind() [2/2]

void OpenGl_Texture::Unbind ( const Handle< OpenGl_Context > &  theCtx,
const Graphic3d_TextureUnit  theTextureUnit 
) const

Unbind texture from specified unit. Also unbinds Sampler Object if it is allocated.

Field Documentation

◆ myIsAlpha

bool OpenGl_Texture::myIsAlpha
protected

indicates alpha format

◆ myIsTopDown

bool OpenGl_Texture::myIsTopDown
protected

indicates if 2D surface is defined top-down (TRUE) or bottom-up (FALSE)

◆ myMaxMipLevel

Standard_Integer OpenGl_Texture::myMaxMipLevel
protected

upper mipmap level index (0 means no mipmaps)

◆ myNbSamples

Standard_Integer OpenGl_Texture::myNbSamples
protected

number of MSAA samples

◆ myRevision

Standard_Size OpenGl_Texture::myRevision
protected

revision of associated data source

◆ mySampler

Handle< OpenGl_Sampler > OpenGl_Texture::mySampler
protected

texture sampler

◆ mySizedFormat

GLint OpenGl_Texture::mySizedFormat
protected

internal (sized) texture format

◆ mySizeX

GLsizei OpenGl_Texture::mySizeX
protected

texture width

◆ mySizeY

GLsizei OpenGl_Texture::mySizeY
protected

texture height

◆ mySizeZ

GLsizei OpenGl_Texture::mySizeZ
protected

texture depth

◆ myTarget

GLenum OpenGl_Texture::myTarget
protected

GL_TEXTURE_1D/GL_TEXTURE_2D/GL_TEXTURE_3D.

◆ myTextFormat

GLenum OpenGl_Texture::myTextFormat
protected

texture format - GL_RGB, GL_RGBA,...

◆ myTextureId

GLuint OpenGl_Texture::myTextureId
protected

GL resource ID.

◆ NO_TEXTURE

const GLuint OpenGl_Texture::NO_TEXTURE = 0
static

Helpful constants.


The documentation for this class was generated from the following file: