]> git.tdb.fi Git - libs/gl.git/blob - source/texture.cpp
Add files
[libs/gl.git] / source / texture.cpp
1 #include "texture.h"
2
3 namespace Msp {
4 namespace GL {
5
6 void Texture::bind() const
7 {
8         if(!target) return;
9
10         glEnable(target);
11         glBindTexture(target, id);
12         bound=this;
13 }
14
15 void Texture::parameter(GLenum param, int value)
16 {
17         if(bound!=this) bind();
18
19         glTexParameteri(target, param, value);
20 }
21
22 void Texture::parameter(GLenum param, float value)
23 {
24         if(bound!=this) bind();
25
26         glTexParameterf(target, param, value);
27 }
28
29 sizei Texture::get_width(int level) const
30 {
31         if(bound!=this) bind();
32
33         int width;
34         glGetTexLevelParameteriv(target, level, GL_TEXTURE_WIDTH, &width);
35         return width;
36 }
37
38 sizei Texture::get_height(int level) const
39 {
40         if(bound!=this) bind();
41
42         int height;
43         glGetTexLevelParameteriv(target, level, GL_TEXTURE_HEIGHT, &height);
44         return height;
45 }
46
47 sizei Texture::get_depth(int level) const
48 {
49         if(bound!=this) bind();
50
51         int depth;
52         glGetTexLevelParameteriv(target, level, GL_TEXTURE_DEPTH, &depth);
53         return depth;
54 }
55
56 Texture::~Texture()
57 {
58         glDeleteTextures(1, &id);
59 }
60
61 Texture::Texture():
62         target(0)
63 {
64         glGenTextures(1, &id);
65 }
66
67 const Texture *Texture::bound=0;
68
69 } // namespace GL
70 } // namespace Msp