11package com.lambda.graphics.buffer
22
3+ import net.minecraft.client.texture.NativeImage
34import org.lwjgl.opengl.GL45C.*
45import java.nio.ByteBuffer
56
6- // NOT TESTED
77class PixelBuffer (
8- width : Int ,
9- height : Int ,
10- buffers : Int = 2
8+ private val width : Int ,
9+ private val height : Int ,
10+ private val buffers : Int = 2
1111) {
1212 private val pboIds = IntArray (buffers) { 0 }
1313 private var index = 0
1414
15+ fun mapTexture (id : Int , buffer : ByteBuffer ) {
16+ upload(buffer) {
17+ // Bind the texture
18+ glBindTexture(GL_TEXTURE_2D , id)
19+
20+ if (buffers > 0 )
21+ // Copy the data from the PBO to the texture
22+ glTexSubImage2D(GL_TEXTURE_2D , 0 , 0 , 0 , width, height, GL_RGBA , GL_UNSIGNED_BYTE , 0 )
23+ else
24+ // Copy the data from the buffer to the texture
25+ glTexImage2D(GL_TEXTURE_2D , 0 , GL_RGBA , width, height, 0 , GL_RGBA , GL_UNSIGNED_BYTE , NativeImage .read(buffer).pointer)
26+ }
27+ }
28+
1529 fun upload (data : ByteBuffer , block : () -> Unit ) {
1630 // Bind the current PBO for writing
1731 glBindBuffer(GL_PIXEL_UNPACK_BUFFER , pboIds[index])
@@ -28,7 +42,7 @@ class PixelBuffer(
2842 glBindBuffer(GL_PIXEL_UNPACK_BUFFER , 0 )
2943
3044 // Switch to the other PBO
31- index = (index + 1 ) % pboIds.size
45+ if (buffers > 0 ) index = (index + 1 ) % buffers
3246 }
3347
3448 fun download (): ByteBuffer {
0 commit comments