SimpleGL  1.1.0
A framework for platform independent rendering
texture_object.cpp
Go to the documentation of this file.
1 
9 
11 
12 namespace sgl {
13  Texture* Texture::current = nullptr;
14 
16  glGenTextures(1, &handle);
17  }
18 
20  glDeleteTextures(1, &handle);
21 
22  /* Set current to nullptr if this was the bound texture object */
23  if (Texture::current == this) {
24  Texture::current = nullptr;
25  }
26  }
27 
28  GLuint Texture::getHandle() {
29  return handle;
30  }
31 
33  return width;
34  }
35 
37  return height;
38  }
39 
40  void Texture::bind() {
41  /* If already bound return immediately */
42  if (Texture::current == this) {
43  return;
44  }
45 
46  /* Bind buffer object */
47  glBindTexture(GL_TEXTURE_2D, handle);
48  Texture::current = this;
49  }
50 
52  glGenerateMipmap(GL_TEXTURE_2D);
53  }
54 
56  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, to_GLint(filter));
57  }
58 
60  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, to_GLint(filter));
61  }
62 
64  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, to_GLint(wrap));
65  }
66 
68  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, to_GLint(wrap));
69  }
70 
71  void Texture::uploadImage(int width, int height, unsigned char* data) {
72  this->width = width;
73  this->height = height;
74  glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
75  }
76 
78  uploadImage(image.width, image.height, image.pixels);
79  }
80 }
This structure stores texture image data.
~Texture(void)
Deletes the texture object.
unsigned char * pixels
The pixel data of the image.
void bind()
Binds the texture object.
int height
The height of the image.
void setWrapS(TextureWrap wrap)
Sets the wrapping function of the texture object's coordinate S.
void setMagFilter(TextureFilter filter)
Sets the magnification filter of the texture object.
Texture(void)
Generates a new texture object.
void setWrapT(TextureWrap wrap)
Sets the wrapping function of the texture object's coordinate T.
void generateMipMap()
Generates mipmaps for the texture object.
Generic namespace for the SimpleGL framework.
Definition: application.hpp:18
int getWidth()
Returns the width of the texture object.
TextureWrap
This enum wraps the texture object's wrapping functions.
GLuint getHandle()
Returns the handle of the texture object.
TextureFilter
This enum wraps the texture object's filter.
GLint to_GLint(E e)
Gets the GLint value from an enum class.
Definition: backend_gl.tcc:17
void uploadImage(int width, int height, unsigned char *data)
Uploads image data to the texture object.
void setMinFilter(TextureFilter filter)
Sets the minification filter of the texture object.
int getHeight()
Returns the height of the texture object.
int width
The width of the image.