Skip to content

Commit 04ae067

Browse files
emyfopsbladektAvanatiker
authored
[1.20.4] [All] Feat: Common buffer interface (#80)
# Description **What does this PR do?** This pull request adds a new `IBuffer` interface that can be used for any glMapBuffer compatible buffer target It contains default implementation for buffer mapping in the client's memory It adds a new task shared by all environment in order to debug renderer using [RenderDoc](https://renderdoc.org) --------- Co-authored-by: Blade-gl <[email protected]> Co-authored-by: Constructor <[email protected]>
1 parent 066d9c8 commit 04ae067

36 files changed

+1084
-646
lines changed

build.gradle.kts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
import org.gradle.internal.jvm.*
12
import net.fabricmc.loom.api.LoomGradleExtensionAPI
3+
import org.apache.tools.ant.taskdefs.condition.Os
24
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
5+
import java.io.FileNotFoundException
36
import java.util.*
47

58
val modId: String by project
@@ -66,6 +69,17 @@ subprojects {
6669
if (path == ":common") return@subprojects
6770

6871
tasks {
72+
register<Exec>("renderDoc") {
73+
val javaHome = Jvm.current().javaHome
74+
val gradleWrapper = rootProject.tasks.wrapper.get().jarFile.absolutePath
75+
76+
commandLine = listOf(
77+
findExecutable("renderdoccmd")
78+
?: throw FileNotFoundException("Could not find the renderdoccmd executable"),
79+
"capture", /* Remove the following 2 lines if you don't want api validation */ "--opt-api-validation", "--opt-api-validation-unmute", "--opt-hook-children", "--wait-for-exit", "--working-dir", ".", "$javaHome/bin/java", "-Xmx64m", "-Xms64m", /*"-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:5005",*/ "-Dorg.gradle.appname=gradlew", "-Dorg.gradle.java.home=$javaHome", "-classpath", gradleWrapper, "org.gradle.wrapper.GradleWrapperMain", "${this@subprojects.path}:runClient",
80+
)
81+
}
82+
6983
processResources {
7084
// Replaces placeholders in the mod info files
7185
filesMatching(targets) {
@@ -118,3 +132,10 @@ allprojects {
118132
}
119133
}
120134
}
135+
136+
private fun findExecutable(executable: String): String? {
137+
val isWindows = Os.isFamily(Os.FAMILY_WINDOWS)
138+
val cmd = if (isWindows) "where" else "which"
139+
140+
return ProcessBuilder(cmd, executable).start().inputStream.bufferedReader().readText().trim().takeIf { it.isNotBlank() }
141+
}

common/src/main/java/com/lambda/mixin/render/VertexBufferMixin.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
package com.lambda.mixin.render;
1919

20-
import com.lambda.graphics.gl.VaoUtils;
20+
import com.lambda.graphics.buffer.vertex.ElementBuffer;
2121
import com.mojang.blaze3d.systems.RenderSystem;
2222
import net.minecraft.client.gl.VertexBuffer;
2323
import net.minecraft.client.render.BufferBuilder;
@@ -37,6 +37,6 @@ public class VertexBufferMixin {
3737
@Inject(method = "uploadIndexBuffer", at = @At("RETURN"))
3838
private void onConfigureIndexBuffer(BufferBuilder.DrawParameters parameters, ByteBuffer vertexBuffer, CallbackInfoReturnable<RenderSystem.ShapeIndexBuffer> cir) {
3939
RenderSystem.ShapeIndexBuffer value = cir.getReturnValue();
40-
VaoUtils.lastIbo = value == null ? this.indexBufferId : value.id;
40+
ElementBuffer.lastIbo = value == null ? this.indexBufferId : value.id;
4141
}
4242
}

common/src/main/kotlin/com/lambda/graphics/animation/Animation.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
package com.lambda.graphics.animation
1919

2020
import com.lambda.Lambda.mc
21-
import com.lambda.util.math.lerp
2221
import com.lambda.util.extension.partialTicks
22+
import com.lambda.util.math.lerp
2323
import kotlin.math.abs
2424
import kotlin.reflect.KProperty
2525

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

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

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,8 @@ package com.lambda.graphics.buffer
1919

2020
import com.lambda.Lambda.mc
2121
import com.lambda.graphics.RenderMain
22-
import com.lambda.graphics.buffer.vao.VAO
23-
import com.lambda.graphics.buffer.vao.vertex.VertexAttrib
24-
import com.lambda.graphics.buffer.vao.vertex.VertexMode
22+
import com.lambda.graphics.buffer.vertex.attributes.VertexAttrib
23+
import com.lambda.graphics.buffer.vertex.attributes.VertexMode
2524
import com.lambda.graphics.gl.GlStateUtils.withBlendFunc
2625
import com.lambda.graphics.shader.Shader
2726
import com.lambda.graphics.texture.TextureUtils.bindTexture
@@ -67,7 +66,7 @@ class FrameBuffer(private val depth: Boolean = false) {
6766
shader.use()
6867
shaderBlock(shader)
6968

70-
vao.use {
69+
pipeline.use {
7170
grow(4)
7271

7372
val uv1 = pos1 / RenderMain.screenSize
@@ -82,9 +81,9 @@ class FrameBuffer(private val depth: Boolean = false) {
8281
}
8382

8483
withBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA) {
85-
vao.upload()
86-
vao.render()
87-
vao.clear()
84+
pipeline.upload()
85+
pipeline.render()
86+
pipeline.clear()
8887
}
8988

9089
return this
@@ -149,7 +148,7 @@ class FrameBuffer(private val depth: Boolean = false) {
149148
}
150149

151150
companion object {
152-
private val vao = VAO(VertexMode.TRIANGLES, VertexAttrib.Group.POS_UV)
151+
private val pipeline = VertexPipeline(VertexMode.TRIANGLES, VertexAttrib.Group.POS_UV)
153152
private var lastFrameBuffer: Int? = null
154153
}
155154
}

0 commit comments

Comments
 (0)