CTexture1d.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: 2159 $
41 */
42 //==============================================================================
43 
44 //------------------------------------------------------------------------------
45 #ifndef CTexture1dH
46 #define CTexture1dH
47 //------------------------------------------------------------------------------
48 #include "graphics/CColor.h"
49 #include "graphics/CImage.h"
51 //------------------------------------------------------------------------------
52 
53 //------------------------------------------------------------------------------
54 namespace chai3d {
55 //------------------------------------------------------------------------------
56 
57 //==============================================================================
64 //==============================================================================
65 
66 //------------------------------------------------------------------------------
67 class cTexture1d;
68 typedef std::shared_ptr<cTexture1d> cTexture1dPtr;
69 //------------------------------------------------------------------------------
70 
71 //==============================================================================
82 //==============================================================================
84 {
85  //--------------------------------------------------------------------------
86  // CONSTRUCTOR & DESTRUCTOR:
87  //--------------------------------------------------------------------------
88 
89 public:
90 
92  cTexture1d();
93 
95  virtual ~cTexture1d();
96 
98  static cTexture1dPtr create() { return (std::make_shared<cTexture1d>()); }
99 
100 
101  //--------------------------------------------------------------------------
102  // PUBLIC METHODS:
103  //--------------------------------------------------------------------------
104 
105 public:
106 
108  inline void setTextureUnit(const GLenum a_textureUnit) { m_textureUnit = a_textureUnit; }
109 
111  inline GLenum getTextureUnit() const { return (m_textureUnit); }
112 
114  void setTextureId(const GLuint a_textureId) { m_textureID = a_textureId; }
115 
117  GLuint getTextureId() { return(m_textureID); }
118 
120  cTexture1dPtr copy();
121 
123  virtual bool loadFromFile(const std::string& a_fileName);
124 
126  virtual bool saveToFile(const std::string& a_fileName);
127 
129  virtual void renderInitialize(cRenderOptions& a_options);
130 
132  virtual void renderFinalize(cRenderOptions& a_options);
133 
135  virtual void markForUpdate();
136 
138  virtual void markForDeleteAndUpdate();
139 
141  void setEnvironmentMode(const GLint& a_environmentMode) { m_environmentMode = a_environmentMode; }
142 
144  GLint getEnvironmentMode() { return (m_environmentMode); }
145 
147  virtual void setWrapModeS(const GLint& a_wrapModeS);
148 
150  GLint getWrapModeS() const { return (m_wrapModeS); }
151 
153  void setMagFunction(const GLint a_magFunction);
154 
156  GLint getMagFunction() const { return (m_magFunction); }
157 
159  void setMinFunction(const GLint a_minFunction);
160 
162  GLint getMinFunction() const { return (m_minFunction); }
163 
165  void setSphericalMappingEnabled(const bool a_enabled) { m_useSphericalMapping = a_enabled; }
166 
169 
171  void setUseMipmaps(bool a_useMipmaps);
172 
174  bool getUseMipmaps() { return (m_useMipmaps); }
175 
177  bool setImage (cImagePtr a_image);
178 
179 
180  //--------------------------------------------------------------------------
181  // PUBLIC METHODS:
182  //--------------------------------------------------------------------------
183 
184 public:
185 
188 
191 
192 
193  //--------------------------------------------------------------------------
194  // PROTECTED METHODS:
195  //--------------------------------------------------------------------------
196 
197 protected:
198 
200  virtual void reset();
201 
203  virtual void update(cRenderOptions& a_options);
204 
205 
206  //--------------------------------------------------------------------------
207  // PROTECTED MEMBERS:
208  //--------------------------------------------------------------------------
209 
210 protected:
211 
214 
217 
219  GLuint m_textureID;
220 
222  GLint m_wrapModeS;
223 
226 
229 
232 
235 
238 
241 
244 
247 
250 
253 };
254 
255 //------------------------------------------------------------------------------
256 } // namespace chai3d
257 //------------------------------------------------------------------------------
258 
259 //------------------------------------------------------------------------------
260 #endif
261 //------------------------------------------------------------------------------
virtual ~cTexture1d()
Destructor of cTexture1d.
Definition: CTexture1d.cpp:77
Implements a base class for textures.
This structures provide a containers for storing rendering options that are passed through the sceneg...
Definition: CRenderOptions.h:82
void setEnvironmentMode(const GLint &a_environmentMode)
This method sets the environment mode (GL_MODULATE, GL_DECAL, GL_BLEND, GL_REPLACE).
Definition: CTexture1d.h:141
virtual void reset()
This method resets all internal variables. This function should be called only by constructors...
Definition: CTexture1d.cpp:125
void setTextureUnit(const GLenum a_textureUnit)
This method set the texture unit where a_textureUnit is GL_TEXTUREi_ARB, where 0i<GL_MAX_TEXTURE_UNIT...
Definition: CTexture1d.h:108
bool m_updateTextureFlag
If true, texture bitmap needs to be updated to GPU memory.
Definition: CTexture1d.h:216
virtual void markForDeleteAndUpdate()
This method marks this texture for GPU deletion and reinitialization.
Definition: CTexture1d.cpp:332
GLint getMinFunction() const
This method returns the current minification function value.
Definition: CTexture1d.h:162
virtual void markForUpdate()
This method marks this texture for GPU update.
Definition: CTexture1d.cpp:320
This class implements a base class for textures.
Definition: CGenericTexture.h:131
void setUseMipmaps(bool a_useMipmaps)
This method enables or disables the use of mipmaps.
Definition: CTexture1d.cpp:511
static cTexture1dPtr create()
Shared cTexture1d allocator.
Definition: CTexture1d.h:98
GLint m_minFunctionMipmapsON
Texture minification function when mipmapping is ON.
Definition: CTexture1d.h:252
virtual void renderFinalize(cRenderOptions &a_options)
This method disables texture rendering. This method should be called after triangles have been render...
Definition: CTexture1d.cpp:273
bool m_useSphericalMapping
If true, spherical mapping is enable.
Definition: CTexture1d.h:234
GLuint getTextureId()
This method returns the texture ID.
Definition: CTexture1d.h:117
GLenum getTextureUnit() const
This method returns the texture unit value.
Definition: CTexture1d.h:111
GLint m_magFunctionMipmapsOFF
Texture magnification function when mipmapping is OFF.
Definition: CTexture1d.h:243
bool setImage(cImagePtr a_image)
This method assigns an image to this texture.
Definition: CTexture1d.cpp:537
std::shared_ptr< cTexture1d > cTexture1dPtr
Definition: CTexture1d.h:67
GLint m_wrapModeS
Texture wrap parameter along s (GL_REPEAT or GL_CLAMP).
Definition: CTexture1d.h:222
virtual void setWrapModeS(const GLint &a_wrapModeS)
This method set the texture wrap mode of s.
Definition: CTexture1d.cpp:432
GLint getEnvironmentMode()
This method returns the environment mode status.
Definition: CTexture1d.h:144
void setMinFunction(const GLint a_minFunction)
This method sets the minification function value.
Definition: CTexture1d.cpp:487
This class implements a 1D texture map.
Definition: CTexture1d.h:83
virtual bool saveToFile(const std::string &a_fileName)
This method save a texture image to a file.
Definition: CTexture1d.cpp:307
bool getSphericalMappingEnabled() const
This method returns thestatus of the spherical mapping mode.
Definition: CTexture1d.h:168
GLint m_magFunction
Texture magnification function value. (GL_NEAREST or GL_LINEAR).
Definition: CTexture1d.h:225
void setTextureId(const GLuint a_textureId)
This method sets the texture ID.
Definition: CTexture1d.h:114
GLenum m_textureUnit
Texture unit number.
Definition: CTexture1d.h:240
cTexture1dPtr copy()
This method creates a copy of itself.
Definition: CTexture1d.cpp:97
GLint m_minFunctionMipmapsOFF
Texture minification function when mipmapping is OFF.
Definition: CTexture1d.h:246
GLint getMagFunction() const
This method returns the current magnification function value.
Definition: CTexture1d.h:156
GLint m_minFunction
Texture minification function value. (GL_NEAREST or GL_LINEAR).
Definition: CTexture1d.h:228
bool m_deleteTextureFlag
If true, texture bitmap needs to be deleted from GPU memory.
Definition: CTexture1d.h:213
This class defines a color using a GLfloat representation for each component.
Definition: CColor.h:138
Implements color properties.
GLint m_environmentMode
OpenGL texture mode (GL_MODULATE, GL_DECAL, GL_BLEND, or GL_REPLACE).
Definition: CTexture1d.h:237
virtual bool loadFromFile(const std::string &a_fileName)
This method load a texture image from a file.
Definition: CTexture1d.cpp:294
std::shared_ptr< cImage > cImagePtr
Definition: CImage.h:63
bool m_useMipmaps
If true, mipmaps are enabled.
Definition: CTexture1d.h:231
void setMagFunction(const GLint a_magFunction)
This method sets the magnification function value.
Definition: CTexture1d.cpp:449
virtual void renderInitialize(cRenderOptions &a_options)
This method enables texturing and sets this texture as the current texture.
Definition: CTexture1d.cpp:171
Definition: CAudioBuffer.cpp:56
GLuint m_textureID
OpenGL texture ID number.
Definition: CTexture1d.h:219
cImagePtr m_image
Image object associated with texture (use this to get data about the texture itself).
Definition: CTexture1d.h:187
GLint getWrapModeS() const
This method returns the texture wrap mode of s.
Definition: CTexture1d.h:150
bool getUseMipmaps()
This returns the the status of mipmaps.
Definition: CTexture1d.h:174
GLint m_magFunctionMipmapsON
Texture magnification function when mipmapping is ON.
Definition: CTexture1d.h:249
Implements a 2D image data structure.
cColorf m_color
Environmental color.
Definition: CTexture1d.h:190
virtual void update(cRenderOptions &a_options)
This method update the OpenGL texture to GPU.
Definition: CTexture1d.cpp:346
cTexture1d()
Constructor of cTexture1d.
Definition: CTexture1d.cpp:59
void setSphericalMappingEnabled(const bool a_enabled)
This method enables of disables the spherical mapping mode.
Definition: CTexture1d.h:165