Skip to content

Commit 3b5b46f

Browse files
committed
Avoid some flushing with shaders.
1 parent 384ee28 commit 3b5b46f

File tree

9 files changed

+121
-8
lines changed

9 files changed

+121
-8
lines changed
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
Copyright (c) 2003-2014 SIL International (http://www.sil.org/),
2+
with Reserved Font Names "Gentium" and "SIL".
3+
4+
This Font Software is licensed under the SIL Open Font License, Version 1.1.
5+
This license is copied below, and is also available with a FAQ at:
6+
http://scripts.sil.org/OFL
7+
8+
9+
-----------------------------------------------------------
10+
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
11+
-----------------------------------------------------------
12+
13+
PREAMBLE
14+
The goals of the Open Font License (OFL) are to stimulate worldwide
15+
development of collaborative font projects, to support the font creation
16+
efforts of academic and linguistic communities, and to provide a free and
17+
open framework in which fonts may be shared and improved in partnership
18+
with others.
19+
20+
The OFL allows the licensed fonts to be used, studied, modified and
21+
redistributed freely as long as they are not sold by themselves. The
22+
fonts, including any derivative works, can be bundled, embedded,
23+
redistributed and/or sold with any software provided that any reserved
24+
names are not used by derivative works. The fonts and derivatives,
25+
however, cannot be released under any other type of license. The
26+
requirement for fonts to remain under this license does not apply
27+
to any document created using the fonts or their derivatives.
28+
29+
DEFINITIONS
30+
"Font Software" refers to the set of files released by the Copyright
31+
Holder(s) under this license and clearly marked as such. This may
32+
include source files, build scripts and documentation.
33+
34+
"Reserved Font Name" refers to any names specified as such after the
35+
copyright statement(s).
36+
37+
"Original Version" refers to the collection of Font Software components as
38+
distributed by the Copyright Holder(s).
39+
40+
"Modified Version" refers to any derivative made by adding to, deleting,
41+
or substituting -- in part or in whole -- any of the components of the
42+
Original Version, by changing formats or by porting the Font Software to a
43+
new environment.
44+
45+
"Author" refers to any designer, engineer, programmer, technical
46+
writer or other person who contributed to the Font Software.
47+
48+
PERMISSION & CONDITIONS
49+
Permission is hereby granted, free of charge, to any person obtaining
50+
a copy of the Font Software, to use, study, copy, merge, embed, modify,
51+
redistribute, and sell modified and unmodified copies of the Font
52+
Software, subject to the following conditions:
53+
54+
1) Neither the Font Software nor any of its individual components,
55+
in Original or Modified Versions, may be sold by itself.
56+
57+
2) Original or Modified Versions of the Font Software may be bundled,
58+
redistributed and/or sold with any software, provided that each copy
59+
contains the above copyright notice and this license. These can be
60+
included either as stand-alone text files, human-readable headers or
61+
in the appropriate machine-readable metadata fields within text or
62+
binary files as long as those fields can be easily viewed by the user.
63+
64+
3) No Modified Version of the Font Software may use the Reserved Font
65+
Name(s) unless explicit written permission is granted by the corresponding
66+
Copyright Holder. This restriction only applies to the primary font name as
67+
presented to the users.
68+
69+
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
70+
Software shall not be used to promote, endorse or advertise any
71+
Modified Version, except to acknowledge the contribution(s) of the
72+
Copyright Holder(s) and the Author(s) or with their explicit written
73+
permission.
74+
75+
5) The Font Software, modified or unmodified, in part or in whole,
76+
must be distributed entirely under this license, and must not be
77+
distributed under any other license. The requirement for fonts to
78+
remain under this license does not apply to any document created
79+
using the Font Software.
80+
81+
TERMINATION
82+
This license becomes null and void if any of the above conditions are
83+
not met.
84+
85+
DISCLAIMER
86+
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
87+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
88+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
89+
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
90+
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
91+
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
92+
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
93+
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
94+
OTHER DEALINGS IN THE FONT SOFTWARE.

knownFonts/fontwriter/Gentium-msdf.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.
4.04 MB
Loading

knownFonts/fontwriter/Gentium-sdf.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

knownFonts/fontwriter/Gentium-sdf.png

1.27 MB
Loading

knownFonts/fontwriter/Gentium-standard.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.
703 KB
Loading

src/main/java/com/github/tommyettinger/textra/Font.java

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2153,11 +2153,11 @@ public Font(String jsonName, TextureRegion textureRegion,
21532153
String dfType = atlas.getString("type", "");
21542154
if("msdf".equals(dfType) || "mtsdf".equals(dfType)) {
21552155
this.setDistanceField(DistanceFieldType.MSDF);
2156-
distanceFieldCrispness = 16f / atlas.getFloat("distanceRange", 2f);
2156+
setCrispness(16f / atlas.getFloat("distanceRange", 2f));
21572157
}
21582158
else if("sdf".equals(dfType) || "psdf".equals(dfType)) {
21592159
this.setDistanceField(DistanceFieldType.SDF);
2160-
distanceFieldCrispness = 16f / atlas.getFloat("distanceRange", 4f);
2160+
setCrispness(16f / atlas.getFloat("distanceRange", 4f));
21612161
}
21622162
else // softmask, hardmask
21632163
this.setDistanceField(DistanceFieldType.STANDARD);
@@ -2280,7 +2280,7 @@ else if("sdf".equals(dfType) || "psdf".equals(dfType)) {
22802280
textureRegion.getTexture().setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear);
22812281
if(distanceField == DistanceFieldType.MSDF)
22822282
distanceFieldCrispness = -8f / (float)Math.log(1f/originalCellHeight);
2283-
else if(distanceField == DistanceFieldType.SDF)
2283+
else if(distanceField == DistanceFieldType.SDF || distanceField == DistanceFieldType.SDF_OUTLINE)
22842284
distanceFieldCrispness = -1.2f / (float)Math.log(1f/originalCellHeight);
22852285
}
22862286

