1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-04-16 10:08:36 +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:
kgv 2012-11-15 12:52:57 +04:00
parent 33a085531a
commit 3c3131a05d
9 changed files with 463 additions and 519 deletions

View File

@ -188,12 +188,6 @@ is
is deferred; is deferred;
---Purpose: call_togl_inquireview ---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 -- Category: Highlight methods
------------------------------ ------------------------------
@ -811,10 +805,10 @@ is
----------------------------- -----------------------------
CreateTexture ( me; CreateTexture ( me;
Type : TypeOfTexture from Graphic3d; theType : TypeOfTexture from Graphic3d;
Image : AlienImage from AlienImage; theImage : PixMap from Image;
FileName : CString from Standard; theFileName : CString from Standard;
TexUpperBounds : HArray1OfReal from TColStd ) theTexUpperBounds : HArray1OfReal from TColStd )
returns Integer from Standard returns Integer from Standard
is deferred; is deferred;
---Purpose: ---Purpose:

View File

@ -18,34 +18,29 @@
-- purpose or non-infringement. Please see the License for the specific terms -- purpose or non-infringement. Please see the License for the specific terms
-- and conditions governing the rights and limitations under the License. -- 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 ---Purpose: This is the texture root class enable the dialog with the GraphicDriver
-- allows the loading of texture too supported formats: -- allows the loading of texture.
-- X, SunRaster, Aida, Euclid, SGI rgb
uses uses
CInitTexture from Graphic3d, CInitTexture from Graphic3d,
GraphicDriver from Graphic3d, GraphicDriver from Graphic3d,
StructureManager from Graphic3d, StructureManager from Graphic3d,
TypeOfTexture from Graphic3d, TypeOfTexture from Graphic3d,
AlienImage from AlienImage, PixMap from Image,
Path from OSD, Path from OSD,
HArray1OfReal from TColStd HArray1OfReal from TColStd
is is
Initialize(SM : StructureManager from Graphic3d;
Path : CString from Standard; Initialize (theSM : StructureManager from Graphic3d;
FileName : CString from Standard; thePath : CString from Standard;
Type : TypeOfTexture from Graphic3d); theFileName : CString from Standard;
theType : TypeOfTexture from Graphic3d);
---Purpose: Creates a texture from a file ---Purpose: Creates a texture from a file
-- Warning: Note that if <FileName> is NULL the texture must be realized -- Warning: Note that if <FileName> is NULL the texture must be realized
-- using LoadTexture(image) method. -- using LoadTexture(image) method.
@ -59,7 +54,12 @@ is
IsDone (me) returns Boolean from Standard; IsDone (me) returns Boolean from Standard;
---Level: public ---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
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 -- returns true if the construction of the class is correct
Path (me) returns Path from OSD; Path (me) returns Path from OSD;
@ -73,33 +73,16 @@ is
---Purpose: ---Purpose:
-- Returns the texture type. -- Returns the texture type.
LoadTexture (me : mutable; theImage : PixMap from Image) returns Boolean from Standard;
--
-- private methods
--
Update(me) is protected;
LoadTexture(me : mutable; anImage: AlienImage from AlienImage);
---Level: advanced ---Level: advanced
---Purpose: ---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 ---Level: advanced
---Purpose: ---Purpose:
-- returns the Texture ID which references the -- returns the Texture ID which references the
-- texture to use for drawing. Used by the -- texture to use for drawing. Used by the graphic driver.
-- graphic driver.
Image(me) returns AlienImage from AlienImage;
---Level: advanced
---Purpose:
-- Returns the created image texture.
GetTexUpperBounds(me) returns HArray1OfReal from TColStd; GetTexUpperBounds(me) returns HArray1OfReal from TColStd;
---Level: advanced ---Level: advanced
@ -107,17 +90,19 @@ is
---Gets upper bounds of texture coordinates. This is used when sizes ---Gets upper bounds of texture coordinates. This is used when sizes
---of texture are not equal to the powers of two ---of texture are not equal to the powers of two
-- internal fields for managing the class --
-- private methods
--
Update (me) is protected;
fields fields
MyGraphicDriver : GraphicDriver from Graphic3d;
MyTexId : Integer from Standard; myGraphicDriver : GraphicDriver from Graphic3d;
myTexId : Integer from Standard;
MyCInitTexture : CInitTexture from Graphic3d is protected; MyCInitTexture : CInitTexture from Graphic3d is protected;
-- MyIsDone : Boolean from Standard; myPath : Path from OSD;
MyPath : Path from OSD; myType : TypeOfTexture from Graphic3d;
MyType : TypeOfTexture from Graphic3d; myTexUpperBounds : HArray1OfReal from TColStd;
MyImage : AlienImage from AlienImage;
MyTexUpperBounds : HArray1OfReal from TColStd;
end TextureRoot; end TextureRoot;

