SLProject 4.0.000
|
Texture object for OpenGL texturing. More...
#include <SLGLTexture.h>
Public Member Functions | |
SLGLTexture () | |
Default ctor for all stack instances (not created with new) More... | |
SLGLTexture (SLAssetManager *assetMgr, const SLVCol4f &colors, SLint min_filter=GL_LINEAR, SLint mag_filter=GL_LINEAR, SLint wrapS=GL_REPEAT, const SLstring &name="2D-Texture") | |
ctor for 1D texture with internal image allocation More... | |
SLGLTexture (SLAssetManager *assetMgr, SLint min_filter, SLint mag_filter, SLint wrapS, SLint wrapT, SLenum target=GL_TEXTURE_2D) | |
ctor for empty 2D textures More... | |
SLGLTexture (SLAssetManager *assetMgr, unsigned char *data, int width, int height, int cvtype, SLint min_filter, SLint mag_filter, SLTextureType type, SLint wrapS, SLint wrapT) | |
ctor for 2D textures from byte pointer More... | |
SLGLTexture (SLAssetManager *assetMgr, const SLstring &imageFilename, SLint min_filter=GL_LINEAR_MIPMAP_LINEAR, SLint mag_filter=GL_LINEAR, SLTextureType type=TT_unknown, SLint wrapS=GL_REPEAT, SLint wrapT=GL_REPEAT) | |
ctor for 2D textures with internal image allocation More... | |
SLGLTexture (SLAssetManager *assetMgr, const SLVstring &imageFilenames, SLint min_filter=GL_LINEAR, SLint mag_filter=GL_LINEAR, SLint wrapS=GL_REPEAT, SLint wrapT=GL_REPEAT, const SLstring &name="3D-Texture", SLbool loadGrayscaleIntoAlpha=false) | |
ctor for 3D texture with internal image allocation More... | |
SLGLTexture (SLAssetManager *assetMgr, SLint depth, const SLstring &imageFilename, SLint min_filter=GL_LINEAR, SLint mag_filter=GL_LINEAR, SLint wrapS=GL_REPEAT, SLint wrapT=GL_REPEAT, const SLstring &name="3D-Texture", SLbool loadGrayscaleIntoAlpha=false) | |
ctor for 3D texture from a single file with depth as 3rd dimension More... | |
SLGLTexture (SLAssetManager *assetMgr, const SLstring &imageFilenameXPos, const SLstring &imageFilenameXNeg, const SLstring &imageFilenameYPos, const SLstring &imageFilenameYNeg, const SLstring &imageFilenameZPos, const SLstring &imageFilenameZNeg, SLint min_filter=GL_LINEAR, SLint mag_filter=GL_LINEAR, SLTextureType type=TT_unknown) | |
ctor for cube mapping with internal image allocation More... | |
~SLGLTexture () override | |
virtual void | build (SLint texUnit) |
void | deleteData () |
Delete all data (CVImages and GPU textures) More... | |
void | deleteDataGpu () |
Deletes the OpenGL texture objects and releases the memory on the GPU. More... | |
void | deleteImages () |
Deletes the CVImages in _images. No more texture mapping in ray tracing. More... | |
void | bindActive (SLuint texUnit=0) |
void | fullUpdate () |
void | drawSprite (SLbool doUpdate, SLfloat x, SLfloat y, SLfloat w, SLfloat h) |
Draws the texture as 2D sprite with OpenGL buffers. More... | |
void | cubeUV2XYZ (SLint index, SLfloat u, SLfloat v, SLfloat &x, SLfloat &y, SLfloat &z) |
Computes the unnormalised vector x,y,z from tex. coords. uv with cubemap index. More... | |
void | cubeXYZ2UV (SLfloat x, SLfloat y, SLfloat z, SLint &index, SLfloat &u, SLfloat &v) |
Computes the uv and cubemap image index from a unnormalised vector x,y,z. More... | |
SLstring | filterString (SLint glFilter) |
Returns OpenGL texture filter as string. More... | |
void | texType (SLTextureType bt) |
void | uvIndex (SLbyte i) |
void | bumpScale (SLfloat bs) |
void | minFiler (SLint minF) |
void | magFiler (SLint magF) |
void | needsUpdate (SLbool update) |
void | textureSize (int width, int height) |
void | deleteImageAfterBuild (SLbool delImg) |
If deleteImageAfterBuild is set to true you won't be able to ray trace the scene. More... | |
SLuint | width () |
SLuint | height () |
SLuint | depth () |
SLbyte | uvIndex () |
SLint | bytesPerPixel () |
SLint | bytesOnGPU () |
SLint | bytesInFile () |
CVVImage & | images () |
SLenum | target () const |
SLuint | texID () const |
SLTextureType | texType () |
SLfloat | bumpScale () const |
SLCol4f | getTexelf (SLfloat u, SLfloat v, SLuint imgIndex=0) |
SLGLTexture::getTexelf returns a pixel color from u & v texture coordinates. More... | |
SLCol4f | getTexelf (const SLVec3f &cubemapDir) |
SLGLTexture::getTexelf returns a pixel color at the specified cubemap direction. More... | |
SLbool | hasAlpha () |
SLMat4f | tm () |
SLbool | autoCalcTM3D () const |
SLbool | needsUpdate () |
SLstring | typeName () |
Returns the texture type as string. More... | |
SLstring | typeShortName () |
Returns the texture type short. More... | |
bool | isTexture () |
SLstring | minificationFilterName () |
SLstring | magnificationFilterName () |
void | build2DMipmaps (SLint target, SLuint index) |
SLbool | copyVideoImage (SLint camWidth, SLint camHeight, CVPixelFormatGL glFormat, SLuchar *data, SLbool isContinuous, SLbool isTopLeft) |
Copies the image data from a video camera into the current video image. More... | |
SLbool | copyVideoImage (SLint camWidth, SLint camHeight, CVPixelFormatGL srcFormat, CVPixelFormatGL dstFormat, SLuchar *data, SLbool isContinuous, SLbool isTopLeft) |
void | calc3DGradients (SLint sampleRadius, const function< void(int)> &onUpdateProgress) |
void | smooth3DGradients (SLint smoothRadius, function< void(int)> onUpdateProgress) |
SLVec2f | dudv (SLfloat u, SLfloat v) |
Public Member Functions inherited from SLObject | |
SLObject (const SLstring &Name="", const SLstring &url="") | |
virtual | ~SLObject () |
void | name (const SLstring &Name) |
void | url (const SLstring &url) |
const SLstring & | name () const |
const SLstring & | url () const |
Static Public Member Functions | |
static SLTextureType | detectType (const SLstring &filename) |
Detects the texture type from the filename appendix (See SLTexType def.) More... | |
static string | internalFormatStr (int internalFormat) |
Returns the internal pixel format from OpenGL. More... | |
Static Public Attributes | |
static SLfloat | maxAnisotropy = -1.0f |
Returns the derivation as [s,t]. More... | |
static SLuint | totalNumBytesOnGPU = 0 |
Total NO. of bytes used for textures on GPU. More... | |
Protected Member Functions | |
void | load (const SLstring &filename, SLbool flipVertical=true, SLbool loadGrayscaleIntoAlpha=false) |
Loads the texture, converts color depth & applies vertical mirroring. More... | |
void | load (const SLVCol4f &colors) |
Loads the 1D color data into an image of height 1. More... | |
Protected Attributes | |
CVVImage | _images |
Vector of CVImage pointers. More... | |
SLuint | _texID |
OpenGL texture ID. More... | |
SLTextureType | _texType |
See SLTextureType. More... | |
SLint | _width |
Texture image width in pixels (images exist either in _images or on the GPU or on both) More... | |
SLint | _height |
Texture image height in pixels (images exist either in _images or on the GPU or on both) More... | |
SLint | _depth |
3D Texture image depth (images exist either in _images or on the GPU or on both) More... | |
SLbyte | _uvIndex |
Texture coordinate index in SLMesh (0 = default) More... | |
SLint | _internalFormat |
Internal OpenGL format. More... | |
SLint | _bytesPerPixel |
Bytes per texture image pixel (images exist either in _images or on the GPU or on both) More... | |
SLint | _min_filter |
Minification filter. More... | |
SLint | _mag_filter |
Magnification filter. More... | |
SLint | _wrap_s |
Wrapping in s direction. More... | |
SLint | _wrap_t |
Wrapping in t direction. More... | |
SLenum | _target |
texture target More... | |
SLMat4f | _tm |
texture matrix More... | |
SLuint | _bytesOnGPU |
NO. of bytes on GPU. More... | |
SLuint | _bytesInFile |
NO. of bytes in file. More... | |
SLbool | _autoCalcTM3D |
Flag if texture matrix should be calculated from AABB for 3D mapping. More... | |
SLfloat | _bumpScale |
Bump mapping scale factor. More... | |
SLbool | _resizeToPow2 |
Flag if image should be resized to n^2. More... | |
SLGLVertexArray | _vaoSprite |
Vertex array object for sprite rendering. More... | |
std::atomic< bool > | _needsUpdate {} |
Flag if image needs an single update. More... | |
std::mutex | _mutex |
Mutex to protect parallel access (used in ray tracing) More... | |
SLbool | _deleteImageAfterBuild |
Flag if images should be deleted after build on GPU. More... | |
SLbool | _compressedTexture = false |
True for compressed texture format on GPU. More... | |
Protected Attributes inherited from SLObject | |
SLstring | _name |
name of an object More... | |
SLstring | _url |
uniform resource locator More... | |
Texture object for OpenGL texturing.
The SLGLTexture class implements an OpenGL texture object that can be used by the SLMaterial class. A texture can have 1-n CVImages in the vector _images. A simple 2D texture has just a single texture image (_images[0]). For cube maps you will need 6 images (_images[0-5]). For 3D textures you can have as much images of the same size than your GPU and/or CPU memory can hold. The images are not released after the OpenGL texture creation unless you set the flag _deleteImageAfterBuild to true. If the images get deleted after build, you won't be able to ray trace the scene.
SLGLTexture::SLGLTexture | ( | ) |
Default ctor for all stack instances (not created with new)
Default ctor for all stack instances such as the video textures in SLScene or the textures inherited by SLRaytracer. All other constructors add the this pointer to the SLScene::_texture vector for global deallocation.
|
explicit |
ctor for 1D texture with internal image allocation
Constructor for 1D texture from a color vector. Textures can be used in multiple materials. Textures can belong therefore to the global assets such as meshes (SLMesh), materials (SLMaterial), textures (SLGLTexture) and shader programs (SLGLProgram).
assetMgr | Pointer to a global asset manager. If passed the asset manager is the owner of the instance and will do the deallocation. If a nullptr is passed the creator is responsible for the deallocation. |
colors | Vector of colors |
min_filter | Minification filter constant from OpenGL |
mag_filter | Magnification filter constant from OpenGL |
wrapS | Texture wrapping in S direction (OpenGL constant) |
name | Name of the 1D texture |
|
explicit |
ctor for empty 2D textures
Constructor for empty 2D textures. Textures can be used in multiple materials. Textures can belong therefore to the global assets such as meshes (SLMesh), materials (SLMaterial), textures (SLGLTexture) and shader programs (SLGLProgram).
assetMgr | Pointer to a global asset manager. If passed the asset manager is the owner of the instance and will do the deallocation. If a nullptr is passed the creator is responsible for the deallocation. |
min_filter | Minification filter constant from OpenGL |
mag_filter | Magnification filter constant from OpenGL |
wrapS | Texture wrapping in S direction (OpenGL constant) |
wrapT | Texture wrapping in T direction (OpenGL constant) |
target | Texture target GL_TEXTURE_1D, 2D, 3D |
|
explicit |
ctor for 2D textures from byte pointer
Constructor for 2D texture with a passed image data pointer. Textures can be used in multiple materials. Textures can belong therefore to the global assets such as meshes (SLMesh), materials (SLMaterial), textures (SLGLTexture) and shader programs (SLGLProgram).
assetMgr | Pointer to a global asset manager. If passed the asset manager is the owner of the instance and will do the deallocation. If a nullptr is passed the creator is responsible for the deallocation. |
data | Data pointer to the first top-left pixel |
width | Width of the image in pixels |
height | Height of the image in pixels |
cvtype | OpenCV image type |
min_filter | Minification filter constant from OpenGL |
mag_filter | Magnification filter constant from OpenGL |
type | Type of the texture |
wrapS | Texture wrapping in S direction (OpenGL constant) |
wrapT | Texture wrapping in T direction (OpenGL constant) |
|
explicit |
ctor for 2D textures with internal image allocation
Constructor for 2D textures from image file with internal image allocation. Textures can be used in multiple materials. Textures can belong therefore to the global assets such as meshes (SLMesh), materials (SLMaterial), textures (SLGLTexture) and shader programs (SLGLProgram).
assetMgr | Pointer to a global asset manager. If passed the asset manager is the owner of the instance and will do the deallocation. If a nullptr is passed the creator is responsible for the deallocation. |
filename | Name of the texture image file. If only a filename is passed it will be search on the SLGLTexture::defaultPath. |
min_filter | Minification filter constant from OpenGL |
mag_filter | Magnification filter constant from OpenGL |
type | Type of the texture |
wrapS | Texture wrapping in S direction (OpenGL constant) |
wrapT | Texture wrapping in T direction (OpenGL constant) |
|
explicit |
ctor for 3D texture with internal image allocation
Constructor for 3D textures from image files with internal image allocation. Textures can be used in multiple materials. Textures can belong therefore to the global assets such as meshes (SLMesh), materials (SLMaterial), textures (SLGLTexture) and shader programs (SLGLProgram).
assetMgr | Pointer to a global asset manager. If passed the asset manager is the owner of the instance and will do the deallocation. If a nullptr is passed the creator is responsible for the deallocation. |
files | Vector of texture image files. If only filenames are passed they will be searched on the SLGLTexture::defaultPath. |
min_filter | Minification filter constant from OpenGL |
mag_filter | Magnification filter constant from OpenGL |
wrapS | Texture wrapping in S direction (OpenGL constant) |
wrapT | Texture wrapping in T direction (OpenGL constant) |
name | Name of the 3D texture |
loadGrayscaleIntoAlpha | Flag if grayscale image should be loaded into alpha channel. |
|
explicit |
ctor for 3D texture from a single file with depth as 3rd dimension
Constructor for 3D textures from single image file that is stacked depth times. Textures can be used in multiple materials. Textures can belong therefore to the global assets such as meshes (SLMesh), materials (SLMaterial), textures (SLGLTexture) and shader programs (SLGLProgram).
assetMgr | Pointer to a global asset manager. If passed the asset manager is the owner of the instance and will do the deallocation. If a nullptr is passed the creator is responsible for the deallocation. |
depth | Depth of 3D texture. |
filename | texture image file. If only filenames are passed they will be searched on the SLGLTexture::defaultPath. |
min_filter | Minification filter constant from OpenGL |
mag_filter | Magnification filter constant from OpenGL |
wrapS | Texture wrapping in S direction (OpenGL constant) |
wrapT | Texture wrapping in T direction (OpenGL constant) |
name | Name of the 3D texture |
loadGrayscaleIntoAlpha | Flag if grayscale image should be loaded into alpha channel. |
SLGLTexture::SLGLTexture | ( | SLAssetManager * | assetMgr, |
const SLstring & | filenameXPos, | ||
const SLstring & | filenameXNeg, | ||
const SLstring & | filenameYPos, | ||
const SLstring & | filenameYNeg, | ||
const SLstring & | filenameZPos, | ||
const SLstring & | filenameZNeg, | ||
SLint | min_filter = GL_LINEAR , |
||
SLint | mag_filter = GL_LINEAR , |
||
SLTextureType | type = TT_unknown |
||
) |
ctor for cube mapping with internal image allocation
Constructor for a cubemap texture from 6 image files. Textures can be used in multiple materials. Textures can belong therefore to the global assets such as meshes (SLMesh), materials (SLMaterial), textures (SLGLTexture) and shader programs (SLGLProgram).
assetMgr | Pointer to a global asset manager. If passed the asset manager is the owner of the instance and will do the deallocation. If a nullptr is passed the creator is responsible for the deallocation. |
filenameXPos | Filename of the cubemap image in the pos. X direction. |
filenameXNeg | Filename of the cubemap image in the neg. X direction. |
filenameYPos | Filename of the cubemap image in the pos. Y direction. |
filenameYNeg | Filename of the cubemap image in the neg. Y direction. |
filenameZPos | Filename of the cubemap image in the pos. Z direction. |
filenameZNeg | Filename of the cubemap image in the neg. Z direction. |
min_filter | Minification filter constant from OpenGL |
mag_filter | Magnification filter constant from OpenGL |
type | Texture Type |
|
override |
The destructor should be called by the owner of the texture. If an asset manager was passed in the constructor it will do it after scene destruction. The destructor deletes all images in the RAM as well as the texture objects on the GPU.
|
inline |
void SLGLTexture::bindActive | ( | SLuint | texUnit = 0 | ) |
SLGLTexture::bindActive binds the active texture. This method must be called by the object that uses the texture every time BEFORE the its rendering. The texUnit is only used for multi texturing. Before the first time the texture is passed to OpenGL.
|
virtual |
Builds an OpenGL texture object with the according OpenGL commands. This texture creation must be done only once when a valid OpenGL rendering context is present. This function is called the first time within the enable method which is called by object that uses the texture.
Reimplemented in SLGLTextureIBL.
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
void SLGLTexture::calc3DGradients | ( | SLint | sampleRadius, |
const function< void(int)> & | onUpdateProgress | ||
) |
SLGLTexture::calc3DGradients calculates the normals based on the 3D gradient of all images and stores them in the RGB components.
sampleRadius | Distance from center to calculate the gradient |
onUpdateProgress | Callback function for progress display |
SLbool SLGLTexture::copyVideoImage | ( | SLint | camWidth, |
SLint | camHeight, | ||
CVPixelFormatGL | srcFormat, | ||
SLuchar * | data, | ||
SLbool | isContinuous, | ||
SLbool | isTopLeft | ||
) |
Copies the image data from a video camera into the current video image.
camWidth | Width in pixels of the camera image |
camHeight | Height in pixels of the camera image |
srcFormat | Pixel format according to the OpenGL pixel formats |
data | Pointer to the first byte of the first pixel |
isContinuous | Flag if the next line comes after the last byte of the prev. line |
isTopLeft | Flag if the data pointer points to the top left pixel |
SLbool SLGLTexture::copyVideoImage | ( | SLint | camWidth, |
SLint | camHeight, | ||
CVPixelFormatGL | srcFormat, | ||
CVPixelFormatGL | dstFormat, | ||
SLuchar * | data, | ||
SLbool | isContinuous, | ||
SLbool | isTopLeft | ||
) |
void SLGLTexture::cubeUV2XYZ | ( | SLint | index, |
SLfloat | u, | ||
SLfloat | v, | ||
SLfloat & | x, | ||
SLfloat & | y, | ||
SLfloat & | z | ||
) |
Computes the unnormalised vector x,y,z from tex. coords. uv with cubemap index.
A cube texture indexes six texture maps from 0 to 5 in order Positive X, Negative X, Positive Y, Negative Y, Positive Z, Negative Z. The images are stored with the origin at the lower left of the image. The Positive X and Y faces must reverse the Z coordinate and the Negative Z face must negate the X coordinate. If given the face, and texture coordinates (u,v), the unnormalized vector (x,y,z) are computed. Source:
https://en.wikipedia.org/wiki/Cube_mapping
void SLGLTexture::cubeXYZ2UV | ( | SLfloat | x, |
SLfloat | y, | ||
SLfloat | z, | ||
SLint & | index, | ||
SLfloat & | u, | ||
SLfloat & | v | ||
) |
Computes the uv and cubemap image index from a unnormalised vector x,y,z.
See also SLGLTexture::cubeUV2XYZ. Source:
https://en.wikipedia.org/wiki/Cube_mapping
void SLGLTexture::deleteData | ( | ) |
Delete all data (CVImages and GPU textures)
void SLGLTexture::deleteDataGpu | ( | ) |
Deletes the OpenGL texture objects and releases the memory on the GPU.
|
inline |
If deleteImageAfterBuild is set to true you won't be able to ray trace the scene.
void SLGLTexture::deleteImages | ( | ) |
Deletes the CVImages in _images. No more texture mapping in ray tracing.
|
inline |
|
static |
Detects the texture type from the filename appendix (See SLTexType def.)
Draws the texture as 2D sprite with OpenGL buffers.
Draws the texture as a flat 2D sprite with a height and a width on two triangles with zero in the bottom left corner:
w +--—+ | /| | / | h | / | | / | |/ | 0 +--—+ 0
dudv calculates the partial derivation (gray value slope) at u,v for bump mapping either from a height map or a normal map
void SLGLTexture::fullUpdate | ( | ) |
Fully updates the OpenGL internal texture data by the image data
SLGLTexture::getTexelf returns a pixel color at the specified cubemap direction.
SLGLTexture::getTexelf returns a pixel color from u & v texture coordinates.
If the OpenGL filtering is set to GL_LINEAR a bilinear interpolated color out of four neighboring pixels is return. Otherwise the nearest pixel is returned.
|
inline |
|
inline |
|
inline |
|
static |
Returns the internal pixel format from OpenGL.
Taken from https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glTexImage2D.xhtml
|
inline |
|
protected |
Loads the texture, converts color depth & applies vertical mirroring.
|
protected |
Loads the 1D color data into an image of height 1.
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
void SLGLTexture::smooth3DGradients | ( | SLint | smoothRadius, |
function< void(int)> | onUpdateProgress | ||
) |
SLGLTexture::smooth3DGradients smooths the 3D gradients in the RGB channels of all images.
smoothRadius | Soothing radius |
onUpdateProgress | Callback function for progress display |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
SLstring SLGLTexture::typeName | ( | ) |
Returns the texture type as string.
SLstring SLGLTexture::typeShortName | ( | ) |
Returns the texture type short.
|
inline |
|
inline |
|
inline |
|
protected |
Flag if texture matrix should be calculated from AABB for 3D mapping.
|
protected |
Bump mapping scale factor.
|
protected |
NO. of bytes in file.
|
protected |
NO. of bytes on GPU.
|
protected |
Bytes per texture image pixel (images exist either in _images or on the GPU or on both)
|
protected |
True for compressed texture format on GPU.
|
protected |
Flag if images should be deleted after build on GPU.
|
protected |
3D Texture image depth (images exist either in _images or on the GPU or on both)
|
protected |
Texture image height in pixels (images exist either in _images or on the GPU or on both)
|
protected |
Vector of CVImage pointers.
|
protected |
Internal OpenGL format.
|
protected |
Magnification filter.
|
protected |
Minification filter.
|
protected |
Mutex to protect parallel access (used in ray tracing)
|
protected |
Flag if image needs an single update.
|
protected |
Flag if image should be resized to n^2.
|
protected |
texture target
|
protected |
OpenGL texture ID.
|
protected |
See SLTextureType.
|
protected |
texture matrix
|
protected |
Vertex array object for sprite rendering.
|
protected |
Texture image width in pixels (images exist either in _images or on the GPU or on both)
|
protected |
Wrapping in s direction.
|
protected |
Wrapping in t direction.
|
static |
Returns the derivation as [s,t].
maxAnisotropy=-1 show that GL_EXT_texture_filter_anisotropic is not checked
max. anisotropy available
|
static |
Total NO. of bytes used for textures on GPU.
NO. of texture byte allocated on GPU.