]> git.tdb.fi Git - libs/gl.git/blob - source/texture1d.cpp
Use a renderer in the viewer
[libs/gl.git] / source / texture1d.cpp
1 #include "bindable.h"
2 #include "error.h"
3 #include "texture1d.h"
4
5 using namespace std;
6
7 namespace Msp {
8 namespace GL {
9
10 Texture1D::Texture1D():
11         Texture(GL_TEXTURE_1D),
12         width(0),
13         allocated(0)
14 { }
15
16 void Texture1D::storage(PixelFormat fmt, unsigned wd)
17 {
18         if(width>0)
19                 throw invalid_operation("Texture1D::storage");
20         if(wd==0)
21                 throw invalid_argument("Texture1D::storage");
22         require_pixelformat(fmt);
23
24         ifmt = fmt;
25         width = wd;
26 }
27
28 void Texture1D::allocate(unsigned level)
29 {
30         if(allocated&(1<<level))
31                 return;
32
33         image(level, get_base_pixelformat(ifmt), UNSIGNED_BYTE, 0);
34 }
35
36 void Texture1D::image(unsigned level, PixelFormat fmt, DataType type, const void *data)
37 {
38         if(width==0)
39                 throw invalid_operation("Texture1D::image");
40
41         unsigned w = get_level_size(level);
42
43         BindRestore _bind(this);
44         glTexImage1D(target, level, ifmt, w, 0, fmt, type, data);
45
46         allocated |= 1<<level;
47         if(gen_mipmap && level==0)
48         {
49                 for(; w; w>>=1, ++level) ;
50                 allocated |= (1<<level)-1;
51         }
52 }
53
54 unsigned Texture1D::get_level_size(unsigned level)
55 {
56         return width>>level;
57 }
58
59 } // namespace GL
60 } // namespace Msp