0024224: Suspicious logics in changing clipping planes at OpenGl_Structure
[occt.git] / src / Graphic3d / Graphic3d_Texture2D.cxx
1 // Created on: 1997-07-28
2 // Created by: Pierre CHALAMET
3 // Copyright (c) 1997-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
5 //
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
10 //
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 //
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
20
21 #include <Graphic3d_Texture2D.ixx>
22 #include <TCollection_AsciiString.hxx>
23
24 static const char *NameOfTexture_to_FileName[] =
25 {
26   "2d_MatraDatavision.rgb",
27   "2d_alienskin.rgb",
28   "2d_blue_rock.rgb",
29   "2d_bluewhite_paper.rgb",
30   "2d_brushed.rgb",
31   "2d_bubbles.rgb",
32   "2d_bumps.rgb",
33   "2d_cast.rgb",
34   "2d_chipbd.rgb",
35   "2d_clouds.rgb",
36   "2d_flesh.rgb",
37   "2d_floor.rgb",
38   "2d_galvnisd.rgb",
39   "2d_grass.rgb",
40   "2d_aluminum.rgb",
41   "2d_rock.rgb",
42   "2d_knurl.rgb",
43   "2d_maple.rgb",
44   "2d_marble.rgb",
45   "2d_mottled.rgb",
46   "2d_rain.rgb"
47 };
48
49 // =======================================================================
50 // function : Graphic3d_Texture2D
51 // purpose  :
52 // =======================================================================
53 Graphic3d_Texture2D::Graphic3d_Texture2D (const TCollection_AsciiString& theFileName,
54                                           const Graphic3d_TypeOfTexture  theType)
55 : Graphic3d_TextureMap (theFileName, theType),
56   myName (Graphic3d_NOT_2D_UNKNOWN)
57 {
58 }
59
60 // =======================================================================
61 // function : Graphic3d_Texture2D
62 // purpose  :
63 // =======================================================================
64 Graphic3d_Texture2D::Graphic3d_Texture2D (const Graphic3d_NameOfTexture2D theNOT,
65                                           const Graphic3d_TypeOfTexture   theType)
66 : Graphic3d_TextureMap (NameOfTexture_to_FileName[theNOT], theType),
67   myName (theNOT)
68 {
69   myPath.SetTrek (Graphic3d_TextureRoot::TexturesFolder());
70   myTexId = TCollection_AsciiString ("Graphic3d_Texture2D_")
71           + NameOfTexture_to_FileName[theNOT];
72 }
73
74 // =======================================================================
75 // function : NumberOfTextures
76 // purpose  :
77 // =======================================================================
78 Standard_Integer Graphic3d_Texture2D::NumberOfTextures()
79 {
80   return sizeof(NameOfTexture_to_FileName)/sizeof(char*);
81 }
82
83 // =======================================================================
84 // function : Name
85 // purpose  :
86 // =======================================================================
87 Graphic3d_NameOfTexture2D Graphic3d_Texture2D::Name() const
88 {
89   return myName;
90 }
91
92 // =======================================================================
93 // function : TextureName
94 // purpose  :
95 // =======================================================================
96 TCollection_AsciiString Graphic3d_Texture2D::TextureName (const Standard_Integer theRank)
97 {
98   if (theRank < 1 || theRank > NumberOfTextures())
99   {
100     Standard_OutOfRange::Raise ("BAD index of texture");
101   }
102
103   TCollection_AsciiString aFileName (NameOfTexture_to_FileName[theRank - 1]);
104   Standard_Integer i = aFileName.SearchFromEnd (".");
105   return aFileName.SubString (4, i - 1);
106 }