]> git.tdb.fi Git - libs/gl.git/blob - source/texture2d.h
Add class MeshBuilder
[libs/gl.git] / source / texture2d.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_TEXTURE2D_H_
9 #define MSP_GL_TEXTURE2D_H_
10
11 #include <string>
12 #include <msp/datafile/loader.h>
13 #include "pixelformat.h"
14 #include "texture.h"
15
16 namespace Msp {
17 namespace GL {
18
19 class Image;
20
21 /**
22 Two-dimensional texture class.  This is the most common type of texture.
23 */
24 class Texture2D: public Texture
25 {
26 public:
27         class Loader: public Texture::Loader
28         {
29         public:
30                 Loader(Texture2D &);
31         private:
32                 void image_data(const std::string &);
33                 void raw_data(const std::string &);
34                 void storage(PixelFormat, unsigned, unsigned, unsigned);
35         };
36
37 private:
38         PixelFormat ifmt;
39         sizei width;
40         sizei height;
41         int border;
42
43 public:
44         Texture2D();
45
46         /**
47         Defines the texture storage.  This function may only be successfully called
48         once.
49         */
50         void storage(PixelFormat fmt, sizei wd, sizei ht, int brd);
51         
52         /**
53         Uploads an image to the texture.  storage() must have been called prior to
54         this, and the image must have dimensions conforming to the specified
55         storage.
56         */
57         void image(int level, PixelFormat fmt, DataType type, const void *data);
58
59         /**
60         Uploads a sub-image into the texture.  Unlike full image upload, there are
61         no constraints on the size of the sub-image.
62         */
63         void sub_image(int level, int x, int y, sizei wd, sizei ht, PixelFormat fmt, DataType type, const void *data);
64
65         /**
66         Loads an image from a file and uploads it to the texture.  If storage() has
67         not been called, the storage format will be set to match the loaded image.
68         */
69         void load_image(const std::string &fn);
70
71         sizei get_width() const  { return width; }
72         sizei get_height() const { return height; }
73
74 private:
75         void image(const Image &);
76 };
77
78 } // namespace GL
79 } // namespace Msp
80
81 #endif