source: trunk/packages/vizservers/nanovis/Texture3D.cpp @ 3559

Last change on this file since 3559 was 3559, checked in by gah, 11 years ago
  • Clean up unused variable warnings.
  • Remove use of ffmpeg libraries from nanovis. This should make it easier to maintain (don't have to keep up with all the backward incompatible changes to the ffmpeg library).
  • Property svn:eol-style set to native
File size: 3.7 KB
Line 
1/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2/*
3 * ----------------------------------------------------------------------
4 * Texture3d.cpp: 3d texture class
5 *
6 * ======================================================================
7 *  AUTHOR:  Wei Qiao <qiaow@purdue.edu>
8 *           Purdue Rendering and Perceptualization Lab (PURPL)
9 *
10 *  Copyright (c) 2004-2013  HUBzero Foundation, LLC
11 *
12 *  See the file "license.terms" for information on usage and
13 *  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
14 * ======================================================================
15 */
16#include <stdio.h>
17#include <assert.h>
18#include <math.h>
19
20#include "config.h"
21
22#include "Texture3D.h"
23#include "Trace.h"
24
25Texture3D::Texture3D() :
26    _width(0),
27    _height(0),
28    _depth(0),
29    _numComponents(3),
30    _glResourceAllocated(false),
31    _id(0),
32    _type(GL_FLOAT),
33    _interpType(GL_LINEAR),
34    _wrapS(GL_CLAMP_TO_EDGE),
35    _wrapT(GL_CLAMP_TO_EDGE),
36    _wrapR(GL_CLAMP_TO_EDGE)
37{}
38
39Texture3D::Texture3D(int width, int height, int depth,
40                     GLuint type, GLuint interp,
41                     int numComponents, void *data) :
42    _width(width),
43    _height(height),
44    _depth(depth),
45    _numComponents(numComponents),
46    _glResourceAllocated(false),
47    _id(0),
48    _type(type),
49    _interpType(interp),
50    _wrapS(GL_CLAMP_TO_EDGE),
51    _wrapT(GL_CLAMP_TO_EDGE),
52    _wrapR(GL_CLAMP_TO_EDGE)
53{
54    if (data != NULL)
55        initialize(data);
56}
57
58Texture3D::~Texture3D()
59{
60    glDeleteTextures(1, &_id);
61}
62
63GLuint Texture3D::initialize(void *data)
64{
65    if (_glResourceAllocated)
66        glDeleteTextures(1, &_id);
67
68    glGenTextures(1, &_id);
69
70    update(data);
71
72    _glResourceAllocated = true;
73    return _id;
74}
75
76void Texture3D::update(void *data)
77{
78    static GLuint halfFloatFormats[] = {
79        (unsigned int)-1, GL_LUMINANCE16F_ARB, GL_LUMINANCE_ALPHA16F_ARB,
80        GL_RGB16F_ARB, GL_RGBA16F_ARB };
81    static GLuint basicFormats[] = {
82        (unsigned int)-1, GL_LUMINANCE, GL_LUMINANCE_ALPHA, GL_RGB, GL_RGBA
83    };
84    glBindTexture(GL_TEXTURE_3D, _id);
85
86    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
87
88    glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, _wrapS);
89    glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, _wrapT);
90    glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, _wrapR);
91
92    glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, _interpType);
93    glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, _interpType);
94
95    //to do: add handling to more formats
96    GLuint *targetFormats;
97#ifdef HAVE_FLOAT_TEXTURES
98    if (_type == GL_FLOAT) {
99# ifdef USE_HALF_FLOAT
100        targetFormats = halfFloatFormats;
101# else
102        targetFormats = floatFormats;
103# endif
104    } else {
105#endif
106        targetFormats = basicFormats;
107#ifdef HAVE_FLOAT_TEXTURES
108    }
109#endif
110
111    glTexImage3D(GL_TEXTURE_3D, 0, targetFormats[_numComponents],
112                 _width, _height, _depth, 0,
113                 basicFormats[_numComponents], _type, data);
114
115    assert(glGetError()==0);
116}
117
118void Texture3D::activate()
119{
120    glEnable(GL_TEXTURE_3D);
121    glBindTexture(GL_TEXTURE_3D, _id);
122}
123
124void Texture3D::deactivate()
125{
126    glDisable(GL_TEXTURE_3D);           
127}
128
129void Texture3D::setWrapS(GLuint wrapMode)
130{
131    _wrapS = wrapMode;
132}
133
134void Texture3D::setWrapT(GLuint wrapMode)
135{
136    _wrapT = wrapMode;
137}
138
139void Texture3D::setWrapR(GLuint wrapMode)
140{
141    _wrapR = wrapMode;
142}
143
144void Texture3D::checkMaxSize()
145{
146    GLint max = 0;
147    glGetIntegerv(GL_MAX_3D_TEXTURE_SIZE_EXT, &max);
148
149    TRACE("max 3d texture size: %d", max);
150}
151
152void Texture3D::checkMaxUnit()
153{
154    int max;
155    glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &max);
156
157    TRACE("max texture units: %d", max);
158}
Note: See TracBrowser for help on using the repository browser.