SceneTexture(getDrawable(R.drawable.myDrawable)) // Creating a SceneTexture from drawable in resources SceneTexture(Color.valueOf(Color.BLACK)) // Creating a plain black SceneTexture
class SceneTexture
SceneTexture
(
width
, height
, numberOfMips
, samplerConfig
, color
)
|
Signature
constructor(width: Int, height: Int, numberOfMips: Int, samplerConfig: SamplerConfig = SamplerConfig(), color: Color?) Parameters Returns SceneTexture |
SceneTexture
(
image
, samplerConfig
)
|
Signature
constructor(image: Image, samplerConfig: SamplerConfig = SamplerConfig()) Parameters image: ImagesamplerConfig: SamplerConfigReturns SceneTexture |
SceneTexture
(
bitmap
, samplerConfig
)
|
Signature
constructor(bitmap: Bitmap, samplerConfig: SamplerConfig = SamplerConfig()) Parameters bitmap: BitmapsamplerConfig: SamplerConfigReturns SceneTexture |
SceneTexture
(
drawable
)
| |
SceneTexture
(
color
, samplerConfig
)
|
Signature
constructor(color: Color, samplerConfig: SamplerConfig = SamplerConfig()) Parameters color: ColorsamplerConfig: SamplerConfigReturns SceneTexture |
handle
: Long
[Get] |
Signature
var handle: Long |
clear
(
r
, g
, b
, a
)
|
Clears the texture with a solid color specified by RGBA float values.
Signature
fun clear(r: Float, g: Float, b: Float, a: Float) Parameters r: Float
Red component (0.0 to 1.0)
g: Float
Green component (0.0 to 1.0)
b: Float
Blue component (0.0 to 1.0)
a: Float
Alpha component (0.0 to 1.0)
|
destroy
()
|
Signature
fun destroy() |
nativeHandle
()
|
Signature
fun nativeHandle(): Long Returns Long |
update
(
buffer
, width
, height
, strideInBytes
)
|
Updates the texture with new data.
Signature
fun update(buffer: ByteBuffer, width: Int, height: Int, strideInBytes: Int) Parameters buffer: ByteBuffer
ByteBuffer containing the pixel data
width: Int
Width of the image data in pixels
height: Int
Height of the image data in pixels
strideInBytes: Int
Number of bytes per row in the buffer
|
DEFAULT_TEXTURE_SIZE
: Int
[Get] |
Default texture size for non-bitmap resources (e.g., vector drawables).
Signature
const val DEFAULT_TEXTURE_SIZE: Int = 256 |
calculateMips
(
w
, h
)
|
Calculates the number of mipmap levels for a texture of the given dimensions.
Mipmaps are smaller versions of a texture used for rendering at different distances, which improves rendering quality and performance.
Signature
fun calculateMips(w: Int, h: Int): Int Parameters w: Int
Width of the texture in pixels
h: Int
Height of the texture in pixels
Returns Int
The number of mipmap levels
|
createFromPlatformImage
(
w
, h
, mips
, platformImage
, samplerConfig
)
DeprecatedUse SceneTexture constructor and SceneTexture.update instead. |
Signature
fun createFromPlatformImage(w: Int, h: Int, mips: Int, platformImage: Long, samplerConfig: SamplerConfig = SamplerConfig()): SceneTexture Parameters Returns SceneTexture |
fromBitmapWithScaling
(
originalBitmap
, targetWidth
, targetHeight
, scale
, samplerConfig
)
|
Helper to create a SceneTexture from a bitmap with optional scaling.
Signature
fun fromBitmapWithScaling(originalBitmap: Bitmap, targetWidth: Int?, targetHeight: Int?, scale: Float?, samplerConfig: SamplerConfig): SceneTexture Parameters Returns SceneTexture |
fromResource
(
context
, resourceId
, targetWidth
, targetHeight
, scale
, samplerConfig
)
|
Creates a SceneTexture from an Android drawable resource, automatically converting it to a bitmap and optionally scaling it.
This is a convenience method that handles the common pattern of loading a drawable resource, decoding it to a bitmap, optionally scaling it, and creating a texture.
Size behavior:
Supported resource types:
Example usage:
// Use original bitmap size or intrinsic drawable size val texture = SceneTexture.fromResource(context, R.drawable.my_bitmap) // Scale to 50% of original size val halfSize = SceneTexture.fromResource(context, R.drawable.my_bitmap, scale = 0.5f) // Force specific dimensions (good for vector/shape drawables) val fixedSize = SceneTexture.fromResource(context, R.drawable.my_shape, 512, 512)
Signature
fun fromResource(context: Context, resourceId: Int, targetWidth: Int? = null, targetHeight: Int? = null, scale: Float? = null, samplerConfig: SamplerConfig = SamplerConfig()): SceneTexture Parameters context: Context
Android context used to access resources
resourceId: Int
The drawable resource ID (e.g., R.drawable.my_image)
targetWidth: Int?
Optional target width in pixels. If null, uses intrinsic/original size or default.
targetHeight: Int?
Optional target height in pixels. If null, uses intrinsic/original size or default.
scale: Float?
Optional scale factor applied to the base size (1.0 = no scaling). Ignored if targetWidth/targetHeight are specified.
Throws IllegalArgumentException
if the resource cannot be loaded
|
loadFile
(
assetPath
, samplerConfig
)
|
Loads a SceneTexture from an Android asset file path.
This method loads the image file natively using stb_image via the Android asset manager, supporting PNG, JPG, BMP, TGA, GIF, and other formats. The image is decoded directly to RGBA pixels without going through Android's Bitmap pipeline, avoiding premultiplied alpha issues.
Example usage:
val texture = SceneTexture.loadFile("textures/particle_glow.png")
Signature
fun loadFile(assetPath: String, samplerConfig: SamplerConfig = SamplerConfig()): SceneTexture? Parameters assetPath: String
Path to the file within the assets directory (e.g., "textures/particle_glow.png")
|