Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
BaseFlatBatch.cs
浏览该文件的文档.
1namespace Engine.Graphics {
2 public abstract class BaseFlatBatch : BaseBatch {
3 public static UnlitShader m_shader = new(true, false, false, false);
4
5 public readonly DynamicArray<VertexPositionColor> LineVertices = [];
6
7 public readonly DynamicArray<int> LineIndices = [];
8
9 public readonly DynamicArray<VertexPositionColor> TriangleVertices = [];
10
11 public readonly DynamicArray<int> TriangleIndices = [];
12
13 public override bool IsEmpty() => LineIndices.Count == 0 && TriangleIndices.Count == 0;
14
15 public override void Clear() {
16 LineVertices.Clear();
17 LineIndices.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(matrix, color, clearAfterFlush);
31 }
32
33 public void FlushWithDeviceState(Matrix matrix, Vector4 color, bool clearAfterFlush = true) {
34 if (!IsEmpty()) {
35 m_shader.Transforms.World[0] = matrix;
36 m_shader.Color = color;
37 FlushWithDeviceState(m_shader, clearAfterFlush);
38 }
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 = Math.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 (LineIndices.Count > 0) {
63 int num4 = 0;
64 int num5 = LineIndices.Count;
65 while (num5 > 0) {
66 int num6 = Math.Min(num5, 131070);
67 Display.DrawUserIndexed(
68 PrimitiveType.LineList,
69 shader,
71 LineVertices.Array,
72 0,
73 LineVertices.Count,
74 LineIndices.Array,
75 num4,
76 num6
77 );
78 num4 += num6;
79 num5 -= num6;
80 }
81 }
82 if (clearAfterFlush) {
83 Clear();
84 }
85 }
86
87 public void TransformLines(Matrix matrix, int start = 0, int end = -1) {
88 VertexPositionColor[] array = LineVertices.Array;
89 if (end < 0) {
90 end = LineVertices.Count;
91 }
92 for (int i = start; i < end; i++) {
93 Vector3.Transform(ref array[i].Position, ref matrix, out array[i].Position);
94 }
95 }
96
97 public void TransformLinesColors(Color color, int start = 0, int end = -1) {
98 VertexPositionColor[] array = LineVertices.Array;
99 if (end < 0) {
100 end = LineVertices.Count;
101 }
102 for (int i = start; i < end; i++) {
103 array[i].Color *= color;
104 }
105 }
106
107 public void TransformTriangles(Matrix matrix, int start = 0, int end = -1) {
109 if (end < 0) {
110 end = TriangleVertices.Count;
111 }
112 for (int i = start; i < end; i++) {
113 Vector3.Transform(ref array[i].Position, ref matrix, out array[i].Position);
114 }
115 }
116
117 public void TransformTrianglesColors(Color color, int start = 0, int end = -1) {
119 if (end < 0) {
120 end = TriangleVertices.Count;
121 }
122 for (int i = start; i < end; i++) {
123 array[i].Color *= color;
124 }
125 }
126 }
127}
RasterizerState RasterizerState
DepthStencilState DepthStencilState
readonly DynamicArray< int > LineIndices
readonly DynamicArray< int > TriangleIndices
void TransformLines(Matrix matrix, int start=0, int end=-1)
readonly DynamicArray< VertexPositionColor > TriangleVertices
override void Flush(Matrix matrix, Vector4 color, bool clearAfterFlush=true)
void TransformTrianglesColors(Color color, int start=0, int end=-1)
void Flush(Matrix matrix, bool clearAfterFlush=true)
void TransformLinesColors(Color color, int start=0, int end=-1)
void FlushWithDeviceState(Matrix matrix, Vector4 color, bool clearAfterFlush=true)
readonly DynamicArray< VertexPositionColor > LineVertices
void TransformTriangles(Matrix matrix, int start=0, int end=-1)
void FlushWithDeviceState(Shader shader, bool clearAfterFlush=true)
static readonly VertexDeclaration VertexDeclaration
static Vector3 Transform(Vector3 v, Matrix m)
static readonly Vector4 One