Hi,
I’m sure there is a simple answer to this question-- I hope someone out there has a few seconds to point me in the right direction or even supply me with some code or psuedocode.
What’s the best way to bind images to a texture in real time?
My application needs to read jpegs from a remote database every 60 seconds or so. Every time it binds an image to a texture (using glTexImage2D) the display loop pauses for about 5 seconds. The slowness is definitely from the binding and not from the image loading. I’ve tried to move the code into its own thread, but I get strange behavior where the polygon appears but no texture is actually bound to it, or the entire polygon turns white.
As long as the binding occurs in the background then I actually don’t care about the speed of the binding-- I just don’t want it to pause and mess up my display loop!!!
Here’s my actual bindTexture method :
public void bindTexture(PhotoData photodata)
{
gl.glBindTexture(gl.GL_TEXTURE_2D, photodata.textureID);
gl.glTexParameteri(gl.GL_TEXTURE_2D,gl.GL_TEXTURE_MAG_FILTER,gl.GL_LINEAR);
gl.glTexParameteri(gl.GL_TEXTURE_2D,gl.GL_TEXTURE_MIN_FILTER,gl.GL_LINEAR);
ByteBuffer bb = ByteBuffer.wrap(photodata.data);
gl.glTexImage2D(gl.GL_TEXTURE_2D, 0, 3, photodata.width, photodata.height, 0, gl.GL_RGB, gl.GL_UNSIGNED_BYTE, bb);
}
And this method is being called after I’ve loaded in an image (into my simple PhotoData class) remotely like so :
Image img = new ImageIcon(myURL).getImage();
Then I use PixelGrabber to get the bytes for the image before calling my bindTexture as above. Currently this is all triggered by pressing the space bar, so there is no timer thread at all right now, except I’m using the Animator class to display. I’m using Java 1.6 beta 2/JSR-231 beta 5 on a PC.
Thanks!
-spiraljetty
(PS I’ve posted this by mistake in the performance tuning board as well, so apologies for that…)