Skip to content

Commit

Permalink
Begin particle registry impl
Browse files Browse the repository at this point in the history
  • Loading branch information
wahfl2 committed Sep 27, 2023
1 parent fe37166 commit ed09a66
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,16 @@ public void push(MemoryStack ignoredStack, long src, int size) {
byteOffset += size;
}

public Built build() {
return new Built(this.byteOffset, MemoryUtil.memSlice(this.buffer, 0, this.byteOffset));
}

public void reset() {
this.byteOffset = 0;
}

/**
* Resets this builder.
* Builds and resets this builder.
* Make sure to use/upload the return value before pushing more data.
* @return a ByteBuffer containing all the data pushed to this builder
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ public GlBufferTexture() {
this.glBufferHandle = GlStateManager._glGenBuffers();
}

public void uploadData(ByteBuffer data, int size) {
public void putData(ByteBuffer data, int offset, int size) {
int neededSize = offset + size;
GL31.glBindBuffer(GL31.GL_TEXTURE_BUFFER, this.glBufferHandle);
if (size > this.bufferSize) {

if (neededSize > this.bufferSize) {
RenderSystem.glBufferData(GL31.GL_TEXTURE_BUFFER, data, GlConst.GL_DYNAMIC_DRAW);
this.bufferSize = size;
this.bufferSize = neededSize;
} else {
GL15.glBufferSubData(GL31.GL_TEXTURE_BUFFER, 0, data);
GL15.glBufferSubData(GL31.GL_TEXTURE_BUFFER, offset, data);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package me.jellysquid.mods.sodium.client.render.texture;

import it.unimi.dsi.fastutil.longs.Long2IntOpenHashMap;

public class ParticleTextureRegistry {
private final Long2IntOpenHashMap uvToIndex = new Long2IntOpenHashMap();

public int get(float u, float v) {
long key = ((long) Float.floatToRawIntBits(u)) << 32 | ((long) Float.floatToRawIntBits(v));
return uvToIndex.get(key);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ public abstract class ParticleManagerMixin {
@Unique
private UnmanagedBufferBuilder particleBuffer;

@Unique
private UnmanagedBufferBuilder particleTextureBuffer;

@Unique
private GlBufferTexture bufferTexture;

Expand All @@ -98,6 +101,7 @@ public abstract class ParticleManagerMixin {
private void postInit(ClientWorld world, TextureManager textureManager, CallbackInfo ci) {
this.glVertexArray = GlStateManager._glGenVertexArrays();
this.particleBuffer = new UnmanagedBufferBuilder(1);
this.particleTextureBuffer = new UnmanagedBufferBuilder(1);
this.bufferTexture = new GlBufferTexture();
this.renderView = new ParticleRenderView(world);
}
Expand Down Expand Up @@ -265,7 +269,7 @@ private void bindDummyVao() {
@Unique
private void uploadParticleBuffer() {
UnmanagedBufferBuilder.Built particleData = this.particleBuffer.end();
this.bufferTexture.uploadData(particleData.buffer, particleData.size);
this.bufferTexture.putData(particleData.buffer, 0, particleData.size);
}

@Inject(method = "setWorld", at = @At("RETURN"))
Expand Down

0 comments on commit ed09a66

Please sign in to comment.