Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
BaseFontBatch.cs
浏览该文件的文档.
1using Engine.Media;
2
3namespace Engine.Graphics {
4 public abstract class BaseFontBatch : BaseBatch {
5 public static UnlitShader m_shader = new(true, true, false, false);
6
7 public readonly DynamicArray<VertexPositionColorTexture> TriangleVertices = [];
8
9 public readonly DynamicArray<int> TriangleIndices = [];
10
11 public BitmapFont Font { get; set; }
12
13 public SamplerState SamplerState { get; set; }
14
15 public override bool IsEmpty() => TriangleIndices.Count == 0;
16
17 public override void Clear() {
18 TriangleVertices.Clear();
19 TriangleIndices.Clear();
20 }
21
22 public void Flush(Matrix matrix, bool clearAfterFlush = true) {
23 Flush(matrix, Vector4.One, clearAfterFlush);
24 }
25
26 public override void Flush(Matrix matrix, Vector4 color, bool clearAfterFlush = true) {
27 Display.DepthStencilState = DepthStencilState;
28 Display.RasterizerState = RasterizerState;
29 Display.BlendState = BlendState;
30 FlushWithDeviceState(Font, SamplerState, matrix, color, clearAfterFlush);
31 }
32
33 public void FlushWithDeviceState(BitmapFont font, SamplerState samplerState, Matrix matrix, Vector4 color, bool clearAfterFlush = true) {
34 m_shader.Texture = font.Texture;
35 m_shader.SamplerState = samplerState;
36 m_shader.Transforms.World[0] = matrix;
37 m_shader.Color = color;
38 FlushWithDeviceState(m_shader, clearAfterFlush);
39 }
40
41 public void FlushWithDeviceState(Shader shader, bool clearAfterFlush = true) {
42 if (TriangleIndices.Count > 0) {
43 int num = 0;
44 int num2 = TriangleIndices.Count;
45 while (num2 > 0) {
46 int num3 = MathUtils.Min(num2, 196605);
47 Display.DrawUserIndexed(
48 PrimitiveType.TriangleList,
49 shader,
51 TriangleVertices.Array,
52 0,
53 TriangleVertices.Count,
54 TriangleIndices.Array,
55 num,
56 num3
57 );
58 num += num3;
59 num2 -= num3;
60 }
61 }
62 if (clearAfterFlush) {
63 Clear();
64 }
65 }
66
67 public void FlushWithCurrentStateAndShader(Shader shader, bool clearAfterFlush = true) {
68 if (TriangleIndices.Count > 0) {
69 int num = 0;
70 int num2 = TriangleIndices.Count;
71 while (num2 > 0) {
72 int num3 = Math.Min(num2, 196605);
73 Display.DrawUserIndexed(
74 PrimitiveType.TriangleList,
75 shader,
77 TriangleVertices.Array,
78 0,
79 TriangleVertices.Count,
80 TriangleIndices.Array,
81 num,
82 num3
83 );
84 num += num3;
85 num2 -= num3;
86 }
87 }
88 if (clearAfterFlush) {
89 Clear();
90 }
91 }
92
93 public void TransformTriangles(Matrix matrix, int start = 0, int end = -1) {
95 if (end < 0) {
96 end = TriangleVertices.Count;
97 }
98 for (int i = start; i < end; i++) {
99 Vector3.Transform(ref array[i].Position, ref matrix, out array[i].Position);
100 }
101 }
102
103 public void TransformTrianglesColors(Color color, int start = 0, int end = -1) {
105 if (end < 0) {
106 end = TriangleVertices.Count;
107 }
108 for (int i = start; i < end; i++) {
109 array[i].Color *= color;
110 }
111 }
112
113 public Vector2 CalculateTextOffset(string text, int start, int count, TextAnchor anchor, Vector2 scale, Vector2 spacing) {
114 Vector2 zero = Vector2.Zero;
115 if (anchor != 0) {
116 Vector2 vector = Font.MeasureText(text, start, count, scale, spacing);
117 if ((anchor & TextAnchor.HorizontalCenter) != 0) {
118 zero.X = (0f - vector.X) / 2f;
119 }
120 else if ((anchor & TextAnchor.Right) != 0) {
121 zero.X = 0f - vector.X;
122 }
123 if ((anchor & TextAnchor.VerticalCenter) != 0) {
124 zero.Y = (0f - vector.Y) / 2f;
125 }
126 else if ((anchor & TextAnchor.Bottom) != 0) {
127 zero.Y = 0f - vector.Y;
128 }
129 }
130 return zero;
131 }
132 }
133}
RasterizerState RasterizerState
DepthStencilState DepthStencilState
void FlushWithCurrentStateAndShader(Shader shader, bool clearAfterFlush=true)
void TransformTrianglesColors(Color color, int start=0, int end=-1)
void FlushWithDeviceState(Shader shader, bool clearAfterFlush=true)
void TransformTriangles(Matrix matrix, int start=0, int end=-1)
readonly DynamicArray< int > TriangleIndices
readonly DynamicArray< VertexPositionColorTexture > TriangleVertices
override void Flush(Matrix matrix, Vector4 color, bool clearAfterFlush=true)
Vector2 CalculateTextOffset(string text, int start, int count, TextAnchor anchor, Vector2 scale, Vector2 spacing)
void FlushWithDeviceState(BitmapFont font, SamplerState samplerState, Matrix matrix, Vector4 color, bool clearAfterFlush=true)
void Flush(Matrix matrix, bool clearAfterFlush=true)
static int Min(int x1, int x2)
static readonly Vector2 Zero
static Vector3 Transform(Vector3 v, Matrix m)
static readonly Vector4 One