mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-04-06 18:26:22 +03:00
0022591: Migration to FreeImage: texture management
Graphic3d_TextureRoot - migrate to Image_AlienPixMap OpenGl_View::CreateBackgroundTexture() - migrate to Image_AlienPixMap Fixed Graphic3d_TextureRoot::LoadTexture() method.
This commit is contained in:
parent
33a085531a
commit
3c3131a05d
@ -188,12 +188,6 @@ is
|
||||
is deferred;
|
||||
---Purpose: call_togl_inquireview
|
||||
|
||||
InquireTextureAvailable ( me : mutable )
|
||||
returns Boolean from Standard
|
||||
is deferred;
|
||||
---Purpose: Returns Standard_True if texture is
|
||||
-- supported by the graphic driver
|
||||
|
||||
------------------------------
|
||||
-- Category: Highlight methods
|
||||
------------------------------
|
||||
@ -810,12 +804,12 @@ is
|
||||
-- Category: Textures methods
|
||||
-----------------------------
|
||||
|
||||
CreateTexture ( me;
|
||||
Type : TypeOfTexture from Graphic3d;
|
||||
Image : AlienImage from AlienImage;
|
||||
FileName : CString from Standard;
|
||||
TexUpperBounds : HArray1OfReal from TColStd )
|
||||
returns Integer from Standard
|
||||
CreateTexture ( me;
|
||||
theType : TypeOfTexture from Graphic3d;
|
||||
theImage : PixMap from Image;
|
||||
theFileName : CString from Standard;
|
||||
theTexUpperBounds : HArray1OfReal from TColStd )
|
||||
returns Integer from Standard
|
||||
is deferred;
|
||||
---Purpose:
|
||||
|
||||
|
@ -18,88 +18,71 @@
|
||||
-- purpose or non-infringement. Please see the License for the specific terms
|
||||
-- and conditions governing the rights and limitations under the License.
|
||||
|
||||
-- Modified: GG 10/01/2000 IMP add Path() & Type() methods.
|
||||
-- GG 10/11/2000 IMP add Image() & LoadTexture() methods.
|
||||
-- Remove MyIsDone field
|
||||
-- Add MyImage field
|
||||
deferred class TextureRoot from Graphic3d
|
||||
|
||||
deferred class TextureRoot from Graphic3d
|
||||
|
||||
inherits TShared from MMgt
|
||||
inherits TShared from MMgt
|
||||
|
||||
---Purpose: This is the texture root class enable the dialog with the GraphicDriver
|
||||
-- allows the loading of texture too supported formats:
|
||||
-- X, SunRaster, Aida, Euclid, SGI rgb
|
||||
-- allows the loading of texture.
|
||||
|
||||
uses
|
||||
CInitTexture from Graphic3d,
|
||||
GraphicDriver from Graphic3d,
|
||||
StructureManager from Graphic3d,
|
||||
TypeOfTexture from Graphic3d,
|
||||
AlienImage from AlienImage,
|
||||
Path from OSD,
|
||||
HArray1OfReal from TColStd
|
||||
|
||||
CInitTexture from Graphic3d,
|
||||
GraphicDriver from Graphic3d,
|
||||
StructureManager from Graphic3d,
|
||||
TypeOfTexture from Graphic3d,
|
||||
PixMap from Image,
|
||||
Path from OSD,
|
||||
HArray1OfReal from TColStd
|
||||
|
||||
is
|
||||
Initialize(SM : StructureManager from Graphic3d;
|
||||
Path : CString from Standard;
|
||||
FileName : CString from Standard;
|
||||
Type : TypeOfTexture from Graphic3d);
|
||||
|
||||
Initialize (theSM : StructureManager from Graphic3d;
|
||||
thePath : CString from Standard;
|
||||
theFileName : CString from Standard;
|
||||
theType : TypeOfTexture from Graphic3d);
|
||||
---Purpose: Creates a texture from a file
|
||||
-- Warning: Note that if <FileName> is NULL the texture must be realized
|
||||
-- using LoadTexture(image) method.
|
||||
|
||||
Destroy(me);
|
||||
Destroy (me);
|
||||
---C++ : alias ~
|
||||
|
||||
--
|
||||
-- public methods
|
||||
--
|
||||
|
||||
IsDone(me) returns Boolean from Standard;
|
||||
IsDone (me) returns Boolean from Standard;
|
||||
---Level: public
|
||||
---Purpose: Checks if a texture class is valide or not
|
||||
---Purpose: Checks if a texture class is valid or not
|
||||
-- returns true if the construction of the class is correct
|
||||
|
||||
Path(me) returns Path from OSD;
|
||||
IsValid (me) returns Boolean from Standard;
|
||||
---Level: public
|
||||
---Purpose: Checks if a texture class is valid or not
|
||||
-- returns true if the construction of the class is correct
|
||||
|
||||
Path (me) returns Path from OSD;
|
||||
---Level: public
|
||||
---Purpose:
|
||||
-- Returns the full path of the defined texture.
|
||||
---C++: return const &
|
||||
|
||||
Type(me) returns TypeOfTexture from Graphic3d;
|
||||
Type (me) returns TypeOfTexture from Graphic3d;
|
||||
---Level: public
|
||||
---Purpose:
|
||||
-- Returns the texture type.
|
||||
|
||||
|
||||
--
|
||||
-- private methods
|
||||
--
|
||||
|
||||
Update(me) is protected;
|
||||
|
||||
LoadTexture(me : mutable; anImage: AlienImage from AlienImage);
|
||||
LoadTexture (me : mutable; theImage : PixMap from Image) returns Boolean from Standard;
|
||||
---Level: advanced
|
||||
---Purpose:
|
||||
-- Updates the current texture from a requested alien image.
|
||||
-- Updates the current texture from a requested image.
|
||||
|
||||
LoadTexture(me)
|
||||
returns AlienImage from AlienImage
|
||||
is private;
|
||||
|
||||
TextureId(me) returns Integer from Standard;
|
||||
TextureId (me) returns Integer from Standard;
|
||||
---Level: advanced
|
||||
---Purpose:
|
||||
-- returns the Texture ID which references the
|
||||
-- texture to use for drawing. Used by the
|
||||
-- graphic driver.
|
||||
|
||||
Image(me) returns AlienImage from AlienImage;
|
||||
---Level: advanced
|
||||
---Purpose:
|
||||
-- Returns the created image texture.
|
||||
-- texture to use for drawing. Used by the graphic driver.
|
||||
|
||||
GetTexUpperBounds(me) returns HArray1OfReal from TColStd;
|
||||
---Level: advanced
|
||||
@ -107,17 +90,19 @@ is
|
||||
---Gets upper bounds of texture coordinates. This is used when sizes
|
||||
---of texture are not equal to the powers of two
|
||||
|
||||
-- internal fields for managing the class
|
||||
--
|
||||
-- private methods
|
||||
--
|
||||
|
||||
Update (me) is protected;
|
||||
|
||||
fields
|
||||
MyGraphicDriver : GraphicDriver from Graphic3d;
|
||||
MyTexId : Integer from Standard;
|
||||
MyCInitTexture : CInitTexture from Graphic3d is protected;
|
||||
-- MyIsDone : Boolean from Standard;
|
||||
MyPath : Path from OSD;
|
||||
MyType : TypeOfTexture from Graphic3d;
|
||||
MyImage : AlienImage from AlienImage;
|
||||
MyTexUpperBounds : HArray1OfReal from TColStd;
|
||||
|
||||
end TextureRoot;
|
||||
|
||||
myGraphicDriver : GraphicDriver from Graphic3d;
|
||||
myTexId : Integer from Standard;
|
||||
MyCInitTexture : CInitTexture from Graphic3d is protected;
|
||||
myPath : Path from OSD;
|
||||
myType : TypeOfTexture from Graphic3d;
|
||||
myTexUpperBounds : HArray1OfReal from TColStd;
|
||||
|
||||
end TextureRoot;
|
||||
|
@ -18,215 +18,142 @@
|
||||
// purpose or non-infringement. Please see the License for the specific terms
|
||||
// and conditions governing the rights and limitations under the License.
|
||||
|
||||
// modified:
|
||||
// 8/09/97 : mise en commentaire des tentatives pour charger
|
||||
// autre chose que du RGB. AlienImage buggee ?
|
||||
// 5/01/99 : Ajout test sur les objets Path et FileName dans LoadTexture().
|
||||
// Si le path est null on trappe.
|
||||
// 11/06/99 : GG Enable to use GIF and BMP image format
|
||||
// 10/01/00 : GG IMP Add Path() and Type() methods.
|
||||
// 10/11/00 : GG Add Image() & LoadTexture() methods.
|
||||
|
||||
#define IMP140601 //GG Avoid to change the Trek of the current defined path
|
||||
// when the directory string is NULL or empty.
|
||||
|
||||
#define xTRACE 1
|
||||
|
||||
#include <Graphic3d_TextureRoot.ixx>
|
||||
#include <Graphic3d_GraphicDevice.hxx>
|
||||
#include <Graphic3d_GraphicDriver.hxx>
|
||||
|
||||
#include <AlienImage_EuclidAlienImage.hxx>
|
||||
#include <AlienImage_SGIRGBAlienImage.hxx>
|
||||
#include <AlienImage_XAlienImage.hxx>
|
||||
#include <AlienImage_GIFAlienImage.hxx>
|
||||
#include <AlienImage_BMPAlienImage.hxx>
|
||||
#include <AlienImage_AidaAlienImage.hxx>
|
||||
#include <AlienImage_SunRFAlienImage.hxx>
|
||||
#include <AlienImage_AlienImage.hxx>
|
||||
#include <Image_AlienPixMap.hxx>
|
||||
|
||||
#include <OSD_Protection.hxx>
|
||||
#include <OSD_File.hxx>
|
||||
#include <stdio.h>
|
||||
|
||||
Graphic3d_TextureRoot::Graphic3d_TextureRoot(const Handle(Graphic3d_StructureManager)& SM,const Standard_CString Path,const Standard_CString FileName,const Graphic3d_TypeOfTexture Type) : MyPath(FileName),MyType(Type)
|
||||
// =======================================================================
|
||||
// function : Graphic3d_TextureRoot
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
Graphic3d_TextureRoot::Graphic3d_TextureRoot (const Handle(Graphic3d_StructureManager)& theSM,
|
||||
const Standard_CString thePath,
|
||||
const Standard_CString theFileName,
|
||||
const Graphic3d_TypeOfTexture theType)
|
||||
: myGraphicDriver (Handle(Graphic3d_GraphicDriver)::DownCast (theSM->GraphicDevice()->GraphicDriver())),
|
||||
myTexId (-1),
|
||||
myPath (theFileName),
|
||||
myType (theType),
|
||||
myTexUpperBounds (new TColStd_HArray1OfReal (1, 2)) // currently always allocating an array for two texture bounds...
|
||||
{
|
||||
// It will be necessary to improve the code below as soon as 3D or 4D textures
|
||||
// are implemented. Currently, always allocating an array for two texture bounds...
|
||||
MyTexUpperBounds = new TColStd_HArray1OfReal(1,2);
|
||||
|
||||
#ifdef IMP140601
|
||||
if( Path && (strlen(Path) > 0) )
|
||||
#endif
|
||||
MyPath.SetTrek(TCollection_AsciiString( Path ));
|
||||
|
||||
MyGraphicDriver = Handle(Graphic3d_GraphicDriver)::DownCast(SM->GraphicDevice()->GraphicDriver());
|
||||
|
||||
if (MyGraphicDriver->InquireTextureAvailable())
|
||||
if (thePath != NULL && (strlen (thePath) > 0))
|
||||
{
|
||||
// chargement de l'image
|
||||
//-GG Handle(AlienImage_AlienImage) MyImage = LoadTexture();
|
||||
if (MyImage.IsNull() && FileName && (strlen(FileName) > 0))
|
||||
MyImage = LoadTexture();
|
||||
|
||||
if (MyImage.IsNull()) {
|
||||
MyTexId = -1;
|
||||
return;
|
||||
}
|
||||
|
||||
MyTexId = MyGraphicDriver->CreateTexture(Type, MyImage, FileName, MyTexUpperBounds);
|
||||
myPath.SetTrek (TCollection_AsciiString (thePath));
|
||||
}
|
||||
#ifdef TRACE
|
||||
printf(" *** Graphic3d_TextureRoot::Create() textId %d\n",MyTexId);
|
||||
#endif
|
||||
|
||||
if (theFileName == NULL || (strlen (theFileName) <= 0))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
TCollection_AsciiString aFilePath;
|
||||
myPath.SystemName (aFilePath);
|
||||
Image_AlienPixMap anImage;
|
||||
if (!anImage.Load (aFilePath))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
myTexId = myGraphicDriver->CreateTexture (myType, anImage, theFileName, myTexUpperBounds);
|
||||
Update();
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : Destroy
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
void Graphic3d_TextureRoot::Destroy() const
|
||||
{
|
||||
if (MyTexId >= 0 )
|
||||
MyGraphicDriver->DestroyTexture(MyTexId);
|
||||
#ifdef TRACE
|
||||
printf(" *** Graphic3d_TextureRoot::Destroy() textId %d\n",MyTexId);
|
||||
#endif
|
||||
if (IsValid())
|
||||
{
|
||||
myGraphicDriver->DestroyTexture (myTexId);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// =======================================================================
|
||||
// function : TextureId
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
Standard_Integer Graphic3d_TextureRoot::TextureId() const
|
||||
{
|
||||
return MyTexId;
|
||||
return myTexId;
|
||||
}
|
||||
|
||||
|
||||
// =======================================================================
|
||||
// function : Update
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
void Graphic3d_TextureRoot::Update() const
|
||||
{
|
||||
if( MyTexId >= 0 )
|
||||
MyGraphicDriver->ModifyTexture(MyTexId, MyCInitTexture);
|
||||
if (IsValid())
|
||||
{
|
||||
myGraphicDriver->ModifyTexture (myTexId, MyCInitTexture);
|
||||
}
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : IsValid
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
Standard_Boolean Graphic3d_TextureRoot::IsValid() const
|
||||
{
|
||||
return myTexId >= 0;
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : IsDone
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
Standard_Boolean Graphic3d_TextureRoot::IsDone() const
|
||||
{
|
||||
return (MyTexId >= 0) ? Standard_True : Standard_False;
|
||||
return myTexId >= 0;
|
||||
}
|
||||
|
||||
void Graphic3d_TextureRoot::LoadTexture(const Handle(AlienImage_AlienImage)& anImage) {
|
||||
|
||||
if (MyGraphicDriver->InquireTextureAvailable()) {
|
||||
if( MyTexId >= 0 )
|
||||
MyGraphicDriver->DestroyTexture(MyTexId);
|
||||
MyImage = anImage;
|
||||
MyTexId = MyGraphicDriver->CreateTexture(MyType, MyImage, "", MyTexUpperBounds);
|
||||
Update();
|
||||
}
|
||||
}
|
||||
|
||||
Handle(AlienImage_AlienImage) Graphic3d_TextureRoot::LoadTexture() const
|
||||
// =======================================================================
|
||||
// function : LoadTexture
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
Standard_Boolean Graphic3d_TextureRoot::LoadTexture (const Image_PixMap& theImage)
|
||||
{
|
||||
OSD_Protection Protection( OSD_R, OSD_R, OSD_R, OSD_R ) ; /* Read Only */
|
||||
Handle(AlienImage_AlienImage) TheAlienImage = NULL ;
|
||||
|
||||
OSD_File File(MyPath);
|
||||
File.Open(OSD_ReadOnly, Protection);
|
||||
|
||||
// open file ok ?
|
||||
if ( File.IsOpen() == Standard_False ) {
|
||||
TCollection_AsciiString sysname;
|
||||
MyPath.SystemName(sysname);
|
||||
cout << " *** Can't open texture file '" << sysname << "'" << endl;
|
||||
return TheAlienImage;
|
||||
if (myTexId >= 0)
|
||||
{
|
||||
myGraphicDriver->DestroyTexture (myTexId);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////
|
||||
// file reading //
|
||||
////////////////////////
|
||||
|
||||
|
||||
// image X ?
|
||||
////////////
|
||||
Handle(AlienImage_XAlienImage) XAlienImage = new AlienImage_XAlienImage() ;
|
||||
|
||||
if (XAlienImage->Read( File )) {
|
||||
File.Close();
|
||||
return XAlienImage;
|
||||
}
|
||||
|
||||
// image GIF ?
|
||||
////////////
|
||||
Handle(AlienImage_GIFAlienImage) GIFAlienImage = new AlienImage_GIFAlienImage() ;
|
||||
|
||||
if (GIFAlienImage->Read( File )) {
|
||||
File.Close();
|
||||
return GIFAlienImage;
|
||||
}
|
||||
|
||||
// image BMP ?
|
||||
////////////
|
||||
Handle(AlienImage_BMPAlienImage) BMPAlienImage = new AlienImage_BMPAlienImage() ;
|
||||
|
||||
if (BMPAlienImage->Read( File )) {
|
||||
File.Close();
|
||||
return BMPAlienImage;
|
||||
}
|
||||
|
||||
// SunRaster ?
|
||||
//////////////
|
||||
Handle(AlienImage_SunRFAlienImage) SunRFAlienImage = new AlienImage_SunRFAlienImage() ;
|
||||
|
||||
if (SunRFAlienImage->Read( File )) {
|
||||
File.Close();
|
||||
return SunRFAlienImage;
|
||||
}
|
||||
|
||||
// Aida ?
|
||||
/////////
|
||||
Handle(AlienImage_AidaAlienImage) AidaAlienImage = new AlienImage_AidaAlienImage() ;
|
||||
|
||||
if (AidaAlienImage->Read( File )) {
|
||||
File.Close();
|
||||
return AidaAlienImage;
|
||||
}
|
||||
|
||||
// Euclid ?
|
||||
///////////
|
||||
Handle(AlienImage_EuclidAlienImage) EuclidAlienImage = new AlienImage_EuclidAlienImage() ;
|
||||
|
||||
if (EuclidAlienImage->Read( File )) {
|
||||
File.Close();
|
||||
return EuclidAlienImage;
|
||||
}
|
||||
|
||||
|
||||
// SGIRGB ?
|
||||
///////////
|
||||
Handle(AlienImage_SGIRGBAlienImage) SGIRGBAlienImage = new AlienImage_SGIRGBAlienImage() ;
|
||||
|
||||
if (SGIRGBAlienImage->Read( File )) {
|
||||
File.Close();
|
||||
return SGIRGBAlienImage;
|
||||
}
|
||||
|
||||
|
||||
// raise exception: file type unknown
|
||||
return TheAlienImage;
|
||||
myTexId = myGraphicDriver->CreateTexture (myType, theImage, "", myTexUpperBounds);
|
||||
Update();
|
||||
return IsValid();
|
||||
}
|
||||
|
||||
const OSD_Path& Graphic3d_TextureRoot::Path() const {
|
||||
|
||||
return MyPath;
|
||||
// =======================================================================
|
||||
// function : Path
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
const OSD_Path& Graphic3d_TextureRoot::Path() const
|
||||
{
|
||||
return myPath;
|
||||
}
|
||||
|
||||
Graphic3d_TypeOfTexture Graphic3d_TextureRoot::Type() const {
|
||||
|
||||
return MyType;
|
||||
}
|
||||
|
||||
Handle(AlienImage_AlienImage) Graphic3d_TextureRoot::Image() const {
|
||||
|
||||
return MyImage;
|
||||
// =======================================================================
|
||||
// function : Type
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
Graphic3d_TypeOfTexture Graphic3d_TextureRoot::Type() const
|
||||
{
|
||||
return myType;
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : GetTexUpperBounds
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
Handle(TColStd_HArray1OfReal) Graphic3d_TextureRoot::GetTexUpperBounds() const
|
||||
{
|
||||
return MyTexUpperBounds;
|
||||
return myTexUpperBounds;
|
||||
}
|
||||
|
@ -182,7 +182,7 @@ bool Image_AlienPixMap::InitTrash (ImgFormat thePixelFormat,
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : Clear
|
||||
// function : InitCopy
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
bool Image_AlienPixMap::InitCopy (const Image_PixMap& theCopy)
|
||||
@ -368,7 +368,6 @@ bool Image_AlienPixMap::Save (const TCollection_AsciiString& theFileName)
|
||||
|
||||
// FreeImage doesn't provide flexible format convertion API
|
||||
// so we should perform multiple convertions in some cases!
|
||||
Standard_Boolean isCopied = Standard_False;
|
||||
FIBITMAP* anImageToDump = myLibImage;
|
||||
switch (anImageFormat)
|
||||
{
|
||||
|
@ -53,9 +53,7 @@
|
||||
#include <MeshVS_Buffer.hxx>
|
||||
|
||||
#include <gp_Pnt.hxx>
|
||||
#include <Image_ColorImage.hxx>
|
||||
#include <AlienImage_AlienImage.hxx>
|
||||
#include <AlienImage_BMPAlienImage.hxx>
|
||||
#include <Image_PixMap.hxx>
|
||||
#include <Graphic3d_Texture2D.hxx>
|
||||
#include <Graphic3d_TypeOfTextureMode.hxx>
|
||||
#include <Standard_DefineHandle.hxx>
|
||||
@ -72,22 +70,21 @@
|
||||
class MeshVS_ImageTexture2D : public Graphic3d_Texture2D
|
||||
{
|
||||
public:
|
||||
MeshVS_ImageTexture2D( Handle(Graphic3d_StructureManager) theSM,
|
||||
const Handle(AlienImage_AlienImage)& theImg );
|
||||
MeshVS_ImageTexture2D (Handle(Graphic3d_StructureManager) theSM,
|
||||
const Image_PixMap& theImg);
|
||||
virtual ~MeshVS_ImageTexture2D();
|
||||
|
||||
public:
|
||||
DEFINE_STANDARD_RTTI(MeshVS_ImageTexture2D)
|
||||
};
|
||||
|
||||
DEFINE_STANDARD_HANDLE(MeshVS_ImageTexture2D,Graphic3d_Texture2D)
|
||||
IMPLEMENT_STANDARD_HANDLE(MeshVS_ImageTexture2D,Graphic3d_Texture2D)
|
||||
DEFINE_STANDARD_HANDLE (MeshVS_ImageTexture2D, Graphic3d_Texture2D)
|
||||
IMPLEMENT_STANDARD_HANDLE (MeshVS_ImageTexture2D, Graphic3d_Texture2D)
|
||||
IMPLEMENT_STANDARD_RTTIEXT(MeshVS_ImageTexture2D, Graphic3d_Texture2D)
|
||||
|
||||
MeshVS_ImageTexture2D::MeshVS_ImageTexture2D
|
||||
(Handle(Graphic3d_StructureManager) theSM,
|
||||
const Handle(AlienImage_AlienImage)& theImg)
|
||||
: Graphic3d_Texture2D( theSM, "", Graphic3d_TOT_2D )
|
||||
MeshVS_ImageTexture2D::MeshVS_ImageTexture2D (Handle(Graphic3d_StructureManager) theSM,
|
||||
const Image_PixMap& theImg)
|
||||
: Graphic3d_Texture2D (theSM, "", Graphic3d_TOT_2D)
|
||||
{
|
||||
MyCInitTexture.doModulate = 1;
|
||||
MyCInitTexture.doRepeat = 0;
|
||||
@ -720,43 +717,65 @@ Standard_Real MeshVS_NodalColorPrsBuilder::GetTextureCoord( const Standard_Integ
|
||||
//================================================================
|
||||
Handle(Graphic3d_Texture2D) MeshVS_NodalColorPrsBuilder::CreateTexture() const
|
||||
{
|
||||
Handle(Graphic3d_Texture2D) aTexture;
|
||||
|
||||
int nbColors = myTextureColorMap.Length();
|
||||
if ( nbColors == 0 )
|
||||
return aTexture;
|
||||
|
||||
Handle(PrsMgr_PresentationManager3d) aPrsMgr = GetPresentationManager();
|
||||
if ( aPrsMgr.IsNull() )
|
||||
return aTexture;
|
||||
|
||||
int nbTextureColors = getNearestPow2( nbColors );
|
||||
|
||||
// Create and fill image with colors
|
||||
Handle(Image_ColorImage) aCImage =
|
||||
new Image_ColorImage( 0, 0, nbTextureColors, 2 );
|
||||
|
||||
if ( nbColors > 0 )
|
||||
const Standard_Integer aColorsNb = myTextureColorMap.Length();
|
||||
if (aColorsNb == 0)
|
||||
{
|
||||
int i;
|
||||
for ( i = 0; i < nbColors; i++ )
|
||||
{
|
||||
aCImage->SetPixel( i, 0, Aspect_ColorPixel( myTextureColorMap( i + 1 ) ) );
|
||||
aCImage->SetPixel( i, 1, Aspect_ColorPixel( myInvalidColor ) );
|
||||
}
|
||||
Quantity_Color aLastColor = myTextureColorMap( nbColors );
|
||||
for ( i = nbColors; i < nbTextureColors; i++ )
|
||||
{
|
||||
aCImage->SetPixel( i, 0, aLastColor );
|
||||
aCImage->SetPixel( i, 1, Aspect_ColorPixel( myInvalidColor ) );
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Convert image to bmp
|
||||
Handle(AlienImage_BMPAlienImage) aTextureImage = new AlienImage_BMPAlienImage();
|
||||
aTextureImage->FromImage( aCImage );
|
||||
Handle(PrsMgr_PresentationManager3d) aPrsMgr = GetPresentationManager();
|
||||
if (aPrsMgr.IsNull())
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Create texture
|
||||
aTexture = new MeshVS_ImageTexture2D( aPrsMgr->StructureManager(), aTextureImage );
|
||||
return aTexture;
|
||||
// create and fill image with colors
|
||||
Image_PixMap anImage;
|
||||
if (!anImage.InitTrash (Image_PixMap::ImgRGBA, Standard_Size(getNearestPow2 (aColorsNb)), 2))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
anImage.SetTopDown (false);
|
||||
Image_PixMapData<Image_ColorRGBA>& aData = anImage.EditData<Image_ColorRGBA>();
|
||||
for (Standard_Size aCol = 0; aCol < Standard_Size(aColorsNb); ++aCol)
|
||||
{
|
||||
const Quantity_Color& aSrcColor = myTextureColorMap.Value (Standard_Integer(aCol) + 1);
|
||||
Image_ColorRGBA& aColor = aData.ChangeValue (0, aCol);
|
||||
aColor.r() = int(255.0 * aSrcColor.Red());
|
||||
aColor.g() = int(255.0 * aSrcColor.Green());
|
||||
aColor.b() = int(255.0 * aSrcColor.Blue());
|
||||
aColor.a() = 0xFF;
|
||||
}
|
||||
|
||||
// fill padding bytes
|
||||
const Quantity_Color& aLastColorSrc = myTextureColorMap.Last();
|
||||
const Image_ColorRGBA aLastColor =
|
||||
{{
|
||||
int(255.0 * aLastColorSrc.Red()),
|
||||
int(255.0 * aLastColorSrc.Green()),
|
||||
int(255.0 * aLastColorSrc.Blue()),
|
||||
0xFF
|
||||
}};
|
||||
|
||||
// fill second row
|
||||
for (Standard_Size aCol = (Standard_Size )aColorsNb; aCol < anImage.SizeX(); ++aCol)
|
||||
{
|
||||
aData.ChangeValue (0, aCol) = aLastColor;
|
||||
}
|
||||
|
||||
const Image_ColorRGBA anInvalidColor =
|
||||
{{
|
||||
int(255.0 * myInvalidColor.Red()),
|
||||
int(255.0 * myInvalidColor.Green()),
|
||||
int(255.0 * myInvalidColor.Blue()),
|
||||
0xFF
|
||||
}};
|
||||
for (Standard_Size aCol = 0; aCol < anImage.SizeX(); ++aCol)
|
||||
{
|
||||
aData.ChangeValue (1, aCol) = anInvalidColor;
|
||||
}
|
||||
|
||||
// create texture
|
||||
return new MeshVS_ImageTexture2D (aPrsMgr->StructureManager(), anImage);
|
||||
}
|
||||
|
@ -103,7 +103,6 @@ class OpenGl_GraphicDriver : public Graphic3d_GraphicDriver
|
||||
Standard_EXPORT Standard_Integer InquireLightLimit ();
|
||||
Standard_EXPORT void InquireMat (const Graphic3d_CView& ACView, TColStd_Array2OfReal& AMatO, TColStd_Array2OfReal& AMatM);
|
||||
Standard_EXPORT Standard_Integer InquireViewLimit ();
|
||||
Standard_EXPORT Standard_Boolean InquireTextureAvailable ();
|
||||
Standard_EXPORT void Blink (const Graphic3d_CStructure& ACStructure,const Standard_Boolean Create);
|
||||
Standard_EXPORT void BoundaryBox (const Graphic3d_CStructure& ACStructure, const Standard_Boolean Create);
|
||||
Standard_EXPORT void HighlightColor (const Graphic3d_CStructure& ACStructure, const Standard_ShortReal R, const Standard_ShortReal G, const Standard_ShortReal B, const Standard_Boolean Create);
|
||||
@ -273,7 +272,10 @@ public:
|
||||
//! This method is internal and should be used by Graphic3d_Group only. <br>
|
||||
Standard_EXPORT void RemovePrimitiveArray(const Graphic3d_CGroup& theCGroup,const Graphic3d_PrimitiveArray& thePArray);
|
||||
Standard_EXPORT Standard_Integer InquirePlaneLimit();
|
||||
Standard_EXPORT Standard_Integer CreateTexture(const Graphic3d_TypeOfTexture Type,const Handle(AlienImage_AlienImage)& Image,const Standard_CString FileName,const Handle(TColStd_HArray1OfReal)& TexUpperBounds) const;
|
||||
Standard_EXPORT Standard_Integer CreateTexture (const Graphic3d_TypeOfTexture theType,
|
||||
const Image_PixMap& theImage,
|
||||
const Standard_CString theFileName,
|
||||
const Handle(TColStd_HArray1OfReal)& theTexUpperBounds) const;
|
||||
Standard_EXPORT void DestroyTexture(const Standard_Integer TexId) const;
|
||||
Standard_EXPORT void ModifyTexture(const Standard_Integer TexId,const Graphic3d_CInitTexture& AValue) const;
|
||||
Standard_EXPORT Standard_ShortReal DefaultTextHeight() const;
|
||||
|
@ -42,11 +42,6 @@ Standard_Integer OpenGl_GraphicDriver::InquireViewLimit ()
|
||||
return (openglDisplay.IsNull()? 0 : openglDisplay->Facilities().MaxViews);
|
||||
}
|
||||
|
||||
Standard_Boolean OpenGl_GraphicDriver::InquireTextureAvailable ()
|
||||
{
|
||||
return Standard_True;
|
||||
}
|
||||
|
||||
Standard_Integer OpenGl_GraphicDriver::InquirePlaneLimit ()
|
||||
{
|
||||
GLint aMaxPlanes = 0;
|
||||
|
@ -17,7 +17,6 @@
|
||||
// purpose or non-infringement. Please see the License for the specific terms
|
||||
// and conditions governing the rights and limitations under the License.
|
||||
|
||||
|
||||
#include <OpenGl_GraphicDriver.hxx>
|
||||
#include <OpenGl_CView.hxx>
|
||||
#include <OpenGl_Trihedron.hxx>
|
||||
@ -27,7 +26,6 @@
|
||||
|
||||
#include <Quantity_NameOfColor.hxx>
|
||||
#include <TColStd_HArray1OfReal.hxx>
|
||||
#include <AlienImage_AlienImage.hxx>
|
||||
#include <Image_Image.hxx>
|
||||
|
||||
void OpenGl_GraphicDriver::Environment(const Graphic3d_CView& ACView)
|
||||
@ -151,79 +149,81 @@ inline Standard_Integer GetNearestPow2(Standard_Integer theValue)
|
||||
return aRes;
|
||||
}
|
||||
|
||||
Standard_Integer OpenGl_GraphicDriver::CreateTexture (const Graphic3d_TypeOfTexture Type,
|
||||
const Handle_AlienImage_AlienImage &Image,
|
||||
const Standard_CString FileName,
|
||||
const Handle(TColStd_HArray1OfReal)& TexUpperBounds) const
|
||||
Standard_Integer OpenGl_GraphicDriver::CreateTexture (const Graphic3d_TypeOfTexture theType,
|
||||
const Image_PixMap& theImage,
|
||||
const Standard_CString theFileName,
|
||||
const Handle(TColStd_HArray1OfReal)& theTexUpperBounds) const
|
||||
{
|
||||
Handle(Image_Image) MyPic = Image->ToImage();
|
||||
|
||||
Standard_Integer aGlWidth = (Type == Graphic3d_TOT_2D_MIPMAP) ? MyPic->Width() : GetNearestPow2(MyPic->Width());
|
||||
Standard_Integer aGlHeight = (Type == Graphic3d_TOT_2D_MIPMAP) ? MyPic->Height() : GetNearestPow2(MyPic->Height());
|
||||
|
||||
TexUpperBounds->SetValue(1, ((Standard_Real) (MyPic->Width())/((Standard_Real) aGlWidth)));
|
||||
TexUpperBounds->SetValue(2, ((Standard_Real) (MyPic->Height())/((Standard_Real) aGlHeight)));
|
||||
|
||||
unsigned char *MyImageData = new unsigned char[aGlWidth*aGlHeight*4];
|
||||
unsigned char *MyData = MyImageData;
|
||||
int TexId;
|
||||
int i,j;
|
||||
Quantity_Color MyColor;
|
||||
|
||||
if (MyImageData == NULL)
|
||||
if (theImage.IsEmpty())
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
static Standard_Integer textureRank=0;
|
||||
char textureName[16];
|
||||
Standard_PCharacter fileName = textureName;
|
||||
sprintf(fileName,"Tex%d",++textureRank);
|
||||
Standard_Integer aGlWidth = (Standard_Integer )theImage.Width();
|
||||
Standard_Integer aGlHeight = (Standard_Integer )theImage.Height();
|
||||
if (theType != Graphic3d_TOT_2D_MIPMAP)
|
||||
{
|
||||
aGlWidth = GetNearestPow2 (aGlWidth);
|
||||
aGlHeight = GetNearestPow2 (aGlHeight);
|
||||
}
|
||||
theTexUpperBounds->SetValue (1, Standard_Real(theImage.Width()) / Standard_Real(aGlWidth));
|
||||
theTexUpperBounds->SetValue (2, Standard_Real(theImage.Height()) / Standard_Real(aGlHeight));
|
||||
|
||||
for (j = MyPic->Height() - 1; j >= 0; j--)
|
||||
for (i = 0; i < aGlWidth; i++){
|
||||
if (i < MyPic->Width()){
|
||||
MyColor = MyPic->PixelColor(i, j);
|
||||
*MyData++ = (int)(255 * MyColor.Red());
|
||||
*MyData++ = (int)(255 * MyColor.Green());
|
||||
*MyData++ = (int)(255 * MyColor.Blue());
|
||||
}
|
||||
else {
|
||||
*MyData++ = (int)(0);
|
||||
*MyData++ = (int)(0);
|
||||
*MyData++ = (int)(0);
|
||||
}
|
||||
*MyData++ = 0xFF;
|
||||
}
|
||||
Image_PixMap anImage;
|
||||
if (!anImage.InitTrash (Image_PixMap::ImgRGBA, Standard_Size(aGlWidth), Standard_Size(aGlHeight)))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Padding the lower part of the texture with black
|
||||
for (j = aGlHeight - 1; j >= MyPic->Height(); j--)
|
||||
for (i = 0; i < aGlWidth; i++){
|
||||
*MyData++ = (int)(0);
|
||||
*MyData++ = (int)(0);
|
||||
*MyData++ = (int)(0);
|
||||
*MyData++ = 0xFF;
|
||||
}
|
||||
anImage.SetTopDown (false);
|
||||
Image_PixMapData<Image_ColorRGBA>& aDataNew = anImage.EditData<Image_ColorRGBA>();
|
||||
Quantity_Color aSrcColor;
|
||||
for (Standard_Size aRow = 0; aRow < theImage.SizeY(); ++aRow)
|
||||
{
|
||||
for (Standard_Size aCol = 0; aCol < theImage.SizeX(); ++aCol)
|
||||
{
|
||||
aSrcColor = theImage.PixelColor (aCol, aRow);
|
||||
Image_ColorRGBA& aColor = aDataNew.ChangeValue (aRow, aCol);
|
||||
aColor.r() = int(255.0 * aSrcColor.Red());
|
||||
aColor.g() = int(255.0 * aSrcColor.Green());
|
||||
aColor.b() = int(255.0 * aSrcColor.Blue());
|
||||
aColor.a() = 0xFF;
|
||||
}
|
||||
|
||||
switch (Type)
|
||||
{
|
||||
case Graphic3d_TOT_1D:
|
||||
TexId = GetTextureData1D (fileName, aGlWidth, aGlHeight, MyImageData);
|
||||
break;
|
||||
for (Standard_Size aCol = theImage.SizeX(); aCol < anImage.SizeX(); ++aCol)
|
||||
{
|
||||
Image_ColorRGBA& aColor = aDataNew.ChangeValue (aRow, aCol);
|
||||
aColor.r() = 0x00;
|
||||
aColor.g() = 0x00;
|
||||
aColor.b() = 0x00;
|
||||
aColor.a() = 0xFF;
|
||||
}
|
||||
}
|
||||
|
||||
case Graphic3d_TOT_2D:
|
||||
TexId = GetTextureData2D (fileName, aGlWidth, aGlHeight, MyImageData);
|
||||
break;
|
||||
// Padding the lower part of the texture with black
|
||||
for (Standard_Size aRow = theImage.SizeY(); aRow < anImage.SizeY(); ++aRow)
|
||||
{
|
||||
for (Standard_Size aCol = 0; aCol < anImage.SizeX(); ++aCol)
|
||||
{
|
||||
Image_ColorRGBA& aColor = aDataNew.ChangeValue (aRow, aCol);
|
||||
aColor.r() = 0x00;
|
||||
aColor.g() = 0x00;
|
||||
aColor.b() = 0x00;
|
||||
aColor.a() = 0xFF;
|
||||
}
|
||||
}
|
||||
|
||||
case Graphic3d_TOT_2D_MIPMAP:
|
||||
TexId = GetTextureData2DMipMap (fileName, aGlWidth, aGlHeight, MyImageData);
|
||||
break;
|
||||
|
||||
default:
|
||||
TexId = -1;
|
||||
}
|
||||
|
||||
delete [] MyImageData;
|
||||
return TexId;
|
||||
static Standard_Integer TheTextureRank = 0;
|
||||
char aTextureStrId[255];
|
||||
sprintf (aTextureStrId, "Tex%d", ++TheTextureRank);
|
||||
|
||||
switch (theType)
|
||||
{
|
||||
case Graphic3d_TOT_1D: return GetTextureData1D (aTextureStrId, aGlWidth, aGlHeight, anImage.Data());
|
||||
case Graphic3d_TOT_2D: return GetTextureData2D (aTextureStrId, aGlWidth, aGlHeight, anImage.Data());
|
||||
case Graphic3d_TOT_2D_MIPMAP: return GetTextureData2DMipMap (aTextureStrId, aGlWidth, aGlHeight, anImage.Data());
|
||||
default: return -1;
|
||||
}
|
||||
}
|
||||
|
||||
void OpenGl_GraphicDriver::DestroyTexture (const Standard_Integer theTexId) const
|
||||
|
@ -17,7 +17,6 @@
|
||||
// purpose or non-infringement. Please see the License for the specific terms
|
||||
// and conditions governing the rights and limitations under the License.
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
@ -25,8 +24,7 @@
|
||||
#include <OpenGl_tgl_funcs.hxx>
|
||||
#include <OpenGl_TextureBox.hxx>
|
||||
|
||||
#include <AlienImage.hxx>
|
||||
#include <Image_Image.hxx>
|
||||
#include <Image_AlienPixMap.hxx>
|
||||
#include <Visual3d_Layer.hxx>
|
||||
|
||||
#include <OpenGl_AspectLine.hxx>
|
||||
@ -1419,53 +1417,78 @@ void OpenGl_View::RedrawLayer2d (const Handle(OpenGl_Workspace) &AWorkspace, con
|
||||
/*----------------------------------------------------------------------*/
|
||||
|
||||
//call_togl_create_bg_texture
|
||||
void OpenGl_View::CreateBackgroundTexture (const Standard_CString AFileName, const Aspect_FillMethod AFillStyle)
|
||||
void OpenGl_View::CreateBackgroundTexture (const Standard_CString theFilePath,
|
||||
const Aspect_FillMethod theFillStyle)
|
||||
{
|
||||
// Delete existing texture
|
||||
if ( myBgTexture.TexId != 0 )
|
||||
if (myBgTexture.TexId != 0)
|
||||
{
|
||||
glDeleteTextures( 1, (GLuint*)&(myBgTexture.TexId) );
|
||||
// delete existing texture
|
||||
glDeleteTextures (1, (GLuint* )&(myBgTexture.TexId));
|
||||
myBgTexture.TexId = 0;
|
||||
}
|
||||
|
||||
Standard_Integer width, height;
|
||||
Handle(Image_Image) image;
|
||||
if ( AlienImage::LoadImageFile( AFileName, image, width, height ) )
|
||||
// load image from file
|
||||
Image_AlienPixMap anImageLoaded;
|
||||
if (!anImageLoaded.Load (theFilePath))
|
||||
{
|
||||
const int nbbytes = width * height * 3;
|
||||
GLubyte *data = new GLubyte[nbbytes];
|
||||
GLubyte *pdata = data;
|
||||
Standard_Integer i, j;
|
||||
for ( j = height - 1; j >= 0; j-- )
|
||||
for ( i = 0; i < width; i++ )
|
||||
{
|
||||
const Quantity_Color &color = image->PixelColor( i, j );
|
||||
*pdata++ = (GLubyte)( 255 * color.Red() );
|
||||
*pdata++ = (GLubyte)( 255 * color.Green() );
|
||||
*pdata++ = (GLubyte)( 255 * color.Blue() );
|
||||
}
|
||||
|
||||
glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
|
||||
|
||||
GLuint texture = 0;
|
||||
glGenTextures( 1, &texture );
|
||||
glBindTexture( GL_TEXTURE_2D, texture );
|
||||
|
||||
/* Create MipMapped Texture */
|
||||
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
|
||||
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
|
||||
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
|
||||
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
|
||||
|
||||
gluBuild2DMipmaps( GL_TEXTURE_2D, 3/*4*/, width, height, GL_RGB, GL_UNSIGNED_BYTE, data );
|
||||
|
||||
delete[] data;
|
||||
|
||||
myBgTexture.TexId = texture;
|
||||
myBgTexture.Width = width;
|
||||
myBgTexture.Height = height;
|
||||
myBgTexture.Style = AFillStyle;
|
||||
return;
|
||||
}
|
||||
|
||||
Image_PixMap anImage;
|
||||
if (anImageLoaded.RowExtraBytes() == 0 &&
|
||||
(anImageLoaded.Format() == Image_PixMap::ImgRGB
|
||||
|| anImageLoaded.Format() == Image_PixMap::ImgRGB32
|
||||
|| anImageLoaded.Format() == Image_PixMap::ImgRGBA))
|
||||
{
|
||||
anImage.InitWrapper (anImageLoaded.Format(), anImageLoaded.ChangeData(),
|
||||
anImageLoaded.SizeX(), anImageLoaded.SizeY(), anImageLoaded.SizeRowBytes());
|
||||
}
|
||||
else
|
||||
{
|
||||
// convert image to RGB format
|
||||
if (!anImage.InitTrash (Image_PixMap::ImgRGB, anImageLoaded.SizeX(), anImageLoaded.SizeY()))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
anImage.SetTopDown (false);
|
||||
Image_PixMapData<Image_ColorRGB>& aDataNew = anImage.EditData<Image_ColorRGB>();
|
||||
Quantity_Color aSrcColor;
|
||||
for (Standard_Size aRow = 0; aRow < anImage.SizeY(); ++aRow)
|
||||
{
|
||||
for (Standard_Size aCol = 0; aCol < anImage.SizeX(); ++aCol)
|
||||
{
|
||||
aSrcColor = anImageLoaded.PixelColor (aCol, aRow);
|
||||
Image_ColorRGB& aColor = aDataNew.ChangeValue (aRow, aCol);
|
||||
aColor.r() = int(255.0 * aSrcColor.Red());
|
||||
aColor.g() = int(255.0 * aSrcColor.Green());
|
||||
aColor.b() = int(255.0 * aSrcColor.Blue());
|
||||
}
|
||||
}
|
||||
anImageLoaded.Clear();
|
||||
}
|
||||
|
||||
// create MipMapped texture
|
||||
glPixelStorei (GL_UNPACK_ALIGNMENT, 1);
|
||||
|
||||
GLuint aTextureId = 0;
|
||||
glGenTextures (1, &aTextureId);
|
||||
glBindTexture (GL_TEXTURE_2D, aTextureId);
|
||||
|
||||
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
|
||||
|
||||
const GLenum aDataFormat = (anImage.Format() == Image_PixMap::ImgRGB) ? GL_RGB : GL_RGBA;
|
||||
gluBuild2DMipmaps (GL_TEXTURE_2D, 3/*4*/,
|
||||
GLint(anImage.SizeX()), GLint(anImage.SizeY()),
|
||||
aDataFormat, GL_UNSIGNED_BYTE, anImage.Data());
|
||||
|
||||
myBgTexture.TexId = aTextureId;
|
||||
myBgTexture.Width = (Standard_Integer )anImage.SizeX();
|
||||
myBgTexture.Height = (Standard_Integer )anImage.SizeY();
|
||||
myBgTexture.Style = theFillStyle;
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user