Skip to content

Commit 6d7a344

Browse files
committed
some fix
1 parent 4ab774e commit 6d7a344

File tree

18 files changed

+196
-531
lines changed

18 files changed

+196
-531
lines changed

src/main/java/com/lambda/mixin/input/KeyboardMixin.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
public class KeyboardMixin {
3030
@Inject(method = "onKey", at = @At("HEAD"))
3131
private void onKey(long window, int key, int scancode, int action, int modifiers, CallbackInfo ci) {
32-
if (key <= 0) return;
3332
EventFlow.post(new KeyboardEvent.Press(key, scancode, action, modifiers));
3433
}
3534

src/main/java/com/lambda/mixin/render/GlResourceManagerMixin.java

Lines changed: 0 additions & 31 deletions
This file was deleted.

src/main/java/com/lambda/mixin/render/LivingEntityRendererMixin.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package com.lambda.mixin.render;
1919

2020
import com.lambda.interaction.request.rotation.RotationManager;
21+
import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
2122
import net.minecraft.client.render.entity.LivingEntityRenderer;
2223
import net.minecraft.entity.LivingEntity;
2324
import org.spongepowered.asm.mixin.Mixin;
@@ -45,8 +46,8 @@ public class LivingEntityRendererMixin {
4546
* }
4647
* }</pre>
4748
*/
48-
@Redirect(method = "updateRenderState(Lnet/minecraft/entity/LivingEntity;Lnet/minecraft/client/render/entity/state/LivingEntityRenderState;F)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;getLerpedPitch(F)F", ordinal = 0), require = 0)
49-
private float injectRotationPitch(LivingEntity instance, float v) {
50-
return Objects.requireNonNullElse(RotationManager.getRenderPitch(), v);
49+
@ModifyExpressionValue(method = "updateRenderState(Lnet/minecraft/entity/LivingEntity;Lnet/minecraft/client/render/entity/state/LivingEntityRenderState;F)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;getLerpedPitch(F)F"))
50+
private float injectRotationPitch(float original) {
51+
return Objects.requireNonNullElse(RotationManager.getRenderPitch(), original);
5152
}
5253
}

src/main/java/com/lambda/mixin/render/VertexFormatMixin.java

Lines changed: 0 additions & 38 deletions
This file was deleted.

src/main/kotlin/com/lambda/graphics/buffer/Buffer.kt

Lines changed: 28 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2025 Lambda
2+
* Copyright 2024 Lambda
33
*
44
* This program is free software: you can redistribute it and/or modify
55
* it under the terms of the GNU General Public License as published by
@@ -17,40 +17,6 @@
1717

1818
package com.lambda.graphics.buffer
1919

20-
import org.lwjgl.opengl.GL15.GL_ARRAY_BUFFER
21-
import org.lwjgl.opengl.GL15.GL_DYNAMIC_COPY
22-
import org.lwjgl.opengl.GL15.GL_DYNAMIC_DRAW
23-
import org.lwjgl.opengl.GL15.GL_DYNAMIC_READ
24-
import org.lwjgl.opengl.GL15.GL_ELEMENT_ARRAY_BUFFER
25-
import org.lwjgl.opengl.GL15.GL_STATIC_COPY
26-
import org.lwjgl.opengl.GL15.GL_STATIC_DRAW
27-
import org.lwjgl.opengl.GL15.GL_STATIC_READ
28-
import org.lwjgl.opengl.GL15.GL_STREAM_COPY
29-
import org.lwjgl.opengl.GL15.GL_STREAM_DRAW
30-
import org.lwjgl.opengl.GL15.GL_STREAM_READ
31-
import org.lwjgl.opengl.GL15.glBufferSubData
32-
import org.lwjgl.opengl.GL21.GL_PIXEL_PACK_BUFFER
33-
import org.lwjgl.opengl.GL21.GL_PIXEL_UNPACK_BUFFER
34-
import org.lwjgl.opengl.GL30.GL_MAP_FLUSH_EXPLICIT_BIT
35-
import org.lwjgl.opengl.GL30.GL_MAP_INVALIDATE_BUFFER_BIT
36-
import org.lwjgl.opengl.GL30.GL_MAP_INVALIDATE_RANGE_BIT
37-
import org.lwjgl.opengl.GL30.GL_MAP_READ_BIT
38-
import org.lwjgl.opengl.GL30.GL_MAP_UNSYNCHRONIZED_BIT
39-
import org.lwjgl.opengl.GL30.GL_MAP_WRITE_BIT
40-
import org.lwjgl.opengl.GL30.GL_TRANSFORM_FEEDBACK_BUFFER
41-
import org.lwjgl.opengl.GL31.GL_COPY_READ_BUFFER
42-
import org.lwjgl.opengl.GL31.GL_COPY_WRITE_BUFFER
43-
import org.lwjgl.opengl.GL31.GL_TEXTURE_BUFFER
44-
import org.lwjgl.opengl.GL31.GL_UNIFORM_BUFFER
45-
import org.lwjgl.opengl.GL40.GL_DRAW_INDIRECT_BUFFER
46-
import org.lwjgl.opengl.GL42.GL_ATOMIC_COUNTER_BUFFER
47-
import org.lwjgl.opengl.GL43.GL_DISPATCH_INDIRECT_BUFFER
48-
import org.lwjgl.opengl.GL43.GL_SHADER_STORAGE_BUFFER
49-
import org.lwjgl.opengl.GL44.GL_CLIENT_STORAGE_BIT
50-
import org.lwjgl.opengl.GL44.GL_DYNAMIC_STORAGE_BIT
51-
import org.lwjgl.opengl.GL44.GL_MAP_COHERENT_BIT
52-
import org.lwjgl.opengl.GL44.GL_MAP_PERSISTENT_BIT
53-
import org.lwjgl.opengl.GL44.GL_QUERY_BUFFER
5420
import org.lwjgl.opengl.GL46.*
5521
import java.nio.ByteBuffer
5622

