[2096] | 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) |
---|
[1701] | 18 | : _width(0) |
---|
[2096] | 19 | { |
---|
| 20 | _target = TT_TEXTURE_1D; |
---|
| 21 | _wrapS =TW_CLAMP_TO_EDGE; |
---|
| 22 | } |
---|
[1701] | 23 | |
---|
[2096] | 24 | vrTexture1D::~vrTexture1D() |
---|
| 25 | { |
---|
| 26 | } |
---|
[1701] | 27 | |
---|
[2096] | 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 | glPixelStorei(GL_UNPACK_ALIGNMENT, 1); |
---|
| 49 | glGenTextures(1, &_objectID); |
---|
| 50 | glBindTexture(_target, _objectID); |
---|
| 51 | |
---|
| 52 | glTexParameteri(_target, GL_TEXTURE_MAG_FILTER, _magFilter); |
---|
| 53 | glTexParameteri(_target, GL_TEXTURE_MIN_FILTER, _minFilter); |
---|
| 54 | glTexParameteri(_target, GL_TEXTURE_WRAP_S, _wrapS); |
---|
| 55 | |
---|
| 56 | glTexImage1D(_target, 0, _internalColorFormat, _width, 0, _colorFormat, _type, data); |
---|
| 57 | |
---|
| 58 | |
---|
| 59 | } |
---|
| 60 | |
---|
| 61 | void vrTexture1D::updatePixels(void* data) |
---|
| 62 | { |
---|
| 63 | glPixelStorei(GL_UNPACK_ALIGNMENT, 1); |
---|
| 64 | glBindTexture(_target, _objectID); |
---|
| 65 | glTexParameteri(_target, GL_TEXTURE_WRAP_S, _wrapS); |
---|
| 66 | glTexParameteri(_target, GL_TEXTURE_MAG_FILTER, _magFilter); |
---|
| 67 | glTexParameteri(_target, GL_TEXTURE_MIN_FILTER, _minFilter); |
---|
| 68 | glTexImage1D(_target, 0, _internalColorFormat, _width, 0, _colorFormat, _type, data); |
---|
| 69 | } |
---|
| 70 | |
---|