Graphite  Version 3
An experimental 3D geometry processing program
texture.h
Go to the documentation of this file.
1 /*
2  * OGF/Graphite: Geometry and Graphics Programming Library + Utilities
3  * Copyright (C) 2000 Bruno Levy
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  *
19  * If you modify this software, you should include a notice giving the
20  * name of the person performing the modification, the date of modification,
21  * and the reason for such modification.
22  *
23  * Contact: Bruno Levy
24  *
25  * levy@loria.fr
26  *
27  * ISA Project
28  * LORIA, INRIA Lorraine,
29  * Campus Scientifique, BP 239
30  * 54506 VANDOEUVRE LES NANCY CEDEX
31  * FRANCE
32  *
33  * Note that the GNU General Public License does not permit incorporating
34  * the Software into proprietary programs.
35  */
36 
37 #ifndef H_OGF_RENDERER_CONTEXT_TEXTURE_H
38 #define H_OGF_RENDERER_CONTEXT_TEXTURE_H
39 
41 #include <geogram/image/image.h>
42 #include <geogram_gfx/basic/GL.h>
43 
49 namespace OGF {
50 
51 //_________________________________________________________
52 
56  class RENDERER_API Texture : public Counted {
57  public:
58 
63 
70 
71 
78  index_t dimension() const;
79 
84  index_t width() const {
85  return sizes_[0];
86  }
87 
92  index_t height() const {
93  return sizes_[1];
94  }
95 
100  index_t depth() const {
101  return sizes_[2];
102  }
103 
114  const Image* image,
115  GLint filtering = GL_LINEAR,
116  GLint wrapping = GL_CLAMP_TO_EDGE
117  );
118 
134  Memory::pointer ptr,
135  Image::ColorEncoding color_encoding,
136  Image::ComponentEncoding component_encoding,
137  index_t width, index_t height, index_t depth=1,
138  GLint filtering = GL_LINEAR,
139  GLint wrapping = GL_CLAMP_TO_EDGE
140  );
141 
145  void bind();
146 
150  void unbind();
151 
156  GLuint id() const {
157  return id_;
158  }
159 
166  void reset_id() {
167  id_ = 0;
168  }
169 
170  /*
171  * \brief Gets the filtering mode.
172  * \return one of GL_NEAREST, GL_LINEAR
173  */
174  GLint get_filtering() const {
175  return filtering_;
176  }
177 
178  /*
179  * \brief Sets the filtering mode.
180  * \param filtering one of GL_NEAREST, GL_LINEAR
181  */
182  void set_filtering(GLint filtering);
183 
184  /*
185  * \brief Gets the wrapping mode.
186  * \return one of GL_CLAMP_TO_EDGE, GL_WRAP.
187  */
188  GLint get_wrapping() const {
189  return wrapping_;
190  }
191 
192  /*
193  * \brief Sets the wrapping mode.
194  * \param wrapping one of GL_CLAMP_TO_EDGE, GL_WRAP.
195  */
196  void set_wrapping(GLint wrapping) {
197  wrapping_ = wrapping;
198  }
199 
200  protected:
201 
211  Memory::pointer ptr,
212  Image::ColorEncoding color_encoding,
213  Image::ComponentEncoding component_encoding,
214  index_t width
215  );
216 
227  Memory::pointer ptr,
228  Image::ColorEncoding color_encoding,
229  Image::ComponentEncoding component_encoding,
230  index_t width, index_t height
231  );
232 
244  Memory::pointer ptr,
245  Image::ColorEncoding color_encoding,
246  Image::ComponentEncoding component_encoding,
247  index_t width, index_t height, index_t depth
248  );
249 
250 
265  static bool get_GL_formats(
266  Image::ColorEncoding color_encoding,
267  Image::ComponentEncoding component_encoding,
268  GLint& internal_format,
269  GLenum& format,
270  GLenum& type
271  );
272 
273  private:
274  index_t dimension_;
275  index_t sizes_[3];
276  GLenum target_;
277  GLUPtextureType type_;
278  GLint unit_;
279  GLint filtering_;
280  GLint wrapping_;
281  GLuint id_;
282  bool has_mipmaps_;
283  } ;
284 
286 
287 //_________________________________________________________
288 
289 }
290 #endif
291 
Some utility functions for OpenGL graphics.
Base class for reference-counted objects.
Definition: counted.h:71
An image.
Definition: image.h:59
ComponentEncoding
Indicates the datatype used to encode each component of the colors.
Definition: image.h:74
ColorEncoding
Indicates how colors are encoded within the image.
Definition: image.h:66
An OpenGL texture.
Definition: texture.h:56
static bool get_GL_formats(Image::ColorEncoding color_encoding, Image::ComponentEncoding component_encoding, GLint &internal_format, GLenum &format, GLenum &type)
Gets the parameters for specifying OpenGL textures from Image color encoding and component encoding.
~Texture()
Texture destructor.
void create_from_image(const Image *image, GLint filtering=GL_LINEAR, GLint wrapping=GL_CLAMP_TO_EDGE)
Creates a texture from an image.
index_t width() const
Gets the width.
Definition: texture.h:84
void bind()
Binds the texture to its texture target.
index_t depth() const
Gets the height.
Definition: texture.h:100
void create_from_data_1d(Memory::pointer ptr, Image::ColorEncoding color_encoding, Image::ComponentEncoding component_encoding, index_t width)
Initializes texture data for a 1d texture.
void unbind()
Unbinds the texture from its texture target.
void create_from_data(Memory::pointer ptr, Image::ColorEncoding color_encoding, Image::ComponentEncoding component_encoding, index_t width, index_t height, index_t depth=1, GLint filtering=GL_LINEAR, GLint wrapping=GL_CLAMP_TO_EDGE)
Creates a texture from raw data.
void create_from_data_3d(Memory::pointer ptr, Image::ColorEncoding color_encoding, Image::ComponentEncoding component_encoding, index_t width, index_t height, index_t depth)
Initializes texture data for a 2d texture.
GLuint id() const
Gets the id of the texture.
Definition: texture.h:156
void create_from_data_2d(Memory::pointer ptr, Image::ColorEncoding color_encoding, Image::ComponentEncoding component_encoding, index_t width, index_t height)
Initializes texture data for a 2d texture.
index_t height() const
Gets the height.
Definition: texture.h:92
Texture()
Texture constructor.
void reset_id()
Resets the id of this texture.
Definition: texture.h:166
index_t dimension() const
Gets the dimension of the texture.
byte * pointer
Pointer to unsigned byte(s)
Definition: memory.h:104
geo_index_t index_t
The type for storing and manipulating indices.
Definition: numeric.h:329
Global Graphite namespace.
Definition: common.h:76
Definitions common to all include files in the renderer library.