sgltk 0.6
Simple OpenGL Tool Kit
Loading...
Searching...
No Matches
texture.h
1#ifndef __TEXTURE_H__
2#define __TEXTURE_H__
3
4#include "app.h"
5#include "image.h"
6
7namespace sgltk {
8
13class Texture {
17 EXPORT static std::map<std::string, std::shared_ptr<Texture> > textures;
18public:
26 EXPORT static void add_path(std::string path);
30 GLenum target;
34 GLuint texture;
38 unsigned int width;
42 unsigned int height;
46 unsigned int num_layers;
47
48 EXPORT Texture();
49 EXPORT ~Texture();
50
56 EXPORT void set_parameter(GLenum name, int parameter);
62 EXPORT void set_parameter(GLenum name, float parameter);
68 EXPORT void set_parameter(GLenum name, float *parameter);
69
77 EXPORT static bool store_texture(std::string name, std::shared_ptr<Texture> texture);
84 EXPORT static std::shared_ptr<Texture> find_texture(std::string name);
89 virtual void bind(unsigned int texture_unit = 0) = 0;
94 virtual void unbind(unsigned int texture_unit = 0) = 0;
108 EXPORT void bind_image(GLuint unit, GLint level,
109 GLboolean layered, GLint layer,
110 GLenum access, GLenum format);
111};
112
113
118class Texture_1d : public Texture {
119public:
120 EXPORT Texture_1d();
124 EXPORT Texture_1d(const std::string& path);
128 EXPORT Texture_1d(const sgltk::Image& image);
135 EXPORT Texture_1d(unsigned int res,
136 GLenum internal_format,
137 GLenum type, GLenum format);
138 EXPORT ~Texture_1d();
139
147 EXPORT void create_empty(unsigned int res,
148 GLenum internal_format,
149 GLenum type,
150 GLenum format);
155 EXPORT bool load(const sgltk::Image& image);
160 EXPORT bool load(const std::string& path);
165 EXPORT void bind(unsigned int texture_unit = 0);
170 EXPORT void unbind(unsigned int texture_unit = 0);
171};
172
173
178class Texture_1d_Array : public Texture {
179public:
180 EXPORT Texture_1d_Array();
184 EXPORT Texture_1d_Array(const std::vector<std::string>& paths);
188 EXPORT Texture_1d_Array(const std::vector<sgltk::Image>& images);
197 EXPORT Texture_1d_Array(unsigned int res,
198 unsigned int num_layers,
199 GLenum internal_format,
200 GLenum type, GLenum format);
201 EXPORT ~Texture_1d_Array();
202
211 EXPORT void create_empty(unsigned int res,
212 unsigned int num_layers,
213 GLenum internal_format,
214 GLenum type,
215 GLenum format);
220 EXPORT bool load(const std::vector<sgltk::Image>& images);
225 EXPORT bool load(const std::vector<std::string>& paths);
230 EXPORT void bind(unsigned int texture_unit = 0);
235 EXPORT void unbind(unsigned int texture_unit = 0);
236};
237
238
243class Texture_2d : public Texture {
244public:
245 EXPORT Texture_2d();
249 EXPORT Texture_2d(const std::string& path);
253 EXPORT Texture_2d(const sgltk::Image& image);
261 EXPORT Texture_2d(unsigned int res_x,
262 unsigned int res_y,
263 GLenum internal_format,
264 GLenum type, GLenum format);
265 EXPORT ~Texture_2d();
266
275 EXPORT void create_empty(unsigned int res_x,
276 unsigned int res_y,
277 GLenum internal_format,
278 GLenum type,
279 GLenum format);
284 EXPORT bool load(const sgltk::Image& image);
289 EXPORT bool load(const std::string& path);
294 EXPORT void bind(unsigned int texture_unit = 0);
299 EXPORT void unbind(unsigned int texture_unit = 0);
300};
301
306class Texture_2d_Array : public Texture {
307public:
308 EXPORT Texture_2d_Array();
312 EXPORT Texture_2d_Array(const std::vector<std::string>& paths);
316 EXPORT Texture_2d_Array(const std::vector<sgltk::Image>& images);
326 EXPORT Texture_2d_Array(unsigned int res_x,
327 unsigned int res_y,
328 unsigned int num_layers,
329 GLenum internal_format,
330 GLenum type, GLenum format);
331 EXPORT ~Texture_2d_Array();
332
342 EXPORT void create_empty(unsigned int res_x,
343 unsigned int res_y,
344 unsigned int num_layers,
345 GLenum internal_format,
346 GLenum type,
347 GLenum format);
352 EXPORT bool load(const std::vector<sgltk::Image>& images);
357 EXPORT bool load(const std::vector<std::string>& paths);
362 EXPORT void bind(unsigned int texture_unit = 0);
367 EXPORT void unbind(unsigned int texture_unit = 0);
368};
369
374class Texture_3d : public Texture {
375public:
376 EXPORT Texture_3d();
380 EXPORT Texture_3d(const std::vector<std::string>& paths);
384 EXPORT Texture_3d(const std::vector<sgltk::Image>& images);
393 EXPORT Texture_3d(unsigned int res_x,
394 unsigned int res_y,
395 unsigned int res_z,
396 GLenum internal_format,
397 GLenum type,
398 GLenum format);
399 EXPORT ~Texture_3d();
400
410 EXPORT void create_empty(unsigned int res_x,
411 unsigned int res_y,
412 unsigned int res_z,
413 GLenum internal_format,
414 GLenum type,
415 GLenum format);
420 EXPORT bool load(const std::vector<sgltk::Image>& images);
425 EXPORT bool load(const std::vector<std::string>& paths);
430 EXPORT void bind(unsigned int texture_unit = 0);
435 EXPORT void unbind(unsigned int texture_unit = 0);
436};
437
442class Cubemap : public Texture {
443public:
444 EXPORT Cubemap();
452 EXPORT Cubemap(unsigned int res_x,
453 unsigned int res_y,
454 GLenum internal_format,
455 GLenum type,
456 GLenum format);
466 EXPORT Cubemap(const sgltk::Image& pos_x, const sgltk::Image& neg_x,
467 const sgltk::Image& pos_y, const sgltk::Image& neg_y,
468 const sgltk::Image& pos_z, const sgltk::Image& neg_z);
469 EXPORT ~Cubemap();
470
479 EXPORT void create_empty(unsigned int res_x,
480 unsigned int res_y,
481 GLenum internal_format,
482 GLenum type,
483 GLenum format);
493 EXPORT bool load(const std::string& pos_x, const std::string& neg_x,
494 const std::string& pos_y, const std::string& neg_y,
495 const std::string& pos_z, const std::string& neg_z);
505 EXPORT bool load(const sgltk::Image& pos_x, const sgltk::Image& neg_x,
506 const sgltk::Image& pos_y, const sgltk::Image& neg_y,
507 const sgltk::Image& pos_z, const sgltk::Image& neg_z);
512 EXPORT void bind(unsigned int texture_unit = 0);
517 EXPORT void unbind(unsigned int texture_unit = 0);
518};
519}
520
521#endif
void unbind(unsigned int texture_unit=0)
Unbind the texture.
Definition cubemap.cpp:100
void create_empty(unsigned int res_x, unsigned int res_y, GLenum internal_format, GLenum type, GLenum format)
Creates an empty texture.
Definition cubemap.cpp:29
bool load(const std::string &pos_x, const std::string &neg_x, const std::string &pos_y, const std::string &neg_y, const std::string &pos_z, const std::string &neg_z)
Load a new cubemap.
Definition cubemap.cpp:51
void bind(unsigned int texture_unit=0)
Bind the texture to be used by the shader.
Definition cubemap.cpp:95
Manages images.
Definition image.h:12
void unbind(unsigned int texture_unit=0)
Unbind the texture.
void create_empty(unsigned int res, unsigned int num_layers, GLenum internal_format, GLenum type, GLenum format)
Creates an empty texture.
Texture_1d_Array(const std::vector< sgltk::Image > &images)
bool load(const std::vector< sgltk::Image > &images)
Load a new image as texture.
void bind(unsigned int texture_unit=0)
Bind the texture to be used by the shader.
bool load(const sgltk::Image &image)
Load a new image as texture.
void bind(unsigned int texture_unit=0)
Bind the texture to be used by the shader.
void unbind(unsigned int texture_unit=0)
Unbind the texture.
void create_empty(unsigned int res, GLenum internal_format, GLenum type, GLenum format)
Creates an empty texture.
void bind(unsigned int texture_unit=0)
Bind the texture to be used by the shader.
bool load(const std::vector< sgltk::Image > &images)
Load a new image as texture.
void unbind(unsigned int texture_unit=0)
Unbind the texture.
Texture_2d_Array(const std::vector< sgltk::Image > &images)
void create_empty(unsigned int res_x, unsigned int res_y, unsigned int num_layers, GLenum internal_format, GLenum type, GLenum format)
Creates an empty texture.
void unbind(unsigned int texture_unit=0)
Unbind the texture.
void create_empty(unsigned int res_x, unsigned int res_y, GLenum internal_format, GLenum type, GLenum format)
Creates an empty texture.
bool load(const sgltk::Image &image)
Load a new image as texture.
void bind(unsigned int texture_unit=0)
Bind the texture to be used by the shader.
Texture_3d(const std::vector< sgltk::Image > &images)
void create_empty(unsigned int res_x, unsigned int res_y, unsigned int res_z, GLenum internal_format, GLenum type, GLenum format)
Creates an empty texture.
void unbind(unsigned int texture_unit=0)
Unbind the texture.
bool load(const std::vector< sgltk::Image > &images)
Load a new image as texture.
void bind(unsigned int texture_unit=0)
Bind the texture to be used by the shader.
unsigned int num_layers
The number of layers.
Definition texture.h:46
static std::shared_ptr< Texture > find_texture(std::string name)
Finds a texture in the internal map using the name as key.
Definition texture.cpp:40
void bind_image(GLuint unit, GLint level, GLboolean layered, GLint layer, GLenum access, GLenum format)
Binds a level of a texture to an image unit.
Definition texture.cpp:51
unsigned int width
The width of the texture.
Definition texture.h:38
static bool store_texture(std::string name, std::shared_ptr< Texture > texture)
Stores a texture object in an internal map using the name parameter as key (no duplicates)
Definition texture.cpp:36
GLenum target
The texture target.
Definition texture.h:30
void set_parameter(GLenum name, int parameter)
Sets a texture parameter.
Definition texture.cpp:18
virtual void unbind(unsigned int texture_unit=0)=0
Unbind the texture.
virtual void bind(unsigned int texture_unit=0)=0
Bind the texture to be used by the shader.
GLuint texture
The texture name.
Definition texture.h:34
static void add_path(std::string path)
Adds a path to the list of paths to be searched for image files.
Definition texture.cpp:47
unsigned int height
The height of the texture.
Definition texture.h:42