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

Last change on this file since 3464 was 3452, checked in by ldelgass, 7 years ago

Remove XINETD define from nanovis. We only support server mode now, no glut
interaction loop with mouse/keyboard handlers. Fixes for trace logging to make
output closer to vtkvis: inlcude function name for trace messages, remove
newlines from format strings in macros since newlines get added by syslog.

  • 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-2012  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] = { -1, GL_LUMINANCE, GL_LUMINANCE_ALPHA, GL_RGB, GL_RGBA };
79
80    glTexImage1D(GL_TEXTURE_1D, 0, format[_numComponents], _width, 0,
81                 format[_numComponents], _type, data);
82
83    assert(glGetError()==0);   
84}
85
86void Texture1D::activate()
87{
88    glBindTexture(GL_TEXTURE_1D, _id);
89    glEnable(GL_TEXTURE_1D);
90}
91
92void Texture1D::deactivate()
93{
94    glDisable(GL_TEXTURE_1D);           
95}
96
97void Texture1D::setWrapS(GLuint wrapMode)
98{
99    _wrapS = wrapMode;
100}
101
102void Texture1D::checkMaxSize()
103{
104    GLint max = 0;
105    glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max);
106
107    TRACE("max texture size: %d", max);
108}
109
110void Texture1D::checkMaxUnit()
111{
112    int max;
113    glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &max);
114
115    TRACE("max texture units: %d", max);
116}
Note: See TracBrowser for help on using the repository browser.