sgsrules
Full Member
Offline
Posts: 108
Texas
Using PBO's (pixel buffer objects) in processing
Oct 21st , 2008, 1:15am
I've been trying to speed up my texture transfers using pbo's but haven't been successful yet. I can get the texture to display but they come out garbled. here's a code snippet: PImage texImage = loadImage(filename); int tex = new int[1]; int pbo = new int[1]; gl.glGenTextures(1, tex, 0); gl.glBindTexture(GL.GL_TEXTURE_2D, tex[0]); gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_GENERATE_MIPMAP, GL.GL_TRUE); gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER,GL.GL_LINEAR_MIPMAP_LINEAR); gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER,GL.GL_LINEAR); gl.glTexImage2D(GL.GL_TEXTURE_2D, 0, 4, texImage.width,texImage.height, 0, GL.GL_BGRA, GL.GL_UNSIGNED_BYTE, null); gl.glGenBuffers(1, pbo, 0); gl.glBindBuffer(GL.GL_PIXEL_UNPACK_BUFFER, pbo[0]); gl.glBufferData(GL.GL_PIXEL_UNPACK_BUFFER, texImage.height* texImage.width*BufferUtil.SIZEOF_FLOAT, IntBuffer.wrap(texImage.pixels),GL.GL_STATIC_DRAW); gl.glMapBuffer(GL.GL_PIXEL_UNPACK_BUFFER, GL.GL_WRITE_ONLY); gl.glUnmapBuffer(GL.GL_PIXEL_UNPACK_BUFFER); gl.glBindBuffer(GL.GL_PIXEL_UNPACK_BUFFER, 0); gl.glEnable(GL.GL_TEXTURE_2D); I suspect the culprit is in the gl.glBufferData call where i state: texImage.height* texImage.width*BufferUtil.SIZEOF_FLOAT. While i was messing around i was able to get the texture to display properly by using: texImage.height* texImage.width*7 but for some reason this only worked when i ran the sketch the first couple of times and now the texture is corrupted every time, weird. Any help would be greatly appreciated.