Skip to content

Commit 4bce875

Browse files
committed
Working immediate mode ui
1 parent a0189f7 commit 4bce875

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+438
-546
lines changed

common/src/main/kotlin/com/lambda/event/events/GuiEvent.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ sealed class GuiEvent : Event {
2626
data object Show : GuiEvent()
2727
data object Hide : GuiEvent()
2828
data object Tick : GuiEvent()
29+
data object Update : GuiEvent()
2930
data object Render : GuiEvent()
3031

3132
class KeyPress(val key: KeyCode) : GuiEvent()

common/src/main/kotlin/com/lambda/event/events/RenderEvent.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import com.lambda.Lambda.mc
2121
import com.lambda.event.Event
2222
import com.lambda.event.callback.Cancellable
2323
import com.lambda.event.callback.ICancellable
24-
import com.lambda.graphics.pipeline.UIPipeline
2524
import com.lambda.graphics.renderer.esp.global.DynamicESP
2625
import com.lambda.graphics.renderer.esp.global.StaticESP
2726
import com.lambda.util.math.Vec2d

common/src/main/kotlin/com/lambda/graphics/RenderMain.kt

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import com.lambda.event.events.RenderEvent
2323
import com.lambda.graphics.gl.GlStateUtils.setupGL
2424
import com.lambda.graphics.gl.Matrices
2525
import com.lambda.graphics.gl.Matrices.resetMatrices
26-
import com.lambda.graphics.pipeline.UIPipeline
2726
import com.lambda.module.modules.client.GuiSettings
2827
import com.lambda.util.math.Vec2d
2928
import com.mojang.blaze3d.systems.RenderSystem.getProjectionMatrix
@@ -35,22 +34,19 @@ object RenderMain {
3534
val projModel get() = Matrix4f(projectionMatrix).mul(modelViewMatrix)
3635

3736
var screenSize = Vec2d.ZERO
37+
var scaleFactor = 1.0
3838

3939
@JvmStatic
4040
fun render2D() {
4141
resetMatrices(Matrix4f().translate(0f, 0f, -3000f))
4242

4343
setupGL {
44-
UIPipeline.reset()
45-
4644
rescale(1.0)
4745
RenderEvent.GUI.Fixed().post()
4846

4947
rescale(GuiSettings.scale)
5048
RenderEvent.GUI.HUD(GuiSettings.scale).post()
5149
RenderEvent.GUI.Scaled(GuiSettings.scale).post()
52-
53-
UIPipeline.render()
5450
}
5551
}
5652

@@ -72,6 +68,8 @@ object RenderMain {
7268
val scaledHeight = height / factor
7369

7470
screenSize = Vec2d(scaledWidth, scaledHeight)
71+
scaleFactor = factor
72+
7573
projectionMatrix.setOrtho(0f, scaledWidth.toFloat(), scaledHeight.toFloat(), 0f, 1000f, 21000f)
7674
}
7775
}

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,12 @@ abstract class Buffer(
121121
/**
122122
* Binds current the buffer [index] to the [target]
123123
*/
124-
fun bind() = bind(bufferIds[index])
124+
fun bind() = bind(bufferAt(index))
125+
126+
/**
127+
* Returns the id of the buffer based on the index
128+
*/
129+
fun bufferAt(index: Int) = bufferIds[index]
125130

126131
/**
127132
* Swaps the buffer [index] if [buffers] is greater than 1

common/src/main/kotlin/com/lambda/graphics/buffer/VertexPipeline.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import com.lambda.graphics.gl.Memory.vector2f
3232
import com.lambda.graphics.gl.Memory.vector3f
3333
import com.lambda.graphics.gl.kibibyte
3434
import org.joml.Vector4d
35+
import org.lwjgl.opengl.GL15C
3536
import org.lwjgl.opengl.GL20C.*
3637
import java.awt.Color
3738

@@ -183,6 +184,10 @@ class VertexPipeline(
183184
uploadedIndices = 0
184185
}
185186

187+
fun finalize() {
188+
189+
}
190+
186191
init {
187192
// All the buffers have been generated, all we have to
188193
// do now it bind them correctly and populate them

common/src/main/kotlin/com/lambda/graphics/buffer/vertex/attributes/VertexAttrib.kt

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,26 +41,19 @@ enum class VertexAttrib(
4141
FONT(
4242
Vec3, // pos
4343
Vec2, // uv
44-
Vec2, Vec2, // scissor test bounds
4544
Color
4645
),
4746

4847
RECT_FILLED(
4948
Vec3, // pos
5049
Vec2, // uv
51-
Vec2, // size
52-
Vec2, Vec2, // roundL, roundR
53-
Float, // shade
54-
Vec2, Vec2, // scissor test bounds
5550
Color
5651
),
5752

5853
RECT_OUTLINE(
5954
Vec3, // pos
6055
Vec2, // uv
6156
Float, // alpha
62-
Float, // shade
63-
Vec2, Vec2, // scissor test bounds
6457
Color
6558
),
6659

common/src/main/kotlin/com/lambda/graphics/gl/Matrices.kt

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ object Matrices {
3838
*/
3939
var vertexTransformer: Matrix4d? = null
4040

41+
/**
42+
* An optional vec3 offset for applying vertex transformations.
43+
*/
44+
var vertexOffset: Vec3d? = null
45+
4146
/**
4247
* Executes a block of code within the context of a new matrix.
4348
* The current matrix is pushed onto the stack before the block executes and popped after the block completes.
@@ -51,7 +56,7 @@ object Matrices {
5156
*/
5257
fun push(block: Matrices.() -> Unit) {
5358
push()
54-
block()
59+
block.invoke(this)
5560
pop()
5661
}
5762

@@ -146,6 +151,20 @@ object Matrices {
146151
vertexTransformer = null
147152
}
148153

154+
/**
155+
* Temporarily sets a vertex offset vector for the duration of a block.
156+
*
157+
* Use this to avoid precision loss when using matrices while being on huge coordinates.
158+
*
159+
* @param offset The transformation offset to apply to vertices.
160+
* @param block The block of code to execute with the transformation applied.
161+
*/
162+
fun withVertexOffset(offset: Vec3d, block: () -> Unit) {
163+
vertexOffset = offset
164+
block()
165+
vertexOffset = null
166+
}
167+
149168
/**
150169
* Builds a world projection matrix for a given position, scale, and rotation mode.
151170
*

common/src/main/kotlin/com/lambda/graphics/pipeline/ScissorAdapter.kt

Lines changed: 20 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -17,71 +17,43 @@
1717

1818
package com.lambda.graphics.pipeline
1919

20-
import com.lambda.graphics.renderer.gui.font.core.GlyphInfo
20+
import com.lambda.Lambda.mc
21+
import com.lambda.graphics.RenderMain
22+
import com.lambda.util.math.MathUtils.ceilToInt
23+
import com.lambda.util.math.MathUtils.floorToInt
2124
import com.lambda.util.math.Rect
22-
import com.lambda.util.math.transform
25+
import com.mojang.blaze3d.systems.RenderSystem.disableScissor
26+
import com.mojang.blaze3d.systems.RenderSystem.enableScissor
2327

2428
object ScissorAdapter {
2529
private var stack = ArrayDeque<Rect>()
26-
private val scissorInstance = ScissorRect()
2730

2831
fun scissor(rect: Rect, block: () -> Unit) {
29-
// clamp corners so children scissor boxes can't overlap parent
3032
val processed = stack.lastOrNull()?.let(rect::clamp) ?: rect
3133

32-
// push the stack
3334
stack.add(processed)
35+
scissorRect(processed)
3436

35-
// do render tasks
3637
block()
3738

38-
// pop the stack
3939
stack.removeLast()
40+
stack.lastOrNull()?.let { scissorRect(it) } ?: disableScissor()
4041
}
4142

42-
fun scissorTest(x1: Double, y1: Double, x2: Double, y2: Double, glyph: GlyphInfo? = null): ScissorRect {
43-
reset()
43+
private fun scissorRect(rect: Rect) {
44+
val pos1 = rect.leftTop * RenderMain.scaleFactor
45+
val pos2 = rect.rightBottom * RenderMain.scaleFactor
4446

45-
run {
46-
val entry = stack.lastOrNull() ?: return@run
47+
val width = pos2.x - pos1.x
48+
val height = pos2.y - pos1.y
4749

48-
val width = x2 - x1
49-
val height = y2 - y1
50+
val y = mc.window.framebufferHeight - pos1.y - height
5051

51-
if (width <= 0 || height <= 0) {
52-
nullify()
53-
return@run
54-
}
55-
56-
val si = scissorInstance
57-
58-
si.x1 = transform(entry.left, x1, x2, glyph?.u1 ?: 0.0, glyph?.u2 ?: 1.0)
59-
si.y1 = transform(entry.top, y1, y2, glyph?.v1 ?: 0.0, glyph?.v2 ?: 1.0)
60-
si.x2 = transform(entry.right, x1, x2, glyph?.u1 ?: 0.0, glyph?.u2 ?: 1.0)
61-
si.y2 = transform(entry.bottom, y1, y2, glyph?.v1 ?: 0.0, glyph?.v2 ?: 1.0)
62-
}
63-
64-
return scissorInstance
65-
}
66-
67-
private fun reset() = scissorInstance.apply {
68-
x1 = 0.0
69-
y1 = 0.0
70-
x2 = 1.0
71-
y2 = 1.0
72-
}
73-
74-
private fun nullify() = scissorInstance.apply {
75-
x1 = 0.0
76-
y1 = 0.0
77-
x2 = 0.0
78-
y2 = 0.0
79-
}
80-
81-
class ScissorRect {
82-
var x1 = 0.0
83-
var y1 = 0.0
84-
var x2 = 1.0
85-
var y2 = 1.0
52+
enableScissor(
53+
pos1.x.floorToInt(),
54+
y.floorToInt(),
55+
width.ceilToInt(),
56+
height.ceilToInt()
57+
)
8658
}
8759
}

common/src/main/kotlin/com/lambda/graphics/pipeline/UIPipeline.kt

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

common/src/main/kotlin/com/lambda/graphics/renderer/esp/ESPRenderer.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import com.lambda.graphics.buffer.vertex.attributes.VertexAttrib
2323
import com.lambda.graphics.buffer.vertex.attributes.VertexMode
2424
import com.lambda.graphics.gl.GlStateUtils
2525
import com.lambda.graphics.shader.Shader
26+
import com.lambda.graphics.shader.Shader.Companion.shader
2627
import com.lambda.module.modules.client.RenderSettings
2728
import com.lambda.util.extension.partialTicks
2829

@@ -59,12 +60,12 @@ open class ESPRenderer(tickedMode: Boolean) {
5960
}
6061

6162
companion object {
62-
private val staticMode = Shader(
63+
private val staticMode = shader(
6364
"renderer/pos_color",
6465
"renderer/box_static"
6566
) to VertexAttrib.Group.STATIC_RENDERER
6667

67-
private val dynamicMode = Shader(
68+
private val dynamicMode = shader(
6869
"renderer/pos_color",
6970
"renderer/box_dynamic"
7071
) to VertexAttrib.Group.DYNAMIC_RENDERER

0 commit comments

Comments
 (0)