mirror of
https://github.com/Jozufozu/Flywheel.git
synced 2024-12-29 08:26:37 +01:00
fixup! Initial data/struct format refactor
This commit is contained in:
parent
613c933206
commit
ee7f6fd5e2
5 changed files with 33 additions and 8 deletions
|
@ -3,11 +3,26 @@ package com.jozufozu.flywheel.backend.struct;
|
||||||
import com.jozufozu.flywheel.backend.gl.attrib.VertexFormat;
|
import com.jozufozu.flywheel.backend.gl.attrib.VertexFormat;
|
||||||
import com.jozufozu.flywheel.backend.gl.buffer.VecBuffer;
|
import com.jozufozu.flywheel.backend.gl.buffer.VecBuffer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A StructType contains metadata for a specific instance struct that Flywheel can interface with.
|
||||||
|
* @param <S> The java representation of the instance struct.
|
||||||
|
*/
|
||||||
public interface StructType<S> {
|
public interface StructType<S> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return A new, zeroed instance of the struct.
|
||||||
|
*/
|
||||||
S create();
|
S create();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return The format descriptor of the struct type.
|
||||||
|
*/
|
||||||
VertexFormat format();
|
VertexFormat format();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a {@link StructWriter} that will consume instances of S and write them to the given buffer.
|
||||||
|
*
|
||||||
|
* @param backing The buffer that the StructWriter will write to.
|
||||||
|
*/
|
||||||
StructWriter<S> getWriter(VecBuffer backing);
|
StructWriter<S> getWriter(VecBuffer backing);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,17 @@
|
||||||
package com.jozufozu.flywheel.backend.struct;
|
package com.jozufozu.flywheel.backend.struct;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* StructWriters can quickly consume many instances of S and write them to some backing buffer.
|
||||||
|
*/
|
||||||
public interface StructWriter<S> {
|
public interface StructWriter<S> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Write the given struct to the backing array.
|
||||||
|
*/
|
||||||
void write(S struct);
|
void write(S struct);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Seek to the given position. The next write will occur there.
|
||||||
|
*/
|
||||||
void seek(int pos);
|
void seek(int pos);
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,19 +5,21 @@ import org.lwjgl.system.MemoryUtil;
|
||||||
import com.jozufozu.flywheel.backend.gl.buffer.VecBuffer;
|
import com.jozufozu.flywheel.backend.gl.buffer.VecBuffer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* This class copied/adapted from jellysquid's
|
||||||
|
*
|
||||||
* An unsafe {@link BufferWriter} implementation which uses direct memory operations to enable fast blitting of
|
* An unsafe {@link BufferWriter} implementation which uses direct memory operations to enable fast blitting of
|
||||||
* data into memory buffers. Only available on JVMs which support {@link sun.misc.Unsafe}, but generally produces much
|
* data into memory buffers. Only available on JVMs which support {@link sun.misc.Unsafe}, but generally produces much
|
||||||
* better optimized code than other implementations. The implementation does not check for invalid memory accesses,
|
* better optimized code than other implementations. The implementation does not check for invalid memory accesses,
|
||||||
* meaning that errors can corrupt process memory.
|
* meaning that errors can corrupt process memory.
|
||||||
*/
|
*/
|
||||||
public abstract class BufferWriterUnsafe<S> extends BufferWriter<S> {
|
public abstract class UnsafeBufferWriter<S> extends BufferWriter<S> {
|
||||||
/**
|
/**
|
||||||
* The write pointer into the buffer storage. This is advanced by the vertex stride every time
|
* The write pointer into the buffer storage. This is advanced by the vertex stride every time
|
||||||
* {@link BufferWriterUnsafe#advance()} is called.
|
* {@link UnsafeBufferWriter#advance()} is called.
|
||||||
*/
|
*/
|
||||||
protected long writePointer;
|
protected long writePointer;
|
||||||
|
|
||||||
protected BufferWriterUnsafe(VecBuffer backingBuffer, StructType<S> vertexType) {
|
protected UnsafeBufferWriter(VecBuffer backingBuffer, StructType<S> vertexType) {
|
||||||
super(backingBuffer, vertexType);
|
super(backingBuffer, vertexType);
|
||||||
|
|
||||||
acquireWritePointer();
|
acquireWritePointer();
|
|
@ -3,12 +3,11 @@ package com.jozufozu.flywheel.core.materials.model.writer;
|
||||||
import org.lwjgl.system.MemoryUtil;
|
import org.lwjgl.system.MemoryUtil;
|
||||||
|
|
||||||
import com.jozufozu.flywheel.backend.gl.buffer.VecBuffer;
|
import com.jozufozu.flywheel.backend.gl.buffer.VecBuffer;
|
||||||
import com.jozufozu.flywheel.backend.struct.BufferWriterUnsafe;
|
import com.jozufozu.flywheel.backend.struct.UnsafeBufferWriter;
|
||||||
import com.jozufozu.flywheel.backend.struct.StructType;
|
import com.jozufozu.flywheel.backend.struct.StructType;
|
||||||
import com.jozufozu.flywheel.backend.struct.BufferWriter;
|
|
||||||
import com.jozufozu.flywheel.core.materials.model.ModelData;
|
import com.jozufozu.flywheel.core.materials.model.ModelData;
|
||||||
|
|
||||||
public class UnsafeModelWriter extends BufferWriterUnsafe<ModelData> {
|
public class UnsafeModelWriter extends UnsafeBufferWriter<ModelData> {
|
||||||
|
|
||||||
public UnsafeModelWriter(VecBuffer backingBuffer, StructType<ModelData> vertexType) {
|
public UnsafeModelWriter(VecBuffer backingBuffer, StructType<ModelData> vertexType) {
|
||||||
super(backingBuffer, vertexType);
|
super(backingBuffer, vertexType);
|
||||||
|
|
|
@ -3,11 +3,11 @@ package com.jozufozu.flywheel.core.materials.oriented.writer;
|
||||||
import org.lwjgl.system.MemoryUtil;
|
import org.lwjgl.system.MemoryUtil;
|
||||||
|
|
||||||
import com.jozufozu.flywheel.backend.gl.buffer.VecBuffer;
|
import com.jozufozu.flywheel.backend.gl.buffer.VecBuffer;
|
||||||
import com.jozufozu.flywheel.backend.struct.BufferWriterUnsafe;
|
import com.jozufozu.flywheel.backend.struct.UnsafeBufferWriter;
|
||||||
import com.jozufozu.flywheel.backend.struct.StructType;
|
import com.jozufozu.flywheel.backend.struct.StructType;
|
||||||
import com.jozufozu.flywheel.core.materials.oriented.OrientedData;
|
import com.jozufozu.flywheel.core.materials.oriented.OrientedData;
|
||||||
|
|
||||||
public class UnsafeOrientedWriter extends BufferWriterUnsafe<OrientedData> {
|
public class UnsafeOrientedWriter extends UnsafeBufferWriter<OrientedData> {
|
||||||
public UnsafeOrientedWriter(VecBuffer backingBuffer, StructType<OrientedData> vertexType) {
|
public UnsafeOrientedWriter(VecBuffer backingBuffer, StructType<OrientedData> vertexType) {
|
||||||
super(backingBuffer, vertexType);
|
super(backingBuffer, vertexType);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue