1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
|
/****************************************************************************
* Render Radiance Scaling *
* Meshlab's plugin *
* *
* Copyright(C) 2010 *
* Vergne Romain, Dumas Olivier *
* INRIA - Institut Nationnal de Recherche en Informatique et Automatique *
* *
* All rights reserved. *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt) *
* for more details. *
* *
****************************************************************************/
#ifndef TEXTURE_2D_H
#define TEXTURE_2D_H
#include <GL/glew.h>
#include <string>
#include "textureFormat.h"
#include "textureParams.h"
template<typename T = float>
class Texture2D {
public:
Texture2D(const TextureFormat &tf=TextureFormat(),
const TextureParams &tp=TextureParams(),
T* map=NULL,
int id=-1);
Texture2D(const Texture2D &tex);
~Texture2D();
inline GLuint id () const;
inline TextureFormat format() const;
inline TextureParams params() const;
inline void bind () const;
protected:
GLuint _id;
TextureFormat _format;
TextureParams _params;
};
template<typename T>
inline GLuint Texture2D<T>::id() const {
return _id;
}
template<typename T>
inline TextureFormat Texture2D<T>::format() const {
return _format;
}
template<typename T>
inline TextureParams Texture2D<T>::params() const {
return _params;
}
template<typename T>
inline void Texture2D<T>::bind() const {
glBindTexture(_format.target(),_id);
}
template<typename T>
Texture2D<T>::Texture2D(const Texture2D<T> &tex)
: _id(tex.id()),
_format(tex.format()),
_params(tex.params()) {
}
template<typename T>
Texture2D<T>::Texture2D(const TextureFormat &tf,const TextureParams &tp,T* map,int id)
: _id(id),
_format(tf),
_params(tp) {
assert(_format.target()==GL_TEXTURE_2D);
glEnable(GL_TEXTURE_2D);
if(id<0 || glIsTexture(id)==GL_FALSE) {
glGenTextures(1,&_id);
} else {
_id = id;
}
glBindTexture(_format.target(),_id);
if(_format.mipmapmode()==TextureFormat::MIPMAP_GLU_AUTOM) {
gluBuild2DMipmaps(_format.target(),
_format.internalformat(),
_format.width(),
_format.height(),
_format.format(),
_format.type(),
(const GLvoid *)map);
} else {
glTexImage2D(_format.target(),
_format.level(),
_format.internalformat(),
_format.width(),
_format.height(),
_format.border(),
_format.format(),
_format.type(),
(const GLvoid *)map);
if(_format.mipmapmode()==TextureFormat::MIPMAP_FBO_AUTOM) {
assert(map==NULL || map==0);
glGenerateMipmapEXT(_format.target());
}
}
glTexParameteri(_format.target(),GL_TEXTURE_MIN_FILTER,_params.minfilter());
glTexParameteri(_format.target(),GL_TEXTURE_MAG_FILTER,_params.maxfilter());
glTexParameteri(_format.target(),GL_TEXTURE_WRAP_S,_params.wraps());
glTexParameteri(_format.target(),GL_TEXTURE_WRAP_T,_params.wrapt());
//glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,_params.mode());
}
template<typename T>
Texture2D<T>::~Texture2D() {
glDeleteTextures(1,&_id);
}
typedef Texture2D<float> FloatTexture2D;
typedef Texture2D<unsigned char> UbyteTexture2D;
typedef Texture2D<unsigned int> UintTexture2D;
#endif // TEXTURE_2D_H
|