source: nanovis/trunk/Texture1D.cpp @ 6307

Last change on this file since 6307 was 3611, checked in by ldelgass, 11 years ago

Use nv namespace for classes in nanovis rather than prefixing class names with
Nv (still need to convert shader classes).

  • Property svn:eol-style set to native
File size: 2.6 KB
Line 
1/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
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-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
17#include <stdio.h>
18#include <assert.h>
19#include <math.h>
20
21#include "Texture1D.h"
22#include "Trace.h"
23
24using namespace nv;
25
26Texture1D::Texture1D() :
27    _width(0),
28    _numComponents(3),
29    _glResourceAllocated(false),
30    _id(0),
31    _type(GL_FLOAT),
32    _interpType(GL_LINEAR),
33    _wrapS(GL_CLAMP_TO_EDGE)
34{
35}
36
37Texture1D::Texture1D(int width,
38                     GLuint type, GLuint interp,
39                     int numComponents, void *data) :
40    _width(width),
41    _numComponents(numComponents),
42    _glResourceAllocated(false),
43    _id(0),
44    _type(type),
45    _interpType(interp),
46    _wrapS(GL_CLAMP_TO_EDGE)
47{
48    if (data != NULL)
49        initialize(data);
50}
51
52Texture1D::~Texture1D()
53{
54    glDeleteTextures(1, &_id);
55}
56
57GLuint Texture1D::initialize(void *data)
58{
59    if (_glResourceAllocated)
60        glDeleteTextures(1, &_id);
61
62    glGenTextures(1, &_id);
63
64    update(data);
65       
66    _glResourceAllocated = true;
67    return _id;
68}
69
70void Texture1D::update(void *data)
71{
72    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
73
74    glBindTexture(GL_TEXTURE_1D, _id);
75       
76    glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, _wrapS);
77    glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, _interpType);
78    glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, _interpType);
79
80    GLuint format[5] = {
81        (GLuint)-1, GL_LUMINANCE, GL_LUMINANCE_ALPHA, GL_RGB, GL_RGBA
82    };
83
84    glTexImage1D(GL_TEXTURE_1D, 0, format[_numComponents], _width, 0,
85                 format[_numComponents], _type, data);
86
87    assert(glGetError()==0);   
88}
89
90void Texture1D::activate()
91{
92    glBindTexture(GL_TEXTURE_1D, _id);
93    glEnable(GL_TEXTURE_1D);
94}
95
96void Texture1D::deactivate()
97{
98    glDisable(GL_TEXTURE_1D);           
99}
100
101void Texture1D::setWrapS(GLuint wrapMode)
102{
103    _wrapS = wrapMode;
104}
105
106void Texture1D::checkMaxSize()
107{
108    GLint max = 0;
109    glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max);
110
111    TRACE("max texture size: %d", max);
112}
113
114void Texture1D::checkMaxUnit()
115{
116    int max;
117    glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &max);
118
119    TRACE("max texture units: %d", max);
120}
Note: See TracBrowser for help on using the repository browser.