source: trunk/packages/vizservers/nanovis/Texture1D.cpp @ 1358

Last change on this file since 1358 was 1053, checked in by gah, 16 years ago

fixes to make compile under gcc-4.3

File size: 2.5 KB
Line 
1
2/*
3 * ----------------------------------------------------------------------
4 * Texture1d.cpp: 1d texture class
5 *
6 * ======================================================================
7 *  AUTHOR:  Wei Qiao <qiaow@purdue.edu>
8 *           Purdue Rendering and Perceptualization Lab (PURPL)
9 *
10 *  Copyright (c) 2004-2006  Purdue Research Foundation
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
17#include "Texture1D.h"
18#include <stdio.h>
19#include <assert.h>
20#include <math.h>
21
22
23Texture1D::Texture1D(){
24    id = -1;                   
25    gl_resource_allocated = false;
26}
27
28Texture1D::Texture1D(int width, int type)
29{
30    assert(type == GL_UNSIGNED_BYTE || type == GL_FLOAT ||
31           type == GL_UNSIGNED_INT);
32       
33    this->width = width;
34    this->type = type;
35
36    id = -1;
37    gl_resource_allocated = false;
38}
39
40GLuint Texture1D::initialize_float_rgba(float *data)
41{
42    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
43
44    glGenTextures(1, &id);
45    glBindTexture(GL_TEXTURE_1D, id);
46    assert(id != (GLuint)-1);
47
48    glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
49
50    glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
51    glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
52
53    glTexImage1D(GL_TEXTURE_1D, 0, GL_RGBA, width, 0, GL_RGBA, GL_FLOAT, data);
54    assert(glGetError()==0);
55       
56    gl_resource_allocated = true;
57    return id;
58}
59
60void Texture1D::update_float_rgba(float* data){
61    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
62    glBindTexture(GL_TEXTURE_1D, id);
63       
64    glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
65
66    glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
67    glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
68
69    glTexImage1D(GL_TEXTURE_1D, 0, GL_RGBA, width, 0, GL_RGBA, GL_FLOAT, data);
70    assert(glGetError()==0);   
71}
72
73void Texture1D::activate()
74{
75    glBindTexture(GL_TEXTURE_1D, id);
76    glEnable(GL_TEXTURE_1D);
77}
78
79void Texture1D::deactivate()
80{
81    glDisable(GL_TEXTURE_1D);           
82}
83
84Texture1D::~Texture1D()
85{
86    glDeleteTextures(1, &id);
87}
88
89void Texture1D::check_max_size(){
90    GLint max = 0;
91    glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max);
92       
93    //printf("%d", glGetError());
94    fprintf(stderr, "max texture size: %d\n", max);
95}
96
97void Texture1D::check_max_unit(){
98    int max;
99    glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &max);
100
101    fprintf(stderr, "max texture units: %d.\n", max);
102}
Note: See TracBrowser for help on using the repository browser.