source: nanovis/tags/1.1.2/Texture1D.cpp @ 4829

Last change on this file since 4829 was 3561, checked in by ldelgass, 11 years ago

Restore floatFormats lists in Texture2D/3D, they are needed when USE_HALF_FLOAT
is not defined, but HAVE_FLOAT_TEXTURES is. Put ifdefs around declarations of
arrays to quiet the compiler warnings.

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