30 #include <Eigen/Eigen> 87 glGenTextures(1, &tex_id);
89 texID_sptr = std::shared_ptr < GLuint > (
92 glDeleteTextures(1, p);
122 return Eigen::Vector2i(width, height);
146 GLuint
create (GLenum type, GLenum int_format,
int w,
int h, GLenum fmt, GLenum pix_type,
const GLvoid* data = NULL,
int dpt = 256)
149 internal_format = int_format;
153 pixel_type = pix_type;
158 glBindTexture(tex_type, *texID_sptr);
159 if(tex_type == GL_TEXTURE_2D || tex_type == GL_TEXTURE_RECTANGLE)
161 glTexImage2D(tex_type, lod, internal_format, width, height, 0, format, pixel_type, data);
163 else if(tex_type == GL_TEXTURE_2D_MULTISAMPLE)
165 glTexImage2DMultisample(tex_type, num_samples, internal_format, width, height, GL_TRUE);
167 else if (tex_type == GL_TEXTURE_3D)
169 glTexImage3D(tex_type, lod, internal_format, width, height, depth, 0, format, pixel_type, data);
171 else if (tex_type == GL_TEXTURE_1D)
173 glTexImage1D(tex_type, lod, internal_format, width, 0, format, pixel_type, data);
178 glBindTexture(tex_type, 0);
196 GLuint
create (
int w,
int h,
const GLvoid* data = NULL)
198 return create (GL_TEXTURE_2D, GL_RGBA32F, w, h, GL_RGBA, GL_UNSIGNED_BYTE, data, 0);
221 void setTexParameters (GLenum wraps = GL_CLAMP, GLenum wrapt = GL_CLAMP, GLenum magfilter = GL_NEAREST, GLenum minfilter = GL_NEAREST)
224 if (num_samples == 1)
226 glTexParameteri(tex_type, GL_TEXTURE_WRAP_S, wraps);
227 glTexParameteri(tex_type, GL_TEXTURE_WRAP_T, wrapt);
228 glTexParameteri(tex_type, GL_TEXTURE_MAG_FILTER, magfilter);
229 glTexParameteri(tex_type, GL_TEXTURE_MIN_FILTER, minfilter);
244 void setTexParametersMipMap (
int maxlevel,
int baselevel = 0, GLenum wraps = GL_CLAMP, GLenum wrapt = GL_CLAMP, GLenum magfilter = GL_NEAREST, GLenum minfilter = GL_NEAREST_MIPMAP_NEAREST)
246 glTexParameteri(tex_type, GL_TEXTURE_MIN_FILTER, minfilter);
247 glTexParameteri(tex_type, GL_TEXTURE_MAG_FILTER, magfilter);
248 glTexParameteri(tex_type, GL_TEXTURE_WRAP_S, wraps);
249 glTexParameteri(tex_type, GL_TEXTURE_WRAP_T, wrapt);
250 glTexParameteri(tex_type, GL_TEXTURE_BASE_LEVEL, baselevel );
251 glTexParameteri(tex_type, GL_TEXTURE_MAX_LEVEL, maxlevel );
253 glGenerateMipmap(tex_type);
265 glBindTexture(tex_type, *texID_sptr);
266 if(tex_type == GL_TEXTURE_2D || tex_type == GL_TEXTURE_RECTANGLE) {
267 glTexSubImage2D(tex_type, lod, 0, 0, width, height, format, pixel_type, data);
269 else if (tex_type == GL_TEXTURE_3D) {
270 glTexSubImage3D(tex_type, lod, 0, 0, 0, width, height, depth, format, pixel_type, data);
272 else if (tex_type == GL_TEXTURE_1D) {
273 glTexSubImage1D(tex_type, lod, 0, width, format, pixel_type, data);
275 glBindTexture(tex_type,0);
288 texManager.bindTexture(tex_type, *texID_sptr, texture_unit);
298 unit =
texManager.bindTexture(tex_type, *texID_sptr);
311 unit =
texManager.bindTexture(tex_type, *texID_sptr);
314 glBindImageTexture(unit, *texID_sptr, 0,
false, 0, GL_READ_WRITE, internal_format);
329 texManager.bindTexture(tex_type, *texID_sptr, texture_unit);
330 glBindImageTexture(texture_unit, *texID_sptr, 0,
false, 0, GL_READ_WRITE, internal_format);
341 unit =
texManager.bindTexture(tex_type, *texID_sptr);
345 glBindImageTexture(unit, *texID_sptr, 0,
false, 0, GL_READ_WRITE, fmt);
360 texManager.bindTexture(tex_type, *texID_sptr, texture_unit);
361 glBindImageTexture(texture_unit, *texID_sptr, 0,
false, 0, GL_READ_WRITE, fmt);
369 texManager.unbindTextureID(tex_type, *texID_sptr);
GLenum pixel_type
Type of pixel channel (ex. GL_FLOAT, GL_UNSIGNED_BYTE ...).
Definition: texture.hpp:66
GLenum internal_format
Internal format (ex. GL_RGBA, GL_RGBA32F ...).
Definition: texture.hpp:51
int bind(void)
Binds the texture to the first free texture unit and returns the unit used. Gets the first free unit ...
Definition: texture.hpp:296
Definition: bufferobject.hpp:34
#define texManager
Defines our unique instance of this singleton class.
Definition: texturemanager.hpp:5
void bind(int texture_unit)
Binds the texture to a given unit. Note that if there is another texture already binded to this unit...
Definition: texture.hpp:285
void setTexParameters(GLenum wraps=GL_CLAMP, GLenum wrapt=GL_CLAMP, GLenum magfilter=GL_NEAREST, GLenum minfilter=GL_NEAREST)
Deletes the texture.
Definition: texture.hpp:221
GLuint create(int w, int h, const GLvoid *data=NULL)
Creates a texture object with typical default parameters and returns its handler. ...
Definition: texture.hpp:196
int width
Width in pixels.
Definition: texture.hpp:54
int height
Height in pixels.
Definition: texture.hpp:57
int unit
Texture unit this texture is occupying (if any).
Definition: texture.hpp:72
int getWidth(void)
Returns the texture width.
Definition: texture.hpp:102
void errorCheckFunc(std::string file, int line, std::string message="")
GL error check method.
Definition: misc.hpp:53
int bindImageFormatRW(GLenum fmt)
Binds the texture as an image texture with a given format. Binds with READ and WRITE access with a gi...
Definition: texture.hpp:339
GLuint tex_id
ID handler to texture.
Definition: texture.hpp:45
int textureUnit(void) const
Returns the texture unit this texture is bound to.
Definition: texture.hpp:386
void bindImageRW(int texture_unit)
Binds the texture as an image texture to a given unit. Image textures are used for example for atomic...
Definition: texture.hpp:326
std::shared_ptr< GLuint > texID_sptr
shared pointer for maintaing texture id
Definition: texture.hpp:78
void bindImageFormatRW(int texture_unit, GLenum fmt)
Binds the texture as an image texture to a given texture unit with a given internal format...
Definition: texture.hpp:357
Eigen::Vector2i getDimensions(void)
Returns the texture dimensions.
Definition: texture.hpp:120
void setTexParametersMipMap(int maxlevel, int baselevel=0, GLenum wraps=GL_CLAMP, GLenum wrapt=GL_CLAMP, GLenum magfilter=GL_NEAREST, GLenum minfilter=GL_NEAREST_MIPMAP_NEAREST)
Sets texture parameters. Sets the Wrap S and T, Min and Mag filter, and MipMap parameters. Also generates the MipMap at the end.
Definition: texture.hpp:244
GLenum tex_type
Type of texture (ex. GL_TEXTURE_2D, GL_TEXTURE_3D ...).
Definition: texture.hpp:48
Texture(void)
Default Constructor.
Definition: texture.hpp:85
int getHeight(void)
Returns the texture height.
Definition: texture.hpp:111
int depth
Depth in pixels (for 3D texture).
Definition: texture.hpp:60
GLuint texID(void) const
Returns the texture handle (texture ID).
Definition: texture.hpp:377
An OpenGL texture. It can be a simple texture or an FBO texture.
Definition: texture.hpp:41
int bindImageRW(void)
Binds the texture as an image texture. Image textures are used for example for atomic counters...
Definition: texture.hpp:309
void update(const GLvoid *data)
Updates the data of the texture mantaining all other parameters.
Definition: texture.hpp:263
GLuint create(GLenum type, GLenum int_format, int w, int h, GLenum fmt, GLenum pix_type, const GLvoid *data=NULL, int dpt=256)
Creates a texture object and returns its handler.
Definition: texture.hpp:146
int lod
Number of lod levels (1 for textures without lod).
Definition: texture.hpp:69
void unbind(void)
Unbinds this texture and frees the texture unit.
Definition: texture.hpp:367
GLenum format
Format of texture channels (ex. GL_RGBA).
Definition: texture.hpp:63
void setNumSamples(int num)
Sets the number of samples for multisampling.
Definition: texture.hpp:129