Skip to content

Commit 6f2c3ee

Browse files
committed
3.0.0
1 parent 7691068 commit 6f2c3ee

File tree

10 files changed

+96
-56
lines changed

10 files changed

+96
-56
lines changed

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ plugins {
1111
}
1212

1313
group = "gg.generations"
14-
version = "2.14.0"
14+
version = "3.0.0"
1515

1616
java.toolchain.languageVersion.set(JavaLanguageVersion.of(21))
1717

src/library/java/gg/generations/rarecandy/renderer/animation/AnimationInstance.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ public AnimationInstance(Animation animation) {
3636
}
3737

3838
public void update(double secondsPassed) {
39+
if(animation == null) {
40+
this.matrixTransforms = AnimationController.NO_ANIMATION;
41+
42+
return;
43+
}
3944
updateStart(secondsPassed);
4045

4146
if (!paused) {
@@ -45,7 +50,6 @@ public void update(double secondsPassed) {
4550
if (prevTime > currentTime) onLoop();
4651
} else if (timeAtPause == -1) timeAtPause = secondsPassed;
4752

48-
if(animation == null) return;
4953
matrixTransforms = animation.getFrameTransform(secondsPassed);
5054
}
5155

src/library/java/gg/generations/rarecandy/renderer/animation/Transform.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ public boolean isUnit() {
2121
return offset.x == 0f && offset.y == 0f && scale.x == 1f && scale.y == 1f;
2222
}
2323

24-
public void upload(int pos, SSBOBuffer buffer) {
25-
buffer.put(pos, scale);
26-
buffer.put(pos + Float.BYTES * 2, offset);
24+
public void upload(SSBOBuffer buffer) {
25+
buffer.put(scale);
26+
buffer.put(offset);
2727
}
2828
}
2929

src/library/java/gg/generations/rarecandy/renderer/components/MultiRenderObject.java

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import org.joml.Matrix4f;
1515
import org.joml.Vector3f;
1616
import org.lwjgl.opengl.GL43;
17-
import org.lwjgl.opengl.GL43C;
1817

1918
import java.io.IOException;
2019
import java.util.*;
@@ -62,7 +61,7 @@ public abstract class MultiRenderObject {
6261

6362
private Matrix4f rootTransformation = new Matrix4f();
6463

65-
private final List<ObjectInstance> instances = new ArrayList<>();
64+
protected final List<ObjectInstance> instances = new ArrayList<>();
6665

6766
public MultiRenderObject(ModelLoader.Names names) {
6867
meshes = new DrawRecord[names.meshes().size()];
@@ -174,10 +173,10 @@ public boolean isEmpty() {
174173

175174
public void updateSSBOs() {
176175
ensureCapacity();
177-
for (int i = 0; i < instances.size(); i++) {
178-
var instance = instances.get(i);
176+
resetSSBOs();
179177

180-
instance.update(i * InstanceDetails.size, instanceBuffer);
178+
for (ObjectInstance instance : instances) {
179+
instance.update(instanceBuffer);
181180

182181
for (int meshId = 0; meshId < meshes.length; meshId++) {
183182

@@ -196,19 +195,23 @@ public void updateSSBOs() {
196195
}
197196
}
198197

199-
if(transform == null) {
198+
if (transform == null) {
200199
transform = Transform.DEFAULT;
201200
}
202201

203-
int stride = Float.BYTES * 4; // 16
204-
int index = i * meshes.length + meshId;
205-
transform.upload(index * stride, uvTransformBuffer); }
202+
transform.upload(uvTransformBuffer);
203+
}
206204
}
207205

208206
instanceBuffer.upload();
209207
uvTransformBuffer.upload();
210208
}
211209

210+
private void resetSSBOs() {
211+
instanceBuffer.reset();
212+
uvTransformBuffer.reset();
213+
}
214+
212215
public <T extends ObjectInstance> boolean add(@NotNull T instance) {
213216
if(!instance.isLinked()) {
214217
instance.link(this);

src/library/java/gg/generations/rarecandy/renderer/loading/ModelLoader.java

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,9 @@
3232

3333
public class ModelLoader {
3434
public static int byteAmount;
35-
// private final ExecutorService modelLoadingPool;
3635

3736
private static final Vector3f temp = new Vector3f();
3837

39-
public ModelLoader() {
40-
this(4);
41-
}
42-
43-
public ModelLoader(int numThreads) {
44-
// this.modelLoadingPool = Executors.newFixedThreadPool(numThreads);
45-
}
46-
47-
4838
public static List<Attribute> ATTRIBUTES = List.of(
4939
Attribute.POSITION,
5040
Attribute.TEXCOORD,
@@ -631,7 +621,7 @@ public Names() {
631621
}
632622
}
633623

634-
public MultiRenderObject createObject(Function<Names, MultiRenderObject> objBuilder, @NotNull Supplier<PixelAsset> is, BiFunction<MaterialReference, List<String>, Material> materialProcess, Consumer<MultiRenderObject> onFinish) {
624+
public static MultiRenderObject createObject(Function<Names, MultiRenderObject> objBuilder, @NotNull Supplier<PixelAsset> is, BiFunction<MaterialReference, List<String>, Material> materialProcess, Consumer<MultiRenderObject> onFinish) {
635625
var asset = is.get();
636626
var config = asset.getConfig();
637627

@@ -783,11 +773,11 @@ public MultiRenderObject createObject(Function<Names, MultiRenderObject> objBuil
783773
// }
784774
// }
785775

786-
private void checkIfAlreadyIn(List<String> list, String entry) {
776+
private static void checkIfAlreadyIn(List<String> list, String entry) {
787777
checkIfAlreadyIn(list, entry, false);
788778
}
789779

790-
private void checkIfAlreadyIn(List<String> list, String entry, boolean addFirst) {
780+
private static void checkIfAlreadyIn(List<String> list, String entry, boolean addFirst) {
791781
if(!list.contains(entry)) if(addFirst) list.addFirst(entry); else list.add(entry);
792782
}
793783

src/library/java/gg/generations/rarecandy/renderer/rendering/ObjectInstance.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ public ObjectInstance(Matrix4f transformationMatrix, int variant) {
2424
this.variant = variant;
2525
}
2626

27-
public void update(int pos, SSBOBuffer instanceBuffer) {
28-
instanceBuffer.put(pos, transformationMatrix);
27+
public void update(SSBOBuffer instanceBuffer) {
28+
instanceBuffer.put(transformationMatrix);
2929
}
3030

3131
public void link(MultiRenderObject object) {

src/library/java/gg/generations/rarecandy/renderer/storage/AnimatedObjectInstance.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import org.jetbrains.annotations.Nullable;
88
import org.joml.Matrix4f;
99

10+
import java.util.Arrays;
11+
1012
public class AnimatedObjectInstance extends ObjectInstance {
1113
public static final int ANIMATED_SIZE = MAT4_SIZE * 221;
1214

@@ -18,15 +20,12 @@ public AnimatedObjectInstance(Matrix4f transformationMatrix, int materialId) {
1820
}
1921

2022
@Override
21-
public void update(int pos, SSBOBuffer instanceBuffer) {
22-
super.update(pos, instanceBuffer);
23+
public void update(SSBOBuffer instanceBuffer) {
24+
super.update(instanceBuffer);
2325

2426
var bones = getTransforms();
2527

26-
for (int i = 0; i < bones.length; i++) {
27-
var bone = bones[i];
28-
instanceBuffer.put((1 + i) * MAT4_SIZE, bone);
29-
}
28+
Arrays.stream(bones).forEach(instanceBuffer::put);
3029
}
3130

3231

src/library/java/gg/generations/rarecandy/renderer/storage/SSBOBuffer.java

Lines changed: 61 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
package gg.generations.rarecandy.renderer.storage;
22

3-
import gg.generations.rarecandy.renderer.pipeline.util.SSBOBinding;
4-
import org.joml.Matrix4f;
5-
import org.joml.Vector2f;
3+
import org.joml.*;
64
import org.lwjgl.system.MemoryUtil;
75

8-
import java.nio.ByteBuffer;
96
import static org.lwjgl.opengl.GL43.*;
10-
import static org.lwjgl.opengl.GL15.*;
117

128
/**
139
* Manages a single SSBO with dynamic size control
@@ -16,10 +12,12 @@ public class SSBOBuffer {
1612
private int bufferId;
1713
private long currentCapacity; // in bytes
1814
private long pointer; // native memory buffer
15+
private long pos;
1916

2017
public SSBOBuffer() {
2118
this.bufferId = glGenBuffers();
2219
this.currentCapacity = 0;
20+
this.pos = 0;
2321
}
2422

2523
public SSBOBuffer(int capacity) {
@@ -32,6 +30,7 @@ public void ensureCapacity(long newCapacity) {
3230
if (pointer == 0 || currentCapacity < newCapacity) {
3331
if(pointer > 0) MemoryUtil.nmemFree(pointer);
3432
pointer = MemoryUtil.nmemAlloc((int) newCapacity);
33+
pos = pointer;
3534
}
3635

3736
// Resize GPU buffer if needed
@@ -59,21 +58,72 @@ public void delete() {
5958
MemoryUtil.nmemFree(pointer);
6059
pointer = 0;
6160
}
61+
62+
this.pos = 0;
63+
}
64+
65+
public SSBOBuffer put(Matrix2f transformationMatrix) {
66+
transformationMatrix.getToAddress(pos);
67+
pos += 16;
68+
return this;
69+
}
70+
71+
public SSBOBuffer put(Matrix3f transformationMatrix) {
72+
transformationMatrix.getToAddress(pos);
73+
pos += 36;
74+
return this;
75+
}
76+
public SSBOBuffer put(Matrix4f transformationMatrix) {
77+
transformationMatrix.getToAddress(pos);
78+
pos += 64;
79+
return this;
80+
}
81+
82+
public SSBOBuffer put(int value) {
83+
MemoryUtil.memPutInt(pos, value);
84+
pos += 4;
85+
return this;
6286
}
6387

64-
public void put(int pos, Matrix4f transformationMatrix) {
65-
transformationMatrix.getToAddress(pointer + pos);
88+
public void put(boolean value) {
89+
put(value ? 1 : 0);
6690
}
6791

68-
public void put(int pos, float value) {
69-
MemoryUtil.memPutFloat(pointer + pos, value);
92+
public SSBOBuffer put(short value) {
93+
MemoryUtil.memPutShort(pos, value);
94+
pos += 2;
95+
return this;
7096
}
7197

72-
public void put(int pos, Vector2f vec2) {
73-
vec2.getToAddress(pointer + pos);
98+
public SSBOBuffer put(float value) {
99+
MemoryUtil.memPutFloat(pos, value);
100+
pos += 4;
101+
return this;
102+
}
103+
104+
public SSBOBuffer put(Vector2f vec2) {
105+
vec2.getToAddress(pos);
106+
pos += 8;
107+
return this;
108+
}
109+
110+
public SSBOBuffer put(Vector3f vec3) {
111+
vec3.getToAddress(pos);
112+
pos += 12;
113+
return this;
114+
}
115+
116+
public SSBOBuffer put(Vector4f vec4) {
117+
vec4.getToAddress(pos);
118+
pos += 16;
119+
return this;
74120
}
75121

76122
public int getBufferId() {
77123
return bufferId;
78124
}
125+
126+
public void reset() {
127+
this.pos = pointer;
128+
}
79129
}

src/main/java/gg/generations/rarecandy/tools/gui/GuiPipelines.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,9 @@ public static void onInitialize(RareCandyCanvas canvas, PokeUtilsGui.Settings se
7171
.addSSBORange(Scope.MODEL, "SrcBuffer", 0, ctx -> ctx.object().modelBuffer, ctx -> ctx.object().vertex)
7272
.addSSBORange(Scope.MODEL, "IndexBuffer", 1, ctx -> ctx.object().modelBuffer, ctx -> ctx.object().index)
7373
.addSSBORange(Scope.MODEL, "DrawCommands", 2, ctx -> ctx.object().modelBuffer, ctx -> ctx.object().draw)
74-
.addSSBO(Scope.MODEL, "InstanceBuffer", 3, ctx -> {
75-
var id = ctx.object().instanceBuffer.getBufferId();
76-
return id;
77-
})
74+
.addSSBO(Scope.MODEL, "InstanceBuffer", 3, ctx -> ctx.object().instanceBuffer.getBufferId())
7875
.addSSBO(Scope.MODEL, "TransformBuffer", 4, ctx -> ctx.object().uvTransformBuffer.getBufferId())
79-
.addSSBO(Scope.MODEL, "DstBuffer", 5, ctx -> {
80-
return ctx.object().destBuffer;
81-
})
76+
.addSSBO(Scope.MODEL, "DstBuffer", 5, ctx -> ctx.object().destBuffer)
8277
.addUniform(Scope.MODEL, "variantSize", (uniform, ctx) -> uniform.uploadInt(ctx.object().meshes.length))
8378
.addUniform(Scope.GLOBAL, "instanceId", (uniform, ctx) -> uniform.uploadInt(instanceId))
8479
.build();

src/main/java/gg/generations/rarecandy/tools/gui/RareCandyCanvas.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import java.util.List;
2626
import java.util.function.Consumer;
2727

28+
import static gg.generations.rarecandy.renderer.loading.ModelLoader.createObject;
2829
import static org.lwjgl.opengl.GL42C.GL_SHADER_IMAGE_ACCESS_BARRIER_BIT;
2930

3031

@@ -33,8 +34,6 @@ public class RareCandyCanvas {
3334
public static Matrix4f projectionMatrix;
3435
public static float radius = 2.0f;
3536

36-
private final ModelLoader loader = new ModelLoader();
37-
3837
public static float lightLevel = 1;
3938
private static double time;
4039
public static FrameBuffer framebuffer;
@@ -280,7 +279,7 @@ public AnimationInstance createInstance(Animation animation) {
280279
}
281280

282281
protected void loadPokemonModel(PixelAsset is, Consumer<MultiRenderObject> onFinish) {
283-
loader.createObject(
282+
createObject(
284283
ToggleableMultiRenderObject::new,
285284
() -> is, MaterialReference::process, onFinish);
286285
}

0 commit comments

Comments
 (0)