|
2 | 2 |
|
3 | 3 | import com.jme3.math.ColorRGBA; |
4 | 4 | import com.jme3.texture.Texture; |
| 5 | +import com.jme3.util.struct.Struct; |
5 | 6 | import com.jme3.util.struct.StructLayout; |
6 | 7 | import com.jme3.util.struct.StructMapping; |
7 | | -import com.jme3.vulkan.descriptors.CachedDescriptorSet; |
8 | | -import com.jme3.vulkan.descriptors.DescriptorPool; |
9 | | -import com.jme3.vulkan.descriptors.DescriptorSetLayout; |
| 8 | +import com.jme3.vulkan.JmePlatform; |
| 9 | +import com.jme3.vulkan.buffers.BufferUsage; |
| 10 | +import com.jme3.vulkan.buffers.MappableBuffer; |
| 11 | +import com.jme3.vulkan.buffers.saving.UpdateHint; |
10 | 12 | import com.jme3.vulkan.material.structs.UnshadedParams; |
11 | | -import com.jme3.vulkan.pipeline.PipelineLayout; |
| 13 | +import com.jme3.vulkan.util.Flag; |
12 | 14 |
|
| 15 | +import java.util.HashMap; |
13 | 16 | import java.util.IdentityHashMap; |
14 | 17 | import java.util.Map; |
15 | 18 |
|
16 | | -public class Unlit implements ShaderInterface { |
| 19 | +public class Unlit { |
17 | 20 |
|
18 | | - private final Map<DescriptorSetLayout, CachedDescriptorSet> sets = new IdentityHashMap<>(); |
19 | | - private final UnshadedParams params = new UnshadedParams(); |
| 21 | + private final Map<String, Object> parameters = new HashMap<>(); |
| 22 | + private final Map<MappableBuffer, StructMapping> mappings = new IdentityHashMap<>(); |
| 23 | + private final MappableBuffer visualBuffer = JmePlatform.allocateStandardBuffer(1, BufferUsage.Uniform, UpdateHint.Dynamic); |
| 24 | + private final UnshadedParams visuals = new UnshadedParams(); |
20 | 25 |
|
21 | 26 | { |
22 | | - params.bind(StructLayout.std140); |
| 27 | + visuals.bind(StructLayout.std140); |
| 28 | + visualBuffer.resize(visuals.getSize()); |
23 | 29 | } |
24 | 30 |
|
25 | | - public void update(PipelineLayout pipeline, DescriptorPool pool, ParameterPool parameters) { |
26 | | - pipeline.allocate(pool, sets); |
27 | | - pipeline.write(sets, "ColorMap", parameters.get("ColorMap")); |
28 | | - try (StructMapping<UnshadedParams> m = parameters.mapBuffer("Params", params)) { |
29 | | - params.color.compareAndSet(parameters.get("Color")); |
| 31 | + protected <T extends Struct> T map(MappableBuffer buffer, T struct) { |
| 32 | + StructMapping<T> map = mappings.get(buffer); |
| 33 | + if (map == null) { |
| 34 | + mappings.put(buffer, map = buffer.mapStruct(struct)); |
30 | 35 | } |
| 36 | + return map.get(); |
31 | 37 | } |
32 | 38 |
|
33 | | - @Override |
34 | | - public void close() { |
35 | | - |
36 | | - } |
37 | | - |
38 | | - protected UnshadedParams getUnshaded() { |
39 | | - return getStruct("Unshaded", UnshadedParams::new, StructLayout.std140); |
40 | | - } |
41 | | - |
42 | | - public void setBaseColor(ColorRGBA color) { |
43 | | - getUnshaded().color.set(color); |
| 39 | + public void flush() { |
| 40 | + for (StructMapping m : mappings.values()) { |
| 41 | + m.close(); |
| 42 | + } |
| 43 | + mappings.clear(); |
44 | 44 | } |
45 | 45 |
|
46 | | - public void setVertexColor(boolean vertexColor) { |
47 | | - getUnshaded().vertexColor.set(true); |
| 46 | + public void setColor(ColorRGBA color) { |
| 47 | + map(visualBuffer, visuals).color.set(color); |
48 | 48 | } |
49 | 49 |
|
50 | 50 | public void setColorMap(Texture texture) { |
51 | 51 | parameters.put("ColorMap", texture); |
52 | 52 | } |
53 | 53 |
|
54 | | - public ColorRGBA getBaseColor() { |
55 | | - return getUnshaded().color.get(); |
56 | | - } |
57 | | - |
58 | | - public boolean isVertexColor() { |
59 | | - return getUnshaded().vertexColor.get(); |
60 | | - } |
61 | | - |
62 | | - public Texture getColorMap() { |
63 | | - return (Texture)parameters.get("ColorMap"); |
64 | | - } |
65 | | - |
66 | 54 | } |
0 commit comments