Workspace 6.21.5
|
Encapsulates the state attached to an OpenGL texture.
#include <Rendering/OpenGL/wsgltexture.h>
Inherits QOpenGLFunctions.
Public Types | |
enum | DepthTextureCompareFunction { Never = GL_NEVER , Less = GL_LESS , Equal = GL_EQUAL , LEqual = GL_LEQUAL , Greater = GL_GREATER , NotEqual = GL_NOTEQUAL , GEqual = GL_GEQUAL , Always = GL_ALWAYS } |
enum | DepthTextureCompareMode { CompareRToTexture = GL_COMPARE_R_TO_TEXTURE , None = GL_NONE } |
enum | Filtering { Nearest = GL_NEAREST , Linear = GL_LINEAR , NearestMipmapNearest = GL_NEAREST_MIPMAP_NEAREST , LinearMipmapNearest , NearestMipmapLinear , LinearMipmapLinear } |
enum | Format { Red = GL_RED , Green , Blue , Alpha = GL_ALPHA , Rgb = GL_RGB , Rgba = GL_RGBA , Luminance , LuminanceAlpha , Bgr = GL_BGR , Bgra = GL_BGRA , Depth = GL_DEPTH_COMPONENT , Stencil = GL_STENCIL_INDEX , Rg = GL_RG } |
enum | SlicePlane { XY , XZ , YZ } |
enum | Wrap { Clamp = GL_CLAMP , ClampToBorder = GL_CLAMP_TO_BORDER , ClampToEdge = GL_CLAMP_TO_EDGE , MirroredRepeat = GL_MIRRORED_REPEAT , Repeat = GL_REPEAT } |
Public Member Functions | |
~WSGLTexture () | |
bool | allocate (const ColorArray &data, QOpenGLBuffer::UsagePattern usage, bool generateMipmaps=false) |
bool | allocate (const DataAnalysis::Image3d &data, Format format, QOpenGLBuffer::UsagePattern usage, bool generateMipmaps=false) |
bool | allocate (const QImage &data, QOpenGLBuffer::UsagePattern usage, bool generateMipmaps=false) |
bool | allocate (const TextureImage &image) |
bool | allocate (int width, int height, Format format, GLuint internalFormat, GLuint componentDataType, QOpenGLBuffer::UsagePattern usage, bool generateMipmaps=false) |
bool | allocate (int width, int height, Format format, GLuint internalFormat, GLuint componentDataType, QOpenGLBuffer::UsagePattern usage, void *data, GLsizeiptr dataSize, bool generateMipmaps=false) |
bool | allocateSlice (const DataAnalysis::Image3d &data, QOpenGLBuffer::UsagePattern usage, SlicePlane plane, int sliceNum, int sampleDist=1, bool generateMipmaps=false) |
bool | bind () |
WSGLBufferObjectCacheItemPtr | getBuffer () |
GLuint | getGlId () const |
void | notifyBufferUpdated (int width, int height, int depth, Format format, GLuint internalFormat, GLuint componentDataType, bool generateMipmaps=false) |
bool | release () |
void | setDepthTextureCompare (DepthTextureCompareMode compareMode, DepthTextureCompareFunction compareFunction, GLuint depthTextureMode) |
void | setFiltering (bool interpolate) |
void | setFiltering (Filtering minFilter, Filtering magFilter) |
void | setMipmapLevels (int minLevel, int maxLevel) |
void | setWrap (Texturizer::Wrapping wrap) |
void | setWrap (Wrap wrapS) |
void | setWrap (Wrap wrapS, Wrap wrapT) |
void | setWrap (Wrap wrapS, Wrap wrapT, Wrap wrapR) |
bool | updateTexture (const QImage &data, bool generateMipmaps=false) |
Protected Member Functions | |
WSGLTexture (WSGLBufferObjectCache &boCache) | |
enum Filtering |
enum Format |
enum SlicePlane |
enum Wrap |
~WSGLTexture | ( | ) |
|
protected |
Creates a new WSGLTexture, generating an OpenGL texture object for it.
bool allocate | ( | const ColorArray & | data, |
QOpenGLBuffer::UsagePattern | usage, | ||
bool | generateMipmaps = false |
||
) |
data | The data to store in the texture when it is allocated. |
usage | Hint to the GL as to how the texture data is going to be used. |
generateMipmaps | Whether or not to automatically generate and store a mipmap chain with this texture. |
Allocates 1D texture data for our WSGLTexture, using the input color array as the data source. After this function is called, the WSGLTexture will be a 1D texture.
bool allocate | ( | const DataAnalysis::Image3d & | data, |
Format | format, | ||
QOpenGLBuffer::UsagePattern | usage, | ||
bool | generateMipmaps = false |
||
) |
data | The data to store in the texture when it is allocated. |
format | The desired texture format |
usage | Hint to the GL as to how the texture data is going to be used. |
generateMipmaps | Whether or not to automatically generate and store a mipmap chain with this texture. |
Allocates the data for the WSGLTexture, specifying it to be a 3D texture with the input Image3d as data. After this function is called, the WSGLTexture will be a 3D texture.
bool allocate | ( | const QImage & | data, |
QOpenGLBuffer::UsagePattern | usage, | ||
bool | generateMipmaps = false |
||
) |
data | The data to store in the texture when it is allocated. |
usage | Hint to the GL as to how the texture data is going to be used. |
generateMipmaps | Whether or not to automatically generate and store a mipmap chain with this texture. |
Allocates 2D texture data for our WSGLTexture, using the input QImage as the data source. After this function is called, the WSGLTexture will be a 3D texture.
bool allocate | ( | const TextureImage & | image | ) |
image | The texture image to use for data, dimensions and format when allocating the texture. |
Allocates the data associated with the texture in the GL, using the input texture image as a specification of what the format, size and data should be.
bool allocate | ( | int | width, |
int | height, | ||
Format | format, | ||
GLuint | internalFormat, | ||
GLuint | componentDataType, | ||
QOpenGLBuffer::UsagePattern | usage, | ||
bool | generateMipmaps = false |
||
) |
width | The desired width of the texture in texels. |
height | The desired height of the texture in texels. |
format | The desired format of the texture, as it will be used by the GL. |
internalFormat | Specifies the number of color components in the texture. Must be 1, 2, 3, or 4, or one of the following symbolic constants: GL_ALPHA, GL_ALPHA4, GL_ALPHA8, GL_ALPHA12, GL_ALPHA16, GL_COMPRESSED_ALPHA, GL_COMPRESSED_LUMINANCE, GL_COMPRESSED_LUMINANCE_ALPHA, GL_COMPRESSED_INTENSITY, GL_COMPRESSED_RGB, GL_COMPRESSED_RGBA, GL_DEPTH_COMPONENT, GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT24, GL_DEPTH_COMPONENT32, GL_LUMINANCE, GL_LUMINANCE4, GL_LUMINANCE8, GL_LUMINANCE12, GL_LUMINANCE16, GL_LUMINANCE_ALPHA, GL_LUMINANCE4_ALPHA4, GL_LUMINANCE6_ALPHA2, GL_LUMINANCE8_ALPHA8, GL_LUMINANCE12_ALPHA4, GL_LUMINANCE12_ALPHA12, GL_LUMINANCE16_ALPHA16, GL_INTENSITY, GL_INTENSITY4, GL_INTENSITY8, GL_INTENSITY12, GL_INTENSITY16, GL_R3_G3_B2, GL_RGB, GL_RGB4, GL_RGB5, GL_RGB8, GL_RGB10, GL_RGB12, GL_RGB16, GL_RGBA, GL_RGBA2, GL_RGBA4, GL_RGB5_A1, GL_RGBA8, GL_RGB10_A2, GL_RGBA12, GL_RGBA16, GL_SLUMINANCE, GL_SLUMINANCE8, GL_SLUMINANCE_ALPHA, GL_SLUMINANCE8_ALPHA8, GL_SRGB, GL_SRGB8, GL_SRGB_ALPHA, or GL_SRGB8_ALPHA8. |
componentDataType | Specifies the data type of the pixel data, i.e. the format of a single color component. The following symbolic values are accepted: GL_UNSIGNED_BYTE, GL_BYTE, GL_BITMAP, GL_UNSIGNED_SHORT, GL_SHORT, GL_UNSIGNED_INT, GL_INT, GL_FLOAT, GL_UNSIGNED_BYTE_3_3_2, GL_UNSIGNED_BYTE_2_3_3_REV, GL_UNSIGNED_SHORT_5_6_5, GL_UNSIGNED_SHORT_5_6_5_REV, GL_UNSIGNED_SHORT_4_4_4_4, GL_UNSIGNED_SHORT_4_4_4_4_REV, GL_UNSIGNED_SHORT_5_5_5_1, GL_UNSIGNED_SHORT_1_5_5_5_REV, GL_UNSIGNED_INT_8_8_8_8, GL_UNSIGNED_INT_8_8_8_8_REV, GL_UNSIGNED_INT_10_10_10_2, and GL_UNSIGNED_INT_2_10_10_10_REV. |
usage | Hint to the GL as to how the texture data is going to be used. |
generateMipmaps | Whether or not to automatically generate and store a mipmap chain with this texture. |
Allocates the data for the WSGLTexture, specifying it to be a 2D texture with the desired format, internal format, component data type. It also provides facilities for suggesting to the GL how the texture data will be accessed, and generating mipmap data.
After this function is called, the WSGLTexture will be a 2D texture.
bool allocate | ( | int | width, |
int | height, | ||
Format | format, | ||
GLuint | internalFormat, | ||
GLuint | componentDataType, | ||
QOpenGLBuffer::UsagePattern | usage, | ||
void * | data, | ||
GLsizeiptr | dataSize, | ||
bool | generateMipmaps = false |
||
) |
width | The desired width of the texture in texels. |
height | The desired height of the texture in texels. |
format | The desired format of the texture, as it will be used by the GL. |
internalFormat | Specifies the number of color components in the texture. Must be 1, 2, 3, or 4, or one of the following symbolic constants: GL_ALPHA, GL_ALPHA4, GL_ALPHA8, GL_ALPHA12, GL_ALPHA16, GL_COMPRESSED_ALPHA, GL_COMPRESSED_LUMINANCE, GL_COMPRESSED_LUMINANCE_ALPHA, GL_COMPRESSED_INTENSITY, GL_COMPRESSED_RGB, GL_COMPRESSED_RGBA, GL_DEPTH_COMPONENT, GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT24, GL_DEPTH_COMPONENT32, GL_LUMINANCE, GL_LUMINANCE4, GL_LUMINANCE8, GL_LUMINANCE12, GL_LUMINANCE16, GL_LUMINANCE_ALPHA, GL_LUMINANCE4_ALPHA4, GL_LUMINANCE6_ALPHA2, GL_LUMINANCE8_ALPHA8, GL_LUMINANCE12_ALPHA4, GL_LUMINANCE12_ALPHA12, GL_LUMINANCE16_ALPHA16, GL_INTENSITY, GL_INTENSITY4, GL_INTENSITY8, GL_INTENSITY12, GL_INTENSITY16, GL_R3_G3_B2, GL_RGB, GL_RGB4, GL_RGB5, GL_RGB8, GL_RGB10, GL_RGB12, GL_RGB16, GL_RGBA, GL_RGBA2, GL_RGBA4, GL_RGB5_A1, GL_RGBA8, GL_RGB10_A2, GL_RGBA12, GL_RGBA16, GL_SLUMINANCE, GL_SLUMINANCE8, GL_SLUMINANCE_ALPHA, GL_SLUMINANCE8_ALPHA8, GL_SRGB, GL_SRGB8, GL_SRGB_ALPHA, or GL_SRGB8_ALPHA8. |
componentDataType | Specifies the data type of the pixel data, i.e. the format of a single color component. The following symbolic values are accepted: GL_UNSIGNED_BYTE, GL_BYTE, GL_BITMAP, GL_UNSIGNED_SHORT, GL_SHORT, GL_UNSIGNED_INT, GL_INT, GL_FLOAT, GL_UNSIGNED_BYTE_3_3_2, GL_UNSIGNED_BYTE_2_3_3_REV, GL_UNSIGNED_SHORT_5_6_5, GL_UNSIGNED_SHORT_5_6_5_REV, GL_UNSIGNED_SHORT_4_4_4_4, GL_UNSIGNED_SHORT_4_4_4_4_REV, GL_UNSIGNED_SHORT_5_5_5_1, GL_UNSIGNED_SHORT_1_5_5_5_REV, GL_UNSIGNED_INT_8_8_8_8, GL_UNSIGNED_INT_8_8_8_8_REV, GL_UNSIGNED_INT_10_10_10_2, and GL_UNSIGNED_INT_2_10_10_10_REV. |
usage | Hint to the GL as to how the texture data is going to be used. |
data | A pointer to the raw data to upload to the pixel-buffer-object. |
dataSize | The number of bytes of the buffer pointed to by data |
generateMipmaps | Whether or not to automatically generate and store a mipmap chain with this texture. |
Allocates the data for the WSGLTexture, specifying it to be a 2D texture with the desired format, internal format, component data type. It also provides facilities for suggesting to the GL how the texture data will be accessed, and generating mipmap data.
After this function is called, the WSGLTexture will be a 2D texture.
bool allocateSlice | ( | const DataAnalysis::Image3d & | data, |
QOpenGLBuffer::UsagePattern | usage, | ||
SlicePlane | plane, | ||
int | sliceNum, | ||
int | sampleDist = 1 , |
||
bool | generateMipmaps = false |
||
) |
bool bind | ( | ) |
Binds the texture to the current context's active texture unit. Equivalent to glBindTexture(id)
WSGLBufferObjectCacheItemPtr getBuffer | ( | ) |
Returns the BufferObject associated with this texture, i.e. the buffer that its texture data is stored in.
GLuint getGlId | ( | ) | const |
Returns the internal GL identifier for this texture, which can be used to manually bind the texture, or attach it to FBOs etc.
void notifyBufferUpdated | ( | int | width, |
int | height, | ||
int | depth, | ||
WSGLTexture::Format | format, | ||
GLuint | internalFormat, | ||
GLuint | componentDataType, | ||
bool | generateMipMaps = false |
||
) |
width | The width of the texture data stored in the buffer. |
height | The height of the texture data stored in the buffer. Value greater than 1 will indicate a 2D or 3D texture. |
depth | The depth of the texture data stored in the buffer. Value greater than 1 will indicate a 3D texture. |
format | The desired format of the texture. |
internalFormat | The format that the data has been stored inside the buffer |
componentDataType | The data type of individual components of each texel; for example for RGBA, this is often GL_UNSIGNED_BYTE. |
generateMipMaps | If true, mip maps will be generated for the texture. |
If we directly modify the underlying pixel buffer object, we need to notify the texture that it's data has changed, and that it therefore needs to update the OpenGL texture information associated with it.
bool release | ( | ) |
Unbinds the texture from the current context's active texture unit. Equivalent to glBindTexture(0)
void setDepthTextureCompare | ( | WSGLTexture::DepthTextureCompareMode | compareMode, |
WSGLTexture::DepthTextureCompareFunction | compareFunction, | ||
GLuint | depthTextureMode | ||
) |
Indicates that this texture is a depth texture. This means we can use the texture in a shader using shadow2D(), which will perform a depth test for us, and provide us a result in a vector. To understand how this comparison works, see below:
If R is the currently interpolated texture coordinate clamped to [0, 1], and Dt is the depth value at that coordinate in the range [0, 1], then the value Lt, It, At is equal to:
(If compare func == GREATER) result = { 1.0, if R > Dt { { 0.0, if R <= Dt
The result is a vec4 in the shader, just like a normal texture sample, with the depth test result stored in the the location corresponding to our depth mode parameter.
To give an example, in the case of depth peeling, the R texture coordinate will be the pixel z window coord (depth) - see the wsgldepthpeeling.inc. Since pixel depth is in the range [0, 1] (0.0 being the closest to the eye, and 1.0 is the farthest), the results of our test can be summarized as:
void setFiltering | ( | bool | interpolate | ) |
interpolate | Whether or not to "interpolate" the texture, which means to apply linear minification and linear magnification filters. |
void setFiltering | ( | WSGLTexture::Filtering | minFilter, |
WSGLTexture::Filtering | magFilter | ||
) |
minFilter | Controls how the texture is filtered when it is minified. Allowed values are Nearest, Linear, NearestMipmapNearest, LinearMipmapNearest, NearestMipmapLinear, LinearMipmapLinear. |
magFilter | Controls how the texture is filtered when it is magnified. Allowed values are Nearest, Linear. |
Controls how the texture will be filtered when it is magnified or minified. See WSGLTexture::Filtering for more information.
void setMipmapLevels | ( | int | minLevel, |
int | maxLevel | ||
) |
minLevel | The base level of mipmap that can be used when maps are automatically selected. |
maxLevel | The maximum mipmap level that will be used. |
Controls the range of mipmaps available to the application for selection.
void setWrap | ( | Texturizer::Wrapping | wrap | ) |
wrap | The type of wrapping to apply to the S, T (and potentially R) dimensions. |
void setWrap | ( | WSGLTexture::Wrap | wrapS | ) |
wrapS | Controls how the texture will wrap in the S dimension. |
Sets the wrap property of the texture in the S dimension. Can be invoked on 1D, 2D or 3D textures.
void setWrap | ( | WSGLTexture::Wrap | wrapS, |
WSGLTexture::Wrap | wrapT | ||
) |
wrapS | Controls how the texture will wrap in the S dimension. |
wrapT | Controls how the texture will wrap in the T dimension. |
Sets the wrap property of the texture (if it's a 2D or 3D texture only).
void setWrap | ( | WSGLTexture::Wrap | wrapS, |
WSGLTexture::Wrap | wrapT, | ||
WSGLTexture::Wrap | wrapR | ||
) |
wrapS | Controls how the texture will wrap in the S dimension. |
wrapT | Controls how the texture will wrap in the T dimension. |
wrapR | Controls how the texture will wrap in the R dimension. |
Sets the wrap property of the texture (if it's a 3D texture only).
bool updateTexture | ( | const QImage & | data, |
bool | generateMipmaps = false |
||
) |
data | The data to upload to the texture. |
generateMipmaps | Whether or not to generate mipmaps for the updated texture data |
Updates the texture to use the specified image.