View File

@ -18,215 +18,142 @@
// purpose or non-infringement. Please see the License for the specific terms // purpose or non-infringement. Please see the License for the specific terms
// and conditions governing the rights and limitations under the License. // 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_TextureRoot.ixx>
#include <Graphic3d_GraphicDevice.hxx> #include <Graphic3d_GraphicDevice.hxx>
#include <Graphic3d_GraphicDriver.hxx> #include <Graphic3d_GraphicDriver.hxx>
#include <AlienImage_EuclidAlienImage.hxx> #include <Image_AlienPixMap.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 <OSD_Protection.hxx> #include <OSD_Protection.hxx>
#include <OSD_File.hxx> #include <OSD_File.hxx>
#include <stdio.h> #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 if (thePath != NULL && (strlen (thePath) > 0))
// 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())
{ {
// chargement de l'image myPath.SetTrek (TCollection_AsciiString (thePath));
//-GG Handle(AlienImage_AlienImage) MyImage = LoadTexture(); }
if (MyImage.IsNull() && FileName && (strlen(FileName) > 0))
MyImage = LoadTexture();
if (MyImage.IsNull()) { if (theFileName == NULL || (strlen (theFileName) <= 0))
MyTexId = -1; {
return; return;
} }
MyTexId = MyGraphicDriver->CreateTexture(Type, MyImage, FileName, MyTexUpperBounds); TCollection_AsciiString aFilePath;
} myPath.SystemName (aFilePath);
#ifdef TRACE Image_AlienPixMap anImage;
printf(" *** Graphic3d_TextureRoot::Create() textId %d\n",MyTexId); if (!anImage.Load (aFilePath))
#endif
}
void Graphic3d_TextureRoot::Destroy() const
{ {
if (MyTexId >= 0 ) return;
MyGraphicDriver->DestroyTexture(MyTexId);
#ifdef TRACE
printf(" *** Graphic3d_TextureRoot::Destroy() textId %d\n",MyTexId);
#endif
} }
myTexId = myGraphicDriver->CreateTexture (myType, anImage, theFileName, myTexUpperBounds);
Standard_Integer Graphic3d_TextureRoot::TextureId() const
{
return MyTexId;
}
void Graphic3d_TextureRoot::Update() const
{
if( MyTexId >= 0 )
MyGraphicDriver->ModifyTexture(MyTexId, MyCInitTexture);
}
Standard_Boolean Graphic3d_TextureRoot::IsDone() const
{
return (MyTexId >= 0) ? Standard_True : Standard_False;
}
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(); Update();
} }
}
Handle(AlienImage_AlienImage) Graphic3d_TextureRoot::LoadTexture() const // =======================================================================
// function : Destroy
// purpose :
// =======================================================================
void Graphic3d_TextureRoot::Destroy() const
{ {
OSD_Protection Protection( OSD_R, OSD_R, OSD_R, OSD_R ) ; /* Read Only */ if (IsValid())
Handle(AlienImage_AlienImage) TheAlienImage = NULL ; {
myGraphicDriver->DestroyTexture (myTexId);
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;
} }
// =======================================================================
//////////////////////// // function : TextureId
// file reading // // purpose :
//////////////////////// // =======================================================================
Standard_Integer Graphic3d_TextureRoot::TextureId() const
{
// image X ? return myTexId;
////////////
Handle(AlienImage_XAlienImage) XAlienImage = new AlienImage_XAlienImage() ;
if (XAlienImage->Read( File )) {
File.Close();
return XAlienImage;
} }
// image GIF ? // =======================================================================
//////////// // function : Update
Handle(AlienImage_GIFAlienImage) GIFAlienImage = new AlienImage_GIFAlienImage() ; // purpose :
// =======================================================================
if (GIFAlienImage->Read( File )) { void Graphic3d_TextureRoot::Update() const
File.Close(); {
return GIFAlienImage; if (IsValid())
{
myGraphicDriver->ModifyTexture (myTexId, MyCInitTexture);
}
} }
// image BMP ? // =======================================================================
//////////// // function : IsValid
Handle(AlienImage_BMPAlienImage) BMPAlienImage = new AlienImage_BMPAlienImage() ; // purpose :
// =======================================================================
if (BMPAlienImage->Read( File )) { Standard_Boolean Graphic3d_TextureRoot::IsValid() const
File.Close(); {
return BMPAlienImage; return myTexId >= 0;
} }
// SunRaster ? // =======================================================================
////////////// // function : IsDone
Handle(AlienImage_SunRFAlienImage) SunRFAlienImage = new AlienImage_SunRFAlienImage() ; // purpose :
// =======================================================================
if (SunRFAlienImage->Read( File )) { Standard_Boolean Graphic3d_TextureRoot::IsDone() const
File.Close(); {
return SunRFAlienImage; return myTexId >= 0;
} }
// Aida ? // =======================================================================
///////// // function : LoadTexture
Handle(AlienImage_AidaAlienImage) AidaAlienImage = new AlienImage_AidaAlienImage() ; // purpose :
// =======================================================================
if (AidaAlienImage->Read( File )) { Standard_Boolean Graphic3d_TextureRoot::LoadTexture (const Image_PixMap& theImage)
File.Close(); {
return AidaAlienImage; if (myTexId >= 0)
{
myGraphicDriver->DestroyTexture (myTexId);
} }
// Euclid ? myTexId = myGraphicDriver->CreateTexture (myType, theImage, "", myTexUpperBounds);
/////////// Update();
Handle(AlienImage_EuclidAlienImage) EuclidAlienImage = new AlienImage_EuclidAlienImage() ; return IsValid();
if (EuclidAlienImage->Read( File )) {
File.Close();
return EuclidAlienImage;
} }
// =======================================================================
// SGIRGB ? // function : Path
/////////// // purpose :
Handle(AlienImage_SGIRGBAlienImage) SGIRGBAlienImage = new AlienImage_SGIRGBAlienImage() ; // =======================================================================
const OSD_Path& Graphic3d_TextureRoot::Path() const
if (SGIRGBAlienImage->Read( File )) { {
File.Close(); return myPath;
return SGIRGBAlienImage;
} }
// =======================================================================
// raise exception: file type unknown // function : Type
return TheAlienImage; // purpose :
} // =======================================================================
Graphic3d_TypeOfTexture Graphic3d_TextureRoot::Type() const
const OSD_Path& Graphic3d_TextureRoot::Path() const { {
return myType;
return MyPath;
}
Graphic3d_TypeOfTexture Graphic3d_TextureRoot::Type() const {
return MyType;
}
Handle(AlienImage_AlienImage) Graphic3d_TextureRoot::Image() const {
return MyImage;
} }
// =======================================================================
// function : GetTexUpperBounds
// purpose :
// =======================================================================
Handle(TColStd_HArray1OfReal) Graphic3d_TextureRoot::GetTexUpperBounds() const Handle(TColStd_HArray1OfReal) Graphic3d_TextureRoot::GetTexUpperBounds() const
{ {
return MyTexUpperBounds; return myTexUpperBounds;
} }

