1 | /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ |
---|
2 | #include <vr3d/vrTexture3D.h> |
---|
3 | |
---|
4 | #include <string.h> |
---|
5 | #include <math.h> |
---|
6 | #include <valarray> |
---|
7 | |
---|
8 | #ifndef OPENGLES |
---|
9 | #ifdef _WIN32 |
---|
10 | inline unsigned int log2(unsigned int x) |
---|
11 | { |
---|
12 | unsigned int i = 0; |
---|
13 | while ( ( x = ( x >> 1 ) ) != 0 ) i++; |
---|
14 | return i; |
---|
15 | } |
---|
16 | #endif |
---|
17 | |
---|
18 | |
---|
19 | vrTexture3D::vrTexture3D() |
---|
20 | : _width(0), _height(0), _depth(0) |
---|
21 | { |
---|
22 | _target = TT_TEXTURE_3D; |
---|
23 | _wrapT = TW_CLAMP_TO_EDGE; |
---|
24 | _wrapS =TW_CLAMP_TO_EDGE; |
---|
25 | } |
---|
26 | |
---|
27 | vrTexture3D::~vrTexture3D() |
---|
28 | { |
---|
29 | |
---|
30 | } |
---|
31 | |
---|
32 | void vrTexture3D::setPixels(COLORFORMAT colorFormat, DATATYPE type, int width, int height, int depth, void* data) |
---|
33 | { |
---|
34 | setPixels(TT_TEXTURE_3D, colorFormat, colorFormat, type, width, height, depth, data); |
---|
35 | } |
---|
36 | |
---|
37 | void vrTexture3D::setPixels(TEXTARGET target, COLORFORMAT internalColorFormat, COLORFORMAT colorFormat, DATATYPE type, int width, int height, int depth, void* data) |
---|
38 | { |
---|
39 | _target = target; |
---|
40 | _width = width; |
---|
41 | _height = height; |
---|
42 | _depth = depth; |
---|
43 | _type = type; |
---|
44 | _internalColorFormat = internalColorFormat; |
---|
45 | _colorFormat = colorFormat; |
---|
46 | _compCount = GetNumComponent(_colorFormat); |
---|
47 | |
---|
48 | if (_objectID) |
---|
49 | { |
---|
50 | glDeleteTextures(1, &_objectID); |
---|
51 | } |
---|
52 | |
---|
53 | //glPixelStorei(GL_UNPACK_ALIGNMENT, 1); |
---|
54 | glGenTextures(1, &_objectID); |
---|
55 | glBindTexture(_target, _objectID); |
---|
56 | glTexImage3D(_target, 0, _internalColorFormat, _width, _height, _depth, 0, _colorFormat, _type, data) ; |
---|
57 | glTexParameteri(_target, GL_TEXTURE_MAG_FILTER, _magFilter); |
---|
58 | glTexParameteri(_target, GL_TEXTURE_MIN_FILTER, _minFilter); |
---|
59 | |
---|
60 | //TBD.. |
---|
61 | glTexParameterf(_target, GL_TEXTURE_WRAP_S, _wrapS); |
---|
62 | glTexParameterf(_target, GL_TEXTURE_WRAP_T, _wrapT); |
---|
63 | |
---|
64 | |
---|
65 | } |
---|
66 | |
---|
67 | void vrTexture3D::updatePixels(void* data) |
---|
68 | { |
---|
69 | glPixelStorei(GL_UNPACK_ALIGNMENT, 1); |
---|
70 | glBindTexture(_target, _objectID); |
---|
71 | glTexParameteri(_target, GL_TEXTURE_WRAP_S, _wrapS); |
---|
72 | glTexParameteri(_target, GL_TEXTURE_WRAP_T, _wrapT); |
---|
73 | glTexParameteri(_target, GL_TEXTURE_MAG_FILTER, _magFilter); |
---|
74 | glTexParameteri(_target, GL_TEXTURE_MIN_FILTER, _minFilter); |
---|
75 | glTexImage3D(_target, 0, _internalColorFormat, _width, _height, _depth, 0, _colorFormat, _type, data); |
---|
76 | /* |
---|
77 | glBindTexture(_target, _objectID); |
---|
78 | glTexSubImage3D(_target, |
---|
79 | 0, |
---|
80 | 0, |
---|
81 | 0, |
---|
82 | 0, |
---|
83 | _width, |
---|
84 | _height, |
---|
85 | _depth, |
---|
86 | _colorFormat, |
---|
87 | _type, |
---|
88 | data); |
---|
89 | */ |
---|
90 | } |
---|
91 | |
---|
92 | #endif |
---|