|
1 | 1 | package cn.ussshenzhou.madparticle.particle.render; |
2 | 2 |
|
| 3 | +import com.mojang.blaze3d.buffers.GpuBuffer; |
| 4 | +import com.mojang.blaze3d.opengl.GlBuffer; |
| 5 | +import com.mojang.blaze3d.systems.RenderSystem; |
3 | 6 | import org.lwjgl.system.MemoryUtil; |
4 | 7 |
|
5 | 8 | import java.nio.ByteBuffer; |
@@ -60,30 +63,25 @@ public void next() { |
60 | 63 | } |
61 | 64 |
|
62 | 65 | public static class PersistentMappedBuffer { |
63 | | - private ByteBuffer mappedBuffer; |
64 | | - private final int id; |
| 66 | + private final GpuBuffer gpuBuffer; |
| 67 | + private final GpuBuffer.MappedView mappedBuffer; |
65 | 68 |
|
66 | 69 | public PersistentMappedBuffer(int byteSize) { |
67 | | - this.id = glGenBuffers(); |
68 | | - glBindBuffer(GL_ARRAY_BUFFER, id); |
69 | | - int flag = GL_MAP_WRITE_BIT | GL_MAP_COHERENT_BIT | GL_MAP_PERSISTENT_BIT; |
70 | | - glBufferStorage(GL_ARRAY_BUFFER, byteSize, flag); |
71 | | - mappedBuffer = glMapBufferRange(GL_ARRAY_BUFFER, 0, byteSize, flag); |
72 | | - glBindBuffer(GL_ARRAY_BUFFER, 0); |
| 70 | + gpuBuffer = RenderSystem.getDevice().createBuffer(() -> "MadParticle VBO", GpuBuffer.USAGE_MAP_WRITE, byteSize); |
| 71 | + mappedBuffer = RenderSystem.getDevice().createCommandEncoder().mapBuffer(gpuBuffer, false, true); |
73 | 72 | } |
74 | 73 |
|
75 | 74 | public long getAddress() { |
76 | | - return MemoryUtil.memAddress(mappedBuffer); |
| 75 | + return MemoryUtil.memAddress(mappedBuffer.data()); |
77 | 76 | } |
78 | 77 |
|
79 | 78 | public void free() { |
80 | | - glUnmapNamedBuffer(id); |
81 | | - glDeleteBuffers(id); |
82 | | - mappedBuffer = null; |
| 79 | + mappedBuffer.close(); |
| 80 | + gpuBuffer.close(); |
83 | 81 | } |
84 | 82 |
|
85 | 83 | public void bind() { |
86 | | - glBindBuffer(GL_ARRAY_BUFFER, id); |
| 84 | + glBindBuffer(GL_ARRAY_BUFFER, ((GlBuffer) (gpuBuffer)).handle); |
87 | 85 | } |
88 | 86 |
|
89 | 87 | } |
|
0 commit comments