0024413: Visualization - get rid of projection shift from orthographic camera definition
[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 #include <Graphic3d_TextureEnv.ixx>
18 #include <Graphic3d_TypeOfTexture.hxx>
19 #include <Graphic3d_TypeOfTextureMode.hxx>
20 #include <Graphic3d_TextureParams.hxx>
21 #include <TCollection_AsciiString.hxx>
22
23 static const char *NameOfTexture_to_FileName[] =
24 {
25   "env_clouds.rgb",
26   "env_cv.rgb",
27   "env_medit.rgb",
28   "env_pearl.rgb",
29   "env_sky1.rgb",
30   "env_sky2.rgb",
31   "env_lines.rgb",
32   "env_road.rgb"
33 };
34
35 // =======================================================================
36 // function : Graphic3d_TextureEnv
37 // purpose  :
38 // =======================================================================
39 Graphic3d_TextureEnv::Graphic3d_TextureEnv (const TCollection_AsciiString& theFileName)
40 : Graphic3d_TextureRoot (theFileName, Graphic3d_TOT_2D_MIPMAP),
41   myName (Graphic3d_NOT_ENV_UNKNOWN)
42 {
43   myParams->SetFilter  (Graphic3d_TOTF_TRILINEAR);
44   myParams->SetGenMode (Graphic3d_TOTM_SPHERE,
45                         Graphic3d_Vec4 (1.0f, 0.0f, 0.0f, 0.0f),
46                         Graphic3d_Vec4 (0.0f, 1.0f, 0.0f, 0.0f));
47 }
48
49 // =======================================================================
50 // function : Graphic3d_TextureEnv
51 // purpose  :
52 // =======================================================================
53 Graphic3d_TextureEnv::Graphic3d_TextureEnv (const Graphic3d_NameOfTextureEnv theNOT)
54 : Graphic3d_TextureRoot (NameOfTexture_to_FileName[theNOT], Graphic3d_TOT_2D_MIPMAP),
55   myName (theNOT)
56 {
57   myPath.SetTrek (Graphic3d_TextureRoot::TexturesFolder());
58   myTexId = TCollection_AsciiString ("Graphic3d_TextureEnv_")
59           + NameOfTexture_to_FileName[theNOT];
60
61   myParams->SetFilter  (Graphic3d_TOTF_TRILINEAR);
62   myParams->SetGenMode (Graphic3d_TOTM_SPHERE,
63                         Graphic3d_Vec4 (1.0f, 0.0f, 0.0f, 0.0f),
64                         Graphic3d_Vec4 (0.0f, 1.0f, 0.0f, 0.0f));
65 }
66
67 // =======================================================================
68 // function : Name
69 // purpose  :
70 // =======================================================================
71 Graphic3d_NameOfTextureEnv Graphic3d_TextureEnv::Name() const
72 {
73   return myName;
74 }
75
76 // =======================================================================
77 // function : NumberOfTextures
78 // purpose  :
79 // =======================================================================
80 Standard_Integer Graphic3d_TextureEnv::NumberOfTextures()
81 {
82   return sizeof(NameOfTexture_to_FileName)/sizeof(char*);
83 }
84
85 // =======================================================================
86 // function : TextureName
87 // purpose  :
88 // =======================================================================
89 TCollection_AsciiString Graphic3d_TextureEnv::TextureName (const Standard_Integer theRank)
90 {
91   if(theRank < 1 || theRank > NumberOfTextures())
92   {
93         Standard_OutOfRange::Raise ("BAD index of texture");
94   }
95
96   TCollection_AsciiString aFileName (NameOfTexture_to_FileName[theRank - 1]);
97   Standard_Integer i = aFileName.SearchFromEnd(".");
98   return aFileName.SubString (5, i - 1);
99 }