Package com.jme3.texture
Class Image
java.lang.Object
com.jme3.util.NativeObject
com.jme3.texture.Image
Image
defines a data format for a graphical image. The image
is defined by a format, a height and width, and the image data. The width and
height must be greater than 0. The data is contained in a byte buffer, and
should be packed before creation of the image object.-
Nested Class Summary
-
Field Summary
Modifier and TypeFieldDescriptionprotected ColorSpace
protected ArrayList<ByteBuffer>
protected int
protected Image.Format
protected int
protected LastTextureState
protected int[]
protected boolean
protected int
protected boolean
protected int
Fields inherited from class com.jme3.util.NativeObject
handleRef, id, INVALID_ID, objectManager, OBJTYPE_AUDIOBUFFER, OBJTYPE_AUDIOSTREAM, OBJTYPE_BO, OBJTYPE_FILTER, OBJTYPE_FRAMEBUFFER, OBJTYPE_SHADER, OBJTYPE_SHADERSOURCE, OBJTYPE_TEXTURE, OBJTYPE_VERTEXBUFFER, updateNeeded
-
Constructor Summary
ModifierConstructorDescriptionImage()
Constructor instantiates a newImage
object.protected
Image
(int id) Image
(Image.Format format, int width, int height, int depth, ArrayList<ByteBuffer> data) Deprecated.Image
(Image.Format format, int width, int height, int depth, ArrayList<ByteBuffer> data, int[] mipMapSizes) Image
(Image.Format format, int width, int height, int depth, ArrayList<ByteBuffer> data, int[] mipMapSizes, ColorSpace colorSpace) Constructor instantiates a newImage
object.Image
(Image.Format format, int width, int height, int depth, ArrayList<ByteBuffer> data, ColorSpace colorSpace) Constructor instantiates a newImage
object.Image
(Image.Format format, int width, int height, ByteBuffer data) Image
(Image.Format format, int width, int height, ByteBuffer data, int[] mipMapSizes) Image
(Image.Format format, int width, int height, ByteBuffer data, int[] mipMapSizes, ColorSpace colorSpace) Constructor instantiates a newImage
object.Image
(Image.Format format, int width, int height, ByteBuffer data, ColorSpace colorSpace) Constructor instantiates a newImage
object. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addData
(ByteBuffer data) clone()
This should create a deep clone.Creates a shallow clone of this GL Object.protected void
Deletes any associated nativebuffers
.void
deleteObject
(Object rendererObject) Deletes the GL object from the GPU when it is no longer used.boolean
Specifies that this image is an SRGB image and therefore must undergo an sRGB -> linear RGB color conversion prior to being read by a shader and with theRenderer.setLinearizeSrgbImages(boolean)
option is enabled.getData()
getData
returns the data for this image.getData
(int index) getData
returns the data for this image.int
getDepth()
getDepth
returns the depth of this image (for 3d images).Deprecated.This feature is no longer used by the enginegetFormat
returns the image format for this image.int
getHeight
returns the height of this image.Internal use only.int[]
Returns the mipmap sizes for this image.int
long
Returns a unique ID for this NativeObject.int
getWidth()
getWidth
returns the width of this image.int
hashCode()
boolean
Returns whether the image data contains mipmaps.boolean
boolean
Internal use only.boolean
isNPOT()
Determine if the image is NPOT.void
read
(JmeImporter importer) void
Called when the GL context is restarted to reset all IDs.void
setColorSpace
(ColorSpace colorSpace) image loader is responsible for setting this attribute based on the color space in which the image has been encoded with.void
setData
(int index, ByteBuffer data) void
setData
(ByteBuffer data) setData
sets the data that makes up the image.void
setData
(ArrayList<ByteBuffer> data) setData
sets the data that makes up the image.void
setDepth
(int depth) setDepth
sets the depth value of the image.void
setFormat
(Image.Format format) setFormat
sets the image format for this image.void
setHeight
(int height) setHeight
sets the height value of the image.void
setMipmapsGenerated
(boolean generated) Internal use only.void
setMipMapSizes
(int[] mipMapSizes) Sets the mipmap sizes stored in this image's data buffer.void
setMultiSamples
(int multiSamples) void
Sets the update needed flag, while also checking if mipmaps need to be regenerated.void
setWidth
(int width) setWidth
sets the width value of the image.toString()
void
write
(JmeExporter e) Methods inherited from class com.jme3.util.NativeObject
clearUpdateNeeded, dispose, getId, getWeakRef, isUpdateNeeded, setId
-
Field Details
-
format
-
width
protected int width -
height
protected int height -
depth
protected int depth -
mipMapSizes
protected int[] mipMapSizes -
data
-
multiSamples
protected int multiSamples -
colorSpace
-
mipsWereGenerated
protected boolean mipsWereGenerated -
needGeneratedMips
protected boolean needGeneratedMips -
lastTextureState
-
-
Constructor Details
-
Image
public Image()Constructor instantiates a newImage
object. All values are undefined. -
Image
protected Image(int id) -
Image
public Image(Image.Format format, int width, int height, int depth, ArrayList<ByteBuffer> data, int[] mipMapSizes, ColorSpace colorSpace) Constructor instantiates a newImage
object. The attributes of the image are defined during construction.- Parameters:
format
- the data format of the image.width
- the width of the image.height
- the height of the image.depth
- the desired image depthdata
- the image data.mipMapSizes
- the array of mipmap sizes, or null for no mipmaps.colorSpace
- the colorSpace of the image
-
Image
@Deprecated public Image(Image.Format format, int width, int height, int depth, ArrayList<ByteBuffer> data, int[] mipMapSizes) Deprecated.- Parameters:
format
- the desired data formatwidth
- the desired width (in pixels)height
- the desired height (in pixels)depth
- the desired image depthdata
- the image data to usemipMapSizes
- the desired mipmap sizes, or null for no mipmaps- See Also:
-
Image
public Image(Image.Format format, int width, int height, ByteBuffer data, int[] mipMapSizes, ColorSpace colorSpace) Constructor instantiates a newImage
object. The attributes of the image are defined during construction.- Parameters:
format
- the data format of the image.width
- the width of the image.height
- the height of the image.data
- the image data.mipMapSizes
- the array of mipmap sizes, or null for no mipmaps.colorSpace
- the colorSpace of the image
-
Image
@Deprecated public Image(Image.Format format, int width, int height, ByteBuffer data, int[] mipMapSizes) Deprecated.- Parameters:
format
- the desired data formatwidth
- the desired width (in pixels)height
- the desired height (in pixels)data
- the image data to usemipMapSizes
- the desired mipmap sizes, or null for no mipmaps- See Also:
-
Image
public Image(Image.Format format, int width, int height, int depth, ArrayList<ByteBuffer> data, ColorSpace colorSpace) Constructor instantiates a newImage
object. The attributes of the image are defined during construction.- Parameters:
format
- the data format of the image.width
- the width of the image.height
- the height of the image.depth
- the desired image depthdata
- the image data.colorSpace
- the colorSpace of the image
-
Image
@Deprecated public Image(Image.Format format, int width, int height, int depth, ArrayList<ByteBuffer> data) Deprecated.- Parameters:
format
- the desired data formatwidth
- the desired width (in pixels)height
- the desired height (in pixels)depth
- the desired image depthdata
- the image data to use- See Also:
-
Image
Constructor instantiates a newImage
object. The attributes of the image are defined during construction.- Parameters:
format
- the data format of the image.width
- the width of the image.height
- the height of the image.data
- the image data.colorSpace
- the colorSpace of the image
-
Image
Deprecated.- Parameters:
format
- the desired data formatwidth
- the desired width (in pixels)height
- the desired height (in pixels)data
- the image data- See Also:
-
-
Method Details
-
getLastTextureState
Internal use only. The renderer stores the texture state set from the last texture, so it doesn't have to change it unless necessary.- Returns:
- The image parameter state.
-
setMipmapsGenerated
public void setMipmapsGenerated(boolean generated) Internal use only. The renderer marks which images have generated mipmaps in VRAM and which do not, so it can generate them as needed.- Parameters:
generated
- If mipmaps were generated or not.
-
isMipmapsGenerated
public boolean isMipmapsGenerated()Internal use only. Check if the renderer has generated mipmaps for this image in VRAM or not.- Returns:
- If mipmaps were generated already.
-
isGeneratedMipmapsRequired
public boolean isGeneratedMipmapsRequired()- Returns:
- True if the image needs to have mipmaps generated for it (as requested by the texture). This stays true even after mipmaps have been generated.
-
setUpdateNeeded
public void setUpdateNeeded()Sets the update needed flag, while also checking if mipmaps need to be regenerated.- Overrides:
setUpdateNeeded
in classNativeObject
-
isNPOT
public boolean isNPOT()Determine if the image is NPOT.- Returns:
- if the image is a non-power-of-2 image, e.g. having dimensions that are not powers of 2.
-
resetObject
public void resetObject()Description copied from class:NativeObject
Called when the GL context is restarted to reset all IDs. Prevents "white textures" on display restart.- Specified by:
resetObject
in classNativeObject
-
deleteNativeBuffers
protected void deleteNativeBuffers()Description copied from class:NativeObject
Deletes any associated nativebuffers
. This is necessary because it is unlikely that native buffers will be garbage collected naturally (due to how GC works), therefore the collection must be handled manually. Only implementations that manage native buffers need to override this method. Note that the behavior that occurs when a deleted native buffer is used is not defined, therefore this method is protected- Overrides:
deleteNativeBuffers
in classNativeObject
-
deleteObject
Description copied from class:NativeObject
Deletes the GL object from the GPU when it is no longer used. Called automatically by the GL object manager.- Specified by:
deleteObject
in classNativeObject
- Parameters:
rendererObject
- The renderer to be used to delete the object
-
createDestructableClone
Description copied from class:NativeObject
Creates a shallow clone of this GL Object. The deleteObject method should be functional for this object.- Specified by:
createDestructableClone
in classNativeObject
- Returns:
- a new instance
-
getUniqueId
public long getUniqueId()Description copied from class:NativeObject
Returns a unique ID for this NativeObject. No other NativeObject shall have the same ID.- Specified by:
getUniqueId
in classNativeObject
- Returns:
- unique ID for this NativeObject.
-
clone
Description copied from class:NativeObject
This should create a deep clone. For a shallow clone, use createDestructableClone().- Overrides:
clone
in classNativeObject
- Returns:
- A shallow clone of this image. The data is not cloned.
-
getMultiSamples
public int getMultiSamples()- Returns:
- The number of samples (for multisampled textures).
- See Also:
-
setMultiSamples
public void setMultiSamples(int multiSamples) - Parameters:
multiSamples
- Set the number of samples to use for this image, setting this to a value higher than 1 turns this image/texture into a multisample texture (on OpenGL3.1 and higher).
-
setData
setData
sets the data that makes up the image. This data is packed into an array ofByteBuffer
objects.- Parameters:
data
- the data that contains the image information.
-
setData
setData
sets the data that makes up the image. This data is packed into a singleByteBuffer
.- Parameters:
data
- the data that contains the image information.
-
addData
-
setData
-
getEfficentData
Deprecated.This feature is no longer used by the engine- Returns:
- null
-
setMipMapSizes
public void setMipMapSizes(int[] mipMapSizes) Sets the mipmap sizes stored in this image's data buffer. Mipmaps are stored sequentially, and the first mipmap is the main image data. To specify no mipmaps, pass null and this will automatically be expanded into a single mipmap of the full- Parameters:
mipMapSizes
- the mipmap sizes array, or null for a single image map.
-
setHeight
public void setHeight(int height) setHeight
sets the height value of the image. It is typically a good idea to try to keep this as a multiple of 2.- Parameters:
height
- the height of the image.
-
setDepth
public void setDepth(int depth) setDepth
sets the depth value of the image. It is typically a good idea to try to keep this as a multiple of 2. This is used for 3d images.- Parameters:
depth
- the depth of the image.
-
setWidth
public void setWidth(int width) setWidth
sets the width value of the image. It is typically a good idea to try to keep this as a multiple of 2.- Parameters:
width
- the width of the image.
-
setFormat
setFormat
sets the image format for this image.- Parameters:
format
- the image format (not null)- Throws:
IllegalArgumentException
- if format is null- See Also:
-
getFormat
getFormat
returns the image format for this image.- Returns:
- the image format.
- See Also:
-
getWidth
public int getWidth()getWidth
returns the width of this image.- Returns:
- the width of this image.
-
getHeight
public int getHeight()getHeight
returns the height of this image.- Returns:
- the height of this image.
-
getDepth
public int getDepth()getDepth
returns the depth of this image (for 3d images).- Returns:
- the depth of this image.
-
getData
getData
returns the data for this image. If the data is undefined, null will be returned.- Returns:
- the data for this image.
-
getData
getData
returns the data for this image. If the data is undefined, null will be returned.- Parameters:
index
- index of the data buffer to access- Returns:
- the data for this image.
-
hasMipmaps
public boolean hasMipmaps()Returns whether the image data contains mipmaps.- Returns:
- true if the image data contains mipmaps, false if not.
-
getMipMapSizes
public int[] getMipMapSizes()Returns the mipmap sizes for this image.- Returns:
- the mipmap sizes for this image.
-
setColorSpace
image loader is responsible for setting this attribute based on the color space in which the image has been encoded with. In the majority of cases, this flag will be set to sRGB by default since many image formats do not contain any color space information and the most frequently used colors space is sRGB The material loader may override this attribute to Linear if it determines that such conversion must not be performed, for example, when loading normal maps.- Parameters:
colorSpace
- Set to sRGB to enable srgb -> linear conversion, Linear otherwise.- See Also:
-
getColorSpace
Specifies that this image is an SRGB image and therefore must undergo an sRGB -> linear RGB color conversion prior to being read by a shader and with theRenderer.setLinearizeSrgbImages(boolean)
option is enabled. This option is only supported for the 8-bit color and grayscale image formats. Determines if the image is in SRGB color space or not.- Returns:
- True, if the image is an SRGB image, false if it is linear RGB.
- See Also:
-
toString
- Overrides:
toString
in classNativeObject
-
equals
-
hashCode
public int hashCode() -
write
- Specified by:
write
in interfaceSavable
- Throws:
IOException
-
read
- Specified by:
read
in interfaceSavable
- Throws:
IOException
-
Image(com.jme3.texture.Image.Format, int, int, int, java.util.ArrayList, com.jme3.texture.image.ColorSpace)