Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
BaseTexturedBatch.cs
浏览该文件的文档.
1namespace Engine.Graphics {
2 public abstract class BaseTexturedBatch : BaseBatch {
3 public static UnlitShader m_shader = new(true, true, false, false);
4
5 public static UnlitShader m_shaderAlphaTest = new(true, true, false, true);
6
7 public readonly DynamicArray<VertexPositionColorTexture> TriangleVertices = [];
8
9 public readonly DynamicArray<int> TriangleIndices = [];
10
11 public Texture2D Texture { get; set; }
12
13 public bool UseAlphaTest { get; set; }
14
15 public SamplerState SamplerState { get; set; }
16
17 public override bool IsEmpty() => TriangleIndices.Count == 0;
18
19 public override void Clear() {
20 TriangleVertices.Clear();
21 TriangleIndices.Clear();
22 }
23
24 public virtual void Flush(Matrix matrix, bool clearAfterFlush = true) {
25 Flush(matrix, Vector4.One, clearAfterFlush);
26 }
27
28 public override void Flush(Matrix matrix, Vector4 color, bool clearAfterFlush = true) {
29 Display.DepthStencilState = DepthStencilState;
30 Display.RasterizerState = RasterizerState;
31 Display.BlendState = BlendState;
32 FlushWithDeviceState(UseAlphaTest, Texture, SamplerState, matrix, color, clearAfterFlush);
33 }
34
35 public void FlushWithDeviceState(bool useAlphaTest,
36 Texture2D texture,
37 SamplerState samplerState,
38 Matrix matrix,
39 Vector4 color,
40 bool clearAfterFlush = true) {
41 if (useAlphaTest) {
42 m_shaderAlphaTest.Texture = texture;
43 m_shaderAlphaTest.SamplerState = samplerState;
44 m_shaderAlphaTest.Transforms.World[0] = matrix;
45 m_shaderAlphaTest.Color = color;
46 m_shaderAlphaTest.AlphaThreshold = 0f;
48 }
49 else {
50 m_shader.Texture = texture;
51 m_shader.SamplerState = samplerState;
52 m_shader.Transforms.World[0] = matrix;
53 m_shader.Color = color;
54 FlushWithDeviceState(m_shader, clearAfterFlush);
55 }
56 }
57
58 public void FlushWithDeviceState(Shader shader, bool clearAfterFlush = true) {
59 int num = 0;
60 int num2 = TriangleIndices.Count;
61 while (num2 > 0) {
62 int num3 = Math.Min(num2, 196605);
63 Display.DrawUserIndexed(
64 PrimitiveType.TriangleList,
65 shader,
67 TriangleVertices.Array,
68 0,
69 TriangleVertices.Count,
70 TriangleIndices.Array,
71 num,
72 num3
73 );
74 num += num3;
75 num2 -= num3;
76 }
77 if (clearAfterFlush) {
78 Clear();
79 }
80 }
81
82 public void TransformTriangles(Matrix matrix, int start = 0, int end = -1) {
84 if (end < 0) {
85 end = TriangleVertices.Count;
86 }
87 for (int i = start; i < end; i++) {
88 Vector3.Transform(ref array[i].Position, ref matrix, out array[i].Position);
89 }
90 }
91
92 public void TransformTrianglesColors(Color color, int start = 0, int end = -1) {
94 if (end < 0) {
95 end = TriangleVertices.Count;
96 }
97 for (int i = start; i < end; i++) {
98 array[i].Color *= color;
99 }
100 }
101 }
102}
RasterizerState RasterizerState
DepthStencilState DepthStencilState
void TransformTriangles(Matrix matrix, int start=0, int end=-1)
void FlushWithDeviceState(Shader shader, bool clearAfterFlush=true)
readonly DynamicArray< int > TriangleIndices
void FlushWithDeviceState(bool useAlphaTest, Texture2D texture, SamplerState samplerState, Matrix matrix, Vector4 color, bool clearAfterFlush=true)
override void Flush(Matrix matrix, Vector4 color, bool clearAfterFlush=true)
readonly DynamicArray< VertexPositionColorTexture > TriangleVertices
virtual void Flush(Matrix matrix, bool clearAfterFlush=true)
void TransformTrianglesColors(Color color, int start=0, int end=-1)
static Vector3 Transform(Vector3 v, Matrix m)
static readonly Vector4 One