Coin
4.0.3
Coin3D core library
|
The SoGLImage class is used to handle OpenGL 2D/3D textures. More...
#include <include/Inventor/misc/SoGLImage.h>
Public Types | |
enum | Flags { SCALE_DOWN = 0x0001 , NO_MIPMAP = 0x0002 , LINEAR_MAG_FILTER = 0x0004 , LINEAR_MIN_FILTER = 0x0008 , LINEAR_MIPMAP_FILTER = 0x0010 , FORCE_TRANSPARENCY_TRUE = 0x0020 , FORCE_TRANSPARENCY_FALSE = 0x0040 , FORCE_ALPHA_TEST_TRUE = 0x0080 , FORCE_ALPHA_TEST_FALSE = 0x0100 , INVINCIBLE = 0x0200 , RECTANGLE = 0x0400 , COMPRESSED = 0x0800 , USE_QUALITY_VALUE = 0X8000 } |
enum | ResizeReason { IMAGE = 0 , SUBIMAGE , MIPMAP } |
typedef SbBool | SoGLImageResizeCB(SoState *state, const SbVec3s &newsize, unsigned char *destbuffer, ResizeReason reason, void *closure, class SoGLImage *image) |
enum | Wrap { REPEAT = 0 , CLAMP , CLAMP_TO_EDGE , CLAMP_TO_BORDER } |
Static Public Member Functions | |
static void | beginFrame (SoState *state) |
static void | endFrame (SoState *state) |
static void | freeAllImages (SoState *state=NULL) |
static SoType | getClassTypeId (void) |
static void | initClass (void) |
static void | setDisplayListMaxAge (const uint32_t maxage) |
static void | setResizeCallback (SoGLImageResizeCB *f, void *closure) |
static void | tagImage (SoState *state, SoGLImage *image) |
Protected Member Functions | |
virtual | ~SoGLImage () |
void | incAge (void) const |
void | resetAge (void) const |
virtual void | unrefOldDL (SoState *state, const uint32_t maxage) |
The SoGLImage class is used to handle OpenGL 2D/3D textures.
A number of environment variables can be set to control how textures are created. This is useful to tune Coin to fit your system. E.g. if you are running on a laptop, it might be a good idea to disable linear filtering and mipmaps.
Be aware that this class is an extension for Coin, and it is not available in the original SGI Open Inventor v2.1 API.
bool SoGLImage::SoGLImageResizeCB |
Image resize callback type. If registered using setResizeCallback(), this function will be called whenever Coin needs to resize an image. The function will be called both for 2D and 3D images.
state is the current state at the time of resizing. newsize is the requested new image size. Note that the z size of a 2D image is 0. destbuffer is a preallocated buffer big enough to hold the pixels for the resized image. The # of bytes per pixel is the same as for the original image. reason is a hint about why the image is resized. At the moment, only IMAGE is supported. image is the original image.
Return value: TRUE if the resize has been resized, FALSE if not. If FALSE is returned, Coin will resize the image instead.
Can be used to tune/optimize the GL texture handling. Normally the texture quality will be used to decide scaling and filtering, and the image data will be scanned to decide if the image is (partially) transparent, and if the texture can be rendered using the cheaper alpha test instead of blending if it does contain transparency. If you know the contents of your texture image, or if you have special requirements on how the texture should be rendered, you can set the flags using the SoGLImage::setFlags() method.
Sent as a parameter to SoGLImageResizeCB as a hint to why an image is being resized. IMAGE means that a whole image is being initially resized (e.g. a texture image). SUBIMAGE and MIPMAP are not in use and reserved for future use.
Used to specify how texture coordinates < 0.0 and > 1.0 should be handled. It can either be repeated (REPEAT), clamped (CLAMP) or clamped to edge (CLAMP_TO_EDGE), which is useful when tiling textures. Since 2002-11-18, CLAMP will be treated as CLAMP_TO_EDGE. The environment variable COIN_ENABLE_CONFORMANT_GL_CLAMP can be used to override this behaviour.
SoGLImage::SoGLImage | ( | void | ) |
Constructor.
|
protectedvirtual |
Destructor.
When doing texture resource control, call this method before rendering the scene, typically in the viewer's actualRedraw(). state should be your SoGLRenderAction state.
Should be called after your scene is rendered. Old display lists will be deleted when you call this method. state should be your SoGLRenderAction state.
Free all GL images currently used. This can be used to help the operating system and/or OpenGL driver's resource handling. If you know you're not going to render for a while, maybe you're switching to a different application or something, calling this method could be a good idea since it will release all the texture memory used by your application.
This static method returns the SoType object associated with objects of this class.
uint32_t SoGLImage::getFlags | ( | void | ) | const |
Returns the flags.
|
virtual |
Returns or creates a SoGLDisplayList to be used for rendering. Returns NULL if no SoGLDisplayList could be created.
Reimplemented in SoGLBigImage, and SoGLCubeMapImage.
uint32_t SoGLImage::getGLImageId | ( | void | ) | const |
Returns an unique id for this GL image. This id can be used to test for changes in an SoGLImage's internal data.
float SoGLImage::getQuality | ( | void | ) | const |
Returns the texture quality for this texture image.
Returns the type identification of an object derived from a class inheriting SoGLImage. This is used for runtime type checking and "downward" casting.
Reimplemented in SoGLBigImage, and SoGLCubeMapImage.
SoGLImage::Wrap SoGLImage::getWrapR | ( | void | ) | const |
Returns the wrap strategy for the R (depth) direction.
SoGLImage::Wrap SoGLImage::getWrapS | ( | void | ) | const |
Returns the wrap strategy for the S (horizontal) direction.
SoGLImage::Wrap SoGLImage::getWrapT | ( | void | ) | const |
Returns the wrap strategy for the T (vertical) direction.
SbBool SoGLImage::hasTransparency | ( | void | ) | const |
Returns TRUE if this texture has some pixels with alpha value != 255
This static method initializes static data for the SoGLImage class.
|
virtual |
Returns TRUE
if the type of this object is either of the same type or inherited from type. This is used for runtime type checking and "downward" casting.
|
virtual |
Sets the data for this GL image. Should only be called when one of the parameters have changed, since this will cause the GL texture object to be recreated. Caller is responsible for sending legal wrap values. CLAMP_TO_EDGE is only supported on OpenGL v1.2 implementations, and as an extension on some earlier SGI implementations (GL_SGIS_texture_edge_clamp).
For now, if quality > 0.5 when created, we create mipmaps, otherwise a regular texture is created. Be aware, if you for instance create a texture with texture quality 0.4, and then later try to apply the texture with a texture quality greater than 0.5, the texture object will be recreated as a mipmap texture object. This will happen only once though, of course.
If border != 0, the OpenGL texture will be created with this border size. Be aware that this might be extremely slow on most PC hardware.
Normally, the OpenGL texture object isn't created until the first time it is needed, but if createinstate is != NULL, the texture object is created immediately. This is useful if you use a temporary buffer to hold the texture data. Be careful when using this feature, since the texture data might be needed at a later stage (for instance to create a texture object for another context). It will not be possible to create texture objects for other cache contexts when createinstate is != NULL.
Also if createinstate is supplied, and all the attributes are the same as the current data in the image, glTexSubImage() will be used to insert the image data instead of creating a new texture object. This is much faster on most OpenGL drivers, and is very useful, for instance when doing animated textures.
If you supply NULL for image, the instance will be reset, causing all display lists and memory to be freed.
Reimplemented in SoGLBigImage, and SoGLCubeMapImage.
|
virtual |
Convenience 2D wrapper function around the 3D setData().
Reimplemented in SoGLBigImage, and SoGLCubeMapImage.
Set the maximum age for a texture object/display list. The age of an image is the number of frames since it has been used. Default maximum age is 60.
Sets flags to control how the texture is handled/initialized.
void SoGLImage::setGLDisplayList | ( | SoGLDisplayList * | dl, |
SoState * | state, | ||
const Wrap | wraps = REPEAT, | ||
const Wrap | wrapt = REPEAT, | ||
const float | quality = 0.5f ) |
Can be used for creating a custom OpenGL texture inside an SoGLImage instance.
Example use (creates a depth texture):
SoGLDisplayList * depthmap = new SoGLDisplayList(state, SoGLDisplayList::TEXTURE_OBJECT); depthmap->ref(); depthmap->open(state);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, // GL_DEPTH_COMPONENT24 size[0], size[1], 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
depthmap->close(state);
SoGLImage * image = new SoGLImage; image->setGLDisplayList(depthmap, state);
void SoGLImage::setPBuffer | ( | SoState * | state, |
void * | pbuffer, | ||
const Wrap | wraps = REPEAT, | ||
const Wrap | wrapt = REPEAT, | ||
const float | quality = 0.5f ) |
Sets the pbuffer for this texture. Experimental code, use with care.
|
static |
Sets a custom image resize function.
Should be called when a texture image is used. In Coin this is handled by SoGLTextureImageElement, but if you use an SoGLImage on your own, you should call this method to avoid that the display list is deleted too soon. state should be your SoGLRenderAction state, image the image you are about to use/have used.
This class has a private destructor since we want users to supply the current GL state when deleting the image. This is to make sure GL texture objects are freed as soon as possible. If you supply NULL to this method, the GL texture objects won't be deleted until the next time an GLRenderAction is applied in the image's cache context(s).
Reimplemented in SoGLBigImage, and SoGLCubeMapImage.
Virtual method that will be called once each frame. The method should unref display lists that have an age bigger or equal to maxage, and increment the age for other display lists.
Reimplemented in SoGLBigImage.
SbBool SoGLImage::useAlphaTest | ( | void | ) | const |
Returns TRUE if this image has some alpha value != 255, and all these values are 0. If this is the case, alpha test can be used to render this texture instead of for instance blending, which is usually slower and might yield z-buffer artifacts.