Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions Source.ShaderAPI.Gl46/IndexBufferGl46.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public unsafe class IndexBufferGl46 : IDisposable

int ibo = -1;
int lastBufferSize = -1;
int LockedPosition;
public unsafe void RecomputeIBO() {
// Create the IBO if it doesn't exist
if (ibo == -1)
Expand Down Expand Up @@ -78,14 +79,16 @@ public unsafe void RecomputeIBO() {
glNamedBufferData((uint)ibo, BufferSize, null, GL_DYNAMIC_DRAW);
}
Locked = true;
return (short*)glMapNamedBufferRange((uint)ibo, position * 2, Math.Max(1, indexCount * 2), GL_MAP_WRITE_BIT | GL_MAP_UNSYNCHRONIZED_BIT);
LockedPosition = position;
return (short*)SysmemBuffer + position;
}

public void Unlock(int indexCount) {
if (!Locked)
return;

glUnmapNamedBuffer((uint)ibo);
if (indexCount > 0)
glNamedBufferSubData((uint)ibo, LockedPosition * 2, indexCount * 2, (short*)SysmemBuffer + LockedPosition);
Position += indexCount;
Locked = false;
}
Expand All @@ -98,14 +101,15 @@ public void Unlock(int indexCount) {

startIndex = firstIndex;
Locked = true;
return (short*)glMapNamedBufferRange((uint)ibo, firstIndex * 2, Math.Max(1, indexCount * 2), GL_MAP_WRITE_BIT);
return (short*)SysmemBuffer + firstIndex;
}

public void ModifyUnlock(int firstIndex, int indexCount) {
if (!Locked)
return;

glUnmapNamedBuffer((uint)ibo);
if (indexCount > 0)
glNamedBufferSubData((uint)ibo, firstIndex * 2, indexCount * 2, (short*)SysmemBuffer + firstIndex);
Locked = false;
}

Expand Down
Loading