Modifying JOGL - overiding glTexImage2D

Hello,

Please could somebody suggest some pointers on how to modify JOGL, specifically the GL class.
Specifically I need to override glTexImage2D to take a pointer in native memory as its pixel source.

glTexImage2D(texType,
0,
0,
0,
rowPixels,
height,
GL.GL_BGRA,
GL.GL_UNSIGNED_INT_8_8_8_8_REV,
pixels); // pointer to address in memory

and the associated function glTexSubImage2D.

gl.glTexSubImage2D (texType,
0,
0,
0,
rowPixels,
height,
GL.GL_BGRA,
GL.GL_UNSIGNED_INT_8_8_8_8_REV,
pixels); // pointer to address in memory

The app uses quicktime for java to render video, image data from the video is then copied into a a Buffer and passed to glTexImage2D.
ByteBuffer.wrap(gworld.getPixMap().getPixelData().getBytes());
Each copy takes a long time. I’d like to miss out the copy by passing the memory address to glTexSubImage.
QTObject.ID(gworld.getPixMap().getPixelData());

Thanks for your help.

Cheers,

Ewan

I guess you don’t have to modify JOGL, because what you need seems to be already there (at least in JSR-231):

glTexImage2D(int target, int level, int internalFormat, int width, int height, int border, int format, int type, long pixels_buffer_offset)
glTexSubImage2D(int target, int level, int xoffset, int yoffset, int width, int height, int format, int type, long pixels_buffer_offset)

makes sense?

This seems to just move the problem of copying. Instead of copying into a ByteBuffer and using that as the texture I now create a Pixel Buffer Object and copy the pixels into that. Any suggestions would be great,
Cheers,
Ewan

gl.glBindBuffer(GL.GL_PIXEL_UNPACK_BUFFER_EXT,0);
gl.glTexImage2D (texType,,0, GL.GL_RGBA, rowPixels, height,0,GL.GL_BGRA,GL.GL_UNSIGNED_INT_8_8_8_8_REV, null);
int[] texBuffer = new int[1];
gl.glGenBuffers(1,texBuffer,0);
pboID =  texBuffer[0];
gl.glBindBuffer(GL.GL_PIXEL_UNPACK_BUFFER_EXT,pboID);
		
gl.glBufferData(GL.GL_PIXEL_UNPACK_BUFFER_EXT, texSize, null, GL.GL_STREAM_DRAW);
pboBuffer = gl.glMapBuffer(GL.GL_PIXEL_UNPACK_BUFFER_EXT,GL.GL_WRITE_ONLY);
pboBuffer.put(gworld.getPixMap().getPixelData().getBytes()); //COPY
gl.glUnmapBuffer(GL.GL_PIXEL_UNPACK_BUFFER_EXT);

int[] texName = new int[1];
gl.glEnable (texType);
gl.glGenTextures (1, texName,0);
textureID = texName[0];
gl.glBindTexture(texType, textureID);
gl.glTexEnvf(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE,GL.GL_REPLACE);
gl.glTexParameteri(texType, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR);
gl.glTexParameteri(texType, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR);
gl.glTexParameteri(texType, GL.GL_TEXTURE_WRAP_S, GL.GL_CLAMP_TO_EDGE);
gl.glTexParameteri(texType, GL.GL_TEXTURE_WRAP_T, GL.GL_CLAMP_TO_EDGE);
gl.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, 1);
gl.glPixelStorei(GL.GL_UNPACK_ROW_LENGTH, 0);
		
gl.glBindTexture(texType, textureID);
gl.glTexImage2D (texType,0,GL.GL_RGBA,rowPixels,height,0,GL.GL_BGRA,GL.GL_UNSIGNED_INT_8_8_8_8_REV,0);

You need a small snippet of native code to be able to call the JNI function NewDirectByteBuffer, which will create a ByteBuffer object referring to your native memory region. You can then pass this to JOGL, in particular glTexImage2D.

Great, this works like a dream, thanks.

Could someone elaborate on this and possibly provide some full sample code, i’m a bit stumped.