Package com.jogamp.opengl.util.packrect
Class RectanglePacker
java.lang.Object
com.jogamp.opengl.util.packrect.RectanglePacker
Packs rectangles supplied by the user (typically representing
image regions) into a larger backing store rectangle (typically
representing a large texture). Supports automatic compaction of
the space on the backing store, and automatic expansion of the
backing store, when necessary.
-
Constructor Summary
ConstructorsConstructorDescriptionRectanglePacker
(BackingStoreManager manager, int initialWidth, int initialHeight) -
Method Summary
Modifier and TypeMethodDescriptionvoid
Decides upon an (x, y) position for the given rectangle (leaving its width and height unchanged) and places it on the backing store.void
clear()
Clears all Rects contained in this RectanglePacker.void
compact()
Forces a compaction cycle, which typically results in allocating a new backing store and copying all entries to it.void
dispose()
Disposes the backing store allocated by the BackingStoreManager.void
Removes the given rectangle from this RectanglePacker.void
setMaxSize
(int maxWidth, int maxHeight) Sets up a maximum width and height for the backing store.float
Returns the vertical fragmentation ratio of this RectanglePacker.void
visit
(RectVisitor visitor) Visits all Rects contained in this RectanglePacker.
-
Constructor Details
-
RectanglePacker
-
-
Method Details
-
getBackingStore
-
setMaxSize
public void setMaxSize(int maxWidth, int maxHeight) Sets up a maximum width and height for the backing store. These are optional and if not specified the backing store will grow as necessary. Setting up a maximum width and height introduces the possibility that additions will fail; these are handled with the BackingStoreManager's allocationFailed notification. -
add
Decides upon an (x, y) position for the given rectangle (leaving its width and height unchanged) and places it on the backing store. May provoke re-layout of other Rects already added. If the BackingStoreManager does not support compaction, andBackingStoreManager.preExpand
does not clear enough space for the incoming rectangle, then this method will throw a RuntimeException.- Throws:
RuntimeException
-
remove
Removes the given rectangle from this RectanglePacker. -
visit
Visits all Rects contained in this RectanglePacker. -
verticalFragmentationRatio
public float verticalFragmentationRatio()Returns the vertical fragmentation ratio of this RectanglePacker. This is defined as the ratio of the sum of the heights of all completely empty Levels divided by the overall used height of the LevelSet. A high vertical fragmentation ratio indicates that it may be profitable to perform a compaction. -
compact
public void compact()Forces a compaction cycle, which typically results in allocating a new backing store and copying all entries to it. -
clear
public void clear()Clears all Rects contained in this RectanglePacker. -
dispose
public void dispose()Disposes the backing store allocated by the BackingStoreManager. This RectanglePacker may no longer be used after calling this method.
-