Package icyllis.modernui.graphics
Class ImageShader
java.lang.Object
icyllis.modernui.graphics.Shader
icyllis.modernui.graphics.ImageShader
Shader used to draw an image as a texture. The image can be repeated or
mirrored by setting the tiling mode.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic @interfaceTheFilterModespecifies the sampling method on transformed texture images.static @interfaceTheMipmapModespecifies the interpolation method for MIP image levels when down-sampling texture images.Nested classes/interfaces inherited from class icyllis.modernui.graphics.Shader
Shader.TileMode -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final ObjectUse bicubic sampling, the Catmull-Rom spline with B=0, C=0.5.static final ObjectUse bicubic sampling, the cubic B-spline with B=1, C=0.static final ObjectUse linear interpolation for minification, magnification; no mipmapping.static final ObjectUse bicubic sampling, the Mitchell–Netravali filter with B=1/3, C=1/3.static final intInterpolate between 2x2 sample points (bilinear interpolation).static final intSingle sample point (nearest neighbor).static final ObjectUse bicubic sampling, the Photoshop bicubic filter with B=0, C=0.75.static final ObjectUse nearest-neighbour sampling for minification, magnification; no mipmapping.static final intInterpolate between the two nearest levels.static final intSample from the nearest level.static final intIgnore mipmap levels, sample from the "base". -
Constructor Summary
ConstructorsConstructorDescriptionImageShader(Image image, Shader.TileMode tileModeX, Shader.TileMode tileModeY, int filter, int mipmap, Matrix localMatrix) Create a new shader for the given image.ImageShader(Image image, Shader.TileMode tileModeX, Shader.TileMode tileModeY, int filter, Matrix localMatrix) Create a new shader for the given image.ImageShader(Image image, Shader.TileMode tileModeX, Shader.TileMode tileModeY, Object filter, Matrix localMatrix) Create a new shader for the given image. -
Method Summary
Modifier and TypeMethodDescriptioncopyWithLocalMatrix(Matrix newLocalMatrix, boolean discardThis) Create a new ImageShader that replaces its local matrix with a new local matrix.booleangetLocalMatrix(Matrix localMatrix) Return true if the shader has a non-identity local matrix.booleanlocalMatrixEquals(Matrix localMatrix) Return true if the local matrix of the shader is equal to the given local matrix.
-
Field Details
-
FILTER_MODE_NEAREST
public static final int FILTER_MODE_NEARESTSingle sample point (nearest neighbor).- See Also:
-
FILTER_MODE_LINEAR
public static final int FILTER_MODE_LINEARInterpolate between 2x2 sample points (bilinear interpolation).- See Also:
-
MIPMAP_MODE_NONE
public static final int MIPMAP_MODE_NONEIgnore mipmap levels, sample from the "base".- See Also:
-
MIPMAP_MODE_NEAREST
public static final int MIPMAP_MODE_NEARESTSample from the nearest level.- See Also:
-
MIPMAP_MODE_LINEAR
public static final int MIPMAP_MODE_LINEARInterpolate between the two nearest levels.- See Also:
-
FILTER_POINT
Use nearest-neighbour sampling for minification, magnification; no mipmapping. Also known as point sampling. -
FILTER_LINEAR
Use linear interpolation for minification, magnification; no mipmapping. Also known as triangle sampling and bilinear sampling. -
FILTER_CUBIC_BSPLINE
Use bicubic sampling, the cubic B-spline with B=1, C=0. -
FILTER_MITCHELL
Use bicubic sampling, the Mitchell–Netravali filter with B=1/3, C=1/3. -
FILTER_PHOTOSHOP_BICUBIC
Use bicubic sampling, the Photoshop bicubic filter with B=0, C=0.75. -
FILTER_CATMULLROM
Use bicubic sampling, the Catmull-Rom spline with B=0, C=0.5.
-
-
Constructor Details
-
ImageShader
public ImageShader(@NonNull Image image, @NonNull Shader.TileMode tileModeX, @NonNull Shader.TileMode tileModeY, int filter, @Nullable Matrix localMatrix) Create a new shader for the given image.If local matrix is not null, then it transforms image's local coordinates to geometry's local coordinates.
- Parameters:
image- the image to use inside the shadertileModeX- the tiling mode on x-axis to draw the imagetileModeY- the tiling mode on y-axis to draw the imagefilter- the filter mode to draw the imagelocalMatrix- the local matrix, null means identity
-
ImageShader
public ImageShader(@NonNull Image image, @NonNull Shader.TileMode tileModeX, @NonNull Shader.TileMode tileModeY, int filter, int mipmap, @Nullable Matrix localMatrix) Create a new shader for the given image.If the image has no mipmaps, then mipmap mode will be ignored when drawing.
If local matrix is not null, then it transforms image's local coordinates to geometry's local coordinates.
- Parameters:
image- the image to use inside the shadertileModeX- the tiling mode on x-axis to draw the imagetileModeY- the tiling mode on y-axis to draw the imagefilter- the filter mode to draw the imagemipmap- the mipmap mode to draw the imagelocalMatrix- the local matrix, null means identity
-
ImageShader
public ImageShader(@NonNull Image image, @NonNull Shader.TileMode tileModeX, @NonNull Shader.TileMode tileModeY, @NonNull Object filter, @Nullable Matrix localMatrix) Create a new shader for the given image.The filter must be one of constants in this class, which are
FILTER_POINT,FILTER_LINEAR,FILTER_CUBIC_BSPLINE,FILTER_MITCHELL,FILTER_PHOTOSHOP_BICUBICandFILTER_CATMULLROM.If local matrix is not null, then it transforms image's local coordinates to geometry's local coordinates.
- Parameters:
image- the image to use inside the shadertileModeX- the tiling mode on x-axis to draw the imagetileModeY- the tiling mode on y-axis to draw the imagefilter- the filter to draw the imagelocalMatrix- the local matrix, null means identity
-
-
Method Details
-
getLocalMatrix
Return true if the shader has a non-identity local matrix.- Parameters:
localMatrix- Set to the local matrix of the shader, if the shader's matrix is non-null.- Returns:
- true if the shader has a non-identity local matrix
-
localMatrixEquals
Return true if the local matrix of the shader is equal to the given local matrix.- Parameters:
localMatrix- the local matrix to compare, null means identity- Returns:
- true if local matrix equals
-
copyWithLocalMatrix
@NonNull public ImageShader copyWithLocalMatrix(@Nullable Matrix newLocalMatrix, boolean discardThis) Create a new ImageShader that replaces its local matrix with a new local matrix. This method is faster than re-creating with the constructor when you only want to modify the local matrix. UselocalMatrixEquals(Matrix)to determine if the new local matrix is different from previous one.- Parameters:
newLocalMatrix- the new local matrix that replaces thisdiscardThis- true to discard this shader, if you no longer need the old shader- Returns:
- a newly created shader
-