source: trunk/gui/vizservers/nanovis/Texture3D.cpp @ 226

Last change on this file since 226 was 226, checked in by mmc, 18 years ago
  • Added code for Wei's visualization server.
  • Fixed the energyLevels widget so that it doesn't barf when the user attempts to download its contents.
File size: 3.5 KB
Line 
1/*
2 * ----------------------------------------------------------------------
3 * Texture3d.cpp: 3d texture class
4 *
5 * ======================================================================
6 *  AUTHOR:  Wei Qiao <qiaow@purdue.edu>
7 *           Purdue Rendering and Perceptualization Lab (PURPL)
8 *
9 *  Copyright (c) 2004-2006  Purdue Research Foundation
10 *
11 *  See the file "license.terms" for information on usage and
12 *  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
13 * ======================================================================
14 */
15#ifdef WIN32
16        #include <windows.h>
17#endif
18
19#include "Texture3D.h"
20#include <stdio.h>
21#include <assert.h>
22#include <math.h>
23
24
25Texture3D::Texture3D(){ id=-1; gl_resource_allocated = false; }
26
27Texture3D::Texture3D(int width, int height, int depth, int type, int interp, int components)
28{
29        assert(type == GL_UNSIGNED_BYTE || type == GL_FLOAT|| type ==GL_UNSIGNED_INT);
30       
31        this->width = width;
32        this->height = height;
33        this->depth = depth;
34
35        int m = (width > height) ? width : height;
36        m = (m > depth) ? m : depth;
37
38        //int m = max(max(width, height), depth);
39        this->aspect_ratio_width = (double)width/(double)m;
40        this->aspect_ratio_height = (double)height/(double)m;
41        this->aspect_ratio_depth = (double)depth/(double)m;
42
43        this->type = type;
44        this->interp_type = interp;
45        this->n_components = components;
46
47        id = -1;
48        gl_resource_allocated = false;
49}
50
51GLuint Texture3D::load_tex_data(float *data)
52{
53        //load texture with 16 bit half floating point precision
54        //half float with linear interpolation is only supported by 6 series and up cards
55        glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
56
57        glGenTextures(1, &id);
58        glBindTexture(GL_TEXTURE_3D, id);
59        assert(id!=-1);
60
61        glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
62        glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
63        glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
64
65        if(interp_type==GL_LINEAR){
66                glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
67                glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
68        }
69        else{
70                glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
71                glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
72        }
73
74        switch(n_components){
75                case 1:
76                        glTexImage3D(GL_TEXTURE_3D, 0, GL_LUMINANCE16F_ARB, width, height, depth, 0, GL_LUMINANCE, GL_FLOAT, data);
77                        break;
78                case 2:
79                        glTexImage3D(GL_TEXTURE_3D, 0, GL_LUMINANCE_ALPHA16F_ARB, width, height, depth, 0, GL_LUMINANCE_ALPHA, GL_FLOAT, data);
80                        break;
81                case 3:
82                        glTexImage3D(GL_TEXTURE_3D, 0, GL_RGB16F_ARB, width, height, depth, 0, GL_RGB, GL_FLOAT, data);
83                        break;
84                case 4:
85                        glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA16F_ARB, width, height, depth, 0, GL_RGBA, GL_FLOAT, data);
86                        break;
87                default:
88                        break;
89        }
90        assert(glGetError()==0);
91       
92        gl_resource_allocated = true;
93        return id;
94}
95
96void Texture3D::activate()
97{
98        glEnable(GL_TEXTURE_3D);
99        glBindTexture(GL_TEXTURE_3D, id);
100}
101
102void Texture3D::deactivate()
103{
104        glDisable(GL_TEXTURE_3D);               
105}
106
107Texture3D::~Texture3D()
108{
109        glDeleteTextures(1, &id);
110}
111
112void Texture3D::check_max_size(){
113        GLint max = 0;
114        glGetIntegerv(GL_MAX_3D_TEXTURE_SIZE_EXT, &max);
115       
116        //printf("%d", glGetError());
117        fprintf(stderr, "max 3d texture size: %d\n", max);
118}
119
120void Texture3D::check_max_unit(){
121        int max;
122        glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &max);
123
124        fprintf(stderr, "max texture units: %d.\n", max);
125}
Note: See TracBrowser for help on using the repository browser.