Support Forum G3D Web Page |
A 1D, 2D, or 3D array (e.g., an image) stored on the GPU, commonly used for mapping reflectance values (colors) over meshes.
More...
Inherits G3D::ReferenceCountedObject.
Classes | |
class | Encoding |
Attaches semantics for reading and writing this texture beyond the OpenGL bitwise description. More... | |
class | LoadingInfo |
All transient information used by image loading and preprocessing of Textures, collected here so that the process can efficiently run on separate threads in a multithreaded environment. More... | |
class | Preprocess |
class | Specification |
class | TexelType |
class | Visualization |
Public Types | |
enum | Dimension { DIM_2D = GL_TEXTURE_2D, DIM_2D_ARRAY = GL_TEXTURE_2D_ARRAY, DIM_3D = GL_TEXTURE_3D, DIM_2D_RECT = GL_TEXTURE_RECTANGLE, DIM_CUBE_MAP = GL_TEXTURE_CUBE_MAP, DIM_CUBE_MAP_ARRAY = GL_TEXTURE_CUBE_MAP_ARRAY } |
These values are guaranteed to correspond to the equivalent OpenGL constant, so they can be cast directly for convenience when porting. More... | |
Public Member Functions | |
virtual | ~Texture () |
Deallocates the OpenGL texture. More... | |
AlphaFilter | alphaFilter () const |
The value that AlphaFilter::DETECT should use for this texture when applied to a G3D::UniversalMaterial. More... | |
shared_ptr< Texture > | alphaOnlyVersion () const |
Creates another texture that is the same as this one but contains only an alpha channel. More... | |
bool | appearsInTextureBrowserWindow () const |
String | caption () const |
Suggested caption for screen capture. More... | |
void | clear (int mipLevel=0) |
Clear the texture to 0's (typically after creation, so that it does not contain unitialized data). More... | |
bool | conservativelyHasNonUnitAlpha () const |
Returns true if this texture might have non-unit alpha without forcing lazy loading to complete. More... | |
bool | conservativelyHasUnitAlpha () const |
Returns true if this texture cannot have non-unit alpha, without forcing lazy loading to complete. More... | |
void | copyFromScreen (const Rect2D &rect, const ImageFormat *fmt=nullptr) |
Copies data from screen into an existing texture (replacing whatever was previously there). More... | |
void | copyFromScreen (const Rect2D &rect, CubeFace face) |
Copies into the specified face of a cube map. More... | |
bool | copyInto (shared_ptr< Texture > &dest, CubeFace cf=CubeFace::POS_X, int mipLevel=0, RenderDevice *rd=nullptr) const |
Copies this texture over dest, allocating or resizing dest as needed. More... | |
int | depth () const |
Dimension | dimension () const |
const Encoding & | encoding () const |
const ImageFormat * | format () const |
void | generateMipMaps () |
For a texture with that supports the FrameBufferObject extension, generate mipmaps from the level 0 mipmap immediately. More... | |
void | getTexImage (void *data, const ImageFormat *desiredFormat, CubeFace face=CubeFace::POS_X, int mipLevel=0) const |
bool | hasMipMaps () const |
int | height () const |
Number of horizontal texels in the level 0 mipmap. More... | |
bool | isCubeMap () const |
Deprecated, use dimension() == Texture::DIM_CUBE_MAP instead. More... | |
Color4 | max () const |
If this texture was loaded from an uncompressed format in memory or disk (and not rendered to), then this is the largest value in the texture, modified by the encoding's scale and bias. More... | |
Color4 | mean () const |
If this texture was loaded from an uncompressed format in memory or disk (and not rendered to), then this is the average value in the texture, modified by the encoding's scale and bias. More... | |
Color4 | min () const |
If this texture was loaded from an uncompressed format in memory or disk (and not rendered to), this is the smallest value in the texture, modified by the encoding's scale and bias. More... | |
const String & | name () const |
For debugging purposes, appears in the texture viewer. More... | |
int | numMipMapLevels () |
int | numSamples () |
bool | opaque () const |
True if this texture was created with an alpha channel. More... | |
unsigned int | openGLID () const |
unsigned int | openGLTextureTarget () const |
The OpenGL texture target this binds (e.g. More... | |
Color4 | readTexel (int ix, int iy, class RenderDevice *rd=nullptr, int mipLevel=0, int iz=0, CubeFace face=CubeFace::POS_X) const |
Reads back a single texel. More... | |
Rect2D | rect2DBounds () const |
Returns a rectangle whose m_width and m_height match the dimensions of the texture. More... | |
void | registerReallocationHook (std::function< void(GLuint)> reallocateHook) const |
void | resize (int w, int h) |
Resize the underlying OpenGL texture memory buffer, without reallocating the OpenGL texture ID. More... | |
void | resize (int w, int h, int d) |
New resize for 3D textures. More... | |
void | setCaption (const String &c) |
void | setName (const String &n) |
void | setShaderArgs (class UniformTable &args, const String &prefix, const Sampler &sampler) |
Binds the following uniforms: More... | |
int | sizeInMemory () const |
How much (texture) memory this texture occupies. More... | |
TexelType | texelType () const |
shared_ptr< class CubeMap > | toCubeMap () const |
shared_ptr< Image1unorm8 > | toDepthImage1unorm8 () const |
Extracts the data as ImageFormat::DEPTH32F and converts to 8-bit. More... | |
shared_ptr< Map2D< float > > | toDepthMap () const |
Extracts the data as ImageFormat::DEPTH32F. More... | |
shared_ptr< Image > | toImage (const ImageFormat *outFormat=ImageFormat::AUTO(), int mipLevel=0, CubeFace face=CubeFace::POS_X) const |
shared_ptr< GLPixelTransferBuffer > | toPixelTransferBuffer (const ImageFormat *outFormat=ImageFormat::AUTO(), int mipLevel=0, CubeFace face=CubeFace::POS_X) const |
void | toPixelTransferBuffer (shared_ptr< GLPixelTransferBuffer > &buffer, const ImageFormat *outFormat=ImageFormat::AUTO(), int mipLevel=0, CubeFace face=CubeFace::POS_X, bool runMapHooks=true) const |
void | update (const shared_ptr< PixelTransferBuffer > &src, int mipLevel=0, CubeFace face=CubeFace::POS_X, bool runMapHooks=true, size_t byteOffset=0, bool resizeTexture=true) |
Upload new data from the CPU to this texture. More... | |
Vector2 | vector2Bounds () const |
int | width () const |
Number of horizontal texels in the level 0 mipmap. More... | |
Static Public Member Functions | |
static void | clearCache () |
Textures are normally cached by Texture::Specification to speed loading and reduce memory consumption unless explicitly flagged not to enter the cache. More... | |
static void | copy (shared_ptr< Texture > src, shared_ptr< Texture > dst, int srcMipLevel=0, int dstMipLevel=0, float scale=1.0f, const Vector2int16 &shift=Vector2int16(0, 0), CubeFace srcCubeFace=CubeFace::POS_X, CubeFace dstCubeFace=CubeFace::POS_X, RenderDevice *rd=nullptr, bool resize=true, int srcLayer=0, int dstLayer=0) |
Copies src to dst, resizing if resize == true (the default). More... | |
static shared_ptr< Texture > | cosHemiRandom () |
Returns a texture of 1024^2 oct32-encoded cosine-weighted hemispherical random vectors about the positive z-axis. More... | |
static shared_ptr< Texture > | create (const Specification &s) |
static shared_ptr< Texture > | createColorCube (const Color4 &color) |
static shared_ptr< Texture > | createEmpty (const String &name, int width, int height, const Encoding &encoding=Encoding(ImageFormat::RGBA8()), Dimension dimension=DIM_2D, bool generateMipMaps=false, int depth=1, int numSamples=1) |
Creates an empty texture (useful for later reading from the screen). More... | |
static const CubeMapConvention::CubeMapInfo & | cubeMapInfo (CubeMapConvention convention) |
Returns the mapping from [0, 5] to cube map faces and filename suffixes. More... | |
static CubeMapConvention | determineCubeConvention (const String &filename) |
filename should contain a * wildcard More... | |
static shared_ptr< Texture > | fromFile (const String &filenameSpec, const Encoding encoding=Encoding(), Dimension dimension=DIM_2D, bool generateMipMaps=true, const Preprocess &preprocess=Preprocess::defaults(), bool preferSRGBForAuto=false) |
Creates a texture from a single image or a set of files for a texture array or cube map based on a wildcard specification such as foo-*.png . More... | |
static shared_ptr< Texture > | fromGLTexture (const String &name, GLuint textureID, Encoding encoding, AlphaFilter alphaFilter, Dimension dimension=DIM_2D, bool destroyGLTextureInDestructor=true, int numSamples=1, int width=-1, int height=-1, int depth=-1, bool hasMIPMaps=false) |
Wrap will override the existing parameters on the GL texture. More... | |
static shared_ptr< Texture > | fromImage (const String &name, const shared_ptr< Image > &image, const ImageFormat *desiredFormat=ImageFormat::AUTO(), Dimension dimension=DIM_2D, bool generateMipMaps=true, const Preprocess &preprocess=Preprocess::defaults()) |
Shorthand for Texture::fromPixelTransferBuffer(name, image->toPixelTransferBuffer(), ...) More... | |
static shared_ptr< Texture > | fromMemory (const String &name, const Array< Array< const void *> > &bytes, const ImageFormat *bytesFormat, int width, int height, int depth, int numSamples=1, Encoding encoding=Encoding(ImageFormat::AUTO()), Dimension dimension=DIM_2D, bool generateMipMaps=true, const Preprocess &preprocess=Preprocess::defaults(), bool preferSRGBForAuto=false) |
Construct from an explicit set of (optional) mipmaps and (optional) cubemap faces. More... | |
static shared_ptr< Texture > | fromMemory (const String &name, const void *bytes, const ImageFormat *bytesFormat, int width, int height, int depth, int numSamples=1, Encoding encoding=Encoding(), Dimension dimension=DIM_2D, bool generateMipMaps=true, const Preprocess &preprocess=Preprocess::defaults(), bool preferSRGBForAuto=false) |
Construct from a single packed 2D or 3D data set. More... | |
static shared_ptr< Texture > | fromPixelTransferBuffer (const String &name, const shared_ptr< PixelTransferBuffer > &image, Encoding desiredEncoding=Encoding(), Dimension dimension=DIM_2D, bool generateMipMaps=true, const Preprocess &preprocess=Preprocess::defaults()) |
static shared_ptr< Texture > | fromTwoFiles (const String &filename, const String &alphaFilename, Encoding encoding=Encoding(), Dimension dimension=DIM_2D, bool generateMipMaps=true, const Preprocess &preprocess=Preprocess::defaults(), bool preferSRGBForAuto=true, const bool useAlpha=false) |
Creates a texture from the colors of filename and takes the alpha values from the red channel of alpha filename if useAlpha is set to true, it will use the alpha channel instead. More... | |
static void | getAllTextures (Array< shared_ptr< Texture >> &textures) |
static void | getAllTextures (Array< weak_ptr< Texture >> &textures) |
static void | getCubeMapRotation (CubeFace face, Matrix3 &outMatrix) |
Returns the rotation matrix that should be used for rendering the given cube map face. More... | |
static shared_ptr< Texture > | getTextureByName (const String &textureName) |
Returns a pointer to a texture with the name textureName, if such a texture exists. More... | |
static bool | isSupportedImage (const String &filename) |
Returns true if the specified filename exists and is an image that can be loaded as a Texture. More... | |
static const shared_ptr< Texture > & | one () |
Returns a small all-white (1,1,1,1) texture. More... | |
static const shared_ptr< Texture > & | opaqueBlack (Dimension d=DIM_2D) |
Returns a small opaque all-black (0,0,0,1) texture. More... | |
static const shared_ptr< Texture > & | opaqueBlackCube () |
Returns a small opaque all-black (0,0,0,1) texture. More... | |
static const shared_ptr< Texture > & | opaqueBlackIfNull (const shared_ptr< Texture > &t) |
Returns t if it is non-nullptr, or opaqueBlack() if t is nullptr. More... | |
static const shared_ptr< Texture > & | opaqueGray () |
Returns a small all-gray (0.5,0.5,0.5,1) texture. More... | |
static const shared_ptr< Texture > & | opaqueGrayIfNull (const shared_ptr< Texture > &t) |
Returns t if it is non-nullptr, or gray() if t is nullptr. More... | |
static shared_ptr< Texture > | singleChannelDifference (RenderDevice *rd, const shared_ptr< Texture > &t0, const shared_ptr< Texture > &t1, int channel=0) |
Returns an RG32F difference texture of the same dimensions as t0 and t1 of (t0 - t1) of the specified channel, with positive values in the red channel and negative values in the green. More... | |
static int64 | sizeOfAllTexturesInMemory () |
Video memory occupied by all OpenGL textures allocated using Texture or maintained by pointers to a Texture. More... | |
static shared_ptr< Texture > | sphereRandom () |
Returns a texture of 1024^2 oct32-encoded uniformly distributed random vectors on the sphere. More... | |
static void | splitFilenameAtWildCard (const String &filename, String &filenameBeforeWildCard, String &filenameAfterWildCard) |
Splits a filename around the '*' character– used by cube maps to generate all filenames. More... | |
static bool | supportsWrapMode (WrapMode m) |
Returns true if this is a legal wrap mode for a G3D::Texture. More... | |
static DepthReadMode | toDepthReadMode (const String &s) |
static Dimension | toDimension (const String &s) |
static const char * | toString (DepthReadMode m) |
static const char * | toString (Dimension m) |
static shared_ptr< Texture > | uniformRandom () |
Returns a texture of 1024^2 RG16 vectors of uniformly distributed random numbers: ([0,1], [0,1]). More... | |
static const shared_ptr< Texture > & | white () |
Returns a small all-white (1,1,1,1) texture. More... | |
static const shared_ptr< Texture > & | whiteCube () |
Returns a small all-white (1,1,1,1) cube map texture. More... | |
static const shared_ptr< Texture > & | whiteCubeIfNull (const shared_ptr< Texture > &t) |
Returns t if it is non-nullptr, or whiteCube() if t is nullptr. More... | |
static const shared_ptr< Texture > & | whiteIfNull (const shared_ptr< Texture > &t) |
Returns t if it is non-nullptr, or white() if t is nullptr. More... | |
static const shared_ptr< Texture > & | zero (Dimension d=DIM_2D) |
Returns a small, all zero Color4(0,0,0,0) texture. More... | |
static const shared_ptr< Texture > & | zeroIfNull (const shared_ptr< Texture > &t) |
Returns t if it is non-nullptr, or zero() if t is nullptr. More... | |
Public Attributes | |
Visualization | visualization |
Used to display this Texture in a GuiTextureBox. More... | |
Protected Types | |
typedef Array< Array< const void * > > | MIPCubeFacePointerArray |
typedef Array< Array< shared_ptr< PixelTransferBuffer > > > | MIPCubeFacePTBArray |
Protected Member Functions | |
Texture (const String &name, int width, int height, int depth, Dimension dimension, const Encoding &encoding, int numSamples, bool needsForce) | |
void | completeCPULoading () |
Perform the next CPU steps specified in m_loadingInfo. More... | |
void | completeGPULoading () |
Perform the final GPU step specified in m_loadingInfo. More... | |
void | force () const |
If the underlying texture has not yet been uploaded to the GPU, then this method immediately blocks on the loading thread and does not return until the upload is completed. More... | |
Static Protected Member Functions | |
template<class T , class ... ArgTypes> | |
static shared_ptr< T > | createShared (ArgTypes &&... args) |
Like std::make_shared, but works for protected constructors. More... | |
static unsigned int | newGLTextureID () |
Helper method. More... | |
Protected Attributes | |
bool | m_appearsInTextureBrowserWindow |
If true, this texture can be registered in the TextureBrowser for run-time debugging. More... | |
Sampler | m_cachedSamplerSettings |
String | m_caption |
bool | m_conservativelyHasNonUnitAlpha = false |
bool | m_conservativelyHasUnitAlpha = false |
int | m_depth |
bool | m_destroyGLTextureInDestructor |
True if the GL texture is owned by the instance and should be cleaned up with the class instance. More... | |
AlphaFilter | m_detectedHint |
What AlphaFilter::DETECT should resolve to for this texture. More... | |
Dimension | m_dimension |
Encoding | m_encoding |
bool | m_hasMipMaps |
int | m_height |
LoadingInfo * | m_loadingInfo = nullptr |
std::mutex | m_loadingMutex |
Protects m_needsForce, m_loadingThread, and m_loadingGLCallback. More... | |
std::thread * | m_loadingThread = nullptr |
The thread that lazy loads into memory by invoking the m_loadingCPUCallbackQueue callbacks. More... | |
Color4 | m_max |
Invoke force() before accessing. More... | |
Color4 | m_mean |
Invoke force() before accessing. More... | |
Color4 | m_min |
Invoke force() before accessing. More... | |
String | m_name |
volatile bool | m_needsForce = false |
If true, this Texture is waiting for loading and/or upload to the GPU. More... | |
int | m_numSamples |
Multi-sampled texture parameters. More... | |
bool | m_opaque |
shared_ptr< std::function< void(GLuint)> > | m_reallocateHook |
GLuint | m_textureID |
OpenGL texture ID. More... | |
int | m_width |
Static Protected Attributes | |
static int64 | m_sizeOfAllTexturesInMemory |
static WeakCache< uintptr_t, shared_ptr< Texture > > | s_allTextures |
Used for the Texture browser. More... | |
static WeakCache< Specification, shared_ptr< Texture > > | s_cache |
Used to avoid re-loading textures. More... | |
Friends | |
class | BufferTexture |
template<class C , class I > | |
class | Component |
class | GLSamplerObject |
template<class I > | |
class | MapComponent |
class | Shader |
A 1D, 2D, or 3D array (e.g., an image) stored on the GPU, commonly used for mapping reflectance values (colors) over meshes.
Abstraction of OpenGL textures. This class can be used with raw OpenGL, without RenderDevice. G3D::Texture supports all of the image formats that G3D::Image can load, and DDS (DirectX textures), and Quake-style cube maps.
If you enable texture compression, textures will be compressed on the fly. This can be slow (up to a second).
The special filename "<white>" generates an all-white Color4 texture (this works for both 2D and cube map texures; "<whiteCube>" can also be used explicitly for cube maps). You can use Preprocess::modulate to create other colors from this.
|
protected |
|
protected |
|
protected |
|
virtual |
Deallocates the OpenGL texture.
|
inline |
The value that AlphaFilter::DETECT should use for this texture when applied to a G3D::UniversalMaterial.
If this returns AlphaFilter::DETECT, then detection has not been executed, likely because the texture was not in an 8-bit format.
shared_ptr<Texture> G3D::Texture::alphaOnlyVersion | ( | ) | const |
Creates another texture that is the same as this one but contains only an alpha channel.
Alpha-only textures are useful as mattes.
If the current texture is opaque(), returns nullptr (since it is not useful to construct an alpha-only version of a texture without an alpha channel).
Like all texture construction methods, this is fairly slow and should not be called every frame during interactive rendering.
|
inline |
String G3D::Texture::caption | ( | ) | const |
void G3D::Texture::clear | ( | int | mipLevel = 0 | ) |
Clear the texture to 0's (typically after creation, so that it does not contain unitialized data).
|
static |
Textures are normally cached by Texture::Specification to speed loading and reduce memory consumption unless explicitly flagged not to enter the cache.
This method flushes the G3D-wide Texture cache to allow it to reload from disk.
|
protected |
Perform the next CPU steps specified in m_loadingInfo.
Blocks. Does nothing if GPU loading is already complete.
|
protected |
Perform the final GPU step specified in m_loadingInfo.
It assumes that CPU loading has been completed and that the caller is on the GL thread.
deletes m_loadingInfo.
|
inline |
Returns true if this texture might have non-unit alpha without forcing lazy loading to complete.
|
inline |
Returns true if this texture cannot have non-unit alpha, without forcing lazy loading to complete.
|
static |
Copies src to dst, resizing if resize == true (the default).
Both src and dst image formats are preserved.
At least one of the following must hold: either dstMipLevel == 0, or srcMipLevel == dstMipLevel.
Uses a shader and makes a draw call in some cases, and executes a direct copy in others.
scale | Source coordinates are multipled by this before shift is added |
API subject to change
shift | Add This to destination coordinates to find source coordinates. For example, use the negative guard band thickness to crop a guard band. |
void G3D::Texture::copyFromScreen | ( | const Rect2D & | rect, |
const ImageFormat * | fmt = nullptr |
||
) |
Copies data from screen into an existing texture (replacing whatever was previously there).
The dimensions must be powers of two or a texture rectangle will be created (not supported on some cards).
This call is provided for backwards compatibility on old cards. It is substantially slower than simply rendering to a G3D::Texture using a G3D::Framebuffer.
The (x, y) coordinates are in OpenGL coordinates. If a FrameBuffer is bound then (0, 0) is the top left of the screen. When rendering directly to a window, (0,0) is the lower left. Use RenderDevice::copyTextureFromScreen to obtain consistent coordinates.
The texture dimensions will be updated but all other properties will be preserved: The previous wrap mode will be preserved. The interpolation mode will be preserved (unless it required a mipmap, in which case it will be set to BILINEAR_NO_MIPMAP). The previous color m_depth and alpha m_depth will be preserved. Texture compression is not supported for textures copied from the screen.
To copy a depth texture, first create an empty depth texture then copy into it.
If you invoke this method on a texture that is currently set on RenderDevice, the texture will immediately be updated (there is no need to rebind).
rect | The rectangle to copy (relative to the viewport) |
fmt | If nullptr, uses the existing texture format, otherwise forces this texture to use the specified format. |
Copies into the specified face of a cube map.
Because cube maps can't have the Y direction inverted (and still do anything useful), you should render the cube map faces upside-down before copying them into the map. This is an unfortunate side-effect of OpenGL's cube map convention.
Use G3D::Texture::getCubeMapRotation to generate the (upside-down) camera orientations.
bool G3D::Texture::copyInto | ( | shared_ptr< Texture > & | dest, |
CubeFace | cf = CubeFace::POS_X , |
||
int | mipLevel = 0 , |
||
RenderDevice * | rd = nullptr |
||
) | const |
Copies this texture over dest, allocating or resizing dest as needed.
(It reallocs if the internal formats mismatch or dest is null) Uses a shader and makes a draw call. If src is a depth texture, mipLevel must be 0.
DEPRECATED: To be replaced with a clearer API before G3D10 final release.
|
static |
Returns a texture of 1024^2 oct32-encoded cosine-weighted hemispherical random vectors about the positive z-axis.
Use octDecode(texelFetch(g3d_cosHemiRandom, pos, 0).xy) in a shader to decode these. This is automatically bound as g3d_cosHemiRandom in shaders that use it.
|
static |
|
static |
Creates an empty texture (useful for later reading from the screen).
|
inlinestaticprotectedinherited |
Like std::make_shared, but works for protected constructors.
Call as createShared<myclass>.
|
static |
Returns the mapping from [0, 5] to cube map faces and filename suffixes.
There are multiple filename conventions, so the suffixes specify each of the options.
|
inline |
|
static |
filename should contain a * wildcard
|
inline |
|
inline |
|
protected |
If the underlying texture has not yet been uploaded to the GPU, then this method immediately blocks on the loading thread and does not return until the upload is completed.
Otherwise it does nothing. This should be called on the OpenGL thread.
Referenced by hasMipMaps(), max(), mean(), min(), opaque(), and openGLID().
|
inline |
|
static |
Creates a texture from a single image or a set of files for a texture array or cube map based on a wildcard specification such as foo-*.png
.
Cube maps can have any common cube map specifier in the wildcard, such as "bk", "+z", or "pz". Texture arrays must have sequential integers in the wildcard. The image must have a format understood by G3D::Image or be a DirectDraw Surface (DDS).
|
static |
Wrap will override the existing parameters on the GL texture.
name | Arbitrary name for this texture to identify it |
textureID | Set to newGLTextureID() to create an empty texture. |
destroyGLTextureInDestructor | If true, deallocate the OpenGL texture when the G3D::Texture is destroyed |
|
static |
Shorthand for Texture::fromPixelTransferBuffer(name, image->toPixelTransferBuffer(), ...)
|
static |
Construct from an explicit set of (optional) mipmaps and (optional) cubemap faces.
bytes[miplevel][cubeface] is a pointer to the bytes for that miplevel and cube face. If the outer array has only one element and the interpolation mode is TRILINEAR_MIPMAP, mip-maps are automatically generated from the level 0 mip-map.
There must be exactly 6 cube faces per mip-level if the dimensions are DIM_CUBE and and 1 per mip-level otherwise. You may specify compressed and uncompressed formats for both the bytesformat and the desiredformat.
3D Textures may not use mip-maps.
Data is converted between normalized fixed point and floating point as described in section 2.1.5 of the OpenGL 3.2 specification. Specifically, uint8 values are converted to floating point by v' = v / 255.0f
. Note that this differs from how G3D::Color1uint8 converts to G3D::Color3.
Note: OpenGL stores values at texel centers. Thus element at integer position (x, y) in the input "image" is stored at texture coordinate ((x + 0.5) / width, (x + 0.5) / height).
Referenced by G3D::MapComponent< Image >::getTexture().
|
static |
Construct from a single packed 2D or 3D data set.
Shorthand for Texture::fromMemory(name, Array<Array<const void*>> bytes, ...)
|
static |
|
static |
Creates a texture from the colors of filename and takes the alpha values from the red channel of alpha filename if useAlpha is set to true, it will use the alpha channel instead.
See G3D::RenderDevice::setBlendFunc for important information about turning on alpha blending.
void G3D::Texture::generateMipMaps | ( | ) |
For a texture with that supports the FrameBufferObject extension, generate mipmaps from the level 0 mipmap immediately.
For other textures, does nothing.
Returns the rotation matrix that should be used for rendering the given cube map face.
The orientations will seem to have the camera "upside down" compared to what you might expect because OpenGL's cube map convention and texture convention are both inverted from how we usually visualize the data.
The resulting cube maps can be saved to disk by:
const Texture::CubeMapInfo::Face& faceInfo = cubeMapInfo.face[f]; Image temp; renderTarget->getImage(temp, ImageFormat::RGB8()); temp.flipVertical(); temp.rotate90CW(-faceInfo.rotations); if (faceInfo.flipY) temp.flipVertical(); if (faceInfo.flipX) temp.flipHorizontal(); temp.save(format("out-%s.png", faceInfo.suffix.c_str()));
void G3D::Texture::getTexImage | ( | void * | data, |
const ImageFormat * | desiredFormat, | ||
CubeFace | face = CubeFace::POS_X , |
||
int | mipLevel = 0 |
||
) | const |
Returns a pointer to a texture with the name textureName, if such a texture exists.
Returns null otherwise. If multiple textures have the name textureName, one is chosen arbitrarily.
This function is not performant, it is linear in the number of existing textures; it is provided for convenience.
|
inline |
Referenced by numMipMapLevels().
|
inline |
Number of horizontal texels in the level 0 mipmap.
|
inline |
Deprecated, use dimension() == Texture::DIM_CUBE_MAP instead.
|
static |
Returns true if the specified filename exists and is an image that can be loaded as a Texture.
|
inline |
If this texture was loaded from an uncompressed format in memory or disk (and not rendered to), then this is the largest value in the texture, modified by the encoding's scale and bias.
NaN if unknown.
|
inline |
If this texture was loaded from an uncompressed format in memory or disk (and not rendered to), then this is the average value in the texture, modified by the encoding's scale and bias.
NaN if unknown.
|
inline |
If this texture was loaded from an uncompressed format in memory or disk (and not rendered to), this is the smallest value in the texture, modified by the encoding's scale and bias.
NaN if unknown.
|
inline |
For debugging purposes, appears in the texture viewer.
|
staticprotected |
Helper method.
Returns a new OpenGL texture ID that is not yet managed by a G3D Texture. Used by Texture and G3D::BufferTexture only.
|
inline |
|
inline |
|
inlinestatic |
Returns a small all-white (1,1,1,1) texture.
The result is memoized and shared. Do not mutate this texture or future calls will return the mutated texture as well.
|
inline |
True if this texture was created with an alpha channel.
Note that a texture may have a format that is not opaque (e.g., RGBA8) yet still have a completely opaque alpha channel, causing texture->opaque to be true. This is just a flag set for the user's convenience– it does not affect rendering in any way. See G3D::RenderDevice::setBlendFunc for important information about turning on alpha blending.
Referenced by alphaFilter().
Returns a small opaque all-black (0,0,0,1) texture.
The result is memoized and shared. Do not mutate this texture or future calls will return the mutated texture as well.
d | must be DIM_2D, DIM_3D, or DIM_2D_ARRAY |
Referenced by opaqueBlackIfNull(), and G3D::LightingEnvironment::screenColorTexture().
|
static |
Returns a small opaque all-black (0,0,0,1) texture.
The result is memoized and shared. Do not mutate this texture or future calls will return the mutated texture as well.
|
inlinestatic |
Returns t if it is non-nullptr, or opaqueBlack() if t is nullptr.
|
static |
Returns a small all-gray (0.5,0.5,0.5,1) texture.
The result is memoized and shared. Do not mutate this texture or future calls will return the mutated texture as well.
Referenced by opaqueGrayIfNull().
|
inlinestatic |
Returns t if it is non-nullptr, or gray() if t is nullptr.
|
inline |
unsigned int G3D::Texture::openGLTextureTarget | ( | ) | const |
The OpenGL texture target this binds (e.g.
GL_TEXTURE_2D)
Color4 G3D::Texture::readTexel | ( | int | ix, |
int | iy, | ||
class RenderDevice * | rd = nullptr , |
||
int | mipLevel = 0 , |
||
int | iz = 0 , |
||
CubeFace | face = CubeFace::POS_X |
||
) | const |
Reads back a single texel.
This is slow because it stalls the CPU on the GPU. However, it requires less bandwidth than reading an entire image.
rd If nullptr, set to RenderDevice::current;
Rect2D G3D::Texture::rect2DBounds | ( | ) | const |
Returns a rectangle whose m_width and m_height match the dimensions of the texture.
|
inline |
void G3D::Texture::resize | ( | int | w, |
int | h | ||
) |
Resize the underlying OpenGL texture memory buffer, without reallocating the OpenGL texture ID.
This does not scale the contents; the contents are undefined after resizing. This is only useful for textures that are render targets.
void G3D::Texture::resize | ( | int | w, |
int | h, | ||
int | d | ||
) |
New resize for 3D textures.
|
inline |
|
inline |
void G3D::Texture::setShaderArgs | ( | class UniformTable & | args, |
const String & | prefix, | ||
const Sampler & | sampler | ||
) |
Binds the following uniforms:
to args, with X and Y being chosen based on the texture dimension.
If prefix contains no period (deprecated), then the macro is bound:
#define prefix##notNull 1
otherwise,
bool prefix##notNull
is set to true.
Inside a shader, these arguments can be automatically defined using the macro (deprecated)
or by using a struct
|
static |
Returns an RG32F difference texture of the same dimensions as t0 and t1 of (t0 - t1) of the specified channel, with positive values in the red channel and negative values in the green.
Expect changes to this API as we use it more and make it more manageable
int G3D::Texture::sizeInMemory | ( | ) | const |
How much (texture) memory this texture occupies.
OpenGL backs video memory textures with main memory, so the total memory is actually twice this number.
|
inlinestatic |
|
static |
Returns a texture of 1024^2 oct32-encoded uniformly distributed random vectors on the sphere.
Use octDecode(texelFetch(g3d_sphereRandom, pos, 0).xy) in a shader to decode these. This is automatically bound as g3d_sphereRandom in shaders that use it.
|
static |
Splits a filename around the '*' character– used by cube maps to generate all filenames.
|
inlinestatic |
Returns true if this is a legal wrap mode for a G3D::Texture.
TexelType G3D::Texture::texelType | ( | ) | const |
shared_ptr<class CubeMap> G3D::Texture::toCubeMap | ( | ) | const |
shared_ptr<Image1unorm8> G3D::Texture::toDepthImage1unorm8 | ( | ) | const |
Extracts the data as ImageFormat::DEPTH32F and converts to 8-bit.
Note that you may want to call Image1unorm8::flipVertical afterward.
shared_ptr<Map2D<float> > G3D::Texture::toDepthMap | ( | ) | const |
Extracts the data as ImageFormat::DEPTH32F.
|
static |
shared_ptr<Image> G3D::Texture::toImage | ( | const ImageFormat * | outFormat = ImageFormat::AUTO() , |
int | mipLevel = 0 , |
||
CubeFace | face = CubeFace::POS_X |
||
) | const |
shared_ptr<GLPixelTransferBuffer> G3D::Texture::toPixelTransferBuffer | ( | const ImageFormat * | outFormat = ImageFormat::AUTO() , |
int | mipLevel = 0 , |
||
CubeFace | face = CubeFace::POS_X |
||
) | const |
void G3D::Texture::toPixelTransferBuffer | ( | shared_ptr< GLPixelTransferBuffer > & | buffer, |
const ImageFormat * | outFormat = ImageFormat::AUTO() , |
||
int | mipLevel = 0 , |
||
CubeFace | face = CubeFace::POS_X , |
||
bool | runMapHooks = true |
||
) | const |
|
static |
|
static |
|
static |
Returns a texture of 1024^2 RG16 vectors of uniformly distributed random numbers: ([0,1], [0,1]).
This is automatically bound as g3d_uniformRandom in shaders that use it.
void G3D::Texture::update | ( | const shared_ptr< PixelTransferBuffer > & | src, |
int | mipLevel = 0 , |
||
CubeFace | face = CubeFace::POS_X , |
||
bool | runMapHooks = true , |
||
size_t | byteOffset = 0 , |
||
bool | resizeTexture = true |
||
) |
Upload new data from the CPU to this texture.
Corresponds to glTexSubImage2D. If src is smaller than the current dimensions of this, only part of this is updated.
This routine does not provide the same protections as creating a new Texture from memory: you must handle scaling and ensure compatible formats yourself.
face | If specified, determines the cubemap face to copy into |
src | GLPixelTransferBuffer is handled specially to support updates when the buffer is not yet PixelTransferBuffer::readyToMap. All other PixelTransferBuffers are mapped for read. The upload to the GPU is asynchronous (assuming that the GPU driver is reasonable) and the buffer may be modified immediately on return. |
|
inline |
|
static |
Returns a small all-white (1,1,1,1) texture.
The result is memoized and shared. Do not mutate this texture or future calls will return the mutated texture as well.
Referenced by one(), and whiteIfNull().
|
static |
Returns a small all-white (1,1,1,1) cube map texture.
The result is memoized and shared. Do not mutate this texture or future calls will return the mutated texture as well.
The underlying OpenGL texture is guaranteed not to be deallocated before RenderDevice shuts down.
Referenced by whiteCubeIfNull().
|
inlinestatic |
Returns t if it is non-nullptr, or whiteCube() if t is nullptr.
|
inlinestatic |
Returns t if it is non-nullptr, or white() if t is nullptr.
|
inline |
Number of horizontal texels in the level 0 mipmap.
Returns a small, all zero Color4(0,0,0,0) texture.
The result is memoized and shared. Do not mutate this texture or future calls will return the mutated texture as well.
d | must be DIM_2D, DIM_3D, or DIM_2D_ARRAY |
Referenced by zeroIfNull().
|
inlinestatic |
Returns t if it is non-nullptr, or zero() if t is nullptr.
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
|
protected |
If true, this texture can be registered in the TextureBrowser for run-time debugging.
Referenced by appearsInTextureBrowserWindow().
|
protected |
|
protected |
Referenced by setCaption().
|
protected |
Referenced by conservativelyHasNonUnitAlpha(), and opaque().
|
protected |
Referenced by conservativelyHasUnitAlpha(), and opaque().
|
protected |
Referenced by depth(), and numMipMapLevels().
|
protected |
True if the GL texture is owned by the instance and should be cleaned up with the class instance.
|
protected |
What AlphaFilter::DETECT should resolve to for this texture.
Left as DETECT if not computed.
Referenced by alphaFilter().
|
protected |
Referenced by dimension(), and isCubeMap().
|
protected |
|
protected |
Referenced by hasMipMaps().
|
protected |
Referenced by height(), numMipMapLevels(), and vector2Bounds().
|
mutableprotected |
|
mutableprotected |
Protects m_needsForce, m_loadingThread, and m_loadingGLCallback.
|
mutableprotected |
The thread that lazy loads into memory by invoking the m_loadingCPUCallbackQueue callbacks.
Not permitted to make any OpenGL calls. Mutable so that it can be deallocated during the const force() method.
The loading thread advances through m_loadingInfo.nextStep processing until it reaches the UPLOAD_TO_GPU stage. That must be run during force on the GL thread.
|
protected |
|
protected |
|
protected |
|
mutableprotected |
If true, this Texture is waiting for loading and/or upload to the GPU.
Set by certain lazy initialization paths of Texture::fromFile. This is protected by m_loadingMutex, but can be conservatively checked for the false case without a mutex for efficiency. Mutable so that it can be written during the const force() method.
|
protected |
Multi-sampled texture parameters.
Referenced by numSamples().
|
protected |
Referenced by opaque().
|
mutableprotected |
Referenced by registerReallocationHook().
|
staticprotected |
Referenced by sizeOfAllTexturesInMemory().
|
protected |
|
protected |
Referenced by numMipMapLevels(), vector2Bounds(), and width().
Used for the Texture browser.
nullptr elements are flushed during reloadAll(). The key is the raw pointer.
|
staticprotected |
Used to avoid re-loading textures.
Visualization G3D::Texture::visualization |
Used to display this Texture in a GuiTextureBox.