Open CASCADE Technology 7.8.0
|
Texture resource. More...
#include <OpenGl_Texture.hxx>
Public Member Functions | |
OpenGl_Texture (const TCollection_AsciiString &theResourceId=TCollection_AsciiString(), const Handle< Graphic3d_TextureParams > &theParams=Handle< Graphic3d_TextureParams >()) | |
Create uninitialized texture. | |
virtual | ~OpenGl_Texture () |
Destroy object. | |
virtual bool | IsValid () const |
unsigned int | GetTarget () const |
const Graphic3d_Vec3i & | Size () const |
Return texture dimensions (0 LOD) | |
Standard_Integer | SizeX () const |
Return texture width (0 LOD) | |
Standard_Integer | SizeY () const |
Return texture height (0 LOD) | |
Standard_Integer | SizeZ () const |
Return texture depth (0 LOD) | |
unsigned int | TextureId () const |
unsigned int | GetFormat () const |
Standard_Integer | SizedFormat () const |
bool | IsAlpha () const |
Return true for GL_RED and GL_ALPHA formats. | |
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). | |
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. | |
void | SetTopDown (bool theIsTopDown) |
Set if 2D surface is defined top-down (TRUE) or bottom-up (FALSE). | |
bool | Create (const Handle< OpenGl_Context > &theCtx) |
Creates Texture id if not yet generated. Data should be initialized by another method. | |
virtual void | Release (OpenGl_Context *theCtx) override |
Destroy object - will release GPU memory if any. | |
const Handle< OpenGl_Sampler > & | Sampler () const |
Return texture sampler. | |
void | SetSampler (const Handle< OpenGl_Sampler > &theSampler) |
Set texture sampler. | |
bool | InitSamplerObject (const Handle< OpenGl_Context > &theCtx) |
Initialize the Sampler Object (as OpenGL object). | |
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. | |
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. | |
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. | |
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. | |
Standard_Size | Revision () const |
Revision of associated data source. | |
void | SetRevision (const Standard_Size theRevision) |
Set revision of associated data source. | |
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. | |
bool | Init (const Handle< OpenGl_Context > &theCtx, const OpenGl_TextureFormat &theFormat, const Graphic3d_Vec3i &theSizeXYZ, 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. | |
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 2D 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. | |
bool | Init (const Handle< OpenGl_Context > &theCtx, const Handle< Graphic3d_TextureRoot > &theTextureMap) |
Initialize the texture with Graphic3d_TextureMap. It is an universal way to initialize. Suitable initialization method will be chosen. | |
bool | GenerateMipmaps (const Handle< OpenGl_Context > &theCtx) |
Generate mipmaps. | |
bool | InitCompressed (const Handle< OpenGl_Context > &theCtx, const Image_CompressedPixMap &theImage, const Standard_Boolean theIsColorMap) |
Initialize the texture with Image_CompressedPixMap. | |
bool | Init2DMultisample (const Handle< OpenGl_Context > &theCtx, const Standard_Integer theNbSamples, const Standard_Integer theTextFormat, const Standard_Integer theSizeX, const Standard_Integer theSizeY) |
Initialize the 2D multisampling texture using glTexImage2DMultisample(). | |
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. | |
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. | |
Standard_Boolean | HasMipmaps () const |
Standard_Integer | MaxMipmapLevel () const |
Return upper mipmap level index (0 means no mipmaps). | |
Standard_Integer | NbSamples () const |
Return number of MSAA samples. | |
virtual Standard_Size | EstimatedDataSize () const override |
Returns estimated GPU memory usage for holding data without considering overheads and allocation alignment rules. | |
virtual bool | IsPointSprite () const |
Returns TRUE for point sprite texture. | |
bool | ImageDump (Image_PixMap &theImage, const Handle< OpenGl_Context > &theCtx, Graphic3d_TextureUnit theTexUnit, Standard_Integer theLevel=0, Standard_Integer theCubeSide=0) const |
Auxiliary method for making an image dump from texture data. | |
bool | Init (const Handle< OpenGl_Context > &theCtx, const Standard_Integer theTextFormat, const unsigned int thePixelFormat, const unsigned int theDataType, const Standard_Integer theSizeX, const Standard_Integer 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 Standard_Integer theTextFormat, const unsigned int thePixelFormat, const unsigned int 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 parameters will be taken from arguments. | |
Public Member Functions inherited from OpenGl_NamedResource | |
OpenGl_NamedResource (const TCollection_AsciiString &theId) | |
Empty constructor. | |
const TCollection_AsciiString & | ResourceId () const |
Return resource name. | |
Public Member Functions inherited from OpenGl_Resource | |
OpenGl_Resource () | |
Empty constructor. | |
virtual | ~OpenGl_Resource () |
Destructor. Inheritors should call Clean (NULL) within it. | |
virtual void | DumpJson (Standard_OStream &theOStream, Standard_Integer theDepth=-1) const |
Dumps the content of me into the stream. | |
Public Member Functions inherited from Standard_Transient | |
Standard_Transient () | |
Empty constructor. | |
Standard_Transient (const Standard_Transient &) | |
Copy constructor – does nothing. | |
Standard_Transient & | operator= (const Standard_Transient &) |
Assignment operator, needed to avoid copying reference counter. | |
virtual | ~Standard_Transient () |
Destructor must be virtual. | |
virtual const opencascade::handle< Standard_Type > & | DynamicType () const |
Returns a type descriptor about this object. | |
Standard_Boolean | IsInstance (const opencascade::handle< Standard_Type > &theType) const |
Returns a true value if this is an instance of Type. | |
Standard_Boolean | IsInstance (const Standard_CString theTypeName) const |
Returns a true value if this is an instance of TypeName. | |
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. | |
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. | |
Standard_Transient * | This () 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. | |
Standard_Integer | GetRefCount () const noexcept |
Get the reference counter of this object. | |
void | IncrementRefCounter () noexcept |
Increments the reference counter of this object. | |
Standard_Integer | DecrementRefCounter () noexcept |
Decrements the reference counter of this object; returns the decremented value. | |
virtual void | Delete () const |
Memory deallocator for transient classes. | |
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! | |
static bool | GetDataFormat (const Handle< OpenGl_Context > &theCtx, const Image_Format theFormat, Standard_Integer &theTextFormat, unsigned int &thePixelFormat, unsigned int &theDataType) |
static bool | GetDataFormat (const Handle< OpenGl_Context > &theCtx, const Image_PixMap &theData, Standard_Integer &theTextFormat, unsigned int &thePixelFormat, unsigned int &theDataType) |
Static Public Member Functions inherited from Standard_Transient | |
static constexpr const char * | get_type_name () |
Returns a type descriptor about this object. | |
static const opencascade::handle< Standard_Type > & | get_type_descriptor () |
Returns type descriptor of Standard_Transient class. | |
Static Public Attributes | |
static const unsigned int | NO_TEXTURE = 0 |
Helpful constants. | |
Protected Member Functions | |
void | applyDefaultSamplerParams (const Handle< OpenGl_Context > &theCtx) |
Apply default sampler parameters after texture creation. | |
Protected Attributes | |
Handle< OpenGl_Sampler > | mySampler |
texture sampler | |
Standard_Size | myRevision |
revision of associated data source | |
unsigned int | myTextureId |
GL resource ID. | |
unsigned int | myTarget |
GL_TEXTURE_1D/GL_TEXTURE_2D/GL_TEXTURE_3D. | |
Graphic3d_Vec3i | mySize |
texture width x height x depth | |
unsigned int | myTextFormat |
texture format - GL_RGB, GL_RGBA,... | |
Standard_Integer | mySizedFormat |
internal (sized) texture format | |
Standard_Integer | myNbSamples |
number of MSAA samples | |
Standard_Integer | myMaxMipLevel |
upper mipmap level index (0 means no mipmaps) | |
bool | myIsAlpha |
indicates alpha format | |
bool | myIsTopDown |
indicates if 2D surface is defined top-down (TRUE) or bottom-up (FALSE) | |
Protected Attributes inherited from OpenGl_NamedResource | |
TCollection_AsciiString | myResourceId |
resource name | |
Additional Inherited Members | |
Public Types inherited from Standard_Transient | |
typedef void | base_type |
Returns a type descriptor about this object. | |
Texture resource.
OpenGl_Texture::OpenGl_Texture | ( | const TCollection_AsciiString & | theResourceId = TCollection_AsciiString() , |
const Handle< Graphic3d_TextureParams > & | theParams = Handle< Graphic3d_TextureParams >() |
||
) |
Create uninitialized texture.
|
virtual |
Destroy object.
|
protected |
Apply default sampler parameters after texture creation.
|
inline |
Bind this Texture to the unit specified in sampler parameters. Also binds Sampler Object if it is allocated.
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.
bool OpenGl_Texture::Create | ( | const Handle< OpenGl_Context > & | theCtx | ) |
Creates Texture id if not yet generated. Data should be initialized by another method.
|
overridevirtual |
Returns estimated GPU memory usage for holding data without considering overheads and allocation alignment rules.
Implements OpenGl_Resource.
bool OpenGl_Texture::GenerateMipmaps | ( | const Handle< OpenGl_Context > & | theCtx | ) |
Generate mipmaps.
|
inlinestatic |
|
inlinestatic |
|
inline |
bool OpenGl_Texture::ImageDump | ( | Image_PixMap & | theImage, |
const Handle< OpenGl_Context > & | theCtx, | ||
Graphic3d_TextureUnit | theTexUnit, | ||
Standard_Integer | theLevel = 0 , |
||
Standard_Integer | theCubeSide = 0 |
||
) | const |
Auxiliary method for making an image dump from texture data.
theImage | [out] result image data (will be overridden) |
theCtx | [in] active GL context |
theTexUnit | [in] texture slot to use |
theLevel | [in] mipmap level to dump |
theCubeSide | [in] cubemap side to dump within [0, 5] range |
bool OpenGl_Texture::Init | ( | const Handle< OpenGl_Context > & | theCtx, |
const Handle< Graphic3d_TextureRoot > & | theTextureMap | ||
) |
Initialize the texture with Graphic3d_TextureMap. It is an universal way to initialize. Suitable initialization method will be chosen.
|
inline |
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.
|
inline |
Initialize the 2D 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.
bool OpenGl_Texture::Init | ( | const Handle< OpenGl_Context > & | theCtx, |
const OpenGl_TextureFormat & | theFormat, | ||
const Graphic3d_Vec3i & | theSizeXYZ, | ||
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.
|
inline |
bool OpenGl_Texture::Init2DMultisample | ( | const Handle< OpenGl_Context > & | theCtx, |
const Standard_Integer | theNbSamples, | ||
const Standard_Integer | theTextFormat, | ||
const Standard_Integer | theSizeX, | ||
const Standard_Integer | theSizeY | ||
) |
Initialize the 2D multisampling texture using glTexImage2DMultisample().
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.
|
inline |
bool OpenGl_Texture::InitCompressed | ( | const Handle< OpenGl_Context > & | theCtx, |
const Image_CompressedPixMap & | theImage, | ||
const Standard_Boolean | theIsColorMap | ||
) |
Initialize the texture with Image_CompressedPixMap.
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 parameters will be taken from arguments.
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 |
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.
bool OpenGl_Texture::InitSamplerObject | ( | const Handle< OpenGl_Context > & | theCtx | ) |
Initialize the Sampler Object (as OpenGL object).
theCtx | currently bound OpenGL context |
|
inline |
Return true for GL_RED and GL_ALPHA formats.
Returns TRUE for point sprite texture.
Reimplemented in OpenGl_PointSprite.
|
inline |
Return if 2D surface is defined top-down (TRUE) or bottom-up (FALSE). Normally set from Image_PixMap::IsTopDown() within texture initialization.
Reimplemented in OpenGl_PointSprite.
|
inline |
Return upper mipmap level index (0 means no mipmaps).
|
inline |
Return number of MSAA samples.
|
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!
|
overridevirtual |
Destroy object - will release GPU memory if any.
Implements OpenGl_Resource.
Reimplemented in OpenGl_PointSprite.
|
inline |
Revision of associated data source.
|
inline |
Return texture sampler.
Setup to interpret the format as Alpha by Shader Manager (should be GL_ALPHA within compatible context or GL_RED otherwise).
|
inline |
Set revision of associated data source.
|
inline |
Set texture sampler.
|
inline |
Set if 2D surface is defined top-down (TRUE) or bottom-up (FALSE).
|
inline |
Return texture dimensions (0 LOD)
|
inline |
|
inline |
Return texture width (0 LOD)
|
inline |
Return texture height (0 LOD)
|
inline |
Return texture depth (0 LOD)
|
inline |
Unbind texture from the unit specified in sampler parameters. Also unbinds Sampler Object if it is allocated.
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.
|
protected |
indicates alpha format
|
protected |
indicates if 2D surface is defined top-down (TRUE) or bottom-up (FALSE)
|
protected |
upper mipmap level index (0 means no mipmaps)
|
protected |
number of MSAA samples
|
protected |
revision of associated data source
|
protected |
texture sampler
|
protected |
texture width x height x depth
|
protected |
internal (sized) texture format