Class AdaptiveTessellationController
This controller dynamically adjusts the screen-space tessellation threshold to keep the number of tessellated polygons approximately within a target budget. When polygon count exceeds the budget, the threshold is increased (less tessellation, larger polygons). When below budget and threshold is above minimum, it's decreased (better quality, smaller polygons).
Frame lifecycle:
resetFrameCount()called at frame start to clear counteraddTessellatedPolygons(int)called during transform for each tessellated polygonendFrame()called after painting to adjust threshold based on count
Adjustment logic:
- If polygonCount exceeds TARGET: increase threshold by INCREASE_FACTOR
- If polygonCount is below 80% of TARGET and threshold above MIN: decrease threshold
- Threshold is clamped to MIN_THRESHOLD as the lower bound
Thread safety: Uses volatile for threshold and AtomicInteger for count. Safe for multi-threaded rendering pipelines.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final doubleMinimum tessellation threshold in pixels.static final intTarget polygon count for tessellated triangles. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddTessellatedPolygons(int count) Adds tessellated polygons to the current frame's count.booleanendFrame()Called at the end of each frame to adjust threshold based on polygon count.intReturns the current frame's polygon count (so far).Returns the singleton instance.intReturns the polygon count from the last frame.doubleReturns the current tessellation threshold in screen pixels.voidreset()Resets the threshold to the minimum value and clears counters.voidResets the polygon counter at the start of a new frame.
-
Field Details
-
MIN_THRESHOLD
public static final double MIN_THRESHOLDMinimum tessellation threshold in pixels. This is the base value fromTexturedTriangle.TESSELLATION_THRESHOLD_PIXELS. Threshold will never go below this.- See Also:
-
TARGET_POLYGON_COUNT
public static final int TARGET_POLYGON_COUNTTarget polygon count for tessellated triangles. The controller tries to keep actual count close to this value.- See Also:
-
-
Constructor Details
-
AdaptiveTessellationController
public AdaptiveTessellationController()
-
-
Method Details
-
getInstance
Returns the singleton instance.- Returns:
- the adaptive tessellation controller
-
getThreshold
public double getThreshold()Returns the current tessellation threshold in screen pixels.This value is read by tessellators during the transform phase to determine when to subdivide triangles.
- Returns:
- the current threshold in pixels
-
resetFrameCount
public void resetFrameCount()Resets the polygon counter at the start of a new frame.Called from
ShapeCollection.transformShapes()before processing shapes. -
addTessellatedPolygons
public void addTessellatedPolygons(int count) Adds tessellated polygons to the current frame's count.Called from
TexturedTriangle.transform()after tessellation completes, with the number of sub-triangles produced.- Parameters:
count- the number of tessellated polygons to add
-
endFrame
public boolean endFrame()Called at the end of each frame to adjust threshold based on polygon count.Adjustment rules:
- Adjustment is proportional to how far count is from target (smoother convergence)
- Minimum change per frame is 2% to ensure gradual adjustment
- Maximum change per frame is 10% to prevent sudden jumps
- Threshold is always clamped between MIN_THRESHOLD and MAX_THRESHOLD
- Returns:
- true if threshold changed significantly (should invalidate caches)
-
getLastPolygonCount
public int getLastPolygonCount()Returns the polygon count from the last frame.- Returns:
- the last frame's polygon count
-
getCurrentFrameCount
public int getCurrentFrameCount()Returns the current frame's polygon count (so far).- Returns:
- the current frame's polygon count
-
reset
public void reset()Resets the threshold to the minimum value and clears counters.Useful when starting a new scene or resetting renderer state.
-