Class Texture
- java.lang.Object
-
- com.google.android.filament.Texture
-
public class Texture extends java.lang.ObjectTextureThe
Textureclass supports:- 2D textures
- 3D textures
- Cube maps
- mip mapping
Usage example
ATextureobject is created using theTexture.Builderand destroyed by callingEngine.destroyTexture(com.google.android.filament.Texture). They're bound usingMaterialInstance.setParameter(java.lang.String, boolean).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());
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classTexture.BuilderUseBuilderto construct aTextureobject instance.static classTexture.CompressedFormatCompressed data types for use withTexture.PixelBufferDescriptorstatic classTexture.CubemapFaceCubemap facesstatic classTexture.FormatPixel color formatstatic classTexture.InternalFormatInternal texel formatsstatic classTexture.PixelBufferDescriptorA descriptor to an image in main memory, typically used to transfer image data from the CPU to the GPU.static classTexture.PrefilterOptionsstatic classTexture.SamplerType of samplerstatic classTexture.SwizzleTexture swizzling channelsstatic classTexture.TypePixel data typestatic classTexture.UsageA bitmask to specify how the texture will be used.
-
Field Summary
Fields Modifier and Type Field Description static intBASE_LEVEL
-
Constructor Summary
Constructors Constructor Description Texture(long nativeTexture)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidgenerateMipmaps(Engine engine)Generates all the mipmap levels automatically.voidgeneratePrefilterMipmap(Engine engine, Texture.PixelBufferDescriptor buffer, int[] faceOffsetsInBytes, Texture.PrefilterOptions options)Creates a reflection map from an environment map.intgetDepth(int level)Queries the number of layers of given level of this texture has.Texture.InternalFormatgetFormat()intgetHeight(int level)Queries the height of a given level of this texture.intgetLevels()longgetNativeObject()Texture.SamplergetTarget()intgetWidth(int level)Queries the width of a given level of this texture.static booleanisTextureFormatSupported(Engine engine, Texture.InternalFormat format)Checks whether a given format is supported for texturing in thisEngine.static booleanisTextureSwizzleSupported(Engine engine)Checks whether texture swizzling is supported in thisEngine.voidsetExternalImage(Engine engine, long eglImage)Specifies the external image to associate with thisTexture.voidsetExternalStream(Engine engine, Stream stream)Specifies the external stream to associate with thisTexture.voidsetImage(Engine engine, int level, int xoffset, int yoffset, int zoffset, int width, int height, int depth, Texture.PixelBufferDescriptor buffer)setImageis used to modify a sub-region of the 3D texture or 2D texture array from a CPU-buffer.voidsetImage(Engine engine, int level, int xoffset, int yoffset, int width, int height, Texture.PixelBufferDescriptor buffer)setImageis used to modify a sub-region of the texture from a CPU-buffer.voidsetImage(Engine engine, int level, Texture.PixelBufferDescriptor buffer)setImageis used to modify the whole content of the texure from a CPU-buffer.voidsetImage(Engine engine, int level, Texture.PixelBufferDescriptor buffer, int[] faceOffsetsInBytes)setImageis used to specify all six images of a cubemap level and follows exactly the OpenGL conventions
-
-
-
Field Detail
-
BASE_LEVEL
public static final int BASE_LEVEL
- See Also:
- Constant Field Values
-
-
Method Detail
-
isTextureFormatSupported
public static boolean isTextureFormatSupported(@NonNull Engine engine, @NonNull Texture.InternalFormat format)Checks whether a given format is supported for texturing in thisEngine. This depends on the selected backend.- Parameters:
engine-Engineto test theInternalFormatagainstformat- format to check- Returns:
trueif this format is supported for texturing.
-
isTextureSwizzleSupported
public static boolean isTextureSwizzleSupported(@NonNull Engine engine)Checks whether texture swizzling is supported in thisEngine. This depends on the selected backend.- Parameters:
engine-Engine- Returns:
trueif 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 andgetLevels()- 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 andgetLevels()- 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 andgetLevels()- Returns:
- The number of layers of the given level
-
getLevels
public int getLevels()
- Returns:
- the number of mipmap levels of this texture
-
getTarget
@NonNull public Texture.Sampler getTarget()
- Returns:
- This texture
Samplertype.
-
getFormat
@NonNull public Texture.InternalFormat getFormat()
- Returns:
- This texture's
InternalFormat.
-
setImage
public void setImage(@NonNull Engine engine, @IntRange(from=0L) int level, @NonNull Texture.PixelBufferDescriptor buffer)setImageis used to modify the whole content of the texure from a CPU-buffer.This
This is equivalent to calling:Textureinstance must useSAMPLER_2DorSAMPLER_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 withSAMPLER_2D.
setImage(engine, level, 0, 0, getWidth(level), getHeight(level), buffer)- Parameters:
engine-Enginethis texture is associated to. Must be the instance passed toBuilder.build().level- Level to set the image for. Must be less thangetLevels().buffer- Client-side buffer containing the image to set.buffer'sformatmust match that ofgetFormat()- Throws:
java.nio.BufferOverflowException- if the specified parameters would result in reading outside ofbuffer.- 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)setImageis used to modify a sub-region of the texture from a CPU-buffer.This
Textureinstance must useSAMPLER_2DorSAMPLER_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 withSAMPLER_2D.- Parameters:
engine-Enginethis texture is associated to. Must be the instance passed toBuilder.build().level- Level to set the image for. Must be less thangetLevels().xoffset- x-offset in texel of the region to modifyyoffset- y-offset in texel of the region to modifywidth- width in texel of the region to modifyheight- height in texel of the region to modifybuffer- Client-side buffer containing the image to set.buffer'sformatmust match that ofgetFormat()- Throws:
java.nio.BufferOverflowException- if the specified parameters would result in reading outside ofbuffer.- 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)setImageis used to modify a sub-region of the 3D texture or 2D texture array from a CPU-buffer.This
Textureinstance must useSAMPLER_2D_ARRAYorSAMPLER_3D.- Parameters:
engine-Enginethis texture is associated to. Must be the instance passed toBuilder.build().level- Level to set the image for. Must be less thangetLevels().xoffset- x-offset in texel of the region to modifyyoffset- y-offset in texel of the region to modifyzoffset- z-offset in texel of the region to modifywidth- width in texel of the region to modifyheight- height in texel of the region to modifydepth- depth in texel or index of the region to modifybuffer- Client-side buffer containing the image to set.buffer'sformatmust match that ofgetFormat()- Throws:
java.nio.BufferOverflowException- if the specified parameters would result in reading outside ofbuffer.- 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)setImageis used to specify all six images of a cubemap level and follows exactly the OpenGL conventionsThis
Textureinstance must useSAMPLER_CUBEMAP.- Parameters:
engine-Enginethis texture is associated to. Must be the instance passed toBuilder.build().level- Level to set the image for. Must be less thangetLevels().buffer- Client-side buffer containing the image to set.buffer'sformatmust match that ofgetFormat()faceOffsetsInBytes- Offsets in bytes intobufferfor all six images. The offsets are specified in the following order: +x, -x, +y, -y, +z, -z.faceOffsetsInBytesare offsets in byte in thebufferrelative to the currentBuffer.position(). UseTexture.CubemapFaceto index thefaceOffsetsInBytesarray. All six faces must be tightly packed.- Throws:
java.nio.BufferOverflowException- if the specified parameters would result in reading outside ofbuffer.- 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 thisTexture.This
Textureinstance 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:
- Parameters:
engine-Enginethis texture is associated to. Must be the instance passed toBuilder.build().eglImage- An opaque handle to a platform specific image. Supported types areeglImageOESon Android andCVPixelBufferRefon iOS.On iOS the following pixel formats are supported:
kCVPixelFormatType_32BGRAkCVPixelFormatType_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 thisTexture.This
Textureinstance 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:
- Parameters:
engine-Enginethis texture is associated to. Must be the instance passed toBuilder.build().stream- AStreamobject- Throws:
java.lang.IllegalStateException- if the sampler type is notSAMPLER_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
Textureinstance must not useSAMPLER_CUBEMAP, or it has no effect.- Parameters:
engine-Enginethis texture is associated to. Must be the instance passed toBuilder.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 toolcmgenat 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
formatmust beTexture.Format.RGB - the data
typemust be one of
The current texture must be a cubemap.
The reflections cubemap's
internal formatcannot 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-Enginethis texture is associated to. Must be the instance passed toBuilder.build().buffer- Client-side buffer containing the image to set.buffer'sformatandtypemust match the constraints above.faceOffsetsInBytes- Offsets in bytes intobufferfor 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.faceOffsetsInBytesare offsets in byte in thebufferrelative to the currentBuffer.position(). UseTexture.CubemapFaceto index thefaceOffsetsInBytesarray. All six faces must be tightly packed.- Throws:
java.nio.BufferOverflowException- if the specified parameters would result in reading outside ofbuffer.
- the data
-
getNativeObject
public long getNativeObject()
-
-