]> git.tdb.fi Git - libs/gl.git/blob - source/texture.h
Add static Texture::unbind_from function
[libs/gl.git] / source / texture.h
1 /* $Id$
2
3 This file is part of libmspgl
4 Copyright © 2007  Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
6 */
7
8 #ifndef MSP_GL_TEXTURE_H_
9 #define MSP_GL_TEXTURE_H_
10
11 #include <istream>
12 #include <msp/datafile/loader.h>
13 #include "gl.h"
14 #include "types.h"
15
16 namespace Msp {
17 namespace GL {
18
19 enum TextureFilter
20 {
21         NEAREST                = GL_NEAREST,
22         LINEAR                 = GL_LINEAR,
23         NEAREST_MIPMAP_NEAREST = GL_NEAREST_MIPMAP_NEAREST,
24         NEAREST_MIPMAP_LINEAR  = GL_NEAREST_MIPMAP_LINEAR,
25         LINEAR_MIPMAP_NEAREST  = GL_LINEAR_MIPMAP_NEAREST,
26         LINEAR_MIPMAP_LINEAR   = GL_LINEAR_MIPMAP_LINEAR
27 };
28
29 std::istream &operator>>(std::istream &, TextureFilter &);
30
31
32 /**
33 Base class for textures.  This class only defines operations common for all
34 texture types and is not instantiable.  For specifying images for textures, see
35 one of the dimensioned texture classes.
36 */
37 class Texture
38 {
39 protected:
40         class Loader: public DataFile::Loader
41         {
42         protected:
43                 Texture &tex;
44
45         public:
46                 Loader(Texture &);
47                 void min_filter(TextureFilter);
48                 void mag_filter(TextureFilter);
49                 void generate_mipmap(bool);
50         };
51
52 public:
53         ~Texture();
54
55         void bind() const;
56         void bind_to(unsigned) const;
57         void parameter(GLenum, int);
58         void parameter(GLenum, float);
59         void set_min_filter(TextureFilter f) { parameter(GL_TEXTURE_MIN_FILTER, f); }
60         void set_mag_filter(TextureFilter f) { parameter(GL_TEXTURE_MAG_FILTER, f); }
61         GLenum get_target() const            { return target; }
62         uint  get_id() const                 { return id; }
63
64         static void unbind();
65         static void unbind_from(unsigned);
66 protected:
67         uint   id;
68         GLenum target;
69
70         Texture();
71         Texture(const Texture &);
72         Texture &operator=(const Texture &);
73         void maybe_bind() const;
74 };
75
76 } // namespace GL
77 } // namespace Msp
78
79 #endif