sgltk 0.6
Simple OpenGL Tool Kit
Loading...
Searching...
No Matches
texture.cpp
1#include "texture.h"
2
3using namespace sgltk;
4
5std::map<std::string, std::shared_ptr<Texture> > Texture::textures;
6
7Texture::Texture() {
8 width = 0;
9 height = 0;
10 num_layers = 1;
11 glGenTextures(1, &texture);
12}
13
14Texture::~Texture() {
15 glDeleteTextures(1, &texture);
16}
17
18void Texture::set_parameter(GLenum name, int parameter) {
19 bind();
20 glTexParameteri(target, name, parameter);
21 unbind();
22}
23
24void Texture::set_parameter(GLenum name, float parameter) {
25 bind();
26 glTexParameterf(target, name, parameter);
27 unbind();
28}
29
30void Texture::set_parameter(GLenum name, float *parameter) {
31 bind();
32 glTexParameterfv(target, name, parameter);
33 unbind();
34}
35
36bool Texture::store_texture(std::string name, std::shared_ptr<Texture> texture) {
37 return textures.insert(std::make_pair(name, texture)).second;
38}
39
40std::shared_ptr<Texture> Texture::find_texture(std::string name) {
41 const auto& it = textures.find(name);
42 if(it == textures.end())
43 return nullptr;
44 return it->second;
45}
46
47void Texture::add_path(std::string path) {
48 Image::add_path(path);
49}
50
51void Texture::bind_image(GLuint unit, GLint level,
52 GLboolean layered, GLint layer,
53 GLenum access, GLenum format) {
54
55 glBindImageTexture(unit, texture, level, layered, layer, access, format);
56}
static void add_path(std::string path)
Adds a path to the list of paths to be searched for image files.
Definition image.cpp:374
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