]> git.tdb.fi Git - libs/gl.git/blob - source/texture.h
Get rid of the typedefs for fundamental types
[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/objectloader.h>
13 #include "gl.h"
14
15 namespace Msp {
16 namespace GL {
17
18 enum TextureFilter
19 {
20         NEAREST                = GL_NEAREST,
21         LINEAR                 = GL_LINEAR,
22         NEAREST_MIPMAP_NEAREST = GL_NEAREST_MIPMAP_NEAREST,
23         NEAREST_MIPMAP_LINEAR  = GL_NEAREST_MIPMAP_LINEAR,
24         LINEAR_MIPMAP_NEAREST  = GL_LINEAR_MIPMAP_NEAREST,
25         LINEAR_MIPMAP_LINEAR   = GL_LINEAR_MIPMAP_LINEAR
26 };
27
28 std::istream &operator>>(std::istream &, TextureFilter &);
29
30
31 /**
32 Base class for textures.  This class only defines operations common for all
33 texture types and is not instantiable.  For specifying images for textures, see
34 one of the dimensioned texture classes.
35 */
36 class Texture
37 {
38 protected:
39         class Loader: public DataFile::ObjectLoader<Texture>
40         {
41         public:
42                 Loader(Texture &);
43                 void min_filter(TextureFilter);
44                 void mag_filter(TextureFilter);
45                 void generate_mipmap(bool);
46         };
47
48 public:
49         ~Texture();
50
51         void bind() const;
52         void bind_to(unsigned) const;
53         void parameter(GLenum, int);
54         void parameter(GLenum, float);
55         void set_min_filter(TextureFilter f) { parameter(GL_TEXTURE_MIN_FILTER, f); }
56         void set_mag_filter(TextureFilter f) { parameter(GL_TEXTURE_MAG_FILTER, f); }
57         GLenum get_target() const            { return target; }
58         unsigned  get_id() const                 { return id; }
59
60         static void unbind();
61         static void unbind_from(unsigned);
62 protected:
63         unsigned   id;
64         GLenum target;
65
66         Texture();
67         Texture(const Texture &);
68         Texture &operator=(const Texture &);
69         void maybe_bind() const;
70 };
71
72 } // namespace GL
73 } // namespace Msp
74
75 #endif