[2798] | 1 | /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ |
---|
[934] | 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 | * |
---|
[3502] | 10 | * Copyright (c) 2004-2013 HUBzero Foundation, LLC |
---|
[934] | 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 | |
---|
[2831] | 21 | #include "Texture1D.h" |
---|
| 22 | #include "Trace.h" |
---|
[934] | 23 | |
---|
[4889] | 24 | using namespace nv; |
---|
| 25 | |
---|
[2831] | 26 | Texture1D::Texture1D() : |
---|
[2857] | 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) |
---|
[2831] | 34 | { |
---|
[934] | 35 | } |
---|
| 36 | |
---|
[2831] | 37 | Texture1D::Texture1D(int width, |
---|
| 38 | GLuint type, GLuint interp, |
---|
| 39 | int numComponents, void *data) : |
---|
[2857] | 40 | _width(width), |
---|
| 41 | _numComponents(numComponents), |
---|
| 42 | _glResourceAllocated(false), |
---|
| 43 | _id(0), |
---|
| 44 | _type(type), |
---|
| 45 | _interpType(interp), |
---|
| 46 | _wrapS(GL_CLAMP_TO_EDGE) |
---|
[934] | 47 | { |
---|
[2831] | 48 | if (data != NULL) |
---|
| 49 | initialize(data); |
---|
[934] | 50 | } |
---|
| 51 | |
---|
[2831] | 52 | Texture1D::~Texture1D() |
---|
[934] | 53 | { |
---|
[2857] | 54 | glDeleteTextures(1, &_id); |
---|
[2831] | 55 | } |
---|
[934] | 56 | |
---|
[2831] | 57 | GLuint Texture1D::initialize(void *data) |
---|
| 58 | { |
---|
[2857] | 59 | if (_glResourceAllocated) |
---|
| 60 | glDeleteTextures(1, &_id); |
---|
[2831] | 61 | |
---|
[2857] | 62 | glGenTextures(1, &_id); |
---|
[934] | 63 | |
---|
[2831] | 64 | update(data); |
---|
[934] | 65 | |
---|
[2857] | 66 | _glResourceAllocated = true; |
---|
| 67 | return _id; |
---|
[934] | 68 | } |
---|
| 69 | |
---|
[2831] | 70 | void Texture1D::update(void *data) |
---|
| 71 | { |
---|
[934] | 72 | glPixelStorei(GL_UNPACK_ALIGNMENT, 1); |
---|
[2831] | 73 | |
---|
[2857] | 74 | glBindTexture(GL_TEXTURE_1D, _id); |
---|
[934] | 75 | |
---|
[2857] | 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); |
---|
[934] | 79 | |
---|
[3559] | 80 | GLuint format[5] = { |
---|
[3561] | 81 | (GLuint)-1, GL_LUMINANCE, GL_LUMINANCE_ALPHA, GL_RGB, GL_RGBA |
---|
[3559] | 82 | }; |
---|
[934] | 83 | |
---|
[2857] | 84 | glTexImage1D(GL_TEXTURE_1D, 0, format[_numComponents], _width, 0, |
---|
| 85 | format[_numComponents], _type, data); |
---|
[2831] | 86 | |
---|
[934] | 87 | assert(glGetError()==0); |
---|
| 88 | } |
---|
| 89 | |
---|
| 90 | void Texture1D::activate() |
---|
| 91 | { |
---|
[2857] | 92 | glBindTexture(GL_TEXTURE_1D, _id); |
---|
[934] | 93 | glEnable(GL_TEXTURE_1D); |
---|
| 94 | } |
---|
| 95 | |
---|
| 96 | void Texture1D::deactivate() |
---|
| 97 | { |
---|
| 98 | glDisable(GL_TEXTURE_1D); |
---|
| 99 | } |
---|
| 100 | |
---|
[2857] | 101 | void Texture1D::setWrapS(GLuint wrapMode) |
---|
| 102 | { |
---|
| 103 | _wrapS = wrapMode; |
---|
| 104 | } |
---|
| 105 | |
---|
[2900] | 106 | void Texture1D::checkMaxSize() |
---|
[934] | 107 | { |
---|
| 108 | GLint max = 0; |
---|
| 109 | glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max); |
---|
[2831] | 110 | |
---|
[3452] | 111 | TRACE("max texture size: %d", max); |
---|
[934] | 112 | } |
---|
| 113 | |
---|
[2900] | 114 | void Texture1D::checkMaxUnit() |
---|
[2831] | 115 | { |
---|
[934] | 116 | int max; |
---|
| 117 | glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &max); |
---|
| 118 | |
---|
[3452] | 119 | TRACE("max texture units: %d", max); |
---|
[934] | 120 | } |
---|