View File

@ -182,7 +182,7 @@ bool Image_AlienPixMap::InitTrash (ImgFormat thePixelFormat,
} }
// ======================================================================= // =======================================================================
// function : Clear // function : InitCopy
// purpose : // purpose :
// ======================================================================= // =======================================================================
bool Image_AlienPixMap::InitCopy (const Image_PixMap& theCopy) 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 // FreeImage doesn't provide flexible format convertion API
// so we should perform multiple convertions in some cases! // so we should perform multiple convertions in some cases!
Standard_Boolean isCopied = Standard_False;
FIBITMAP* anImageToDump = myLibImage; FIBITMAP* anImageToDump = myLibImage;
switch (anImageFormat) switch (anImageFormat)
{ {

View File

@ -53,9 +53,7 @@
#include <MeshVS_Buffer.hxx> #include <MeshVS_Buffer.hxx>
#include <gp_Pnt.hxx> #include <gp_Pnt.hxx>
#include <Image_ColorImage.hxx> #include <Image_PixMap.hxx>
#include <AlienImage_AlienImage.hxx>
#include <AlienImage_BMPAlienImage.hxx>
#include <Graphic3d_Texture2D.hxx> #include <Graphic3d_Texture2D.hxx>
#include <Graphic3d_TypeOfTextureMode.hxx> #include <Graphic3d_TypeOfTextureMode.hxx>
#include <Standard_DefineHandle.hxx> #include <Standard_DefineHandle.hxx>
@ -73,7 +71,7 @@ class MeshVS_ImageTexture2D : public Graphic3d_Texture2D
{ {
public: public:
MeshVS_ImageTexture2D (Handle(Graphic3d_StructureManager) theSM, MeshVS_ImageTexture2D (Handle(Graphic3d_StructureManager) theSM,
const Handle(AlienImage_AlienImage)& theImg ); const Image_PixMap& theImg);
virtual ~MeshVS_ImageTexture2D(); virtual ~MeshVS_ImageTexture2D();
public: public:
@ -84,9 +82,8 @@ DEFINE_STANDARD_HANDLE(MeshVS_ImageTexture2D,Graphic3d_Texture2D)
IMPLEMENT_STANDARD_HANDLE (MeshVS_ImageTexture2D, Graphic3d_Texture2D) IMPLEMENT_STANDARD_HANDLE (MeshVS_ImageTexture2D, Graphic3d_Texture2D)
IMPLEMENT_STANDARD_RTTIEXT(MeshVS_ImageTexture2D, Graphic3d_Texture2D) IMPLEMENT_STANDARD_RTTIEXT(MeshVS_ImageTexture2D, Graphic3d_Texture2D)
MeshVS_ImageTexture2D::MeshVS_ImageTexture2D MeshVS_ImageTexture2D::MeshVS_ImageTexture2D (Handle(Graphic3d_StructureManager) theSM,
(Handle(Graphic3d_StructureManager) theSM, const Image_PixMap& theImg)
const Handle(AlienImage_AlienImage)& theImg)
: Graphic3d_Texture2D (theSM, "", Graphic3d_TOT_2D) : Graphic3d_Texture2D (theSM, "", Graphic3d_TOT_2D)
{ {
MyCInitTexture.doModulate = 1; MyCInitTexture.doModulate = 1;
@ -720,43 +717,65 @@ Standard_Real MeshVS_NodalColorPrsBuilder::GetTextureCoord( const Standard_Integ
//================================================================ //================================================================
Handle(Graphic3d_Texture2D) MeshVS_NodalColorPrsBuilder::CreateTexture() const Handle(Graphic3d_Texture2D) MeshVS_NodalColorPrsBuilder::CreateTexture() const
{ {
Handle(Graphic3d_Texture2D) aTexture; const Standard_Integer aColorsNb = myTextureColorMap.Length();
if (aColorsNb == 0)
int nbColors = myTextureColorMap.Length(); {
if ( nbColors == 0 ) return NULL;
return aTexture; }
Handle(PrsMgr_PresentationManager3d) aPrsMgr = GetPresentationManager(); Handle(PrsMgr_PresentationManager3d) aPrsMgr = GetPresentationManager();
if (aPrsMgr.IsNull()) 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 )
{ {
int i; return NULL;
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 ) );
}
} }
// Convert image to bmp // create and fill image with colors
Handle(AlienImage_BMPAlienImage) aTextureImage = new AlienImage_BMPAlienImage(); Image_PixMap anImage;
aTextureImage->FromImage( aCImage ); if (!anImage.InitTrash (Image_PixMap::ImgRGBA, Standard_Size(getNearestPow2 (aColorsNb)), 2))
{
// Create texture return NULL;
aTexture = new MeshVS_ImageTexture2D( aPrsMgr->StructureManager(), aTextureImage ); }
return aTexture;
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);
} }

View File

@ -103,7 +103,6 @@ class OpenGl_GraphicDriver : public Graphic3d_GraphicDriver
Standard_EXPORT Standard_Integer InquireLightLimit (); Standard_EXPORT Standard_Integer InquireLightLimit ();
Standard_EXPORT void InquireMat (const Graphic3d_CView& ACView, TColStd_Array2OfReal& AMatO, TColStd_Array2OfReal& AMatM); Standard_EXPORT void InquireMat (const Graphic3d_CView& ACView, TColStd_Array2OfReal& AMatO, TColStd_Array2OfReal& AMatM);
Standard_EXPORT Standard_Integer InquireViewLimit (); 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 Blink (const Graphic3d_CStructure& ACStructure,const Standard_Boolean Create);
Standard_EXPORT void BoundaryBox (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); 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> //! 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 void RemovePrimitiveArray(const Graphic3d_CGroup& theCGroup,const Graphic3d_PrimitiveArray& thePArray);
Standard_EXPORT Standard_Integer InquirePlaneLimit(); 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 DestroyTexture(const Standard_Integer TexId) const;
Standard_EXPORT void ModifyTexture(const Standard_Integer TexId,const Graphic3d_CInitTexture& AValue) const; Standard_EXPORT void ModifyTexture(const Standard_Integer TexId,const Graphic3d_CInitTexture& AValue) const;
Standard_EXPORT Standard_ShortReal DefaultTextHeight() const; Standard_EXPORT Standard_ShortReal DefaultTextHeight() const;

View File

@ -42,11 +42,6 @@ Standard_Integer OpenGl_GraphicDriver::InquireViewLimit ()
return (openglDisplay.IsNull()? 0 : openglDisplay->Facilities().MaxViews); return (openglDisplay.IsNull()? 0 : openglDisplay->Facilities().MaxViews);
} }
Standard_Boolean OpenGl_GraphicDriver::InquireTextureAvailable ()
{
return Standard_True;
}
Standard_Integer OpenGl_GraphicDriver::InquirePlaneLimit () Standard_Integer OpenGl_GraphicDriver::InquirePlaneLimit ()
{ {
GLint aMaxPlanes = 0; GLint aMaxPlanes = 0;

View File

@ -17,7 +17,6 @@
// purpose or non-infringement. Please see the License for the specific terms // purpose or non-infringement. Please see the License for the specific terms
// and conditions governing the rights and limitations under the License. // and conditions governing the rights and limitations under the License.
#include <OpenGl_GraphicDriver.hxx> #include <OpenGl_GraphicDriver.hxx>
#include <OpenGl_CView.hxx> #include <OpenGl_CView.hxx>
#include <OpenGl_Trihedron.hxx> #include <OpenGl_Trihedron.hxx>
@ -27,7 +26,6 @@
#include <Quantity_NameOfColor.hxx> #include <Quantity_NameOfColor.hxx>
#include <TColStd_HArray1OfReal.hxx> #include <TColStd_HArray1OfReal.hxx>
#include <AlienImage_AlienImage.hxx>
#include <Image_Image.hxx> #include <Image_Image.hxx>
void OpenGl_GraphicDriver::Environment(const Graphic3d_CView& ACView) void OpenGl_GraphicDriver::Environment(const Graphic3d_CView& ACView)
@ -151,79 +149,81 @@ inline Standard_Integer GetNearestPow2(Standard_Integer theValue)
return aRes; return aRes;
} }
Standard_Integer OpenGl_GraphicDriver::CreateTexture (const Graphic3d_TypeOfTexture Type, Standard_Integer OpenGl_GraphicDriver::CreateTexture (const Graphic3d_TypeOfTexture theType,
const Handle_AlienImage_AlienImage &Image, const Image_PixMap& theImage,
const Standard_CString FileName, const Standard_CString theFileName,
const Handle(TColStd_HArray1OfReal)& TexUpperBounds) const const Handle(TColStd_HArray1OfReal)& theTexUpperBounds) const
{
if (theImage.IsEmpty())
{ {
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)
return -1; return -1;
static Standard_Integer textureRank=0;
char textureName[16];
Standard_PCharacter fileName = textureName;
sprintf(fileName,"Tex%d",++textureRank);
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); Standard_Integer aGlWidth = (Standard_Integer )theImage.Width();
*MyData++ = (int)(0); Standard_Integer aGlHeight = (Standard_Integer )theImage.Height();
*MyData++ = (int)(0); 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));
Image_PixMap anImage;
if (!anImage.InitTrash (Image_PixMap::ImgRGBA, Standard_Size(aGlWidth), Standard_Size(aGlHeight)))
{
return -1;
}
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;
}
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;
} }
*MyData++ = 0xFF;
} }
// Padding the lower part of the texture with black // Padding the lower part of the texture with black
for (j = aGlHeight - 1; j >= MyPic->Height(); j--) for (Standard_Size aRow = theImage.SizeY(); aRow < anImage.SizeY(); ++aRow)
for (i = 0; i < aGlWidth; i++){
*MyData++ = (int)(0);
*MyData++ = (int)(0);
*MyData++ = (int)(0);
*MyData++ = 0xFF;
}
switch (Type)
{ {
case Graphic3d_TOT_1D: for (Standard_Size aCol = 0; aCol < anImage.SizeX(); ++aCol)
TexId = GetTextureData1D (fileName, aGlWidth, aGlHeight, MyImageData); {
break; Image_ColorRGBA& aColor = aDataNew.ChangeValue (aRow, aCol);
aColor.r() = 0x00;
case Graphic3d_TOT_2D: aColor.g() = 0x00;
TexId = GetTextureData2D (fileName, aGlWidth, aGlHeight, MyImageData); aColor.b() = 0x00;
break; aColor.a() = 0xFF;
}
case Graphic3d_TOT_2D_MIPMAP:
TexId = GetTextureData2DMipMap (fileName, aGlWidth, aGlHeight, MyImageData);
break;
default:
TexId = -1;
} }
delete [] MyImageData; static Standard_Integer TheTextureRank = 0;
return TexId; 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 void OpenGl_GraphicDriver::DestroyTexture (const Standard_Integer theTexId) const