@@ -70,6 +36,7 @@ abstract class Buffer(
7036
* Edge case to handle vertex arrays
7137
*/
7238
val isVertexArray: Boolean = false,
39+
val validate: Boolean = true
7340
) {
7441
/**
7542
* Specifies how the buffers are used
@@ -139,27 +106,43 @@ abstract class Buffer(
139106
/**
140107
* Index of the current buffer.
141108
*/
142-
var index: Int = 0; private set
109+
private var index: Int = 0; private set(value) {
110+
if (field == value) return
111+
field = value
112+
id = bufferIds[value]
113+
}
114+
115+
/**
116+
* ID of the current buffer.
117+
*/
118+
var id: Int = 0; get() {
119+
if (field == 0) field = bufferIds[0]
120+
return field
121+
} private set
143122

144123
/**
145124
* List of all the buffers.
146125
*/
147126
private val bufferIds = IntArray(buffers)
148127

149128
/**
150-
* Binds the buffer id to the [target].
129+
* Execute the [block] in a bound context
151130
*/
152-
open fun bind(id: Int) = glBindBuffer(target, id)
131+
fun bind(block: Buffer.() -> Unit) {
132+
bind()
133+
block(this)
134+
bind(0)
135+
}
153136

154137
/**
155-
* Binds current the buffer [index] to the [target].
138+
* Binds the buffer id to the [target].
156139
*/
157-
fun bind() = bind(bufferAt(index))
140+
open fun bind(id: Int) = glBindBuffer(target, id)
158141

159142
/**
160-
* Returns the id of the buffer based on the index.
143+
* Binds current the buffer [index] to the [target].
161144
*/
162-
fun bufferAt(index: Int) = bufferIds[index]
145+
fun bind() = bind(id)
163146

164147
/**
165148
* Swaps the buffer [index] if [buffers] is greater than 1.
@@ -351,6 +334,8 @@ abstract class Buffer(
351334
abstract fun upload(data: ByteBuffer, offset: Long)
352335

353336
private fun validate() {
337+
if (!validate) return
338+
354339
check(usage in GL_STREAM_DRAW..GL_DYNAMIC_COPY)
355340
{ "Usage is invalid, refer to the documentation table." }
356341

@@ -393,7 +378,7 @@ abstract class Buffer(
393378
var lastIbo = 0
394379
var prevIbo = 0
395380

396-
fun createPipelineBuffer(bufferTarget: Int) = object : Buffer(buffers = 1) {
381+
fun createPipelineBuffer(bufferTarget: Int) = object : Buffer(buffers = 1, validate = false) {
397382
override val target: Int = bufferTarget
398383

399384
override val usage: Int = GL_STATIC_DRAW

src/main/kotlin/com/lambda/graphics/buffer/frame/CachedFrame.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2025 Lambda
2+
* Copyright 2024 Lambda
33
*
44
* This program is free software: you can redistribute it and/or modify
55
* it under the terms of the GNU General Public License as published by

src/main/kotlin/com/lambda/graphics/buffer/frame/FrameBuffer.kt

Lines changed: 28 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2025 Lambda
2+
* Copyright 2024 Lambda
33
*
44
* This program is free software: you can redistribute it and/or modify
55
* it under the terms of the GNU General Public License as published by
@@ -18,50 +18,27 @@
1818
package com.lambda.graphics.buffer.frame
1919

2020
import com.lambda.Lambda.mc
21+
import com.lambda.graphics.pipeline.VertexPipeline
2122
import com.lambda.graphics.buffer.vertex.attributes.VertexAttrib
2223
import com.lambda.graphics.buffer.vertex.attributes.VertexMode
23-
import com.lambda.graphics.pipeline.VertexPipeline
2424
import com.lambda.graphics.texture.TextureUtils
25+
import com.mojang.blaze3d.systems.RenderSystem
26+
import net.minecraft.client.gl.GlBackend
2527
import net.minecraft.client.texture.GlTexture
2628
import org.lwjgl.opengl.GL12C.GL_CLAMP_TO_EDGE
27-
import org.lwjgl.opengl.GL30C.GL_COLOR_ATTACHMENT0
28-
import org.lwjgl.opengl.GL30C.GL_COLOR_BUFFER_BIT
29-
import org.lwjgl.opengl.GL30C.GL_DEPTH_ATTACHMENT
30-
import org.lwjgl.opengl.GL30C.GL_DEPTH_BUFFER_BIT
31-
import org.lwjgl.opengl.GL30C.GL_DEPTH_COMPONENT
32-
import org.lwjgl.opengl.GL30C.GL_DEPTH_COMPONENT32F
33-
import org.lwjgl.opengl.GL30C.GL_FLOAT
34-
import org.lwjgl.opengl.GL30C.GL_FRAMEBUFFER
35-
import org.lwjgl.opengl.GL30C.GL_FRAMEBUFFER_COMPLETE
36-
import org.lwjgl.opengl.GL30C.GL_LINEAR
37-
import org.lwjgl.opengl.GL30C.GL_RGBA
38-
import org.lwjgl.opengl.GL30C.GL_TEXTURE_2D
39-
import org.lwjgl.opengl.GL30C.GL_TEXTURE_MAG_FILTER
40-
import org.lwjgl.opengl.GL30C.GL_TEXTURE_MIN_FILTER
41-
import org.lwjgl.opengl.GL30C.GL_TEXTURE_WRAP_S
42-
import org.lwjgl.opengl.GL30C.GL_TEXTURE_WRAP_T
43-
import org.lwjgl.opengl.GL30C.GL_UNSIGNED_BYTE
44-
import org.lwjgl.opengl.GL30C.glBindFramebuffer
45-
import org.lwjgl.opengl.GL30C.glCheckFramebufferStatus
46-
import org.lwjgl.opengl.GL30C.glClear
47-
import org.lwjgl.opengl.GL30C.glClearColor
48-
import org.lwjgl.opengl.GL30C.glClearDepth
49-
import org.lwjgl.opengl.GL30C.glFramebufferTexture2D
50-
import org.lwjgl.opengl.GL30C.glGenFramebuffers
51-
import org.lwjgl.opengl.GL30C.glGenTextures
52-
import org.lwjgl.opengl.GL30C.glTexImage2D
53-
import org.lwjgl.opengl.GL30C.glTexParameteri
29+
import org.lwjgl.opengl.GL30C.*
30+
import sun.awt.geom.Curve.prev
5431
import java.nio.IntBuffer
5532

5633
open class FrameBuffer(
57-
protected var width: Int = 1,
58-
protected var height: Int = 1,
34+
var width: Int = 1,
35+
var height: Int = 1,
5936
private val depth: Boolean = false
6037
) {
61-
private val fbo = glGenFramebuffers()
38+
val fbo = glGenFramebuffers()
6239

63-
private val colorAttachment = glGenTextures()
64-
private val depthAttachment by lazy(::glGenTextures)
40+
val colorAttachment = glGenTextures()
41+
val depthAttachment by lazy(::glGenTextures)
6542

6643
private val clearMask = if (!depth) GL_COLOR_BUFFER_BIT
6744
else GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT
@@ -70,22 +47,32 @@ open class FrameBuffer(
7047
private var lastHeight = -1
7148

7249
open fun write(block: () -> Unit): FrameBuffer {
73-
val prev = lastFrameBuffer ?: (mc.framebuffer.colorAttachment as GlTexture).glId
50+
// You're a real one dude https://github.com/FlorianMichael/fabric-imgui-example-mod/blob/1.21.5/src/main/java/de/florianmichael/imguiexample/imgui/ImGuiImpl.java
51+
// Minecraft will not bind the framebuffer unless it is needed, so do it manually and hope Vulcan never gets real:tm:
52+
val framebuffer = mc.framebuffer
53+
val prevFramebuffer = (framebuffer.getColorAttachment() as GlTexture).getOrCreateFramebuffer((RenderSystem.getDevice() as GlBackend).framebufferManager, null)
7454

7555
glBindFramebuffer(GL_FRAMEBUFFER, fbo)
76-
lastFrameBuffer = fbo
7756

7857
update()
79-
8058
block()
8159

82-
lastFrameBuffer = prev
83-
glBindFramebuffer(GL_FRAMEBUFFER, prev)
60+
glBindFramebuffer(GL_FRAMEBUFFER, prevFramebuffer)
8461
return this
8562
}
8663

87-
private fun update() {
88-
if (width == lastWidth && height == lastWidth) {
64+
fun bind() {
65+
glBindFramebuffer(GL_FRAMEBUFFER, fbo)
66+
}
67+
68+
fun updateScreenSized() {
69+
width = mc.framebuffer.viewportWidth
70+
height = mc.framebuffer.viewportHeight
71+
update()
72+
}
73+
74+
fun update() {
75+
if (width == lastWidth && height == lastHeight) {
8976
glClear(clearMask)
9077
return
9178
}

0 commit comments

Comments
 (0)