Skip to content

Commit a165a3b

Browse files
committed
Renderer rewroriette
1 parent d99d1e7 commit a165a3b

Some content is hidden

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

42 files changed

+527
-1321
lines changed

common/src/main/kotlin/com/lambda/graphics/renderer/IRenderEntry.kt

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

common/src/main/kotlin/com/lambda/graphics/renderer/IRenderer.kt

Lines changed: 0 additions & 33 deletions
This file was deleted.
Lines changed: 6 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,89 +1,15 @@
11
package com.lambda.graphics.renderer
22

33
import com.lambda.graphics.buffer.vao.VAO
4-
import com.lambda.graphics.gl.Matrices
5-
import com.lambda.graphics.shader.Shader
6-
import com.lambda.util.math.Vec2d
7-
import kotlinx.coroutines.*
8-
import kotlin.properties.Delegates
4+
import com.lambda.graphics.buffer.vao.vertex.VertexAttrib
5+
import com.lambda.graphics.buffer.vao.vertex.VertexMode
96

10-
abstract class Renderer <T: IRenderEntry<T>> (
11-
protected val shader: Shader
12-
) : IRenderer<T> {
13-
private val entrySet = mutableSetOf<T>()
14-
protected var rebuild = false
15-
private var destroyed = false
7+
abstract class Renderer(drawMode: VertexMode, attribGroup: VertexAttrib.Group) {
8+
protected val vao = VAO(drawMode, attribGroup)
169

17-
val asRenderer get() = this as IRenderer<T>
18-
19-
// Optimization tweak to reduce build calls when whole renderer moves
20-
// Instead of rebuilding all entries you translate the matrix
21-
var matrixOffset = Vec2d.ZERO
22-
23-
abstract val vao: VAO
24-
protected abstract fun newEntry(block: T.() -> Unit): T
25-
26-
override fun build(block: T.() -> Unit): T {
27-
return newEntry(block).process(entrySet::add)
28-
}
29-
30-
override fun remove(entry: T): T {
31-
return entry.process(entrySet::remove)
32-
}
33-
34-
override fun render() {
35-
if (destroyed) return
36-
37-
if (rebuild) {
38-
rebuild = false
39-
40-
vao.clear()
41-
entrySet.forEach { it.build(vao) }
42-
vao.upload()
43-
}
44-
45-
Matrices.push()
46-
Matrices.translate(matrixOffset.x, matrixOffset.y, 0.0)
47-
48-
shader.use()
49-
preRender()
10+
open fun render() {
11+
vao.upload()
5012
vao.render()
51-
52-
Matrices.pop()
53-
}
54-
55-
protected open fun preRender() {}
56-
57-
override fun update() {
58-
if (destroyed) return
59-
entrySet.forEach(IRenderEntry<T>::update)
60-
}
61-
62-
override fun clear() {
63-
if (destroyed) return
64-
65-
entrySet.clear()
6613
vao.clear()
6714
}
68-
69-
override fun destroy() {
70-
if (destroyed) return
71-
72-
entrySet.clear()
73-
vao.destroy()
74-
destroyed = true
75-
}
76-
77-
private fun T.process(action: T.() -> Unit): T {
78-
this.apply(action)
79-
rebuild = true
80-
81-
return this
82-
}
83-
84-
fun <T> field(initValue: T) =
85-
Delegates.observable(initValue) { _, prev: T, curr: T ->
86-
if (prev == curr) return@observable
87-
rebuild = true
88-
}
8915
}

common/src/main/kotlin/com/lambda/graphics/renderer/gui/AbstractGuiRenderer.kt

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

common/src/main/kotlin/com/lambda/graphics/renderer/immediate/BlurPostProcessor.kt renamed to common/src/main/kotlin/com/lambda/graphics/renderer/gui/BlurPostProcessor.kt

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
package com.lambda.graphics.renderer.immediate
1+
package com.lambda.graphics.renderer.gui
22

3-
import com.lambda.Lambda.mc
3+
import com.lambda.Lambda
44
import com.lambda.graphics.RenderMain
55
import com.lambda.graphics.buffer.vao.VAO
66
import com.lambda.graphics.buffer.vao.vertex.VertexAttrib
77
import com.lambda.graphics.buffer.vao.vertex.VertexMode
88
import com.lambda.graphics.shader.Shader
9-
import com.lambda.graphics.texture.TextureUtils.bindTexture
9+
import com.lambda.graphics.texture.TextureUtils
1010
import com.lambda.util.math.Rect
1111
import com.lambda.util.math.Vec2d
1212

@@ -41,11 +41,14 @@ object BlurPostProcessor {
4141
)
4242

4343
shader.use()
44-
shader["u_Direction"] = direction / Vec2d(mc.window.framebufferWidth, mc.window.framebufferHeight)
44+
shader["u_Direction"] = direction / Vec2d(
45+
Lambda.mc.window.framebufferWidth,
46+
Lambda.mc.window.framebufferHeight
47+
)
4548
shader["u_BlurLevel"] = level
4649
shader["u_Alpha"] = alpha
4750

48-
bindTexture(mc.framebuffer.colorAttachment)
51+
TextureUtils.bindTexture(Lambda.mc.framebuffer.colorAttachment)
4952
upload()
5053
render()
5154
clear()

common/src/main/kotlin/com/lambda/graphics/renderer/gui/font/FontEntry.kt

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

0 commit comments

Comments
 (0)