1 /***************************************************************************
2 * This file is part of Tecorrec. *
3 * Copyright 2008 James Hogan <james@albanarts.com> *
5 * Tecorrec is free software: you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation, either version 2 of the License, or *
8 * (at your option) any later version. *
10 * Tecorrec is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with Tecorrec. If not, write to the Free Software Foundation, *
17 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
18 ***************************************************************************/
21 * @file tcPixelData.cpp
22 * @brief A block of pixel data.
25 #include "tcPixelData.h"
32 * Abstract Pixel Data Constructors + destructor
35 /// Primary constructor.
36 tcAbstractPixelData::tcAbstractPixelData(int width
, int height
)
46 tcAbstractPixelData::~tcAbstractPixelData()
55 /// Get the width of the image.
56 int tcAbstractPixelData::width() const
61 /// Get the height of the image.
62 int tcAbstractPixelData::height() const
67 /// Get (creating if necessary) a GL texture for this image.
68 GLuint
tcAbstractPixelData::texture()
72 m_textureId
= loadTexture();
77 /// Discard of any cached texture id for this image.
78 void tcAbstractPixelData::discardTexture()
80 glDeleteTextures(1, &m_textureId
);
84 * Virtual interface for derived classes to implement.
87 /// Load the pixel data into a GL texture.
88 GLuint
tcAbstractPixelData::loadTexture()
94 * Pixel data texture creation
98 GLuint tcPixelData
<GLubyte
>::loadTexture()
100 GLuint textureId
= 0;
103 glGenTextures(1, &textureId
);
105 glGetIntegerv(GL_TEXTURE_BINDING_2D
, &binding
);
106 glBindTexture(GL_TEXTURE_2D
, textureId
);
107 if (0 == gluBuild2DMipmaps(GL_TEXTURE_2D
, GL_LUMINANCE
, m_size
[0], m_size
[1],
108 GL_LUMINANCE
, GL_UNSIGNED_BYTE
, buffer()))
110 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_LINEAR_MIPMAP_NEAREST
);
111 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_LINEAR
);
112 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_S
, GL_CLAMP
);
113 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_T
, GL_CLAMP
);
117 glDeleteTextures(1, &textureId
);
119 glBindTexture(GL_TEXTURE_2D
, binding
);
125 GLuint tcPixelData
<GLfloat
>::loadTexture()
127 GLuint textureId
= 0;
130 glGenTextures(1, &textureId
);
132 glGetIntegerv(GL_TEXTURE_BINDING_2D
, &binding
);
133 glBindTexture(GL_TEXTURE_2D
, textureId
);
134 if (0 == gluBuild2DMipmaps(GL_TEXTURE_2D
, GL_LUMINANCE
, m_size
[0], m_size
[1],
135 GL_LUMINANCE
, GL_FLOAT
, buffer()))
137 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_LINEAR_MIPMAP_NEAREST
);
138 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_LINEAR
);
139 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_S
, GL_CLAMP
);
140 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_T
, GL_CLAMP
);
144 glDeleteTextures(1, &textureId
);
146 glBindTexture(GL_TEXTURE_2D
, binding
);