1 | /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ |
---|
2 | #include <vr3d/vrTexture1D.h> |
---|
3 | |
---|
4 | #include <string.h> |
---|
5 | #include <math.h> |
---|
6 | #include <valarray> |
---|
7 | |
---|
8 | #ifdef _WIN32 |
---|
9 | inline unsigned int log2(unsigned int x) |
---|
10 | { |
---|
11 | unsigned int i = 0; |
---|
12 | while ( ( x = ( x >> 1 ) ) != 0 ) i++; |
---|
13 | return i; |
---|
14 | } |
---|
15 | #endif |
---|
16 | |
---|
17 | |
---|
18 | vrTexture1D::vrTexture1D(bool depth) |
---|
19 | : _width(0) |
---|
20 | { |
---|
21 | _target = TT_TEXTURE_1D; |
---|
22 | _wrapS =TW_CLAMP_TO_EDGE; |
---|
23 | } |
---|
24 | |
---|
25 | vrTexture1D::~vrTexture1D() |
---|
26 | { |
---|
27 | } |
---|
28 | |
---|
29 | void vrTexture1D::setPixels(COLORFORMAT colorFormat, DATATYPE type, int width, void* data) |
---|
30 | |
---|
31 | { |
---|
32 | setPixels(TT_TEXTURE_1D, colorFormat, colorFormat, type, width, data); |
---|
33 | } |
---|
34 | |
---|
35 | void vrTexture1D::setPixels(TEXTARGET target, COLORFORMAT internalColorFormat, COLORFORMAT colorFormat, DATATYPE type, int width, void* data) |
---|
36 | { |
---|
37 | _target = target; |
---|
38 | _width = width; |
---|
39 | _type = type; |
---|
40 | _internalColorFormat = internalColorFormat; |
---|
41 | _colorFormat = colorFormat; |
---|
42 | _compCount = GetNumComponent(_colorFormat); |
---|
43 | |
---|
44 | if (_objectID) |
---|
45 | { |
---|
46 | glDeleteTextures(1, &_objectID); |
---|
47 | } |
---|
48 | |
---|
49 | glPixelStorei(GL_UNPACK_ALIGNMENT, 1); |
---|
50 | glGenTextures(1, &_objectID); |
---|
51 | glBindTexture(_target, _objectID); |
---|
52 | |
---|
53 | glTexParameteri(_target, GL_TEXTURE_MAG_FILTER, _magFilter); |
---|
54 | glTexParameteri(_target, GL_TEXTURE_MIN_FILTER, _minFilter); |
---|
55 | glTexParameteri(_target, GL_TEXTURE_WRAP_S, _wrapS); |
---|
56 | |
---|
57 | glTexImage1D(_target, 0, _internalColorFormat, _width, 0, _colorFormat, _type, data); |
---|
58 | |
---|
59 | |
---|
60 | } |
---|
61 | |
---|
62 | void vrTexture1D::updatePixels(void* data) |
---|
63 | { |
---|
64 | glPixelStorei(GL_UNPACK_ALIGNMENT, 1); |
---|
65 | glBindTexture(_target, _objectID); |
---|
66 | glTexParameteri(_target, GL_TEXTURE_WRAP_S, _wrapS); |
---|
67 | glTexParameteri(_target, GL_TEXTURE_MAG_FILTER, _magFilter); |
---|
68 | glTexParameteri(_target, GL_TEXTURE_MIN_FILTER, _minFilter); |
---|
69 | glTexImage1D(_target, 0, _internalColorFormat, _width, 0, _colorFormat, _type, data); |
---|
70 | } |
---|
71 | |
---|