]> git.tdb.fi Git - libs/gl.git/blob - source/core/texture1d.h
Update and improve documentation
[libs/gl.git] / source / core / texture1d.h
1 #ifndef MSP_GL_TEXTURE1D_H_
2 #define MSP_GL_TEXTURE1D_H_
3
4 #include <string>
5 #include "texture1d_backend.h"
6
7 namespace Msp {
8 namespace GL {
9
10 /**
11 One-dimensional texture, consisting of a single row of texels.
12 */
13 class Texture1D: public Texture1DBackend
14 {
15         friend Texture1DBackend;
16
17 public:
18         class Loader: public DataFile::DerivedObjectLoader<Texture1D, Texture::Loader>
19         {
20         public:
21                 Loader(Texture1D &);
22                 Loader(Texture1D &, Collection &);
23         private:
24                 void init();
25
26                 void raw_data(const std::string &);
27                 void storage(PixelFormat, unsigned);
28                 void storage_levels(PixelFormat, unsigned, unsigned);
29         };
30
31 private:
32         unsigned width = 0;
33         unsigned levels = 0;
34
35 public:
36         /** Sets storage format and size and allocates memory for the texture.  If
37         lv is zero, a complete mipmap pyramid is automatically created.  Storage
38         cannot be changed once set. */
39         void storage(PixelFormat, unsigned wd, unsigned lv = 0);
40
41         /** Replaces contents of an entire mipmap level.  Allocated storage must
42         exist.  The image data is interpreted according to the storage format and
43         must have size matching the selected mipmap level. */
44         void image(unsigned level, const void *);
45
46         /** Replaces a range of texels in the texture.  Allocated storage must
47         exist.  The image data is interpreted according to the storage format and
48         the range must be fully inside the selected mipmap level. */
49         void sub_image(unsigned level, int x, unsigned wd, const void *);
50
51         virtual void image(const Graphics::Image &, unsigned = 0);
52
53         unsigned get_width() const { return width; }
54
55 private:
56         unsigned get_n_levels() const;
57         unsigned get_level_size(unsigned) const;
58
59 public:
60         virtual AsyncLoader *load(IO::Seekable &, const Resources * = 0) { return 0; }
61         virtual std::size_t get_data_size() const;
62         virtual void unload() { }
63 };
64
65 } // namespace GL
66 } // namespace Msp
67
68 #endif