Class SoTexture2

  • All Implemented Interfaces:
    Direct Known Subclasses:

    public class SoTexture2
    extends SoTexture
    2D texture mapping node. This property node defines a texture map and parameters for that map. This map applies to the current texture unit (see SoTextureUnit) and is used to apply texture to subsequent shapes as they are rendered. The image may be loaded from a file, loaded from an image in memory or created by rendering a scene graph.

    Loading an image

    The texture can be read from a file specified in the filename field. Open Inventor supports most common file formats including: BMP, DDS, GIF, JPEG, PNG and TIFF. See SoRasterImageRW for a complete list. If Open Inventor recognizes the extension part of the file name, for example "png" for a PNG format image, it will automatically use the corresponding image reader (SoPNGImageRW). If the file extension is not recognized, Open Inventor will attempt to determine the actual image file format by opening the file with each of the built-in image file reader classes.

    Note that the image file is read immediately when the filename field is set. If you want to postpone the texture loading, set the loadingMode field to MANUAL before setting the filename field. In this case, you must call loadTexture() to load and display the texture. Alternatively, consider using SoExtTexture2, which defers loading the image until the texture node is actually traversed.

    Once the texture has been read, the image field contains the texture data. However, this field is marked so the image is not written out when the texture node is written to a file. To turn off texturing, set the filename field to an empty string ("").

    DDS format files load faster because the compressed image can be sent directly to the graphics hardware. This format can also embed mipmaps (levels of resolution). Note that the image field is not filled with the image data when using DDS files. DDS format is not supported on all hardware. The GL_EXT_texture_compression_s3tc extension is required. If it is not available, the DDS texture is not loaded.

    Textures can also be specified in memory by setting the image field to contain the texture data. Doing so resets the filename to the empty string.

    Textures can also be rendered from a scene graph using the renderToTextureProperty field. If a value is specified for this field, the image and filename fields are ignored.

    Modifying a texture image

    You can modify a subset of the image without causing the OpenGL texture to be recreated. Open Inventor will automatically use glTexSubImage2D if the image is modified using the SoSFImage.setSubValue() method. This is much more efficient than using the startEditing and finishEditing methods because when these methods are used Open Inventor must assume that the entire image has been modified.

    Texture quality

    The SoTexture.minFilter and SoTexture.magFilter fields can be used to specifically control the texture minification and magnification "filter" algorithms used by the GPU. The minification filter is used when the rendered size of the geometry is smaller than the texture image (for example: far away objects). Conversely the magnification filter is used when the rendered size of the geometry is larger than the texture image (near objects). Effectively these settings control whether the GPU will select the "nearest" texel value or do linear interpolation (smoothing) or (in the case of minification) interpolate between mipmap levels. Using NEAREST may allow better performance, but the LINEAR options produce much higher quality rendering. If mipmap filtering is required, mipmaps are automatically created.

    NOTE: The default value for these SoTexture fields is AUTO, meaning that the minification and magnification algorithms are actually controlled by the SoComplexity.textureQuality field. To maximize performance, the default value for textureQuality is 0.5, which selects NEAREST filtering. For best image quality we recommend setting this field to (at least) 0.75.


    Texture images can contain transparency (alpha values less than 1) and modify the transparency of geometry in the scene. Also note that some image file formats, for example JPEG, do not support transparency information (alpha channel).

    Non-power-of-two images

    If the texture image's width or height is not a power of 2, e.g. 128 or 256, and the Non Power Of Two (NPOT) extension is available on your graphics board, by default Open Inventor will send the image to OpenGL without modification. Almost all modern graphics hardware support this extension (check using SoTexture.isSupported(HW_NPOT)). However if your application must run on graphics hardware that does not support NPOT, please read the following.

    If the texture image's width or height is not a power of 2 (and the Non Power Of Two (NPOT) extension is not available on your graphics board), or the image's width or height is greater than the maximum supported by OpenGL, then the image will be automatically scaled up or down to the nearest power of 2 or the maximum texture size. For maximum speed, point-sampling is used to do the scaling. If you want higher quality scaling, pre-filter your images to a power of 2 smaller than the maximum texture size. Use the OpenGL glGetIntegerv(GL_MAX_TEXTURE_SIZE...) call to determine the maximum texture dimension for a specific OpenGL implementation. Setting the environment variable OIV_USE_NPOT to 0 will force the image to be rescaled (when necessary) even if the NPOT extension is available.

    Performance Note: Automatic scaling of texture images to a power of 2 is a very convenient feature for prototyping, but it does take additional time the first time the texture node is traversed for rendering. For large images, or a large number of images, this can make the application seem slow while starting up or loading a new data file. Avoid this effect by either pre-scaling the image or by storing it as a sub-image in a "power of 2" image (then provide explicit texture coordinates such that only the sub-image is used). (Not applicable if GPU supports non-power-of-2 images. Most do.)

    Performance Note: The performance advantage of modifying a sub-image is significantly less when the texture image needs to be automatically scaled to a power of 2. This is because each sub-image must be scaled before sending it to OpenGL. (Not applicable if GPU supports non-power-of-2 images. Most do.)

    File format/default:

    Texture2 {

      filename ""
      image 0 0 0
      wrapS REPEAT
      wrapT REPEAT
      model MODULATE
      enableCompressedTexture false
      blendColor 0 0 0
      enableBorder false
      borderColor 0 0 0 1
      maxAnisotropy 1.0
      minFilter AUTO
      magFilter AUTO
      loadingMode AUTO
      useAutoMipmap false
      internalFormat AUTO_INTERNAL_FORMAT
      renderToTextureProperty NULL

    Action behavior:

    SoGLRenderAction, SoCallbackAction
    Sets current texture in state. Sets: SoTextureImageElement, SoTextureEnabledElement

    See Also:
    SoComplexity, SoExtTexture2, SoMaterial, SoTexture, SoTexture2Transform, SoTexture3, SoTextureCombiner, SoTextureCoordinate2, SoTextureCoordinateBinding, SoTextureCoordinateFunction, SoTextureCubeMap, SoTextureUnit
    • Field Detail

      • filename

        public final SoSFFilePathString filename
        Name of the file from which to read texture image.
        The standard image file formats are supported. See SoRasterImageRW for the list. If the filename is not an absolute path name, the list of directories maintained by SoInput is searched. If the texture is not found in any of those directories, then the file is searched for relative to the directory from which the SoTexture2 node was read. For example, if an SoTexture2 node with a filename of "../tofu.rgb" is read from /usr/people/bob/models/food.iv, then /usr/people/bob/tofu.rgb will be read (assuming tofu.rgb isn't found in the directories maintained by SoInput).
      • image

        public final SoSFImage image
        Contains an in-memory representation of the texture map. It is either the contents of the file read from filename, an image read directly from an Open Inventor file, or an image set programmatically using the methods provided by SoSFImage.
      • wrapT

        public final SoSFEnum<SoTexture.WrapType> wrapT
        Indicates what to do when texture coordinates in the T (vertical) direction lie outside the range 0-1. . Default is REPEAT.
      • renderToTextureProperty

        public final SoSFNode renderToTextureProperty
        Specifies an SoRenderToTextureProperty node containing a scene graph that will be rendered to create the texture image. Null by default.

        NOTE: The image field is not updated when the scene graph is rendered. That would require reading back the frame buffer from the graphics board, which can be time consuming and would reduce performance.

        Open Inventor 6.0

    • Constructor Detail

      • SoTexture2

        public SoTexture2()
        Creates a texture node with default settings.
    • Method Detail

      • loadTexture

        public void loadTexture()
        Loads the texture if the loadingMode field is set to MANUAL.