@@ -2908,12 +2908,20 @@ public void enableShader(Batch batch) {
29082908
if (distanceField == DistanceFieldType.MSDF) {
29092909
batch.setShader(shader);
29102910
float smoothing = 7f * actualCrispness * Math.max(cellHeight / originalCellHeight, cellWidth / originalCellWidth);
2911+
Float old = smoothingValues.get(batch);
2912+
if(old != null && MathUtils.isEqual(old, smoothing))
2913+
return;
2914+
batch.flush();
29112915
shader.setUniformf("u_smoothing", smoothing);
29122916
smoothingValues.put(batch, smoothing);
29132917
} else if (distanceField == DistanceFieldType.SDF || getDistanceField() == DistanceFieldType.SDF_OUTLINE) {
29142918
batch.setShader(shader);
29152919
float smoothing = (actualCrispness / (Math.max(cellHeight / originalCellHeight,
29162920
cellWidth / originalCellWidth) * 0.5f + 0.125f));
2921+
Float old = smoothingValues.get(batch);
2922+
if(old != null && MathUtils.isEqual(old, smoothing))
2923+
return;
2924+
batch.flush();
29172925
shader.setUniformf("u_smoothing", smoothing);
29182926
smoothingValues.put(batch, smoothing);
29192927
} else {
@@ -2938,14 +2946,20 @@ public void enableShader(Batch batch) {
29382946
public void enableDistanceFieldShader(Batch batch) {
29392947
if (batch.getShader() == shader) {
29402948
if (distanceField == DistanceFieldType.MSDF) {
2941-
batch.flush();
29422949
float smoothing = 7f * actualCrispness * Math.max(cellHeight / originalCellHeight, cellWidth / originalCellWidth);
2950+
Float old = smoothingValues.get(batch);
2951+
if(old != null && MathUtils.isEqual(old, smoothing))
2952+
return;
2953+
batch.flush();
29432954
shader.setUniformf("u_smoothing", smoothing);
29442955
smoothingValues.put(batch, smoothing);
29452956
} else if (distanceField == DistanceFieldType.SDF || getDistanceField() == DistanceFieldType.SDF_OUTLINE) {
2946-
batch.flush();
29472957
float smoothing = (actualCrispness / (Math.max(cellHeight / originalCellHeight,
29482958
cellWidth / originalCellWidth) * 0.5f + 0.125f));
2959+
Float old = smoothingValues.get(batch);
2960+
if(old != null && MathUtils.isEqual(old, smoothing))
2961+
return;
2962+
batch.flush();
29492963
shader.setUniformf("u_smoothing", smoothing);
29502964
smoothingValues.put(batch, smoothing);
29512965
}

src/test/java/com/github/tommyettinger/textra/EmojiTypingLabelTest.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ public void create() {
4242
adjustTypingConfigs();
4343

4444
batch = new SpriteBatch();
45-
skin = new Skin(Gdx.files.internal("uiskin.json"));
45+
skin = new FreeTypistSkin(Gdx.files.internal("uiskin.json"));
4646
// skin.getAtlas().getTextures().iterator().next().setFilter(TextureFilter.Nearest, TextureFilter.Nearest);
47-
skin.getFont("default-font");//.getData().setScale(0.5f);
47+
// skin.getFont("default-font").getData().setScale(0.5f);
4848
stage = new Stage(new StretchViewport(720, 405), batch);
4949
stage.setDebugAll(true);
5050
Gdx.input.setInputProcessor(stage);
@@ -102,7 +102,9 @@ public TypingLabel createTypingLabel() {
102102
// Font font = new Font("dawnlike/PlainAndSimplePlus-standard.fnt", atlas.findRegion("PlainAndSimplePlus-standard"), 0, 0, 2, 2);
103103
// font.addImage("😀", atlas.findRegion("love box")).addImage("💀", atlas.findRegion("hate box"));
104104
// font.scale(2, 2);
105-
Font font = KnownFonts.addEmoji(KnownFonts.getNowAlt());
105+
// Font font = KnownFonts.addEmoji(new Font("experimental/GentiumUnItalic-sdf.json", true)).scale(0.5f, 0.5f);
106+
Font font = KnownFonts.addEmoji(new Font("fontwriter/Gentium-sdf.json", true)).scale(0.6f, 0.6f);
107+
// Font font = KnownFonts.addEmoji(KnownFonts.getGentiumSDF());
106108

107109
// Font font = new Font(KnownFonts.getOpenSans().scale(0.5f, 0.5f).setTextureFilter());
108110
// Create label

0 commit comments

Comments
 (0)