G3D::Texture Class ReferenceAbstraction of OpenGL textures.
More...
#include <Texture.h>
Inherits G3D::ReferenceCountedObject.
List of all members.
|
Public Types |
| enum | CubeFace {
CUBE_POS_X = 0,
CUBE_NEG_X = 1,
CUBE_POS_Y = 2,
CUBE_NEG_Y = 3,
CUBE_POS_Z = 4,
CUBE_NEG_Z = 5
} |
| enum | DepthReadMode { DEPTH_NORMAL = 0,
DEPTH_LEQUAL = 1,
DEPTH_GEQUAL = 2
} |
| enum | Dimension {
DIM_2D = 2,
DIM_3D = 3,
DIM_2D_RECT = 4,
DIM_CUBE_MAP = 5,
DIM_2D_NPOT = 6,
DIM_CUBE_MAP_NPOT = 7
} |
| enum | InterpolateMode {
TRILINEAR_MIPMAP = 3,
BILINEAR_MIPMAP = 4,
NEAREST_MIPMAP = 5,
BILINEAR_NO_MIPMAP = 2,
NEAREST_NO_MIPMAP = 6
} |
typedef ReferenceCountedPointer<
class Texture > | Ref |
Public Member Functions |
| Texture::Ref | alphaOnlyVersion () const |
| void | copyFromScreen (const Rect2D &rect, CubeFace face, bool useBackBuffer=true) |
| void | copyFromScreen (const Rect2D &rect, bool useBackBuffer=true) |
| int | depth () const |
| Dimension | dimension () const |
| const TextureFormat * | format () const |
| void | generateMipMaps () |
| void | getImage (GImage &dst, const TextureFormat *outFormat=TextureFormat::AUTO()) const |
| int | height () const |
| const std::string & | name () const |
| bool | opaque () const |
| unsigned int | openGLID () const |
| unsigned int | openGLTextureTarget () const |
| Rect2D | rect2DBounds () const |
| void | ReferenceCountedObject_zeroWeakPointers () |
| void | setAutoMipMap (bool b) |
| const Settings & | settings () const |
| size_t | sizeInMemory () const |
| int | texelDepth () const |
| int | texelHeight () const |
| int | texelWidth () const |
| Image1Ref | toDepthImage1 () const |
| Image1uint8Ref | toDepthImage1uint8 () const |
| Map2D< float >::Ref | toDepthMap () const |
| Image1Ref | toImage1 () const |
| Image1uint8Ref | toImage1uint8 () const |
| Image3Ref | toImage3 () const |
| Image3uint8Ref | toImage3uint8 () const |
| Image4Ref | toImage4 () const |
| Image4uint8Ref | toImage4uint8 () const |
| Vector2 | vector2Bounds () const |
| int | width () const |
| virtual | ~Texture () |
Static Public Member Functions |
| static Texture::Ref | createEmpty (const std::string &name, int m_width, int m_height, const class TextureFormat *desiredFormat=TextureFormat::RGBA8(), Dimension dimension=DIM_2D, const Settings &settings=Settings::defaults()) |
| static Texture::Ref | fromFile (const std::string filename[6], const class TextureFormat *desiredFormat=TextureFormat::AUTO(), Dimension dimension=DIM_2D, const Settings &settings=Settings::defaults(), const PreProcess &process=PreProcess()) |
| static Texture::Ref | fromFile (const std::string &filename, const class TextureFormat *desiredFormat=TextureFormat::AUTO(), Dimension dimension=DIM_2D, const Settings &settings=Settings::defaults(), const PreProcess &process=PreProcess()) |
| static Texture::Ref | fromGImage (const std::string &name, const GImage &image, const class TextureFormat *desiredFormat=TextureFormat::AUTO(), Dimension dimension=DIM_2D, const Settings &settings=Settings::defaults(), const PreProcess &preProcess=PreProcess::defaults()) |
| static Texture::Ref | fromGLTexture (const std::string &name, GLuint textureID, const class TextureFormat *textureFormat, Dimension dimension=DIM_2D, const Settings &settings=Settings::defaults()) |
| static Texture::Ref | fromMemory (const std::string &name, const void *bytes, const class TextureFormat *bytesFormat, int m_width, int m_height, int m_depth, const class TextureFormat *desiredFormat=TextureFormat::AUTO(), Dimension dimension=DIM_2D, const Settings &settings=Settings::defaults(), const PreProcess &preProcess=PreProcess::defaults()) |
| static Texture::Ref | fromMemory (const std::string &name, const Array< Array< const void * > > &bytes, const TextureFormat *bytesFormat, int m_width, int m_height, int m_depth, const TextureFormat *desiredFormat=TextureFormat::AUTO(), Dimension dimension=DIM_2D, const Settings &settings=Settings::defaults(), const PreProcess &preProcess=PreProcess::defaults()) |
| static Texture::Ref | fromTwoFiles (const std::string &filename, const std::string &alphaFilename, const class TextureFormat *desiredFormat=TextureFormat::AUTO(), Dimension dimension=DIM_2D, const Settings &settings=Settings::defaults(), const PreProcess &process=PreProcess()) |
| static void | getCameraRotation (CubeFace face, Matrix3 &outMatrix) |
| static bool | isSupportedImage (const std::string &filename) |
| static uint32 | newGLTextureID () |
| static size_t | sizeOfAllTexturesInMemory () |
| static void | splitFilenameAtWildCard (const std::string &filename, std::string &filenameBeforeWildCard, std::string &filenameAfterWildCard) |
| static bool | supportsWrapMode (WrapMode m) |
Public Attributes |
| bool | invertY |
| AtomicInt32 | ReferenceCountedObject_refCount |
| _WeakPtrLinkedList * | ReferenceCountedObject_weakPointer |
Classes |
| class | DDSTexture |
| class | PreProcess |
| class | Settings |
| | All parameters of a texture that are independent of the underlying image data. More...
|
Detailed Description
Abstraction of OpenGL textures.
This class can be used with raw OpenGL, without RenderDevice. G3D::Texture supports all of the image formats that G3D::GImage 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).
Unless DIM_2D_RECT, DIM_2D_NPOT, DIM_CUBE_MAP_NPOT are used, the texture is automatically scaled to the next power of 2 along each dimension to meet hardware requirements, if not already a power of 2. However, DIM_2D_NPOT and DIM_CUBE_MAP_NPOT will safely fallback to POT requirements if the ARB_non_power_of_two extension is not supported. Develoeprs can check if this will happen by calling GLCaps::supports_GL_ARB_texture_non_power_of_two(). Note that the texture does not have to be a rectangle; the dimensions can be different powers of two. DIM_2D_RECT is provided primarily for older cards only and does not interact well with shaders.
Textures are loaded so that (0, 0) is the upper-left corner of the image. If you set the invertY flag, RenderDevice will automatically turn them upside down when rendering to allow a (0, 0) lower-left corner. If you aren't using RenderDevice, you must change the texture matrix to have a -1 in the Y column yourself. If you replace the default vertex shader then the texture matrix transformation will not be performed.
DIM_2D_RECT requires the GL_EXT_texture_rectangle extension. Texture compression requires the EXT_texture_compression_s3tc extions. You can either query OpenGL for whether these are supported or use the G3D::GLCaps facility for doing so.
G3D::Texture can be used with straight OpenGL, without G3D::RenderDevice, as follows:
Texture::Ref texture = new Texture("logo.jpg");
...
GLint u = texture->getOpenGLTextureTarget();
glEnable(u);
glBindTexture(u, texture->getOpenGLID());
To use Texture with RenderDevice:
Texture::Ref texture = new Texture("logo.jpg");
...
renderDevice->setTexture(0, texture);
(to disable: renderDevice->setTexture(0, NULL);)
3D MIP Maps are not supported because gluBuild3DMipMaps is not in all GLU implementations.
See G3D::RenderDevice::setBlendFunc for important information about turning on alpha blending.
Member Typedef Documentation
Reference counted pointer to a Texture.
Member Enumeration Documentation
Argument for copyFromScreen.
- Enumerator:
-
| CUBE_POS_X |
|
| CUBE_NEG_X |
|
| CUBE_POS_Y |
|
| CUBE_NEG_Y |
|
| CUBE_POS_Z |
|
| CUBE_NEG_Z |
|
A m_depth texture can automatically perform the m_depth comparison used for shadow mapping on a texture lookup.
The result of a texture lookup is thus the shadowed amount (which will be percentage closer filtered on newer hardware) and not the actual m_depth from the light's point of view.
This combines GL_TEXTURE_COMPARE_MODE_ARB and GL_TEXTURE_COMPARE_FUNC_ARB from http://www.nvidia.com/dev_content/nvopenglspecs/GL_ARB_shadow.txt
For best results on percentage closer hardware (GeForceFX and Radeon9xxx or better), create shadow maps as m_depth textures with BILINEAR_NO_MIPMAP sampling.
See also G3D::RenderDevice::configureShadowMap and the Collision_Demo. - Enumerator:
-
| DEPTH_NORMAL |
|
| DEPTH_LEQUAL |
|
| DEPTH_GEQUAL |
|
DIM_2D_NPOT and DIM_CUBE_MAP_NPOT attempt to use ARB_non_power_of_two texture support with POT fallback.
- Enumerator:
-
| DIM_2D |
|
| DIM_3D |
|
| DIM_2D_RECT |
|
| DIM_CUBE_MAP |
|
| DIM_2D_NPOT |
|
| DIM_CUBE_MAP_NPOT |
|
Trilinear mipmap is the best quality (and frequently fastest) mode.
The no-mipmap modes conserve memory. Non-interpolating ("Nearest") modes are generally useful only when packing lookup tables into textures for shaders.
3D textures do not support mipmap interpolation modes. - Enumerator:
-
| TRILINEAR_MIPMAP |
|
| BILINEAR_MIPMAP |
|
| NEAREST_MIPMAP |
|
| BILINEAR_NO_MIPMAP |
|
| NEAREST_NO_MIPMAP |
|
Constructor & Destructor Documentation
| virtual G3D::Texture::~Texture |
( |
|
) |
[virtual] |
Deallocates the OpenGL texture.
Member Function Documentation
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 NULL (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.
| void G3D::Texture::copyFromScreen |
( |
const Rect2D & |
rect, |
|
|
CubeFace |
face, |
|
|
bool |
useBackBuffer = true | |
|
) |
| | |
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::getCameraRotation to generate the (upside-down) camera orientations.
| void G3D::Texture::copyFromScreen |
( |
const Rect2D & |
rect, |
|
|
bool |
useBackBuffer = true | |
|
) |
| | |
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).
The (x, y) coordinates are in real screen pixels. (0, 0) is the top left of the screen.
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 m_depth texture, first create an empty m_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).
- Parameters:
-
| useBackBuffer | If true, the texture is created from the back buffer. If false, the texture is created from the front buffer. |
| rect | The rectangle to copy (relative to the viewport) See also RenderDevice::screenShotPic |
| static Texture::Ref G3D::Texture::createEmpty |
( |
const std::string & |
name, |
|
|
int |
m_width, |
|
|
int |
m_height, |
|
|
const class TextureFormat * |
desiredFormat = TextureFormat::RGBA8(), |
|
|
Dimension |
dimension = DIM_2D, |
|
|
const Settings & |
settings = Settings::defaults() | |
|
) |
| | [static] |
Creates an empty texture (useful for later reading from the screen).
| int G3D::Texture::depth |
( |
|
) |
const [inline] |
| Dimension G3D::Texture::dimension |
( |
|
) |
const [inline] |
Creates a cube map from six independently named files.
The first becomes the name of the texture.
Creates a texture from a single image.
The image must have a format understood by G3D::GImage or a DirectDraw Surface (DDS). If dimension is DIM_CUBE_MAP, this loads the 6 files with names _ft, _bk, ... following the G3D::Sky documentation.
| static Texture::Ref G3D::Texture::fromGImage |
( |
const std::string & |
name, |
|
|
const GImage & |
image, |
|
|
const class TextureFormat * |
desiredFormat = TextureFormat::AUTO(), |
|
|
Dimension |
dimension = DIM_2D, |
|
|
const Settings & |
settings = Settings::defaults(), |
|
|
const PreProcess & |
preProcess = PreProcess::defaults() | |
|
) |
| | [static] |
| static Texture::Ref G3D::Texture::fromGLTexture |
( |
const std::string & |
name, |
|
|
GLuint |
textureID, |
|
|
const class TextureFormat * |
textureFormat, |
|
|
Dimension |
dimension = DIM_2D, |
|
|
const Settings & |
settings = Settings::defaults() | |
|
) |
| | [static] |
Wrap and interpolate will override the existing parameters on the GL texture.
- Parameters:
-
| name | Arbitrary name for this texture to identify it |
| textureID | Set to newGLTextureID() to create an empty texture. |
| static Texture::Ref G3D::Texture::fromMemory |
( |
const std::string & |
name, |
|
|
const void * |
bytes, |
|
|
const class TextureFormat * |
bytesFormat, |
|
|
int |
m_width, |
|
|
int |
m_height, |
|
|
int |
m_depth, |
|
|
const class TextureFormat * |
desiredFormat = TextureFormat::AUTO(), |
|
|
Dimension |
dimension = DIM_2D, |
|
|
const Settings & |
settings = Settings::defaults(), |
|
|
const PreProcess & |
preProcess = PreProcess::defaults() | |
|
) |
| | [static] |
Construct from a single packed 2D or 3D data set.
For 3D textures, the interpolation mode must be one that does not use MipMaps.
| static Texture::Ref G3D::Texture::fromMemory |
( |
const std::string & |
name, |
|
|
const Array< Array< const void * > > & |
bytes, |
|
|
const TextureFormat * |
bytesFormat, |
|
|
int |
m_width, |
|
|
int |
m_height, |
|
|
int |
m_depth, |
|
|
const TextureFormat * |
desiredFormat = TextureFormat::AUTO(), |
|
|
Dimension |
dimension = DIM_2D, |
|
|
const Settings & |
settings = Settings::defaults(), |
|
|
const PreProcess & |
preProcess = PreProcess::defaults() | |
|
) |
| | [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 map not use mip-maps.
| static Texture::Ref G3D::Texture::fromTwoFiles |
( |
const std::string & |
filename, |
|
|
const std::string & |
alphaFilename, |
|
|
const class TextureFormat * |
desiredFormat = TextureFormat::AUTO(), |
|
|
Dimension |
dimension = DIM_2D, |
|
|
const Settings & |
settings = Settings::defaults(), |
|
|
const PreProcess & |
process = PreProcess() | |
|
) |
| | [static] |
Creates a texture from the colors of filename and takes the alpha values from the red channel of alpha filename.
See G3D::RenderDevice::setBlendFunc for important information about turning on alpha blending.
| void G3D::Texture::generateMipMaps |
( |
|
) |
|
For a texture with automipmap off that supports the FrameBufferObject extension, generate mipmaps from the level 0 mipmap immediately.
For other textures, does nothing.
| static void G3D::Texture::getCameraRotation |
( |
CubeFace |
face, |
|
|
Matrix3 & |
outMatrix | |
|
) |
| | [static] |
Returns the rotation matrix that should be used for rendering the given cube map face.
| void G3D::Texture::getImage |
( |
GImage & |
dst, |
|
|
const TextureFormat * |
outFormat = TextureFormat::AUTO() | |
|
) |
| | const |
Returns the level 0 mip-map data in the format that most closely matches outFormat.
- Parameters:
-
| int G3D::Texture::height |
( |
|
) |
const [inline] |
Number of horizontal texels in the level 0 mipmap.
| static bool G3D::Texture::isSupportedImage |
( |
const std::string & |
filename |
) |
[static] |
Returns true if the specified filename exists and is an image that can be loaded as a Texture.
| const std::string& G3D::Texture::name |
( |
|
) |
const [inline] |
| static uint32 G3D::Texture::newGLTextureID |
( |
|
) |
[static] |
Helper method.
Returns a new OpenGL texture ID that is not yet managed by a G3D Texture.
| bool G3D::Texture::opaque |
( |
|
) |
const [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.
| unsigned int G3D::Texture::openGLID |
( |
|
) |
const [inline] |
| unsigned int G3D::Texture::openGLTextureTarget |
( |
|
) |
const |
The OpenGL texture target this binds (e.g.
GL_TEXTURE_2D)
| Rect2D G3D::Texture::rect2DBounds |
( |
|
) |
const |
Returns a rectangle whose m_width and m_height match the dimensions of the texture.
| void G3D::ReferenceCountedObject::ReferenceCountedObject_zeroWeakPointers |
( |
|
) |
[inline, inherited] |
Automatically called immediately before the object is deleted.
This is not called from the destructor because it needs to be invoked before the subclass destructor.
| void G3D::Texture::setAutoMipMap |
( |
bool |
b |
) |
|
Set the autoMipMap value, which only affects textures when they are rendered to or copied from the screen.
You can read the automipmap value from settings().autoMipMap.
| const Settings& G3D::Texture::settings |
( |
|
) |
const |
| size_t 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.
| static size_t G3D::Texture::sizeOfAllTexturesInMemory |
( |
|
) |
[inline, static] |
Video memory occupied by all OpenGL textures allocated using Texture or maintained by pointers to a Texture.
| static void G3D::Texture::splitFilenameAtWildCard |
( |
const std::string & |
filename, |
|
|
std::string & |
filenameBeforeWildCard, |
|
|
std::string & |
filenameAfterWildCard | |
|
) |
| | [static] |
Splits a filename around the '*' character-- used by cube maps to generate all filenames.
| static bool G3D::Texture::supportsWrapMode |
( |
WrapMode |
m |
) |
[inline, static] |
Returns true if this is a legal wrap mode for a G3D::Texture.
| int G3D::Texture::texelDepth |
( |
|
) |
const [inline] |
| int G3D::Texture::texelHeight |
( |
|
) |
const [inline] |
| int G3D::Texture::texelWidth |
( |
|
) |
const [inline] |
| Image1Ref G3D::Texture::toDepthImage1 |
( |
|
) |
const |
| Map2D<float>::Ref G3D::Texture::toDepthMap |
( |
|
) |
const |
| Vector2 G3D::Texture::vector2Bounds |
( |
|
) |
const [inline] |
| int G3D::Texture::width |
( |
|
) |
const [inline] |
Number of horizontal texels in the level 0 mipmap.
Member Data Documentation
When true, rendering code that uses this texture is respondible for flipping texture coordinates applied to this texture vertically (initially, this is false).
RenderDevice watches this flag and performs the appropriate transformation. If you are not using RenderDevice (or are writing shaders), you must do it yourself.
The long name is to keep this from accidentally conflicting with a subclass's variable name.
Do not use or explicitly manipulate this value--its type may change in the future and is not part of the supported API.
Linked list of all weak pointers that reference this (some may be on the stack!).
Do not use or explicitly manipulate this value.
The documentation for this class was generated from the following file:
Generated on Thu Aug 2 11:40:48 2007 for G3D by
1.5.2
Hosted by
|