View File

@ -17,7 +17,6 @@
// purpose or non-infringement. Please see the License for the specific terms // purpose or non-infringement. Please see the License for the specific terms
// and conditions governing the rights and limitations under the License. // and conditions governing the rights and limitations under the License.
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@ -25,8 +24,7 @@
#include <OpenGl_tgl_funcs.hxx> #include <OpenGl_tgl_funcs.hxx>
#include <OpenGl_TextureBox.hxx> #include <OpenGl_TextureBox.hxx>
#include <AlienImage.hxx> #include <Image_AlienPixMap.hxx>
#include <Image_Image.hxx>
#include <Visual3d_Layer.hxx> #include <Visual3d_Layer.hxx>
#include <OpenGl_AspectLine.hxx> #include <OpenGl_AspectLine.hxx>
@ -1419,53 +1417,78 @@ void OpenGl_View::RedrawLayer2d (const Handle(OpenGl_Workspace) &AWorkspace, con
/*----------------------------------------------------------------------*/ /*----------------------------------------------------------------------*/
//call_togl_create_bg_texture //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)
{ {
// delete existing texture
glDeleteTextures (1, (GLuint* )&(myBgTexture.TexId)); glDeleteTextures (1, (GLuint* )&(myBgTexture.TexId));
myBgTexture.TexId = 0; myBgTexture.TexId = 0;
} }
Standard_Integer width, height; // load image from file
Handle(Image_Image) image; Image_AlienPixMap anImageLoaded;
if ( AlienImage::LoadImageFile( AFileName, image, width, height ) ) if (!anImageLoaded.Load (theFilePath))
{ {
const int nbbytes = width * height * 3; return;
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() );
} }
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); glPixelStorei (GL_UNPACK_ALIGNMENT, 1);
GLuint texture = 0; GLuint aTextureId = 0;
glGenTextures( 1, &texture ); glGenTextures (1, &aTextureId);
glBindTexture( GL_TEXTURE_2D, texture ); glBindTexture (GL_TEXTURE_2D, aTextureId);
/* Create MipMapped Texture */
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); 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_WRAP_T, GL_REPEAT);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); 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 ); 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());
delete[] data; myBgTexture.TexId = aTextureId;
myBgTexture.Width = (Standard_Integer )anImage.SizeX();
myBgTexture.TexId = texture; myBgTexture.Height = (Standard_Integer )anImage.SizeY();
myBgTexture.Width = width; myBgTexture.Style = theFillStyle;
myBgTexture.Height = height;
myBgTexture.Style = AFillStyle;
}
} }
/*----------------------------------------------------------------------*/ /*----------------------------------------------------------------------*/