CGenericTexture.h
Go to the documentation of this file.
1 //==============================================================================
2 /*
3  Software License Agreement (BSD License)
4  Copyright (c) 2003-2016, CHAI3D.
5  (www.chai3d.org)
6 
7  All rights reserved.
8 
9  Redistribution and use in source and binary forms, with or without
10  modification, are permitted provided that the following conditions
11  are met:
12 
13  * Redistributions of source code must retain the above copyright
14  notice, this list of conditions and the following disclaimer.
15 
16  * Redistributions in binary form must reproduce the above
17  copyright notice, this list of conditions and the following
18  disclaimer in the documentation and/or other materials provided
19  with the distribution.
20 
21  * Neither the name of CHAI3D nor the names of its contributors may
22  be used to endorse or promote products derived from this software
23  without specific prior written permission.
24 
25  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
28  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
29  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
30  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
31  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
32  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
33  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
35  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36  POSSIBILITY OF SUCH DAMAGE.
37 
38  \author <http://www.chai3d.org>
39  \author Francois Conti
40  \version 3.2.0 $Rev: 1869 $
41 */
42 //==============================================================================
43 
44 //------------------------------------------------------------------------------
45 // Texture Filter Parameters Explained:
46 //------------------------------------------------------------------------------
47 /*
48  The value of parameter number three depends on whether you are setting a
49  GL_TEXTURE_MIN_FILTER variable or a GL_TEXTURE_MAG_FILTER variable.
50  Here are the possible combinations:
51 
52  When the second parameter is GL_TEXTURE_MIN_FILTER, parameter three can be:
53  GL_NEAREST_MIPMAP_NEAREST
54  GL_LINEAR_MIPMAP_NEAREST
55  GL_NEAREST_MIPMAP_LINEAR
56  GL_LINEAR_MIPMAP_LINEAR
57  GL_NEAREST
58  GL_LINEAR
59 
60  When the second parameter is GL_TEXTURE_MAG_FILTER, parameter three can be:
61  GL_LINEAR
62  GL_NEAREST
63 
64  The filter value set for GL_TEXTURE_MIN_FILTER is used whenever a surface is
65  rendered with smaller dimensions than its corresponding texture bitmap
66  (far away objects). Whereas the filter value for GL_TEXTURE_MAG_FILTER is used in
67  the exact opposite case when a surface is bigger than the texture being applied (near objects).
68 
69  There are more options for the min filter because it can potentially have mipmapping.
70  However, it wouldn't make sense to apply mipmapping to the mag filter since close-up
71  objects don't need it in the first place. Here's a list of all the possible combinations
72  and how they impact what is rendered (first constant in the left-most column is the near
73  object filter [mag]; second constant is the far object filter [min]):
74 
75 
76  Filter Combination Bilinear Filtering Bilinear Filtering Mipmapping
77  (MAG_FILTER/MIN_FILTER) (Near) (Far)
78  GL_NEAREST / GL_NEAREST_MIPMAP_NEAREST Off Off Standard
79  GL_NEAREST / GL_LINEAR_MIPMAP_NEAREST Off On Standard
80  GL_NEAREST / GL_NEAREST_MIPMAP_LINEAR Off Off Use trilinear filtering
81  GL_NEAREST / GL_LINEAR_MIPMAP_LINEAR Off On Use trilinear filtering
82  GL_NEAREST / GL_NEAREST Off Off None
83  GL_NEAREST / GL_LINEAR Off On None
84  GL_LINEAR / GL_NEAREST_MIPMAP_NEAREST On Off Standard
85  GL_LINEAR / GL_LINEAR_MIPMAP_NEAREST On On Standard
86  GL_LINEAR / GL_NEAREST_MIPMAP_LINEAR On Off Use trilinear filtering
87  GL_LINEAR / GL_LINEAR_MIPMAP_LINEAR On On Use trilinear filtering
88  GL_LINEAR / GL_NEAREST On Off None
89  GL_LINEAR / GL_LINEAR On On None
90 */
91 //------------------------------------------------------------------------------
92 
93 //------------------------------------------------------------------------------
94 #ifndef CGenericTextureH
95 #define CGenericTextureH
96 //------------------------------------------------------------------------------
97 #include "graphics/CColor.h"
99 //------------------------------------------------------------------------------
100 
101 //------------------------------------------------------------------------------
102 namespace chai3d {
103 //------------------------------------------------------------------------------
104 
105 //==============================================================================
112 //==============================================================================
113 
114 //------------------------------------------------------------------------------
116 typedef std::shared_ptr<cGenericTexture> cGenericTexturePtr;
117 //------------------------------------------------------------------------------
118 
119 //==============================================================================
130 //==============================================================================
132 {
133  //--------------------------------------------------------------------------
134  // CONSTRUCTOR & DESTRUCTOR:
135  //--------------------------------------------------------------------------
136 
137 public:
138 
140  cGenericTexture() { m_enabled = true; };
141 
143  virtual ~cGenericTexture() {};
144 
146  static cGenericTexturePtr create() { return (std::make_shared<cGenericTexture>()); }
147 
148 
149  //-----------------------------------------------------------------------
150  // PUBLIC METHODS:
151  //--------------------------------------------------------------------------
152 
153 public:
154 
156  virtual bool loadFromFile(const std::string& a_fileName) { return (false); }
157 
159  virtual bool saveToFile(const std::string& a_fileName) { return (false); }
160 
162  virtual void renderInitialize(cRenderOptions& a_options) {}
163 
165  virtual void renderFinalize(cRenderOptions& a_options) {}
166 
168  virtual void markForUpdate() {}
169 
171  virtual void markForDeleteAndUpdate() {}
172 
174  void setEnabled(bool a_enabled) { m_enabled = a_enabled; }
175 
177  bool getEnabled() const { return(m_enabled); }
178 
179 
180  //-----------------------------------------------------------------------
181  // PROTECTED MEMBERS:
182  //--------------------------------------------------------------------------
183 
184 protected:
185 
187  bool m_enabled;
188 };
189 
190 //------------------------------------------------------------------------------
191 } // namespace chai3d
192 //------------------------------------------------------------------------------
193 
194 //------------------------------------------------------------------------------
195 #endif
196 //------------------------------------------------------------------------------
This structures provide a containers for storing rendering options that are passed through the sceneg...
Definition: CRenderOptions.h:82
virtual ~cGenericTexture()
Destructor of cGenericTexture.
Definition: CGenericTexture.h:143
This class implements a base class for textures.
Definition: CGenericTexture.h:131
virtual void markForDeleteAndUpdate()
This method marks this texture for GPU deletion and reinitialization.
Definition: CGenericTexture.h:171
std::shared_ptr< cGenericTexture > cGenericTexturePtr
Definition: CGenericTexture.h:115
static cGenericTexturePtr create()
Shared cGenericTexture allocator.
Definition: CGenericTexture.h:146
bool getEnabled() const
This method returns true if the texture map is enabled, false otherwise.
Definition: CGenericTexture.h:177
virtual void renderInitialize(cRenderOptions &a_options)
This method enables texturing and set this texture as the current texture.
Definition: CGenericTexture.h:162
void setEnabled(bool a_enabled)
This method enables or disables texture mapping.
Definition: CGenericTexture.h:174
virtual void renderFinalize(cRenderOptions &a_options)
This method disables texturing and should be called after triangles have been rendered.
Definition: CGenericTexture.h:165
virtual bool loadFromFile(const std::string &a_fileName)
This method loads a texture image file.
Definition: CGenericTexture.h:156
Implements a structure to store rendering options.
bool m_enabled
If true, this texture is enabled, false otherwise.
Definition: CGenericTexture.h:187
Implements color properties.
cGenericTexture()
Constructor of cGenericTexture.
Definition: CGenericTexture.h:140
Definition: CAudioBuffer.cpp:56
virtual void markForUpdate()
This method marks this texture for GPU update.
Definition: CGenericTexture.h:168
virtual bool saveToFile(const std::string &a_fileName)
This method saves a texture image file.
Definition: CGenericTexture.h:159