mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-08-14 13:30:48 +03:00
0027853: Visualization, OpenGl_Texture - optimize sequential upload of texture image
Graphic3d_TextureRoot - added methods Revision() and UpdateRevision() for marking updates in texture data source. OpenGl_AspectFace handles Graphic3d_TextureRoot::Revision() changes. OpenGl_Texture::Init() now patches already allocated texture image when possible. Graphic3d_Texture2D - added methods HasMipMaps()/SetMipMaps() for configuring MipMap usage (as alternative to sub-classing).
This commit is contained in:
@@ -14,11 +14,9 @@
|
||||
// Alternatively, this file may be used under the terms of Open CASCADE
|
||||
// commercial license or contractual agreement.
|
||||
|
||||
|
||||
#include <Graphic3d_Texture2D.hxx>
|
||||
|
||||
#include <Standard_OutOfRange.hxx>
|
||||
#include <Standard_Type.hxx>
|
||||
#include <TCollection_AsciiString.hxx>
|
||||
|
||||
IMPLEMENT_STANDARD_RTTIEXT(Graphic3d_Texture2D,Graphic3d_TextureMap)
|
||||
|
||||
@@ -116,3 +114,14 @@ TCollection_AsciiString Graphic3d_Texture2D::TextureName (const Standard_Integer
|
||||
Standard_Integer i = aFileName.SearchFromEnd (".");
|
||||
return aFileName.SubString (4, i - 1);
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : SetImage
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
void Graphic3d_Texture2D::SetImage (const Handle(Image_PixMap)& thePixMap)
|
||||
{
|
||||
myPixMap = thePixMap;
|
||||
myPath = OSD_Path();
|
||||
myName = Graphic3d_NOT_2D_UNKNOWN;
|
||||
}
|
||||
|
@@ -17,48 +17,39 @@
|
||||
#ifndef _Graphic3d_Texture2D_HeaderFile
|
||||
#define _Graphic3d_Texture2D_HeaderFile
|
||||
|
||||
#include <Standard.hxx>
|
||||
#include <Standard_Type.hxx>
|
||||
|
||||
#include <Graphic3d_NameOfTexture2D.hxx>
|
||||
#include <Graphic3d_TextureMap.hxx>
|
||||
#include <Graphic3d_TypeOfTexture.hxx>
|
||||
#include <Image_PixMap.hxx>
|
||||
#include <Standard_Integer.hxx>
|
||||
class Standard_OutOfRange;
|
||||
class TCollection_AsciiString;
|
||||
|
||||
|
||||
class Graphic3d_Texture2D;
|
||||
DEFINE_STANDARD_HANDLE(Graphic3d_Texture2D, Graphic3d_TextureMap)
|
||||
|
||||
//! This abstract class for managing 2D textures
|
||||
class Graphic3d_Texture2D : public Graphic3d_TextureMap
|
||||
{
|
||||
|
||||
DEFINE_STANDARD_RTTIEXT(Graphic3d_Texture2D, Graphic3d_TextureMap)
|
||||
public:
|
||||
|
||||
|
||||
|
||||
//! Returns the name of the predefined textures or NOT_2D_UNKNOWN
|
||||
//! when the name is given as a filename.
|
||||
Standard_EXPORT Graphic3d_NameOfTexture2D Name() const;
|
||||
|
||||
|
||||
//! Returns the number of predefined textures.
|
||||
Standard_EXPORT static Standard_Integer NumberOfTextures();
|
||||
|
||||
|
||||
//! Returns the name of the predefined texture of rank <aRank>
|
||||
Standard_EXPORT static TCollection_AsciiString TextureName (const Standard_Integer theRank);
|
||||
|
||||
public:
|
||||
|
||||
//! Returns the name of the predefined textures or NOT_2D_UNKNOWN
|
||||
//! when the name is given as a filename.
|
||||
Standard_EXPORT Graphic3d_NameOfTexture2D Name() const;
|
||||
|
||||
//! Assign new image to the texture.
|
||||
//! Note that this method does not invalidate already uploaded resources - consider calling ::UpdateRevision() if needed.
|
||||
Standard_EXPORT void SetImage (const Handle(Image_PixMap)& thePixMap);
|
||||
|
||||
DEFINE_STANDARD_RTTIEXT(Graphic3d_Texture2D,Graphic3d_TextureMap)
|
||||
//! Return true if mip-maps should be used.
|
||||
Standard_Boolean HasMipMaps() const { return myType == Graphic3d_TOT_2D_MIPMAP; }
|
||||
|
||||
//! Set if mip-maps should be used (generated if needed).
|
||||
//! Note that this method should be called before loading / using the texture.
|
||||
void SetMipMaps (const Standard_Boolean theToUse) { myType = theToUse ? Graphic3d_TOT_2D_MIPMAP : Graphic3d_TOT_2D; }
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
Standard_EXPORT Graphic3d_Texture2D(const TCollection_AsciiString& theFileName, const Graphic3d_TypeOfTexture theType);
|
||||
|
||||
@@ -66,20 +57,12 @@ protected:
|
||||
|
||||
Standard_EXPORT Graphic3d_Texture2D(const Handle(Image_PixMap)& thePixMap, const Graphic3d_TypeOfTexture theType);
|
||||
|
||||
|
||||
|
||||
private:
|
||||
|
||||
protected:
|
||||
|
||||
Graphic3d_NameOfTexture2D myName;
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
DEFINE_STANDARD_HANDLE(Graphic3d_Texture2D, Graphic3d_TextureMap)
|
||||
|
||||
#endif // _Graphic3d_Texture2D_HeaderFile
|
||||
|
@@ -14,12 +14,10 @@
|
||||
// Alternatively, this file may be used under the terms of Open CASCADE
|
||||
// commercial license or contractual agreement.
|
||||
|
||||
|
||||
#include <Graphic3d_Texture2Dmanual.hxx>
|
||||
|
||||
#include <Graphic3d_TextureParams.hxx>
|
||||
#include <Graphic3d_TypeOfTextureMode.hxx>
|
||||
#include <Standard_Type.hxx>
|
||||
#include <TCollection_AsciiString.hxx>
|
||||
|
||||
IMPLEMENT_STANDARD_RTTIEXT(Graphic3d_Texture2Dmanual,Graphic3d_Texture2D)
|
||||
|
||||
|
@@ -17,56 +17,31 @@
|
||||
#ifndef _Graphic3d_Texture2Dmanual_HeaderFile
|
||||
#define _Graphic3d_Texture2Dmanual_HeaderFile
|
||||
|
||||
#include <Standard.hxx>
|
||||
#include <Standard_Type.hxx>
|
||||
|
||||
#include <Graphic3d_Texture2D.hxx>
|
||||
#include <Graphic3d_NameOfTexture2D.hxx>
|
||||
class TCollection_AsciiString;
|
||||
|
||||
|
||||
class Graphic3d_Texture2Dmanual;
|
||||
DEFINE_STANDARD_HANDLE(Graphic3d_Texture2Dmanual, Graphic3d_Texture2D)
|
||||
|
||||
//! This class defined a manual texture 2D
|
||||
//! facets MUST define texture coordinate
|
||||
//! if you want to see somethings on.
|
||||
class Graphic3d_Texture2Dmanual : public Graphic3d_Texture2D
|
||||
{
|
||||
|
||||
DEFINE_STANDARD_RTTIEXT(Graphic3d_Texture2Dmanual,Graphic3d_Texture2D)
|
||||
public:
|
||||
|
||||
|
||||
//! Creates a texture from a file
|
||||
//! Creates a texture from a file.
|
||||
//! MipMaps levels will be automatically generated if needed.
|
||||
Standard_EXPORT Graphic3d_Texture2Dmanual(const TCollection_AsciiString& theFileName);
|
||||
|
||||
//! Creates a texture from a predefined texture name set.
|
||||
//! MipMaps levels will be automatically generated if needed.
|
||||
Standard_EXPORT Graphic3d_Texture2Dmanual(const Graphic3d_NameOfTexture2D theNOT);
|
||||
|
||||
|
||||
//! Creates a texture from the pixmap.
|
||||
//! MipMaps levels will be automatically generated if needed.
|
||||
Standard_EXPORT Graphic3d_Texture2Dmanual(const Handle(Image_PixMap)& thePixMap);
|
||||
|
||||
|
||||
|
||||
|
||||
DEFINE_STANDARD_RTTIEXT(Graphic3d_Texture2Dmanual,Graphic3d_Texture2D)
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
|
||||
|
||||
private:
|
||||
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
DEFINE_STANDARD_HANDLE(Graphic3d_Texture2Dmanual, Graphic3d_Texture2D)
|
||||
|
||||
#endif // _Graphic3d_Texture2Dmanual_HeaderFile
|
||||
|
@@ -14,21 +14,18 @@
|
||||
// Alternatively, this file may be used under the terms of Open CASCADE
|
||||
// commercial license or contractual agreement.
|
||||
|
||||
#include <Graphic3d_TextureRoot.hxx>
|
||||
|
||||
#include <Graphic3d_GraphicDriver.hxx>
|
||||
#include <Graphic3d_TextureParams.hxx>
|
||||
#include <Graphic3d_TextureRoot.hxx>
|
||||
#include <Image_AlienPixMap.hxx>
|
||||
#include <OSD_Directory.hxx>
|
||||
#include <OSD_Environment.hxx>
|
||||
#include <OSD_File.hxx>
|
||||
#include <OSD_Path.hxx>
|
||||
#include <OSD_Protection.hxx>
|
||||
#include <Standard_Atomic.hxx>
|
||||
#include <Standard_Type.hxx>
|
||||
#include <TCollection_AsciiString.hxx>
|
||||
|
||||
IMPLEMENT_STANDARD_RTTIEXT(Graphic3d_TextureRoot,MMgt_TShared)
|
||||
IMPLEMENT_STANDARD_RTTIEXT(Graphic3d_TextureRoot, Standard_Transient)
|
||||
|
||||
namespace
|
||||
{
|
||||
@@ -91,12 +88,12 @@ TCollection_AsciiString Graphic3d_TextureRoot::TexturesFolder()
|
||||
// =======================================================================
|
||||
Graphic3d_TextureRoot::Graphic3d_TextureRoot (const TCollection_AsciiString& theFileName,
|
||||
const Graphic3d_TypeOfTexture theType)
|
||||
: myParams (new Graphic3d_TextureParams()),
|
||||
myPath (theFileName),
|
||||
myType (theType)
|
||||
: myParams (new Graphic3d_TextureParams()),
|
||||
myPath (theFileName),
|
||||
myRevision (0),
|
||||
myType (theType)
|
||||
{
|
||||
myTexId = TCollection_AsciiString ("Graphic3d_TextureRoot_") //DynamicType()->Name()
|
||||
+ TCollection_AsciiString (Standard_Atomic_Increment (&THE_TEXTURE_COUNTER));
|
||||
generateId();
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
@@ -105,39 +102,31 @@ Graphic3d_TextureRoot::Graphic3d_TextureRoot (const TCollection_AsciiString& the
|
||||
// =======================================================================
|
||||
Graphic3d_TextureRoot::Graphic3d_TextureRoot (const Handle(Image_PixMap)& thePixMap,
|
||||
const Graphic3d_TypeOfTexture theType)
|
||||
: myParams (new Graphic3d_TextureParams()),
|
||||
myPixMap (thePixMap),
|
||||
myType (theType)
|
||||
: myParams (new Graphic3d_TextureParams()),
|
||||
myPixMap (thePixMap),
|
||||
myRevision (0),
|
||||
myType (theType)
|
||||
{
|
||||
myTexId = TCollection_AsciiString ("Graphic3d_TextureRoot_")
|
||||
+ TCollection_AsciiString (Standard_Atomic_Increment (&THE_TEXTURE_COUNTER));
|
||||
generateId();
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : Destroy
|
||||
// function : ~Graphic3d_TextureRoot
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
void Graphic3d_TextureRoot::Destroy() const
|
||||
Graphic3d_TextureRoot::~Graphic3d_TextureRoot()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : GetId
|
||||
// function : generateId
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
const TCollection_AsciiString& Graphic3d_TextureRoot::GetId() const
|
||||
void Graphic3d_TextureRoot::generateId()
|
||||
{
|
||||
return myTexId;
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : GetParams
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
const Handle(Graphic3d_TextureParams)& Graphic3d_TextureRoot::GetParams() const
|
||||
{
|
||||
return myParams;
|
||||
myTexId = TCollection_AsciiString ("Graphic3d_TextureRoot_")
|
||||
+ TCollection_AsciiString (Standard_Atomic_Increment (&THE_TEXTURE_COUNTER));
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
@@ -185,21 +174,3 @@ Standard_Boolean Graphic3d_TextureRoot::IsDone() const
|
||||
OSD_File aTextureFile (myPath);
|
||||
return aTextureFile.Exists();
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : Path
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
const OSD_Path& Graphic3d_TextureRoot::Path() const
|
||||
{
|
||||
return myPath;
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : Type
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
Graphic3d_TypeOfTexture Graphic3d_TextureRoot::Type() const
|
||||
{
|
||||
return myType;
|
||||
}
|
||||
|
@@ -17,48 +17,41 @@
|
||||
#ifndef _Graphic3d_TextureRoot_HeaderFile
|
||||
#define _Graphic3d_TextureRoot_HeaderFile
|
||||
|
||||
#include <Standard.hxx>
|
||||
#include <Standard_Type.hxx>
|
||||
|
||||
#include <TCollection_AsciiString.hxx>
|
||||
#include <Image_PixMap.hxx>
|
||||
#include <OSD_Path.hxx>
|
||||
#include <Graphic3d_TypeOfTexture.hxx>
|
||||
#include <MMgt_TShared.hxx>
|
||||
#include <Standard_Boolean.hxx>
|
||||
#include <Standard.hxx>
|
||||
#include <Standard_Transient.hxx>
|
||||
#include <Standard_Type.hxx>
|
||||
#include <TCollection_AsciiString.hxx>
|
||||
|
||||
class Graphic3d_TextureParams;
|
||||
class TCollection_AsciiString;
|
||||
class OSD_Path;
|
||||
|
||||
|
||||
class Graphic3d_TextureRoot;
|
||||
DEFINE_STANDARD_HANDLE(Graphic3d_TextureRoot, MMgt_TShared)
|
||||
|
||||
//! This is the texture root class enable the dialog with the GraphicDriver allows the loading of texture.
|
||||
class Graphic3d_TextureRoot : public MMgt_TShared
|
||||
class Graphic3d_TextureRoot : public Standard_Transient
|
||||
{
|
||||
DEFINE_STANDARD_RTTIEXT(Graphic3d_TextureRoot, Standard_Transient)
|
||||
public:
|
||||
|
||||
//! The path to textures determined from CSF_MDTVTexturesDirectory or CASROOT environment variables.
|
||||
//! @return the root folder with default textures.
|
||||
Standard_EXPORT static TCollection_AsciiString TexturesFolder();
|
||||
|
||||
public:
|
||||
|
||||
|
||||
Standard_EXPORT void Destroy() const;
|
||||
~Graphic3d_TextureRoot()
|
||||
{
|
||||
Destroy();
|
||||
}
|
||||
|
||||
//! Destructor.
|
||||
Standard_EXPORT ~Graphic3d_TextureRoot();
|
||||
|
||||
//! Checks if a texture class is valid or not.
|
||||
//! @return true if the construction of the class is correct
|
||||
Standard_EXPORT virtual Standard_Boolean IsDone() const;
|
||||
|
||||
|
||||
//! Returns the full path of the defined texture.
|
||||
//! It could be empty path if GetImage() is overridden to load image not from file.
|
||||
Standard_EXPORT const OSD_Path& Path() const;
|
||||
|
||||
const OSD_Path& Path() const { return myPath; }
|
||||
|
||||
//! @return the texture type.
|
||||
Standard_EXPORT Graphic3d_TypeOfTexture Type() const;
|
||||
|
||||
Graphic3d_TypeOfTexture Type() const { return myType; }
|
||||
|
||||
//! This ID will be used to manage resource in graphic driver.
|
||||
//!
|
||||
@@ -74,7 +67,15 @@ public:
|
||||
//! for each instance of Graphic3d_AspectFillArea3d where texture will be used.
|
||||
//!
|
||||
//! @return texture identifier.
|
||||
Standard_EXPORT const TCollection_AsciiString& GetId() const;
|
||||
const TCollection_AsciiString& GetId() const { return myTexId; }
|
||||
|
||||
//! Return image revision.
|
||||
Standard_Size Revision() const { return myRevision; }
|
||||
|
||||
//! Update image revision.
|
||||
//! Can be used for signalling changes in the texture source (e.g. file update, pixmap update)
|
||||
//! without re-creating texture source itself (e.g. preserving the unique id).
|
||||
void UpdateRevision() { ++myRevision; }
|
||||
|
||||
//! This method will be called by graphic driver each time when texture resource should be created.
|
||||
//! Default constructors allow defining the texture source as path to texture image or directly as pixmap.
|
||||
@@ -86,20 +87,10 @@ public:
|
||||
Standard_EXPORT virtual Handle(Image_PixMap) GetImage() const;
|
||||
|
||||
//! @return low-level texture parameters
|
||||
Standard_EXPORT const Handle(Graphic3d_TextureParams)& GetParams() const;
|
||||
|
||||
|
||||
//! The path to textures determined from CSF_MDTVTexturesDirectory or CASROOT environment variables.
|
||||
//! @return the root folder with default textures.
|
||||
Standard_EXPORT static TCollection_AsciiString TexturesFolder();
|
||||
|
||||
|
||||
|
||||
DEFINE_STANDARD_RTTIEXT(Graphic3d_TextureRoot,MMgt_TShared)
|
||||
const Handle(Graphic3d_TextureParams)& GetParams() const { return myParams; }
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
//! Creates a texture from a file
|
||||
//! Warning: Note that if <FileName> is NULL the texture must be realized
|
||||
//! using LoadTexture(image) method.
|
||||
@@ -110,24 +101,20 @@ protected:
|
||||
//! to be in Bottom-Up order (see Image_PixMap::IsTopDown()).
|
||||
Standard_EXPORT Graphic3d_TextureRoot(const Handle(Image_PixMap)& thePixmap, const Graphic3d_TypeOfTexture theType);
|
||||
|
||||
Handle(Graphic3d_TextureParams) myParams;
|
||||
TCollection_AsciiString myTexId;
|
||||
Handle(Image_PixMap) myPixMap;
|
||||
OSD_Path myPath;
|
||||
//! Unconditionally generate new texture id.
|
||||
Standard_EXPORT void generateId();
|
||||
|
||||
protected:
|
||||
|
||||
private:
|
||||
|
||||
|
||||
Graphic3d_TypeOfTexture myType;
|
||||
|
||||
Handle(Graphic3d_TextureParams) myParams; //!< associated texture parameters
|
||||
TCollection_AsciiString myTexId; //!< unique identifier of this resource (for sharing)
|
||||
Handle(Image_PixMap) myPixMap; //!< image pixmap - as one of the ways for defining the texture source
|
||||
OSD_Path myPath; //!< image file path - as one of the ways for defining the texture source
|
||||
Standard_Size myRevision; //!< image revision - for signalling changes in the texture source (e.g. file update, pixmap update)
|
||||
Graphic3d_TypeOfTexture myType; //!< texture type
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
DEFINE_STANDARD_HANDLE(Graphic3d_TextureRoot, Standard_Transient)
|
||||
|
||||
#endif // _Graphic3d_TextureRoot_HeaderFile
|
||||
|
Reference in New Issue
Block a user