forked from xCollateral/VulkanMod
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRenderSystemMixin.java
More file actions
464 lines (401 loc) · 11.9 KB
/
RenderSystemMixin.java
File metadata and controls
464 lines (401 loc) · 11.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
package net.vulkanmod.mixin.render;
import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.VertexSorting;
import net.vulkanmod.gl.GlTexture;
import net.vulkanmod.vulkan.Renderer;
import net.vulkanmod.vulkan.VRenderSystem;
import org.jetbrains.annotations.Nullable;
import org.joml.Matrix4f;
import org.joml.Matrix4fStack;
import org.joml.Vector3f;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
import java.util.function.Consumer;
import static com.mojang.blaze3d.systems.RenderSystem.*;
@Mixin(RenderSystem.class)
public abstract class RenderSystemMixin {
@Shadow private static Matrix4f projectionMatrix;
@Shadow private static Matrix4f savedProjectionMatrix;
@Shadow @Final private static Matrix4fStack modelViewStack;
@Shadow private static Matrix4f modelViewMatrix;
@Shadow private static Matrix4f textureMatrix;
@Shadow @Final private static int[] shaderTextures;
@Shadow @Final private static float[] shaderColor;
@Shadow @Final private static Vector3f[] shaderLightDirections;
@Shadow @Final private static float[] shaderFogColor;
@Shadow private static @Nullable Thread renderThread;
@Shadow public static VertexSorting vertexSorting;
@Shadow private static VertexSorting savedVertexSorting;
@Shadow
public static void assertOnRenderThread() {
}
/**
* @author
*/
@Overwrite(remap = false)
public static void initRenderer(int debugVerbosity, boolean debugSync) {
VRenderSystem.initRenderer();
renderThread.setPriority(Thread.NORM_PRIORITY + 2);
}
/**
* @author
*/
@Overwrite(remap = false)
public static void setupDefaultState(int x, int y, int width, int height) { }
/**
* @author
*/
@Overwrite(remap = false)
public static void enableColorLogicOp() {
assertOnRenderThread();
VRenderSystem.enableColorLogicOp();
}
/**
* @author
*/
@Overwrite(remap = false)
public static void disableColorLogicOp() {
assertOnRenderThread();
VRenderSystem.disableColorLogicOp();
}
/**
* @author
*/
@Overwrite
public static void logicOp(GlStateManager.LogicOp op) {
assertOnRenderThread();
VRenderSystem.logicOp(op);
}
/**
* @author
*/
@Overwrite(remap = false)
public static void activeTexture(int texture) {
GlTexture.activeTexture(texture);
}
/**
* @author
*/
@Overwrite(remap = false)
public static void glGenBuffers(Consumer<Integer> consumer) {}
/**
* @author
*/
@Overwrite(remap = false)
public static void glGenVertexArrays(Consumer<Integer> consumer) {}
/**
* @author
*/
@Overwrite(remap = false)
public static int maxSupportedTextureSize() {
return VRenderSystem.maxSupportedTextureSize();
}
/**
* @author
*/
@Overwrite(remap = false)
public static void clear(int mask, boolean getError) {
VRenderSystem.clear(mask);
}
/**
* @author
*/
@Overwrite(remap = false)
public static void clearColor(float r, float g, float b, float a) {
VRenderSystem.setClearColor(r, g, b, a);
}
/**
* @author
*/
@Overwrite(remap = false)
public static void clearDepth(double d) {
VRenderSystem.clearDepth(d);
}
@Redirect(method = "flipFrame", at = @At(value = "INVOKE", target = "Lorg/lwjgl/glfw/GLFW;glfwSwapBuffers(J)V"), remap = false)
private static void removeSwapBuffers(long window) {
}
/**
* @author
*/
@Overwrite(remap = false)
public static void viewport(int x, int y, int width, int height) {
Renderer.setViewport(x, y, width, height);
}
/**
* @author
*/
@Overwrite(remap = false)
public static void enableScissor(int x, int y, int width, int height) {
Renderer.setScissor(x, y, width, height);
}
/**
* @author
*/
@Overwrite(remap = false)
public static void disableScissor() {
Renderer.resetScissor();
}
/**
* @author
*/
@Overwrite(remap = false)
public static void disableDepthTest() {
assertOnRenderThread();
//GlStateManager._disableDepthTest();
VRenderSystem.disableDepthTest();
}
/**
* @author
*/
@Overwrite(remap = false)
public static void enableDepthTest() {
assertOnRenderThreadOrInit();
VRenderSystem.enableDepthTest();
}
/**
* @author
*/
@Overwrite(remap = false)
public static void depthFunc(int i) {
assertOnRenderThread();
VRenderSystem.depthFunc(i);
}
/**
* @author
*/
@Overwrite(remap = false)
public static void depthMask(boolean b) {
assertOnRenderThread();
VRenderSystem.depthMask(b);
}
/**
* @author
*/
@Overwrite(remap = false)
public static void colorMask(boolean red, boolean green, boolean blue, boolean alpha) {
VRenderSystem.colorMask(red, green, blue, alpha);
}
/**
* @author
*/
@Overwrite(remap = false)
public static void blendEquation(int i) {
assertOnRenderThread();
//TODO
}
/**
* @author
*/
@Overwrite(remap = false)
public static void enableBlend() {
VRenderSystem.enableBlend();
}
/**
* @author
*/
@Overwrite(remap = false)
public static void disableBlend() {
VRenderSystem.disableBlend();
}
/**
* @author
*/
@Overwrite(remap = false)
public static void blendFunc(GlStateManager.SourceFactor sourceFactor, GlStateManager.DestFactor destFactor) {
VRenderSystem.blendFunc(sourceFactor, destFactor);
}
/**
* @author
*/
@Overwrite(remap = false)
public static void blendFunc(int srcFactor, int dstFactor) {
VRenderSystem.blendFunc(srcFactor, dstFactor);
}
/**
* @author
*/
@Overwrite(remap = false)
public static void blendFuncSeparate(GlStateManager.SourceFactor p_69417_, GlStateManager.DestFactor p_69418_, GlStateManager.SourceFactor p_69419_, GlStateManager.DestFactor p_69420_) {
VRenderSystem.blendFuncSeparate(p_69417_, p_69418_, p_69419_, p_69420_);
}
/**
* @author
*/
@Overwrite(remap = false)
public static void blendFuncSeparate(int srcFactorRGB, int dstFactorRGB, int srcFactorAlpha, int dstFactorAlpha) {
VRenderSystem.blendFuncSeparate(srcFactorRGB, dstFactorRGB, srcFactorAlpha, dstFactorAlpha);
}
/**
* @author
*/
@Overwrite(remap = false)
public static void enableCull() {
assertOnRenderThread();
VRenderSystem.enableCull();
}
/**
* @author
*/
@Overwrite(remap = false)
public static void disableCull() {
assertOnRenderThread();
VRenderSystem.disableCull();
}
/**
* @author
*/
@Overwrite(remap = false)
public static void polygonMode(final int face, final int mode) {
assertOnRenderThread();
VRenderSystem.setPolygonModeGL(mode);
}
/**
* @author
*/
@Overwrite(remap = false)
public static void enablePolygonOffset() {
assertOnRenderThread();
VRenderSystem.enablePolygonOffset();
}
/**
* @author
*/
@Overwrite(remap = false)
public static void disablePolygonOffset() {
assertOnRenderThread();
VRenderSystem.disablePolygonOffset();
}
/**
* @author
*/
@Overwrite(remap = false)
public static void polygonOffset(float p_69864_, float p_69865_) {
assertOnRenderThread();
VRenderSystem.polygonOffset(p_69864_, p_69865_);
}
/**
* @author
*/
@Overwrite(remap = false)
public static void setShaderLights(Vector3f dir0, Vector3f dir1) {
shaderLightDirections[0] = dir0;
shaderLightDirections[1] = dir1;
VRenderSystem.lightDirection0.buffer.putFloat(0, dir0.x());
VRenderSystem.lightDirection0.buffer.putFloat(4, dir0.y());
VRenderSystem.lightDirection0.buffer.putFloat(8, dir0.z());
VRenderSystem.lightDirection1.buffer.putFloat(0, dir1.x());
VRenderSystem.lightDirection1.buffer.putFloat(4, dir1.y());
VRenderSystem.lightDirection1.buffer.putFloat(8, dir1.z());
}
/**
* @author
*/
@Overwrite(remap = false)
private static void _setShaderColor(float r, float g, float b, float a) {
shaderColor[0] = r;
shaderColor[1] = g;
shaderColor[2] = b;
shaderColor[3] = a;
VRenderSystem.setShaderColor(r, g, b, a);
}
/**
* @author
*/
@Overwrite(remap = false)
public static void setShaderFogColor(float f, float g, float h, float i) {
shaderFogColor[0] = f;
shaderFogColor[1] = g;
shaderFogColor[2] = h;
shaderFogColor[3] = i;
VRenderSystem.setShaderFogColor(f, g, h, i);
}
/**
* @author
*/
@Overwrite(remap = false)
public static void setProjectionMatrix(Matrix4f projectionMatrix, VertexSorting vertexSorting) {
Matrix4f matrix4f = new Matrix4f(projectionMatrix);
if (!isOnRenderThread()) {
recordRenderCall(() -> {
RenderSystemMixin.projectionMatrix = matrix4f;
RenderSystem.vertexSorting = vertexSorting;
VRenderSystem.applyProjectionMatrix(matrix4f);
VRenderSystem.calculateMVP();
});
} else {
RenderSystemMixin.projectionMatrix = matrix4f;
RenderSystem.vertexSorting = vertexSorting;
VRenderSystem.applyProjectionMatrix(matrix4f);
VRenderSystem.calculateMVP();
}
}
/**
* @author
*/
@Overwrite(remap = false)
public static void setTextureMatrix(Matrix4f matrix4f) {
Matrix4f matrix4f2 = new Matrix4f(matrix4f);
if (!RenderSystem.isOnRenderThread()) {
RenderSystem.recordRenderCall(() -> {
textureMatrix = matrix4f2;
VRenderSystem.setTextureMatrix(matrix4f);
});
} else {
textureMatrix = matrix4f2;
VRenderSystem.setTextureMatrix(matrix4f);
}
}
/**
* @author
*/
@Overwrite(remap = false)
public static void resetTextureMatrix() {
if (!RenderSystem.isOnRenderThread()) {
RenderSystem.recordRenderCall(() -> textureMatrix.identity());
} else {
textureMatrix.identity();
VRenderSystem.setTextureMatrix(textureMatrix);
}
}
/**
* @author
*/
@Overwrite(remap = false)
public static void applyModelViewMatrix() {
Matrix4f matrix4f = new Matrix4f(modelViewStack);
if (!isOnRenderThread()) {
recordRenderCall(() -> {
modelViewMatrix = matrix4f;
//Vulkan
VRenderSystem.applyModelViewMatrix(matrix4f);
VRenderSystem.calculateMVP();
});
} else {
modelViewMatrix = matrix4f;
VRenderSystem.applyModelViewMatrix(matrix4f);
VRenderSystem.calculateMVP();
}
}
/**
* @author
*/
@Overwrite(remap = false)
private static void _restoreProjectionMatrix() {
projectionMatrix = savedProjectionMatrix;
vertexSorting = savedVertexSorting;
VRenderSystem.applyProjectionMatrix(projectionMatrix);
VRenderSystem.calculateMVP();
}
/**
* @author
*/
@Overwrite(remap = false)
public static void texParameter(int target, int pname, int param) {
GlTexture.texParameteri(target, pname, param);
}
}