Skip to content

Commit c6328ca

Browse files
committed
pixel n-buffer object
1 parent ea972be commit c6328ca

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ import java.nio.ByteBuffer
66
// NOT TESTED
77
class PixelBuffer(
88
width: Int,
9-
height: Int
9+
height: Int,
10+
buffers: Int = 2
1011
) {
11-
private val pboIds = IntArray(2) { 0 }
12+
private val pboIds = IntArray(buffers) { 0 }
1213
private var index = 0
1314

1415
fun upload(data: ByteBuffer, block: () -> Unit) {
@@ -27,7 +28,7 @@ class PixelBuffer(
2728
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0)
2829

2930
// Switch to the other PBO
30-
index = (index + 1) % 2
31+
index = (index + 1) % pboIds.size
3132
}
3233

3334
fun download(): ByteBuffer {
@@ -55,10 +56,10 @@ class PixelBuffer(
5556
glGenBuffers(pboIds)
5657

5758
// Fill the buffers with null data to allocate the memory spaces
58-
glBindBuffer(GL_PIXEL_PACK_BUFFER, pboIds[0])
59-
glBufferData(GL_PIXEL_PACK_BUFFER, width * height * 4L, GL_DYNAMIC_READ)
60-
glBindBuffer(GL_PIXEL_PACK_BUFFER, pboIds[1])
61-
glBufferData(GL_PIXEL_PACK_BUFFER, width * height * 4L, GL_DYNAMIC_READ)
59+
repeat(buffers) {
60+
glBindBuffer(GL_PIXEL_PACK_BUFFER, pboIds[it])
61+
glBufferData(GL_PIXEL_PACK_BUFFER, width * height * 4L, GL_DYNAMIC_READ)
62+
}
6263

6364
// Unbind the buffer
6465
glBindBuffer(GL_PIXEL_PACK_BUFFER, 0)

0 commit comments

Comments
 (0)