|
| 1 | +package com.jme3.vulkan; |
| 2 | + |
| 3 | +import com.jme3.util.natives.Native; |
| 4 | +import com.jme3.util.natives.NativeReference; |
| 5 | +import org.lwjgl.system.MemoryStack; |
| 6 | +import org.lwjgl.vulkan.VkVertexInputAttributeDescription; |
| 7 | +import org.lwjgl.vulkan.VkVertexInputBindingDescription; |
| 8 | + |
| 9 | +import static org.lwjgl.vulkan.VK10.*; |
| 10 | + |
| 11 | +public class TestCaseMeshDescription implements Native<Object>, MeshDescription { |
| 12 | + |
| 13 | + private final VkVertexInputBindingDescription.Buffer bindings; |
| 14 | + private final VkVertexInputAttributeDescription.Buffer attributes; |
| 15 | + private final NativeReference ref; |
| 16 | + |
| 17 | + public TestCaseMeshDescription() { |
| 18 | + // for each vertex buffer on the mesh |
| 19 | + bindings = VkVertexInputBindingDescription.calloc(1) |
| 20 | + .binding(0) |
| 21 | + .stride(Float.BYTES * 8) // bytes per vertex |
| 22 | + .inputRate(VK_VERTEX_INPUT_RATE_VERTEX); |
| 23 | + // for each attribute in each vertex buffer |
| 24 | + attributes = VkVertexInputAttributeDescription.calloc(3); |
| 25 | + attributes.get(0).binding(0) |
| 26 | + .location(0) |
| 27 | + .format(VK_FORMAT_R32G32B32_SFLOAT) |
| 28 | + .offset(0); |
| 29 | + attributes.get(1).binding(0) |
| 30 | + .location(1) |
| 31 | + .format(VK_FORMAT_R32G32B32_SFLOAT) |
| 32 | + .offset(Float.BYTES * 3); |
| 33 | + attributes.get(2).binding(0) |
| 34 | + .location(2) |
| 35 | + .format(VK_FORMAT_R32G32_SFLOAT) |
| 36 | + .offset(Float.BYTES * 6); |
| 37 | + ref = Native.get().register(this); |
| 38 | + } |
| 39 | + |
| 40 | + @Override |
| 41 | + public Object getNativeObject() { |
| 42 | + return null; |
| 43 | + } |
| 44 | + |
| 45 | + @Override |
| 46 | + public Runnable createNativeDestroyer() { |
| 47 | + return () -> { |
| 48 | + bindings.free(); |
| 49 | + attributes.free(); |
| 50 | + }; |
| 51 | + } |
| 52 | + |
| 53 | + @Override |
| 54 | + public void prematureNativeDestruction() {} |
| 55 | + |
| 56 | + @Override |
| 57 | + public NativeReference getNativeReference() { |
| 58 | + return ref; |
| 59 | + } |
| 60 | + |
| 61 | + @Override |
| 62 | + public VkVertexInputBindingDescription.Buffer getBindings(MemoryStack stack) { |
| 63 | + return bindings; |
| 64 | + } |
| 65 | + |
| 66 | + @Override |
| 67 | + public VkVertexInputAttributeDescription.Buffer getAttributes(MemoryStack stack) { |
| 68 | + return attributes; |
| 69 | + } |
| 70 | + |
| 71 | +} |
0 commit comments