Easy3D 2.5.3
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
44 class Texture {
45 public:
46 enum WrapMode {
47 CLAMP_TO_EDGE, REPEAT
48 };
49 enum FilterMode {
50 NEAREST, LINEAR
51 };
52
58 static Texture *
59 create(const std::string &image_file, WrapMode wrap = CLAMP_TO_EDGE, FilterMode filter = LINEAR);
60
69 static Texture *create(const std::vector<unsigned char> &rgb_data, int width, int height, int comp,
70 WrapMode wrap = CLAMP_TO_EDGE, FilterMode filter = LINEAR);
71
72 ~Texture();
73
74 unsigned int id() const { return id_; }
75
76 const std::string &name() const { return name_; }
77
78 void bind(int unit = 0) const;
79
80 void release() const;
81
82 int width() const { return sizes_[0]; }
83
84 int height() const { return sizes_[1]; }
85
86 int channels() const { return sizes_[2]; }
87
88 WrapMode wrap_mode() const { return wrap_mode_; }
89
90 FilterMode filter_mode() const { return filter_mode_; }
91
92 private:
93 unsigned int id_;
94 int sizes_[3];
95
96 std::string name_;
97 WrapMode wrap_mode_;
98 FilterMode filter_mode_;
99
100 private:
102 Texture();
103
104 //copying disabled
105 Texture(const Texture &);
106
107 Texture &operator=(const Texture &);
108
109 friend class TextureManager;
110 };
111
112
122 void discretize_image(
123 std::vector<unsigned char> &data,
124 int width,
125 int height,
126 int channels,
127 int num_stripes
128 );
129
130} // namespace easy3d
131
132
133#endif // EASY3D_RENDERER_OPENGL_TEXTURE_H
134
OpenGL texture.
Definition: texture.h:44
static Texture * create(const std::string &image_file, WrapMode wrap=CLAMP_TO_EDGE, FilterMode filter=LINEAR)
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