1 | /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ |
---|
2 | |
---|
3 | #include <vr3d/vrTexture3D.h> |
---|
4 | |
---|
5 | vrTexture3D::vrTexture3D() : |
---|
6 | _width(0), |
---|
7 | _height(0), |
---|
8 | _depth(0) |
---|
9 | { |
---|
10 | _target = TT_TEXTURE_3D; |
---|
11 | _wrapT = TW_CLAMP_TO_EDGE; |
---|
12 | _wrapS = TW_CLAMP_TO_EDGE; |
---|
13 | } |
---|
14 | |
---|
15 | vrTexture3D::~vrTexture3D() |
---|
16 | { |
---|
17 | } |
---|
18 | |
---|
19 | void vrTexture3D::setPixels(COLORFORMAT colorFormat, DATATYPE type, |
---|
20 | int width, int height, int depth, void *data) |
---|
21 | { |
---|
22 | setPixels(TT_TEXTURE_3D, colorFormat, colorFormat, type, width, height, depth, data); |
---|
23 | } |
---|
24 | |
---|
25 | void vrTexture3D::setPixels(TEXTARGET target, |
---|
26 | COLORFORMAT internalColorFormat, |
---|
27 | COLORFORMAT colorFormat, |
---|
28 | DATATYPE type, |
---|
29 | int width, int height, int depth, void *data) |
---|
30 | { |
---|
31 | _target = target; |
---|
32 | _width = width; |
---|
33 | _height = height; |
---|
34 | _depth = depth; |
---|
35 | _type = type; |
---|
36 | _internalColorFormat = internalColorFormat; |
---|
37 | _colorFormat = colorFormat; |
---|
38 | _compCount = GetNumComponent(_colorFormat); |
---|
39 | |
---|
40 | if (_objectID) { |
---|
41 | glDeleteTextures(1, &_objectID); |
---|
42 | } |
---|
43 | |
---|
44 | //glPixelStorei(GL_UNPACK_ALIGNMENT, 1); |
---|
45 | glGenTextures(1, &_objectID); |
---|
46 | glBindTexture(_target, _objectID); |
---|
47 | glTexImage3D(_target, 0, _internalColorFormat, _width, _height, _depth, 0, _colorFormat, _type, data) ; |
---|
48 | glTexParameteri(_target, GL_TEXTURE_MAG_FILTER, _magFilter); |
---|
49 | glTexParameteri(_target, GL_TEXTURE_MIN_FILTER, _minFilter); |
---|
50 | |
---|
51 | //TBD.. |
---|
52 | glTexParameterf(_target, GL_TEXTURE_WRAP_S, _wrapS); |
---|
53 | glTexParameterf(_target, GL_TEXTURE_WRAP_T, _wrapT); |
---|
54 | } |
---|
55 | |
---|
56 | void vrTexture3D::updatePixels(void* data) |
---|
57 | { |
---|
58 | glPixelStorei(GL_UNPACK_ALIGNMENT, 1); |
---|
59 | glBindTexture(_target, _objectID); |
---|
60 | glTexParameteri(_target, GL_TEXTURE_WRAP_S, _wrapS); |
---|
61 | glTexParameteri(_target, GL_TEXTURE_WRAP_T, _wrapT); |
---|
62 | glTexParameteri(_target, GL_TEXTURE_MAG_FILTER, _magFilter); |
---|
63 | glTexParameteri(_target, GL_TEXTURE_MIN_FILTER, _minFilter); |
---|
64 | glTexImage3D(_target, 0, _internalColorFormat, _width, _height, _depth, 0, _colorFormat, _type, data); |
---|
65 | } |
---|