8
8
import com .mojang .blaze3d .vertex .VertexFormat ;
9
9
import com .mojang .blaze3d .vertex .VertexFormatElement ;
10
10
import net .coderbot .iris .block_rendering .BlockRenderingSettings ;
11
- import org .joml .Vector3f ;
12
- import net .coderbot .iris .vertices .NormI8 ;
13
- import org .jetbrains .annotations .NotNull ;
14
11
import net .coderbot .iris .uniforms .CapturedRenderingState ;
15
12
import net .coderbot .iris .vertices .BlockSensitiveBufferBuilder ;
16
13
import net .coderbot .iris .vertices .BufferBuilderPolygonView ;
17
14
import net .coderbot .iris .vertices .ExtendedDataHelper ;
18
15
import net .coderbot .iris .vertices .ExtendingBufferBuilder ;
16
+ import net .coderbot .iris .vertices .IrisExtendedBufferBuilder ;
19
17
import net .coderbot .iris .vertices .IrisVertexFormats ;
18
+ import net .coderbot .iris .vertices .NormI8 ;
20
19
import net .coderbot .iris .vertices .NormalHelper ;
20
+ import org .jetbrains .annotations .NotNull ;
21
21
import org .jetbrains .annotations .Nullable ;
22
+ import org .joml .Vector3f ;
22
23
import org .spongepowered .asm .mixin .Mixin ;
23
24
import org .spongepowered .asm .mixin .Shadow ;
24
25
import org .spongepowered .asm .mixin .Unique ;
25
26
import org .spongepowered .asm .mixin .injection .At ;
26
27
import org .spongepowered .asm .mixin .injection .Inject ;
27
- import org .spongepowered .asm .mixin .injection .ModifyArg ;
28
+ import org .spongepowered .asm .mixin .injection .ModifyVariable ;
28
29
import org .spongepowered .asm .mixin .injection .callback .CallbackInfo ;
29
30
30
31
import java .nio .ByteBuffer ;
33
34
* Dynamically and transparently extends the vanilla vertex formats with additional data
34
35
*/
35
36
@ Mixin (BufferBuilder .class )
36
- public abstract class MixinBufferBuilder extends DefaultedVertexConsumer implements BufferVertexConsumer , BlockSensitiveBufferBuilder , ExtendingBufferBuilder {
37
+ public abstract class MixinBufferBuilder extends DefaultedVertexConsumer implements BufferVertexConsumer , BlockSensitiveBufferBuilder , ExtendingBufferBuilder , IrisExtendedBufferBuilder {
37
38
@ Unique
38
- private boolean extending ;
39
+ private boolean iris$shouldNotExtend ;
39
40
40
41
@ Unique
41
- private boolean iris$shouldNotExtend = false ;
42
-
43
- @ Unique
44
- private boolean iris$isTerrain = false ;
42
+ private boolean extending ;
45
43
46
44
@ Unique
47
- private int vertexCount ;
45
+ private boolean iris$isTerrain ;
48
46
49
47
@ Unique
50
- private final BufferBuilderPolygonView polygon = new BufferBuilderPolygonView ();
51
-
52
- @ Unique
53
- private final Vector3f normal = new Vector3f ();
48
+ private boolean injectNormalAndUV1 ;
54
49
55
50
@ Unique
56
- private boolean injectNormalAndUV1 ;
51
+ private int vertexCount ;
57
52
58
53
@ Unique
59
- private short currentBlock ;
54
+ private short currentBlock = - 1 ;
60
55
61
56
@ Unique
62
- private short currentRenderType ;
57
+ private short currentRenderType = - 1 ;
63
58
64
59
@ Unique
65
60
private int currentLocalPosX ;
@@ -70,11 +65,11 @@ public abstract class MixinBufferBuilder extends DefaultedVertexConsumer impleme
70
65
@ Unique
71
66
private int currentLocalPosZ ;
72
67
73
- @ Shadow
74
- private boolean fastFormat ;
68
+ @ Unique
69
+ private final BufferBuilderPolygonView polygon = new BufferBuilderPolygonView () ;
75
70
76
- @ Shadow
77
- private boolean fullFormat ;
71
+ @ Unique
72
+ private final Vector3f normal = new Vector3f () ;
78
73
79
74
@ Shadow
80
75
private ByteBuffer buffer ;
@@ -97,9 +92,6 @@ public abstract class MixinBufferBuilder extends DefaultedVertexConsumer impleme
97
92
@ Shadow
98
93
public abstract void putShort (int i , short s );
99
94
100
- @ Shadow
101
- protected abstract void switchFormat (VertexFormat arg );
102
-
103
95
@ Shadow
104
96
public abstract void nextElement ();
105
97
@@ -110,75 +102,44 @@ public abstract class MixinBufferBuilder extends DefaultedVertexConsumer impleme
110
102
iris$shouldNotExtend = false ;
111
103
}
112
104
113
- @ Inject (method = "begin" , at = @ At ("HEAD" ))
114
- private void iris$onBegin (VertexFormat .Mode drawMode , VertexFormat format , CallbackInfo ci ) {
115
- boolean shouldExtend = (!iris$shouldNotExtend ) && BlockRenderingSettings .INSTANCE .shouldUseExtendedVertexFormat ();
116
- extending = shouldExtend && (format == DefaultVertexFormat .BLOCK || format == DefaultVertexFormat .NEW_ENTITY
117
- || format == DefaultVertexFormat .POSITION_COLOR_TEX_LIGHTMAP );
118
- vertexCount = 0 ;
119
-
120
- if (extending ) {
121
- injectNormalAndUV1 = format == DefaultVertexFormat .POSITION_COLOR_TEX_LIGHTMAP ;
122
- }
123
- }
124
-
125
- @ Inject (method = "begin" , at = @ At ("RETURN" ))
126
- private void iris$afterBegin (VertexFormat .Mode drawMode , VertexFormat format , CallbackInfo ci ) {
127
- if (extending ) {
128
- if (format == DefaultVertexFormat .BLOCK ) {
129
- this .switchFormat (IrisVertexFormats .TERRAIN );
130
- this .iris$isTerrain = true ;
131
- } else if (format == DefaultVertexFormat .POSITION_COLOR_TEX_LIGHTMAP ) {
132
- this .switchFormat (IrisVertexFormats .GLYPH );
133
- this .iris$isTerrain = false ;
134
- } else {
135
- this .switchFormat (IrisVertexFormats .ENTITY );
136
- this .iris$isTerrain = false ;
137
- }
138
- this .currentElement = this .format .getElements ().get (0 );
139
- }
140
- }
141
-
142
105
@ Override
143
106
public @ NotNull VertexConsumer uv2 (int pBufferVertexConsumer0 , int pInt1 ) {
144
-
145
107
return BufferVertexConsumer .super .uv2 (pBufferVertexConsumer0 , pInt1 );
146
108
}
147
109
148
- @ ModifyArg (method = "begin" , at = @ At (value = "INVOKE" , target = "Lcom/mojang/blaze3d/vertex/BufferBuilder;switchFormat(Lcom/mojang/blaze3d/vertex/VertexFormat;)V" ))
149
- private VertexFormat iris$afterBeginSwitchFormat (VertexFormat arg ) {
150
- if (extending ) {
151
- if (format == DefaultVertexFormat .BLOCK ) {
152
- this .switchFormat (IrisVertexFormats .TERRAIN );
153
- this .iris$isTerrain = true ;
154
- } else if (format == DefaultVertexFormat .POSITION_COLOR_TEX_LIGHTMAP ) {
155
- this .switchFormat (IrisVertexFormats .GLYPH );
156
- this .iris$isTerrain = false ;
157
- } else {
158
- this .switchFormat (IrisVertexFormats .ENTITY );
159
- this .iris$isTerrain = false ;
160
- }
161
- }
162
- return arg ;
163
- }
164
-
165
-
166
-
167
- @ Inject (method = "discard()V" , at = @ At ("HEAD" ))
168
- private void iris$onDiscard (CallbackInfo ci ) {
110
+ @ ModifyVariable (method = "begin" , at = @ At ("HEAD" ), argsOnly = true )
111
+ private VertexFormat iris$extendFormat (VertexFormat format ) {
169
112
extending = false ;
113
+ iris$isTerrain = false ;
170
114
injectNormalAndUV1 = false ;
171
- vertexCount = 0 ;
172
- }
173
115
174
- @ Inject (method = "switchFormat" , at = @ At ("RETURN" ))
175
- private void iris$preventHardcodedVertexWriting (VertexFormat format , CallbackInfo ci ) {
176
- if (!extending ) {
177
- return ;
116
+ if (iris$shouldNotExtend || !BlockRenderingSettings .INSTANCE .shouldUseExtendedVertexFormat ()) {
117
+ return format ;
118
+ }
119
+
120
+ if (format == DefaultVertexFormat .BLOCK ) {
121
+ extending = true ;
122
+ iris$isTerrain = true ;
123
+ injectNormalAndUV1 = false ;
124
+ return IrisVertexFormats .TERRAIN ;
125
+ } else if (format == DefaultVertexFormat .NEW_ENTITY ) {
126
+ extending = true ;
127
+ iris$isTerrain = false ;
128
+ injectNormalAndUV1 = false ;
129
+ return IrisVertexFormats .ENTITY ;
130
+ } else if (format == DefaultVertexFormat .POSITION_COLOR_TEX_LIGHTMAP ) {
131
+ extending = true ;
132
+ iris$isTerrain = false ;
133
+ injectNormalAndUV1 = true ;
134
+ return IrisVertexFormats .GLYPH ;
178
135
}
179
136
180
- fastFormat = false ;
181
- fullFormat = false ;
137
+ return format ;
138
+ }
139
+
140
+ @ Inject (method = "reset()V" , at = @ At ("HEAD" ))
141
+ private void iris$onReset (CallbackInfo ci ) {
142
+ vertexCount = 0 ;
182
143
}
183
144
184
145
@ Inject (method = "endVertex" , at = @ At ("HEAD" ))
@@ -197,7 +158,7 @@ public abstract class MixinBufferBuilder extends DefaultedVertexConsumer impleme
197
158
this .putShort (0 , currentBlock );
198
159
this .putShort (2 , currentRenderType );
199
160
} else {
200
- // ENTITY_ELEMENT
161
+ // ENTITY_ID_ELEMENT
201
162
this .putShort (0 , (short ) CapturedRenderingState .INSTANCE .getCurrentRenderedEntity ());
202
163
this .putShort (2 , (short ) CapturedRenderingState .INSTANCE .getCurrentRenderedBlockEntity ());
203
164
this .putShort (4 , (short ) CapturedRenderingState .INSTANCE .getCurrentRenderedItem ());
@@ -290,6 +251,11 @@ private void fillExtendedData(int vertexAmount) {
290
251
}
291
252
}
292
253
254
+ @ Unique
255
+ private void putInt (int i , int value ) {
256
+ this .buffer .putInt (this .nextElementByte + i , value );
257
+ }
258
+
293
259
@ Override
294
260
public void beginBlock (short block , short renderType , int localPosX , int localPosY , int localPosZ ) {
295
261
this .currentBlock = block ;
@@ -308,8 +274,68 @@ public void endBlock() {
308
274
this .currentLocalPosZ = 0 ;
309
275
}
310
276
311
- @ Unique
312
- private void putInt (int i , int value ) {
313
- this .buffer .putInt (this .nextElementByte + i , value );
277
+ @ Override
278
+ public VertexFormat iris$format () {
279
+ return format ;
280
+ }
281
+
282
+ @ Override
283
+ public VertexFormat .Mode iris$mode () {
284
+ return mode ;
285
+ }
286
+
287
+ @ Override
288
+ public boolean iris$extending () {
289
+ return extending ;
290
+ }
291
+
292
+ @ Override
293
+ public boolean iris$isTerrain () {
294
+ return iris$isTerrain ;
295
+ }
296
+
297
+ @ Override
298
+ public boolean iris$injectNormalAndUV1 () {
299
+ return injectNormalAndUV1 ;
300
+ }
301
+
302
+ @ Override
303
+ public int iris$vertexCount () {
304
+ return vertexCount ;
305
+ }
306
+
307
+ @ Override
308
+ public void iris$incrementVertexCount () {
309
+ vertexCount ++;
310
+ }
311
+
312
+ @ Override
313
+ public void iris$resetVertexCount () {
314
+ vertexCount = 0 ;
315
+ }
316
+
317
+ @ Override
318
+ public short iris$currentBlock () {
319
+ return currentBlock ;
320
+ }
321
+
322
+ @ Override
323
+ public short iris$currentRenderType () {
324
+ return currentRenderType ;
325
+ }
326
+
327
+ @ Override
328
+ public int iris$currentLocalPosX () {
329
+ return currentLocalPosX ;
330
+ }
331
+
332
+ @ Override
333
+ public int iris$currentLocalPosY () {
334
+ return currentLocalPosY ;
335
+ }
336
+
337
+ @ Override
338
+ public int iris$currentLocalPosZ () {
339
+ return currentLocalPosZ ;
314
340
}
315
341
}
0 commit comments