0030640: Visualization, Graphic3d_Camera - add option creating Projection matrix...
[occt.git] / src / Graphic3d / Graphic3d_TextureEnv.cxx
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
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
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.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17
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>
25
26 IMPLEMENT_STANDARD_RTTIEXT(Graphic3d_TextureEnv,Graphic3d_TextureRoot)
27
28 static const char *NameOfTextureEnv_to_FileName[] =
29 {
30   "env_clouds.rgb",
31   "env_cv.rgb",
32   "env_medit.rgb",
33   "env_pearl.rgb",
34   "env_sky1.rgb",
35   "env_sky2.rgb",
36   "env_lines.rgb",
37   "env_road.rgb"
38 };
39
40 // =======================================================================
41 // function : Graphic3d_TextureEnv
42 // purpose  :
43 // =======================================================================
44 Graphic3d_TextureEnv::Graphic3d_TextureEnv (const TCollection_AsciiString& theFileName)
45 : Graphic3d_TextureRoot (theFileName, Graphic3d_TOT_2D_MIPMAP),
46   myName (Graphic3d_NOT_ENV_UNKNOWN)
47 {
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));
52 }
53
54 // =======================================================================
55 // function : Graphic3d_TextureEnv
56 // purpose  :
57 // =======================================================================
58 Graphic3d_TextureEnv::Graphic3d_TextureEnv (const Graphic3d_NameOfTextureEnv theNOT)
59 : Graphic3d_TextureRoot (NameOfTextureEnv_to_FileName[theNOT], Graphic3d_TOT_2D_MIPMAP),
60   myName (theNOT)
61 {
62   myPath.SetTrek (Graphic3d_TextureRoot::TexturesFolder());
63   myTexId = TCollection_AsciiString ("Graphic3d_TextureEnv_")
64           + NameOfTextureEnv_to_FileName[theNOT];
65
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));
70 }
71
72 // =======================================================================
73 // function : Graphic3d_TextureEnv
74 // purpose  :
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)
79 {
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));
84 }
85
86 // =======================================================================
87 // function : Name
88 // purpose  :
89 // =======================================================================
90 Graphic3d_NameOfTextureEnv Graphic3d_TextureEnv::Name() const
91 {
92   return myName;
93 }
94
95 // =======================================================================
96 // function : NumberOfTextures
97 // purpose  :
98 // =======================================================================
99 Standard_Integer Graphic3d_TextureEnv::NumberOfTextures()
100 {
101   return sizeof(NameOfTextureEnv_to_FileName)/sizeof(char*);
102 }
103
104 // =======================================================================
105 // function : TextureName
106 // purpose  :
107 // =======================================================================
108 TCollection_AsciiString Graphic3d_TextureEnv::TextureName (const Standard_Integer theRank)
109 {
110   if(theRank < 1 || theRank > NumberOfTextures())
111   {
112         throw Standard_OutOfRange("BAD index of texture");
113   }
114
115   TCollection_AsciiString aFileName (NameOfTextureEnv_to_FileName[theRank - 1]);
116   Standard_Integer i = aFileName.SearchFromEnd(".");
117   return aFileName.SubString (5, i - 1);
118 }