Easy3D 2.6.1
All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
texture.h
1/********************************************************************
2 * Copyright (C) 2015 Liangliang Nan <liangliang.nan@gmail.com>
3 * https://3d.bk.tudelft.nl/liangliang/
4 *
5 * This file is part of Easy3D. If it is useful in your research/work,
6 * I would be grateful if you show your appreciation by citing it:
7 * ------------------------------------------------------------------
8 * Liangliang Nan.
9 * Easy3D: a lightweight, easy-to-use, and efficient C++ library
10 * for processing and rendering 3D data.
11 * Journal of Open Source Software, 6(64), 3255, 2021.
12 * ------------------------------------------------------------------
13 *
14 * Easy3D is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License Version 3
16 * as published by the Free Software Foundation.
17 *
18 * Easy3D is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25 ********************************************************************/
26
27#ifndef EASY3D_RENDERER_OPENGL_TEXTURE_H
28#define EASY3D_RENDERER_OPENGL_TEXTURE_H
29
30
31#include <string>
32#include <vector>
33
34
35namespace easy3d {
36
42 class Texture {
43 public:
49
54
62 static Texture* create(const std::string &image_file, WrapMode wrap = CLAMP_TO_EDGE, FilterMode filter = LINEAR);
63
74 static Texture *create(const std::vector<unsigned char> &rgb_data, int width, int height, int comp,
75 WrapMode wrap = CLAMP_TO_EDGE, FilterMode filter = LINEAR);
76
80 ~Texture();
81
86 unsigned int id() const { return id_; }
91 const std::string &name() const { return name_; }
96 void bind(int unit = 0) const;
100 void release() const;
105 int width() const { return sizes_[0]; }
110 int height() const { return sizes_[1]; }
115 int channels() const { return sizes_[2]; }
120 WrapMode wrap_mode() const { return wrap_mode_; }
125 FilterMode filter_mode() const { return filter_mode_; }
126
127 private:
128 unsigned int id_;
129 int sizes_[3];
130
131 std::string name_;
132 WrapMode wrap_mode_;
133 FilterMode filter_mode_;
134
135 private:
139 Texture();
140
141 //copying disabled
142 Texture(const Texture &);
143
144 Texture &operator=(const Texture &);
145
146 friend class TextureManager;
147 };
148
149
159 void discretize_image(
160 std::vector<unsigned char> &data,
161 int width,
162 int height,
163 int channels,
164 int num_stripes
165 );
166
167} // namespace easy3d
168
169
170#endif // EASY3D_RENDERER_OPENGL_TEXTURE_H
171
OpenGL texture.
Definition texture.h:42
const std::string & name() const
Get the name of the texture.
Definition texture.h:91
FilterMode filter_mode() const
Get the filter mode of the texture.
Definition texture.h:125
FilterMode
The filter mode of the texture.
Definition texture.h:50
@ NEAREST
Nearest neighbor interpolation.
Definition texture.h:51
@ LINEAR
Linear interpolation.
Definition texture.h:52
void release() const
Release the texture.
Definition texture.cpp:190
int channels() const
Get the number of channels of the texture.
Definition texture.h:115
void bind(int unit=0) const
Bind the texture to a texture unit.
Definition texture.cpp:184
WrapMode
The wrap mode of the texture.
Definition texture.h:45
@ REPEAT
Repeat the texture coordinate.
Definition texture.h:47
@ CLAMP_TO_EDGE
Clamp the texture coordinate to the range [0, 1].
Definition texture.h:46
int height() const
Get the height of the texture.
Definition texture.h:110
int width() const
Get the width of the texture.
Definition texture.h:105
~Texture()
Destructor.
Definition texture.cpp:45
WrapMode wrap_mode() const
Get the wrap mode of the texture.
Definition texture.h:120
unsigned int id() const
Get the OpenGL texture ID.
Definition texture.h:86
static Texture * create(const std::string &image_file, WrapMode wrap=CLAMP_TO_EDGE, FilterMode filter=LINEAR)
Creates a texture from an image file.
Definition texture.cpp:53
Management of OpenGL textures.
Definition texture_manager.h:53
Definition collider.cpp:182
void discretize_image(std::vector< unsigned char > &data, int width, int height, int channels, int num_stripes)
Discretize a gradually varying-color (from left to right) image into a set of uniform colored vertica...
Definition texture.cpp:196