Skip to content

Commit ec2e9d8

Browse files
committed
check for buffer access flags
1 parent aa9c7ce commit ec2e9d8

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

common/src/main/kotlin/com/lambda/graphics/buffer/IBuffer.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ interface IBuffer {
134134
data: ByteBuffer,
135135
offset: Long,
136136
): Throwable? {
137-
if (!bufferValid(target))
137+
if (!bufferValid(target, access))
138138
return IllegalArgumentException("Target is not valid. Refer to the table in the documentation")
139139

140140
if (!bufferBound(target))
@@ -152,7 +152,7 @@ interface IBuffer {
152152
* @param data The data to put in the new allocated buffer
153153
*/
154154
fun allocate(data: ByteBuffer): Throwable? {
155-
if (!bufferValid(target))
155+
if (!bufferValid(target, access))
156156
return IllegalArgumentException("Target is not valid. Refer to the table in the documentation")
157157

158158
if (!bufferUsageValid(usage))
@@ -172,7 +172,7 @@ interface IBuffer {
172172
* @param size The size of the new buffer
173173
*/
174174
fun allocate(size: Long): Throwable? {
175-
if (!bufferValid(target))
175+
if (!bufferValid(target, access))
176176
return IllegalArgumentException("Target is not valid. Refer to the table in the documentation")
177177

178178
if (!bufferUsageValid(usage))
@@ -191,7 +191,7 @@ interface IBuffer {
191191
* This function handles the buffer binding
192192
*/
193193
fun storage(data: ByteBuffer): Throwable? {
194-
if (!bufferValid(target))
194+
if (!bufferValid(target, access))
195195
return IllegalArgumentException("Target is not valid. Refer to the table in the documentation")
196196

197197
if (!bufferUsageValid(usage))
@@ -212,7 +212,7 @@ interface IBuffer {
212212
* @param size The size of the storage buffer
213213
*/
214214
fun storage(size: Long): Throwable? {
215-
if (!bufferValid(target))
215+
if (!bufferValid(target, access))
216216
return IllegalArgumentException("Target is not valid. Refer to the table in the documentation")
217217

218218
if (!bufferUsageValid(usage))
@@ -243,7 +243,7 @@ interface IBuffer {
243243
size < 0
244244
) return IllegalArgumentException("Invalid offset or size parameter offset: $offset size: $size")
245245

246-
if (!bufferValid(target))
246+
if (!bufferValid(target, access))
247247
return IllegalArgumentException("Target is not valid. Refer to the table in the documentation")
248248

249249
if (!bufferBound(target))

common/src/main/kotlin/com/lambda/graphics/gl/Buffers.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,12 @@ val bindingCheckMappings = mapOf(
4343
/**
4444
* Returns whether the buffer target is valid
4545
*/
46-
fun bufferValid(target: Int): Boolean = target in bindingCheckMappings
46+
fun bufferValid(target: Int, access: Int): Boolean =
47+
target in bindingCheckMappings &&
48+
// If access contains GL_MAP_COHERENT_BIT, it must also contain GL_MAP_PERSISTENT_BIT.
49+
(access and GL_MAP_COHERENT_BIT == 0 || access and GL_MAP_PERSISTENT_BIT != 0) &&
50+
// If access contains GL_MAP_PERSISTENT_BIT, it must also contain at least one of GL_MAP_READ_BIT or GL_MAP_WRITE_BIT.
51+
(access and GL_MAP_PERSISTENT_BIT == 0 || (access and (GL_MAP_READ_BIT or GL_MAP_WRITE_BIT) != 0))
4752

4853
/**
4954
* Returns whether the provided buffer target is bound

0 commit comments

Comments
 (0)