Skip to content

Commit 61bd98f

Browse files
Fix bufferStorage
The current packed struct is wrong, it was implemented in the order which the flags are described in the OpenGL Spec. This is not how the bits are laid out in memory though, in fact if you were to write true to map_write with this implementation it would through a GL_INVALID_VALUE error since the function does not allow setting any bits besides the defined ones. This commit fixes the bitfield to have the correct order and padding aswell as providing their offsets as a comment and a small description of what each flag does.
1 parent c3b5731 commit 61bd98f

File tree

1 file changed

+30
-9
lines changed

1 file changed

+30
-9
lines changed

src/wrapper.zig

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5227,15 +5227,36 @@ pub fn Wrap(comptime bindings: anytype) type {
52275227
pub const QUERY_RESULT_NO_WAIT = bindings.QUERY_RESULT_NO_WAIT;
52285228
pub const MIRROR_CLAMP_TO_EDGE = bindings.MIRROR_CLAMP_TO_EDGE;
52295229

5230-
pub fn bufferStorage(target: BufferTarget, size: usize, data: ?[]const u8, flags: packed struct(Bitfield) {
5231-
dynamic_storage: bool = false,
5232-
map_read: bool = false,
5233-
map_write: bool = false,
5234-
map_persistent: bool = false,
5235-
map_coherent: bool = false,
5236-
client_storage: bool = false,
5237-
__unused: u26 = 0,
5238-
}) void {
5230+
pub fn bufferStorage(
5231+
target: BufferTarget,
5232+
size: usize,
5233+
data: ?[]const u8,
5234+
flags: packed struct(Bitfield) {
5235+
///Enables reading via buffer mapping; read mapping fails otherwise.
5236+
map_read: bool = false, //0x1
5237+
5238+
///Enables write mapping; write mapping fails otherwise.
5239+
map_write: bool = false, //0x2
5240+
5241+
/// DO NOT WRITE
5242+
pad1: u4 = 0,
5243+
5244+
///Permits buffer operations while mapped; otherwise, such operations fail.
5245+
map_persistent: bool = false, //0x40
5246+
5247+
///Makes persistent accesses coherent without barriers; barriers required otherwise.
5248+
map_coherent: bool = false, //0x80
5249+
5250+
///Permits glNamedBufferSubData updates; calls fail otherwise.
5251+
dynamic_storage: bool = false, //0x100
5252+
5253+
///Hints storage should use client memory.
5254+
client_storage: bool = false, //0x200
5255+
5256+
/// DO NOT WRITE
5257+
pad2: u22 = 0,
5258+
},
5259+
) void {
52395260
bindings.bufferStorage(
52405261
@intFromEnum(target),
52415262
@as(Sizeiptr, @bitCast(size)),

0 commit comments

Comments
 (0)