Class Texture

    • Constructor Detail

      • Texture

        public Texture​(long nativeTexture)
    • Method Detail

      • isTextureFormatSupported

        public static boolean isTextureFormatSupported​(@NonNull
                                                       Engine engine,
                                                       @NonNull
                                                       Texture.InternalFormat format)
        Checks whether a given format is supported for texturing in this Engine. This depends on the selected backend.
        Parameters:
        engine - Engine to test the InternalFormat against
        format - format to check
        Returns:
        true if this format is supported for texturing.
      • isTextureSwizzleSupported

        public static boolean isTextureSwizzleSupported​(@NonNull
                                                        Engine engine)
        Checks whether texture swizzling is supported in this Engine. This depends on the selected backend.
        Parameters:
        engine - Engine
        Returns:
        true if texture swizzling.
      • getWidth

        public int getWidth​(@IntRange(from=0L)
                            int level)
        Queries the width of a given level of this texture.
        Parameters:
        level - to query the with of. Must be between 0 and getLevels()
        Returns:
        The width in texel of the given level
      • getHeight

        public int getHeight​(@IntRange(from=0L)
                             int level)
        Queries the height of a given level of this texture.
        Parameters:
        level - to query the height of. Must be between 0 and getLevels()
        Returns:
        The height in texel of the given level
      • getDepth

        public int getDepth​(@IntRange(from=0L)
                            int level)
        Queries the number of layers of given level of this texture has.
        Parameters:
        level - to query the number of layers of. Must be between 0 and getLevels()
        Returns:
        The number of layers of the given level
      • getLevels

        public int getLevels()
        Returns:
        the number of mipmap levels of this texture
      • setImage

        public void setImage​(@NonNull
                             Engine engine,
                             @IntRange(from=0L)
                             int level,
                             @NonNull
                             Texture.PixelBufferDescriptor buffer)
        setImage is used to modify the whole content of the texure from a CPU-buffer.

        This Texture instance must use SAMPLER_2D or SAMPLER_EXTERNAL. If the later is specified and external textures are supported by the driver implementation, this method will have no effect, otherwise it will behave as if the texture 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. Must be the instance passed to Builder.build().
        level - Level to set the image for. Must be less than getLevels().
        buffer - Client-side buffer containing the image to set. buffer's format must match that of getFormat()
        Throws:
        java.nio.BufferOverflowException - if the specified parameters would result in reading outside of buffer.
        See Also:
        Texture.Builder.sampler(com.google.android.filament.Texture.Sampler), Texture.PixelBufferDescriptor
      • setImage

        public void setImage​(@NonNull
                             Engine engine,
                             @IntRange(from=0L)
                             int level,
                             @IntRange(from=0L)
                             int xoffset,
                             @IntRange(from=0L)
                             int yoffset,
                             @IntRange(from=0L)
                             int width,
                             @IntRange(from=0L)
                             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 or SAMPLER_EXTERNAL. If the later is specified and external textures are supported by the driver implementation, this method will have no effect, otherwise it will behave as if the texture was specified with SAMPLER_2D.

        Parameters:
        engine - Engine this texture is associated to. Must be the instance passed to Builder.build().
        level - Level to set the image for. Must be less than getLevels().
        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. buffer's format must match that of getFormat()
        Throws:
        java.nio.BufferOverflowException - if the specified parameters would result in reading outside of buffer.
        See Also:
        Texture.Builder.sampler(com.google.android.filament.Texture.Sampler), Texture.PixelBufferDescriptor
      • setImage

        public void setImage​(@NonNull
                             Engine engine,
                             @IntRange(from=0L)
                             int level,
                             @IntRange(from=0L)
                             int xoffset,
                             @IntRange(from=0L)
                             int yoffset,
                             @IntRange(from=0L)
                             int zoffset,
                             @IntRange(from=0L)
                             int width,
                             @IntRange(from=0L)
                             int height,
                             @IntRange(from=0L)
                             int depth,
                             @NonNull
                             Texture.PixelBufferDescriptor buffer)
        setImage is used to modify a sub-region of the 3D texture or 2D texture array from a CPU-buffer.

        This Texture instance must use SAMPLER_2D_ARRAY or SAMPLER_3D.

        Parameters:
        engine - Engine this texture is associated to. Must be the instance passed to Builder.build().
        level - Level to set the image for. Must be less than getLevels().
        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. buffer's format must match that of getFormat()
        Throws:
        java.nio.BufferOverflowException - if the specified parameters would result in reading outside of buffer.
        See Also:
        Texture.Builder.sampler(com.google.android.filament.Texture.Sampler), Texture.PixelBufferDescriptor
      • setImage

        public void setImage​(@NonNull
                             Engine engine,
                             @IntRange(from=0L)
                             int level,
                             @NonNull
                             Texture.PixelBufferDescriptor buffer,
                             @NonNull @Size(min=6L)
                             int[] faceOffsetsInBytes)
        setImage is used to specify all six images of a cubemap level and follows exactly the OpenGL conventions

        This Texture instance must use SAMPLER_CUBEMAP.

        Parameters:
        engine - Engine this texture is associated to. Must be the instance passed to Builder.build().
        level - Level to set the image for. Must be less than getLevels().
        buffer - Client-side buffer containing the image to set. buffer's format must match that of getFormat()
        faceOffsetsInBytes - Offsets in bytes into buffer for all six images. The offsets are specified in the following order: +x, -x, +y, -y, +z, -z.

        faceOffsetsInBytes are offsets in byte in the buffer relative to the current Buffer.position(). Use Texture.CubemapFace to index the faceOffsetsInBytes array. All six faces must be tightly packed.

        Throws:
        java.nio.BufferOverflowException - if the specified parameters would result in reading outside of buffer.
        See Also:
        Texture.Builder.sampler(com.google.android.filament.Texture.Sampler), Texture.PixelBufferDescriptor
      • setExternalImage

        public void setExternalImage​(@NonNull
                                     Engine engine,
                                     long eglImage)
        Specifies the external image to associate with this Texture.

        This Texture instance must use SAMPLER_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 or LINEAR filtering is supported
        • the size and format of the texture is defined by the external image
        Parameters:
        engine - Engine this texture is associated to. Must be the instance passed to Builder.build().
        eglImage - An opaque handle to a platform specific image. Supported types are eglImageOES on Android and CVPixelBufferRef on iOS.

        On iOS the following pixel formats are supported:

        • kCVPixelFormatType_32BGRA
        • kCVPixelFormatType_420YpCbCr8BiPlanarFullRange

        See Also:
        Texture.Builder.sampler(com.google.android.filament.Texture.Sampler)
      • setExternalStream

        public void setExternalStream​(@NonNull
                                      Engine engine,
                                      @NonNull
                                      Stream stream)
        Specifies the external stream to associate with this Texture.

        This Texture instance must use SAMPLER_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 or LINEAR filtering is supported
        • the size and format of the texture is defined by the external image
        Parameters:
        engine - Engine this texture is associated to. Must be the instance passed to Builder.build().
        stream - A Stream object
        Throws:
        java.lang.IllegalStateException - if the sampler type is not SAMPLER_EXTERNAL
        See Also:
        Stream, Texture.Builder.sampler(com.google.android.filament.Texture.Sampler)
      • generateMipmaps

        public void generateMipmaps​(@NonNull
                                    Engine engine)
        Generates all the mipmap levels automatically. This requires the texture to have a color-renderable format.

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

        Parameters:
        engine - Engine this texture is associated to. Must be the instance passed to Builder.build().
      • generatePrefilterMipmap

        public void generatePrefilterMipmap​(@NonNull
                                            Engine engine,
                                            @NonNull
                                            Texture.PixelBufferDescriptor buffer,
                                            @NonNull @Size(min=6L)
                                            int[] faceOffsetsInBytes,
                                            Texture.PrefilterOptions options)
        Creates a reflection map from an environment map.

        This is a utility function that replaces calls to setImage(com.google.android.filament.Engine, int, com.google.android.filament.Texture.PixelBufferDescriptor). The provided environment map is processed and all mipmap levels are populated. The processing 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 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 and is currently synchronous. Expect about 1ms for a 16 × 16 cubemap.

        Parameters:
        engine - Engine this texture is associated to. Must be the instance passed to Builder.build().
        buffer - Client-side buffer containing the image to set. buffer's format and type must match the constraints above.
        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.

        faceOffsetsInBytes are offsets in byte in the buffer relative to the current Buffer.position(). Use Texture.CubemapFace to index the faceOffsetsInBytes array. All six faces must be tightly packed.

        Throws:
        java.nio.BufferOverflowException - if the specified parameters would result in reading outside of buffer.
      • getNativeObject

        public long getNativeObject()