1 // Created on: 1997-07-28
2 // Created by: Pierre CHALAMET
3 // Copyright (c) 1997-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
18 #include <Graphic3d_TextureEnv.hxx>
19 #include <Graphic3d_TextureParams.hxx>
20 #include <Graphic3d_TypeOfTexture.hxx>
21 #include <Graphic3d_TypeOfTextureMode.hxx>
22 #include <Standard_OutOfRange.hxx>
23 #include <Standard_Type.hxx>
24 #include <TCollection_AsciiString.hxx>
26 IMPLEMENT_STANDARD_RTTIEXT(Graphic3d_TextureEnv,Graphic3d_TextureRoot)
28 static const char *NameOfTextureEnv_to_FileName[] =
40 // =======================================================================
41 // function : Graphic3d_TextureEnv
43 // =======================================================================
44 Graphic3d_TextureEnv::Graphic3d_TextureEnv (const TCollection_AsciiString& theFileName)
45 : Graphic3d_TextureRoot (theFileName, Graphic3d_TOT_2D_MIPMAP),
46 myName (Graphic3d_NOT_ENV_UNKNOWN)
48 myParams->SetFilter (Graphic3d_TOTF_TRILINEAR);
49 myParams->SetGenMode (Graphic3d_TOTM_SPHERE,
50 Graphic3d_Vec4 (1.0f, 0.0f, 0.0f, 0.0f),
51 Graphic3d_Vec4 (0.0f, 1.0f, 0.0f, 0.0f));
54 // =======================================================================
55 // function : Graphic3d_TextureEnv
57 // =======================================================================
58 Graphic3d_TextureEnv::Graphic3d_TextureEnv (const Graphic3d_NameOfTextureEnv theNOT)
59 : Graphic3d_TextureRoot (NameOfTextureEnv_to_FileName[theNOT], Graphic3d_TOT_2D_MIPMAP),
62 myPath.SetTrek (Graphic3d_TextureRoot::TexturesFolder());
63 myTexId = TCollection_AsciiString ("Graphic3d_TextureEnv_")
64 + NameOfTextureEnv_to_FileName[theNOT];
66 myParams->SetFilter (Graphic3d_TOTF_TRILINEAR);
67 myParams->SetGenMode (Graphic3d_TOTM_SPHERE,
68 Graphic3d_Vec4 (1.0f, 0.0f, 0.0f, 0.0f),
69 Graphic3d_Vec4 (0.0f, 1.0f, 0.0f, 0.0f));
72 // =======================================================================
73 // function : Graphic3d_TextureEnv
75 // =======================================================================
76 Graphic3d_TextureEnv::Graphic3d_TextureEnv (const Handle(Image_PixMap)& thePixMap)
77 : Graphic3d_TextureRoot (thePixMap, Graphic3d_TOT_2D_MIPMAP),
78 myName (Graphic3d_NOT_ENV_UNKNOWN)
80 myParams->SetFilter (Graphic3d_TOTF_TRILINEAR);
81 myParams->SetGenMode (Graphic3d_TOTM_SPHERE,
82 Graphic3d_Vec4 (1.0f, 0.0f, 0.0f, 0.0f),
83 Graphic3d_Vec4 (0.0f, 1.0f, 0.0f, 0.0f));
86 // =======================================================================
89 // =======================================================================
90 Graphic3d_NameOfTextureEnv Graphic3d_TextureEnv::Name() const
95 // =======================================================================
96 // function : NumberOfTextures
98 // =======================================================================
99 Standard_Integer Graphic3d_TextureEnv::NumberOfTextures()
101 return sizeof(NameOfTextureEnv_to_FileName)/sizeof(char*);
104 // =======================================================================
105 // function : TextureName
107 // =======================================================================
108 TCollection_AsciiString Graphic3d_TextureEnv::TextureName (const Standard_Integer theRank)
110 if(theRank < 1 || theRank > NumberOfTextures())
112 throw Standard_OutOfRange("BAD index of texture");
115 TCollection_AsciiString aFileName (NameOfTextureEnv_to_FileName[theRank - 1]);
116 Standard_Integer i = aFileName.SearchFromEnd(".");
117 return aFileName.SubString (5, i - 1);