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