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
------------------------------
-- 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:
-- 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
-
-uses
- CInitTexture from Graphic3d,
- GraphicDriver from Graphic3d,
- StructureManager from Graphic3d,
- TypeOfTexture from Graphic3d,
- AlienImage from AlienImage,
- Path from OSD,
- HArray1OfReal from TColStd
-
-
-is
- Initialize(SM : StructureManager from Graphic3d;
- Path : CString from Standard;
- FileName : CString from Standard;
- Type : TypeOfTexture from Graphic3d);
+ -- allows the loading of texture.
+
+uses
+
+ CInitTexture from Graphic3d,
+ GraphicDriver from Graphic3d,
+ StructureManager from Graphic3d,
+ TypeOfTexture from Graphic3d,
+ PixMap from Image,
+ Path from OSD,
+ HArray1OfReal from TColStd
+
+is
+
+ 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);
- ---Level: advanced
+ LoadTexture (me : mutable; theImage : PixMap from Image) returns Boolean from Standard;
+ ---Level: advanced
---Purpose:
- -- Updates the current texture from a requested alien image.
-
- LoadTexture(me)
- returns AlienImage from AlienImage
- is private;
+ -- Updates the current texture from a requested image.
- TextureId(me) returns Integer from Standard;
- ---Level: advanced
+ 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
+ GetTexUpperBounds(me) returns HArray1OfReal from TColStd;
+ ---Level: advanced
---Purpose:
---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
-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;
+ --
+ -- private methods
+ --
+
+ Update (me) is protected;
+
+fields
+ 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;
// 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 ));
+ if (thePath != NULL && (strlen (thePath) > 0))
+ {
+ myPath.SetTrek (TCollection_AsciiString (thePath));
+ }
- MyGraphicDriver = Handle(Graphic3d_GraphicDriver)::DownCast(SM->GraphicDevice()->GraphicDriver());
+ if (theFileName == NULL || (strlen (theFileName) <= 0))
+ {
+ return;
+ }
- if (MyGraphicDriver->InquireTextureAvailable())
+ TCollection_AsciiString aFilePath;
+ myPath.SystemName (aFilePath);
+ Image_AlienPixMap anImage;
+ if (!anImage.Load (aFilePath))
{
- // 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);
+ return;
}
-#ifdef TRACE
- printf(" *** Graphic3d_TextureRoot::Create() textId %d\n",MyTexId);
-#endif
+
+ 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;
- }
-
-
- ////////////////////////
- // 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;
+ if (myTexId >= 0)
+ {
+ myGraphicDriver->DestroyTexture (myTexId);
}
-
- // raise exception: file type unknown
- return TheAlienImage;
-}
-
-const OSD_Path& Graphic3d_TextureRoot::Path() const {
-
- return MyPath;
+ myTexId = myGraphicDriver->CreateTexture (myType, theImage, "", myTexUpperBounds);
+ Update();
+ return IsValid();
}
-Graphic3d_TypeOfTexture Graphic3d_TextureRoot::Type() const {
-
- return MyType;
+// =======================================================================
+// function : Path
+// purpose :
+// =======================================================================
+const OSD_Path& Graphic3d_TextureRoot::Path() const
+{
+ return myPath;
}
-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;
}
}
// =======================================================================
-// function : Clear
+// function : InitCopy
// purpose :
// =======================================================================
bool Image_AlienPixMap::InitCopy (const Image_PixMap& theCopy)
// 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)
{
#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>
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;
//================================================================
// Function : getNearestPow2
-// Purpose : Returns the nearest power of two greater than the
+// Purpose : Returns the nearest power of two greater than the
// argument value
//================================================================
static inline Standard_Integer getNearestPow2( Standard_Integer theValue )
/*
Class : MeshVS_NodalColorPrsBuilder
- Description : This class provides methods to create presentation of
+ Description : This class provides methods to create presentation of
nodes with assigned color (See hxx for more description )
*/
const Standard_Integer Id,
const MeshVS_BuilderPriority& Priority )
: MeshVS_PrsBuilder ( Parent, Flags, DS, Id, Priority ),
- myUseTexture( Standard_False ),
+ myUseTexture( Standard_False ),
myInvalidColor( Quantity_NOC_GRAY )
{
SetExcluding ( Standard_True );
if ( !( DisplayMode & GetFlags() ) || !IsElement )
return;
- if ( myUseTexture && ( !myTextureCoords.Extent() || !myTextureColorMap.Length() ) ||
+ if ( myUseTexture && ( !myTextureCoords.Extent() || !myTextureColorMap.Length() ) ||
!myUseTexture && !myNodeColorMap.Extent() )
return;
Standard_Boolean IsReflect = Standard_False, IsMeshSmoothShading = Standard_False;
aDrawer->GetBoolean( MeshVS_DA_ColorReflection, IsReflect );
aDrawer->GetBoolean( MeshVS_DA_SmoothShading, IsMeshSmoothShading );
-
+
// Following parameter are used for texture presentation only
int nbColors = 0; // Number of colors from color map
int nbTextureColors = 0; // Number of colors in texture (it will be pow of 2)
nbColors = myTextureColorMap.Length();
nbTextureColors = getNearestPow2( nbColors );
}
-
+
Standard_Integer aSize = anIDs.Extent();
// Calculate maximum possible number of vertices and bounds
// Draw faces with nodal color
// OCC20644 Use "plastic" material as it is "non-physic" and so it is easier
// to get the required colors (see TelUpdateMaterial() function in OpenGl_attri.c)
- Graphic3d_MaterialAspect aMaterial[ 2 ];
+ Graphic3d_MaterialAspect aMaterial[ 2 ];
aMaterial[ 0 ] = Graphic3d_MaterialAspect( Graphic3d_NOM_PLASTIC );
aMaterial[ 1 ] = Graphic3d_MaterialAspect( Graphic3d_NOM_PLASTIC );
Standard_Integer i;
aMaterial[i].SetSpecular( 0. );
aMaterial[i].SetEmissive( 0. );
}
-
- }
+
+ }
// Create array of polygons for interior presentation of faces and volumes
Handle(Graphic3d_ArrayOfPolygons) aCPolyArr = new Graphic3d_ArrayOfPolygons
- ( aMaxFaceNodes * aSize + PolygonVerticesFor3D, aSize + PolygonBoundsFor3D,
+ ( aMaxFaceNodes * aSize + PolygonVerticesFor3D, aSize + PolygonBoundsFor3D,
0, myUseTexture || IsReflect, !myUseTexture, Standard_False, myUseTexture );
- // Create array of polylines for presentation of edges
- // (used for optimization insted of SetEdgeOn method call)
+ // Create array of polylines for presentation of edges
+ // (used for optimization insted of SetEdgeOn method call)
Handle(Graphic3d_ArrayOfPolylines) aPolyL = new Graphic3d_ArrayOfPolylines
( ( aMaxFaceNodes + 1 ) * aSize + PolygonVerticesFor3D, aSize + PolygonBoundsFor3D );
// Preparing normal(s) to show reflections if requested
Handle(TColStd_HArray1OfReal) aNormals;
- Standard_Boolean hasNormals =
+ Standard_Boolean hasNormals =
( IsReflect && aSource->GetNormalsByElement( aKey, IsMeshSmoothShading, aMaxFaceNodes, aNormals ) );
if ( aType == MeshVS_ET_Face )
int anId = aNodes( i );
double aTexCoord = myTextureCoords( anId );
- // transform texture coordinate in accordance with number of colors specified
+ // transform texture coordinate in accordance with number of colors specified
// by upper level and real size of Gl texture
// The Gl texture has border colors interpolated with the colors from the color map,
- // thats why we need to shrink texture coordinates around the middle point to
+ // thats why we need to shrink texture coordinates around the middle point to
// exclude areas where the map colors are interpolated with the borders color
double aWrapCoord = 1.0 / (2.0 * nbTextureColors) + aTexCoord * (nbColors - 1.0) / nbTextureColors;
if ( hasNormals )
{
- gp_Vec aNorm(aNormals->Value( 3 * i - 2 ),
- aNormals->Value( 3 * i - 1 ),
+ gp_Vec aNorm(aNormals->Value( 3 * i - 2 ),
+ aNormals->Value( 3 * i - 1 ),
aNormals->Value( 3 * i ));
// There are two "rows" of colors: user's invalid color at the top
// of texture and line of map colors at the bottom of the texture.
// Since the texture has borders, which are interpolated with the "rows" of colors
// we should specify the 0.25 offset to get the correct texture color
aNorm.SquareMagnitude() > aMin ?
- aCPolyArr->AddVertex(P, gp_Dir( aNorm ),
- gp_Pnt2d( aWrapCoord, aTexCoord >= 0 && aTexCoord <= 1 ? 0.75 : 0.25 ) ) :
- aCPolyArr->AddVertex(P, aDefNorm,
+ aCPolyArr->AddVertex(P, gp_Dir( aNorm ),
+ gp_Pnt2d( aWrapCoord, aTexCoord >= 0 && aTexCoord <= 1 ? 0.75 : 0.25 ) ) :
+ aCPolyArr->AddVertex(P, aDefNorm,
gp_Pnt2d( aWrapCoord, aTexCoord >= 0 && aTexCoord <= 1 ? 0.75 : 0.25 ) );
}
else
- aCPolyArr->AddVertex( P, aDefNorm,
+ aCPolyArr->AddVertex( P, aDefNorm,
gp_Pnt2d( aWrapCoord, aTexCoord >= 0 && aTexCoord <= 1 ? 0.75 : 0.25 ) );
}
else
{
GetColor ( aNodes( i ), aNColor );
-
+
if ( IsReflect )
- {
+ {
// Simulating TelUpdateMaterial() from OpenGl_attri.c
// to get the same colors in elemental and nodal color prs builders
aNColor.SetValues(anColorRatio * aNColor.Red(),
anColorRatio * aNColor.Green(),
- anColorRatio * aNColor.Blue(),
+ anColorRatio * aNColor.Blue(),
Quantity_TOC_RGB);
-
+
if ( hasNormals )
{
- gp_Vec aNorm(aNormals->Value( 3 * i - 2 ),
- aNormals->Value( 3 * i - 1 ),
+ gp_Vec aNorm(aNormals->Value( 3 * i - 2 ),
+ aNormals->Value( 3 * i - 1 ),
aNormals->Value( 3 * i ));
aNorm.SquareMagnitude() > aMin ?
- aCPolyArr->AddVertex(P, gp_Dir( aNorm ), aNColor ) :
+ aCPolyArr->AddVertex(P, gp_Dir( aNorm ), aNColor ) :
aCPolyArr->AddVertex(P, aDefNorm , aNColor );
}
else
if ( !aSource->Get3DGeom( aKey, NbNodes, aTopo ) )
continue;
- // iterate through faces of volume
+ // iterate through faces of volume
for ( Standard_Integer k = aTopo->Lower(), last = aTopo->Upper(), normIndex = 1; k <= last; k++, normIndex++ )
{
const TColStd_SequenceOfInteger& aSeq = aTopo->Value( k );
for ( Standard_Integer j = 1; j <= m; j++ )
{
ind = aSeq.Value( j );
- P = gp_Pnt( aCoords( 3 * ind + 1 ),
- aCoords( 3 * ind + 2 ),
+ P = gp_Pnt( aCoords( 3 * ind + 1 ),
+ aCoords( 3 * ind + 2 ),
aCoords( 3 * ind + 3 ) );
if ( myUseTexture )
{
Standard_Integer anId = aNodes( ind + 1 );
Standard_Real aTexCoord = myTextureCoords( anId );
- // transform texture coordinate in accordance with number of colors specified
+ // transform texture coordinate in accordance with number of colors specified
// by upper level and real size of Gl texture
// The Gl texture has border colors interpolated with the colors from the color map,
- // thats why we need to shrink texture coordinates around the middle point to
+ // thats why we need to shrink texture coordinates around the middle point to
// exclude areas where the map colors are interpolated with the borders color
double aWrapCoord = 1.0 / (2.0 * nbTextureColors) + aTexCoord * (nbColors - 1.0) / nbTextureColors;
if ( hasNormals )
{
- gp_Vec aNorm(aNormals->Value( 3 * i - 2 ),
- aNormals->Value( 3 * i - 1 ),
+ gp_Vec aNorm(aNormals->Value( 3 * i - 2 ),
+ aNormals->Value( 3 * i - 1 ),
aNormals->Value( 3 * i ));
// There are two "rows" of colors: user's invalid color at the top
// of texture and line of map colors at the bottom of the texture.
// Since the texture has borders, which are interpolated with the "rows" of colors
// we should specify the 0.25 offset to get the correct texture color
aNorm.SquareMagnitude() > aMin ?
- aCPolyArr->AddVertex(P, gp_Dir( aNorm ),
- gp_Pnt2d( aWrapCoord, aTexCoord >= 0 && aTexCoord <= 1 ? 0.75 : 0.25 ) ) :
- aCPolyArr->AddVertex(P, aDefNorm,
+ aCPolyArr->AddVertex(P, gp_Dir( aNorm ),
+ gp_Pnt2d( aWrapCoord, aTexCoord >= 0 && aTexCoord <= 1 ? 0.75 : 0.25 ) ) :
+ aCPolyArr->AddVertex(P, aDefNorm,
gp_Pnt2d( aWrapCoord, aTexCoord >= 0 && aTexCoord <= 1 ? 0.75 : 0.25 ) );
}
else
- aCPolyArr->AddVertex( P, aDefNorm,
+ aCPolyArr->AddVertex( P, aDefNorm,
gp_Pnt2d( aWrapCoord, aTexCoord >= 0 && aTexCoord <= 1 ? 0.75 : 0.25 ) );
}
else
{
GetColor( aNodes( ind + 1 ), aNColor );
if ( IsReflect )
- {
+ {
// Simulating TelUpdateMaterial() from OpenGl_attri.c
// to get the same colors in elemental and nodal color prs builders
aNColor.SetValues(anColorRatio * aNColor.Red(),
anColorRatio * aNColor.Green(),
- anColorRatio * aNColor.Blue(),
+ anColorRatio * aNColor.Blue(),
Quantity_TOC_RGB);
-
+
if ( hasNormals )
{
- gp_Vec aNorm(aNormals->Value( 3 * normIndex - 2 ),
- aNormals->Value( 3 * normIndex - 1 ),
+ gp_Vec aNorm(aNormals->Value( 3 * normIndex - 2 ),
+ aNormals->Value( 3 * normIndex - 1 ),
aNormals->Value( 3 * normIndex ));
- aNorm.SquareMagnitude() > aMin ?
- aCPolyArr->AddVertex( P, gp_Dir( aNorm ), aNColor ) :
+ aNorm.SquareMagnitude() > aMin ?
+ aCPolyArr->AddVertex( P, gp_Dir( aNorm ), aNColor ) :
aCPolyArr->AddVertex( P, aDefNorm , aNColor );
}
else
// if IsExcludingOn then presentation must not be built by other builders
if ( IsExcludingOn() )
IDsToExclude.Add( aKey );
- }
- }
+ }
+ }
} // for ( ...
Handle(Graphic3d_AspectFillArea3d) anAsp;
Handle(AIS_Drawer) anAISDrawer = myParentMesh->Attributes();
if ( anAISDrawer.IsNull() )
return;
-
+
anAISDrawer->SetShadingAspect( new Prs3d_ShadingAspect() );
anAsp = anAISDrawer->ShadingAspect()->Aspect();
if ( anAsp.IsNull() )
anAsp->SetFrontMaterial( aMaterial[ 0 ] );
anAsp->SetBackMaterial( aMaterial[ 1 ] );
-
+
Handle(Graphic3d_Texture2D) aTexture = CreateTexture();
if ( aTexture.IsNull() )
return;
- anAsp->SetTextureMapOn();
+ anAsp->SetTextureMapOn();
anAsp->SetTextureMap( aTexture );
anAsp->SetInteriorColor( Quantity_NOC_WHITE );
}
// if ( aDrawer->GetInteger ( MeshVS_DA_InteriorStyle, aStyleInt ) )
// aStyle = (Aspect_InteriorStyle)aStyleInt;
- anAsp = new Graphic3d_AspectFillArea3d (
+ anAsp = new Graphic3d_AspectFillArea3d (
Aspect_IS_SOLID, Quantity_NOC_GRAY, anEdgeColor,
anEdgeType, anEdgeWidth, aMaterial[ 0 ], aMaterial[ 1 ] );
}
anAsp->SetDistinguishOff();
anAsp->SetEdgeOff();
- Handle(Graphic3d_AspectLine3d) anLAsp =
+ Handle(Graphic3d_AspectLine3d) anLAsp =
new Graphic3d_AspectLine3d( anEdgeColor, anEdgeType, anEdgeWidth );
-
+
Prs3d_Root::NewGroup ( Prs );
Handle(Graphic3d_Group) aGroup1 = Prs3d_Root::CurrentGroup ( Prs );
-
+
aGroup1->SetPrimitivesAspect( anAsp );
aGroup1->BeginPrimitives();
aGroup1->AddPrimitiveArray( aCPolyArr );
Handle(Graphic3d_Group) aGroup2 = Prs3d_Root::CurrentGroup ( Prs );
anAsp->SetEdgeOff();
- anAsp->SetTextureMapOff();
+ anAsp->SetTextureMapOff();
aGroup2->SetPrimitivesAspect( anAsp );
aGroup2->SetPrimitivesAspect( anLAsp );
aGroup2->BeginPrimitives();
// Function : SetColors
// Purpose :
//================================================================
-void MeshVS_NodalColorPrsBuilder::SetColors (
+void MeshVS_NodalColorPrsBuilder::SetColors (
const MeshVS_DataMapOfIntegerColor& theColorMap )
{
myNodeColorMap = theColorMap;
//================================================================
// Function : SetColorMap
-// Purpose : Set colors to be used for texrture presentation.
+// Purpose : Set colors to be used for texrture presentation.
// Generate texture in accordance with given parameters
//================================================================
void MeshVS_NodalColorPrsBuilder::SetColorMap( const Aspect_SequenceOfColor& theColors )
//================================================================
// Function : GetColorMap
-// Purpose : Return colors used for texrture presentation
+// Purpose : Return colors used for texrture presentation
//================================================================
const Aspect_SequenceOfColor& MeshVS_NodalColorPrsBuilder::GetColorMap() const
{
//================================================================
// Function : SetInvalidColor
-// Purpose : Set color representing invalid texture coordinate
+// Purpose : Set color representing invalid texture coordinate
// (laying outside range [0, 1])
//================================================================
-void MeshVS_NodalColorPrsBuilder::SetInvalidColor(
+void MeshVS_NodalColorPrsBuilder::SetInvalidColor(
const Quantity_Color& theInvalidColor )
{
myInvalidColor = theInvalidColor;
//================================================================
// Function : SetTextureCoords
-// Purpose : Specify correspondence between node IDs and texture
+// Purpose : Specify correspondence between node IDs and texture
// coordinates (range [0, 1])
//================================================================
-void MeshVS_NodalColorPrsBuilder::SetTextureCoords (
+void MeshVS_NodalColorPrsBuilder::SetTextureCoords (
const TColStd_DataMapOfIntegerReal& theMap )
{
myTextureCoords = theMap;
//================================================================
// Function : GetTextureCoords
-// Purpose : Get correspondence between node IDs and texture
-// coordinates (range [0, 1])
+// Purpose : Get correspondence between node IDs and texture
+// coordinates (range [0, 1])
//================================================================
const TColStd_DataMapOfIntegerReal& MeshVS_NodalColorPrsBuilder::GetTextureCoords() const
{
//================================================================
// Function : SetTextureCoord
-// Purpose : Specify correspondence between node ID and texture
-// coordinate (range [0, 1])
+// Purpose : Specify correspondence between node ID and texture
+// coordinate (range [0, 1])
//================================================================
void MeshVS_NodalColorPrsBuilder::SetTextureCoord( const Standard_Integer theID,
const Standard_Real theCoord )
//================================================================
// Function : GetTextureCoord
-// Purpose : Return correspondence between node IDs and texture
-// coordinate (range [0, 1])
+// Purpose : Return correspondence between node IDs and texture
+// coordinate (range [0, 1])
//================================================================
Standard_Real MeshVS_NodalColorPrsBuilder::GetTextureCoord( const Standard_Integer theID )
{
//================================================================
Handle(Graphic3d_Texture2D) MeshVS_NodalColorPrsBuilder::CreateTexture() const
{
- Handle(Graphic3d_Texture2D) aTexture;
-
- int nbColors = myTextureColorMap.Length();
- if ( nbColors == 0 )
- return aTexture;
+ const Standard_Integer aColorsNb = myTextureColorMap.Length();
+ if (aColorsNb == 0)
+ {
+ return NULL;
+ }
Handle(PrsMgr_PresentationManager3d) aPrsMgr = GetPresentationManager();
- if ( aPrsMgr.IsNull() )
- return aTexture;
+ if (aPrsMgr.IsNull())
+ {
+ return NULL;
+ }
- int nbTextureColors = getNearestPow2( nbColors );
+ // create and fill image with colors
+ Image_PixMap anImage;
+ if (!anImage.InitTrash (Image_PixMap::ImgRGBA, Standard_Size(getNearestPow2 (aColorsNb)), 2))
+ {
+ return NULL;
+ }
- // Create and fill image with colors
- Handle(Image_ColorImage) aCImage =
- new Image_ColorImage( 0, 0, nbTextureColors, 2 );
+ 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;
+ }
- if ( nbColors > 0 )
+ // 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)
{
- 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 ) );
- }
+ aData.ChangeValue (0, aCol) = aLastColor;
}
- // Convert image to bmp
- Handle(AlienImage_BMPAlienImage) aTextureImage = new AlienImage_BMPAlienImage();
- aTextureImage->FromImage( aCImage );
+ 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
- aTexture = new MeshVS_ImageTexture2D( aPrsMgr->StructureManager(), aTextureImage );
- return aTexture;
+ // create texture
+ return new MeshVS_ImageTexture2D (aPrsMgr->StructureManager(), anImage);
}
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);
//! 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;
Standard_EXPORT void FBOGetDimensions(const Graphic3d_CView& view,const Graphic3d_PtrFrameBuffer fboPtr,Standard_Integer& width,Standard_Integer& height,Standard_Integer& widthMax,Standard_Integer& heightMax);
Standard_EXPORT void FBOChangeViewport(const Graphic3d_CView& view,Graphic3d_PtrFrameBuffer& fboPtr,const Standard_Integer width,const Standard_Integer height);
Standard_EXPORT Standard_Boolean Export(const Standard_CString theFileName,const Graphic3d_ExportFormat theFormat,const Graphic3d_SortType theSortType,const Standard_Integer theWidth,const Standard_Integer theHeight,const Graphic3d_CView& theView,const Aspect_CLayer2d& theLayerUnder,const Aspect_CLayer2d& theLayerOver,const Standard_Real thePrecision = 0.005,const Standard_Address theProgressBarFunc = NULL,const Standard_Address theProgressObject = NULL);
-
+
//! Add a new top-level z layer with ID <theLayerId> for <br>
//! the view. Z layers allow drawing structures in higher layers <br>
//! in foreground of structures in lower layers. To add a structure <br>
return (openglDisplay.IsNull()? 0 : openglDisplay->Facilities().MaxViews);
}
-Standard_Boolean OpenGl_GraphicDriver::InquireTextureAvailable ()
-{
- return Standard_True;
-}
-
Standard_Integer OpenGl_GraphicDriver::InquirePlaneLimit ()
{
GLint aMaxPlanes = 0;
// 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>
#include <Quantity_NameOfColor.hxx>
#include <TColStd_HArray1OfReal.hxx>
-#include <AlienImage_AlienImage.hxx>
#include <Image_Image.hxx>
void OpenGl_GraphicDriver::Environment(const Graphic3d_CView& ACView)
void OpenGl_GraphicDriver::TriedronDisplay (
const Graphic3d_CView& ACView,
const Aspect_TypeOfTriedronPosition APosition,
- const Quantity_NameOfColor AColor,
+ const Quantity_NameOfColor AColor,
const Standard_Real AScale,
const Standard_Boolean AsWireframe )
{
}
}
-void OpenGl_GraphicDriver::TriedronErase (const Graphic3d_CView& ACView)
+void OpenGl_GraphicDriver::TriedronErase (const Graphic3d_CView& ACView)
{
const OpenGl_CView *aCView = (const OpenGl_CView *)ACView.ptrView;
if (aCView)
// Do nothing
}
-void OpenGl_GraphicDriver::BackgroundImage( const Standard_CString FileName,
+void OpenGl_GraphicDriver::BackgroundImage( const Standard_CString FileName,
const Graphic3d_CView& ACView,
const Aspect_FillMethod FillStyle )
{
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();
+ if (theImage.IsEmpty())
+ {
+ return -1;
+ }
- 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());
+ 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));
- TexUpperBounds->SetValue(1, ((Standard_Real) (MyPic->Width())/((Standard_Real) aGlWidth)));
- TexUpperBounds->SetValue(2, ((Standard_Real) (MyPic->Height())/((Standard_Real) aGlHeight)));
+ Image_PixMap anImage;
+ if (!anImage.InitTrash (Image_PixMap::ImgRGBA, Standard_Size(aGlWidth), Standard_Size(aGlHeight)))
+ {
+ return -1;
+ }
- unsigned char *MyImageData = new unsigned char[aGlWidth*aGlHeight*4];
- unsigned char *MyData = MyImageData;
- int TexId;
- int i,j;
- Quantity_Color MyColor;
+ 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;
+ }
+ }
- if (MyImageData == NULL)
- return -1;
+ // 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;
+ }
+ }
- 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);
- *MyData++ = (int)(0);
- *MyData++ = (int)(0);
- }
- *MyData++ = 0xFF;
- }
-
- // 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;
- }
-
- switch (Type)
- {
- case Graphic3d_TOT_1D:
- TexId = GetTextureData1D (fileName, aGlWidth, aGlHeight, MyImageData);
- break;
-
- case Graphic3d_TOT_2D:
- TexId = GetTextureData2D (fileName, aGlWidth, aGlHeight, MyImageData);
- break;
-
- 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
case 3:
SetModeManual (theTexId);
- break;
+ break;
}
if (theInfo.doLinear)
// 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>
#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>
* The GL_AMBIENT parameter refers to RGBA intensity of the ambient
* light.
*/
- glLightModelfv(GL_LIGHT_MODEL_AMBIENT, data_amb);
+ glLightModelfv(GL_LIGHT_MODEL_AMBIENT, data_amb);
break;
corresponding light source is a Directional one.
GL_SPOT_CUTOFF a 180 signifie que ce n'est pas un spot.
- To create a realistic effect, set the GL_SPECULAR parameter
+ To create a realistic effect, set the GL_SPECULAR parameter
to the same value as the GL_DIFFUSE.
*/
GL_SPOT_CUTOFF a 180 signifie que ce n'est pas un spot.
- To create a realistic effect, set the GL_SPECULAR parameter
+ To create a realistic effect, set the GL_SPECULAR parameter
to the same value as the GL_DIFFUSE.
*/
glLightf(*gl_lid, GL_SPOT_CUTOFF, default_sptcutoff);
glLightf(*gl_lid, GL_CONSTANT_ATTENUATION, data_constantattenuation);
glLightf(*gl_lid, GL_LINEAR_ATTENUATION, data_linearattenuation);
- glLightf(*gl_lid, GL_QUADRATIC_ATTENUATION, 0.0);
+ glLightf(*gl_lid, GL_QUADRATIC_ATTENUATION, 0.0);
break;
glLightfv(*gl_lid, GL_AMBIENT, default_amb);
glLightfv(*gl_lid, GL_DIFFUSE, data_diffu);
- glLightfv(*gl_lid, GL_SPECULAR, data_diffu);
+ glLightfv(*gl_lid, GL_SPECULAR, data_diffu);
- glLightfv(*gl_lid, GL_POSITION, data_pos);
+ glLightfv(*gl_lid, GL_POSITION, data_pos);
glLightfv(*gl_lid, GL_SPOT_DIRECTION, data_sptdir);
glLightf(*gl_lid, GL_SPOT_EXPONENT, data_sptexpo);
glLightf(*gl_lid, GL_SPOT_CUTOFF, data_sptcutoff);
glLightf(*gl_lid, GL_CONSTANT_ATTENUATION, data_constantattenuation);
glLightf(*gl_lid, GL_LINEAR_ATTENUATION, data_linearattenuation);
- glLightf(*gl_lid, GL_QUADRATIC_ATTENUATION, 0.0);
+ glLightf(*gl_lid, GL_QUADRATIC_ATTENUATION, 0.0);
break;
}
- if (lptr->type != TLightAmbient)
- {
+ if (lptr->type != TLightAmbient)
+ {
glEnable(*gl_lid);
(*gl_lid)++;
}
void call_func_eval_ori_matrix3 (const point3* vrp, // view reference point
const vec3* vpn, // view plane normal
const vec3* vup, // view up vector
- int* err_ind,
+ int* err_ind,
float mout[4][4]) // OUT view orientation matrix
{
*/
/* OCC18942: obsolete in OCCT6.3, might be removed in further versions! */
void call_func_eval_map_matrix3(
- view_map3 *Map,
- int *err_ind,
+ view_map3 *Map,
+ int *err_ind,
matrix3 mat)
{
int i, j;
/*
* Type Parallele
- */
+ */
if (Map->proj_type == TYPE_PARAL)
{
float umid, vmid;
call_util_mat_mul( tmat, shmat, tshmat );
call_util_mat_mul( smat, tshmat, mat );
- return;
+ return;
#endif
/* CAL */
aux_mat1[3][2] = Map->proj_vp.z_min;
call_util_mat_mul (aux_mat2, aux_mat1, mat);
- return;
- }
+ return;
+ }
/*
* Type Perspective
- */
+ */
else if (Map->proj_type == TYPE_PERSPECT)
{
float umid, vmid;
break;
case Aspect_GFM_DIAG1:
corner2 = myBgGradient.color2.rgb;
- corner4 = myBgGradient.color1.rgb;
+ corner4 = myBgGradient.color1.rgb;
dcorner1 [0] = dcorner2[0] = 0.5F * (corner2[0] + corner4[0]);
dcorner1 [1] = dcorner2[1] = 0.5F * (corner2[1] + corner4[1]);
dcorner1 [2] = dcorner2[2] = 0.5F * (corner2[2] + corner4[2]);
corner1 = dcorner1;
- corner3 = dcorner2;
+ corner3 = dcorner2;
break;
case Aspect_GFM_DIAG2:
- corner1 = myBgGradient.color2.rgb;
- corner3 = myBgGradient.color1.rgb;
+ corner1 = myBgGradient.color2.rgb;
+ corner3 = myBgGradient.color1.rgb;
dcorner1 [0] = dcorner2[0] = 0.5F * (corner1[0] + corner3[0]);
dcorner1 [1] = dcorner2[1] = 0.5F * (corner1[1] + corner3[1]);
dcorner1 [2] = dcorner2[2] = 0.5F * (corner1[2] + corner3[2]);
corner2 = dcorner1;
- corner4 = dcorner2;
+ corner4 = dcorner2;
break;
case Aspect_GFM_CORNER1:
corner1 = myBgGradient.color2.rgb;
glColor3f(corner2[0],corner2[1],corner2[2]); glVertex2f( 1.,-1.);
glColor3f(corner3[0],corner3[1],corner3[2]); glVertex2f( 1., 1.);
glColor3f(corner4[0],corner4[1],corner4[2]); glVertex2f(-1., 1.);
- }
+ }
else //if ( myBgGradient.type == Aspect_GFM_CORNER1 || myBgGradient.type == Aspect_GFM_CORNER3 )
{
glColor3f(corner2[0],corner2[1],corner2[2]); glVertex2f( 1.,-1.);
//TsmPushAttri(); /* save previous graphics context */
// if the view is scaled normal vectors are scaled to unit length for correct displaying of shaded objects
- if(myExtra.scaleFactors[0] != 1.F ||
+ if(myExtra.scaleFactors[0] != 1.F ||
myExtra.scaleFactors[1] != 1.F ||
myExtra.scaleFactors[2] != 1.F)
glEnable(GL_NORMALIZE);
- else if(glIsEnabled(GL_NORMALIZE))
+ else if(glIsEnabled(GL_NORMALIZE))
glDisable(GL_NORMALIZE);
// Apply View Projection
GLboolean zbuff_w;
glGetBooleanv(GL_DEPTH_WRITEMASK, &zbuff_w);
glGetIntegerv(GL_DEPTH_FUNC, &zbuff_f);
- glGetIntegerv(GL_BLEND_DST, &blend_dst);
- glGetIntegerv(GL_BLEND_SRC, &blend_src);
+ glGetIntegerv(GL_BLEND_DST, &blend_dst);
+ glGetIntegerv(GL_BLEND_SRC, &blend_src);
GLboolean zbuff_state = glIsEnabled(GL_DEPTH_TEST);
GLboolean blend_state = glIsEnabled(GL_BLEND);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
glDepthFunc(GL_EQUAL);
glEnable(GL_POINT_SMOOTH);
glEnable(GL_LINE_SMOOTH);
if( antiAliasingMode & 2 ) glEnable(GL_POLYGON_SMOOTH);
- glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable (GL_BLEND);
}
}
if (anViewportX != 0 && anViewportY != 0)
glViewport (0, 0, anViewportX, anViewportY);
}
-#endif
+#endif
glOrtho (left, right, bottom, top, -1.0, 1.0);
/*----------------------------------------------------------------------*/
//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))
+ {
+ return;
+ }
+
+ Image_PixMap anImage;
+ if (anImageLoaded.RowExtraBytes() == 0 &&
+ (anImageLoaded.Format() == Image_PixMap::ImgRGB
+ || anImageLoaded.Format() == Image_PixMap::ImgRGB32
+ || anImageLoaded.Format() == Image_PixMap::ImgRGBA))
{
- 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++ )
+ 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)
{
- const Quantity_Color &color = image->PixelColor( i, j );
- *pdata++ = (GLubyte)( 255 * color.Red() );
- *pdata++ = (GLubyte)( 255 * color.Green() );
- *pdata++ = (GLubyte)( 255 * color.Blue() );
+ 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();
+ }
- glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
-
- GLuint texture = 0;
- glGenTextures( 1, &texture );
- glBindTexture( GL_TEXTURE_2D, texture );
+ // create MipMapped texture
+ glPixelStorei (GL_UNPACK_ALIGNMENT, 1);
- /* 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);
+ GLuint aTextureId = 0;
+ glGenTextures (1, &aTextureId);
+ glBindTexture (GL_TEXTURE_2D, aTextureId);
- gluBuild2DMipmaps( GL_TEXTURE_2D, 3/*4*/, width, height, GL_RGB, GL_UNSIGNED_BYTE, data );
+ 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);
- delete[] 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());
- myBgTexture.TexId = texture;
- myBgTexture.Width = width;
- myBgTexture.Height = height;
- myBgTexture.Style = AFillStyle;
- }
+ myBgTexture.TexId = aTextureId;
+ myBgTexture.Width = (Standard_Integer )anImage.SizeX();
+ myBgTexture.Height = (Standard_Integer )anImage.SizeY();
+ myBgTexture.Style = theFillStyle;
}
/*----------------------------------------------------------------------*/
//=======================================================================
//function : AddZLayer
-//purpose :
+//purpose :
//=======================================================================
void OpenGl_View::AddZLayer (const Standard_Integer theLayerId)
//=======================================================================
//function : RemoveZLayer
-//purpose :
+//purpose :
//=======================================================================
void OpenGl_View::RemoveZLayer (const Standard_Integer theLayerId)
//=======================================================================
//function : DisplayStructure
-//purpose :
+//purpose :
//=======================================================================
void OpenGl_View::DisplayStructure (const OpenGl_Structure *theStructure,
//=======================================================================
//function : EraseStructure
-//purpose :
+//purpose :
//=======================================================================
void OpenGl_View::EraseStructure (const OpenGl_Structure *theStructure)