@@ -2925,19 +2925,13 @@ public void enableShader(Batch batch) {
2925
2925
if (distanceField == DistanceFieldType .MSDF ) {
2926
2926
batch .setShader (shader );
2927
2927
float smoothing = 7f * actualCrispness * Math .max (cellHeight / originalCellHeight , cellWidth / originalCellWidth );
2928
- Float old = smoothingValues .get (batch );
2929
- if (old != null && MathUtils .isEqual (old , smoothing ))
2930
- return ;
2931
2928
batch .flush ();
2932
2929
shader .setUniformf ("u_smoothing" , smoothing );
2933
2930
smoothingValues .put (batch , smoothing );
2934
2931
} else if (distanceField == DistanceFieldType .SDF || getDistanceField () == DistanceFieldType .SDF_OUTLINE ) {
2935
2932
batch .setShader (shader );
2936
2933
float smoothing = (actualCrispness / (Math .max (cellHeight / originalCellHeight ,
2937
2934
cellWidth / originalCellWidth ) * 0.5f + 0.125f ));
2938
- Float old = smoothingValues .get (batch );
2939
- if (old != null && MathUtils .isEqual (old , smoothing ))
2940
- return ;
2941
2935
batch .flush ();
2942
2936
shader .setUniformf ("u_smoothing" , smoothing );
2943
2937
smoothingValues .put (batch , smoothing );
@@ -2964,18 +2958,12 @@ public void enableDistanceFieldShader(Batch batch) {
2964
2958
if (batch .getShader () == shader ) {
2965
2959
if (distanceField == DistanceFieldType .MSDF ) {
2966
2960
float smoothing = 7f * actualCrispness * Math .max (cellHeight / originalCellHeight , cellWidth / originalCellWidth );
2967
- Float old = smoothingValues .get (batch );
2968
- if (old != null && MathUtils .isEqual (old , smoothing ))
2969
- return ;
2970
2961
batch .flush ();
2971
2962
shader .setUniformf ("u_smoothing" , smoothing );
2972
2963
smoothingValues .put (batch , smoothing );
2973
2964
} else if (distanceField == DistanceFieldType .SDF || getDistanceField () == DistanceFieldType .SDF_OUTLINE ) {
2974
2965
float smoothing = (actualCrispness / (Math .max (cellHeight / originalCellHeight ,
2975
2966
cellWidth / originalCellWidth ) * 0.5f + 0.125f ));
2976
- Float old = smoothingValues .get (batch );
2977
- if (old != null && MathUtils .isEqual (old , smoothing ))
2978
- return ;
2979
2967
batch .flush ();
2980
2968
shader .setUniformf ("u_smoothing" , smoothing );
2981
2969
smoothingValues .put (batch , smoothing );
@@ -6608,31 +6596,26 @@ public void removeStoredState(String name) {
6608
6596
storedStates .remove (name , 0L );
6609
6597
}
6610
6598
/**
6599
+ * Important; must be called in {@link com.badlogic.gdx.ApplicationListener#resize(int, int)} on each
6600
+ * SDF, MSDF, or SDF_OUTLINE font you have currently rendering! This allows the distance field to appear
6601
+ * as correct and crisp-outlined as it should be; without this, the distance field will probably not look
6602
+ * very sharp at all. This doesn't need to be called every frame, only in resize().
6603
+ * <br>
6611
6604
* Given the new width and height for a window, this attempts to adjust the {@link #actualCrispness} of an
6612
6605
* SDF/MSDF/SDF_OUTLINE font so that it will display cleanly at a different size. This uses this font's
6613
6606
* {@link #distanceFieldCrispness} as a multiplier applied after calculating the initial crispness.
6614
- * This is a suggestion for what to call in your {@link com.badlogic.gdx.ApplicationListener#resize(int, int)}
6615
- * method for each SDF, MSDF, or SDF_OUTLINE font you have currently rendering.
6616
6607
*
6617
6608
* @param width the new window width; usually a parameter in {@link com.badlogic.gdx.ApplicationListener#resize(int, int)}
6618
6609
* @param height the new window height; usually a parameter in {@link com.badlogic.gdx.ApplicationListener#resize(int, int)}
6619
6610
*/
6620
6611
public void resizeDistanceField (int width , int height ) {
6621
- if (getDistanceField () == DistanceFieldType .MSDF ) {
6622
- if (Gdx .graphics .getBackBufferWidth () == 0 || Gdx .graphics .getBackBufferHeight () == 0 ) {
6623
- actualCrispness = distanceFieldCrispness ;
6624
- } else {
6625
- actualCrispness = distanceFieldCrispness * (float ) Math .pow (8f ,
6626
- Math .max ((float ) width / Gdx .graphics .getBackBufferWidth (),
6627
- (float ) height / Gdx .graphics .getBackBufferHeight ()) * 1.9f - 2.15f + cellHeight * 0.01f );
6628
- }
6629
- } else if (getDistanceField () == DistanceFieldType .SDF || getDistanceField () == DistanceFieldType .SDF_OUTLINE ) {
6612
+ if (getDistanceField () != DistanceFieldType .STANDARD ) {
6630
6613
if (Gdx .graphics .getBackBufferWidth () == 0 || Gdx .graphics .getBackBufferHeight () == 0 ) {
6631
6614
actualCrispness = distanceFieldCrispness ;
6632
6615
} else {
6633
- actualCrispness = distanceFieldCrispness * ( float ) Math . pow ( 4f ,
6634
- Math .max ((float ) width / Gdx .graphics .getBackBufferWidth (),
6635
- (float ) height / Gdx .graphics .getBackBufferHeight ()) * 1.9f - 2f + cellHeight * 0.005f );
6616
+ actualCrispness = distanceFieldCrispness *
6617
+ Math .max ((float ) width / Gdx .graphics .getBackBufferWidth (),
6618
+ (float ) height / Gdx .graphics .getBackBufferHeight ());
6636
6619
}
6637
6620
}
6638
6621
}
0 commit comments