forked from 117HD/RLHD
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBaseCommand.java
More file actions
67 lines (48 loc) · 2.23 KB
/
BaseCommand.java
File metadata and controls
67 lines (48 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package rs117.hd.opengl.commandbuffer;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.lwjgl.system.MemoryStack;
import rs117.hd.opengl.uniforms.UniformBuffer;
@Slf4j
public abstract class BaseCommand {
protected int id;
@Getter
private final String name;
@Getter
private final boolean isDrawCall;
@Getter
private final boolean isGLCommand;
protected CommandBuffer owner;
protected BaseCommand(boolean isDrawCall, boolean isGLCommand) {
this.name = getClass().getSimpleName();
this.isDrawCall = isDrawCall;
this.isGLCommand = isDrawCall || isGLCommand;
}
protected BaseCommand(boolean isDrawCall) { this(isDrawCall, false); }
protected BaseCommand() { this(false, false); }
protected abstract void execute(MemoryStack stack);
protected abstract void print(StringBuilder sb);
protected final void write() {
write8(id);
doWrite();
}
protected abstract void doWrite();
protected abstract void doRead(MemoryStack stack);
protected final void markUniformBufferDirty(UniformBuffer buffer) { owner.markUniformBufferDirty(buffer); }
protected final void write1(int value) { owner.writeBits(value & 0x1L, 1); }
protected final void write8(int value) { owner.writeBits(value & 0xFFL, 8); }
protected final void write16(int value) { owner.writeBits(value & 0xFFFFL, 16); }
protected final void write32(int value) { owner.writeBits(value & 0xFFFFFFFFL, 32); }
protected final void write64(long value) { owner.writeBits(value, 64); }
protected final int read1() { return (int) owner.readBits(1); }
protected final int read8() { return (int) owner.readBits(8); }
protected final int read16() { return (int) owner.readBits(16); }
protected final int read32() { return (int) owner.readBits(32); }
protected final long read64() { return owner.readBits(64); }
protected final void writeObject(Object value) {owner.writeObject(value);}
protected final <T> T readObject() { return owner.readObject(); }
protected final void write32F(float value) { write32(Float.floatToIntBits(value)); }
protected final float read32F() { return Float.intBitsToFloat(read32()); }
protected final void writeFlag(boolean value) { write1(value ? 1 : 0); }
protected final boolean readFlag() { return read1() != 0; }
}