source: trunk/packages/vizservers/nanovis/vr3d/vrTexture1D.cpp @ 2096

Last change on this file since 2096 was 2096, checked in by ldelgass, 13 years ago

Normalize line endings, set eol-style to native on *.cpp, *.h files

File size: 1.7 KB
Line 
1#include <vr3d/vrTexture1D.h>
2
3#include <string.h>
4#include <math.h>
5#include <valarray>
6
7#ifdef _WIN32
8inline 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
17vrTexture1D::vrTexture1D(bool depth)
18: _width(0)
19{
20        _target = TT_TEXTURE_1D;
21        _wrapS =TW_CLAMP_TO_EDGE;
22}
23
24vrTexture1D::~vrTexture1D()
25{
26}
27
28void vrTexture1D::setPixels(COLORFORMAT colorFormat, DATATYPE type, int width, void* data)
29
30{
31    setPixels(TT_TEXTURE_1D, colorFormat,  colorFormat, type, width, data);
32}
33
34void 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
66void 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
Note: See TracBrowser for help on using the repository browser.