primaryBitmap
graphics modifies this bitmap's backing data.A Texture contains a primary bitmap at native resolution, along with
cached upscaled and downscaled versions (mipmaps) that are lazily generated on demand.
This mipmap chain enables efficient texture sampling at varying distances from the camera,
avoiding aliasing artifacts for distant surfaces and pixelation for close-up views.
The texture also exposes a Graphics2D context backed by the primary
bitmap's BufferedImage, allowing dynamic rendering of text,
shapes, or other 2D content directly onto the texture surface. Anti-aliasing is
enabled by default on this graphics context.
Mipmap levels
Usage example
Texture tex = new Texture(256, 256, 3);
// Draw content using the Graphics2D context
tex.graphics.setColor(java.awt.Color.RED);
tex.graphics.fillRect(0, 0, 256, 256);
// Invalidate cached mipmaps after modifying the primary bitmap
tex.resetResampledBitmapCache();
// Retrieve the appropriate mipmap for a given zoom level
TextureBitmap bitmap = tex.getZoomedBitmap(0.5);
static class final Graphics2DGraphics2D context for drawing 2D content onto the primary bitmap.final TextureBitmapTexture(int width,
int height,
int maxUpscale) intdetectDownscaleFactorForZoom(double zoom) intdetectUpscaleFactorForZoom(double zoom) downscaleBitmap(TextureBitmap originalBitmap) getDownscaledBitmap(int scaleFactor) getUpscaledBitmap(int scaleFactor) getZoomedBitmap(double zoomLevel) voidupscaleBitmap(TextureBitmap originalBitmap) graphics modifies this bitmap's backing data.Graphics2D context for drawing 2D content onto the primary bitmap.
Anti-aliasing for both geometry and text is enabled by default.The underlying BufferedImage is created using
RenderingContext.bufferedImageType for
compatibility with the raster rendering pipeline.
width - the width of the primary bitmap in pixelsheight - the height of the primary bitmap in pixelsmaxUpscale - the maximum number of upscaled mipmap levels to support
(each level doubles the resolution)Iterates through the downsampled mipmap levels (each halving the size) and returns the index of the first level whose effective size falls below the requested zoom.
zoom - the zoom level (typically less than 1.0 for downscaling)downSampled array to use, clamped to the
maximum available levelIterates through the upsampled mipmap levels (each doubling the size) and returns the index of the first level whose effective size exceeds the requested zoom.
zoom - the zoom level (typically greater than 2.0 for upscaling)upSampled array to use, clamped to the
maximum available leveloriginalBitmap - Bitmap to downscale.Level 0 is half the primary resolution, level 1 is a quarter, and so on. Each level is derived by downscaling the previous level by a factor of 2.
scaleFactor - the downscale level index (0 = 1/2 size, 1 = 1/4 size, etc.)TextureBitmapscaleFactor - The upscale factorzoomLevel - The zoom leveloriginalBitmap - The bitmap to upscale