1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-04-09 18:50:54 +03:00

0032862: Visualization, Graphic3d_TextureMap - add 3D texture definition

Image_PixMap has been extended to support definition of 3D bitmap (as an array of 2D slices).

Graphic3d_TypeOfTexture enumeration values have been renamed to include full enum prefix.
Added Graphic3d_TypeOfTexture_3D redirecting to GL_TEXTURE_3D.
OpenGl_Texture::Init() has been extended to allow initialization of 3D texture.

Graphic3d_Texture2Dmanual merged into Graphic3d_Texture2D and marked as deprecated alias.
Graphic3d_TOT_2D_MIPMAP has been deprecated in favor of dedicated Graphic3d_TextureRoot::SetMipMaps().

Added Graphic3d_Texture3D class.
vtexture - added argument -3d for uploading 3D texture.
This commit is contained in:
kgv 2022-03-02 15:21:22 +03:00 committed by smoskvin
parent a9e5f65041
commit 633084b809
47 changed files with 1327 additions and 663 deletions

View File

@ -26,9 +26,7 @@
#include <BRepBuilderAPI_MakeWire.hxx> #include <BRepBuilderAPI_MakeWire.hxx>
#include <BRepBuilderAPI_MakeFace.hxx> #include <BRepBuilderAPI_MakeFace.hxx>
#include <gp_Pnt.hxx> #include <gp_Pnt.hxx>
#include <Graphic3d_Texture1D.hxx> #include <Graphic3d_Texture2D.hxx>
#include <Graphic3d_Texture1Dsegment.hxx>
#include <Graphic3d_Texture2Dmanual.hxx>
#include <Image_AlienPixMap.hxx> #include <Image_AlienPixMap.hxx>
#include <Prs3d_ShadingAspect.hxx> #include <Prs3d_ShadingAspect.hxx>
#include <TopoDS_Edge.hxx> #include <TopoDS_Edge.hxx>
@ -81,7 +79,7 @@ void Sample2D_Image::SetContext (const Handle(AIS_InteractiveContext)& theContex
this->Set(TopoDS_Shape(myFace)); this->Set(TopoDS_Shape(myFace));
myDrawer->SetShadingAspect(new Prs3d_ShadingAspect()); myDrawer->SetShadingAspect(new Prs3d_ShadingAspect());
Handle(Graphic3d_Texture2Dmanual) aTexture = new Graphic3d_Texture2Dmanual(myFilename); Handle(Graphic3d_Texture2D) aTexture = new Graphic3d_Texture2D (myFilename);
aTexture->DisableModulate(); aTexture->DisableModulate();
myDrawer->ShadingAspect()->Aspect()->SetTextureMap (aTexture); myDrawer->ShadingAspect()->Aspect()->SetTextureMap (aTexture);
myDrawer->ShadingAspect()->Aspect()->SetTextureMapOn(); myDrawer->ShadingAspect()->Aspect()->SetTextureMapOn();

View File

@ -22,7 +22,7 @@
#include <Graphic3d_AspectFillArea3d.hxx> #include <Graphic3d_AspectFillArea3d.hxx>
#include <Graphic3d_Group.hxx> #include <Graphic3d_Group.hxx>
#include <Graphic3d_StructureManager.hxx> #include <Graphic3d_StructureManager.hxx>
#include <Graphic3d_Texture2Dmanual.hxx> #include <Graphic3d_Texture2D.hxx>
#include <Message.hxx> #include <Message.hxx>
#include <Message_Messenger.hxx> #include <Message_Messenger.hxx>
#include <Prs3d_Drawer.hxx> #include <Prs3d_Drawer.hxx>
@ -278,17 +278,17 @@ void AIS_TexturedShape::updateAttributes (const Handle(Prs3d_Presentation)& theP
TCollection_AsciiString aTextureDesc; TCollection_AsciiString aTextureDesc;
if (!myTexturePixMap.IsNull()) if (!myTexturePixMap.IsNull())
{ {
myTexture = new Graphic3d_Texture2Dmanual (myTexturePixMap); myTexture = new Graphic3d_Texture2D (myTexturePixMap);
aTextureDesc = " (custom image)"; aTextureDesc = " (custom image)";
} }
else if (myPredefTexture != Graphic3d_NOT_2D_UNKNOWN) else if (myPredefTexture != Graphic3d_NOT_2D_UNKNOWN)
{ {
myTexture = new Graphic3d_Texture2Dmanual (myPredefTexture); myTexture = new Graphic3d_Texture2D (myPredefTexture);
aTextureDesc = TCollection_AsciiString(" (predefined texture ") + myTexture->GetId() + ")"; aTextureDesc = TCollection_AsciiString(" (predefined texture ") + myTexture->GetId() + ")";
} }
else else
{ {
myTexture = new Graphic3d_Texture2Dmanual (myTextureFile.ToCString()); myTexture = new Graphic3d_Texture2D (myTextureFile.ToCString());
aTextureDesc = TCollection_AsciiString(" (") + myTextureFile + ")"; aTextureDesc = TCollection_AsciiString(" (") + myTextureFile + ")";
} }

View File

@ -26,7 +26,7 @@
#include <PrsMgr_PresentationManager.hxx> #include <PrsMgr_PresentationManager.hxx>
class Graphic3d_AspectFillArea3d; class Graphic3d_AspectFillArea3d;
class Graphic3d_Texture2Dmanual; class Graphic3d_Texture2D;
//! This class allows to map textures on shapes. //! This class allows to map textures on shapes.
//! Presentations modes AIS_WireFrame (0) and AIS_Shaded (1) behave in the same manner as in AIS_Shape, //! Presentations modes AIS_WireFrame (0) and AIS_Shaded (1) behave in the same manner as in AIS_Shape,
@ -184,7 +184,7 @@ protected: //! @name overridden methods
protected: //! @name presentation fields protected: //! @name presentation fields
Handle(Graphic3d_Texture2Dmanual) myTexture; Handle(Graphic3d_Texture2D) myTexture;
Handle(Graphic3d_AspectFillArea3d) myAspect; Handle(Graphic3d_AspectFillArea3d) myAspect;
protected: //! @name texture source fields protected: //! @name texture source fields

View File

@ -23,14 +23,14 @@
#include <SelectMgr_EntityOwner.hxx> #include <SelectMgr_EntityOwner.hxx>
//! Texture holder. //! Texture holder.
class AIS_XRTrackedDevice::XRTexture : public Graphic3d_Texture2Dmanual class AIS_XRTrackedDevice::XRTexture : public Graphic3d_Texture2D
{ {
public: public:
//! Constructor. //! Constructor.
XRTexture (const Handle(Image_Texture)& theImageSource, XRTexture (const Handle(Image_Texture)& theImageSource,
const Graphic3d_TextureUnit theUnit = Graphic3d_TextureUnit_BaseColor) const Graphic3d_TextureUnit theUnit = Graphic3d_TextureUnit_BaseColor)
: Graphic3d_Texture2Dmanual (""), myImageSource (theImageSource) : Graphic3d_Texture2D (""), myImageSource (theImageSource)
{ {
if (!theImageSource->TextureId().IsEmpty()) if (!theImageSource->TextureId().IsEmpty())
{ {

View File

@ -195,7 +195,7 @@ Standard_Boolean D3DHost_FrameBuffer::InitD3dInterop (const Handle(OpenGl_Contex
const OpenGl_TextureFormat aDepthFormat = OpenGl_TextureFormat::FindSizedFormat (theCtx, myDepthFormat); const OpenGl_TextureFormat aDepthFormat = OpenGl_TextureFormat::FindSizedFormat (theCtx, myDepthFormat);
if (aDepthFormat.IsValid() if (aDepthFormat.IsValid()
&& !myDepthStencilTexture->Init (theCtx, aDepthFormat, Graphic3d_Vec2i (aSizeX, aSizeY), Graphic3d_TOT_2D)) && !myDepthStencilTexture->Init (theCtx, aDepthFormat, Graphic3d_Vec2i (aSizeX, aSizeY), Graphic3d_TypeOfTexture_2D))
{ {
Release (theCtx.get()); Release (theCtx.get());
theCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_ERROR, 0, GL_DEBUG_SEVERITY_HIGH, theCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_ERROR, 0, GL_DEBUG_SEVERITY_HIGH,

View File

@ -154,10 +154,11 @@ Graphic3d_Texture1Dsegment.cxx
Graphic3d_Texture1Dsegment.hxx Graphic3d_Texture1Dsegment.hxx
Graphic3d_Texture2D.cxx Graphic3d_Texture2D.cxx
Graphic3d_Texture2D.hxx Graphic3d_Texture2D.hxx
Graphic3d_Texture2Dmanual.cxx
Graphic3d_Texture2Dmanual.hxx Graphic3d_Texture2Dmanual.hxx
Graphic3d_Texture2Dplane.cxx Graphic3d_Texture2Dplane.cxx
Graphic3d_Texture2Dplane.hxx Graphic3d_Texture2Dplane.hxx
Graphic3d_Texture3D.cxx
Graphic3d_Texture3D.hxx
Graphic3d_TextureEnv.cxx Graphic3d_TextureEnv.cxx
Graphic3d_TextureEnv.hxx Graphic3d_TextureEnv.hxx
Graphic3d_TextureMap.cxx Graphic3d_TextureMap.cxx

View File

@ -15,3 +15,40 @@
#include <Graphic3d_CubeMap.hxx> #include <Graphic3d_CubeMap.hxx>
IMPLEMENT_STANDARD_RTTIEXT(Graphic3d_CubeMap, Graphic3d_TextureMap) IMPLEMENT_STANDARD_RTTIEXT(Graphic3d_CubeMap, Graphic3d_TextureMap)
// =======================================================================
// function : Graphic3d_CubeMap
// purpose :
// =======================================================================
Graphic3d_CubeMap::Graphic3d_CubeMap (const TCollection_AsciiString& theFileName,
Standard_Boolean theToGenerateMipmaps)
: Graphic3d_TextureMap (theFileName, Graphic3d_TypeOfTexture_CUBEMAP),
myCurrentSide (Graphic3d_CMS_POS_X),
myEndIsReached (false),
myZIsInverted (false)
{
myHasMipmaps = theToGenerateMipmaps;
}
// =======================================================================
// function : Graphic3d_CubeMap
// purpose :
// =======================================================================
Graphic3d_CubeMap::Graphic3d_CubeMap (const Handle(Image_PixMap)& thePixmap,
Standard_Boolean theToGenerateMipmaps)
: Graphic3d_TextureMap (thePixmap, Graphic3d_TypeOfTexture_CUBEMAP),
myCurrentSide (Graphic3d_CMS_POS_X),
myEndIsReached (false),
myZIsInverted (false)
{
myHasMipmaps = theToGenerateMipmaps;
}
// =======================================================================
// function : ~Graphic3d_CubeMap
// purpose :
// =======================================================================
Graphic3d_CubeMap::~Graphic3d_CubeMap()
{
//
}

View File

@ -26,24 +26,12 @@ class Graphic3d_CubeMap : public Graphic3d_TextureMap
public: public:
//! Constructor defining loading cubemap from file. //! Constructor defining loading cubemap from file.
Graphic3d_CubeMap (const TCollection_AsciiString& theFileName, Standard_EXPORT Graphic3d_CubeMap (const TCollection_AsciiString& theFileName,
Standard_Boolean theToGenerateMipmaps = Standard_False) : Standard_Boolean theToGenerateMipmaps = Standard_False);
Graphic3d_TextureMap (theFileName, Graphic3d_TOT_CUBEMAP),
myCurrentSide (Graphic3d_CMS_POS_X),
myEndIsReached (false),
myZIsInverted (false),
myHasMipmaps (theToGenerateMipmaps)
{}
//! Constructor defining direct cubemap initialization from PixMap. //! Constructor defining direct cubemap initialization from PixMap.
Graphic3d_CubeMap (const Handle(Image_PixMap)& thePixmap = Handle(Image_PixMap)(), Standard_EXPORT Graphic3d_CubeMap (const Handle(Image_PixMap)& thePixmap = Handle(Image_PixMap)(),
Standard_Boolean theToGenerateMipmaps = Standard_False) : Standard_Boolean theToGenerateMipmaps = Standard_False);
Graphic3d_TextureMap (thePixmap, Graphic3d_TOT_CUBEMAP),
myCurrentSide (Graphic3d_CMS_POS_X),
myEndIsReached (false),
myZIsInverted (false),
myHasMipmaps (theToGenerateMipmaps)
{}
//! Returns whether the iterator has reached the end (true if it hasn't). //! Returns whether the iterator has reached the end (true if it hasn't).
Standard_Boolean More() const { return !myEndIsReached; } Standard_Boolean More() const { return !myEndIsReached; }
@ -100,14 +88,13 @@ public:
} }
//! Empty destructor. //! Empty destructor.
~Graphic3d_CubeMap() {} Standard_EXPORT virtual ~Graphic3d_CubeMap();
protected: protected:
Graphic3d_CubeMapSide myCurrentSide; //!< Iterator state Graphic3d_CubeMapSide myCurrentSide; //!< Iterator state
Standard_Boolean myEndIsReached; //!< Indicates whether end of iteration has been reached or hasn't Standard_Boolean myEndIsReached; //!< Indicates whether end of iteration has been reached or hasn't
Standard_Boolean myZIsInverted; //!< Indicates whether Z axis is inverted that allows to synchronize vertical flip of cubemap Standard_Boolean myZIsInverted; //!< Indicates whether Z axis is inverted that allows to synchronize vertical flip of cubemap
Standard_Boolean myHasMipmaps; //!< Indicates whether mipmaps of cubemap will be generated or not
}; };

View File

@ -42,7 +42,7 @@ IMPLEMENT_STANDARD_RTTIEXT(Graphic3d_MediaTexture, Graphic3d_Texture2D)
// ================================================================ // ================================================================
Graphic3d_MediaTexture::Graphic3d_MediaTexture (const Handle(Standard_HMutex)& theMutex, Graphic3d_MediaTexture::Graphic3d_MediaTexture (const Handle(Standard_HMutex)& theMutex,
Standard_Integer thePlane) Standard_Integer thePlane)
: Graphic3d_Texture2D ("", Graphic3d_TOT_2D), : Graphic3d_Texture2D ("", Graphic3d_TypeOfTexture_2D),
myMutex (theMutex), myMutex (theMutex),
myPlane (thePlane) myPlane (thePlane)
{ {

View File

@ -14,10 +14,8 @@
// Alternatively, this file may be used under the terms of Open CASCADE // Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement. // commercial license or contractual agreement.
#include <Graphic3d_Texture1Dmanual.hxx> #include <Graphic3d_Texture1Dmanual.hxx>
#include <Graphic3d_TypeOfTextureMode.hxx>
#include <Standard_Type.hxx>
#include <TCollection_AsciiString.hxx> #include <TCollection_AsciiString.hxx>
IMPLEMENT_STANDARD_RTTIEXT(Graphic3d_Texture1Dmanual,Graphic3d_Texture1D) IMPLEMENT_STANDARD_RTTIEXT(Graphic3d_Texture1Dmanual,Graphic3d_Texture1D)
@ -27,7 +25,7 @@ IMPLEMENT_STANDARD_RTTIEXT(Graphic3d_Texture1Dmanual,Graphic3d_Texture1D)
// purpose : // purpose :
// ======================================================================= // =======================================================================
Graphic3d_Texture1Dmanual::Graphic3d_Texture1Dmanual (const TCollection_AsciiString& theFileName) Graphic3d_Texture1Dmanual::Graphic3d_Texture1Dmanual (const TCollection_AsciiString& theFileName)
: Graphic3d_Texture1D (theFileName, Graphic3d_TOT_1D) : Graphic3d_Texture1D (theFileName, Graphic3d_TypeOfTexture_1D)
{ {
// //
} }
@ -37,7 +35,7 @@ Graphic3d_Texture1Dmanual::Graphic3d_Texture1Dmanual (const TCollection_AsciiStr
// purpose : // purpose :
// ======================================================================= // =======================================================================
Graphic3d_Texture1Dmanual::Graphic3d_Texture1Dmanual (const Graphic3d_NameOfTexture1D theNOT) Graphic3d_Texture1Dmanual::Graphic3d_Texture1Dmanual (const Graphic3d_NameOfTexture1D theNOT)
: Graphic3d_Texture1D (theNOT, Graphic3d_TOT_1D) : Graphic3d_Texture1D (theNOT, Graphic3d_TypeOfTexture_1D)
{ {
// //
} }
@ -47,7 +45,7 @@ Graphic3d_Texture1Dmanual::Graphic3d_Texture1Dmanual (const Graphic3d_NameOfText
// purpose : // purpose :
// ======================================================================= // =======================================================================
Graphic3d_Texture1Dmanual::Graphic3d_Texture1Dmanual (const Handle(Image_PixMap)& thePixMap) Graphic3d_Texture1Dmanual::Graphic3d_Texture1Dmanual (const Handle(Image_PixMap)& thePixMap)
: Graphic3d_Texture1D (thePixMap, Graphic3d_TOT_1D) : Graphic3d_Texture1D (thePixMap, Graphic3d_TypeOfTexture_1D)
{ {
// //
} }

View File

@ -17,25 +17,18 @@
#ifndef _Graphic3d_Texture1Dmanual_HeaderFile #ifndef _Graphic3d_Texture1Dmanual_HeaderFile
#define _Graphic3d_Texture1Dmanual_HeaderFile #define _Graphic3d_Texture1Dmanual_HeaderFile
#include <Standard.hxx>
#include <Standard_Type.hxx>
#include <Graphic3d_Texture1D.hxx> #include <Graphic3d_Texture1D.hxx>
#include <Graphic3d_NameOfTexture1D.hxx> #include <Graphic3d_NameOfTexture1D.hxx>
class TCollection_AsciiString;
class Graphic3d_Texture1Dmanual;
DEFINE_STANDARD_HANDLE(Graphic3d_Texture1Dmanual, Graphic3d_Texture1D) DEFINE_STANDARD_HANDLE(Graphic3d_Texture1Dmanual, Graphic3d_Texture1D)
//! This class provides the implementation of a manual 1D texture. //! This class provides the implementation of a manual 1D texture.
//! you MUST provides texture coordinates on your facets if you want to see your texture. //! you MUST provide texture coordinates on your facets if you want to see your texture.
class Graphic3d_Texture1Dmanual : public Graphic3d_Texture1D class Graphic3d_Texture1Dmanual : public Graphic3d_Texture1D
{ {
DEFINE_STANDARD_RTTIEXT(Graphic3d_Texture1Dmanual, Graphic3d_Texture1D)
public: public:
//! Creates a texture from the file FileName. //! Creates a texture from the file FileName.
Standard_EXPORT Graphic3d_Texture1Dmanual(const TCollection_AsciiString& theFileName); Standard_EXPORT Graphic3d_Texture1Dmanual(const TCollection_AsciiString& theFileName);
@ -45,27 +38,6 @@ public:
//! Creates a texture from the pixmap. //! Creates a texture from the pixmap.
Standard_EXPORT Graphic3d_Texture1Dmanual(const Handle(Image_PixMap)& thePixMap); Standard_EXPORT Graphic3d_Texture1Dmanual(const Handle(Image_PixMap)& thePixMap);
DEFINE_STANDARD_RTTIEXT(Graphic3d_Texture1Dmanual,Graphic3d_Texture1D)
protected:
private:
}; };
#endif // _Graphic3d_Texture1Dmanual_HeaderFile #endif // _Graphic3d_Texture1Dmanual_HeaderFile

View File

@ -28,7 +28,7 @@ IMPLEMENT_STANDARD_RTTIEXT(Graphic3d_Texture1Dsegment,Graphic3d_Texture1D)
// purpose : // purpose :
// ======================================================================= // =======================================================================
Graphic3d_Texture1Dsegment::Graphic3d_Texture1Dsegment (const TCollection_AsciiString& theFileName) Graphic3d_Texture1Dsegment::Graphic3d_Texture1Dsegment (const TCollection_AsciiString& theFileName)
: Graphic3d_Texture1D (theFileName, Graphic3d_TOT_1D), : Graphic3d_Texture1D (theFileName, Graphic3d_TypeOfTexture_1D),
myX1 (0.0f), myX1 (0.0f),
myY1 (0.0f), myY1 (0.0f),
myZ1 (0.0f), myZ1 (0.0f),
@ -47,7 +47,7 @@ Graphic3d_Texture1Dsegment::Graphic3d_Texture1Dsegment (const TCollection_AsciiS
// purpose : // purpose :
// ======================================================================= // =======================================================================
Graphic3d_Texture1Dsegment::Graphic3d_Texture1Dsegment (const Graphic3d_NameOfTexture1D theNOT) Graphic3d_Texture1Dsegment::Graphic3d_Texture1Dsegment (const Graphic3d_NameOfTexture1D theNOT)
: Graphic3d_Texture1D (theNOT, Graphic3d_TOT_1D), : Graphic3d_Texture1D (theNOT, Graphic3d_TypeOfTexture_1D),
myX1 (0.0f), myX1 (0.0f),
myY1 (0.0f), myY1 (0.0f),
myZ1 (0.0f), myZ1 (0.0f),
@ -66,7 +66,7 @@ Graphic3d_Texture1Dsegment::Graphic3d_Texture1Dsegment (const Graphic3d_NameOfTe
// purpose : // purpose :
// ======================================================================= // =======================================================================
Graphic3d_Texture1Dsegment::Graphic3d_Texture1Dsegment (const Handle(Image_PixMap)& thePixMap) Graphic3d_Texture1Dsegment::Graphic3d_Texture1Dsegment (const Handle(Image_PixMap)& thePixMap)
: Graphic3d_Texture1D (thePixMap, Graphic3d_TOT_1D), : Graphic3d_Texture1D (thePixMap, Graphic3d_TypeOfTexture_1D),
myX1 (0.0f), myX1 (0.0f),
myY1 (0.0f), myY1 (0.0f),
myZ1 (0.0f), myZ1 (0.0f),

View File

@ -16,6 +16,7 @@
#include <Graphic3d_Texture2D.hxx> #include <Graphic3d_Texture2D.hxx>
#include <Graphic3d_TextureParams.hxx>
#include <Standard_OutOfRange.hxx> #include <Standard_OutOfRange.hxx>
IMPLEMENT_STANDARD_RTTIEXT(Graphic3d_Texture2D,Graphic3d_TextureMap) IMPLEMENT_STANDARD_RTTIEXT(Graphic3d_Texture2D,Graphic3d_TextureMap)
@ -46,6 +47,20 @@ static const char *NameOfTexture2d_to_FileName[] =
"2d_chess.rgba" "2d_chess.rgba"
}; };
// =======================================================================
// function : Graphic3d_Texture2D
// purpose :
// =======================================================================
Graphic3d_Texture2D::Graphic3d_Texture2D (const TCollection_AsciiString& theFileName)
: Graphic3d_TextureMap (theFileName, Graphic3d_TypeOfTexture_2D),
myName (Graphic3d_NOT_2D_UNKNOWN)
{
myHasMipmaps = true;
myParams->SetModulate (true);
myParams->SetRepeat (true);
myParams->SetFilter (Graphic3d_TOTF_TRILINEAR);
}
// ======================================================================= // =======================================================================
// function : Graphic3d_Texture2D // function : Graphic3d_Texture2D
// purpose : // purpose :
@ -55,6 +70,25 @@ Graphic3d_Texture2D::Graphic3d_Texture2D (const TCollection_AsciiString& theFile
: Graphic3d_TextureMap (theFileName, theType), : Graphic3d_TextureMap (theFileName, theType),
myName (Graphic3d_NOT_2D_UNKNOWN) myName (Graphic3d_NOT_2D_UNKNOWN)
{ {
//
}
// =======================================================================
// function : Graphic3d_Texture2D
// purpose :
// =======================================================================
Graphic3d_Texture2D::Graphic3d_Texture2D (const Graphic3d_NameOfTexture2D theNOT)
: Graphic3d_TextureMap (NameOfTexture2d_to_FileName[theNOT], Graphic3d_TypeOfTexture_2D),
myName (theNOT)
{
myPath.SetTrek (Graphic3d_TextureRoot::TexturesFolder());
myTexId = TCollection_AsciiString ("Graphic3d_Texture2D_")
+ NameOfTexture2d_to_FileName[theNOT];
myHasMipmaps = true;
myParams->SetModulate (true);
myParams->SetRepeat (true);
myParams->SetFilter (Graphic3d_TOTF_TRILINEAR);
} }
// ======================================================================= // =======================================================================
@ -71,6 +105,20 @@ Graphic3d_Texture2D::Graphic3d_Texture2D (const Graphic3d_NameOfTexture2D theNOT
+ NameOfTexture2d_to_FileName[theNOT]; + NameOfTexture2d_to_FileName[theNOT];
} }
// =======================================================================
// function : Graphic3d_Texture2D
// purpose :
// =======================================================================
Graphic3d_Texture2D::Graphic3d_Texture2D (const Handle(Image_PixMap)& thePixMap)
: Graphic3d_TextureMap (thePixMap, Graphic3d_TypeOfTexture_2D),
myName (Graphic3d_NOT_2D_UNKNOWN)
{
myHasMipmaps = true;
myParams->SetModulate (true);
myParams->SetRepeat (true);
myParams->SetFilter (Graphic3d_TOTF_TRILINEAR);
}
// ======================================================================= // =======================================================================
// function : Graphic3d_Texture2D // function : Graphic3d_Texture2D
// purpose : // purpose :
@ -80,6 +128,7 @@ Graphic3d_Texture2D::Graphic3d_Texture2D (const Handle(Image_PixMap)& thePixM
: Graphic3d_TextureMap (thePixMap, theType), : Graphic3d_TextureMap (thePixMap, theType),
myName (Graphic3d_NOT_2D_UNKNOWN) myName (Graphic3d_NOT_2D_UNKNOWN)
{ {
//
} }
// ======================================================================= // =======================================================================

View File

@ -34,6 +34,18 @@ public:
public: public:
//! Creates a texture from a file.
//! MipMaps levels will be automatically generated if needed.
Standard_EXPORT Graphic3d_Texture2D (const TCollection_AsciiString& theFileName);
//! Creates a texture from a predefined texture name set.
//! MipMaps levels will be automatically generated if needed.
Standard_EXPORT Graphic3d_Texture2D (const Graphic3d_NameOfTexture2D theNOT);
//! Creates a texture from the pixmap.
//! MipMaps levels will be automatically generated if needed.
Standard_EXPORT Graphic3d_Texture2D (const Handle(Image_PixMap)& thePixMap);
//! Returns the name of the predefined textures or NOT_2D_UNKNOWN //! Returns the name of the predefined textures or NOT_2D_UNKNOWN
//! when the name is given as a filename. //! when the name is given as a filename.
Standard_EXPORT Graphic3d_NameOfTexture2D Name() const; Standard_EXPORT Graphic3d_NameOfTexture2D Name() const;
@ -42,13 +54,6 @@ public:
//! Note that this method does not invalidate already uploaded resources - consider calling ::UpdateRevision() if needed. //! Note that this method does not invalidate already uploaded resources - consider calling ::UpdateRevision() if needed.
Standard_EXPORT void SetImage (const Handle(Image_PixMap)& thePixMap); Standard_EXPORT void SetImage (const Handle(Image_PixMap)& thePixMap);
//! 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: protected:
Standard_EXPORT Graphic3d_Texture2D(const TCollection_AsciiString& theFileName, const Graphic3d_TypeOfTexture theType); Standard_EXPORT Graphic3d_Texture2D(const TCollection_AsciiString& theFileName, const Graphic3d_TypeOfTexture theType);

View File

@ -1,58 +0,0 @@
// Created on: 1997-07-28
// Created by: Pierre CHALAMET
// Copyright (c) 1997-1999 Matra Datavision
// Copyright (c) 1999-2014 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// 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>
IMPLEMENT_STANDARD_RTTIEXT(Graphic3d_Texture2Dmanual,Graphic3d_Texture2D)
// =======================================================================
// function : Graphic3d_Texture2Dmanual
// purpose :
// =======================================================================
Graphic3d_Texture2Dmanual::Graphic3d_Texture2Dmanual (const TCollection_AsciiString& theFileName)
: Graphic3d_Texture2D (theFileName, Graphic3d_TOT_2D_MIPMAP)
{
myParams->SetModulate (Standard_True);
myParams->SetRepeat (Standard_True);
myParams->SetFilter (Graphic3d_TOTF_TRILINEAR);
}
// =======================================================================
// function : Graphic3d_Texture2Dmanual
// purpose :
// =======================================================================
Graphic3d_Texture2Dmanual::Graphic3d_Texture2Dmanual (const Graphic3d_NameOfTexture2D theNOT)
: Graphic3d_Texture2D (theNOT, Graphic3d_TOT_2D_MIPMAP)
{
myParams->SetModulate (Standard_True);
myParams->SetRepeat (Standard_True);
myParams->SetFilter (Graphic3d_TOTF_TRILINEAR);
}
// =======================================================================
// function : Graphic3d_Texture2Dmanual
// purpose :
// =======================================================================
Graphic3d_Texture2Dmanual::Graphic3d_Texture2Dmanual (const Handle(Image_PixMap)& thePixMap)
: Graphic3d_Texture2D (thePixMap, Graphic3d_TOT_2D_MIPMAP)
{
myParams->SetModulate (Standard_True);
myParams->SetRepeat (Standard_True);
myParams->SetFilter (Graphic3d_TOTF_TRILINEAR);
}

View File

@ -20,28 +20,7 @@
#include <Graphic3d_Texture2D.hxx> #include <Graphic3d_Texture2D.hxx>
#include <Graphic3d_NameOfTexture2D.hxx> #include <Graphic3d_NameOfTexture2D.hxx>
//! This class defined a manual texture 2D Standard_DEPRECATED ("Deprecated alias to Graphic3d_Texture2D")
//! facets MUST define texture coordinate typedef Graphic3d_Texture2D Graphic3d_Texture2Dmanual;
//! 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.
//! 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_HANDLE(Graphic3d_Texture2Dmanual, Graphic3d_Texture2D)
#endif // _Graphic3d_Texture2Dmanual_HeaderFile #endif // _Graphic3d_Texture2Dmanual_HeaderFile

View File

@ -28,11 +28,8 @@ IMPLEMENT_STANDARD_RTTIEXT(Graphic3d_Texture2Dplane,Graphic3d_Texture2D)
// purpose : // purpose :
// ======================================================================= // =======================================================================
Graphic3d_Texture2Dplane::Graphic3d_Texture2Dplane (const TCollection_AsciiString& theFileName) Graphic3d_Texture2Dplane::Graphic3d_Texture2Dplane (const TCollection_AsciiString& theFileName)
: Graphic3d_Texture2D (theFileName, Graphic3d_TOT_2D_MIPMAP) : Graphic3d_Texture2D (theFileName)
{ {
myParams->SetModulate (Standard_True);
myParams->SetRepeat (Standard_True);
myParams->SetFilter (Graphic3d_TOTF_TRILINEAR);
myParams->SetGenMode (Graphic3d_TOTM_OBJECT, myParams->SetGenMode (Graphic3d_TOTM_OBJECT,
Graphic3d_Vec4 (1.0f, 0.0f, 0.0f, 0.0f), Graphic3d_Vec4 (1.0f, 0.0f, 0.0f, 0.0f),
Graphic3d_Vec4 (0.0f, 1.0f, 0.0f, 0.0f)); Graphic3d_Vec4 (0.0f, 1.0f, 0.0f, 0.0f));
@ -43,11 +40,8 @@ Graphic3d_Texture2Dplane::Graphic3d_Texture2Dplane (const TCollection_AsciiStrin
// purpose : // purpose :
// ======================================================================= // =======================================================================
Graphic3d_Texture2Dplane::Graphic3d_Texture2Dplane (const Graphic3d_NameOfTexture2D theNOT) Graphic3d_Texture2Dplane::Graphic3d_Texture2Dplane (const Graphic3d_NameOfTexture2D theNOT)
: Graphic3d_Texture2D (theNOT, Graphic3d_TOT_2D_MIPMAP) : Graphic3d_Texture2D (theNOT)
{ {
myParams->SetModulate (Standard_True);
myParams->SetRepeat (Standard_True);
myParams->SetFilter (Graphic3d_TOTF_TRILINEAR);
myParams->SetGenMode (Graphic3d_TOTM_OBJECT, myParams->SetGenMode (Graphic3d_TOTM_OBJECT,
Graphic3d_Vec4 (1.0f, 0.0f, 0.0f, 0.0f), Graphic3d_Vec4 (1.0f, 0.0f, 0.0f, 0.0f),
Graphic3d_Vec4 (0.0f, 1.0f, 0.0f, 0.0f)); Graphic3d_Vec4 (0.0f, 1.0f, 0.0f, 0.0f));
@ -58,11 +52,8 @@ Graphic3d_Texture2Dplane::Graphic3d_Texture2Dplane (const Graphic3d_NameOfTextur
// purpose : // purpose :
// ======================================================================= // =======================================================================
Graphic3d_Texture2Dplane::Graphic3d_Texture2Dplane (const Handle(Image_PixMap)& thePixMap) Graphic3d_Texture2Dplane::Graphic3d_Texture2Dplane (const Handle(Image_PixMap)& thePixMap)
: Graphic3d_Texture2D (thePixMap, Graphic3d_TOT_2D_MIPMAP) : Graphic3d_Texture2D (thePixMap)
{ {
myParams->SetModulate (Standard_True);
myParams->SetRepeat (Standard_True);
myParams->SetFilter (Graphic3d_TOTF_TRILINEAR);
myParams->SetGenMode (Graphic3d_TOTM_OBJECT, myParams->SetGenMode (Graphic3d_TOTM_OBJECT,
Graphic3d_Vec4 (1.0f, 0.0f, 0.0f, 0.0f), Graphic3d_Vec4 (1.0f, 0.0f, 0.0f, 0.0f),
Graphic3d_Vec4 (0.0f, 1.0f, 0.0f, 0.0f)); Graphic3d_Vec4 (0.0f, 1.0f, 0.0f, 0.0f));

View File

@ -0,0 +1,127 @@
// Copyright (c) 2022 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <Graphic3d_Texture3D.hxx>
#include <Graphic3d_TextureParams.hxx>
#include <Image_AlienPixMap.hxx>
#include <Message.hxx>
IMPLEMENT_STANDARD_RTTIEXT(Graphic3d_Texture3D, Graphic3d_TextureMap)
// =======================================================================
// function : Graphic3d_Texture3D
// purpose :
// =======================================================================
Graphic3d_Texture3D::Graphic3d_Texture3D (const TCollection_AsciiString& theFileName)
: Graphic3d_TextureMap (theFileName, Graphic3d_TypeOfTexture_3D)
{
myParams->SetFilter (Graphic3d_TOTF_TRILINEAR);
}
// =======================================================================
// function : Graphic3d_Texture3D
// purpose :
// =======================================================================
Graphic3d_Texture3D::Graphic3d_Texture3D (const Handle(Image_PixMap)& thePixMap)
: Graphic3d_TextureMap (thePixMap, Graphic3d_TypeOfTexture_3D)
{
myParams->SetFilter (Graphic3d_TOTF_TRILINEAR);
}
// =======================================================================
// function : Graphic3d_Texture3D
// purpose :
// =======================================================================
Graphic3d_Texture3D::Graphic3d_Texture3D (const NCollection_Array1<TCollection_AsciiString>& theFiles)
: Graphic3d_TextureMap ("", Graphic3d_TypeOfTexture_3D)
{
myParams->SetFilter (Graphic3d_TOTF_TRILINEAR);
myPaths.Resize (theFiles.Lower(), theFiles.Upper(), false);
myPaths.Assign (theFiles);
}
// =======================================================================
// function : ~Graphic3d_Texture3D
// purpose :
// =======================================================================
Graphic3d_Texture3D::~Graphic3d_Texture3D()
{
//
}
// =======================================================================
// function : SetImage
// purpose :
// =======================================================================
void Graphic3d_Texture3D::SetImage (const Handle(Image_PixMap)& thePixMap)
{
myPixMap = thePixMap;
myPath = OSD_Path();
NCollection_Array1<TCollection_AsciiString> anArr;
myPaths.Move (anArr);
}
// =======================================================================
// function : GetImage
// purpose :
// =======================================================================
Handle(Image_PixMap) Graphic3d_Texture3D::GetImage (const Handle(Image_SupportedFormats)& theSupported)
{
if (myPaths.IsEmpty()
|| !myPixMap.IsNull())
{
return base_type::GetImage (theSupported);
}
Handle(Image_PixMap) anImage3D;
const Standard_Integer aNbSlices = myPaths.Length();
for (Standard_Integer aSlice = 0; aSlice < aNbSlices; ++aSlice)
{
const TCollection_AsciiString& aSlicePath = myPaths[myPaths.Lower() + aSlice];
Handle(Image_AlienPixMap) anImage = new Image_AlienPixMap();
if (!anImage->Load (aSlicePath))
{
Message::SendFail() << "Graphic3d_Texture3D::GetImage() failed to load slice " << aSlice << " from '" << aSlicePath << "'";
return Handle(Image_PixMap)();
}
convertToCompatible (theSupported, anImage);
if (anImage3D.IsNull())
{
myIsTopDown = anImage->IsTopDown();
anImage3D = new Image_PixMap();
anImage3D->SetTopDown (myIsTopDown);
if (!anImage3D->InitTrash3D (anImage->Format(),
NCollection_Vec3<Standard_Size> (anImage->SizeX(), anImage->SizeY(), aNbSlices),
anImage->SizeRowBytes()))
{
Message::SendFail() << "Graphic3d_Texture3D::GetImage() failed to allocate 3D image " << (int )anImage->SizeX() << "x" << (int )anImage->SizeY() << "x" << aNbSlices;
return Handle(Image_PixMap)();
}
}
if (anImage->Format() != anImage3D->Format()
|| anImage->SizeX() != anImage3D->SizeX()
|| anImage->SizeY() != anImage3D->SizeY()
|| anImage->SizeRowBytes() != anImage3D->SizeRowBytes())
{
Message::SendFail() << "Graphic3d_Texture3D::GetImage() slice " << aSlice << " from '" << aSlicePath << "' have different dimensions";
return Handle(Image_PixMap)();
}
memcpy (anImage3D->ChangeSlice (aSlice), anImage->Data(), anImage->SizeBytes());
}
return anImage3D;
}

View File

@ -0,0 +1,51 @@
// Copyright (c) 2022 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#ifndef _Graphic3d_Texture3D_HeaderFile
#define _Graphic3d_Texture3D_HeaderFile
#include <Graphic3d_TextureMap.hxx>
#include <NCollection_Array1.hxx>
//! This abstract class for managing 3D textures.
class Graphic3d_Texture3D : public Graphic3d_TextureMap
{
DEFINE_STANDARD_RTTIEXT(Graphic3d_Texture3D, Graphic3d_TextureMap)
public:
//! Creates a texture from a file.
Standard_EXPORT Graphic3d_Texture3D (const TCollection_AsciiString& theFileName);
//! Creates a texture from the pixmap.
Standard_EXPORT Graphic3d_Texture3D (const Handle(Image_PixMap)& thePixMap);
//! Creates a texture from a file.
Standard_EXPORT Graphic3d_Texture3D (const NCollection_Array1<TCollection_AsciiString>& theFiles);
//! Destructor.
Standard_EXPORT virtual ~Graphic3d_Texture3D();
//! 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);
//! Load and return image.
Standard_EXPORT virtual Handle(Image_PixMap) GetImage (const Handle(Image_SupportedFormats)& theSupported) Standard_OVERRIDE;
protected:
NCollection_Array1<TCollection_AsciiString> myPaths;
};
#endif // _Graphic3d_Texture3D_HeaderFile

View File

@ -42,9 +42,10 @@ static const char *NameOfTextureEnv_to_FileName[] =
// purpose : // purpose :
// ======================================================================= // =======================================================================
Graphic3d_TextureEnv::Graphic3d_TextureEnv (const TCollection_AsciiString& theFileName) Graphic3d_TextureEnv::Graphic3d_TextureEnv (const TCollection_AsciiString& theFileName)
: Graphic3d_TextureRoot (theFileName, Graphic3d_TOT_2D_MIPMAP), : Graphic3d_TextureRoot (theFileName, Graphic3d_TypeOfTexture_2D),
myName (Graphic3d_NOT_ENV_UNKNOWN) myName (Graphic3d_NOT_ENV_UNKNOWN)
{ {
myHasMipmaps = true;
myParams->SetFilter (Graphic3d_TOTF_TRILINEAR); myParams->SetFilter (Graphic3d_TOTF_TRILINEAR);
myParams->SetGenMode (Graphic3d_TOTM_SPHERE, myParams->SetGenMode (Graphic3d_TOTM_SPHERE,
Graphic3d_Vec4 (1.0f, 0.0f, 0.0f, 0.0f), Graphic3d_Vec4 (1.0f, 0.0f, 0.0f, 0.0f),
@ -56,9 +57,10 @@ Graphic3d_TextureEnv::Graphic3d_TextureEnv (const TCollection_AsciiString& theFi
// purpose : // purpose :
// ======================================================================= // =======================================================================
Graphic3d_TextureEnv::Graphic3d_TextureEnv (const Graphic3d_NameOfTextureEnv theNOT) Graphic3d_TextureEnv::Graphic3d_TextureEnv (const Graphic3d_NameOfTextureEnv theNOT)
: Graphic3d_TextureRoot (NameOfTextureEnv_to_FileName[theNOT], Graphic3d_TOT_2D_MIPMAP), : Graphic3d_TextureRoot (NameOfTextureEnv_to_FileName[theNOT], Graphic3d_TypeOfTexture_2D),
myName (theNOT) myName (theNOT)
{ {
myHasMipmaps = true;
myPath.SetTrek (Graphic3d_TextureRoot::TexturesFolder()); myPath.SetTrek (Graphic3d_TextureRoot::TexturesFolder());
myTexId = TCollection_AsciiString ("Graphic3d_TextureEnv_") myTexId = TCollection_AsciiString ("Graphic3d_TextureEnv_")
+ NameOfTextureEnv_to_FileName[theNOT]; + NameOfTextureEnv_to_FileName[theNOT];
@ -74,9 +76,10 @@ Graphic3d_TextureEnv::Graphic3d_TextureEnv (const Graphic3d_NameOfTextureEnv the
// purpose : // purpose :
// ======================================================================= // =======================================================================
Graphic3d_TextureEnv::Graphic3d_TextureEnv (const Handle(Image_PixMap)& thePixMap) Graphic3d_TextureEnv::Graphic3d_TextureEnv (const Handle(Image_PixMap)& thePixMap)
: Graphic3d_TextureRoot (thePixMap, Graphic3d_TOT_2D_MIPMAP), : Graphic3d_TextureRoot (thePixMap, Graphic3d_TypeOfTexture_2D),
myName (Graphic3d_NOT_ENV_UNKNOWN) myName (Graphic3d_NOT_ENV_UNKNOWN)
{ {
myHasMipmaps = true;
myParams->SetFilter (Graphic3d_TOTF_TRILINEAR); myParams->SetFilter (Graphic3d_TOTF_TRILINEAR);
myParams->SetGenMode (Graphic3d_TOTM_SPHERE, myParams->SetGenMode (Graphic3d_TOTM_SPHERE,
Graphic3d_Vec4 (1.0f, 0.0f, 0.0f, 0.0f), Graphic3d_Vec4 (1.0f, 0.0f, 0.0f, 0.0f),

View File

@ -92,9 +92,10 @@ Graphic3d_TextureRoot::Graphic3d_TextureRoot (const TCollection_AsciiString& the
: myParams (new Graphic3d_TextureParams()), : myParams (new Graphic3d_TextureParams()),
myPath (theFileName), myPath (theFileName),
myRevision (0), myRevision (0),
myType (theType), myType (theType == Graphic3d_TOT_2D_MIPMAP ? Graphic3d_TypeOfTexture_2D : theType),
myIsColorMap (true), myIsColorMap (true),
myIsTopDown (true) myIsTopDown (true),
myHasMipmaps (theType == Graphic3d_TOT_2D_MIPMAP)
{ {
generateId(); generateId();
} }
@ -108,9 +109,10 @@ Graphic3d_TextureRoot::Graphic3d_TextureRoot (const Handle(Image_PixMap)& theP
: myParams (new Graphic3d_TextureParams()), : myParams (new Graphic3d_TextureParams()),
myPixMap (thePixMap), myPixMap (thePixMap),
myRevision (0), myRevision (0),
myType (theType), myType (theType == Graphic3d_TOT_2D_MIPMAP ? Graphic3d_TypeOfTexture_2D : theType),
myIsColorMap (true), myIsColorMap (true),
myIsTopDown (true) myIsTopDown (true),
myHasMipmaps (theType == Graphic3d_TOT_2D_MIPMAP)
{ {
generateId(); generateId();
} }

View File

@ -113,6 +113,12 @@ public:
//! Set flag indicating color nature of values within the texture. //! Set flag indicating color nature of values within the texture.
void SetColorMap (Standard_Boolean theIsColor) { myIsColorMap = theIsColor; } void SetColorMap (Standard_Boolean theIsColor) { myIsColorMap = theIsColor; }
//! Returns whether mipmaps should be generated or not.
Standard_Boolean HasMipmaps() const { return myHasMipmaps; }
//! Sets whether to generate mipmaps or not.
void SetMipmapsGeneration (Standard_Boolean theToGenerateMipmaps) { myHasMipmaps = theToGenerateMipmaps; }
//! Returns whether row's memory layout is top-down. //! Returns whether row's memory layout is top-down.
Standard_Boolean IsTopDown() const { return myIsTopDown; } Standard_Boolean IsTopDown() const { return myIsTopDown; }
@ -148,7 +154,7 @@ protected:
Graphic3d_TypeOfTexture myType; //!< texture type Graphic3d_TypeOfTexture myType; //!< texture type
Standard_Boolean myIsColorMap; //!< flag indicating color nature of values within the texture Standard_Boolean myIsColorMap; //!< flag indicating color nature of values within the texture
Standard_Boolean myIsTopDown; //!< Stores rows's memory layout Standard_Boolean myIsTopDown; //!< Stores rows's memory layout
Standard_Boolean myHasMipmaps; //!< Indicates whether mipmaps should be generated or not
}; };

View File

@ -20,10 +20,26 @@
//! Type of the texture file format. //! Type of the texture file format.
enum Graphic3d_TypeOfTexture enum Graphic3d_TypeOfTexture
{ {
Graphic3d_TOT_1D, //! 1D texture (array).
Graphic3d_TOT_2D, //! Note that this texture type might be unsupported by graphics API (emulated by 2D texture with 1 pixel height).
Graphic3d_TypeOfTexture_1D,
//! 2D texture (image plane).
Graphic3d_TypeOfTexture_2D,
//! 3D texture (a set of image planes).
Graphic3d_TypeOfTexture_3D,
//! Cubemap texture (6 image planes defining cube sides).
Graphic3d_TypeOfTexture_CUBEMAP,
//! Obsolete type - Graphic3d_TextureRoot::SetMipmapsGeneration() should be used instead.
Graphic3d_TOT_2D_MIPMAP, Graphic3d_TOT_2D_MIPMAP,
Graphic3d_TOT_CUBEMAP
// old aliases
Graphic3d_TOT_1D = Graphic3d_TypeOfTexture_1D,
Graphic3d_TOT_2D = Graphic3d_TypeOfTexture_2D,
Graphic3d_TOT_CUBEMAP = Graphic3d_TypeOfTexture_CUBEMAP
}; };
#endif // _Graphic3d_TypeOfTexture_HeaderFile #endif // _Graphic3d_TypeOfTexture_HeaderFile

View File

@ -73,6 +73,7 @@ namespace
}; };
} }
IMPLEMENT_STANDARD_RTTIEXT(Image_PixMapData, NCollection_Buffer)
IMPLEMENT_STANDARD_RTTIEXT(Image_PixMap, Standard_Transient) IMPLEMENT_STANDARD_RTTIEXT(Image_PixMap, Standard_Transient)
// ======================================================================= // =======================================================================
@ -152,6 +153,31 @@ void Image_PixMap::SetFormat (Image_Format thePixelFormat)
myImgFormat = thePixelFormat; myImgFormat = thePixelFormat;
} }
// =======================================================================
// function : InitWrapper3D
// purpose :
// =======================================================================
bool Image_PixMap::InitWrapper3D (Image_Format thePixelFormat,
Standard_Byte* theDataPtr,
const NCollection_Vec3<Standard_Size>& theSizeXYZ,
const Standard_Size theSizeRowBytes)
{
Clear();
myImgFormat = thePixelFormat;
if (theSizeXYZ.x() == 0
|| theSizeXYZ.y() == 0
|| theSizeXYZ.z() == 0
|| theDataPtr == nullptr)
{
return false;
}
Handle(NCollection_BaseAllocator) anEmptyAlloc;
myData.Init (anEmptyAlloc, Image_PixMap::SizePixelBytes (thePixelFormat),
theSizeXYZ, theSizeRowBytes, theDataPtr);
return true;
}
// ======================================================================= // =======================================================================
// function : InitWrapper // function : InitWrapper
// purpose : // purpose :
@ -161,18 +187,32 @@ bool Image_PixMap::InitWrapper (Image_Format thePixelFormat,
const Standard_Size theSizeX, const Standard_Size theSizeX,
const Standard_Size theSizeY, const Standard_Size theSizeY,
const Standard_Size theSizeRowBytes) const Standard_Size theSizeRowBytes)
{
return InitWrapper3D (thePixelFormat, theDataPtr, NCollection_Vec3<Standard_Size> (theSizeX, theSizeY, 1), theSizeRowBytes);
}
// =======================================================================
// function : InitTrash3D
// purpose :
// =======================================================================
bool Image_PixMap::InitTrash3D (Image_Format thePixelFormat,
const NCollection_Vec3<Standard_Size>& theSizeXYZ,
const Standard_Size theSizeRowBytes)
{ {
Clear(); Clear();
myImgFormat = thePixelFormat; myImgFormat = thePixelFormat;
if ((theSizeX == 0) || (theSizeY == 0) || (theDataPtr == NULL)) if (theSizeXYZ.x() == 0
|| theSizeXYZ.y() == 0
|| theSizeXYZ.z() == 0)
{ {
return false; return false;
} }
Handle(NCollection_BaseAllocator) anEmptyAlloc; // use argument only if it greater
myData.Init (anEmptyAlloc, Image_PixMap::SizePixelBytes (thePixelFormat), const Standard_Size aSizeRowBytes = std::max (theSizeRowBytes, theSizeXYZ.x() * SizePixelBytes (thePixelFormat));
theSizeX, theSizeY, theSizeRowBytes, theDataPtr); myData.Init (DefaultAllocator(), Image_PixMap::SizePixelBytes (thePixelFormat),
return true; theSizeXYZ, aSizeRowBytes, NULL);
return !myData.IsEmpty();
} }
// ======================================================================= // =======================================================================
@ -184,34 +224,32 @@ bool Image_PixMap::InitTrash (Image_Format thePixelFormat,
const Standard_Size theSizeY, const Standard_Size theSizeY,
const Standard_Size theSizeRowBytes) const Standard_Size theSizeRowBytes)
{ {
Clear(); return InitTrash3D (thePixelFormat, NCollection_Vec3<Standard_Size> (theSizeX, theSizeY, 1), theSizeRowBytes);
myImgFormat = thePixelFormat;
if ((theSizeX == 0) || (theSizeY == 0))
{
return false;
}
// use argument only if it greater
const Standard_Size aSizeRowBytes = std::max (theSizeRowBytes, theSizeX * SizePixelBytes (thePixelFormat));
myData.Init (DefaultAllocator(), Image_PixMap::SizePixelBytes (thePixelFormat),
theSizeX, theSizeY, aSizeRowBytes, NULL);
return !myData.IsEmpty();
} }
// ======================================================================= // =======================================================================
// function : InitZero // function : InitZero3D
// purpose : // purpose :
// ======================================================================= // =======================================================================
bool Image_PixMap::InitZero (Image_Format thePixelFormat, bool Image_PixMap::InitZero3D (Image_Format thePixelFormat,
const Standard_Size theSizeX, const NCollection_Vec3<Standard_Size>& theSizeXYZ,
const Standard_Size theSizeY,
const Standard_Size theSizeRowBytes, const Standard_Size theSizeRowBytes,
const Standard_Byte theValue) const Standard_Byte theValue)
{ {
if (!InitTrash (thePixelFormat, theSizeX, theSizeY, theSizeRowBytes)) if (theSizeXYZ.z() > 1)
{
if (!InitTrash3D (thePixelFormat, theSizeXYZ, theSizeRowBytes))
{ {
return false; return false;
} }
}
else
{
if (!InitTrash (thePixelFormat, theSizeXYZ.x(), theSizeXYZ.y(), theSizeRowBytes))
{
return false;
}
}
memset (myData.ChangeData(), (int )theValue, SizeBytes()); memset (myData.ChangeData(), (int )theValue, SizeBytes());
return true; return true;
} }
@ -227,13 +265,25 @@ bool Image_PixMap::InitCopy (const Image_PixMap& theCopy)
// self-copying disallowed // self-copying disallowed
return false; return false;
} }
if (InitTrash (theCopy.myImgFormat, theCopy.SizeX(), theCopy.SizeY(), theCopy.SizeRowBytes()))
if (theCopy.SizeZ() > 1)
{ {
if (!InitTrash3D (theCopy.myImgFormat, theCopy.SizeXYZ(), theCopy.SizeRowBytes()))
{
return false;
}
}
else
{
if (!InitTrash (theCopy.myImgFormat, theCopy.SizeX(), theCopy.SizeY(), theCopy.SizeRowBytes()))
{
return false;
}
}
memcpy (myData.ChangeData(), theCopy.myData.Data(), theCopy.SizeBytes()); memcpy (myData.ChangeData(), theCopy.myData.Data(), theCopy.SizeBytes());
return true; return true;
} }
return false;
}
// ======================================================================= // =======================================================================
// function : Clear // function : Clear
@ -243,80 +293,73 @@ void Image_PixMap::Clear()
{ {
Handle(NCollection_BaseAllocator) anEmptyAlloc; Handle(NCollection_BaseAllocator) anEmptyAlloc;
myData.Init (anEmptyAlloc, Image_PixMap::SizePixelBytes (myImgFormat), myData.Init (anEmptyAlloc, Image_PixMap::SizePixelBytes (myImgFormat),
0, 0, 0, NULL); NCollection_Vec3<Standard_Size> (0), 0, nullptr);
} }
// ======================================================================= // =======================================================================
// function : PixelColor // function : ColorFromRawPixel
// purpose : // purpose :
// ======================================================================= // =======================================================================
Quantity_ColorRGBA Image_PixMap::PixelColor (const Standard_Integer theX, Quantity_ColorRGBA Image_PixMap::ColorFromRawPixel (const Standard_Byte* theRawValue,
const Standard_Integer theY, const Image_Format theFormat,
const Standard_Boolean theToLinearize) const const Standard_Boolean theToLinearize)
{ {
if (IsEmpty() switch (theFormat)
|| theX < 0 || (Standard_Size )theX >= SizeX()
|| theY < 0 || (Standard_Size )theY >= SizeY())
{
return Quantity_ColorRGBA (0.0f, 0.0f, 0.0f, 0.0f); // transparent
}
switch (myImgFormat)
{ {
case Image_Format_GrayF: case Image_Format_GrayF:
{ {
const Standard_ShortReal& aPixel = Value<Standard_ShortReal> (theY, theX); const Standard_ShortReal& aPixel = *reinterpret_cast<const Standard_ShortReal*> (theRawValue);
return Quantity_ColorRGBA (NCollection_Vec4<float> (aPixel, aPixel, aPixel, 1.0f)); // opaque return Quantity_ColorRGBA (NCollection_Vec4<float> (aPixel, aPixel, aPixel, 1.0f)); // opaque
} }
case Image_Format_AlphaF: case Image_Format_AlphaF:
{ {
const Standard_ShortReal& aPixel = Value<Standard_ShortReal> (theY, theX); const Standard_ShortReal& aPixel = *reinterpret_cast<const Standard_ShortReal*> (theRawValue);
return Quantity_ColorRGBA (NCollection_Vec4<float> (1.0f, 1.0f, 1.0f, aPixel)); return Quantity_ColorRGBA (NCollection_Vec4<float> (1.0f, 1.0f, 1.0f, aPixel));
} }
case Image_Format_RGF: case Image_Format_RGF:
{ {
const Image_ColorRGF& aPixel = Value<Image_ColorRGF> (theY, theX); const Image_ColorRGF& aPixel = *reinterpret_cast<const Image_ColorRGF*> (theRawValue);
return Quantity_ColorRGBA (NCollection_Vec4<float> (aPixel.r(), aPixel.g(), 0.0f, 1.0f)); return Quantity_ColorRGBA (NCollection_Vec4<float> (aPixel.r(), aPixel.g(), 0.0f, 1.0f));
} }
case Image_Format_RGBAF: case Image_Format_RGBAF:
{ {
const Image_ColorRGBAF& aPixel = Value<Image_ColorRGBAF> (theY, theX); const Image_ColorRGBAF& aPixel = *reinterpret_cast<const Image_ColorRGBAF*> (theRawValue);
return Quantity_ColorRGBA (NCollection_Vec4<float> (aPixel.r(), aPixel.g(), aPixel.b(), aPixel.a())); return Quantity_ColorRGBA (NCollection_Vec4<float> (aPixel.r(), aPixel.g(), aPixel.b(), aPixel.a()));
} }
case Image_Format_BGRAF: case Image_Format_BGRAF:
{ {
const Image_ColorBGRAF& aPixel = Value<Image_ColorBGRAF> (theY, theX); const Image_ColorBGRAF& aPixel = *reinterpret_cast<const Image_ColorBGRAF*> (theRawValue);
return Quantity_ColorRGBA (NCollection_Vec4<float> (aPixel.r(), aPixel.g(), aPixel.b(), aPixel.a())); return Quantity_ColorRGBA (NCollection_Vec4<float> (aPixel.r(), aPixel.g(), aPixel.b(), aPixel.a()));
} }
case Image_Format_RGBF: case Image_Format_RGBF:
{ {
const Image_ColorRGBF& aPixel = Value<Image_ColorRGBF> (theY, theX); const Image_ColorRGBF& aPixel = *reinterpret_cast<const Image_ColorRGBF*> (theRawValue);
return Quantity_ColorRGBA (NCollection_Vec4<float> (aPixel.r(), aPixel.g(), aPixel.b(), 1.0f)); // opaque return Quantity_ColorRGBA (NCollection_Vec4<float> (aPixel.r(), aPixel.g(), aPixel.b(), 1.0f)); // opaque
} }
case Image_Format_BGRF: case Image_Format_BGRF:
{ {
const Image_ColorBGRF& aPixel = Value<Image_ColorBGRF> (theY, theX); const Image_ColorBGRF& aPixel = *reinterpret_cast<const Image_ColorBGRF*> (theRawValue);
return Quantity_ColorRGBA (NCollection_Vec4<float> (aPixel.r(), aPixel.g(), aPixel.b(), 1.0f)); // opaque return Quantity_ColorRGBA (NCollection_Vec4<float> (aPixel.r(), aPixel.g(), aPixel.b(), 1.0f)); // opaque
} }
case Image_Format_GrayF_half: case Image_Format_GrayF_half:
{ {
const uint16_t& aPixel = Value<uint16_t> (theY, theX); const uint16_t& aPixel = *reinterpret_cast<const uint16_t*> (theRawValue);
return Quantity_ColorRGBA (NCollection_Vec4<float> (ConvertFromHalfFloat (aPixel), 0.0f, 0.0f, 1.0f)); return Quantity_ColorRGBA (NCollection_Vec4<float> (ConvertFromHalfFloat (aPixel), 0.0f, 0.0f, 1.0f));
} }
case Image_Format_RGF_half: case Image_Format_RGF_half:
{ {
const NCollection_Vec2<uint16_t>& aPixel = Value<NCollection_Vec2<uint16_t>> (theY, theX); const NCollection_Vec2<uint16_t>& aPixel = *reinterpret_cast<const NCollection_Vec2<uint16_t>*> (theRawValue);
return Quantity_ColorRGBA (NCollection_Vec4<float> (ConvertFromHalfFloat (aPixel.x()), ConvertFromHalfFloat (aPixel.y()), 0.0f, 1.0f)); return Quantity_ColorRGBA (NCollection_Vec4<float> (ConvertFromHalfFloat (aPixel.x()), ConvertFromHalfFloat (aPixel.y()), 0.0f, 1.0f));
} }
case Image_Format_RGBAF_half: case Image_Format_RGBAF_half:
{ {
const NCollection_Vec4<uint16_t>& aPixel = Value<NCollection_Vec4<uint16_t>> (theY, theX); const NCollection_Vec4<uint16_t>& aPixel = *reinterpret_cast<const NCollection_Vec4<uint16_t>*> (theRawValue);
return Quantity_ColorRGBA (NCollection_Vec4<float> (ConvertFromHalfFloat (aPixel.r()), ConvertFromHalfFloat (aPixel.g()), return Quantity_ColorRGBA (NCollection_Vec4<float> (ConvertFromHalfFloat (aPixel.r()), ConvertFromHalfFloat (aPixel.g()),
ConvertFromHalfFloat (aPixel.b()), ConvertFromHalfFloat (aPixel.a()))); ConvertFromHalfFloat (aPixel.b()), ConvertFromHalfFloat (aPixel.a())));
} }
case Image_Format_RGBA: case Image_Format_RGBA:
{ {
const Image_ColorRGBA& aPixel = Value<Image_ColorRGBA> (theY, theX); const Image_ColorRGBA& aPixel = *reinterpret_cast<const Image_ColorRGBA*> (theRawValue);
return theToLinearize return theToLinearize
? Quantity_ColorRGBA (Quantity_Color::Convert_sRGB_To_LinearRGB (float(aPixel.r()) / 255.0f), ? Quantity_ColorRGBA (Quantity_Color::Convert_sRGB_To_LinearRGB (float(aPixel.r()) / 255.0f),
Quantity_Color::Convert_sRGB_To_LinearRGB (float(aPixel.g()) / 255.0f), Quantity_Color::Convert_sRGB_To_LinearRGB (float(aPixel.g()) / 255.0f),
@ -326,7 +369,7 @@ Quantity_ColorRGBA Image_PixMap::PixelColor (const Standard_Integer theX,
} }
case Image_Format_BGRA: case Image_Format_BGRA:
{ {
const Image_ColorBGRA& aPixel = Value<Image_ColorBGRA> (theY, theX); const Image_ColorBGRA& aPixel = *reinterpret_cast<const Image_ColorBGRA*> (theRawValue);
return theToLinearize return theToLinearize
? Quantity_ColorRGBA (Quantity_Color::Convert_sRGB_To_LinearRGB (float(aPixel.r()) / 255.0f), ? Quantity_ColorRGBA (Quantity_Color::Convert_sRGB_To_LinearRGB (float(aPixel.r()) / 255.0f),
Quantity_Color::Convert_sRGB_To_LinearRGB (float(aPixel.g()) / 255.0f), Quantity_Color::Convert_sRGB_To_LinearRGB (float(aPixel.g()) / 255.0f),
@ -336,7 +379,7 @@ Quantity_ColorRGBA Image_PixMap::PixelColor (const Standard_Integer theX,
} }
case Image_Format_RGB32: case Image_Format_RGB32:
{ {
const Image_ColorRGB32& aPixel = Value<Image_ColorRGB32> (theY, theX); const Image_ColorRGB32& aPixel = *reinterpret_cast<const Image_ColorRGB32*> (theRawValue);
return theToLinearize return theToLinearize
? Quantity_ColorRGBA (Quantity_Color::Convert_sRGB_To_LinearRGB (float(aPixel.r()) / 255.0f), ? Quantity_ColorRGBA (Quantity_Color::Convert_sRGB_To_LinearRGB (float(aPixel.r()) / 255.0f),
Quantity_Color::Convert_sRGB_To_LinearRGB (float(aPixel.g()) / 255.0f), Quantity_Color::Convert_sRGB_To_LinearRGB (float(aPixel.g()) / 255.0f),
@ -345,7 +388,7 @@ Quantity_ColorRGBA Image_PixMap::PixelColor (const Standard_Integer theX,
} }
case Image_Format_BGR32: case Image_Format_BGR32:
{ {
const Image_ColorBGR32& aPixel = Value<Image_ColorBGR32> (theY, theX); const Image_ColorBGR32& aPixel = *reinterpret_cast<const Image_ColorBGR32*> (theRawValue);
return theToLinearize return theToLinearize
? Quantity_ColorRGBA (Quantity_Color::Convert_sRGB_To_LinearRGB (float(aPixel.r()) / 255.0f), ? Quantity_ColorRGBA (Quantity_Color::Convert_sRGB_To_LinearRGB (float(aPixel.r()) / 255.0f),
Quantity_Color::Convert_sRGB_To_LinearRGB (float(aPixel.g()) / 255.0f), Quantity_Color::Convert_sRGB_To_LinearRGB (float(aPixel.g()) / 255.0f),
@ -354,7 +397,7 @@ Quantity_ColorRGBA Image_PixMap::PixelColor (const Standard_Integer theX,
} }
case Image_Format_RGB: case Image_Format_RGB:
{ {
const Image_ColorRGB& aPixel = Value<Image_ColorRGB> (theY, theX); const Image_ColorRGB& aPixel = *reinterpret_cast<const Image_ColorRGB*> (theRawValue);
return theToLinearize return theToLinearize
? Quantity_ColorRGBA (Quantity_Color::Convert_sRGB_To_LinearRGB (float(aPixel.r()) / 255.0f), ? Quantity_ColorRGBA (Quantity_Color::Convert_sRGB_To_LinearRGB (float(aPixel.r()) / 255.0f),
Quantity_Color::Convert_sRGB_To_LinearRGB (float(aPixel.g()) / 255.0f), Quantity_Color::Convert_sRGB_To_LinearRGB (float(aPixel.g()) / 255.0f),
@ -363,7 +406,7 @@ Quantity_ColorRGBA Image_PixMap::PixelColor (const Standard_Integer theX,
} }
case Image_Format_BGR: case Image_Format_BGR:
{ {
const Image_ColorBGR& aPixel = Value<Image_ColorBGR> (theY, theX); const Image_ColorBGR& aPixel = *reinterpret_cast<const Image_ColorBGR*> (theRawValue);
return theToLinearize return theToLinearize
? Quantity_ColorRGBA (Quantity_Color::Convert_sRGB_To_LinearRGB (float(aPixel.r()) / 255.0f), ? Quantity_ColorRGBA (Quantity_Color::Convert_sRGB_To_LinearRGB (float(aPixel.r()) / 255.0f),
Quantity_Color::Convert_sRGB_To_LinearRGB (float(aPixel.g()) / 255.0f), Quantity_Color::Convert_sRGB_To_LinearRGB (float(aPixel.g()) / 255.0f),
@ -372,18 +415,18 @@ Quantity_ColorRGBA Image_PixMap::PixelColor (const Standard_Integer theX,
} }
case Image_Format_Gray: case Image_Format_Gray:
{ {
const Standard_Byte& aPixel = Value<Standard_Byte> (theY, theX); const Standard_Byte& aPixel = *reinterpret_cast<const Standard_Byte*> (theRawValue);
const float anIntensity = float(aPixel) / 255.0f; const float anIntensity = float(aPixel) / 255.0f;
return Quantity_ColorRGBA (anIntensity, anIntensity, anIntensity, 1.0f); // opaque return Quantity_ColorRGBA (anIntensity, anIntensity, anIntensity, 1.0f); // opaque
} }
case Image_Format_Alpha: case Image_Format_Alpha:
{ {
const Standard_Byte& aPixel = Value<Standard_Byte> (theY, theX); const Standard_Byte& aPixel = *reinterpret_cast<const Standard_Byte*> (theRawValue);
return Quantity_ColorRGBA (1.0f, 1.0f, 1.0f, float(aPixel) / 255.0f); return Quantity_ColorRGBA (1.0f, 1.0f, 1.0f, float(aPixel) / 255.0f);
} }
case Image_Format_Gray16: case Image_Format_Gray16:
{ {
const uint16_t& aPixel = Value<uint16_t> (theY, theX); const uint16_t& aPixel = *reinterpret_cast<const uint16_t*> (theRawValue);
const float anIntensity = float(aPixel) / 65535.0f; const float anIntensity = float(aPixel) / 65535.0f;
return Quantity_ColorRGBA (anIntensity, anIntensity, anIntensity, 1.0f); // opaque return Quantity_ColorRGBA (anIntensity, anIntensity, anIntensity, 1.0f); // opaque
} }
@ -398,44 +441,37 @@ Quantity_ColorRGBA Image_PixMap::PixelColor (const Standard_Integer theX,
} }
// ======================================================================= // =======================================================================
// function : SetPixelColor // function : ColorToRawPixel
// purpose : // purpose :
// ======================================================================= // =======================================================================
void Image_PixMap::SetPixelColor (const Standard_Integer theX, void Image_PixMap::ColorToRawPixel (Standard_Byte* theRawValue,
const Standard_Integer theY, const Image_Format theFormat,
const Quantity_ColorRGBA& theColor, const Quantity_ColorRGBA& theColor,
const Standard_Boolean theToDeLinearize) const Standard_Boolean theToDeLinearize)
{ {
if (IsEmpty()
|| theX < 0 || Standard_Size(theX) >= SizeX()
|| theY < 0 || Standard_Size(theY) >= SizeY())
{
return;
}
const NCollection_Vec4<float>& aColor = theColor; const NCollection_Vec4<float>& aColor = theColor;
switch (myImgFormat) switch (theFormat)
{ {
case Image_Format_GrayF: case Image_Format_GrayF:
{ {
ChangeValue<Standard_ShortReal> (theY, theX) = aColor.r(); *reinterpret_cast<Standard_ShortReal*> (theRawValue) = aColor.r();
return; return;
} }
case Image_Format_AlphaF: case Image_Format_AlphaF:
{ {
ChangeValue<Standard_ShortReal> (theY, theX) = aColor.a(); *reinterpret_cast<Standard_ShortReal*> (theRawValue) = aColor.a();
return; return;
} }
case Image_Format_RGF: case Image_Format_RGF:
{ {
Image_ColorRGF& aPixel = ChangeValue<Image_ColorRGF> (theY, theX); Image_ColorRGF& aPixel = *reinterpret_cast<Image_ColorRGF*> (theRawValue);
aPixel.r() = aColor.r(); aPixel.r() = aColor.r();
aPixel.g() = aColor.g(); aPixel.g() = aColor.g();
return; return;
} }
case Image_Format_RGBAF: case Image_Format_RGBAF:
{ {
Image_ColorRGBAF& aPixel = ChangeValue<Image_ColorRGBAF> (theY, theX); Image_ColorRGBAF& aPixel = *reinterpret_cast<Image_ColorRGBAF*> (theRawValue);
aPixel.r() = aColor.r(); aPixel.r() = aColor.r();
aPixel.g() = aColor.g(); aPixel.g() = aColor.g();
aPixel.b() = aColor.b(); aPixel.b() = aColor.b();
@ -444,7 +480,7 @@ void Image_PixMap::SetPixelColor (const Standard_Integer theX,
} }
case Image_Format_BGRAF: case Image_Format_BGRAF:
{ {
Image_ColorBGRAF& aPixel = ChangeValue<Image_ColorBGRAF> (theY, theX); Image_ColorBGRAF& aPixel = *reinterpret_cast<Image_ColorBGRAF*> (theRawValue);
aPixel.r() = aColor.r(); aPixel.r() = aColor.r();
aPixel.g() = aColor.g(); aPixel.g() = aColor.g();
aPixel.b() = aColor.b(); aPixel.b() = aColor.b();
@ -453,7 +489,7 @@ void Image_PixMap::SetPixelColor (const Standard_Integer theX,
} }
case Image_Format_RGBF: case Image_Format_RGBF:
{ {
Image_ColorRGBF& aPixel = ChangeValue<Image_ColorRGBF> (theY, theX); Image_ColorRGBF& aPixel = *reinterpret_cast<Image_ColorRGBF*> (theRawValue);
aPixel.r() = aColor.r(); aPixel.r() = aColor.r();
aPixel.g() = aColor.g(); aPixel.g() = aColor.g();
aPixel.b() = aColor.b(); aPixel.b() = aColor.b();
@ -461,7 +497,7 @@ void Image_PixMap::SetPixelColor (const Standard_Integer theX,
} }
case Image_Format_BGRF: case Image_Format_BGRF:
{ {
Image_ColorBGRF& aPixel = ChangeValue<Image_ColorBGRF> (theY, theX); Image_ColorBGRF& aPixel = *reinterpret_cast<Image_ColorBGRF*> (theRawValue);
aPixel.r() = aColor.r(); aPixel.r() = aColor.r();
aPixel.g() = aColor.g(); aPixel.g() = aColor.g();
aPixel.b() = aColor.b(); aPixel.b() = aColor.b();
@ -469,20 +505,20 @@ void Image_PixMap::SetPixelColor (const Standard_Integer theX,
} }
case Image_Format_GrayF_half: case Image_Format_GrayF_half:
{ {
uint16_t& aPixel = ChangeValue<uint16_t> (theY, theX); uint16_t& aPixel = *reinterpret_cast<uint16_t*> (theRawValue);
aPixel = ConvertToHalfFloat (aColor.r()); aPixel = ConvertToHalfFloat (aColor.r());
return; return;
} }
case Image_Format_RGF_half: case Image_Format_RGF_half:
{ {
NCollection_Vec2<uint16_t>& aPixel = ChangeValue<NCollection_Vec2<uint16_t>> (theY, theX); NCollection_Vec2<uint16_t>& aPixel = *reinterpret_cast<NCollection_Vec2<uint16_t>*> (theRawValue);
aPixel.x() = ConvertToHalfFloat (aColor.r()); aPixel.x() = ConvertToHalfFloat (aColor.r());
aPixel.y() = ConvertToHalfFloat (aColor.g()); aPixel.y() = ConvertToHalfFloat (aColor.g());
return; return;
} }
case Image_Format_RGBAF_half: case Image_Format_RGBAF_half:
{ {
NCollection_Vec4<uint16_t>& aPixel = ChangeValue<NCollection_Vec4<uint16_t>> (theY, theX); NCollection_Vec4<uint16_t>& aPixel = *reinterpret_cast<NCollection_Vec4<uint16_t>*> (theRawValue);
aPixel.r() = ConvertToHalfFloat (aColor.r()); aPixel.r() = ConvertToHalfFloat (aColor.r());
aPixel.g() = ConvertToHalfFloat (aColor.g()); aPixel.g() = ConvertToHalfFloat (aColor.g());
aPixel.b() = ConvertToHalfFloat (aColor.b()); aPixel.b() = ConvertToHalfFloat (aColor.b());
@ -491,7 +527,7 @@ void Image_PixMap::SetPixelColor (const Standard_Integer theX,
} }
case Image_Format_RGBA: case Image_Format_RGBA:
{ {
Image_ColorRGBA& aPixel = ChangeValue<Image_ColorRGBA> (theY, theX); Image_ColorRGBA& aPixel = *reinterpret_cast<Image_ColorRGBA*> (theRawValue);
if (theToDeLinearize) if (theToDeLinearize)
{ {
aPixel.r() = Standard_Byte(Quantity_Color::Convert_LinearRGB_To_sRGB (aColor.r()) * 255.0f); aPixel.r() = Standard_Byte(Quantity_Color::Convert_LinearRGB_To_sRGB (aColor.r()) * 255.0f);
@ -509,7 +545,7 @@ void Image_PixMap::SetPixelColor (const Standard_Integer theX,
} }
case Image_Format_BGRA: case Image_Format_BGRA:
{ {
Image_ColorBGRA& aPixel = ChangeValue<Image_ColorBGRA> (theY, theX); Image_ColorBGRA& aPixel = *reinterpret_cast<Image_ColorBGRA*> (theRawValue);
if (theToDeLinearize) if (theToDeLinearize)
{ {
aPixel.r() = Standard_Byte(Quantity_Color::Convert_LinearRGB_To_sRGB (aColor.r()) * 255.0f); aPixel.r() = Standard_Byte(Quantity_Color::Convert_LinearRGB_To_sRGB (aColor.r()) * 255.0f);
@ -527,7 +563,7 @@ void Image_PixMap::SetPixelColor (const Standard_Integer theX,
} }
case Image_Format_RGB32: case Image_Format_RGB32:
{ {
Image_ColorRGB32& aPixel = ChangeValue<Image_ColorRGB32> (theY, theX); Image_ColorRGB32& aPixel = *reinterpret_cast<Image_ColorRGB32*> (theRawValue);
if (theToDeLinearize) if (theToDeLinearize)
{ {
aPixel.r() = Standard_Byte(Quantity_Color::Convert_LinearRGB_To_sRGB (aColor.r()) * 255.0f); aPixel.r() = Standard_Byte(Quantity_Color::Convert_LinearRGB_To_sRGB (aColor.r()) * 255.0f);
@ -545,7 +581,7 @@ void Image_PixMap::SetPixelColor (const Standard_Integer theX,
} }
case Image_Format_BGR32: case Image_Format_BGR32:
{ {
Image_ColorBGR32& aPixel = ChangeValue<Image_ColorBGR32> (theY, theX); Image_ColorBGR32& aPixel = *reinterpret_cast<Image_ColorBGR32*> (theRawValue);
if (theToDeLinearize) if (theToDeLinearize)
{ {
aPixel.r() = Standard_Byte(Quantity_Color::Convert_LinearRGB_To_sRGB (aColor.r()) * 255.0f); aPixel.r() = Standard_Byte(Quantity_Color::Convert_LinearRGB_To_sRGB (aColor.r()) * 255.0f);
@ -563,7 +599,7 @@ void Image_PixMap::SetPixelColor (const Standard_Integer theX,
} }
case Image_Format_RGB: case Image_Format_RGB:
{ {
Image_ColorRGB& aPixel = ChangeValue<Image_ColorRGB> (theY, theX); Image_ColorRGB& aPixel = *reinterpret_cast<Image_ColorRGB*> (theRawValue);
if (theToDeLinearize) if (theToDeLinearize)
{ {
aPixel.r() = Standard_Byte(Quantity_Color::Convert_LinearRGB_To_sRGB (aColor.r()) * 255.0f); aPixel.r() = Standard_Byte(Quantity_Color::Convert_LinearRGB_To_sRGB (aColor.r()) * 255.0f);
@ -580,7 +616,7 @@ void Image_PixMap::SetPixelColor (const Standard_Integer theX,
} }
case Image_Format_BGR: case Image_Format_BGR:
{ {
Image_ColorBGR& aPixel = ChangeValue<Image_ColorBGR> (theY, theX); Image_ColorBGR& aPixel = *reinterpret_cast<Image_ColorBGR*> (theRawValue);
if (theToDeLinearize) if (theToDeLinearize)
{ {
aPixel.r() = Standard_Byte(Quantity_Color::Convert_LinearRGB_To_sRGB (aColor.r()) * 255.0f); aPixel.r() = Standard_Byte(Quantity_Color::Convert_LinearRGB_To_sRGB (aColor.r()) * 255.0f);
@ -597,17 +633,17 @@ void Image_PixMap::SetPixelColor (const Standard_Integer theX,
} }
case Image_Format_Gray: case Image_Format_Gray:
{ {
ChangeValue<Standard_Byte> (theY, theX) = Standard_Byte(aColor.r() * 255.0f); *reinterpret_cast<Standard_Byte*>(theRawValue) = Standard_Byte(aColor.r() * 255.0f);
return; return;
} }
case Image_Format_Alpha: case Image_Format_Alpha:
{ {
ChangeValue<Standard_Byte> (theY, theX) = Standard_Byte(aColor.a() * 255.0f); *reinterpret_cast<Standard_Byte*>(theRawValue) = Standard_Byte(aColor.a() * 255.0f);
return; return;
} }
case Image_Format_Gray16: case Image_Format_Gray16:
{ {
ChangeValue<uint16_t> (theY, theX) = uint16_t(aColor.r() * 65535.0f); *reinterpret_cast<uint16_t*>(theRawValue) = uint16_t(aColor.r() * 65535.0f);
return; return;
} }
case Image_Format_UNKNOWN: case Image_Format_UNKNOWN:
@ -632,12 +668,14 @@ bool Image_PixMap::SwapRgbaBgra (Image_PixMap& theImage)
{ {
const bool toResetAlpha = theImage.Format() == Image_Format_BGR32 const bool toResetAlpha = theImage.Format() == Image_Format_BGR32
|| theImage.Format() == Image_Format_RGB32; || theImage.Format() == Image_Format_RGB32;
for (Standard_Size aSlice = 0; aSlice < theImage.SizeZ(); ++aSlice)
{
for (Standard_Size aRow = 0; aRow < theImage.SizeY(); ++aRow) for (Standard_Size aRow = 0; aRow < theImage.SizeY(); ++aRow)
{ {
for (Standard_Size aCol = 0; aCol < theImage.SizeX(); ++aCol) for (Standard_Size aCol = 0; aCol < theImage.SizeX(); ++aCol)
{ {
Image_ColorRGBA& aPixel = theImage.ChangeValue<Image_ColorRGBA> (aRow, aCol); Image_ColorRGBA& aPixel = theImage.ChangeValueXYZ<Image_ColorRGBA> (aCol, aRow, aSlice);
Image_ColorBGRA aPixelCopy = theImage.Value <Image_ColorBGRA> (aRow, aCol); Image_ColorBGRA aPixelCopy = theImage.ValueXYZ <Image_ColorBGRA> (aCol, aRow, aSlice);
aPixel.r() = aPixelCopy.r(); aPixel.r() = aPixelCopy.r();
aPixel.g() = aPixelCopy.g(); aPixel.g() = aPixelCopy.g();
aPixel.b() = aPixelCopy.b(); aPixel.b() = aPixelCopy.b();
@ -647,40 +685,47 @@ bool Image_PixMap::SwapRgbaBgra (Image_PixMap& theImage)
} }
} }
} }
}
return true; return true;
} }
case Image_Format_BGR: case Image_Format_BGR:
case Image_Format_RGB: case Image_Format_RGB:
{
for (Standard_Size aSlice = 0; aSlice < theImage.SizeZ(); ++aSlice)
{ {
for (Standard_Size aRow = 0; aRow < theImage.SizeY(); ++aRow) for (Standard_Size aRow = 0; aRow < theImage.SizeY(); ++aRow)
{ {
for (Standard_Size aCol = 0; aCol < theImage.SizeX(); ++aCol) for (Standard_Size aCol = 0; aCol < theImage.SizeX(); ++aCol)
{ {
Image_ColorRGB& aPixel = theImage.ChangeValue<Image_ColorRGB> (aRow, aCol); Image_ColorRGB& aPixel = theImage.ChangeValueXYZ<Image_ColorRGB> (aCol, aRow, aSlice);
Image_ColorBGR aPixelCopy = theImage.Value <Image_ColorBGR> (aRow, aCol); Image_ColorBGR aPixelCopy = theImage.ValueXYZ <Image_ColorBGR> (aCol, aRow, aSlice);
aPixel.r() = aPixelCopy.r(); aPixel.r() = aPixelCopy.r();
aPixel.g() = aPixelCopy.g(); aPixel.g() = aPixelCopy.g();
aPixel.b() = aPixelCopy.b(); aPixel.b() = aPixelCopy.b();
} }
} }
}
return true; return true;
} }
case Image_Format_BGRF: case Image_Format_BGRF:
case Image_Format_RGBF: case Image_Format_RGBF:
case Image_Format_BGRAF: case Image_Format_BGRAF:
case Image_Format_RGBAF: case Image_Format_RGBAF:
{
for (Standard_Size aSlice = 0; aSlice < theImage.SizeZ(); ++aSlice)
{ {
for (Standard_Size aRow = 0; aRow < theImage.SizeY(); ++aRow) for (Standard_Size aRow = 0; aRow < theImage.SizeY(); ++aRow)
{ {
for (Standard_Size aCol = 0; aCol < theImage.SizeX(); ++aCol) for (Standard_Size aCol = 0; aCol < theImage.SizeX(); ++aCol)
{ {
Image_ColorRGBF& aPixel = theImage.ChangeValue<Image_ColorRGBF> (aRow, aCol); Image_ColorRGBF& aPixel = theImage.ChangeValueXYZ<Image_ColorRGBF> (aCol, aRow, aSlice);
Image_ColorBGRF aPixelCopy = theImage.Value <Image_ColorBGRF> (aRow, aCol); Image_ColorBGRF aPixelCopy = theImage.ValueXYZ <Image_ColorBGRF> (aCol, aRow, aSlice);
aPixel.r() = aPixelCopy.r(); aPixel.r() = aPixelCopy.r();
aPixel.g() = aPixelCopy.g(); aPixel.g() = aPixelCopy.g();
aPixel.b() = aPixelCopy.b(); aPixel.b() = aPixelCopy.b();
} }
} }
}
return true; return true;
} }
default: return false; default: return false;
@ -697,33 +742,39 @@ void Image_PixMap::ToBlackWhite (Image_PixMap& theImage)
{ {
case Image_Format_Gray: case Image_Format_Gray:
case Image_Format_Alpha: case Image_Format_Alpha:
{
for (Standard_Size aSlice = 0; aSlice < theImage.SizeZ(); ++aSlice)
{ {
for (Standard_Size aRow = 0; aRow < theImage.SizeY(); ++aRow) for (Standard_Size aRow = 0; aRow < theImage.SizeY(); ++aRow)
{ {
for (Standard_Size aCol = 0; aCol < theImage.SizeX(); ++aCol) for (Standard_Size aCol = 0; aCol < theImage.SizeX(); ++aCol)
{ {
unsigned char& aPixel = theImage.ChangeValue<unsigned char> (aRow, aCol); uint8_t& aPixel = theImage.ChangeValueXYZ<uint8_t> (aCol, aRow, aSlice);
if (aPixel != 0) if (aPixel != 0)
{ {
aPixel = 255; aPixel = 255;
} }
} }
} }
}
break; break;
} }
case Image_Format_Gray16: case Image_Format_Gray16:
{
for (Standard_Size aSlice = 0; aSlice < theImage.SizeZ(); ++aSlice)
{ {
for (Standard_Size aRow = 0; aRow < theImage.SizeY(); ++aRow) for (Standard_Size aRow = 0; aRow < theImage.SizeY(); ++aRow)
{ {
for (Standard_Size aCol = 0; aCol < theImage.SizeX(); ++aCol) for (Standard_Size aCol = 0; aCol < theImage.SizeX(); ++aCol)
{ {
uint16_t& aPixel = theImage.ChangeValue<uint16_t> (aRow, aCol); uint16_t& aPixel = theImage.ChangeValueXYZ<uint16_t> (aCol, aRow, aSlice);
if (aPixel != 0) if (aPixel != 0)
{ {
aPixel = 65535; aPixel = 65535;
} }
} }
} }
}
break; break;
} }
case Image_Format_RGB: case Image_Format_RGB:
@ -733,12 +784,14 @@ void Image_PixMap::ToBlackWhite (Image_PixMap& theImage)
case Image_Format_RGBA: case Image_Format_RGBA:
case Image_Format_BGRA: case Image_Format_BGRA:
{ {
const NCollection_Vec3<unsigned char> aWhite24 (255, 255, 255); const NCollection_Vec3<uint8_t> aWhite24 (255, 255, 255);
for (Standard_Size aSlice = 0; aSlice < theImage.SizeZ(); ++aSlice)
{
for (Standard_Size aRow = 0; aRow < theImage.SizeY(); ++aRow) for (Standard_Size aRow = 0; aRow < theImage.SizeY(); ++aRow)
{ {
for (Standard_Size aCol = 0; aCol < theImage.SizeX(); ++aCol) for (Standard_Size aCol = 0; aCol < theImage.SizeX(); ++aCol)
{ {
NCollection_Vec3<unsigned char>& aPixel = theImage.ChangeValue< NCollection_Vec3<unsigned char> > (aRow, aCol); NCollection_Vec3<uint8_t>& aPixel = theImage.ChangeValueXYZ< NCollection_Vec3<uint8_t> > (aCol, aRow, aSlice);
if (aPixel[0] != 0 if (aPixel[0] != 0
|| aPixel[1] != 0 || aPixel[1] != 0
|| aPixel[2] != 0) || aPixel[2] != 0)
@ -747,22 +800,27 @@ void Image_PixMap::ToBlackWhite (Image_PixMap& theImage)
} }
} }
} }
}
break; break;
} }
default: default:
{ {
const Quantity_ColorRGBA aWhiteRgba (1.0f, 1.0f, 1.0f, 1.0f); const Quantity_ColorRGBA aWhiteRgba (1.0f, 1.0f, 1.0f, 1.0f);
for (Standard_Size aSlice = 0; aSlice < theImage.SizeZ(); ++aSlice)
{
for (Standard_Size aRow = 0; aRow < theImage.SizeY(); ++aRow) for (Standard_Size aRow = 0; aRow < theImage.SizeY(); ++aRow)
{ {
for (Standard_Size aCol = 0; aCol < theImage.SizeX(); ++aCol) for (Standard_Size aCol = 0; aCol < theImage.SizeX(); ++aCol)
{ {
const Quantity_ColorRGBA aPixelRgba = theImage.PixelColor (Standard_Integer(aCol), Standard_Integer(aRow)); Standard_Byte* aRawPixel = theImage.ChangeRawValueXYZ (aCol, aRow, aSlice);
const Quantity_ColorRGBA aPixelRgba = ColorFromRawPixel (aRawPixel, theImage.Format());
const NCollection_Vec4<float>& aPixel = aPixelRgba; const NCollection_Vec4<float>& aPixel = aPixelRgba;
if (aPixel[0] != 0.0f if (aPixel[0] != 0.0f
|| aPixel[1] != 0.0f || aPixel[1] != 0.0f
|| aPixel[2] != 0.0f) || aPixel[2] != 0.0f)
{ {
theImage.SetPixelColor (int(aCol), int(aRow), aWhiteRgba); ColorToRawPixel (aRawPixel, theImage.Format(), aWhiteRgba);
}
} }
} }
} }
@ -772,7 +830,7 @@ void Image_PixMap::ToBlackWhite (Image_PixMap& theImage)
} }
// ======================================================================= // =======================================================================
// function : InitCopy // function : FlipY
// purpose : // purpose :
// ======================================================================= // =======================================================================
bool Image_PixMap::FlipY (Image_PixMap& theImage) bool Image_PixMap::FlipY (Image_PixMap& theImage)
@ -793,13 +851,16 @@ bool Image_PixMap::FlipY (Image_PixMap& theImage)
// for odd height middle row should be left as is // for odd height middle row should be left as is
Standard_Size aNbRowsHalf = theImage.SizeY() / 2; Standard_Size aNbRowsHalf = theImage.SizeY() / 2;
for (Standard_Size aSlice = 0; aSlice < theImage.SizeZ(); ++aSlice)
{
for (Standard_Size aRowT = 0, aRowB = theImage.SizeY() - 1; aRowT < aNbRowsHalf; ++aRowT, --aRowB) for (Standard_Size aRowT = 0, aRowB = theImage.SizeY() - 1; aRowT < aNbRowsHalf; ++aRowT, --aRowB)
{ {
Standard_Byte* aTop = theImage.ChangeRow (aRowT); Standard_Byte* aTop = theImage.ChangeSliceRow (aSlice, aRowT);
Standard_Byte* aBot = theImage.ChangeRow (aRowB); Standard_Byte* aBot = theImage.ChangeSliceRow (aSlice, aRowB);
memcpy (aTmp.ChangeData(), aTop, aRowSize); memcpy (aTmp.ChangeData(), aTop, aRowSize);
memcpy (aTop, aBot, aRowSize); memcpy (aTop, aBot, aRowSize);
memcpy (aBot, aTmp.Data(), aRowSize); memcpy (aBot, aTmp.Data(), aRowSize);
} }
}
return true; return true;
} }

View File

@ -35,6 +35,9 @@ public:
return !aUnion.myChar[0]; return !aUnion.myChar[0];
} }
//! Return bytes reserved for one pixel (may include extra bytes for alignment).
Standard_EXPORT static Standard_Size SizePixelBytes (const Image_Format thePixelFormat);
//! Auxiliary method for swapping bytes between RGB and BGR formats. //! Auxiliary method for swapping bytes between RGB and BGR formats.
//! This method modifies the image data but does not change pixel format! //! This method modifies the image data but does not change pixel format!
//! Method will fail if pixel format is not one of the following: //! Method will fail if pixel format is not one of the following:
@ -60,6 +63,25 @@ public:
//! Return string representation of compressed pixel format. //! Return string representation of compressed pixel format.
Standard_EXPORT static Standard_CString ImageFormatToString (Image_CompressedFormat theFormat); Standard_EXPORT static Standard_CString ImageFormatToString (Image_CompressedFormat theFormat);
//! Convert raw pixel value into Quantity_ColorRGBA. This function is relatively slow.
//! @param[in] theRawValue pointer to pixel definition
//! @param[in] theFormat pixel format
//! @param[in] theToLinearize when TRUE, the color stored in non-linear color space (e.g. Image_Format_RGB) will be linearized
//! @return the pixel color
Standard_EXPORT static Quantity_ColorRGBA ColorFromRawPixel (const Standard_Byte* theRawValue,
const Image_Format theFormat,
const Standard_Boolean theToLinearize = false);
//! Set raw pixel value from Quantity_ColorRGBA. This function is relatively slow.
//! @param[out] theRawValue pointer to pixel definition to modify
//! @param[in] theFormat pixel format
//! @param[in] theColor color value to convert from
//! @param[in] theToDeLinearize when TRUE, the gamma correction will be applied for storing in non-linear color space (e.g. Image_Format_RGB)
Standard_EXPORT static void ColorToRawPixel (Standard_Byte* theRawValue,
const Image_Format theFormat,
const Quantity_ColorRGBA& theColor,
const Standard_Boolean theToDeLinearize = false);
public: // high-level API public: // high-level API
//! Return pixel format. //! Return pixel format.
@ -71,18 +93,30 @@ public: // high-level API
//! (e.g. ImgGray and ImgAlpha). //! (e.g. ImgGray and ImgAlpha).
Standard_EXPORT void SetFormat (const Image_Format thePixelFormat); Standard_EXPORT void SetFormat (const Image_Format thePixelFormat);
//! Return image width in pixels //! Return image width in pixels.
Standard_Size Width() const { return myData.SizeX; } Standard_Size Width() const { return myData.SizeX; }
//! Return image height in pixels //! Return image height in pixels.
Standard_Size Height() const { return myData.SizeY; } Standard_Size Height() const { return myData.SizeY; }
//! Return image width in pixels //! Return image depth in pixels.
Standard_Size Depth() const { return myData.SizeZ; }
//! Return image width in pixels.
Standard_Size SizeX() const { return myData.SizeX; } Standard_Size SizeX() const { return myData.SizeX; }
//! Return image height in pixels //! Return image height in pixels.
Standard_Size SizeY() const { return myData.SizeY; } Standard_Size SizeY() const { return myData.SizeY; }
//! Return image depth in pixels.
Standard_Size SizeZ() const { return myData.SizeZ; }
//! Return image width x height x depth in pixels.
NCollection_Vec3<Standard_Size> SizeXYZ() const
{
return NCollection_Vec3<Standard_Size> (myData.SizeX, myData.SizeY, myData.SizeZ);
}
//! Return width / height. //! Return width / height.
Standard_Real Ratio() const Standard_Real Ratio() const
{ {
@ -100,38 +134,60 @@ public: // high-level API
//! Returns the pixel color. This function is relatively slow. //! Returns the pixel color. This function is relatively slow.
//! Beware that this method takes coordinates in opposite order in contrast to ::Value() and ::ChangeValue(). //! Beware that this method takes coordinates in opposite order in contrast to ::Value() and ::ChangeValue().
//! @param theX [in] column index from left //! @param[in] theX column index from left, starting from 0
//! @param theY [in] row index from top //! @param[in] theY row index from top, starting from 0
//! @param theToLinearize [in] when TRUE, the color stored in non-linear color space (e.g. Image_Format_RGB) will be linearized //! @param[in] theToLinearize when TRUE, the color stored in non-linear color space (e.g. Image_Format_RGB) will be linearized
//! @return the pixel color //! @return the pixel color
Standard_EXPORT Quantity_ColorRGBA PixelColor (const Standard_Integer theX, Quantity_ColorRGBA PixelColor (Standard_Integer theX,
const Standard_Integer theY, Standard_Integer theY,
const Standard_Boolean theToLinearize = Standard_False) const; Standard_Boolean theToLinearize = false) const
{
if (IsEmpty()
|| theX < 0 || (Standard_Size )theX >= SizeX()
|| theY < 0 || (Standard_Size )theY >= SizeY())
{
return Quantity_ColorRGBA (0.0f, 0.0f, 0.0f, 0.0f); // transparent
}
const Standard_Byte* aRawPixel = RawValueXY (theX, theY);
return ColorFromRawPixel (aRawPixel, myImgFormat, theToLinearize);
}
//! Sets the pixel color. This function is relatively slow. //! Sets the pixel color. This function is relatively slow.
//! Beware that this method takes coordinates in opposite order in contrast to ::Value() and ::ChangeValue(). //! Beware that this method takes coordinates in opposite order in contrast to ::Value() and ::ChangeValue().
//! @param theX [in] column index from left //! @param[in] theX column index from left
//! @param theY [in] row index from top //! @param[in] theY row index from top
//! @param theColor [in] color to store //! @param[in] theColor color to store
//! @param theToDeLinearize [in] when TRUE, the gamma correction will be applied for storing in non-linear color space (e.g. Image_Format_RGB) //! @param[in] theToDeLinearize when TRUE, the gamma correction will be applied for storing in non-linear color space (e.g. Image_Format_RGB)
void SetPixelColor (const Standard_Integer theX, void SetPixelColor (const Standard_Integer theX,
const Standard_Integer theY, const Standard_Integer theY,
const Quantity_Color& theColor, const Quantity_Color& theColor,
const Standard_Boolean theToDeLinearize = Standard_False) const Standard_Boolean theToDeLinearize = false)
{ {
SetPixelColor (theX, theY, Quantity_ColorRGBA (theColor, 1.0f), theToDeLinearize); SetPixelColor (theX, theY, Quantity_ColorRGBA (theColor, 1.0f), theToDeLinearize);
} }
//! Sets the pixel color. This function is relatively slow. //! Sets the pixel color. This function is relatively slow.
//! Beware that this method takes coordinates in opposite order in contrast to ::Value() and ::ChangeValue(). //! Beware that this method takes coordinates in opposite order in contrast to ::Value() and ::ChangeValue().
//! @param theX [in] column index from left //! @param[in] theX column index from left
//! @param theY [in] row index from top //! @param[in] theY row index from top
//! @param theColor [in] color to store //! @param[in] theColor color to store
//! @param theToDeLinearize [in] when TRUE, the gamma correction will be applied for storing in non-linear color space (e.g. Image_Format_RGB) //! @param[in] theToDeLinearize when TRUE, the gamma correction will be applied for storing in non-linear color space (e.g. Image_Format_RGB)
Standard_EXPORT void SetPixelColor (const Standard_Integer theX, void SetPixelColor (const Standard_Integer theX,
const Standard_Integer theY, const Standard_Integer theY,
const Quantity_ColorRGBA& theColor, const Quantity_ColorRGBA& theColor,
const Standard_Boolean theToDeLinearize = Standard_False); const Standard_Boolean theToDeLinearize = false)
{
if (IsEmpty()
|| theX < 0 || Standard_Size(theX) >= SizeX()
|| theY < 0 || Standard_Size(theY) >= SizeY())
{
return;
}
Standard_Byte* aRawPixel = ChangeRawValueXY (theX, theY);
ColorToRawPixel (aRawPixel, myImgFormat, theColor, theToDeLinearize);
}
//! Initialize image plane as wrapper over alien data. //! Initialize image plane as wrapper over alien data.
//! Data will not be copied! Notice that caller should ensure //! Data will not be copied! Notice that caller should ensure
@ -156,15 +212,42 @@ public: // high-level API
//! Initialize image plane with required dimensions. //! Initialize image plane with required dimensions.
//! Buffer will be zeroed (black color for most formats). //! Buffer will be zeroed (black color for most formats).
Standard_EXPORT bool InitZero (Image_Format thePixelFormat, bool InitZero (Image_Format thePixelFormat,
const Standard_Size theSizeX, const Standard_Size theSizeX,
const Standard_Size theSizeY, const Standard_Size theSizeY,
const Standard_Size theSizeRowBytes = 0, const Standard_Size theSizeRowBytes = 0,
const Standard_Byte theValue = 0); const Standard_Byte theValue = 0)
{
return InitZero3D (thePixelFormat, NCollection_Vec3<Standard_Size> (theSizeX, theSizeY, 1), theSizeRowBytes, theValue);
}
//! Method correctly deallocate internal buffer. //! Method correctly deallocate internal buffer.
Standard_EXPORT virtual void Clear(); Standard_EXPORT virtual void Clear();
public:
//! Initialize 2D/3D image as wrapper over alien data.
//! Data will not be copied! Notice that caller should ensure
//! that data pointer will not be released during this wrapper lifetime.
//! You may call InitCopy() to perform data copying.
Standard_EXPORT virtual bool InitWrapper3D (Image_Format thePixelFormat,
Standard_Byte* theDataPtr,
const NCollection_Vec3<Standard_Size>& theSizeXYZ,
const Standard_Size theSizeRowBytes = 0);
//! Initialize 2D/3D image with required dimensions.
//! Memory will be left uninitialized (performance trick).
Standard_EXPORT virtual bool InitTrash3D (Image_Format thePixelFormat,
const NCollection_Vec3<Standard_Size>& theSizeXYZ,
const Standard_Size theSizeRowBytes = 0);
//! Initialize 2D/3D image with required dimensions.
//! Buffer will be zeroed (black color for most formats).
Standard_EXPORT bool InitZero3D (Image_Format thePixelFormat,
const NCollection_Vec3<Standard_Size>& theSizeXYZ,
const Standard_Size theSizeRowBytes = 0,
const Standard_Byte theValue = 0);
public: //! @name low-level API for batch-processing (pixels reading / comparison / modification) public: //! @name low-level API for batch-processing (pixels reading / comparison / modification)
//! Returns TRUE if image data is stored from Top to the Down. //! Returns TRUE if image data is stored from Top to the Down.
@ -176,105 +259,106 @@ public: //! @name low-level API for batch-processing (pixels reading / compariso
//! convert input row-index to apply this flag! //! convert input row-index to apply this flag!
//! You should use this flag only if interconnect with alien APIs and buffers. //! You should use this flag only if interconnect with alien APIs and buffers.
//! @return true if image data is top-down //! @return true if image data is top-down
inline bool IsTopDown() const bool IsTopDown() const { return myData.TopToDown == 1; }
{
return myData.TopToDown == 1;
}
//! Setup scanlines order in memory - top-down or bottom-up. //! Setup scanlines order in memory - top-down or bottom-up.
//! Drawers should explicitly specify this value if current state IsTopDown() was ignored! //! Drawers should explicitly specify this value if current state IsTopDown() was ignored!
//! @param theIsTopDown top-down flag //! @param theIsTopDown top-down flag
inline void SetTopDown (const bool theIsTopDown) void SetTopDown (const bool theIsTopDown) { myData.SetTopDown (theIsTopDown); }
{
myData.SetTopDown (theIsTopDown);
}
//! Returns +1 if scanlines ordered in Top->Down order in memory and -1 otherwise. //! Returns +1 if scanlines ordered in Top->Down order in memory and -1 otherwise.
//! @return scanline increment for Top->Down iteration //! @return scanline increment for Top->Down iteration
inline Standard_Size TopDownInc() const Standard_Size TopDownInc() const { return myData.TopToDown; }
//! Return data pointer for low-level operations (copying entire buffer, parsing with extra tools etc.).
const Standard_Byte* Data() const { return myData.Data(); }
//! Return data pointer for low-level operations (copying entire buffer, parsing with extra tools etc.).
Standard_Byte* ChangeData() { return myData.ChangeData(); }
//! Return data pointer to requested row (first column).
//! Indexation starts from 0.
const Standard_Byte* Row (Standard_Size theRow) const { return myData.Row (theRow); }
//! Return data pointer to requested row (first column).
//! Indexation starts from 0.
Standard_Byte* ChangeRow (Standard_Size theRow) { return myData.ChangeRow (theRow); }
//! Return data pointer to requested 2D slice.
//! Indexation starts from 0.
const Standard_Byte* Slice (Standard_Size theSlice) const { return myData.Slice (theSlice); }
//! Return data pointer to requested 2D slice.
//! Indexation starts from 0.
Standard_Byte* ChangeSlice (Standard_Size theSlice) { return myData.ChangeSlice (theSlice); }
//! Return data pointer to requested row (first column).
//! Indexation starts from 0.
const Standard_Byte* SliceRow (Standard_Size theSlice,
Standard_Size theRow) const
{ {
return myData.TopToDown; return myData.SliceRow (theSlice, theRow);
} }
//! @return data pointer for low-level operations (copying entire buffer, parsing with extra tools etc.). //! Return data pointer to requested row (first column).
inline const Standard_Byte* Data() const //! Indexation starts from 0.
Standard_Byte* ChangeSliceRow (Standard_Size theSlice,
Standard_Size theRow)
{ {
return myData.Data(); return myData.ChangeSliceRow (theSlice, theRow);
} }
//! @return data pointer for low-level operations (copying entire buffer, parsing with extra tools etc.). //! Return bytes reserved for one pixel (may include extra bytes for alignment).
inline Standard_Byte* ChangeData() Standard_Size SizePixelBytes() const { return myData.SizeBPP; }
{
return myData.ChangeData();
}
//! @return data pointer to requested row (first column). //! Return bytes reserved per row.
inline const Standard_Byte* Row (const Standard_Size theRow) const
{
return myData.Row (theRow);
}
//! @return data pointer to requested row (first column).
inline Standard_Byte* ChangeRow (const Standard_Size theRow)
{
return myData.ChangeRow (theRow);
}
//! @return bytes reserved for one pixel (may include extra bytes for alignment).
inline Standard_Size SizePixelBytes() const
{
return myData.SizeBPP;
}
//! @return bytes reserved for one pixel (may include extra bytes for alignment).
Standard_EXPORT static Standard_Size SizePixelBytes (const Image_Format thePixelFormat);
//! @return bytes reserved per row.
//! Could be larger than needed to store packed row (extra bytes for alignment etc.). //! Could be larger than needed to store packed row (extra bytes for alignment etc.).
inline Standard_Size SizeRowBytes() const Standard_Size SizeRowBytes() const { return myData.SizeRowBytes; }
{
return myData.SizeRowBytes;
}
//! @return the extra bytes in the row. //! Return the extra bytes in the row.
inline Standard_Size RowExtraBytes() const Standard_Size RowExtraBytes() const
{ {
return SizeRowBytes() - SizeX() * SizePixelBytes(); return SizeRowBytes() - SizeX() * SizePixelBytes();
} }
//! Compute the maximal row alignment for current row size. //! Compute the maximal row alignment for current row size.
//! @return maximal row alignment in bytes (up to 16 bytes). //! @return maximal row alignment in bytes (up to 16 bytes).
inline Standard_Size MaxRowAligmentBytes() const Standard_Size MaxRowAligmentBytes() const { return myData.MaxRowAligmentBytes(); }
{
return myData.MaxRowAligmentBytes();
}
//! @return buffer size //! Return number of bytes per 2D slice.
inline Standard_Size SizeBytes() const Standard_Size SizeSliceBytes() const { return myData.SizeSliceBytes; }
{
return myData.Size(); //! Return buffer size
} Standard_Size SizeBytes() const { return myData.Size(); }
public:
//! Access image pixel with specified color type. //! Access image pixel with specified color type.
//! Indexation starts from 0.
//! This method does not perform any type checks - use on own risk (check Format() before)! //! This method does not perform any type checks - use on own risk (check Format() before)!
//! WARNING: Input parameters are defined in the decreasing majority following memory layout - e.g. row first, column next.
template <typename ColorType_t> template <typename ColorType_t>
inline const ColorType_t& Value (const Standard_Size theRow, const ColorType_t& Value (Standard_Size theRow,
const Standard_Size theCol) const Standard_Size theCol) const
{ {
return *reinterpret_cast<const ColorType_t*>(myData.Value (theRow, theCol)); return *reinterpret_cast<const ColorType_t*>(myData.Value (theRow, theCol));
} }
//! Access image pixel with specified color type. //! Access image pixel with specified color type.
//! Indexation starts from 0.
//! This method does not perform any type checks - use on own risk (check Format() before)! //! This method does not perform any type checks - use on own risk (check Format() before)!
//! WARNING: Input parameters are defined in the decreasing majority following memory layout - e.g. row first, column next.
template <typename ColorType_t> template <typename ColorType_t>
inline ColorType_t& ChangeValue (const Standard_Size theRow, ColorType_t& ChangeValue (Standard_Size theRow,
const Standard_Size theCol) Standard_Size theCol)
{ {
return *reinterpret_cast<ColorType_t* >(myData.ChangeValue (theRow, theCol)); return *reinterpret_cast<ColorType_t* >(myData.ChangeValue (theRow, theCol));
} }
//! Access image pixel as raw data pointer. //! Access image pixel as raw data pointer.
//! Indexation starts from 0.
//! This method does not perform any type checks - use on own risk (check Format() before)! //! This method does not perform any type checks - use on own risk (check Format() before)!
//! WARNING: Input parameters are defined in the decreasing majority following memory layout - e.g. row first, column next.
const Standard_Byte* RawValue (Standard_Size theRow, const Standard_Byte* RawValue (Standard_Size theRow,
Standard_Size theCol) const Standard_Size theCol) const
{ {
@ -282,13 +366,105 @@ public: //! @name low-level API for batch-processing (pixels reading / compariso
} }
//! Access image pixel as raw data pointer. //! Access image pixel as raw data pointer.
//! Indexation starts from 0.
//! This method does not perform any type checks - use on own risk (check Format() before)! //! This method does not perform any type checks - use on own risk (check Format() before)!
//! WARNING: Input parameters are defined in the decreasing majority following memory layout - e.g. row first, column next.
Standard_Byte* ChangeRawValue (Standard_Size theRow, Standard_Byte* ChangeRawValue (Standard_Size theRow,
Standard_Size theCol) Standard_Size theCol)
{ {
return myData.ChangeValue (theRow, theCol); return myData.ChangeValue (theRow, theCol);
} }
//! Access image pixel with specified color type.
//! Indexation starts from 0.
//! This method does not perform any type checks - use on own risk (check Format() before)!
//! WARNING: Input parameters are defined in traditional X, Y order.
template <typename ColorType_t>
const ColorType_t& ValueXY (Standard_Size theX,
Standard_Size theY) const
{
return *reinterpret_cast<const ColorType_t*>(myData.ValueXY (theX, theY));
}
//! Access image pixel with specified color type.
//! Indexation starts from 0.
//! This method does not perform any type checks - use on own risk (check Format() before)!
//! WARNING: Input parameters are defined in traditional X, Y order.
template <typename ColorType_t>
ColorType_t& ChangeValueXY (Standard_Size theX,
Standard_Size theY)
{
return *reinterpret_cast<ColorType_t* >(myData.ChangeValueXY (theX, theY));
}
//! Access image pixel as raw data pointer.
//! Indexation starts from 0.
//! This method does not perform any type checks - use on own risk (check Format() before)!
//! WARNING: Input parameters are defined in traditional X, Y order.
const Standard_Byte* RawValueXY (Standard_Size theX,
Standard_Size theY) const
{
return myData.ValueXY (theX, theY);
}
//! Access image pixel as raw data pointer.
//! Indexation starts from 0.
//! This method does not perform any type checks - use on own risk (check Format() before)!
//! WARNING: Input parameters are defined in traditional X, Y order.
Standard_Byte* ChangeRawValueXY (Standard_Size theX,
Standard_Size theY)
{
return myData.ChangeValueXY (theX, theY);
}
public:
//! Access image pixel with specified color type.
//! Indexation starts from 0.
//! This method does not perform any type checks - use on own risk (check Format() before)!
//! WARNING: Input parameters are defined in traditional X, Y, Z order.
template <typename ColorType_t>
const ColorType_t& ValueXYZ (Standard_Size theX,
Standard_Size theY,
Standard_Size theZ) const
{
return *reinterpret_cast<const ColorType_t*>(myData.ValueXYZ (theX, theY, theZ));
}
//! Access image pixel with specified color type.
//! Indexation starts from 0.
//! This method does not perform any type checks - use on own risk (check Format() before)!
//! WARNING: Input parameters are defined in traditional X, Y, Z order.
template <typename ColorType_t>
ColorType_t& ChangeValueXYZ (Standard_Size theX,
Standard_Size theY,
Standard_Size theZ)
{
return *reinterpret_cast<ColorType_t* >(myData.ChangeValueXYZ (theX, theY, theZ));
}
//! Access image pixel as raw data pointer.
//! Indexation starts from 0.
//! This method does not perform any type checks - use on own risk (check Format() before)!
//! WARNING: Input parameters are defined in traditional X, Y, Z order.
const Standard_Byte* RawValueXYZ (Standard_Size theX,
Standard_Size theY,
Standard_Size theZ) const
{
return myData.ValueXYZ (theX, theY, theZ);
}
//! Access image pixel as raw data pointer.
//! Indexation starts from 0.
//! This method does not perform any type checks - use on own risk (check Format() before)!
//! WARNING: Input parameters are defined in traditional X, Y, Z order.
Standard_Byte* ChangeRawValueXYZ (Standard_Size theX,
Standard_Size theY,
Standard_Size theZ)
{
return myData.ChangeValueXYZ (theX, theY, theZ);
}
public: public:
//! Convert 16-bit half-float value into 32-bit float (simple conversion). //! Convert 16-bit half-float value into 32-bit float (simple conversion).

View File

@ -18,6 +18,7 @@
#include <Image_Color.hxx> #include <Image_Color.hxx>
#include <NCollection_Buffer.hxx> #include <NCollection_Buffer.hxx>
#include <NCollection_Vec3.hxx>
//! Structure to manage image buffer. //! Structure to manage image buffer.
class Image_PixMapData : public NCollection_Buffer class Image_PixMapData : public NCollection_Buffer
@ -31,7 +32,9 @@ public:
SizeBPP (0), SizeBPP (0),
SizeX (0), SizeX (0),
SizeY (0), SizeY (0),
SizeZ (0),
SizeRowBytes (0), SizeRowBytes (0),
SizeSliceBytes (0),
TopToDown (Standard_Size(-1)) TopToDown (Standard_Size(-1))
{ {
// //
@ -44,16 +47,28 @@ public:
const Standard_Size theSizeY, const Standard_Size theSizeY,
const Standard_Size theSizeRowBytes, const Standard_Size theSizeRowBytes,
Standard_Byte* theDataPtr) Standard_Byte* theDataPtr)
{
return Init (theAlloc, theSizeBPP, NCollection_Vec3<Standard_Size> (theSizeX, theSizeY, 1), theSizeRowBytes, theDataPtr);
}
//! Initializer.
bool Init (const Handle(NCollection_BaseAllocator)& theAlloc,
const Standard_Size theSizeBPP,
const NCollection_Vec3<Standard_Size>& theSizeXYZ,
const Standard_Size theSizeRowBytes,
Standard_Byte* theDataPtr)
{ {
SetAllocator (theAlloc); // will free old data as well SetAllocator (theAlloc); // will free old data as well
myData = theDataPtr; myData = theDataPtr;
myTopRowPtr = NULL; myTopRowPtr = NULL;
SizeBPP = theSizeBPP; SizeBPP = theSizeBPP;
SizeX = theSizeX; SizeX = theSizeXYZ.x();
SizeY = theSizeY; SizeY = theSizeXYZ.y();
SizeRowBytes = theSizeRowBytes != 0 ? theSizeRowBytes : (theSizeX * theSizeBPP); SizeZ = theSizeXYZ.z();
mySize = SizeRowBytes * SizeY; SizeRowBytes = theSizeRowBytes != 0 ? theSizeRowBytes : (SizeX * theSizeBPP);
SizeSliceBytes = SizeRowBytes * SizeY;
mySize = SizeSliceBytes * SizeZ;
if (myData == NULL) if (myData == NULL)
{ {
Allocate (mySize); Allocate (mySize);
@ -71,35 +86,93 @@ public:
} }
} }
//! @return data pointer to requested row (first column). //! Return data pointer to requested row (first column).
inline const Standard_Byte* Row (const Standard_Size theRow) const const Standard_Byte* Row (const Standard_Size theRow) const
{ {
return myTopRowPtr + ptrdiff_t(SizeRowBytes * theRow * TopToDown); return myTopRowPtr + ptrdiff_t(SizeRowBytes * theRow * TopToDown);
} }
//! @return data pointer to requested row (first column). //! Return data pointer to requested row (first column).
inline Standard_Byte* ChangeRow (const Standard_Size theRow) Standard_Byte* ChangeRow (const Standard_Size theRow)
{ {
return myTopRowPtr + ptrdiff_t(SizeRowBytes * theRow * TopToDown); return myTopRowPtr + ptrdiff_t(SizeRowBytes * theRow * TopToDown);
} }
//! @return data pointer to requested position. //! Return data pointer to requested position.
inline const Standard_Byte* Value (const Standard_Size theRow, const Standard_Byte* Value (const Standard_Size theRow,
const Standard_Size theCol) const const Standard_Size theCol) const
{ {
return myTopRowPtr + ptrdiff_t(SizeRowBytes * theRow * TopToDown) + SizeBPP * theCol; return myTopRowPtr + ptrdiff_t(SizeRowBytes * theRow * TopToDown) + SizeBPP * theCol;
} }
//! @return data pointer to requested position. //! Return data pointer to requested position.
inline Standard_Byte* ChangeValue (const Standard_Size theRow, Standard_Byte* ChangeValue (Standard_Size theRow,
const Standard_Size theCol) Standard_Size theCol)
{ {
return myTopRowPtr + ptrdiff_t(SizeRowBytes * theRow * TopToDown) + SizeBPP * theCol; return myTopRowPtr + ptrdiff_t(SizeRowBytes * theRow * TopToDown) + SizeBPP * theCol;
} }
//! Return data pointer to requested position.
const Standard_Byte* ValueXY (Standard_Size theX,
Standard_Size theY) const
{
return myTopRowPtr + ptrdiff_t(SizeRowBytes * theY * TopToDown) + SizeBPP * theX;
}
//! Return data pointer to requested position.
Standard_Byte* ChangeValueXY (Standard_Size theX,
Standard_Size theY)
{
return myTopRowPtr + ptrdiff_t(SizeRowBytes * theY * TopToDown) + SizeBPP * theX;
}
public:
//! Return data pointer to requested 2D slice.
const Standard_Byte* Slice (Standard_Size theSlice) const
{
return myData + ptrdiff_t(SizeSliceBytes * theSlice);
}
//! Return data pointer to requested 2D slice.
Standard_Byte* ChangeSlice (Standard_Size theSlice)
{
return myData + ptrdiff_t(SizeSliceBytes * theSlice);
}
//! Return data pointer to requested row (first column).
const Standard_Byte* SliceRow (Standard_Size theSlice,
Standard_Size theRow) const
{
return myTopRowPtr + ptrdiff_t(SizeRowBytes * theRow * TopToDown) + ptrdiff_t(SizeSliceBytes * theSlice);
}
//! Return data pointer to requested row (first column).
Standard_Byte* ChangeSliceRow (Standard_Size theSlice,
Standard_Size theRow)
{
return myTopRowPtr + ptrdiff_t(SizeRowBytes * theRow * TopToDown) + ptrdiff_t(SizeSliceBytes * theSlice);
}
//! Return data pointer to requested position.
const Standard_Byte* ValueXYZ (Standard_Size theX,
Standard_Size theY,
Standard_Size theZ) const
{
return myTopRowPtr + ptrdiff_t(SizeRowBytes * theY * TopToDown) + SizeBPP * theX + ptrdiff_t(SizeSliceBytes * theZ);
}
//! Return data pointer to requested position.
Standard_Byte* ChangeValueXYZ (Standard_Size theX,
Standard_Size theY,
Standard_Size theZ)
{
return myTopRowPtr + ptrdiff_t(SizeRowBytes * theY * TopToDown) + SizeBPP * theX + ptrdiff_t(SizeSliceBytes * theZ);
}
//! Compute the maximal row alignment for current row size. //! Compute the maximal row alignment for current row size.
//! @return maximal row alignment in bytes (up to 16 bytes). //! @return maximal row alignment in bytes (up to 16 bytes).
inline Standard_Size MaxRowAligmentBytes() const Standard_Size MaxRowAligmentBytes() const
{ {
Standard_Size anAlignment = 2; Standard_Size anAlignment = 2;
for (; anAlignment <= 16; anAlignment <<= 1) for (; anAlignment <= 16; anAlignment <<= 1)
@ -115,7 +188,7 @@ public:
//! Setup scanlines order in memory - top-down or bottom-up. //! Setup scanlines order in memory - top-down or bottom-up.
//! Drawers should explicitly specify this value if current state IsTopDown() was ignored! //! Drawers should explicitly specify this value if current state IsTopDown() was ignored!
//! @param theIsTopDown top-down flag //! @param theIsTopDown top-down flag
inline void SetTopDown (const bool theIsTopDown) void SetTopDown (const bool theIsTopDown)
{ {
TopToDown = (theIsTopDown ? 1 : Standard_Size(-1)); TopToDown = (theIsTopDown ? 1 : Standard_Size(-1));
myTopRowPtr = ((TopToDown == 1 || myData == NULL) myTopRowPtr = ((TopToDown == 1 || myData == NULL)
@ -131,13 +204,14 @@ public:
Standard_Size SizeBPP; //!< bytes per pixel Standard_Size SizeBPP; //!< bytes per pixel
Standard_Size SizeX; //!< width in pixels Standard_Size SizeX; //!< width in pixels
Standard_Size SizeY; //!< height in pixels Standard_Size SizeY; //!< height in pixels
Standard_Size SizeZ; //!< depth in pixels
Standard_Size SizeRowBytes; //!< number of bytes per line (in most cases equal to 3 * sizeX) Standard_Size SizeRowBytes; //!< number of bytes per line (in most cases equal to 3 * sizeX)
Standard_Size SizeSliceBytes; //!< number of bytes per 2D slice
Standard_Size TopToDown; //!< image scanlines direction in memory from Top to the Down Standard_Size TopToDown; //!< image scanlines direction in memory from Top to the Down
public: public:
DEFINE_STANDARD_RTTI_INLINE(Image_PixMapData,NCollection_Buffer) // Type definition DEFINE_STANDARD_RTTIEXT(Image_PixMapData, NCollection_Buffer)
}; };

View File

@ -70,9 +70,10 @@ class MeshVS_ImageTexture2D : public Graphic3d_Texture2D
{ {
public: public:
MeshVS_ImageTexture2D (const Handle(Image_PixMap)& theImg) : Graphic3d_Texture2D (theImg, Graphic3d_TOT_2D) MeshVS_ImageTexture2D (const Handle(Image_PixMap)& theImg)
: Graphic3d_Texture2D (theImg, Graphic3d_TypeOfTexture_2D)
{ {
myParams->SetModulate (Standard_True); myParams->SetModulate (true);
myParams->SetFilter (Graphic3d_TOTF_BILINEAR); myParams->SetFilter (Graphic3d_TOTF_BILINEAR);
} }
@ -81,9 +82,6 @@ public:
DEFINE_STANDARD_RTTI_INLINE(MeshVS_ImageTexture2D,Graphic3d_Texture2D) DEFINE_STANDARD_RTTI_INLINE(MeshVS_ImageTexture2D,Graphic3d_Texture2D)
}; };
DEFINE_STANDARD_HANDLE (MeshVS_ImageTexture2D, Graphic3d_Texture2D)
//================================================================ //================================================================
// Function : getNearestPow2 // Function : getNearestPow2
// Purpose : Returns the nearest power of two greater than the // Purpose : Returns the nearest power of two greater than the

View File

@ -261,13 +261,13 @@ void OpenGl_AspectsSprite::build (const Handle(OpenGl_Context)& theCtx,
if (!hadAlreadyRGBA) if (!hadAlreadyRGBA)
{ {
aSprite->Init (theCtx, *anImage, Graphic3d_TOT_2D, true); aSprite->Init (theCtx, *anImage, Graphic3d_TypeOfTexture_2D, true);
} }
if (!hadAlreadyAlpha) if (!hadAlreadyAlpha)
{ {
if (Handle(Image_PixMap) anImageA = aSprite->GetFormat() != GL_ALPHA ? aNewMarkerImage->GetImageAlpha() : Handle(Image_PixMap)()) if (Handle(Image_PixMap) anImageA = aSprite->GetFormat() != GL_ALPHA ? aNewMarkerImage->GetImageAlpha() : Handle(Image_PixMap)())
{ {
aSpriteA->Init (theCtx, *anImageA, Graphic3d_TOT_2D, true); aSpriteA->Init (theCtx, *anImageA, Graphic3d_TypeOfTexture_2D, true);
} }
} }
} }

View File

@ -2136,13 +2136,13 @@ Handle(OpenGl_TextureSet) OpenGl_Context::BindTextures (const Handle(OpenGl_Text
myTextureRgbaWhite = new OpenGl_Texture(); myTextureRgbaWhite = new OpenGl_Texture();
Image_PixMap anImage; Image_PixMap anImage;
anImage.InitZero (Image_Format_RGBA, 2, 2, 0, (Standard_Byte )0); anImage.InitZero (Image_Format_RGBA, 2, 2, 0, (Standard_Byte )0);
if (!myTextureRgbaBlack->Init (this, OpenGl_TextureFormat::Create<GLubyte, 4>(), Graphic3d_Vec2i (2, 2), Graphic3d_TOT_2D, &anImage)) if (!myTextureRgbaBlack->Init (this, OpenGl_TextureFormat::Create<GLubyte, 4>(), Graphic3d_Vec2i (2, 2), Graphic3d_TypeOfTexture_2D, &anImage))
{ {
PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_PORTABILITY, 0, GL_DEBUG_SEVERITY_HIGH, PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_PORTABILITY, 0, GL_DEBUG_SEVERITY_HIGH,
"Error: unable to create unit mock PBR texture map."); "Error: unable to create unit mock PBR texture map.");
} }
anImage.InitZero (Image_Format_RGBA, 2, 2, 0, (Standard_Byte )255); anImage.InitZero (Image_Format_RGBA, 2, 2, 0, (Standard_Byte )255);
if (!myTextureRgbaWhite->Init (this, OpenGl_TextureFormat::Create<GLubyte, 4>(), Graphic3d_Vec2i (2, 2), Graphic3d_TOT_2D, &anImage)) if (!myTextureRgbaWhite->Init (this, OpenGl_TextureFormat::Create<GLubyte, 4>(), Graphic3d_Vec2i (2, 2), Graphic3d_TypeOfTexture_2D, &anImage))
{ {
PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_PORTABILITY, 0, GL_DEBUG_SEVERITY_HIGH, PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_PORTABILITY, 0, GL_DEBUG_SEVERITY_HIGH,
"Error: unable to create normal mock PBR texture map."); "Error: unable to create normal mock PBR texture map.");

View File

@ -147,7 +147,7 @@ bool OpenGl_Font::createTexture (const Handle(OpenGl_Context)& theCtx)
Image_PixMap aBlackImg; Image_PixMap aBlackImg;
if (!aBlackImg.InitZero (Image_Format_Alpha, Standard_Size(aTextureSizeX), Standard_Size(aTextureSizeY)) if (!aBlackImg.InitZero (Image_Format_Alpha, Standard_Size(aTextureSizeX), Standard_Size(aTextureSizeY))
|| !aTexture->Init (theCtx, aBlackImg, Graphic3d_TOT_2D, true)) // myTextureFormat || !aTexture->Init (theCtx, aBlackImg, Graphic3d_TypeOfTexture_2D, true)) // myTextureFormat
{ {
theCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_ERROR, 0, GL_DEBUG_SEVERITY_HIGH, theCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_ERROR, 0, GL_DEBUG_SEVERITY_HIGH,
TCollection_AsciiString ("New texture initialization of size ") TCollection_AsciiString ("New texture initialization of size ")

View File

@ -277,7 +277,7 @@ Standard_Boolean OpenGl_FrameBuffer::Init (const Handle(OpenGl_Context)& theGlCo
const GLint aColorFormat = myColorFormats (aColorBufferIdx); const GLint aColorFormat = myColorFormats (aColorBufferIdx);
const OpenGl_TextureFormat aFormat = OpenGl_TextureFormat::FindSizedFormat (theGlContext, aColorFormat); const OpenGl_TextureFormat aFormat = OpenGl_TextureFormat::FindSizedFormat (theGlContext, aColorFormat);
if (!aFormat.IsValid() if (!aFormat.IsValid()
|| !aColorTexture->Init (theGlContext, aFormat, Graphic3d_Vec2i (aSizeX, aSizeY), Graphic3d_TOT_2D)) || !aColorTexture->Init (theGlContext, aFormat, Graphic3d_Vec2i (aSizeX, aSizeY), Graphic3d_TypeOfTexture_2D))
{ {
Release (theGlContext.get()); Release (theGlContext.get());
return Standard_False; return Standard_False;
@ -415,7 +415,7 @@ Standard_Boolean OpenGl_FrameBuffer::Init (const Handle(OpenGl_Context)& theGlCo
const GLint aColorFormat = myColorFormats (aColorBufferIdx); const GLint aColorFormat = myColorFormats (aColorBufferIdx);
const OpenGl_TextureFormat aFormat = OpenGl_TextureFormat::FindSizedFormat (theGlContext, aColorFormat); const OpenGl_TextureFormat aFormat = OpenGl_TextureFormat::FindSizedFormat (theGlContext, aColorFormat);
if (!aFormat.IsValid() if (!aFormat.IsValid()
|| !aColorTexture->Init (theGlContext, aFormat, Graphic3d_Vec2i (aSizeX, aSizeY), Graphic3d_TOT_2D)) || !aColorTexture->Init (theGlContext, aFormat, Graphic3d_Vec2i (aSizeX, aSizeY), Graphic3d_TypeOfTexture_2D))
{ {
Release (theGlContext.operator->()); Release (theGlContext.operator->());
return Standard_False; return Standard_False;
@ -426,7 +426,7 @@ Standard_Boolean OpenGl_FrameBuffer::Init (const Handle(OpenGl_Context)& theGlCo
// instead of just trying to create such texture // instead of just trying to create such texture
const OpenGl_TextureFormat aDepthFormat = OpenGl_TextureFormat::FindSizedFormat (theGlContext, myDepthFormat); const OpenGl_TextureFormat aDepthFormat = OpenGl_TextureFormat::FindSizedFormat (theGlContext, myDepthFormat);
if (aDepthFormat.IsValid() if (aDepthFormat.IsValid()
&& !myDepthStencilTexture->Init (theGlContext, aDepthFormat, Graphic3d_Vec2i (aSizeX, aSizeY), Graphic3d_TOT_2D)) && !myDepthStencilTexture->Init (theGlContext, aDepthFormat, Graphic3d_Vec2i (aSizeX, aSizeY), Graphic3d_TypeOfTexture_2D))
{ {
theGlContext->PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_PORTABILITY, 0, GL_DEBUG_SEVERITY_HIGH, theGlContext->PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_PORTABILITY, 0, GL_DEBUG_SEVERITY_HIGH,
"Warning! Depth textures are not supported by hardware!"); "Warning! Depth textures are not supported by hardware!");

View File

@ -290,7 +290,7 @@ bool OpenGl_PBREnvironment::initTextures (const Handle(OpenGl_Context)& theCtx)
// NVIDIA's driver didn't work properly with 3 channel texture for diffuse SH coefficients so that alpha channel has been added // NVIDIA's driver didn't work properly with 3 channel texture for diffuse SH coefficients so that alpha channel has been added
if (!myIBLMaps[OpenGl_TypeOfIBLMap_DiffuseSH].Init (theCtx, if (!myIBLMaps[OpenGl_TypeOfIBLMap_DiffuseSH].Init (theCtx,
OpenGl_TextureFormat::FindFormat (theCtx, Image_Format_RGBAF, false), OpenGl_TextureFormat::FindFormat (theCtx, Image_Format_RGBAF, false),
Graphic3d_Vec2i (9, 1), Graphic3d_TOT_2D)) Graphic3d_Vec2i (9, 1), Graphic3d_TypeOfTexture_2D))
{ {
Message::SendFail() << "OpenGl_PBREnvironment, DiffuseSH texture creation failed"; Message::SendFail() << "OpenGl_PBREnvironment, DiffuseSH texture creation failed";
return false; return false;
@ -305,7 +305,7 @@ bool OpenGl_PBREnvironment::initTextures (const Handle(OpenGl_Context)& theCtx)
if (!myIBLMaps[OpenGl_TypeOfIBLMap_DiffuseFallback].Init (theCtx, if (!myIBLMaps[OpenGl_TypeOfIBLMap_DiffuseFallback].Init (theCtx,
OpenGl_TextureFormat::FindFormat (theCtx, Image_Format_RGBA, false), OpenGl_TextureFormat::FindFormat (theCtx, Image_Format_RGBA, false),
Graphic3d_Vec2i (10, 4), Graphic3d_TOT_2D)) Graphic3d_Vec2i (10, 4), Graphic3d_TypeOfTexture_2D))
{ {
Message::SendFail() << "OpenGl_PBREnvironment, DiffuseFallback texture creation failed"; Message::SendFail() << "OpenGl_PBREnvironment, DiffuseFallback texture creation failed";
return false; return false;
@ -432,7 +432,7 @@ bool OpenGl_PBREnvironment::processDiffIBLMap (const Handle(OpenGl_Context)& the
{ {
if (!myIBLMaps[OpenGl_TypeOfIBLMap_DiffuseSH].Init (theCtx, if (!myIBLMaps[OpenGl_TypeOfIBLMap_DiffuseSH].Init (theCtx,
OpenGl_TextureFormat::FindFormat (theCtx, Image_Format_RGBAF, false), OpenGl_TextureFormat::FindFormat (theCtx, Image_Format_RGBAF, false),
Graphic3d_Vec2i (9, 1), Graphic3d_TOT_2D, &anImageF)) Graphic3d_Vec2i (9, 1), Graphic3d_TypeOfTexture_2D, &anImageF))
{ {
Message::SendFail() << "OpenGl_PBREnvironment, DiffuseSH texture update failed"; Message::SendFail() << "OpenGl_PBREnvironment, DiffuseSH texture update failed";
return false; return false;

View File

@ -378,7 +378,11 @@ void OpenGl_Sampler::applyGlobalTextureParams (const Handle(OpenGl_Context)& the
theCtx->core11fwd->glEnable (GL_TEXTURE_2D); theCtx->core11fwd->glEnable (GL_TEXTURE_2D);
break; break;
} }
default: break; case GL_TEXTURE_3D:
default:
{
break;
}
} }
} }
@ -428,6 +432,10 @@ void OpenGl_Sampler::resetGlobalTextureParams (const Handle(OpenGl_Context)& the
theCtx->core11fwd->glDisable (GL_TEXTURE_2D); theCtx->core11fwd->glDisable (GL_TEXTURE_2D);
break; break;
} }
default: break; case GL_TEXTURE_3D:
default:
{
break;
}
} }
} }

View File

@ -69,12 +69,6 @@ static Standard_Integer computeUpperMipMapLevel (Standard_Integer theSize)
} }
} }
//! Compute the upper mipmap level for complete mipmap set (e.g. till the 1x1 level).
static Standard_Integer computeUpperMipMapLevel (Standard_Integer theSizeX, Standard_Integer theSizeY)
{
return computeUpperMipMapLevel (Max (theSizeX, theSizeY));
}
//! Compute size of the smallest defined mipmap level (for verbose messages). //! Compute size of the smallest defined mipmap level (for verbose messages).
static Graphic3d_Vec2i computeSmallestMipMapSize (const Graphic3d_Vec2i& theBaseSize, Standard_Integer theMaxLevel) static Graphic3d_Vec2i computeSmallestMipMapSize (const Graphic3d_Vec2i& theBaseSize, Standard_Integer theMaxLevel)
{ {
@ -105,9 +99,6 @@ OpenGl_Texture::OpenGl_Texture (const TCollection_AsciiString& theResourceId,
myRevision (0), myRevision (0),
myTextureId (NO_TEXTURE), myTextureId (NO_TEXTURE),
myTarget (GL_TEXTURE_2D), myTarget (GL_TEXTURE_2D),
mySizeX (0),
mySizeY (0),
mySizeZ (0),
myTextFormat (GL_RGBA), myTextFormat (GL_RGBA),
mySizedFormat(GL_RGBA8), mySizedFormat(GL_RGBA8),
myNbSamples (1), myNbSamples (1),
@ -169,7 +160,7 @@ void OpenGl_Texture::Release (OpenGl_Context* theGlCtx)
theGlCtx->core11fwd->glDeleteTextures (1, &myTextureId); theGlCtx->core11fwd->glDeleteTextures (1, &myTextureId);
} }
myTextureId = NO_TEXTURE; myTextureId = NO_TEXTURE;
mySizeX = mySizeY = mySizeZ = 0; mySize.SetValues (0, 0, 0);
} }
// ======================================================================= // =======================================================================
@ -231,12 +222,13 @@ bool OpenGl_Texture::InitSamplerObject (const Handle(OpenGl_Context)& theCtx)
// ======================================================================= // =======================================================================
bool OpenGl_Texture::Init (const Handle(OpenGl_Context)& theCtx, bool OpenGl_Texture::Init (const Handle(OpenGl_Context)& theCtx,
const OpenGl_TextureFormat& theFormat, const OpenGl_TextureFormat& theFormat,
const Graphic3d_Vec2i& theSizeXY, const Graphic3d_Vec3i& theSizeXYZ,
const Graphic3d_TypeOfTexture theType, const Graphic3d_TypeOfTexture theType,
const Image_PixMap* theImage) const Image_PixMap* theImage)
{ {
if (theSizeXY.x() < 1 if (theSizeXYZ.x() < 1
|| theSizeXY.y() < 1) || theSizeXYZ.y() < 1
|| theSizeXYZ.z() < 1)
{ {
theCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_ERROR, 0, GL_DEBUG_SEVERITY_HIGH, theCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_ERROR, 0, GL_DEBUG_SEVERITY_HIGH,
TCollection_AsciiString ("Error: texture of 0 size cannot be created [") + myResourceId +"]"); TCollection_AsciiString ("Error: texture of 0 size cannot be created [") + myResourceId +"]");
@ -244,16 +236,39 @@ bool OpenGl_Texture::Init (const Handle(OpenGl_Context)& theCtx,
return false; return false;
} }
const GLenum aTarget = (theType == Graphic3d_TOT_1D GLenum aTarget = GL_TEXTURE_2D;
&& theCtx->GraphicsLibrary() != Aspect_GraphicsLibrary_OpenGLES) switch (theType)
{
case Graphic3d_TypeOfTexture_1D:
{
aTarget = theCtx->GraphicsLibrary() != Aspect_GraphicsLibrary_OpenGLES
? GL_TEXTURE_1D ? GL_TEXTURE_1D
: GL_TEXTURE_2D; : GL_TEXTURE_2D;
break;
}
case Graphic3d_TypeOfTexture_2D:
case Graphic3d_TOT_2D_MIPMAP:
{
aTarget = GL_TEXTURE_2D;
break;
}
case Graphic3d_TypeOfTexture_3D:
{
aTarget = GL_TEXTURE_3D;
break;
}
case Graphic3d_TypeOfTexture_CUBEMAP:
{
aTarget = GL_TEXTURE_CUBE_MAP;
break;
}
}
const bool toPatchExisting = IsValid() const bool toPatchExisting = IsValid()
&& myTextFormat == theFormat.PixelFormat() && myTextFormat == theFormat.PixelFormat()
&& myTarget == aTarget && myTarget == aTarget
&& HasMipmaps() == (theType == Graphic3d_TOT_2D_MIPMAP) && mySize.x() == theSizeXYZ.x()
&& mySizeX == theSizeXY.x() && (mySize.y() == theSizeXYZ.y() || theType == Graphic3d_TypeOfTexture_1D)
&& (mySizeY == theSizeXY.y() || theType == Graphic3d_TOT_1D); && mySize.z() == theSizeXYZ.z();
if (!Create (theCtx)) if (!Create (theCtx))
{ {
Release (theCtx.get()); Release (theCtx.get());
@ -271,9 +286,7 @@ bool OpenGl_Texture::Init (const Handle(OpenGl_Context)& theCtx,
myIsAlpha = theFormat.PixelFormat() == GL_ALPHA; myIsAlpha = theFormat.PixelFormat() == GL_ALPHA;
} }
myMaxMipLevel = theType == Graphic3d_TOT_2D_MIPMAP && theCtx->arbFBO != NULL myMaxMipLevel = 0;
? computeUpperMipMapLevel (theSizeXY.x(), theSizeXY.y())
: 0;
myTextFormat = theFormat.PixelFormat(); myTextFormat = theFormat.PixelFormat();
mySizedFormat = theFormat.InternalFormat(); mySizedFormat = theFormat.InternalFormat();
myNbSamples = 1; myNbSamples = 1;
@ -293,12 +306,12 @@ bool OpenGl_Texture::Init (const Handle(OpenGl_Context)& theCtx,
return false; return false;
} }
const GLsizei aMaxSize = theCtx->MaxTextureSize(); const Standard_Integer aMaxSize = theCtx->MaxTextureSize();
if (theSizeXY.x() > aMaxSize if (theSizeXYZ.maxComp() > aMaxSize)
|| theSizeXY.y() > aMaxSize)
{ {
theCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_ERROR, 0, GL_DEBUG_SEVERITY_HIGH, theCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_ERROR, 0, GL_DEBUG_SEVERITY_HIGH,
TCollection_AsciiString ("Error: Texture dimension - ") + theSizeXY.x() + "x" + theSizeXY.y() TCollection_AsciiString ("Error: Texture dimension - ") + theSizeXYZ.x() + "x" + theSizeXYZ.y()
+ (theSizeXYZ.z() > 1 ? TCollection_AsciiString ("x") + theSizeXYZ.z() : TCollection_AsciiString())
+ " exceeds hardware limits (" + aMaxSize + "x" + aMaxSize + ")" + " exceeds hardware limits (" + aMaxSize + "x" + aMaxSize + ")"
+ " [" + myResourceId +"]"); + " [" + myResourceId +"]");
Release (theCtx.get()); Release (theCtx.get());
@ -312,34 +325,18 @@ bool OpenGl_Texture::Init (const Handle(OpenGl_Context)& theCtx,
// however some hardware (NV30 - GeForce FX, RadeOn 9xxx and Xxxx) supports GLSL but not NPOT! // however some hardware (NV30 - GeForce FX, RadeOn 9xxx and Xxxx) supports GLSL but not NPOT!
// Trying to create NPOT textures on such hardware will not fail // Trying to create NPOT textures on such hardware will not fail
// but driver will fall back into software rendering, // but driver will fall back into software rendering,
const GLsizei aWidthP2 = OpenGl_Context::GetPowerOfTwo (theSizeXY.x(), aMaxSize); const Graphic3d_Vec2i aSizeP2 (OpenGl_Context::GetPowerOfTwo (theSizeXYZ.x(), aMaxSize),
const GLsizei aHeightP2 = OpenGl_Context::GetPowerOfTwo (theSizeXY.y(), aMaxSize); OpenGl_Context::GetPowerOfTwo (theSizeXYZ.y(), aMaxSize));
if (theSizeXY.x() != aWidthP2 if (theSizeXYZ.x() != aSizeP2.x()
|| (theType != Graphic3d_TOT_1D && theSizeXY.y() != aHeightP2)) || (theType != Graphic3d_TypeOfTexture_1D && theSizeXYZ.y() != aSizeP2.y()))
{ {
theCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_PORTABILITY, 0, GL_DEBUG_SEVERITY_HIGH, theCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_PORTABILITY, 0, GL_DEBUG_SEVERITY_HIGH,
TCollection_AsciiString ("Error: NPOT Textures (") + theSizeXY.x() + "x" + theSizeXY.y() + ")" TCollection_AsciiString ("Error: NPOT Textures (") + theSizeXYZ.x() + "x" + theSizeXYZ.y() + ")"
" are not supported by hardware [" + myResourceId +"]"); " are not supported by hardware [" + myResourceId +"]");
Release (theCtx.get()); Release (theCtx.get());
return false; return false;
} }
} }
else if (theCtx->GraphicsLibrary() == Aspect_GraphicsLibrary_OpenGLES
&& !theCtx->IsGlGreaterEqual (3, 0)
&& theType == Graphic3d_TOT_2D_MIPMAP)
{
// Mipmap NPOT textures are not supported by OpenGL ES 2.0.
const GLsizei aWidthP2 = OpenGl_Context::GetPowerOfTwo (theSizeXY.x(), aMaxSize);
const GLsizei aHeightP2 = OpenGl_Context::GetPowerOfTwo (theSizeXY.y(), aMaxSize);
if (theSizeXY.x() != aWidthP2
|| theSizeXY.y() != aHeightP2)
{
theCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_PORTABILITY, 0, GL_DEBUG_SEVERITY_HIGH,
TCollection_AsciiString ("Warning: Mipmap NPOT Textures (") + theSizeXY.x() + "x" + theSizeXY.y() + ")"
" are not supported by OpenGL ES 2.0 [" + myResourceId +"]");
myMaxMipLevel = 0;
}
}
GLint aTestWidth = 0, aTestHeight = 0; GLint aTestWidth = 0, aTestHeight = 0;
GLvoid* aDataPtr = (theImage != NULL) ? (GLvoid* )theImage->Data() : NULL; GLvoid* aDataPtr = (theImage != NULL) ? (GLvoid* )theImage->Data() : NULL;
@ -370,7 +367,7 @@ bool OpenGl_Texture::Init (const Handle(OpenGl_Context)& theCtx,
myTarget = aTarget; myTarget = aTarget;
switch (theType) switch (theType)
{ {
case Graphic3d_TOT_1D: case Graphic3d_TypeOfTexture_1D:
{ {
if (theCtx->GraphicsLibrary() == Aspect_GraphicsLibrary_OpenGLES) if (theCtx->GraphicsLibrary() == Aspect_GraphicsLibrary_OpenGLES)
{ {
@ -385,14 +382,13 @@ bool OpenGl_Texture::Init (const Handle(OpenGl_Context)& theCtx,
if (toPatchExisting) if (toPatchExisting)
{ {
theCtx->core11fwd->glTexSubImage1D (GL_TEXTURE_1D, 0, 0, theCtx->core11fwd->glTexSubImage1D (GL_TEXTURE_1D, 0, 0,
theSizeXY.x(), theFormat.PixelFormat(), theFormat.DataType(), aDataPtr); theSizeXYZ.x(), theFormat.PixelFormat(), theFormat.DataType(), aDataPtr);
Unbind (theCtx); break;
return true;
} }
// use proxy to check texture could be created or not // use proxy to check texture could be created or not
theCtx->core11fwd->glTexImage1D (GL_PROXY_TEXTURE_1D, 0, anIntFormat, theCtx->core11fwd->glTexImage1D (GL_PROXY_TEXTURE_1D, 0, anIntFormat,
theSizeXY.x(), 0, theSizeXYZ.x(), 0,
theFormat.PixelFormat(), theFormat.DataType(), NULL); theFormat.PixelFormat(), theFormat.DataType(), NULL);
theCtx->core11fwd->glGetTexLevelParameteriv (GL_PROXY_TEXTURE_1D, 0, GL_TEXTURE_WIDTH, &aTestWidth); theCtx->core11fwd->glGetTexLevelParameteriv (GL_PROXY_TEXTURE_1D, 0, GL_TEXTURE_WIDTH, &aTestWidth);
theCtx->core11fwd->glGetTexLevelParameteriv (GL_PROXY_TEXTURE_1D, 0, GL_TEXTURE_INTERNAL_FORMAT, &mySizedFormat); theCtx->core11fwd->glGetTexLevelParameteriv (GL_PROXY_TEXTURE_1D, 0, GL_TEXTURE_INTERNAL_FORMAT, &mySizedFormat);
@ -405,7 +401,7 @@ bool OpenGl_Texture::Init (const Handle(OpenGl_Context)& theCtx,
} }
theCtx->core11fwd->glTexImage1D (GL_TEXTURE_1D, 0, anIntFormat, theCtx->core11fwd->glTexImage1D (GL_TEXTURE_1D, 0, anIntFormat,
theSizeXY.x(), 0, theSizeXYZ.x(), 0,
theFormat.PixelFormat(), theFormat.DataType(), aDataPtr); theFormat.PixelFormat(), theFormat.DataType(), aDataPtr);
if (theCtx->core11fwd->glGetError() != GL_NO_ERROR) if (theCtx->core11fwd->glGetError() != GL_NO_ERROR)
{ {
@ -414,13 +410,10 @@ bool OpenGl_Texture::Init (const Handle(OpenGl_Context)& theCtx,
return false; return false;
} }
mySizeX = theSizeXY.x(); mySize.SetValues (theSizeXYZ.x(), 1, 1);
mySizeY = 1; break;
Unbind (theCtx);
return true;
} }
case Graphic3d_TOT_2D: case Graphic3d_TypeOfTexture_2D:
case Graphic3d_TOT_2D_MIPMAP: case Graphic3d_TOT_2D_MIPMAP:
{ {
Bind (theCtx); Bind (theCtx);
@ -429,28 +422,16 @@ bool OpenGl_Texture::Init (const Handle(OpenGl_Context)& theCtx,
{ {
theCtx->core11fwd->glTexSubImage2D (GL_TEXTURE_2D, 0, theCtx->core11fwd->glTexSubImage2D (GL_TEXTURE_2D, 0,
0, 0, 0, 0,
theSizeXY.x(), theSizeXY.y(), theSizeXYZ.x(), theSizeXYZ.y(),
theFormat.PixelFormat(), theFormat.DataType(), aDataPtr); theFormat.PixelFormat(), theFormat.DataType(), aDataPtr);
break;
if (myMaxMipLevel > 0)
{
// generate mipmaps
theCtx->arbFBO->glGenerateMipmap (GL_TEXTURE_2D);
if (theCtx->core11fwd->glGetError() != GL_NO_ERROR)
{
myMaxMipLevel = 0;
}
}
Unbind (theCtx);
return true;
} }
if (theCtx->GraphicsLibrary() == Aspect_GraphicsLibrary_OpenGL) if (theCtx->GraphicsLibrary() == Aspect_GraphicsLibrary_OpenGL)
{ {
// use proxy to check texture could be created or not // use proxy to check texture could be created or not
theCtx->core11fwd->glTexImage2D (GL_PROXY_TEXTURE_2D, 0, anIntFormat, theCtx->core11fwd->glTexImage2D (GL_PROXY_TEXTURE_2D, 0, anIntFormat,
theSizeXY.x(), theSizeXY.y(), 0, theSizeXYZ.x(), theSizeXYZ.y(), 0,
theFormat.PixelFormat(), theFormat.DataType(), NULL); theFormat.PixelFormat(), theFormat.DataType(), NULL);
theCtx->core11fwd->glGetTexLevelParameteriv (GL_PROXY_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &aTestWidth); theCtx->core11fwd->glGetTexLevelParameteriv (GL_PROXY_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &aTestWidth);
theCtx->core11fwd->glGetTexLevelParameteriv (GL_PROXY_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &aTestHeight); theCtx->core11fwd->glGetTexLevelParameteriv (GL_PROXY_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &aTestHeight);
@ -465,13 +446,13 @@ bool OpenGl_Texture::Init (const Handle(OpenGl_Context)& theCtx,
} }
theCtx->core11fwd->glTexImage2D (GL_TEXTURE_2D, 0, anIntFormat, theCtx->core11fwd->glTexImage2D (GL_TEXTURE_2D, 0, anIntFormat,
theSizeXY.x(), theSizeXY.y(), 0, theSizeXYZ.x(), theSizeXYZ.y(), 0,
theFormat.PixelFormat(), theFormat.DataType(), aDataPtr); theFormat.PixelFormat(), theFormat.DataType(), aDataPtr);
GLenum anErr = theCtx->core11fwd->glGetError(); GLenum anErr = theCtx->core11fwd->glGetError();
if (anErr != GL_NO_ERROR) if (anErr != GL_NO_ERROR)
{ {
theCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_ERROR, 0, GL_DEBUG_SEVERITY_HIGH, theCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_ERROR, 0, GL_DEBUG_SEVERITY_HIGH,
TCollection_AsciiString ("Error: 2D texture ") + theSizeXY.x() + "x" + theSizeXY.y() TCollection_AsciiString ("Error: 2D texture ") + theSizeXYZ.x() + "x" + theSizeXYZ.y()
+ " IF: " + OpenGl_TextureFormat::FormatFormat (anIntFormat) + " IF: " + OpenGl_TextureFormat::FormatFormat (anIntFormat)
+ " PF: " + OpenGl_TextureFormat::FormatFormat (theFormat.PixelFormat()) + " PF: " + OpenGl_TextureFormat::FormatFormat (theFormat.PixelFormat())
+ " DT: " + OpenGl_TextureFormat::FormatDataType (theFormat.DataType()) + " DT: " + OpenGl_TextureFormat::FormatDataType (theFormat.DataType())
@ -482,25 +463,135 @@ bool OpenGl_Texture::Init (const Handle(OpenGl_Context)& theCtx,
return false; return false;
} }
mySizeX = theSizeXY.x(); mySize.SetValues (theSizeXYZ.xy(), 1);
mySizeY = theSizeXY.y(); break;
}
if (myMaxMipLevel > 0) case Graphic3d_TypeOfTexture_3D:
{ {
// generate mipmaps if (theCtx->Functions()->glTexImage3D == nullptr)
{
theCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_ERROR, 0, GL_DEBUG_SEVERITY_HIGH,
"Error: three-dimensional textures are not supported by hardware.");
Unbind (theCtx);
Release (theCtx.get());
return false;
}
Bind (theCtx);
applyDefaultSamplerParams (theCtx);
if (theCtx->GraphicsLibrary() == Aspect_GraphicsLibrary_OpenGL)
{
theCtx->Functions()->glTexImage3D (GL_PROXY_TEXTURE_3D, 0, anIntFormat,
theSizeXYZ.x(), theSizeXYZ.y(), theSizeXYZ.z(), 0,
theFormat.PixelFormat(), theFormat.DataType(), nullptr);
NCollection_Vec3<GLint> aTestSizeXYZ;
theCtx->core11fwd->glGetTexLevelParameteriv (GL_PROXY_TEXTURE_3D, 0, GL_TEXTURE_WIDTH, &aTestSizeXYZ.x());
theCtx->core11fwd->glGetTexLevelParameteriv (GL_PROXY_TEXTURE_3D, 0, GL_TEXTURE_HEIGHT, &aTestSizeXYZ.y());
theCtx->core11fwd->glGetTexLevelParameteriv (GL_PROXY_TEXTURE_3D, 0, GL_TEXTURE_DEPTH, &aTestSizeXYZ.z());
theCtx->core11fwd->glGetTexLevelParameteriv (GL_PROXY_TEXTURE_3D, 0, GL_TEXTURE_INTERNAL_FORMAT, &mySizedFormat);
if (aTestSizeXYZ.x() == 0 || aTestSizeXYZ.y() == 0 || aTestSizeXYZ.z() == 0)
{
Unbind (theCtx);
Release (theCtx.get());
return false;
}
}
theCtx->Functions()->glTexImage3D (GL_TEXTURE_3D, 0, anIntFormat,
theSizeXYZ.x(), theSizeXYZ.y(), theSizeXYZ.z(), 0,
theFormat.PixelFormat(), theFormat.DataType(), aDataPtr);
GLenum anErr = theCtx->core11fwd->glGetError();
if (anErr != GL_NO_ERROR)
{
theCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_ERROR, 0, GL_DEBUG_SEVERITY_HIGH,
TCollection_AsciiString ("Error: 3D texture ") + theSizeXYZ.x() + "x" + theSizeXYZ.y() + "x" + theSizeXYZ.z()
+ " IF: " + OpenGl_TextureFormat::FormatFormat (anIntFormat)
+ " PF: " + OpenGl_TextureFormat::FormatFormat (theFormat.PixelFormat())
+ " DT: " + OpenGl_TextureFormat::FormatDataType (theFormat.DataType())
+ " can not be created with error " + OpenGl_Context::FormatGlError (anErr)
+ " [" + myResourceId +"]");
Unbind (theCtx);
Release (theCtx.get());
return false;
}
mySize = theSizeXYZ;
break;
}
case Graphic3d_TypeOfTexture_CUBEMAP:
{
Unbind (theCtx);
Release (theCtx.get());
return false;
}
}
Unbind (theCtx);
return true;
}
// =======================================================================
// function : GenerateMipmaps
// purpose :
// =======================================================================
bool OpenGl_Texture::GenerateMipmaps (const Handle(OpenGl_Context)& theCtx)
{
if (theCtx->arbFBO == nullptr
|| !IsValid())
{
return false;
}
myMaxMipLevel = computeUpperMipMapLevel (mySize.maxComp());
const Standard_Integer aMaxSize = theCtx->MaxTextureSize();
if (theCtx->GraphicsLibrary() == Aspect_GraphicsLibrary_OpenGLES
&& !theCtx->IsGlGreaterEqual (3, 0))
{
// Mipmap NPOT textures are not supported by OpenGL ES 2.0.
const Graphic3d_Vec2i aSizeP2 (OpenGl_Context::GetPowerOfTwo (mySize.x(), aMaxSize),
OpenGl_Context::GetPowerOfTwo (mySize.y(), aMaxSize));
if (mySize.xy() != aSizeP2)
{
theCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_PORTABILITY, 0, GL_DEBUG_SEVERITY_HIGH,
TCollection_AsciiString ("Warning: Mipmap NPOT Textures (") + mySize.x() + "x" + mySize.y() + ")"
" are not supported by OpenGL ES 2.0 [" + myResourceId +"]");
myMaxMipLevel = 0;
}
}
if (myMaxMipLevel <= 0)
{
return false;
}
//glHint (GL_GENERATE_MIPMAP_HINT, GL_NICEST); //glHint (GL_GENERATE_MIPMAP_HINT, GL_NICEST);
theCtx->arbFBO->glGenerateMipmap (GL_TEXTURE_2D); Bind (theCtx);
anErr = theCtx->core11fwd->glGetError(); if (theCtx->HasTextureBaseLevel()
&& !mySampler->isValidSampler())
{
const Standard_Integer aMaxLevel = Min (myMaxMipLevel, mySampler->Parameters()->MaxLevel());
mySampler->SetParameter (theCtx, myTarget, GL_TEXTURE_MAX_LEVEL, aMaxLevel);
}
theCtx->arbFBO->glGenerateMipmap (myTarget);
GLenum anErr = theCtx->core11fwd->glGetError();
if (anErr != GL_NO_ERROR) if (anErr != GL_NO_ERROR)
{ {
myMaxMipLevel = 0; myMaxMipLevel = 0;
if (theCtx->HasTextureBaseLevel()
&& !mySampler->isValidSampler())
{
mySampler->SetParameter (theCtx, myTarget, GL_TEXTURE_MAX_LEVEL, 0);
}
if (theCtx->GraphicsLibrary() == Aspect_GraphicsLibrary_OpenGLES if (theCtx->GraphicsLibrary() == Aspect_GraphicsLibrary_OpenGLES
&& (theFormat.InternalFormat() == GL_RGB8 && (mySizedFormat == GL_RGB8
|| theFormat.InternalFormat() == GL_SRGB8)) || mySizedFormat == GL_SRGB8))
{ {
theCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_PORTABILITY, 0, GL_DEBUG_SEVERITY_HIGH, theCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_PORTABILITY, 0, GL_DEBUG_SEVERITY_HIGH,
TCollection_AsciiString ("Warning: generating mipmaps requires color-renderable format, while giving ") TCollection_AsciiString ("Warning: generating mipmaps requires color-renderable format, while giving ")
+ OpenGl_TextureFormat::FormatFormat (anIntFormat) + " [" + myResourceId +"]"); + OpenGl_TextureFormat::FormatFormat (mySizedFormat) + " [" + myResourceId +"]");
} }
else else
{ {
@ -508,22 +599,11 @@ bool OpenGl_Texture::Init (const Handle(OpenGl_Context)& theCtx,
TCollection_AsciiString ("Warning: generating mipmaps has failed [") + myResourceId +"]"); TCollection_AsciiString ("Warning: generating mipmaps has failed [") + myResourceId +"]");
} }
} }
}
applyDefaultSamplerParams (theCtx);
Unbind (theCtx); Unbind (theCtx);
return true; return true;
} }
case Graphic3d_TOT_CUBEMAP:
{
Unbind (theCtx);
Release (theCtx.get());
return false;
}
}
Release (theCtx.get());
return false;
}
// ======================================================================= // =======================================================================
// function : Init // function : Init
@ -550,8 +630,7 @@ bool OpenGl_Texture::Init (const Handle(OpenGl_Context)& theCtx,
return false; return false;
} }
return Init (theCtx, aFormat, Graphic3d_Vec2i ((Standard_Integer)theImage.SizeX(), (Standard_Integer)theImage.SizeY()), return Init (theCtx, aFormat, Graphic3d_Vec3i (theImage.SizeXYZ()), theType, &theImage);
theType, &theImage);
} }
// ======================================================================= // =======================================================================
@ -559,7 +638,7 @@ bool OpenGl_Texture::Init (const Handle(OpenGl_Context)& theCtx,
// purpose : // purpose :
// ======================================================================= // =======================================================================
bool OpenGl_Texture::Init (const Handle(OpenGl_Context)& theCtx, bool OpenGl_Texture::Init (const Handle(OpenGl_Context)& theCtx,
const Handle(Graphic3d_TextureMap)& theTextureMap) const Handle(Graphic3d_TextureRoot)& theTextureMap)
{ {
if (theTextureMap.IsNull()) if (theTextureMap.IsNull())
{ {
@ -568,7 +647,7 @@ bool OpenGl_Texture::Init (const Handle(OpenGl_Context)& theCtx,
switch (theTextureMap->Type()) switch (theTextureMap->Type())
{ {
case Graphic3d_TOT_CUBEMAP: case Graphic3d_TypeOfTexture_CUBEMAP:
{ {
return InitCubeMap (theCtx, Handle(Graphic3d_CubeMap)::DownCast(theTextureMap), return InitCubeMap (theCtx, Handle(Graphic3d_CubeMap)::DownCast(theTextureMap),
0, Image_Format_RGB, false, theTextureMap->IsColorMap()); 0, Image_Format_RGB, false, theTextureMap->IsColorMap());
@ -589,7 +668,15 @@ bool OpenGl_Texture::Init (const Handle(OpenGl_Context)& theCtx,
{ {
return false; return false;
} }
return Init (theCtx, *anImage, theTextureMap->Type(), theTextureMap->IsColorMap()); if (!Init (theCtx, *anImage, theTextureMap->Type(), theTextureMap->IsColorMap()))
{
return false;
}
if (theTextureMap->HasMipmaps())
{
GenerateMipmaps (theCtx);
}
return true;
} }
} }
} }
@ -641,23 +728,22 @@ bool OpenGl_Texture::InitCompressed (const Handle(OpenGl_Context)& theCtx,
myTextFormat = aFormat.Format(); myTextFormat = aFormat.Format();
mySizedFormat = aFormat.Internal(); mySizedFormat = aFormat.Internal();
myIsTopDown = theImage.IsTopDown(); myIsTopDown = theImage.IsTopDown();
mySizeX = theImage.SizeX(); mySize.SetValues (theImage.SizeX(), theImage.SizeY(), 1);
mySizeY = theImage.SizeY();
myMaxMipLevel = Max (theImage.MipMaps().Size() - 1, 0); myMaxMipLevel = Max (theImage.MipMaps().Size() - 1, 0);
if (myMaxMipLevel > 0 if (myMaxMipLevel > 0
&& !theImage.IsCompleteMipMapSet()) && !theImage.IsCompleteMipMapSet())
{ {
const Graphic3d_Vec2i aMipSize = computeSmallestMipMapSize (Graphic3d_Vec2i (mySizeX, mySizeY), myMaxMipLevel); const Graphic3d_Vec2i aMipSize = computeSmallestMipMapSize (mySize.xy(), myMaxMipLevel);
if (!theCtx->HasTextureBaseLevel()) if (!theCtx->HasTextureBaseLevel())
{ {
myMaxMipLevel = 0; myMaxMipLevel = 0;
theCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_PERFORMANCE, 0, GL_DEBUG_SEVERITY_MEDIUM, theCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_PERFORMANCE, 0, GL_DEBUG_SEVERITY_MEDIUM,
TCollection_AsciiString ("Warning: compressed 2D texture ") + myResourceId + " " + mySizeX + "x" + mySizeY TCollection_AsciiString ("Warning: compressed 2D texture ") + myResourceId + " " + mySize.x() + "x" + mySize.y()
+ " has smallest mipmap " + aMipSize.x() + "x" + aMipSize.y() + "; mipmaps will be ignored"); + " has smallest mipmap " + aMipSize.x() + "x" + aMipSize.y() + "; mipmaps will be ignored");
} }
else else
{ {
Message::SendTrace (TCollection_AsciiString ("Warning: compressed 2D texture ") + myResourceId + " " + mySizeX + "x" + mySizeY Message::SendTrace (TCollection_AsciiString ("Warning: compressed 2D texture ") + myResourceId + " " + mySize.x() + "x" + mySize.y()
+ " has smallest mipmap " + aMipSize.x() + "x" + aMipSize.y()); + " has smallest mipmap " + aMipSize.x() + "x" + aMipSize.y());
} }
} }
@ -762,8 +848,7 @@ bool OpenGl_Texture::Init2DMultisample (const Handle(OpenGl_Context)& theCtx,
return false; return false;
} }
mySizeX = theSizeX; mySize.SetValues (theSizeX, theSizeY, 1);
mySizeY = theSizeY;
Unbind (theCtx); Unbind (theCtx);
return true; return true;
@ -824,8 +909,7 @@ bool OpenGl_Texture::InitRectangle (const Handle(OpenGl_Context)& theCtx,
return false; return false;
} }
mySizeX = aSizeX; mySize.SetValues (aSizeX, aSizeY, 1);
mySizeY = aSizeY;
Unbind (theCtx); Unbind (theCtx);
return true; return true;
} }
@ -912,9 +996,7 @@ bool OpenGl_Texture::Init3D (const Handle(OpenGl_Context)& theCtx,
return false; return false;
} }
mySizeX = aSizeXYZ.x(); mySize = aSizeXYZ;
mySizeY = aSizeXYZ.y();
mySizeZ = aSizeXYZ.z();
Unbind (theCtx); Unbind (theCtx);
return true; return true;
@ -940,6 +1022,7 @@ bool OpenGl_Texture::InitCubeMap (const Handle(OpenGl_Context)& theCtx,
Handle(Image_PixMap) anImage; Handle(Image_PixMap) anImage;
Handle(Image_CompressedPixMap) aCompImage; Handle(Image_CompressedPixMap) aCompImage;
OpenGl_TextureFormat aFormat; OpenGl_TextureFormat aFormat;
myMaxMipLevel = 0;
if (!theCubeMap.IsNull()) if (!theCubeMap.IsNull())
{ {
theCubeMap->Reset(); theCubeMap->Reset();
@ -997,15 +1080,10 @@ bool OpenGl_Texture::InitCubeMap (const Handle(OpenGl_Context)& theCtx,
theSize = anImage->SizeX(); theSize = anImage->SizeX();
theFormat = anImage->Format(); theFormat = anImage->Format();
theToGenMipmap = theCubeMap->HasMipmaps(); theToGenMipmap = theCubeMap->HasMipmaps();
myMaxMipLevel = theToGenMipmap ? computeUpperMipMapLevel ((Standard_Integer )theSize) : 0;
} }
myIsTopDown = theCubeMap->IsTopDown(); myIsTopDown = theCubeMap->IsTopDown();
} }
else
{
myMaxMipLevel = theToGenMipmap ? computeUpperMipMapLevel ((Standard_Integer )theSize) : 0;
}
if (!aFormat.IsValid()) if (!aFormat.IsValid())
{ {
@ -1036,8 +1114,7 @@ bool OpenGl_Texture::InitCubeMap (const Handle(OpenGl_Context)& theCtx,
myTarget = GL_TEXTURE_CUBE_MAP; myTarget = GL_TEXTURE_CUBE_MAP;
myNbSamples = 1; myNbSamples = 1;
mySizeX = (GLsizei )theSize; mySize.SetValues ((GLsizei )theSize, (GLsizei )theSize, 1);
mySizeY = (GLsizei )theSize;
myTextFormat = aFormat.Format(); myTextFormat = aFormat.Format();
mySizedFormat = aFormat.Internal(); mySizedFormat = aFormat.Internal();
@ -1069,7 +1146,7 @@ bool OpenGl_Texture::InitCubeMap (const Handle(OpenGl_Context)& theCtx,
} }
if (!aCompImage.IsNull()) if (!aCompImage.IsNull())
{ {
Graphic3d_Vec2i aMipSizeXY (mySizeX, mySizeY); Graphic3d_Vec2i aMipSizeXY = mySize.xy();
aData = aCompImage->FaceData()->Data(); aData = aCompImage->FaceData()->Data();
for (Standard_Integer aMipIter = 0; aMipIter <= myMaxMipLevel; ++aMipIter) for (Standard_Integer aMipIter = 0; aMipIter <= myMaxMipLevel; ++aMipIter)
{ {
@ -1167,16 +1244,7 @@ bool OpenGl_Texture::InitCubeMap (const Handle(OpenGl_Context)& theCtx,
if (theToGenMipmap && theCtx->arbFBO != NULL) if (theToGenMipmap && theCtx->arbFBO != NULL)
{ {
theCtx->arbFBO->glGenerateMipmap (myTarget); GenerateMipmaps (theCtx);
const GLenum anErr = theCtx->core11fwd->glGetError();
if (anErr != GL_NO_ERROR)
{
theCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_ERROR, 0, GL_DEBUG_SEVERITY_HIGH,
TCollection_AsciiString ("Unable to generate mipmap of cubemap with format ")
+ OpenGl_TextureFormat::FormatFormat (anIntFormat)
+ ", error " + OpenGl_Context::FormatGlError (anErr));
myMaxMipLevel = 0;
}
} }
Unbind (theCtx.get()); Unbind (theCtx.get());
@ -1250,14 +1318,14 @@ Standard_Size OpenGl_Texture::EstimatedDataSize() const
return 0; return 0;
} }
Standard_Size aSize = PixelSizeOfPixelFormat (mySizedFormat) * mySizeX * myNbSamples; Standard_Size aSize = PixelSizeOfPixelFormat (mySizedFormat) * mySize.x() * myNbSamples;
if (mySizeY != 0) if (mySize.y() != 0)
{ {
aSize *= Standard_Size(mySizeY); aSize *= Standard_Size(mySize.y());
} }
if (mySizeZ != 0) if (mySize.z() != 0)
{ {
aSize *= Standard_Size(mySizeZ); aSize *= Standard_Size(mySize.z());
} }
if (myTarget == GL_TEXTURE_CUBE_MAP) if (myTarget == GL_TEXTURE_CUBE_MAP)
{ {
@ -1294,7 +1362,7 @@ bool OpenGl_Texture::ImageDump (Image_PixMap& theImage,
} }
GLenum aTarget = myTarget; GLenum aTarget = myTarget;
Graphic3d_Vec2i aSize (mySizeX, mySizeY); Graphic3d_Vec2i aSize = mySize.xy();
if (myTarget == GL_TEXTURE_CUBE_MAP) if (myTarget == GL_TEXTURE_CUBE_MAP)
{ {
aTarget = GL_TEXTURE_CUBE_MAP_POSITIVE_X + theCubeSide; aTarget = GL_TEXTURE_CUBE_MAP_POSITIVE_X + theCubeSide;

View File

@ -53,11 +53,17 @@ public:
//! @return target to which the texture is bound (GL_TEXTURE_1D, GL_TEXTURE_2D) //! @return target to which the texture is bound (GL_TEXTURE_1D, GL_TEXTURE_2D)
unsigned int GetTarget() const { return myTarget; } unsigned int GetTarget() const { return myTarget; }
//! @return texture width (0 LOD) //! Return texture dimensions (0 LOD)
GLsizei SizeX() const { return mySizeX; } const Graphic3d_Vec3i& Size() const { return mySize; }
//! @return texture height (0 LOD) //! Return texture width (0 LOD)
GLsizei SizeY() const { return mySizeY; } Standard_Integer SizeX() const { return mySize.x(); }
//! Return texture height (0 LOD)
Standard_Integer SizeY() const { return mySize.y(); }
//! Return texture depth (0 LOD)
Standard_Integer SizeZ() const { return mySize.z(); }
//! @return texture ID //! @return texture ID
unsigned int TextureId() const { return myTextureId; } unsigned int TextureId() const { return myTextureId; }
@ -140,15 +146,30 @@ public:
//! Notice that texture will be unbound after this call. //! Notice that texture will be unbound after this call.
Standard_EXPORT bool Init (const Handle(OpenGl_Context)& theCtx, Standard_EXPORT bool Init (const Handle(OpenGl_Context)& theCtx,
const OpenGl_TextureFormat& theFormat, const OpenGl_TextureFormat& theFormat,
const Graphic3d_Vec2i& theSizeXY, const Graphic3d_Vec3i& theSizeXYZ,
const Graphic3d_TypeOfTexture theType, const Graphic3d_TypeOfTexture theType,
const Image_PixMap* theImage = NULL); 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 OpenGl_TextureFormat& theFormat,
const Graphic3d_Vec2i& theSizeXY,
const Graphic3d_TypeOfTexture theType,
const Image_PixMap* theImage = NULL)
{
return Init (theCtx, theFormat, Graphic3d_Vec3i (theSizeXY, 1), theType, theImage);
}
//! Initialize the texture with Graphic3d_TextureMap. //! Initialize the texture with Graphic3d_TextureMap.
//! It is an universal way to initialize. //! It is an universal way to initialize.
//! Suitable initialization method will be chosen. //! Suitable initialization method will be chosen.
Standard_EXPORT bool Init (const Handle(OpenGl_Context)& theCtx, Standard_EXPORT bool Init (const Handle(OpenGl_Context)& theCtx,
const Handle(Graphic3d_TextureMap)& theTextureMap); const Handle(Graphic3d_TextureRoot)& theTextureMap);
//! Generate mipmaps.
Standard_EXPORT bool GenerateMipmaps (const Handle(OpenGl_Context)& theCtx);
//! Initialize the texture with Image_CompressedPixMap. //! Initialize the texture with Image_CompressedPixMap.
Standard_EXPORT bool InitCompressed (const Handle(OpenGl_Context)& theCtx, Standard_EXPORT bool InitCompressed (const Handle(OpenGl_Context)& theCtx,
@ -302,9 +323,7 @@ protected:
Standard_Size myRevision; //!< revision of associated data source Standard_Size myRevision; //!< revision of associated data source
unsigned int myTextureId; //!< GL resource ID unsigned int myTextureId; //!< GL resource ID
unsigned int myTarget; //!< GL_TEXTURE_1D/GL_TEXTURE_2D/GL_TEXTURE_3D unsigned int myTarget; //!< GL_TEXTURE_1D/GL_TEXTURE_2D/GL_TEXTURE_3D
Standard_Integer mySizeX; //!< texture width Graphic3d_Vec3i mySize; //!< texture width x height x depth
Standard_Integer mySizeY; //!< texture height
Standard_Integer mySizeZ; //!< texture depth
unsigned int myTextFormat; //!< texture format - GL_RGB, GL_RGBA,... unsigned int myTextFormat; //!< texture format - GL_RGB, GL_RGBA,...
Standard_Integer mySizedFormat;//!< internal (sized) texture format Standard_Integer mySizedFormat;//!< internal (sized) texture format
Standard_Integer myNbSamples; //!< number of MSAA samples Standard_Integer myNbSamples; //!< number of MSAA samples

View File

@ -302,7 +302,7 @@ bool OpenGl_TileSampler::upload (const Handle(OpenGl_Context)& theContext,
if (!theOffsetsTexture->Init (theContext, if (!theOffsetsTexture->Init (theContext,
OpenGl_TextureFormat::FindSizedFormat (theContext, GL_RG32I), OpenGl_TextureFormat::FindSizedFormat (theContext, GL_RG32I),
Graphic3d_Vec2i ((int )anOffsets.SizeX, (int )anOffsets.SizeY), Graphic3d_Vec2i ((int )anOffsets.SizeX, (int )anOffsets.SizeY),
Graphic3d_TOT_2D)) Graphic3d_TypeOfTexture_2D))
{ {
hasErrors = true; hasErrors = true;
} }

View File

@ -343,10 +343,8 @@ void OpenGl_View::initTextureEnv (const Handle(OpenGl_Context)& theContext)
} }
Handle(OpenGl_Texture) aTextureEnv = new OpenGl_Texture (myTextureEnvData->GetId(), myTextureEnvData->GetParams()); Handle(OpenGl_Texture) aTextureEnv = new OpenGl_Texture (myTextureEnvData->GetId(), myTextureEnvData->GetParams());
if (Handle(Image_PixMap) anImage = myTextureEnvData->GetImage (theContext->SupportedTextureFormats())) aTextureEnv->Init (theContext, myTextureEnvData);
{
aTextureEnv->Init (theContext, *anImage, myTextureEnvData->Type(), true);
}
myTextureEnv = new OpenGl_TextureSet (aTextureEnv); myTextureEnv = new OpenGl_TextureSet (aTextureEnv);
myTextureEnv->ChangeTextureSetBits() = Graphic3d_TextureSetBits_BaseColor; myTextureEnv->ChangeTextureSetBits() = Graphic3d_TextureSetBits_BaseColor;
} }
@ -1391,7 +1389,7 @@ bool OpenGl_View::prepareFrameBuffers (Graphic3d_Camera::Projection& theProj)
aParams->SetTextureUnit (aCtx->PBREnvLUTTexUnit()); aParams->SetTextureUnit (aCtx->PBREnvLUTTexUnit());
anEnvLUT = new OpenGl_Texture(THE_SHARED_ENV_LUT_KEY, aParams); anEnvLUT = new OpenGl_Texture(THE_SHARED_ENV_LUT_KEY, aParams);
if (!aTexFormat.IsValid() if (!aTexFormat.IsValid()
|| !anEnvLUT->Init (aCtx, aTexFormat, Graphic3d_Vec2i((Standard_Integer)Textures_EnvLUTSize), Graphic3d_TOT_2D, aPixMap.get())) || !anEnvLUT->Init (aCtx, aTexFormat, Graphic3d_Vec2i((Standard_Integer)Textures_EnvLUTSize), Graphic3d_TypeOfTexture_2D, aPixMap.get()))
{ {
aCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_ERROR, 0, GL_DEBUG_SEVERITY_HIGH, "Failed allocation of LUT for PBR"); aCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_ERROR, 0, GL_DEBUG_SEVERITY_HIGH, "Failed allocation of LUT for PBR");
anEnvLUT.Nullify(); anEnvLUT.Nullify();

View File

@ -1949,13 +1949,13 @@ Standard_Boolean OpenGl_View::updateRaytraceBuffers (const Standard_Integer
myRaytraceVisualErrorTexture[aViewIter]->Init (theGlContext, myRaytraceVisualErrorTexture[aViewIter]->Init (theGlContext,
OpenGl_TextureFormat::FindSizedFormat (theGlContext, GL_R32I), OpenGl_TextureFormat::FindSizedFormat (theGlContext, GL_R32I),
Graphic3d_Vec2i (myTileSampler.NbTilesX(), myTileSampler.NbTilesY()), Graphic3d_Vec2i (myTileSampler.NbTilesX(), myTileSampler.NbTilesY()),
Graphic3d_TOT_2D); Graphic3d_TypeOfTexture_2D);
if (!myRaytraceParameters.AdaptiveScreenSamplingAtomic) if (!myRaytraceParameters.AdaptiveScreenSamplingAtomic)
{ {
myRaytraceTileSamplesTexture[aViewIter]->Init (theGlContext, myRaytraceTileSamplesTexture[aViewIter]->Init (theGlContext,
OpenGl_TextureFormat::FindSizedFormat (theGlContext, GL_R32I), OpenGl_TextureFormat::FindSizedFormat (theGlContext, GL_R32I),
Graphic3d_Vec2i (myTileSampler.NbTilesX(), myTileSampler.NbTilesY()), Graphic3d_Vec2i (myTileSampler.NbTilesX(), myTileSampler.NbTilesY()),
Graphic3d_TOT_2D); Graphic3d_TypeOfTexture_2D);
} }
} }
else // non-adaptive mode else // non-adaptive mode

View File

@ -508,7 +508,7 @@ static Standard_Integer OCC30182 (Draw_Interpretor& , Standard_Integer theNbArgs
const Handle(Graphic3d_AspectFillArea3d)& anAspect = aPrs->Attributes()->ShadingAspect()->Aspect(); const Handle(Graphic3d_AspectFillArea3d)& anAspect = aPrs->Attributes()->ShadingAspect()->Aspect();
anAspect->SetShadingModel (Graphic3d_TypeOfShadingModel_Unlit); anAspect->SetShadingModel (Graphic3d_TypeOfShadingModel_Unlit);
anAspect->SetTextureMapOn (true); anAspect->SetTextureMapOn (true);
anAspect->SetTextureMap (new Graphic3d_Texture2Dmanual (anImage)); anAspect->SetTextureMap (new Graphic3d_Texture2D (anImage));
if (anImage->IsTopDown()) if (anImage->IsTopDown())
{ {
anAspect->TextureMap()->GetParams()->SetTranslation(Graphic3d_Vec2 (0.0f, -1.0f)); anAspect->TextureMap()->GetParams()->SetTranslation(Graphic3d_Vec2 (0.0f, -1.0f));

View File

@ -479,7 +479,7 @@ void V3d_View::SetBackgroundImage (const Standard_CString theFileName,
const Aspect_FillMethod theFillStyle, const Aspect_FillMethod theFillStyle,
const Standard_Boolean theToUpdate) const Standard_Boolean theToUpdate)
{ {
Handle(Graphic3d_Texture2D) aTextureMap = new Graphic3d_Texture2Dmanual (theFileName); Handle(Graphic3d_Texture2D) aTextureMap = new Graphic3d_Texture2D (theFileName);
aTextureMap->DisableModulate(); aTextureMap->DisableModulate();
SetBackgroundImage (aTextureMap, theFillStyle, theToUpdate); SetBackgroundImage (aTextureMap, theFillStyle, theToUpdate);
} }

View File

@ -48,7 +48,8 @@
#include <Graphic3d_AspectFillArea3d.hxx> #include <Graphic3d_AspectFillArea3d.hxx>
#include <Graphic3d_AspectLine3d.hxx> #include <Graphic3d_AspectLine3d.hxx>
#include <Graphic3d_CStructure.hxx> #include <Graphic3d_CStructure.hxx>
#include <Graphic3d_Texture2Dmanual.hxx> #include <Graphic3d_Texture2D.hxx>
#include <Graphic3d_Texture3D.hxx>
#include <Graphic3d_GraphicDriver.hxx> #include <Graphic3d_GraphicDriver.hxx>
#include <Graphic3d_MediaTextureSet.hxx> #include <Graphic3d_MediaTextureSet.hxx>
#include <Image_AlienPixMap.hxx> #include <Image_AlienPixMap.hxx>
@ -4145,13 +4146,8 @@ Standard_Integer VTexture (Draw_Interpretor& theDi, Standard_Integer theArgsNb,
return 1; return 1;
} }
int toModulate = -1; int toModulate = -1, toSetSRgb = -1;
int toSetSRgb = -1; bool toSetFilter = false, toSetAniso = false, toSetTrsfAngle = false, toSetTrsfTrans = false, toSetTrsfScale = false;
bool toSetFilter = false;
bool toSetAniso = false;
bool toSetTrsfAngle = false;
bool toSetTrsfTrans = false;
bool toSetTrsfScale = false;
Standard_ShortReal aTrsfRotAngle = 0.0f; Standard_ShortReal aTrsfRotAngle = 0.0f;
Graphic3d_Vec2 aTrsfTrans (0.0f, 0.0f); Graphic3d_Vec2 aTrsfTrans (0.0f, 0.0f);
Graphic3d_Vec2 aTrsfScale (1.0f, 1.0f); Graphic3d_Vec2 aTrsfScale (1.0f, 1.0f);
@ -4161,12 +4157,8 @@ Standard_Integer VTexture (Draw_Interpretor& theDi, Standard_Integer theArgsNb,
Handle(AIS_InteractiveObject) aTexturedIO; Handle(AIS_InteractiveObject) aTexturedIO;
Handle(AIS_Shape) aTexturedShape; Handle(AIS_Shape) aTexturedShape;
Handle(Graphic3d_TextureSet) aTextureSetOld; Handle(Graphic3d_TextureSet) aTextureSetOld;
NCollection_Vector<Handle(Graphic3d_Texture2Dmanual)> aTextureVecNew; NCollection_Vector<Handle(Graphic3d_TextureMap)> aTextureVecNew;
bool toSetGenRepeat = false; bool toSetGenRepeat = false, toSetGenScale = false, toSetGenOrigin = false, toSetImage = false, toComputeUV = false;
bool toSetGenScale = false;
bool toSetGenOrigin = false;
bool toSetImage = false;
bool toComputeUV = false;
const TCollection_AsciiString aCommandName (theArgVec[0]); const TCollection_AsciiString aCommandName (theArgVec[0]);
bool toSetDefaults = aCommandName == "vtexdefault"; bool toSetDefaults = aCommandName == "vtexdefault";
@ -4441,6 +4433,38 @@ Standard_Integer VTexture (Draw_Interpretor& theDi, Standard_Integer theArgsNb,
aTexturedIO->Attributes()->ShadingAspect()->Aspect()->SetTextureSet (aMedia); aTexturedIO->Attributes()->ShadingAspect()->Aspect()->SetTextureSet (aMedia);
aTextureSetOld.Nullify(); aTextureSetOld.Nullify();
} }
else if (aCommandName == "vtexture"
&& aTextureVecNew.IsEmpty()
&& aNameCase == "-3d")
{
TColStd_SequenceOfAsciiString aSlicesSeq;
for (; anArgIter + 1 < theArgsNb; ++anArgIter)
{
TCollection_AsciiString aSlicePath (theArgVec[anArgIter + 1]);
if (aSlicePath.StartsWith ("-"))
{
break;
}
aSlicesSeq.Append (aSlicePath);
}
if (aSlicesSeq.Size() < 2)
{
Message::SendFail() << "Syntax error at '" << aNameCase << "'";
return 1;
}
NCollection_Array1<TCollection_AsciiString> aSlices;
aSlices.Resize (0, aSlicesSeq.Size() - 1, false);
Standard_Integer aSliceIndex = 0;
for (const TCollection_AsciiString& aSliceIter : aSlicesSeq)
{
aSlices[aSliceIndex++] = aSliceIter;
}
toSetImage = true;
aTextureVecNew.SetValue (0, new Graphic3d_Texture3D (aSlices));
}
else if (aCommandName == "vtexture" else if (aCommandName == "vtexture"
&& (aTextureVecNew.IsEmpty() && (aTextureVecNew.IsEmpty()
|| aNameCase.StartsWith ("-tex"))) || aNameCase.StartsWith ("-tex")))
@ -4483,7 +4507,7 @@ Standard_Integer VTexture (Draw_Interpretor& theDi, Standard_Integer theArgsNb,
Message::SendFail() << "Syntax error: texture with ID " << aValue << " is undefined!"; Message::SendFail() << "Syntax error: texture with ID " << aValue << " is undefined!";
return 1; return 1;
} }
aTextureVecNew.SetValue (aTexIndex, new Graphic3d_Texture2Dmanual (Graphic3d_NameOfTexture2D (aValue))); aTextureVecNew.SetValue (aTexIndex, new Graphic3d_Texture2D (Graphic3d_NameOfTexture2D (aValue)));
} }
else if (aTexName == "?") else if (aTexName == "?")
{ {
@ -4507,11 +4531,11 @@ Standard_Integer VTexture (Draw_Interpretor& theDi, Standard_Integer theArgsNb,
Message::SendFail() << "Syntax error: non-existing image file has been specified '" << aTexName << "'."; Message::SendFail() << "Syntax error: non-existing image file has been specified '" << aTexName << "'.";
return 1; return 1;
} }
aTextureVecNew.SetValue (aTexIndex, new Graphic3d_Texture2Dmanual (aTexName)); aTextureVecNew.SetValue (aTexIndex, new Graphic3d_Texture2D (aTexName));
} }
else else
{ {
aTextureVecNew.SetValue (aTexIndex, Handle(Graphic3d_Texture2Dmanual)()); aTextureVecNew.SetValue (aTexIndex, Handle(Graphic3d_TextureMap)());
} }
if (aTextureVecNew.Value (aTexIndex)) if (aTextureVecNew.Value (aTexIndex))
@ -4537,7 +4561,7 @@ Standard_Integer VTexture (Draw_Interpretor& theDi, Standard_Integer theArgsNb,
aTextureSetNew = new Graphic3d_TextureSet (aTextureVecNew.Size()); aTextureSetNew = new Graphic3d_TextureSet (aTextureVecNew.Size());
for (Standard_Integer aTexIter = 0; aTexIter < aTextureSetNew->Size(); ++aTexIter) for (Standard_Integer aTexIter = 0; aTexIter < aTextureSetNew->Size(); ++aTexIter)
{ {
Handle(Graphic3d_Texture2Dmanual)& aTextureNew = aTextureVecNew.ChangeValue (aTexIter); Handle(Graphic3d_TextureMap)& aTextureNew = aTextureVecNew.ChangeValue (aTexIter);
Handle(Graphic3d_TextureRoot) aTextureOld; Handle(Graphic3d_TextureRoot) aTextureOld;
if (!aTextureSetOld.IsNull() if (!aTextureSetOld.IsNull()
&& aTexIter < aTextureSetOld->Size()) && aTexIter < aTextureSetOld->Size())
@ -4549,17 +4573,21 @@ Standard_Integer VTexture (Draw_Interpretor& theDi, Standard_Integer theArgsNb,
&& !aTextureNew.IsNull()) && !aTextureNew.IsNull())
{ {
*aTextureNew->GetParams() = *aTextureOld->GetParams(); *aTextureNew->GetParams() = *aTextureOld->GetParams();
if (Handle(Graphic3d_Texture2Dmanual) anOldManualTex = Handle(Graphic3d_Texture2Dmanual)::DownCast (aTextureOld))
Handle(Graphic3d_Texture2D) aTex2dNew = Handle(Graphic3d_Texture2D)::DownCast (aTextureNew);
Handle(Graphic3d_Texture2D) aTex2dOld = Handle(Graphic3d_Texture2D)::DownCast (aTextureOld);
if (!aTex2dOld.IsNull()
&& !aTex2dNew.IsNull())
{ {
TCollection_AsciiString aFilePathOld, aFilePathNew; TCollection_AsciiString aFilePathOld, aFilePathNew;
aTextureOld->Path().SystemName (aFilePathOld); aTextureOld->Path().SystemName (aFilePathOld);
aTextureNew->Path().SystemName (aFilePathNew); aTextureNew->Path().SystemName (aFilePathNew);
if (aTextureNew->Name() == anOldManualTex->Name() if (aTex2dNew->Name() == aTex2dOld->Name()
&& aFilePathOld == aFilePathNew && aFilePathOld == aFilePathNew
&& (!aFilePathNew.IsEmpty() || aTextureNew->Name() != Graphic3d_NOT_2D_UNKNOWN)) && (!aFilePathNew.IsEmpty() || aTex2dNew->Name() != Graphic3d_NOT_2D_UNKNOWN))
{ {
--aNbChanged; --aNbChanged;
aTextureNew = anOldManualTex; aTextureNew = aTex2dOld;
} }
} }
} }
@ -6816,6 +6844,7 @@ Sets default deflection coefficient (0.0008) that defines the quality of the sha
addCmd ("vtexture", VTexture, /* [vtexture] */ R"( addCmd ("vtexture", VTexture, /* [vtexture] */ R"(
vtexture [-noupdate|-update] name [ImageFile|IdOfTexture|off] vtexture [-noupdate|-update] name [ImageFile|IdOfTexture|off]
[-tex0 Image0] [-tex1 Image1] [...] [-tex0 Image0] [-tex1 Image1] [...]
[-3d Image0 Image1 ... ImageN]
[-origin {u v|off}] [-scale {u v|off}] [-repeat {u v|off}] [-origin {u v|off}] [-scale {u v|off}] [-repeat {u v|off}]
[-trsfTrans du dv] [-trsfScale su sv] [-trsfAngle Angle] [-trsfTrans du dv] [-trsfScale su sv] [-trsfAngle Angle]
[-modulate {on|off}] [-srgb {on|off}]=on [-modulate {on|off}] [-srgb {on|off}]=on
@ -6836,6 +6865,7 @@ The options are:
-setFilter Setup texture filter -setFilter Setup texture filter
-setAnisoFilter Setup anisotropic filter for texture with mip-levels -setAnisoFilter Setup anisotropic filter for texture with mip-levels
-default Sets texture mapping default parameters -default Sets texture mapping default parameters
-3d Load 3D texture from the list of 2D image files
)" /* [vtexture] */); )" /* [vtexture] */);
addCmd ("vtexscale", VTexture, /* [vtexscale] */ R"( addCmd ("vtexscale", VTexture, /* [vtexscale] */ R"(

View File

@ -411,6 +411,15 @@ static Standard_Integer VShaderProg (Draw_Interpretor& ,
} }
aProgram->SetHeader (aHeader); aProgram->SetHeader (aHeader);
} }
else if (!aProgram.IsNull()
&& (anArg == "-defaultsampler"
|| anArg == "-defampler"
|| anArg == "-nodefaultsampler"
|| anArg == "-nodefsampler"))
{
bool toUseDefSampler = Draw::ParseOnOffNoIterator (theArgNb, theArgVec, anArgIter);
aProgram->SetDefaultSampler (toUseDefSampler);
}
else if (!anArg.StartsWith ("-") else if (!anArg.StartsWith ("-")
&& GetMapOfAIS().IsBound2 (theArgVec[anArgIter])) && GetMapOfAIS().IsBound2 (theArgVec[anArgIter]))
{ {
@ -1187,6 +1196,7 @@ vshader name -vert VertexShader -frag FragmentShader [-geom GeometryShader]
[-header VersionHeader] [-header VersionHeader]
[-tessControl TessControlShader -tessEval TessEvaluationShader] [-tessControl TessControlShader -tessEval TessEvaluationShader]
[-uniform Name FloatValue] [-uniform Name FloatValue]
[-defaultSampler {0|1}]=1
Assign custom GLSL program to presentation aspects. Assign custom GLSL program to presentation aspects.
)" /* [vshader] */); )" /* [vshader] */);

View File

@ -55,7 +55,7 @@
#include <Graphic3d_GraphicDriver.hxx> #include <Graphic3d_GraphicDriver.hxx>
#include <Graphic3d_GraphicDriverFactory.hxx> #include <Graphic3d_GraphicDriverFactory.hxx>
#include <Graphic3d_NameOfTextureEnv.hxx> #include <Graphic3d_NameOfTextureEnv.hxx>
#include <Graphic3d_Texture2Dmanual.hxx> #include <Graphic3d_Texture2D.hxx>
#include <Graphic3d_TextureEnv.hxx> #include <Graphic3d_TextureEnv.hxx>
#include <Graphic3d_TextureParams.hxx> #include <Graphic3d_TextureParams.hxx>
#include <Graphic3d_TypeOfTextureFilter.hxx> #include <Graphic3d_TypeOfTextureFilter.hxx>
@ -3069,7 +3069,7 @@ static int VBackground (Draw_Interpretor& theDI,
if (!anImagePath.IsEmpty()) if (!anImagePath.IsEmpty())
{ {
Handle(Graphic3d_Texture2D) aTextureMap = new Graphic3d_Texture2Dmanual (anImagePath); Handle(Graphic3d_Texture2D) aTextureMap = new Graphic3d_Texture2D (anImagePath);
aTextureMap->DisableModulate(); aTextureMap->DisableModulate();
aTextureMap->SetColorMap (isSRgb); aTextureMap->SetColorMap (isSRgb);
if (!aTextureMap->IsDone()) if (!aTextureMap->IsDone())
@ -5897,7 +5897,7 @@ public:
aMat.SetSpecularColor (Quantity_NOC_BLACK); aMat.SetSpecularColor (Quantity_NOC_BLACK);
aMat.SetEmissiveColor (Quantity_NOC_BLACK); aMat.SetEmissiveColor (Quantity_NOC_BLACK);
aFillAspect->SetFrontMaterial (aMat); aFillAspect->SetFrontMaterial (aMat);
aFillAspect->SetTextureMap (new Graphic3d_Texture2Dmanual (theImage)); aFillAspect->SetTextureMap (new Graphic3d_Texture2D (theImage));
aFillAspect->SetTextureMapOn(); aFillAspect->SetTextureMapOn();
} }
{ {
@ -8609,7 +8609,7 @@ static int VClipPlane (Draw_Interpretor& theDi, Standard_Integer theArgsNb, cons
} }
TCollection_AsciiString aTextureName (aChangeArgs[1]); TCollection_AsciiString aTextureName (aChangeArgs[1]);
Handle(Graphic3d_Texture2Dmanual) aTexture = new Graphic3d_Texture2Dmanual(aTextureName); Handle(Graphic3d_Texture2D) aTexture = new Graphic3d_Texture2D (aTextureName);
if (!aTexture->IsDone()) if (!aTexture->IsDone())
{ {
aClipPlane->SetCappingTexture (NULL); aClipPlane->SetCappingTexture (NULL);

View File

@ -15,7 +15,7 @@
#include <Graphic3d_TextureParams.hxx> #include <Graphic3d_TextureParams.hxx>
IMPLEMENT_STANDARD_RTTIEXT(XCAFPrs_Texture, Graphic3d_Texture2Dmanual) IMPLEMENT_STANDARD_RTTIEXT(XCAFPrs_Texture, Graphic3d_Texture2D)
//======================================================================= //=======================================================================
//function : XCAFPrs_Texture //function : XCAFPrs_Texture
@ -23,7 +23,7 @@ IMPLEMENT_STANDARD_RTTIEXT(XCAFPrs_Texture, Graphic3d_Texture2Dmanual)
//======================================================================= //=======================================================================
XCAFPrs_Texture::XCAFPrs_Texture (const Image_Texture& theImageSource, XCAFPrs_Texture::XCAFPrs_Texture (const Image_Texture& theImageSource,
const Graphic3d_TextureUnit theUnit) const Graphic3d_TextureUnit theUnit)
: Graphic3d_Texture2Dmanual (""), : Graphic3d_Texture2D (""),
myImageSource (theImageSource) myImageSource (theImageSource)
{ {
if (!myImageSource.TextureId().IsEmpty()) if (!myImageSource.TextureId().IsEmpty())

View File

@ -21,9 +21,9 @@
#include <Image_Texture.hxx> #include <Image_Texture.hxx>
//! Texture holder. //! Texture holder.
class XCAFPrs_Texture : public Graphic3d_Texture2Dmanual class XCAFPrs_Texture : public Graphic3d_Texture2D
{ {
DEFINE_STANDARD_RTTIEXT(XCAFPrs_Texture, Graphic3d_Texture2Dmanual) DEFINE_STANDARD_RTTIEXT(XCAFPrs_Texture, Graphic3d_Texture2D)
public: public:
//! Constructor. //! Constructor.

View File

@ -17,8 +17,6 @@ vinit v -w 512 -h 512
vcamera -fovy 100 vcamera -fovy 100
if { [checkplatform -windows] && [vdriver -default] == "TKOpenGles" } { if { [checkplatform -windows] && [vdriver -default] == "TKOpenGles" } {
# Mipmaps cannot be generated for GL_SRGB8 texture format # Mipmaps cannot be generated for GL_SRGB8 texture format
puts "TODO OCC30807 ALL: TKOpenGl | Type: Error"
puts "TODO OCC30807 ALL: Unable to generate mipmap of cubemap"
} }
vbackground -cubemap $aCubeMap_posx $aCubeMap_negx $aCubeMap_posy $aCubeMap_negy $aCubeMap_posz $aCubeMap_negz vbackground -cubemap $aCubeMap_posx $aCubeMap_negx $aCubeMap_posy $aCubeMap_negy $aCubeMap_posz $aCubeMap_negz

View File

@ -0,0 +1,60 @@
puts "========"
puts "0032862: Visualization, Graphic3d_TextureMap - add 3D texture definition"
puts "========"
pload MODELING VISUALIZATION
set aTex1 [locate_data_file SF_CubeMap_posx.jpg]
set aTex2 [locate_data_file SF_CubeMap_negx.jpg]
set aTex3 [locate_data_file SF_CubeMap_posy.jpg]
set aTex4 [locate_data_file SF_CubeMap_negy.jpg]
set aTex5 [locate_data_file SF_CubeMap_posz.jpg]
set aTex6 [locate_data_file SF_CubeMap_negz.jpg]
set aShaderVert "
THE_SHADER_OUT vec3 TexCoord;
uniform float uSlice;
void main() {
float aNbSlices = 6.0;
TexCoord = occVertex.xyz;
if (uSlice >= 0.0) { TexCoord = vec3(occTexCoord.xy, uSlice * 1.0 / aNbSlices + 0.5 / aNbSlices); }
if (occTextureTrsf_Scale().y < 0.0) { TexCoord.y = 1.0 - TexCoord.y; }
gl_Position = occProjectionMatrix * occWorldViewMatrix * occModelWorldMatrix * occVertex;
}"
set aShaderFrag "
#ifdef GL_ES
uniform mediump sampler3D occSampler0;
#else
uniform sampler3D occSampler0;
#endif
THE_SHADER_IN vec3 TexCoord;
void main() {
occFragColor = occTexture3D(occSampler0, TexCoord);
}"
set aGlslVer "#version 110"
if { [vdriver -default] == "TKOpenGles" } { set aGlslVer "#version 300 es" }
# draw a box
box b 1.0 1.0 1.0
vclear
vclose ALL
vinit View1
vaxo
vdisplay -dispMode 1 b
vfit
vrotate 0.2 0.0 0.0
# load 3D texture
vtexture b -3d $aTex1 $aTex2 $aTex3 $aTex4 $aTex5 $aTex6
# texture slices
foreach aSliceIter {0 1 2 3 4 5} {
vshaderprog b -vert $aShaderVert -frag $aShaderFrag -defaultSampler 0 -uniform "uSlice" ${aSliceIter} -header "$aGlslVer"
vdump $::imagedir/${::casename}_s${aSliceIter}.png
}
# texture interpolation
vshaderprog b -vert $aShaderVert -frag $aShaderFrag -defaultSampler 0 -uniform "uSlice" -1 -header "$aGlslVer"
vdump $::imagedir/${::casename}_def.png