reference

This documentation is automatically generated from the openFrameworks source code using doxygen and refers to the most recent release, version 0.12.0.

ofTexture.h
Go to the documentation of this file.
1#pragma once
2
4#include "ofConstants.h"
5#include "glm/mat4x4.hpp"
6
7class ofRectangle;
8
9template<typename T>
10class ofPixels_;
11
15
16class ofTexture;
17class ofBufferObject;
18
31
32
33
38bool ofGetUsingArbTex();
39
55void ofEnableArbTex();
56
63void ofDisableArbTex();
64
69
82
86
102OF_DEPRECATED_MSG("Use member method ofTexture::setTextureWrap() instead.",void ofSetTextureWrap(GLfloat wrapS = GL_CLAMP_TO_EDGE, GLfloat wrapT = GL_CLAMP_TO_EDGE));
103
110OF_DEPRECATED_MSG("Use member method ofTexture::setTextureWrap() instead.",bool ofGetUsingCustomTextureWrap());
111
119OF_DEPRECATED_MSG("Use member method ofTexture::setTextureWrap() instead.",void ofRestoreTextureWrap());
120
131OF_DEPRECATED_MSG("Use member method ofTexture::setTextureMinMagFilter() instead.",void ofSetMinMagFilters(GLfloat minFilter = GL_LINEAR, GLfloat magFilter = GL_LINEAR));
132
136OF_DEPRECATED_MSG("Use member method ofTexture::setTextureMinMagFilter() instead.",bool ofGetUsingCustomMinMagFilters());
137
142OF_DEPRECATED_MSG("Use member method ofTexture::setTextureMinMagFilter() instead.",void ofRestoreMinMagFilters());
143
155
156
163public:
165 textureID = 0;
166#ifndef TARGET_OPENGLES
167 glInternalFormat = GL_RGB8;
168 textureTarget = GL_TEXTURE_RECTANGLE_ARB;
169#else
170 glInternalFormat = GL_RGB;
171 textureTarget = GL_TEXTURE_2D;
172#endif
173
174 tex_t = 0;
175 tex_u = 0;
176 tex_w = 0;
177 tex_h = 0;
178 width = 0;
179 height = 0;
180
181 bFlipTexture = false;
183 bAllocated = false;
184 bUseExternalTextureID = false;
185 useTextureMatrix = false;
186
187 minFilter = GL_LINEAR;
188 magFilter = GL_LINEAR;
189
190 wrapModeHorizontal = GL_CLAMP_TO_EDGE;
191 wrapModeVertical = GL_CLAMP_TO_EDGE;
192 hasMipmap = false;
193 bufferId = 0;
194
195 }
196
197 unsigned int textureID;
202
203 float tex_t;
204 float tex_u;
205 float tex_w;
206 float tex_h;
207 float width, height;
208
212
213 GLint minFilter;
214 GLint magFilter;
215
218
219 unsigned int bufferId;
220private:
221 std::shared_ptr<ofTexture> alphaMask;
222 bool bUseExternalTextureID;
223 glm::mat4 textureMatrix;
224 bool useTextureMatrix;
225 bool hasMipmap;
226
227 friend class ofTexture;
228
229};
230
232
239
241
245
250
253class ofTexture : public ofBaseDraws {
254 public :
255
258 ofTexture();
259
262 ofTexture(const ofTexture & mom);
263 ofTexture(ofTexture && mom);
264
272 virtual void allocate(const ofTextureData & textureData);
273
278 virtual void allocate(const ofTextureData & textureData, int glFormat, int pixelType);
279
299 virtual void allocate(int w, int h, int glInternalFormat);
300
309 virtual void allocate(int w, int h, int glInternalFormat, int glFormat, int pixelType);
310
324 virtual void allocate(int w, int h, int glInternalFormat, bool bUseARBExtension);
325
335 virtual void allocate(int w, int h, int glInternalFormat, bool bUseARBExtension, int glFormat, int pixelType);
336
339
345 virtual void allocate(const ofPixels& pix);
346
357 virtual void allocate(const ofPixels& pix, bool bUseARBExtension);
358
365 virtual void allocate(const ofShortPixels& pix);
366
374 virtual void allocate(const ofShortPixels& pix, bool bUseARBExtension);
375
382 virtual void allocate(const ofFloatPixels& pix);
383
391 virtual void allocate(const ofFloatPixels& pix, bool bUseARBExtension);
392
393#ifndef TARGET_OPENGLES
408 void allocateAsBufferTexture(const ofBufferObject & buffer, int glInternalFormat);
409#endif
410
411
418 bool isAllocated() const;
419
420
426 OF_DEPRECATED_MSG("Use isAllocated instead",bool bAllocated() const);
427
433 virtual ~ofTexture();
434
438 ofTexture& operator=(const ofTexture & mom);
440
441
449 void clear();
450
460 void setUseExternalTextureID(GLuint externTexID);
461
472 void loadData(const uint8_t* const data, int w, int h, int glFormat);
473
480 void loadData(const uint16_t* data, int w, int h, int glFormat);
481 void loadData(const uint32_t* data, int w, int h, int glFormat);
482
483 void loadData(const int8_t * data, int w, int h, int glFormat);
484 void loadData(const int16_t * data, int w, int h, int glFormat);
485 void loadData(const int32_t * data, int w, int h, int glFormat);
486
493 void loadData(const float* data, int w, int h, int glFormat);
494
497 void loadData(const ofPixels & pix);
498
505 void loadData(const ofShortPixels & pix);
506
513 void loadData(const ofFloatPixels & pix);
514
523 void loadData(const ofPixels & pix, int glFormat);
524
530 void loadData(const ofShortPixels & pix, int glFormat);
531
537 void loadData(const ofFloatPixels & pix, int glFormat);
538
550 void loadData(const void * data, int w, int h, int glFormat, int glType);
551
552#ifndef TARGET_OPENGLES
565 void loadData(const ofBufferObject & buffer, int glFormat, int glType);
566#endif
567
582 void loadScreenData(int x, int y, int w, int h);
583
584 using ofBaseDraws::draw;
585
587 void draw(float x, float y) const;
588 void draw(float x, float y, float z) const;
589 void draw(const glm::vec3 & pos) const;
590
591 void draw(float x, float y, float w, float h) const;
592
600 void draw(float x, float y, float z, float w, float h) const;
601 void draw(const glm::vec3 & pos, float w, float h) const;
602
609 void draw(const glm::vec3 & p1, const glm::vec3 & p2, const glm::vec3 & p3, const glm::vec3 & p4) const;
610
626 void drawSubsection(float x, float y, float w, float h, float sx, float sy) const;
627
638 void drawSubsection(float x, float y, float z, float w, float h, float sx, float sy) const;
639
651 void drawSubsection(float x, float y, float w, float h, float sx, float sy, float sw, float sh) const;
652
658 void drawSubsection(const ofRectangle& drawBounds, const ofRectangle& subsectionBounds) const;
659
672 void drawSubsection(float x, float y, float z, float w, float h, float sx, float sy, float sw, float sh) const;
673
674 ofMesh getQuad(const glm::vec3 & p1, const glm::vec3 & p2, const glm::vec3 & p3, const glm::vec3 & p4) const;
675
690 ofMesh getMeshForSubsection(float x, float y, float z, float w, float h, float sx, float sy, float sw, float sh, bool vflipped, ofRectMode rectMode) const;
691
698 void bind(int textureLocation=0) const;
699
707 void unbind(int textureLocation=0) const;
708
709#if !defined(TARGET_OPENGLES) && defined(glBindImageTexture)
715 void bindAsImage(GLuint unit, GLenum access, GLint level=0, GLboolean layered=0, GLint layer=0);
716#endif
717
718 const ofTexture * getAlphaMask() const;
719
728 float getHeight() const;
729
737 float getWidth() const;
738
746 void setAnchorPercent(float xPct, float yPct);
747
755 void setAnchorPoint(float x, float y);
756
758 void resetAnchor();
759
764 glm::vec2 getCoordFromPoint(float xPos, float yPos) const;
765
770 glm::vec2 getCoordFromPercent(float xPts, float yPts) const;
771
775 void setAlphaMask(ofTexture & mask);
776
778 void disableAlphaMask();
779
793 void setTextureWrap(GLint wrapModeHorizontal, GLint wrapModeVertical);
794
806 void setTextureMinMagFilter(GLint minFilter, GLint magFilter);
807
810 void setTextureMatrix(const glm::mat4 & m);
811
812 const glm::mat4 & getTextureMatrix() const;
813
814 bool isUsingTextureMatrix() const;
815
819
824 void setCompression(ofTexCompression compression);
825
833 void setRGToRGBASwizzles(bool rToRGBSwizzles);
834
848 void setSwizzle(GLenum srcSwizzle, GLenum dstChannel);
849
856 void readToPixels(ofPixels & pixels) const;
857
863 void readToPixels(ofShortPixels & pixels) const;
864
870 void readToPixels(ofFloatPixels & pixels) const;
871
872#ifndef TARGET_OPENGLES
875 void copyTo(ofBufferObject & buffer) const;
876#endif
877
887
890 const ofTextureData& getTextureData() const;
891
904 void enableMipmap();
905
917 void disableMipmap();
918
919
929 void generateMipmap();
930
935 bool hasMipmap() const;
936
940
941protected:
942
945 void enableTextureTarget(int textureLocation) const;
946
949 void disableTextureTarget(int textureLocation) const;
950
951 glm::vec3 anchor;
952
955
956private:
957 bool bWantsMipmap;
958
959};
Definition ofGraphicsBaseTypes.h:139
virtual void draw(float x, float y) const
Draw at a position at the native size.
Definition ofGraphicsBaseTypes.h:150
Definition ofBufferObject.h:8
A class representing a collection of pixels.
Definition ofPixels.h:170
A class representing a 2D rectangle.
Definition ofRectangle.h:87
Internal texture data structure.
Definition ofTexture.h:162
bool bFlipTexture
Should the texture be flipped vertically?
Definition ofTexture.h:209
float tex_h
Texture height (in pixels).
Definition ofTexture.h:206
GLint wrapModeHorizontal
How will the texture wrap around horizontally?
Definition ofTexture.h:216
float height
Texture display size.
Definition ofTexture.h:207
float tex_w
Texture width (in pixels).
Definition ofTexture.h:205
int textureTarget
Definition ofTexture.h:198
GLint wrapModeVertical
How will the texture wrap around vertically?
Definition ofTexture.h:217
bool bAllocated
Has the texture been allocated?
Definition ofTexture.h:211
GLint magFilter
Filter to use for magnification (enlargement).
Definition ofTexture.h:214
ofTexCompression compressionType
Texture compression type.
Definition ofTexture.h:210
int glInternalFormat
Definition ofTexture.h:200
float width
Definition ofTexture.h:207
float tex_u
Texture vertical coordinate, ratio of height to display height.
Definition ofTexture.h:204
GLint minFilter
Filter to use for minification (reduction).
Definition ofTexture.h:213
unsigned int textureID
GL internal texture ID.
Definition ofTexture.h:197
unsigned int bufferId
Optionally if the texture is backed by a buffer so we can bind it.
Definition ofTexture.h:219
float tex_t
Texture horizontal coordinate, ratio of width to display width.
Definition ofTexture.h:203
ofTextureData()
Definition ofTexture.h:164
A wrapper class for an OpenGL texture.
Definition ofTexture.h:253
void drawSubsection(float x, float y, float w, float h, float sx, float sy) const
Draw a subsection of the texture.
Definition ofTexture.cpp:1050
void disableMipmap()
Sets flag disallowing texture to auto-generate mipmap.
Definition ofTexture.cpp:1010
void loadScreenData(int x, int y, int w, int h)
Copy an area of the screen into this texture.
Definition ofTexture.cpp:761
float getWidth() const
Display width of texture.
Definition ofTexture.cpp:1269
ofTexture & operator=(const ofTexture &mom)
Copy a given ofTexture into this texture.
Definition ofTexture.cpp:218
glm::vec3 anchor
The texture's anchor point.
Definition ofTexture.h:951
void disableTextureTarget(int textureLocation) const
Disable a texture target.
bool hasMipmap() const
Find out if a mipmap has been generated for the current texture.
Definition ofTexture.cpp:1016
bool isUsingTextureMatrix() const
Definition ofTexture.cpp:925
OF_DEPRECATED_MSG("Use isAllocated instead", bool bAllocated() const)
Has the texture been allocated?
void setAnchorPoint(float x, float y)
Set the anchor point the texture is drawn around in pixels.
Definition ofTexture.cpp:816
void copyTo(ofBufferObject &buffer) const
Copy the texture to an ofBufferObject.
Definition ofTexture.cpp:1252
const glm::mat4 & getTextureMatrix() const
Definition ofTexture.cpp:920
virtual void allocate(const ofTextureData &textureData)
Allocate the texture using the given settings.
Definition ofTexture.cpp:408
void clear()
Clears the texture.
Definition ofTexture.cpp:289
void setUseExternalTextureID(GLuint externTexID)
Set the texture ID.
Definition ofTexture.cpp:299
void setCompression(ofTexCompression compression)
Set the texture compression.
Definition ofTexture.cpp:999
ofTextureData texData
Definition ofTexture.h:938
void enableMipmap()
Sets flag allowing texture to auto-generate a mipmap.
Definition ofTexture.cpp:1004
const ofTexture * getAlphaMask() const
Definition ofTexture.cpp:856
void allocateAsBufferTexture(const ofBufferObject &buffer, int glInternalFormat)
Allocate texture as a Buffer Texture.
Definition ofTexture.cpp:378
void setAnchorPercent(float xPct, float yPct)
Set the anchor point the texture is drawn around as a percentage.
Definition ofTexture.cpp:808
void setRGToRGBASwizzles(bool rToRGBSwizzles)
Swizzle RGBA to grayscale with alpha in the red channel.
Definition ofTexture.cpp:486
void disableTextureMatrix()
Disable the texture matrix.
Definition ofTexture.cpp:913
void setTextureMinMagFilter(GLint minFilter, GLint magFilter)
Set texture minification/magnification scaling filters.
Definition ofTexture.cpp:965
glm::vec2 getCoordFromPercent(float xPts, float yPts) const
Helper to convert display coordinate to texture coordinate.
Definition ofTexture.cpp:930
void bind(int textureLocation=0) const
Bind the texture.
Definition ofTexture.cpp:830
void generateMipmap()
Generate mipmap for the current texture.
Definition ofTexture.cpp:694
void setTextureMatrix(const glm::mat4 &m)
Sets a texture matrix to be uploaded whenever the texture is bound.
Definition ofTexture.cpp:906
float getHeight() const
Display height of texture.
Definition ofTexture.cpp:1264
void disableAlphaMask()
Disable the alpha mask.
Definition ofTexture.cpp:861
virtual ~ofTexture()
Destroy an ofTexture instance.
Definition ofTexture.cpp:279
void draw(float x, float y) const
Definition ofTexture.cpp:1021
bool isAllocated() const
Determine whether the texture has been allocated.
Definition ofTexture.cpp:256
void setAlphaMask(ofTexture &mask)
Set another ofTexture to use as an alpha mask.
Definition ofTexture.cpp:847
glm::vec2 getCoordFromPoint(float xPos, float yPos) const
Helper to convert display coordinate to texture coordinate.
Definition ofTexture.cpp:869
bool bAnchorIsPct
Definition ofTexture.h:953
ofTextureData & getTextureData()
Internal texture data access.
Definition ofTexture.cpp:262
void resetAnchor()
Reset the anchor point to (0, 0).
Definition ofTexture.cpp:824
void setSwizzle(GLenum srcSwizzle, GLenum dstChannel)
Swizzle a channel to another.
Definition ofTexture.cpp:536
void readToPixels(ofPixels &pixels) const
Read current texture data from the GPU into pixels.
Definition ofTexture.cpp:1219
void setTextureWrap(GLint wrapModeHorizontal, GLint wrapModeVertical)
Set texture wrapping.
Definition ofTexture.cpp:955
ofMesh getQuad(const glm::vec3 &p1, const glm::vec3 &p2, const glm::vec3 &p3, const glm::vec3 &p4) const
Definition ofTexture.cpp:1179
void loadData(const uint8_t *const data, int w, int h, int glFormat)
Load byte pixel data.
Definition ofTexture.cpp:545
ofTexture()
Construct an ofTexture instance.
Definition ofTexture.cpp:188
void enableTextureTarget(int textureLocation) const
Enable a texture target.
void unbind(int textureLocation=0) const
Unbind the texture.
Definition ofTexture.cpp:835
ofMesh getMeshForSubsection(float x, float y, float z, float w, float h, float sx, float sy, float sw, float sh, bool vflipped, ofRectMode rectMode) const
Get a mesh that has the texture coordinates set.
Definition ofTexture.cpp:1079
#define OF_DEPRECATED_MSG(message,...)
Definition ofConstants.h:78
ofRectMode
Used to represent the available rectangle drawing modes.
Definition ofGraphicsConstants.h:139
bool ofGetUsingCustomMinMagFilters()
Definition ofTexture.cpp:96
void ofSetTextureWrap(GLfloat wrapS, GLfloat wrapT)
Definition ofTexture.cpp:60
bool ofGetUsingCustomTextureWrap()
Definition ofTexture.cpp:73
void ofRestoreTextureWrap()
Definition ofTexture.cpp:78
void ofSetMinMagFilters(GLfloat minFilter, GLfloat magFilter)
Definition ofTexture.cpp:83
void ofRestoreMinMagFilters()
Definition ofTexture.cpp:101
ofPixels_< float > ofFloatPixels
Definition ofTexture.h:14
void ofDisableTextureEdgeHack()
Disable global texture "edge hack".
Definition ofTexture.cpp:29
ofTexCompression
Texture compression types.
Definition ofTexture.h:150
@ OF_COMPRESS_ARB
ARB compression.
Definition ofTexture.h:153
@ OF_COMPRESS_NONE
No compression.
Definition ofTexture.h:151
@ OF_COMPRESS_SRGB
sRGB compression.
Definition ofTexture.h:152
void ofEnableArbTex()
Use GL_TEXTURE_RECTANGLE textures.
Definition ofTexture.cpp:114
void ofEnableNormalizedTexCoords()
Use normalized (0 - 1) texture coordinates.
Definition ofTexture.cpp:44
ofPixels_< unsigned char > ofPixels
Definition ofTexture.h:12
void ofDisableArbTex()
Use GL_TEXTURE_2D textures.
Definition ofTexture.cpp:119
bool ofGetUsingNormalizedTexCoords()
Check whether OF is using normalized or pixel texture coordinates.
Definition ofTexture.cpp:39
bool ofIsTextureEdgeHackEnabled()
Check whether OF is using the texture "edge hack".
Definition ofTexture.cpp:34
ofPixels_< unsigned short > ofShortPixels
Definition ofTexture.h:13
bool ofGetUsingArbTex()
Check whether OF is using GL_TEXTURE_RECTANGLE rectangular or GL_TEXTURE_2D textures.
Definition ofTexture.cpp:109
void ofDisableNormalizedTexCoords()
Use pixel-based texture coordinates.
Definition ofTexture.cpp:49
void ofEnableTextureEdgeHack()
Enable the global texture "edge hack" to compensate for edge artifacts.
Definition ofTexture.cpp:24