]> git.tdb.fi Git - libs/gl.git/blob - source/texture1d.cpp
Fix the resource disassociation loop in ~ResourceManager
[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         ifmt(RGB),
13         width(0),
14         allocated(0)
15 { }
16
17 void Texture1D::storage(PixelFormat fmt, unsigned wd)
18 {
19         if(width>0)
20                 throw invalid_operation("Texture1D::storage");
21         if(wd==0)
22                 throw invalid_argument("Texture1D::storage");
23         require_pixelformat(fmt);
24
25         ifmt = fmt;
26         width = wd;
27 }
28
29 void Texture1D::allocate(unsigned level)
30 {
31         if(allocated&(1<<level))
32                 return;
33
34         image(level, get_base_pixelformat(ifmt), UNSIGNED_BYTE, 0);
35 }
36
37 void Texture1D::image(unsigned level, PixelFormat fmt, DataType type, const void *data)
38 {
39         if(width==0)
40                 throw invalid_operation("Texture1D::image");
41
42         unsigned w = get_level_size(level);
43
44         BindRestore _bind(this);
45         glTexImage1D(target, level, ifmt, w, 0, fmt, type, data);
46
47         allocated |= 1<<level;
48         if(gen_mipmap && level==0)
49         {
50                 for(; w; w>>=1, ++level) ;
51                 allocated |= (1<<level)-1;
52         }
53 }
54
55 unsigned Texture1D::get_level_size(unsigned level)
56 {
57         return width>>level;
58 }
59
60 UInt64 Texture1D::get_data_size() const
61 {
62         return id ? width*get_pixel_size(ifmt) : 0;
63 }
64
65 } // namespace GL
66 } // namespace Msp