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 | |
---|
23 | Texture1D::Texture1D(){ |
---|
24 | id = -1; |
---|
25 | gl_resource_allocated = false; |
---|
26 | } |
---|
27 | |
---|
28 | Texture1D::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 | |
---|
40 | GLuint 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 != -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 | |
---|
60 | void 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 | |
---|
73 | void Texture1D::activate() |
---|
74 | { |
---|
75 | glBindTexture(GL_TEXTURE_1D, id); |
---|
76 | glEnable(GL_TEXTURE_1D); |
---|
77 | } |
---|
78 | |
---|
79 | void Texture1D::deactivate() |
---|
80 | { |
---|
81 | glDisable(GL_TEXTURE_1D); |
---|
82 | } |
---|
83 | |
---|
84 | Texture1D::~Texture1D() |
---|
85 | { |
---|
86 | glDeleteTextures(1, &id); |
---|
87 | } |
---|
88 | |
---|
89 | void 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 | |
---|
97 | void 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 | } |
---|