Package 

Class Texture


  • 
    public class Texture
    
                        

    Texture

    The Texture class supports:

    • 2D textures
    • 3D textures
    • Cube maps
    • mip mapping
    Usage exampleA Texture object is created using the Texture.Builder and destroyed by calling destroyTexture. They're bound using setParameter.
     Engine engine = Engine.create();
    
     Material material = new Material.Builder()
                 .payload( ... )
                 .build(ending);
    
     MaterialInstance mi = material.getDefaultInstance();
    
     Texture texture = new Texture.Builder()
                 .width(64)
                 .height(64)
                 .build(engine);
    
    
     texture.setImage(engine, 0,
             new Texture.PixelBufferDescriptor( ... ));
    
     mi.setParameter("parameterName", texture, new TextureSampler());
    
    • Constructor Detail

      • Texture

        Texture(long nativeTexture)
    • Method Detail

      • getWidth

         int getWidth(@IntRange(from = 0) int level)

        Queries the width of a given level of this texture.

        Parameters:
        level - to query the with of.
      • getHeight

         int getHeight(@IntRange(from = 0) int level)

        Queries the height of a given level of this texture.

        Parameters:
        level - to query the height of.
      • getDepth

         int getDepth(@IntRange(from = 0) int level)

        Queries the number of layers of given level of this texture has.

        Parameters:
        level - to query the number of layers of.
      • setImage

         void setImage(@NonNull() Engine engine, @IntRange(from = 0) int level, @NonNull() Texture.PixelBufferDescriptor buffer)

        setImage is used to modify the whole content of the texture from a CPU-buffer.

        This Texture instance must use SAMPLER_2D orSAMPLER_EXTERNAL. If the later is specifiedand external textures are supported by the driver implementation,this method will have no effect, otherwise it will behave as if thetexture was specified with SAMPLER_2D.

        This is equivalent to calling: setImage(engine, level, 0, 0, getWidth(level), getHeight(level), buffer)
        Parameters:
        engine - Engine this texture is associated to.
        level - Level to set the image for.
        buffer - Client-side buffer containing the image to set.
      • setImage

         void setImage(@NonNull() Engine engine, @IntRange(from = 0) int level, @IntRange(from = 0) int xoffset, @IntRange(from = 0) int yoffset, @IntRange(from = 0) int width, @IntRange(from = 0) int height, @NonNull() Texture.PixelBufferDescriptor buffer)

        setImage is used to modify a sub-region of the texture from a CPU-buffer.

        This Texture instance must use SAMPLER_2D orSAMPLER_EXTERNAL. If the later is specifiedand external textures are supported by the driver implementation,this method will have no effect, otherwise it will behave as if thetexture was specified with SAMPLER_2D.

        Parameters:
        engine - Engine this texture is associated to.
        level - Level to set the image for.
        xoffset - x-offset in texel of the region to modify
        yoffset - y-offset in texel of the region to modify
        width - width in texel of the region to modify
        height - height in texel of the region to modify
        buffer - Client-side buffer containing the image to set.
      • setImage

         void setImage(@NonNull() Engine engine, @IntRange(from = 0) int level, @IntRange(from = 0) int xoffset, @IntRange(from = 0) int yoffset, @IntRange(from = 0) int zoffset, @IntRange(from = 0) int width, @IntRange(from = 0) int height, @IntRange(from = 0) int depth, @NonNull() Texture.PixelBufferDescriptor buffer)

        setImage is used to modify a sub-region of a 3D texture, 2D texture array orcubemap from a CPU-buffer. Cubemaps are treated like a 2D array of six layers.

        This Texture instance must use SAMPLER_2D_ARRAY,SAMPLER_3D or SAMPLER_CUBEMAP.

        Parameters:
        engine - Engine this texture is associated to.
        level - Level to set the image for.
        xoffset - x-offset in texel of the region to modify
        yoffset - y-offset in texel of the region to modify
        zoffset - z-offset in texel of the region to modify
        width - width in texel of the region to modify
        height - height in texel of the region to modify
        depth - depth in texel or index of the region to modify
        buffer - Client-side buffer containing the image to set.
      • setImage

        @Deprecated() void setImage(@NonNull() Engine engine, @IntRange(from = 0) int level, @NonNull() Texture.PixelBufferDescriptor buffer, @NonNull() @Size(min = 6) Array<int> faceOffsetsInBytes)

        setImage is used to specify all six images of a cubemap level andfollows exactly the OpenGL conventions

        This Texture instance must useSAMPLER_CUBEMAP.

        Parameters:
        engine - Engine this texture is associated to.
        level - Level to set the image for.
        buffer - Client-side buffer containing the image to set.
        faceOffsetsInBytes - Offsets in bytes into buffer for all six images.The offsets are specified in the following order:+x, -x, +y, -y, +z, -z.
      • setExternalImage

         void setExternalImage(@NonNull() Engine engine, long eglImage)

        Specifies the external image to associate with this Texture.

        This Texture instance must useSAMPLER_EXTERNAL.

        Typically the external image is OS specific, and can be a video or camera frame.There are many restrictions when using an external image as a texture, such as:

        • only the level of detail (LOD) 0 can be specified
        • only NEAREST orLINEAR filtering is supported
        • the size and format of the texture is defined by the external image
        Parameters:
        engine - Engine this texture is associated to.
        eglImage - An opaque handle to a platform specific image.
      • setExternalStream

         void setExternalStream(@NonNull() Engine engine, @NonNull() Stream stream)

        Specifies the external stream to associate with this Texture.

        This Texture instance must useSAMPLER_EXTERNAL.

        Typically the external image is OS specific, and can be a video or camera frame.There are many restrictions when using an external image as a texture, such as:

        • only the level of detail (LOD) 0 can be specified
        • only NEAREST orLINEAR filtering is supported
        • the size and format of the texture is defined by the external image
        Parameters:
        engine - Engine this texture is associated to.
        stream - A Stream object
      • generateMipmaps

         void generateMipmaps(@NonNull() Engine engine)

        Generates all the mipmap levels automatically. This requires the texture to have acolor-renderable format.

        This Texture instance must not useSAMPLER_CUBEMAP, or it has no effect.

        Parameters:
        engine - Engine this texture is associated to.
      • generatePrefilterMipmap

         void generatePrefilterMipmap(@NonNull() Engine engine, @NonNull() Texture.PixelBufferDescriptor buffer, @NonNull() @Size(min = 6) Array<int> faceOffsetsInBytes, Texture.PrefilterOptions options)

        Creates a reflection map from an environment map.

        This is a utility function that replaces calls to setImage.The provided environment map is processed and all mipmap levels are populated. Theprocessing is similar to the offline tool cmgen at a lower quality setting.

        This function is intended to be used when the environment cannot be processed offline,for instance if it's generated at runtime.

        The source data must obey to some constraints:

        • the data format must be RGB
        • the data type must be one of
          • FLOAT
          • HALF

        The current texture must be a cubemap.

        The reflections cubemap's internal format cannot be a compressed format.

        The reflections cubemap's dimension must be a power-of-two.

        This operation is computationally intensive, especially with large environments andis currently synchronous. Expect about 1ms for a 16 × 16 cubemap.

        Parameters:
        engine - Engine this texture is associated to.
        buffer - Client-side buffer containing the image to set.
        faceOffsetsInBytes - Offsets in bytes into buffer for all six images.The offsets are specified in the following order:+x, -x, +y, -y, +z, -z.
        options - Optional parameter to control user-specified quality and options.