An OpenGL Vertex Buffer backed by a ByteBuffer. Useful for VertexArrays and ElementArrays
| 18 | * An OpenGL Vertex Buffer backed by a ByteBuffer. Useful for VertexArrays and ElementArrays |
| 19 | */ |
| 20 | public class SimpleArrayBuffer implements ArrayBuffer { |
| 21 | |
| 22 | static public int uploadBytes = 0; |
| 23 | final int divisor; |
| 24 | private FloatBuffer dataAsFloat; |
| 25 | private IntBuffer dataAsInt; |
| 26 | private final int size; |
| 27 | private final int binding; |
| 28 | private final int attribute; |
| 29 | private final int dimension; |
| 30 | ByteBuffer data; |
| 31 | int mod = 0; |
| 32 | private FloatBuffer customStorage = null; |
| 33 | public SimpleArrayBuffer(int size, int binding, int attribute, int dimension, int divisor) { |
| 34 | this.size = size; |
| 35 | this.binding = binding; |
| 36 | this.attribute = attribute; |
| 37 | this.dimension = dimension; |
| 38 | this.divisor = divisor; |
| 39 | |
| 40 | data = ByteBuffer.allocateDirect(4 * size * dimension) |
| 41 | .order(ByteOrder.nativeOrder()); |
| 42 | dataAsFloat = data.asFloatBuffer(); |
| 43 | dataAsInt = data.asIntBuffer(); |
| 44 | } |
| 45 | |
| 46 | static public ArrayBuffer newArrayBuffer(int maxVertex, int binding, int attribute, int dimension, int divisor) { |
| 47 | return new SimpleArrayBuffer(maxVertex, binding, attribute, dimension, divisor); |
| 48 | } |
| 49 | |
| 50 | public FloatBuffer getCustomStorage() { |
| 51 | return customStorage; |
| 52 | } |
| 53 | |
| 54 | public void setCustomStorage(FloatBuffer customStorage) throws NoSuchFieldException, IllegalAccessException { |
| 55 | this.customStorage = customStorage; |
| 56 | data = BufferUtils.asByteBuffer(customStorage); |
| 57 | dataAsFloat = customStorage; |
| 58 | dataAsInt = data.asIntBuffer(); |
| 59 | mod++; |
| 60 | } |
| 61 | |
| 62 | @Override |
| 63 | public boolean clean(int limit) { |
| 64 | State state = GraphicsContext.get(this); |
| 65 | final State finalState = state; |
| 66 | Log.log("graphics.trace", ()-> " clean " + finalState); |
| 67 | if (state == null) GraphicsContext.put(this, state = setup()); |
| 68 | if (state.mod != mod || state.limit < limit) { |
| 69 | upload(state, limit); |
| 70 | state.mod = mod; |
| 71 | return true; |
| 72 | } |
| 73 | return false; |
| 74 | } |
| 75 | |
| 76 | @Override |
| 77 | public int getSize() { |
nothing calls this directly
no outgoing calls
no test coverage detected