forked from CaffeineMC/sodium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This prevents a lot of invalid usages and makes it easier for sodium-gfx to optimize for things.
- Loading branch information
1 parent
e565ddc
commit 6e42d38
Showing
31 changed files
with
334 additions
and
447 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 4 additions & 5 deletions
9
...affeinemc/gfx/opengl/buffer/GlBuffer.java → ...c/gfx/opengl/buffer/GlAbstractBuffer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 0 additions & 27 deletions
27
components/gfx-opengl/src/main/java/net/caffeinemc/gfx/opengl/buffer/GlAllocatedBuffer.java
This file was deleted.
Oops, something went wrong.
21 changes: 21 additions & 0 deletions
21
components/gfx-opengl/src/main/java/net/caffeinemc/gfx/opengl/buffer/GlDynamicBuffer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package net.caffeinemc.gfx.opengl.buffer; | ||
|
||
import net.caffeinemc.gfx.api.buffer.DynamicBuffer; | ||
import net.caffeinemc.gfx.api.buffer.DynamicBufferFlags; | ||
|
||
import java.util.Collections; | ||
import java.util.Set; | ||
|
||
public class GlDynamicBuffer extends GlAbstractBuffer implements DynamicBuffer { | ||
private final Set<DynamicBufferFlags> flags; | ||
|
||
public GlDynamicBuffer(int handle, long capacity, Set<DynamicBufferFlags> flags) { | ||
super(handle, capacity); | ||
this.flags = Collections.unmodifiableSet(flags); | ||
} | ||
|
||
@Override | ||
public Set<DynamicBufferFlags> flags() { | ||
return this.flags; | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
components/gfx-opengl/src/main/java/net/caffeinemc/gfx/opengl/buffer/GlImmutableBuffer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package net.caffeinemc.gfx.opengl.buffer; | ||
|
||
import net.caffeinemc.gfx.api.buffer.ImmutableBuffer; | ||
import net.caffeinemc.gfx.api.buffer.ImmutableBufferFlags; | ||
|
||
import java.util.Collections; | ||
import java.util.Set; | ||
|
||
public class GlImmutableBuffer extends GlAbstractBuffer implements ImmutableBuffer { | ||
private final Set<ImmutableBufferFlags> flags; | ||
|
||
public GlImmutableBuffer(int handle, long capacity, Set<ImmutableBufferFlags> flags) { | ||
super(handle, capacity); | ||
this.flags = Collections.unmodifiableSet(flags); | ||
} | ||
|
||
@Override | ||
public Set<ImmutableBufferFlags> flags() { | ||
return this.flags; | ||
} | ||
} |
36 changes: 24 additions & 12 deletions
36
components/gfx-opengl/src/main/java/net/caffeinemc/gfx/opengl/buffer/GlMappedBuffer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,45 @@ | ||
package net.caffeinemc.gfx.opengl.buffer; | ||
|
||
import net.caffeinemc.gfx.api.buffer.BufferMapFlags; | ||
import net.caffeinemc.gfx.api.buffer.MappedBufferFlags; | ||
import net.caffeinemc.gfx.api.buffer.MappedBuffer; | ||
import net.caffeinemc.gfx.api.device.RenderConfiguration; | ||
import org.apache.commons.lang3.Validate; | ||
import org.lwjgl.opengl.GL45C; | ||
|
||
import java.nio.ByteBuffer; | ||
import java.util.Collections; | ||
import java.util.Set; | ||
|
||
public class GlMappedBuffer extends GlBuffer implements MappedBuffer { | ||
private final ByteBuffer data; | ||
private final Set<BufferMapFlags> flags; | ||
public class GlMappedBuffer extends GlAbstractBuffer implements MappedBuffer { | ||
private final ByteBuffer view; | ||
private final Set<MappedBufferFlags> flags; | ||
|
||
public GlMappedBuffer(long capacity, int handle, ByteBuffer data, Set<BufferMapFlags> flags) { | ||
super(capacity, handle); | ||
public GlMappedBuffer(int handle, ByteBuffer view, Set<MappedBufferFlags> flags) { | ||
super(handle, view.capacity()); | ||
|
||
this.data = !flags.contains(BufferMapFlags.WRITE) ? data.asReadOnlyBuffer() : data; | ||
this.flags = flags; | ||
this.view = view; | ||
this.flags = Collections.unmodifiableSet(flags); | ||
} | ||
|
||
@Override | ||
public void flush(long pos, long length) { | ||
if (this.flags.contains(BufferMapFlags.EXPLICIT_FLUSH)) { | ||
GL45C.glFlushMappedNamedBufferRange(this.handle(), pos, length); | ||
public void flush(long offset, long length) { | ||
if (RenderConfiguration.API_CHECKS) { | ||
Validate.isTrue(this.flags.contains(MappedBufferFlags.EXPLICIT_FLUSH), "Buffer is not mapped for explicit flushing"); | ||
|
||
Validate.isTrue(offset >= 0, "The offset must be greater than or equal to zero"); | ||
Validate.isTrue(offset + length <= this.capacity(), "Range is outside of buffer bounds"); | ||
} | ||
|
||
GL45C.glFlushMappedNamedBufferRange(this.handle(), offset, length); | ||
} | ||
|
||
@Override | ||
public ByteBuffer view() { | ||
return this.data; | ||
return this.view; | ||
} | ||
|
||
@Override | ||
public Set<MappedBufferFlags> flags() { | ||
return this.flags; | ||
} | ||
} |
Oops, something went wrong.