00001 #include "GLTexture.h"
00002
00003 #include <QDebug>
00004
00005 GLTexture::GLTexture()
00006 {
00007 texture = 0;
00008 }
00009
00010 GLTexture::~GLTexture()
00011 {
00012 free();
00013 }
00014
00015 GLuint GLTexture::getTexture()
00016 {
00017 return texture;
00018 }
00019
00020 void GLTexture::setTypes(GLuint textureColorType, GLuint filterType)
00021 {
00022 this->textureColorType = textureColorType;
00023 this->filterType = filterType;
00024 }
00025
00026 void GLTexture::create(GLuint width, GLuint height)
00027 {
00028 free();
00029
00030 GLenum glError;
00031
00032
00033 GLint cs2DTexture;
00034 glGetIntegerv(GL_TEXTURE_BINDING_2D, &cs2DTexture);
00035
00036 glGenTextures(1, &texture);
00037 glBindTexture(GL_TEXTURE_2D, texture);
00038 if(textureColorType != GL_DEPTH_COMPONENT32)
00039 {
00040 glTexImage2D(GL_TEXTURE_2D, 0, textureColorType, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
00041 }
00042 else
00043 {
00044 glTexImage2D(GL_TEXTURE_2D, 0, textureColorType, width, height, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, 0);
00045 }
00046 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filterType);
00047 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filterType);
00048
00049 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
00050 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
00051
00052 glError = glGetError();
00053 if(glError != GL_NO_ERROR)
00054 {
00055 qDebug() << "create GLTexture error / generate texture: " << (char*)gluErrorString(glError);
00056 }
00057
00058
00059 glBindTexture(GL_TEXTURE_2D, cs2DTexture);
00060
00061 glError = glGetError();
00062 if(glError != GL_NO_ERROR)
00063 {
00064 qDebug() << "create GLTexture error / unbind: " << (char*)gluErrorString(glError);
00065 }
00066 }
00067
00068 void GLTexture::free()
00069 {
00070 if(texture != 0)
00071 {
00072 glDeleteTextures(1, &texture);
00073 texture = 0;
00074
00075 GLenum glError = glGetError();
00076 if(glError != GL_NO_ERROR)
00077 {
00078 qDebug() << "free GLTexture error: " << (char*)gluErrorString(glError);
00079 }
00080 }
00081 }